From 451dd32d9be5bfa7f46abf4000a53d0e1e53ed15 Mon Sep 17 00:00:00 2001 From: volcano Date: Wed, 23 Aug 2023 18:07:07 +0800 Subject: [PATCH 01/34] Support intel-sgx-sdk 2.20 --- common/inc/internal/arch.h | 26 ++- common/inc/internal/inst.h | 3 + common/inc/internal/metadata.h | 12 +- common/inc/sgx_attributes.h | 14 +- common/inc/sgx_tprotected_fs.h | 26 ++- common/inc/sgx_trts_aex.h | 99 +++++++++ common/inc/sgx_trts_exception.h | 18 ++ common/inc/tlibc/stdalign.h | 14 ++ common/inc/tlibc/stdlib.h | 2 + .../download_prebuilt/download_prebuilt.sh | 6 +- sgx_crypto/sgx_crypto_sys/tcrypto/Makefile | 2 +- .../ippcpGetLibVersion.c} | 51 ++--- .../ippsAESDecryptCBC.c} | 51 ++--- .../ippsAESDecryptCBC_CS1.c} | 51 ++--- .../ippsAESDecryptCBC_CS2.c} | 51 ++--- .../ippsAESDecryptCBC_CS3.c} | 51 ++--- .../ippsAESDecryptCFB.c} | 51 ++--- .../ippsAESDecryptCTR.c} | 51 ++--- .../ippsAESDecryptECB.c} | 51 ++--- .../ippsAESDecryptOFB.c} | 51 ++--- .../ippsAESDecryptXTS_Direct.c} | 51 ++--- .../ippsAESEncryptCBC.c} | 51 ++--- .../ippsAESEncryptCBC_CS1.c} | 51 ++--- .../ippsAESEncryptCBC_CS2.c} | 51 ++--- .../ippsAESEncryptCBC_CS3.c} | 51 ++--- .../ippsAESEncryptCFB.c} | 51 ++--- .../ippsAESEncryptCTR.c} | 51 ++--- .../ippsAESEncryptECB.c} | 51 ++--- .../ippsAESEncryptOFB.c} | 51 ++--- .../ippsAESEncryptXTS_Direct.c} | 51 ++--- .../ippsAESGetSize.c} | 51 ++--- .../ippsAESInit.c} | 51 ++--- .../ippsAESPack.c} | 51 ++--- .../ippsAESSetKey.c} | 51 ++--- .../ipp/ipp_disp/intel64/ippsAESSetupNoise.c | 82 ++++++++ .../ippsAESUnpack.c} | 51 ++--- .../ippsAES_CCMDecrypt.c} | 51 ++--- .../ippsAES_CCMEncrypt.c} | 51 ++--- .../ippsAES_CCMGetSize.c} | 51 ++--- .../ippsAES_CCMGetTag.c} | 51 ++--- .../ippsAES_CCMInit.c} | 51 ++--- .../ippsAES_CCMMessageLen.c} | 51 ++--- .../ippsAES_CCMStart.c} | 51 ++--- .../ippsAES_CCMTagLen.c} | 51 ++--- .../ippsAES_CMACFinal.c} | 51 ++--- .../ippsAES_CMACGetSize.c} | 51 ++--- .../ippsAES_CMACGetTag.c} | 51 ++--- .../ippsAES_CMACInit.c} | 51 ++--- .../ipp_disp/intel64/ippsAES_CMACSetupNoise.c | 82 ++++++++ .../ippsAES_CMACUpdate.c} | 51 ++--- .../ippsAES_EncryptCFB16_MB.c} | 51 ++--- .../ippsAES_GCMDecrypt.c} | 51 ++--- .../ippsAES_GCMEncrypt.c} | 51 ++--- .../ippsAES_GCMGetSize.c} | 51 ++--- .../ippsAES_GCMGetTag.c} | 51 ++--- .../ippsAES_GCMInit.c} | 51 ++--- .../ipp_disp/intel64/ippsAES_GCMProcessAAD.c | 82 ++++++++ .../ippsAES_GCMProcessIV.c} | 51 ++--- .../ippsAES_GCMReset.c} | 51 ++--- .../ipp_disp/intel64/ippsAES_GCMSetupNoise.c | 82 ++++++++ .../ippsAES_GCMStart.c} | 51 ++--- .../ippsAES_S2V_CMAC.c} | 51 ++--- .../ippsAES_SIVDecrypt.c} | 51 ++--- .../ippsAES_SIVEncrypt.c} | 51 ++--- .../ippsAES_XTSDecrypt.c} | 51 ++--- .../ippsAES_XTSEncrypt.c} | 51 ++--- .../ippsAES_XTSGetSize.c} | 51 ++--- .../ippsAES_XTSInit.c} | 51 ++--- .../ippsARCFourCheckKey.c} | 51 ++--- .../ippsARCFourDecrypt.c} | 51 ++--- .../ippsARCFourEncrypt.c} | 51 ++--- .../ippsARCFourGetSize.c} | 51 ++--- .../ippsARCFourInit.c} | 51 ++--- .../ippsARCFourPack.c} | 51 ++--- .../ippsARCFourReset.c} | 51 ++--- .../ippsARCFourUnpack.c} | 51 ++--- .../ippsAdd_BN.c} | 51 ++--- .../ippsBigNumGetSize.c} | 51 ++--- .../ippsBigNumInit.c} | 51 ++--- .../ippsCmpZero_BN.c} | 51 ++--- .../ippsCmp_BN.c} | 51 ++--- .../ippsDESGetSize.c} | 51 ++--- .../ippsDESInit.c} | 51 ++--- .../ippsDESPack.c} | 51 ++--- .../ippsDESUnpack.c} | 51 ++--- .../ippsDLGetResultString.c} | 51 ++--- .../ippsDLPGenKeyPair.c} | 51 ++--- .../ippsDLPGenerateDH.c} | 51 ++--- .../ippsDLPGenerateDSA.c} | 51 ++--- .../ippsDLPGet.c} | 51 ++--- .../ippsDLPGetDP.c} | 51 ++--- .../ippsDLPGetSize.c} | 51 ++--- .../ippsDLPInit.c} | 51 ++--- .../ippsDLPPack.c} | 51 ++--- .../ippsDLPPublicKey.c} | 51 ++--- .../ippsDLPSet.c} | 51 ++--- .../ippsDLPSetDP.c} | 51 ++--- .../ippsDLPSetKeyPair.c} | 51 ++--- .../ippsDLPSharedSecretDH.c} | 51 ++--- .../ippsDLPSignDSA.c} | 51 ++--- .../ippsDLPUnpack.c} | 51 ++--- .../ippsDLPValidateDH.c} | 51 ++--- .../ippsDLPValidateDSA.c} | 51 ++--- .../ippsDLPValidateKeyPair.c} | 51 ++--- .../ippsDLPVerifyDSA.c} | 51 ++--- .../ippsDiv_BN.c} | 51 ++--- .../ippsECCGetResultString.c} | 51 ++--- .../ippsECCPAddPoint.c} | 51 ++--- .../ippsECCPBindGxyTblStd192r1.c} | 51 ++--- .../ippsECCPBindGxyTblStd224r1.c} | 51 ++--- .../ippsECCPBindGxyTblStd256r1.c} | 51 ++--- .../ippsECCPBindGxyTblStd384r1.c} | 51 ++--- .../ippsECCPBindGxyTblStd521r1.c} | 51 ++--- .../ippsECCPBindGxyTblStdSM2.c} | 51 ++--- .../ippsECCPCheckPoint.c} | 51 ++--- .../ippsECCPComparePoint.c} | 51 ++--- .../ippsECCPGenKeyPair.c} | 51 ++--- .../ippsECCPGet.c} | 51 ++--- .../ippsECCPGetOrderBitSize.c} | 51 ++--- .../ippsECCPGetPoint.c} | 51 ++--- .../ippsECCPGetSize.c} | 51 ++--- .../ippsECCPGetSizeStd128r1.c} | 51 ++--- .../ippsECCPGetSizeStd128r2.c} | 51 ++--- .../ippsECCPGetSizeStd192r1.c} | 51 ++--- .../ippsECCPGetSizeStd224r1.c} | 51 ++--- .../ippsECCPGetSizeStd256r1.c} | 51 ++--- .../ippsECCPGetSizeStd384r1.c} | 51 ++--- .../ippsECCPGetSizeStd521r1.c} | 51 ++--- .../ippsECCPGetSizeStdSM2.c} | 51 ++--- .../ippsECCPInit.c} | 51 ++--- .../ippsECCPInitStd128r1.c} | 51 ++--- .../ippsECCPInitStd128r2.c} | 51 ++--- .../ippsECCPInitStd192r1.c} | 51 ++--- .../ippsECCPInitStd224r1.c} | 51 ++--- .../ippsECCPInitStd256r1.c} | 51 ++--- .../ippsECCPInitStd384r1.c} | 51 ++--- .../ippsECCPInitStd521r1.c} | 51 ++--- .../ippsECCPInitStdSM2.c} | 51 ++--- .../ippsECCPMulPointScalar.c} | 51 ++--- .../ippsECCPNegativePoint.c} | 51 ++--- .../ippsECCPPointGetSize.c} | 51 ++--- .../ippsECCPPointInit.c} | 51 ++--- .../ippsECCPPublicKey.c} | 51 ++--- .../ippsECCPSet.c} | 51 ++--- .../ippsECCPSetKeyPair.c} | 51 ++--- .../ippsECCPSetPoint.c} | 51 ++--- .../ippsECCPSetPointAtInfinity.c} | 51 ++--- .../ippsECCPSetStd.c} | 51 ++--- .../ippsECCPSetStd128r1.c} | 51 ++--- .../ippsECCPSetStd128r2.c} | 51 ++--- .../ippsECCPSetStd192r1.c} | 51 ++--- .../ippsECCPSetStd224r1.c} | 51 ++--- .../ippsECCPSetStd256r1.c} | 51 ++--- .../ippsECCPSetStd384r1.c} | 51 ++--- .../ippsECCPSetStd521r1.c} | 51 ++--- .../ippsECCPSetStdSM2.c} | 51 ++--- .../ippsECCPSharedSecretDH.c} | 51 ++--- .../ippsECCPSharedSecretDHC.c} | 51 ++--- .../ippsECCPSignDSA.c} | 51 ++--- .../ippsECCPSignNR.c} | 51 ++--- .../ippsECCPSignSM2.c} | 51 ++--- .../ippsECCPValidate.c} | 51 ++--- .../ippsECCPValidateKeyPair.c} | 51 ++--- .../ippsECCPVerifyDSA.c} | 51 ++--- .../ippsECCPVerifyNR.c} | 51 ++--- .../ippsECCPVerifySM2.c} | 51 ++--- .../ippsExtGet_BN.c} | 51 ++--- .../ippsGFpAdd.c} | 51 ++--- .../ippsGFpAdd_PE.c} | 51 ++--- .../ippsGFpCmpElement.c} | 51 ++--- .../ippsGFpConj.c} | 51 ++--- .../ippsGFpCpyElement.c} | 51 ++--- .../ippsGFpECAddPoint.c} | 51 ++--- .../ippsGFpECBindGxyTblStd192r1.c} | 51 ++--- .../ippsGFpECBindGxyTblStd224r1.c} | 51 ++--- .../ippsGFpECBindGxyTblStd256r1.c} | 51 ++--- .../ippsGFpECBindGxyTblStd384r1.c} | 51 ++--- .../ippsGFpECBindGxyTblStd521r1.c} | 51 ++--- .../ippsGFpECBindGxyTblStdSM2.c} | 51 ++--- .../ippsGFpECCmpPoint.c} | 51 ++--- .../ippsGFpECCpyPoint.c} | 51 ++--- .../intel64/ippsGFpECDecryptSM2_Ext.c | 82 ++++++++ .../ippsGFpECDecryptSM2_Ext_DecMsgSize.c | 82 ++++++++ .../ippsGFpECESDecrypt_SM2.c} | 51 ++--- .../ippsGFpECESEncrypt_SM2.c} | 51 ++--- .../ippsGFpECESFinal_SM2.c} | 51 ++--- .../ippsGFpECESGetBuffersSize_SM2.c} | 51 ++--- .../ippsGFpECESGetSize_SM2.c} | 51 ++--- .../ippsGFpECESInit_SM2.c} | 51 ++--- .../ippsGFpECESSetKey_SM2.c} | 51 ++--- .../ippsGFpECESStart_SM2.c} | 51 ++--- .../intel64/ippsGFpECEncryptSM2_Ext.c | 82 ++++++++ .../ippsGFpECEncryptSM2_Ext_EncMsgSize.c | 82 ++++++++ .../ippsGFpECGet.c} | 51 ++--- .../ippsGFpECGetInfo_GF.c} | 51 ++--- .../ippsGFpECGetPoint.c} | 51 ++--- .../ippsGFpECGetPointOctString.c} | 51 ++--- .../ippsGFpECGetPointRegular.c} | 51 ++--- .../ippsGFpECGetSize.c} | 51 ++--- .../ippsGFpECGetSubgroup.c} | 51 ++--- .../ippsGFpECInit.c} | 51 ++--- .../ippsGFpECInitStd128r1.c} | 51 ++--- .../ippsGFpECInitStd128r2.c} | 51 ++--- .../ippsGFpECInitStd192r1.c} | 51 ++--- .../ippsGFpECInitStd224r1.c} | 51 ++--- .../ippsGFpECInitStd256r1.c} | 51 ++--- .../ippsGFpECInitStd384r1.c} | 51 ++--- .../ippsGFpECInitStd521r1.c} | 51 ++--- .../ippsGFpECInitStdBN256.c} | 51 ++--- .../ippsGFpECInitStdSM2.c} | 51 ++--- .../intel64/ippsGFpECKeyExchangeSM2_Confirm.c | 82 ++++++++ .../intel64/ippsGFpECKeyExchangeSM2_GetSize.c | 82 ++++++++ .../intel64/ippsGFpECKeyExchangeSM2_Init.c | 82 ++++++++ .../intel64/ippsGFpECKeyExchangeSM2_Setup.c | 82 ++++++++ .../ippsGFpECKeyExchangeSM2_SharedKey.c | 82 ++++++++ .../ippsGFpECMakePoint.c} | 51 ++--- .../ippsGFpECMessageRepresentationSM2.c | 82 ++++++++ .../ippsGFpECMulPoint.c} | 51 ++--- .../ippsGFpECNegPoint.c} | 51 ++--- .../ippsGFpECPointGetSize.c} | 51 ++--- .../ippsGFpECPointInit.c} | 51 ++--- .../ippsGFpECPrivateKey.c} | 51 ++--- .../ippsGFpECPublicKey.c} | 51 ++--- .../ippsGFpECScratchBufferSize.c} | 51 ++--- .../ippsGFpECSet.c} | 51 ++--- .../ippsGFpECSetPoint.c} | 51 ++--- .../ippsGFpECSetPointAtInfinity.c} | 51 ++--- .../ippsGFpECSetPointHash.c} | 51 ++--- .../ippsGFpECSetPointHashBackCompatible.c} | 51 ++--- ...ippsGFpECSetPointHashBackCompatible_rmf.c} | 51 ++--- .../ippsGFpECSetPointHash_rmf.c} | 51 ++--- .../ippsGFpECSetPointOctString.c} | 51 ++--- .../ippsGFpECSetPointRandom.c} | 51 ++--- .../ippsGFpECSetPointRegular.c} | 51 ++--- .../ippsGFpECSetSubgroup.c} | 51 ++--- .../ippsGFpECSharedSecretDH.c} | 51 ++--- .../ippsGFpECSharedSecretDHC.c} | 51 ++--- .../ipp/ipp_disp/intel64/ippsGFpECSignDSA.c | 82 ++++++++ .../ipp/ipp_disp/intel64/ippsGFpECSignNR.c | 82 ++++++++ .../ipp/ipp_disp/intel64/ippsGFpECSignSM2.c | 82 ++++++++ .../ippsGFpECTstKeyPair.c} | 51 ++--- .../ippsGFpECTstPoint.c} | 51 ++--- .../ippsGFpECTstPointInSubgroup.c} | 51 ++--- .../ipp_disp/intel64/ippsGFpECUserIDHashSM2.c | 82 ++++++++ .../ippsGFpECVerify.c} | 51 ++--- .../ipp/ipp_disp/intel64/ippsGFpECVerifyDSA.c | 82 ++++++++ .../ipp/ipp_disp/intel64/ippsGFpECVerifyNR.c | 82 ++++++++ .../ipp/ipp_disp/intel64/ippsGFpECVerifySM2.c | 82 ++++++++ .../ippsGFpElementGetSize.c} | 51 ++--- .../ippsGFpElementInit.c} | 51 ++--- .../ippsGFpExp.c} | 51 ++--- .../ippsGFpGetElement.c} | 51 ++--- .../ippsGFpGetElementOctString.c} | 51 ++--- .../ippsGFpGetInfo.c} | 51 ++--- .../ippsGFpGetSize.c} | 51 ++--- .../ippsGFpInit.c} | 51 ++--- .../ippsGFpInitArbitrary.c} | 51 ++--- .../ippsGFpInitFixed.c} | 51 ++--- .../ippsGFpInv.c} | 51 ++--- .../ippsGFpIsUnityElement.c} | 51 ++--- .../ippsGFpIsZeroElement.c} | 51 ++--- .../ippsGFpMethod_p192r1.c} | 51 ++--- .../ippsGFpMethod_p224r1.c} | 51 ++--- .../ippsGFpMethod_p256.c} | 51 ++--- .../ippsGFpMethod_p256bn.c} | 51 ++--- .../ippsGFpMethod_p256r1.c} | 51 ++--- .../ippsGFpMethod_p256sm2.c} | 51 ++--- .../ippsGFpMethod_p384r1.c} | 51 ++--- .../ippsGFpMethod_p521r1.c} | 51 ++--- .../ippsGFpMethod_pArb.c} | 51 ++--- .../ippsGFpMul.c} | 51 ++--- .../ippsGFpMul_PE.c} | 51 ++--- .../ippsGFpMultiExp.c} | 51 ++--- .../ippsGFpNeg.c} | 51 ++--- .../ippsGFpScratchBufferSize.c} | 51 ++--- .../ippsGFpSetElement.c} | 51 ++--- .../ippsGFpSetElementHash.c} | 51 ++--- .../ippsGFpSetElementHash_rmf.c} | 51 ++--- .../ippsGFpSetElementOctString.c} | 51 ++--- .../ippsGFpSetElementRandom.c} | 51 ++--- .../ippsGFpSetElementRegular.c} | 51 ++--- .../ippsGFpSqr.c} | 51 ++--- .../ippsGFpSqrt.c} | 51 ++--- .../ippsGFpSub.c} | 51 ++--- .../ippsGFpSub_PE.c} | 51 ++--- .../ippsGFpxGetSize.c} | 51 ++--- .../ippsGFpxInit.c} | 51 ++--- .../ippsGFpxInitBinomial.c} | 51 ++--- .../ippsGFpxMethod_binom.c} | 51 ++--- .../ippsGFpxMethod_binom2.c} | 51 ++--- .../ippsGFpxMethod_binom2_epid2.c} | 51 ++--- .../ippsGFpxMethod_binom3.c} | 51 ++--- .../ippsGFpxMethod_binom3_epid2.c} | 51 ++--- .../ippsGFpxMethod_com.c} | 51 ++--- .../ippsGcd_BN.c} | 51 ++--- .../ippsGetOctString_BN.c} | 51 ++--- .../ippsGetSize_BN.c} | 51 ++--- .../ippsGet_BN.c} | 51 ++--- .../ippsHMACDuplicate_rmf.c} | 51 ++--- .../ippsHMACFinal_rmf.c} | 51 ++--- .../ippsHMACGetSize_rmf.c} | 51 ++--- .../ippsHMACGetTag_rmf.c} | 51 ++--- .../ippsHMACInit_rmf.c} | 51 ++--- .../ippsHMACMessage_rmf.c} | 51 ++--- .../ippsHMACPack_rmf.c} | 51 ++--- .../ippsHMACUnpack_rmf.c} | 51 ++--- .../ippsHMACUpdate_rmf.c} | 51 ++--- .../ippsHMAC_Duplicate.c} | 51 ++--- .../ippsHMAC_Final.c} | 51 ++--- .../ippsHMAC_GetSize.c} | 51 ++--- .../ippsHMAC_GetTag.c} | 51 ++--- .../ippsHMAC_Init.c} | 51 ++--- .../ippsHMAC_Message.c} | 51 ++--- .../ippsHMAC_Pack.c} | 51 ++--- .../ippsHMAC_Unpack.c} | 51 ++--- .../ippsHMAC_Update.c} | 51 ++--- .../ippsHashDuplicate.c} | 51 ++--- .../ippsHashDuplicate_rmf.c} | 51 ++--- .../ippsHashFinal.c} | 51 ++--- .../ippsHashFinal_rmf.c} | 51 ++--- .../ippsHashGetInfo_rmf.c} | 51 ++--- .../ippsHashGetSize.c} | 51 ++--- .../ippsHashGetSize_rmf.c} | 51 ++--- .../ippsHashGetTag.c} | 51 ++--- .../ippsHashGetTag_rmf.c} | 51 ++--- .../ippsHashInit.c} | 51 ++--- .../ippsHashInit_rmf.c} | 51 ++--- .../ippsHashMessage.c} | 51 ++--- .../ippsHashMessage_rmf.c} | 51 ++--- .../ippsHashMethodGetInfo.c} | 51 ++--- .../ippsHashMethodGetSize.c} | 51 ++--- .../ippsHashMethodSet_MD5.c} | 51 ++--- .../ippsHashMethodSet_SHA1.c} | 51 ++--- .../ippsHashMethodSet_SHA1_NI.c} | 51 ++--- .../ippsHashMethodSet_SHA1_TT.c} | 51 ++--- .../ippsHashMethodSet_SHA224.c} | 51 ++--- .../ippsHashMethodSet_SHA224_NI.c} | 51 ++--- .../ippsHashMethodSet_SHA224_TT.c} | 51 ++--- .../ippsHashMethodSet_SHA256.c} | 51 ++--- .../ippsHashMethodSet_SHA256_NI.c} | 51 ++--- .../ippsHashMethodSet_SHA256_TT.c} | 51 ++--- .../ippsHashMethodSet_SHA384.c} | 51 ++--- .../ippsHashMethodSet_SHA512.c} | 51 ++--- .../ippsHashMethodSet_SHA512_224.c} | 51 ++--- .../ippsHashMethodSet_SHA512_256.c} | 51 ++--- .../ippsHashMethodSet_SM3.c} | 51 ++--- .../ippsHashMethod_MD5.c} | 51 ++--- .../ippsHashMethod_SHA1.c} | 51 ++--- .../ippsHashMethod_SHA1_NI.c} | 51 ++--- .../ippsHashMethod_SHA1_TT.c} | 51 ++--- .../ippsHashMethod_SHA224.c} | 51 ++--- .../ippsHashMethod_SHA224_NI.c} | 51 ++--- .../ippsHashMethod_SHA224_TT.c} | 51 ++--- .../ippsHashMethod_SHA256.c} | 51 ++--- .../ippsHashMethod_SHA256_NI.c} | 51 ++--- .../ippsHashMethod_SHA256_TT.c} | 51 ++--- .../ippsHashMethod_SHA384.c} | 51 ++--- .../ippsHashMethod_SHA512.c} | 51 ++--- .../ippsHashMethod_SHA512_224.c} | 51 ++--- .../ippsHashMethod_SHA512_256.c} | 51 ++--- .../ippsHashMethod_SM3.c} | 51 ++--- .../ippsHashPack.c} | 51 ++--- .../ippsHashPack_rmf.c} | 51 ++--- .../intel64/ippsHashStateMethodSet_SHA224.c | 82 ++++++++ .../ippsHashStateMethodSet_SHA224_NI.c | 82 ++++++++ .../ippsHashStateMethodSet_SHA224_TT.c | 82 ++++++++ .../intel64/ippsHashStateMethodSet_SHA256.c | 82 ++++++++ .../ippsHashStateMethodSet_SHA256_NI.c | 82 ++++++++ .../ippsHashStateMethodSet_SHA256_TT.c | 82 ++++++++ .../intel64/ippsHashStateMethodSet_SHA384.c | 82 ++++++++ .../intel64/ippsHashStateMethodSet_SHA512.c | 82 ++++++++ .../ippsHashStateMethodSet_SHA512_224.c | 82 ++++++++ .../ippsHashStateMethodSet_SHA512_256.c | 82 ++++++++ .../intel64/ippsHashStateMethodSet_SM3.c | 82 ++++++++ .../ippsHashUnpack.c} | 51 ++--- .../ippsHashUnpack_rmf.c} | 51 ++--- .../ippsHashUpdate.c} | 51 ++--- .../ippsHashUpdate_rmf.c} | 51 ++--- .../ippsMAC_BN_I.c} | 51 ++--- .../ippsMD5Duplicate.c} | 51 ++--- .../ippsMD5Final.c} | 51 ++--- .../ippsMD5GetSize.c} | 51 ++--- .../ippsMD5GetTag.c} | 51 ++--- .../ippsMD5Init.c} | 51 ++--- .../ippsMD5MessageDigest.c} | 51 ++--- .../ippsMD5Pack.c} | 51 ++--- .../ippsMD5Unpack.c} | 51 ++--- .../ippsMD5Update.c} | 51 ++--- .../ippsMGF.c} | 51 ++--- .../ippsMGF1_rmf.c} | 51 ++--- .../ippsMGF2_rmf.c} | 51 ++--- .../ippsModInv_BN.c} | 51 ++--- .../ippsMod_BN.c} | 51 ++--- .../ippsMontExp.c} | 51 ++--- .../ippsMontForm.c} | 51 ++--- .../ippsMontGet.c} | 51 ++--- .../ippsMontGetSize.c} | 51 ++--- .../ippsMontInit.c} | 51 ++--- .../ippsMontMul.c} | 51 ++--- .../ippsMontSet.c} | 51 ++--- .../ippsMul_BN.c} | 51 ++--- .../ippsPRNGGetSeed.c} | 51 ++--- .../ippsPRNGGetSize.c} | 51 ++--- .../ippsPRNGInit.c} | 51 ++--- .../ippsPRNGSetAugment.c} | 51 ++--- .../ippsPRNGSetH0.c} | 51 ++--- .../ippsPRNGSetModulus.c} | 51 ++--- .../ippsPRNGSetSeed.c} | 51 ++--- .../ippsPRNGen.c} | 51 ++--- .../ippsPRNGenRDRAND.c} | 51 ++--- .../ippsPRNGenRDRAND_BN.c} | 51 ++--- .../ippsPRNGen_BN.c} | 51 ++--- .../ippsPrimeGen.c} | 51 ++--- .../ippsPrimeGen_BN.c} | 51 ++--- .../ippsPrimeGet.c} | 51 ++--- .../ippsPrimeGetSize.c} | 51 ++--- .../ippsPrimeGet_BN.c} | 51 ++--- .../ippsPrimeInit.c} | 51 ++--- .../ippsPrimeSet.c} | 51 ++--- .../ippsPrimeSet_BN.c} | 51 ++--- .../ippsPrimeTest.c} | 51 ++--- .../ippsPrimeTest_BN.c} | 51 ++--- .../ippsRSADecrypt_OAEP.c} | 51 ++--- .../ippsRSADecrypt_OAEP_rmf.c} | 51 ++--- .../ippsRSADecrypt_PKCSv15.c} | 51 ++--- .../ippsRSAEncrypt_OAEP.c} | 51 ++--- .../ippsRSAEncrypt_OAEP_rmf.c} | 51 ++--- .../ippsRSAEncrypt_PKCSv15.c} | 51 ++--- .../ippsRSASign_PKCS1v15.c} | 51 ++--- .../ippsRSASign_PKCS1v15_rmf.c} | 51 ++--- .../ippsRSASign_PSS.c} | 51 ++--- .../ippsRSASign_PSS_rmf.c} | 51 ++--- .../ippsRSAVerify_PKCS1v15.c} | 51 ++--- .../ippsRSAVerify_PKCS1v15_rmf.c} | 51 ++--- .../ippsRSAVerify_PSS.c} | 51 ++--- .../ippsRSAVerify_PSS_rmf.c} | 51 ++--- .../ippsRSA_Decrypt.c} | 51 ++--- .../ippsRSA_Encrypt.c} | 51 ++--- .../ippsRSA_GenerateKeys.c} | 51 ++--- .../ippsRSA_GetBufferSizePrivateKey.c} | 51 ++--- .../ippsRSA_GetBufferSizePublicKey.c} | 51 ++--- .../ippsRSA_GetPrivateKeyType1.c} | 51 ++--- .../ippsRSA_GetPrivateKeyType2.c} | 51 ++--- .../ippsRSA_GetPublicKey.c} | 51 ++--- .../ippsRSA_GetSizePrivateKeyType1.c} | 51 ++--- .../ippsRSA_GetSizePrivateKeyType2.c} | 51 ++--- .../ippsRSA_GetSizePublicKey.c} | 51 ++--- .../ippsRSA_InitPrivateKeyType1.c} | 51 ++--- .../ippsRSA_InitPrivateKeyType2.c} | 51 ++--- .../ippsRSA_InitPublicKey.c} | 51 ++--- .../ippsRSA_SetPrivateKeyType1.c} | 51 ++--- .../ippsRSA_SetPrivateKeyType2.c} | 51 ++--- .../ippsRSA_SetPublicKey.c} | 51 ++--- .../ippsRSA_ValidateKeys.c} | 51 ++--- .../ippsRef_BN.c} | 51 ++--- .../ippsSHA1Duplicate.c} | 51 ++--- .../ippsSHA1Final.c} | 51 ++--- .../ippsSHA1GetSize.c} | 51 ++--- .../ippsSHA1GetTag.c} | 51 ++--- .../ippsSHA1Init.c} | 51 ++--- .../ippsSHA1MessageDigest.c} | 51 ++--- .../ippsSHA1Pack.c} | 51 ++--- .../ippsSHA1Unpack.c} | 51 ++--- .../ippsSHA1Update.c} | 51 ++--- .../ippsSHA224Duplicate.c} | 51 ++--- .../ippsSHA224Final.c} | 51 ++--- .../ippsSHA224GetSize.c} | 51 ++--- .../ippsSHA224GetTag.c} | 51 ++--- .../ippsSHA224Init.c} | 51 ++--- .../ippsSHA224MessageDigest.c} | 51 ++--- .../ippsSHA224Pack.c} | 51 ++--- .../ippsSHA224Unpack.c} | 51 ++--- .../ippsSHA224Update.c} | 51 ++--- .../ippsSHA256Duplicate.c} | 51 ++--- .../ippsSHA256Final.c} | 51 ++--- .../ippsSHA256GetSize.c} | 51 ++--- .../ippsSHA256GetTag.c} | 51 ++--- .../ippsSHA256Init.c} | 51 ++--- .../ippsSHA256MessageDigest.c} | 51 ++--- .../ippsSHA256Pack.c} | 51 ++--- .../ippsSHA256Unpack.c} | 51 ++--- .../ippsSHA256Update.c} | 51 ++--- .../ippsSHA384Duplicate.c} | 51 ++--- .../ippsSHA384Final.c} | 51 ++--- .../ippsSHA384GetSize.c} | 51 ++--- .../ippsSHA384GetTag.c} | 51 ++--- .../ippsSHA384Init.c} | 51 ++--- .../ippsSHA384MessageDigest.c} | 51 ++--- .../ippsSHA384Pack.c} | 51 ++--- .../ippsSHA384Unpack.c} | 51 ++--- .../ippsSHA384Update.c} | 51 ++--- .../ippsSHA512Duplicate.c} | 51 ++--- .../ippsSHA512Final.c} | 51 ++--- .../ippsSHA512GetSize.c} | 51 ++--- .../ippsSHA512GetTag.c} | 51 ++--- .../ippsSHA512Init.c} | 51 ++--- .../ippsSHA512MessageDigest.c} | 51 ++--- .../ippsSHA512Pack.c} | 51 ++--- .../ippsSHA512Unpack.c} | 51 ++--- .../ippsSHA512Update.c} | 51 ++--- .../ippsSM3Duplicate.c} | 51 ++--- .../ippsSM3Final.c} | 51 ++--- .../ippsSM3GetSize.c} | 51 ++--- .../ippsSM3GetTag.c} | 51 ++--- .../ippsSM3Init.c} | 51 ++--- .../ippsSM3MessageDigest.c} | 51 ++--- .../ippsSM3Pack.c} | 51 ++--- .../ippsSM3Unpack.c} | 51 ++--- .../ippsSM3Update.c} | 51 ++--- .../ippsSMS4DecryptCBC.c} | 51 ++--- .../ippsSMS4DecryptCBC_CS1.c} | 51 ++--- .../ippsSMS4DecryptCBC_CS2.c} | 51 ++--- .../ippsSMS4DecryptCBC_CS3.c} | 51 ++--- .../ippsSMS4DecryptCFB.c} | 51 ++--- .../ippsSMS4DecryptCTR.c} | 51 ++--- .../ippsSMS4DecryptECB.c} | 51 ++--- .../ippsSMS4DecryptOFB.c} | 51 ++--- .../ippsSMS4EncryptCBC.c} | 51 ++--- .../ippsSMS4EncryptCBC_CS1.c} | 51 ++--- .../ippsSMS4EncryptCBC_CS2.c} | 51 ++--- .../ippsSMS4EncryptCBC_CS3.c} | 51 ++--- .../ippsSMS4EncryptCFB.c} | 51 ++--- .../ippsSMS4EncryptCTR.c} | 51 ++--- .../ippsSMS4EncryptECB.c} | 51 ++--- .../ippsSMS4EncryptOFB.c} | 51 ++--- .../ippsSMS4GetSize.c} | 51 ++--- .../ippsSMS4Init.c} | 51 ++--- .../ippsSMS4SetKey.c} | 51 ++--- .../ippsSMS4_CCMDecrypt.c} | 51 ++--- .../ippsSMS4_CCMEncrypt.c} | 51 ++--- .../ippsSMS4_CCMGetSize.c} | 51 ++--- .../ippsSMS4_CCMGetTag.c} | 51 ++--- .../ippsSMS4_CCMInit.c} | 51 ++--- .../ippsSMS4_CCMMessageLen.c} | 51 ++--- .../ippsSMS4_CCMStart.c} | 51 ++--- .../ippsSMS4_CCMTagLen.c} | 51 ++--- .../ippsSetOctString_BN.c} | 51 ++--- .../ippsSet_BN.c} | 51 ++--- .../ippsSub_BN.c} | 51 ++--- .../ippsTDESDecryptCBC.c} | 51 ++--- .../ippsTDESDecryptCFB.c} | 51 ++--- .../ippsTDESDecryptCTR.c} | 51 ++--- .../ippsTDESDecryptECB.c} | 51 ++--- .../ippsTDESDecryptOFB.c} | 51 ++--- .../ippsTDESEncryptCBC.c} | 51 ++--- .../ippsTDESEncryptCFB.c} | 51 ++--- .../ippsTDESEncryptCTR.c} | 51 ++--- .../ippsTDESEncryptECB.c} | 51 ++--- .../ippsTDESEncryptOFB.c} | 51 ++--- .../ippsTRNGenRDSEED.c} | 51 ++--- .../ippsTRNGenRDSEED_BN.c} | 51 ++--- .../tcrypto/ipp/ipp_disp/ippcpsgx_disp00078.c | 91 --------- .../tcrypto/ipp/ipp_disp/ippcpsgx_disp00500.c | 91 --------- .../tcrypto/ipp/ipp_disp/ippcpsgx_disp00501.c | 91 --------- .../tcrypto/ipp/ipp_disp/ippcpsgx_disp00502.c | 91 --------- .../tcrypto/ipp/ipp_disp/ippcpsgx_disp00503.c | 91 --------- .../tcrypto/ipp/ipp_disp/ippcpsgx_disp00504.c | 91 --------- .../tcrypto/ipp/ipp_disp/ippcpsgx_disp00505.c | 91 --------- .../sgx_crypto_sys/tcrypto/ipp/sgx_sm2.cpp | 4 +- sgx_libc/sgx_tlibc_sys/tlibc/gen/sbrk.c | 5 + sgx_libc/sgx_tlibc_sys/tlibc/gen/spinlock.c | 21 +- .../tlibc/stdlib/aligned_alloc.c | 6 + sgx_libc/sgx_tlibc_sys/tlibc/stdlib/malloc.c | 6 +- sgx_libc/sgx_tlibc_sys/tlibc/string/memcpy.c | 67 ++++--- sgx_trts/src/aexnotify.rs | 58 ++++++ sgx_trts/src/arch.rs | 86 ++++++-- sgx_trts/src/asm/macro.S | 4 + sgx_trts/src/asm/mod.rs | 3 + sgx_trts/src/asm/pic.S | 30 +-- sgx_trts/src/call/ecall.rs | 9 + sgx_trts/src/call/ocall.rs | 7 + sgx_trts/src/call/ocalloc.rs | 17 +- sgx_trts/src/edmm/layout.rs | 8 + sgx_trts/src/enclave/entry.rs | 13 +- sgx_trts/src/enclave/mem.rs | 62 ++++++ sgx_trts/src/feature/sys.rs | 25 ++- sgx_trts/src/inst/hw/aexnotify.S | 59 ++++++ sgx_trts/src/inst/hw/inst.rs | 20 ++ sgx_trts/src/inst/hyper/aexnotify.S | 24 +++ sgx_trts/src/inst/hyper/inst.rs | 5 + sgx_trts/src/inst/sim/aexnotify.S | 24 +++ sgx_trts/src/inst/sim/inst.rs | 5 + sgx_trts/src/lib.rs | 4 +- sgx_trts/src/tcs/tc.rs | 2 + sgx_trts/src/veh/exception.rs | 189 +++++++++++++----- sgx_trts/src/veh/register.rs | 41 +++- sgx_trts/src/version.rs | 4 +- sgx_trts/src/xsave.rs | 6 + sgx_types/src/metadata.rs | 22 +- sgx_types/src/types/mod.rs | 6 +- sgx_types/src/types/switchless.rs | 10 +- sgx_urts/src/enclave/mod.rs | 4 +- 592 files changed, 14177 insertions(+), 16070 deletions(-) create mode 100644 common/inc/sgx_trts_aex.h create mode 100644 common/inc/tlibc/stdalign.h rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00000.c => intel64/ippcpGetLibVersion.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00026.c => intel64/ippsAESDecryptCBC.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00027.c => intel64/ippsAESDecryptCBC_CS1.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00028.c => intel64/ippsAESDecryptCBC_CS2.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00029.c => intel64/ippsAESDecryptCBC_CS3.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00031.c => intel64/ippsAESDecryptCFB.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00035.c => intel64/ippsAESDecryptCTR.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00021.c => intel64/ippsAESDecryptECB.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00033.c => intel64/ippsAESDecryptOFB.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00037.c => intel64/ippsAESDecryptXTS_Direct.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00022.c => intel64/ippsAESEncryptCBC.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00023.c => intel64/ippsAESEncryptCBC_CS1.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00024.c => intel64/ippsAESEncryptCBC_CS2.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00025.c => intel64/ippsAESEncryptCBC_CS3.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00030.c => intel64/ippsAESEncryptCFB.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00034.c => intel64/ippsAESEncryptCTR.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00020.c => intel64/ippsAESEncryptECB.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00032.c => intel64/ippsAESEncryptOFB.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00036.c => intel64/ippsAESEncryptXTS_Direct.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00015.c => intel64/ippsAESGetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00016.c => intel64/ippsAESInit.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00018.c => intel64/ippsAESPack.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00017.c => intel64/ippsAESSetKey.c} (71%) create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESSetupNoise.c rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00019.c => intel64/ippsAESUnpack.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00072.c => intel64/ippsAES_CCMDecrypt.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00071.c => intel64/ippsAES_CCMEncrypt.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00066.c => intel64/ippsAES_CCMGetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00073.c => intel64/ippsAES_CCMGetTag.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00067.c => intel64/ippsAES_CCMInit.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00068.c => intel64/ippsAES_CCMMessageLen.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00070.c => intel64/ippsAES_CCMStart.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00069.c => intel64/ippsAES_CCMTagLen.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00093.c => intel64/ippsAES_CMACFinal.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00090.c => intel64/ippsAES_CMACGetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00094.c => intel64/ippsAES_CMACGetTag.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00091.c => intel64/ippsAES_CMACInit.c} (69%) create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACSetupNoise.c rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00092.c => intel64/ippsAES_CMACUpdate.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00038.c => intel64/ippsAES_EncryptCFB16_MB.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00081.c => intel64/ippsAES_GCMDecrypt.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00080.c => intel64/ippsAES_GCMEncrypt.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00074.c => intel64/ippsAES_GCMGetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00082.c => intel64/ippsAES_GCMGetTag.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00075.c => intel64/ippsAES_GCMInit.c} (69%) create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMProcessAAD.c rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00077.c => intel64/ippsAES_GCMProcessIV.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00076.c => intel64/ippsAES_GCMReset.c} (72%) create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMSetupNoise.c rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00079.c => intel64/ippsAES_GCMStart.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00087.c => intel64/ippsAES_S2V_CMAC.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00089.c => intel64/ippsAES_SIVDecrypt.c} (64%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00088.c => intel64/ippsAES_SIVEncrypt.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00086.c => intel64/ippsAES_XTSDecrypt.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00085.c => intel64/ippsAES_XTSEncrypt.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00083.c => intel64/ippsAES_XTSGetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00084.c => intel64/ippsAES_XTSInit.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00095.c => intel64/ippsARCFourCheckKey.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00102.c => intel64/ippsARCFourDecrypt.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00101.c => intel64/ippsARCFourEncrypt.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00096.c => intel64/ippsARCFourGetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00097.c => intel64/ippsARCFourInit.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00099.c => intel64/ippsARCFourPack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00098.c => intel64/ippsARCFourReset.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00100.c => intel64/ippsARCFourUnpack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00247.c => intel64/ippsAdd_BN.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00238.c => intel64/ippsBigNumGetSize.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00239.c => intel64/ippsBigNumInit.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00240.c => intel64/ippsCmpZero_BN.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00241.c => intel64/ippsCmp_BN.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00001.c => intel64/ippsDESGetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00002.c => intel64/ippsDESInit.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00003.c => intel64/ippsDESPack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00004.c => intel64/ippsDESUnpack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00319.c => intel64/ippsDLGetResultString.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00328.c => intel64/ippsDLPGenKeyPair.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00337.c => intel64/ippsDLPGenerateDH.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00335.c => intel64/ippsDLPGenerateDSA.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00325.c => intel64/ippsDLPGet.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00327.c => intel64/ippsDLPGetDP.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00320.c => intel64/ippsDLPGetSize.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00321.c => intel64/ippsDLPInit.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00322.c => intel64/ippsDLPPack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00329.c => intel64/ippsDLPPublicKey.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00324.c => intel64/ippsDLPSet.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00326.c => intel64/ippsDLPSetDP.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00331.c => intel64/ippsDLPSetKeyPair.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00334.c => intel64/ippsDLPSharedSecretDH.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00332.c => intel64/ippsDLPSignDSA.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00323.c => intel64/ippsDLPUnpack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00338.c => intel64/ippsDLPValidateDH.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00336.c => intel64/ippsDLPValidateDSA.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00330.c => intel64/ippsDLPValidateKeyPair.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00333.c => intel64/ippsDLPVerifyDSA.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00251.c => intel64/ippsDiv_BN.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00339.c => intel64/ippsECCGetResultString.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00385.c => intel64/ippsECCPAddPoint.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00368.c => intel64/ippsECCPBindGxyTblStd192r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00369.c => intel64/ippsECCPBindGxyTblStd224r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00370.c => intel64/ippsECCPBindGxyTblStd256r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00371.c => intel64/ippsECCPBindGxyTblStd384r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00372.c => intel64/ippsECCPBindGxyTblStd521r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00373.c => intel64/ippsECCPBindGxyTblStdSM2.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00382.c => intel64/ippsECCPCheckPoint.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00383.c => intel64/ippsECCPComparePoint.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00387.c => intel64/ippsECCPGenKeyPair.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00374.c => intel64/ippsECCPGet.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00375.c => intel64/ippsECCPGetOrderBitSize.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00381.c => intel64/ippsECCPGetPoint.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00340.c => intel64/ippsECCPGetSize.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00341.c => intel64/ippsECCPGetSizeStd128r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00342.c => intel64/ippsECCPGetSizeStd128r2.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00343.c => intel64/ippsECCPGetSizeStd192r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00344.c => intel64/ippsECCPGetSizeStd224r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00345.c => intel64/ippsECCPGetSizeStd256r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00346.c => intel64/ippsECCPGetSizeStd384r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00347.c => intel64/ippsECCPGetSizeStd521r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00348.c => intel64/ippsECCPGetSizeStdSM2.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00349.c => intel64/ippsECCPInit.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00350.c => intel64/ippsECCPInitStd128r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00351.c => intel64/ippsECCPInitStd128r2.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00352.c => intel64/ippsECCPInitStd192r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00353.c => intel64/ippsECCPInitStd224r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00354.c => intel64/ippsECCPInitStd256r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00355.c => intel64/ippsECCPInitStd384r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00356.c => intel64/ippsECCPInitStd521r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00357.c => intel64/ippsECCPInitStdSM2.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00386.c => intel64/ippsECCPMulPointScalar.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00384.c => intel64/ippsECCPNegativePoint.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00377.c => intel64/ippsECCPPointGetSize.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00378.c => intel64/ippsECCPPointInit.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00388.c => intel64/ippsECCPPublicKey.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00358.c => intel64/ippsECCPSet.c} (64%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00390.c => intel64/ippsECCPSetKeyPair.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00379.c => intel64/ippsECCPSetPoint.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00380.c => intel64/ippsECCPSetPointAtInfinity.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00359.c => intel64/ippsECCPSetStd.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00360.c => intel64/ippsECCPSetStd128r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00361.c => intel64/ippsECCPSetStd128r2.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00362.c => intel64/ippsECCPSetStd192r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00363.c => intel64/ippsECCPSetStd224r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00364.c => intel64/ippsECCPSetStd256r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00365.c => intel64/ippsECCPSetStd384r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00366.c => intel64/ippsECCPSetStd521r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00367.c => intel64/ippsECCPSetStdSM2.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00391.c => intel64/ippsECCPSharedSecretDH.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00392.c => intel64/ippsECCPSharedSecretDHC.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00393.c => intel64/ippsECCPSignDSA.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00395.c => intel64/ippsECCPSignNR.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00397.c => intel64/ippsECCPSignSM2.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00376.c => intel64/ippsECCPValidate.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00389.c => intel64/ippsECCPValidateKeyPair.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00394.c => intel64/ippsECCPVerifyDSA.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00396.c => intel64/ippsECCPVerifyNR.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00398.c => intel64/ippsECCPVerifySM2.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00246.c => intel64/ippsExtGet_BN.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00441.c => intel64/ippsGFpAdd.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00446.c => intel64/ippsGFpAdd_PE.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00433.c => intel64/ippsGFpCmpElement.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00436.c => intel64/ippsGFpConj.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00430.c => intel64/ippsGFpCpyElement.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00493.c => intel64/ippsGFpECAddPoint.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00463.c => intel64/ippsGFpECBindGxyTblStd192r1.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00464.c => intel64/ippsGFpECBindGxyTblStd224r1.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00465.c => intel64/ippsGFpECBindGxyTblStd256r1.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00466.c => intel64/ippsGFpECBindGxyTblStd384r1.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00467.c => intel64/ippsGFpECBindGxyTblStd521r1.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00468.c => intel64/ippsGFpECBindGxyTblStdSM2.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00491.c => intel64/ippsGFpECCmpPoint.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00490.c => intel64/ippsGFpECCpyPoint.c} (70%) create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECDecryptSM2_Ext.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECDecryptSM2_Ext_DecMsgSize.c rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00512.c => intel64/ippsGFpECESDecrypt_SM2.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00511.c => intel64/ippsGFpECESEncrypt_SM2.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00513.c => intel64/ippsGFpECESFinal_SM2.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00514.c => intel64/ippsGFpECESGetBuffersSize_SM2.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00507.c => intel64/ippsGFpECESGetSize_SM2.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00508.c => intel64/ippsGFpECESInit_SM2.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00509.c => intel64/ippsGFpECESSetKey_SM2.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00510.c => intel64/ippsGFpECESStart_SM2.c} (72%) create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECEncryptSM2_Ext.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECEncryptSM2_Ext_EncMsgSize.c rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00469.c => intel64/ippsGFpECGet.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00506.c => intel64/ippsGFpECGetInfo_GF.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00484.c => intel64/ippsGFpECGetPoint.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00487.c => intel64/ippsGFpECGetPointOctString.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00485.c => intel64/ippsGFpECGetPointRegular.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00450.c => intel64/ippsGFpECGetSize.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00470.c => intel64/ippsGFpECGetSubgroup.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00451.c => intel64/ippsGFpECInit.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00454.c => intel64/ippsGFpECInitStd128r1.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00455.c => intel64/ippsGFpECInitStd128r2.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00456.c => intel64/ippsGFpECInitStd192r1.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00457.c => intel64/ippsGFpECInitStd224r1.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00458.c => intel64/ippsGFpECInitStd256r1.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00459.c => intel64/ippsGFpECInitStd384r1.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00460.c => intel64/ippsGFpECInitStd521r1.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00462.c => intel64/ippsGFpECInitStdBN256.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00461.c => intel64/ippsGFpECInitStdSM2.c} (70%) create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_Confirm.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_GetSize.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_Init.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_Setup.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_SharedKey.c rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00479.c => intel64/ippsGFpECMakePoint.c} (69%) create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECMessageRepresentationSM2.c rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00494.c => intel64/ippsGFpECMulPoint.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00492.c => intel64/ippsGFpECNegPoint.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00473.c => intel64/ippsGFpECPointGetSize.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00474.c => intel64/ippsGFpECPointInit.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00495.c => intel64/ippsGFpECPrivateKey.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00496.c => intel64/ippsGFpECPublicKey.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00471.c => intel64/ippsGFpECScratchBufferSize.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00452.c => intel64/ippsGFpECSet.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00476.c => intel64/ippsGFpECSetPoint.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00475.c => intel64/ippsGFpECSetPointAtInfinity.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00480.c => intel64/ippsGFpECSetPointHash.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00481.c => intel64/ippsGFpECSetPointHashBackCompatible.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00483.c => intel64/ippsGFpECSetPointHashBackCompatible_rmf.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00482.c => intel64/ippsGFpECSetPointHash_rmf.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00486.c => intel64/ippsGFpECSetPointOctString.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00478.c => intel64/ippsGFpECSetPointRandom.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00477.c => intel64/ippsGFpECSetPointRegular.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00453.c => intel64/ippsGFpECSetSubgroup.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00498.c => intel64/ippsGFpECSharedSecretDH.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00499.c => intel64/ippsGFpECSharedSecretDHC.c} (66%) create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSignDSA.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSignNR.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSignSM2.c rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00497.c => intel64/ippsGFpECTstKeyPair.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00488.c => intel64/ippsGFpECTstPoint.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00489.c => intel64/ippsGFpECTstPointInSubgroup.c} (68%) create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECUserIDHashSM2.c rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00472.c => intel64/ippsGFpECVerify.c} (70%) create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerifyDSA.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerifyNR.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerifySM2.c rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00422.c => intel64/ippsGFpElementGetSize.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00423.c => intel64/ippsGFpElementInit.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00444.c => intel64/ippsGFpExp.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00431.c => intel64/ippsGFpGetElement.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00432.c => intel64/ippsGFpGetElementOctString.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00449.c => intel64/ippsGFpGetInfo.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00399.c => intel64/ippsGFpGetSize.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00402.c => intel64/ippsGFpInit.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00400.c => intel64/ippsGFpInitArbitrary.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00401.c => intel64/ippsGFpInitFixed.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00438.c => intel64/ippsGFpInv.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00435.c => intel64/ippsGFpIsUnityElement.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00434.c => intel64/ippsGFpIsZeroElement.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00403.c => intel64/ippsGFpMethod_p192r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00404.c => intel64/ippsGFpMethod_p224r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00410.c => intel64/ippsGFpMethod_p256.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00409.c => intel64/ippsGFpMethod_p256bn.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00405.c => intel64/ippsGFpMethod_p256r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00408.c => intel64/ippsGFpMethod_p256sm2.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00406.c => intel64/ippsGFpMethod_p384r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00407.c => intel64/ippsGFpMethod_p521r1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00411.c => intel64/ippsGFpMethod_pArb.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00443.c => intel64/ippsGFpMul.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00448.c => intel64/ippsGFpMul_PE.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00445.c => intel64/ippsGFpMultiExp.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00437.c => intel64/ippsGFpNeg.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00421.c => intel64/ippsGFpScratchBufferSize.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00424.c => intel64/ippsGFpSetElement.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00428.c => intel64/ippsGFpSetElementHash.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00429.c => intel64/ippsGFpSetElementHash_rmf.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00426.c => intel64/ippsGFpSetElementOctString.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00427.c => intel64/ippsGFpSetElementRandom.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00425.c => intel64/ippsGFpSetElementRegular.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00440.c => intel64/ippsGFpSqr.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00439.c => intel64/ippsGFpSqrt.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00442.c => intel64/ippsGFpSub.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00447.c => intel64/ippsGFpSub_PE.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00412.c => intel64/ippsGFpxGetSize.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00413.c => intel64/ippsGFpxInit.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00414.c => intel64/ippsGFpxInitBinomial.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00419.c => intel64/ippsGFpxMethod_binom.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00417.c => intel64/ippsGFpxMethod_binom2.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00415.c => intel64/ippsGFpxMethod_binom2_epid2.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00418.c => intel64/ippsGFpxMethod_binom3.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00416.c => intel64/ippsGFpxMethod_binom3_epid2.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00420.c => intel64/ippsGFpxMethod_com.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00253.c => intel64/ippsGcd_BN.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00256.c => intel64/ippsGetOctString_BN.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00242.c => intel64/ippsGetSize_BN.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00244.c => intel64/ippsGet_BN.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00233.c => intel64/ippsHMACDuplicate_rmf.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00235.c => intel64/ippsHMACFinal_rmf.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00229.c => intel64/ippsHMACGetSize_rmf.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00236.c => intel64/ippsHMACGetTag_rmf.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00230.c => intel64/ippsHMACInit_rmf.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00237.c => intel64/ippsHMACMessage_rmf.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00231.c => intel64/ippsHMACPack_rmf.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00232.c => intel64/ippsHMACUnpack_rmf.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00234.c => intel64/ippsHMACUpdate_rmf.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00224.c => intel64/ippsHMAC_Duplicate.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00226.c => intel64/ippsHMAC_Final.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00220.c => intel64/ippsHMAC_GetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00227.c => intel64/ippsHMAC_GetTag.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00221.c => intel64/ippsHMAC_Init.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00228.c => intel64/ippsHMAC_Message.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00222.c => intel64/ippsHMAC_Pack.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00223.c => intel64/ippsHMAC_Unpack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00225.c => intel64/ippsHMAC_Update.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00170.c => intel64/ippsHashDuplicate.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00210.c => intel64/ippsHashDuplicate_rmf.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00173.c => intel64/ippsHashFinal.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00213.c => intel64/ippsHashFinal_rmf.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00216.c => intel64/ippsHashGetInfo_rmf.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00166.c => intel64/ippsHashGetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00206.c => intel64/ippsHashGetSize_rmf.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00172.c => intel64/ippsHashGetTag.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00212.c => intel64/ippsHashGetTag_rmf.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00167.c => intel64/ippsHashInit.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00207.c => intel64/ippsHashInit_rmf.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00174.c => intel64/ippsHashMessage.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00214.c => intel64/ippsHashMessage_rmf.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00215.c => intel64/ippsHashMethodGetInfo.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00190.c => intel64/ippsHashMethodGetSize.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00191.c => intel64/ippsHashMethodSet_MD5.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00193.c => intel64/ippsHashMethodSet_SHA1.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00194.c => intel64/ippsHashMethodSet_SHA1_NI.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00195.c => intel64/ippsHashMethodSet_SHA1_TT.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00199.c => intel64/ippsHashMethodSet_SHA224.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00200.c => intel64/ippsHashMethodSet_SHA224_NI.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00201.c => intel64/ippsHashMethodSet_SHA224_TT.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00196.c => intel64/ippsHashMethodSet_SHA256.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00197.c => intel64/ippsHashMethodSet_SHA256_NI.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00198.c => intel64/ippsHashMethodSet_SHA256_TT.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00203.c => intel64/ippsHashMethodSet_SHA384.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00202.c => intel64/ippsHashMethodSet_SHA512.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00205.c => intel64/ippsHashMethodSet_SHA512_224.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00204.c => intel64/ippsHashMethodSet_SHA512_256.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00192.c => intel64/ippsHashMethodSet_SM3.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00175.c => intel64/ippsHashMethod_MD5.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00177.c => intel64/ippsHashMethod_SHA1.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00178.c => intel64/ippsHashMethod_SHA1_NI.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00179.c => intel64/ippsHashMethod_SHA1_TT.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00183.c => intel64/ippsHashMethod_SHA224.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00184.c => intel64/ippsHashMethod_SHA224_NI.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00185.c => intel64/ippsHashMethod_SHA224_TT.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00180.c => intel64/ippsHashMethod_SHA256.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00181.c => intel64/ippsHashMethod_SHA256_NI.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00182.c => intel64/ippsHashMethod_SHA256_TT.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00187.c => intel64/ippsHashMethod_SHA384.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00186.c => intel64/ippsHashMethod_SHA512.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00189.c => intel64/ippsHashMethod_SHA512_224.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00188.c => intel64/ippsHashMethod_SHA512_256.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00176.c => intel64/ippsHashMethod_SM3.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00168.c => intel64/ippsHashPack.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00208.c => intel64/ippsHashPack_rmf.c} (70%) create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA224.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA224_NI.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA224_TT.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA256.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA256_NI.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA256_TT.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA384.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA512.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA512_224.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA512_256.c create mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SM3.c rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00169.c => intel64/ippsHashUnpack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00209.c => intel64/ippsHashUnpack_rmf.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00171.c => intel64/ippsHashUpdate.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00211.c => intel64/ippsHashUpdate_rmf.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00250.c => intel64/ippsMAC_BN_I.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00150.c => intel64/ippsMD5Duplicate.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00155.c => intel64/ippsMD5Final.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00148.c => intel64/ippsMD5GetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00154.c => intel64/ippsMD5GetTag.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00149.c => intel64/ippsMD5Init.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00156.c => intel64/ippsMD5MessageDigest.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00151.c => intel64/ippsMD5Pack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00152.c => intel64/ippsMD5Unpack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00153.c => intel64/ippsMD5Update.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00217.c => intel64/ippsMGF.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00218.c => intel64/ippsMGF1_rmf.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00219.c => intel64/ippsMGF2_rmf.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00254.c => intel64/ippsModInv_BN.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00252.c => intel64/ippsMod_BN.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00263.c => intel64/ippsMontExp.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00261.c => intel64/ippsMontForm.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00260.c => intel64/ippsMontGet.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00257.c => intel64/ippsMontGetSize.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00258.c => intel64/ippsMontInit.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00262.c => intel64/ippsMontMul.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00259.c => intel64/ippsMontSet.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00249.c => intel64/ippsMul_BN.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00270.c => intel64/ippsPRNGGetSeed.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00264.c => intel64/ippsPRNGGetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00265.c => intel64/ippsPRNGInit.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00268.c => intel64/ippsPRNGSetAugment.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00267.c => intel64/ippsPRNGSetH0.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00266.c => intel64/ippsPRNGSetModulus.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00269.c => intel64/ippsPRNGSetSeed.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00271.c => intel64/ippsPRNGen.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00273.c => intel64/ippsPRNGenRDRAND.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00274.c => intel64/ippsPRNGenRDRAND_BN.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00272.c => intel64/ippsPRNGen_BN.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00279.c => intel64/ippsPrimeGen.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00281.c => intel64/ippsPrimeGen_BN.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00283.c => intel64/ippsPrimeGet.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00277.c => intel64/ippsPrimeGetSize.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00284.c => intel64/ippsPrimeGet_BN.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00278.c => intel64/ippsPrimeInit.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00285.c => intel64/ippsPrimeSet.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00286.c => intel64/ippsPrimeSet_BN.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00280.c => intel64/ippsPrimeTest.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00282.c => intel64/ippsPrimeTest_BN.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00306.c => intel64/ippsRSADecrypt_OAEP.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00308.c => intel64/ippsRSADecrypt_OAEP_rmf.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00310.c => intel64/ippsRSADecrypt_PKCSv15.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00305.c => intel64/ippsRSAEncrypt_OAEP.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00307.c => intel64/ippsRSAEncrypt_OAEP_rmf.c} (64%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00309.c => intel64/ippsRSAEncrypt_PKCSv15.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00315.c => intel64/ippsRSASign_PKCS1v15.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00317.c => intel64/ippsRSASign_PKCS1v15_rmf.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00311.c => intel64/ippsRSASign_PSS.c} (64%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00313.c => intel64/ippsRSASign_PSS_rmf.c} (64%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00316.c => intel64/ippsRSAVerify_PKCS1v15.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00318.c => intel64/ippsRSAVerify_PKCS1v15_rmf.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00312.c => intel64/ippsRSAVerify_PSS.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00314.c => intel64/ippsRSAVerify_PSS_rmf.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00302.c => intel64/ippsRSA_Decrypt.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00301.c => intel64/ippsRSA_Encrypt.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00303.c => intel64/ippsRSA_GenerateKeys.c} (62%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00300.c => intel64/ippsRSA_GetBufferSizePrivateKey.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00299.c => intel64/ippsRSA_GetBufferSizePublicKey.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00294.c => intel64/ippsRSA_GetPrivateKeyType1.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00298.c => intel64/ippsRSA_GetPrivateKeyType2.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00290.c => intel64/ippsRSA_GetPublicKey.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00291.c => intel64/ippsRSA_GetSizePrivateKeyType1.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00295.c => intel64/ippsRSA_GetSizePrivateKeyType2.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00287.c => intel64/ippsRSA_GetSizePublicKey.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00292.c => intel64/ippsRSA_InitPrivateKeyType1.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00296.c => intel64/ippsRSA_InitPrivateKeyType2.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00288.c => intel64/ippsRSA_InitPublicKey.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00293.c => intel64/ippsRSA_SetPrivateKeyType1.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00297.c => intel64/ippsRSA_SetPrivateKeyType2.c} (64%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00289.c => intel64/ippsRSA_SetPublicKey.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00304.c => intel64/ippsRSA_ValidateKeys.c} (62%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00245.c => intel64/ippsRef_BN.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00105.c => intel64/ippsSHA1Duplicate.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00110.c => intel64/ippsSHA1Final.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00103.c => intel64/ippsSHA1GetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00109.c => intel64/ippsSHA1GetTag.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00104.c => intel64/ippsSHA1Init.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00111.c => intel64/ippsSHA1MessageDigest.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00106.c => intel64/ippsSHA1Pack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00107.c => intel64/ippsSHA1Unpack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00108.c => intel64/ippsSHA1Update.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00114.c => intel64/ippsSHA224Duplicate.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00119.c => intel64/ippsSHA224Final.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00112.c => intel64/ippsSHA224GetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00118.c => intel64/ippsSHA224GetTag.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00113.c => intel64/ippsSHA224Init.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00120.c => intel64/ippsSHA224MessageDigest.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00115.c => intel64/ippsSHA224Pack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00116.c => intel64/ippsSHA224Unpack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00117.c => intel64/ippsSHA224Update.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00123.c => intel64/ippsSHA256Duplicate.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00128.c => intel64/ippsSHA256Final.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00121.c => intel64/ippsSHA256GetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00127.c => intel64/ippsSHA256GetTag.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00122.c => intel64/ippsSHA256Init.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00129.c => intel64/ippsSHA256MessageDigest.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00124.c => intel64/ippsSHA256Pack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00125.c => intel64/ippsSHA256Unpack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00126.c => intel64/ippsSHA256Update.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00132.c => intel64/ippsSHA384Duplicate.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00137.c => intel64/ippsSHA384Final.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00130.c => intel64/ippsSHA384GetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00136.c => intel64/ippsSHA384GetTag.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00131.c => intel64/ippsSHA384Init.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00138.c => intel64/ippsSHA384MessageDigest.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00133.c => intel64/ippsSHA384Pack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00134.c => intel64/ippsSHA384Unpack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00135.c => intel64/ippsSHA384Update.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00141.c => intel64/ippsSHA512Duplicate.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00146.c => intel64/ippsSHA512Final.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00139.c => intel64/ippsSHA512GetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00145.c => intel64/ippsSHA512GetTag.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00140.c => intel64/ippsSHA512Init.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00147.c => intel64/ippsSHA512MessageDigest.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00142.c => intel64/ippsSHA512Pack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00143.c => intel64/ippsSHA512Unpack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00144.c => intel64/ippsSHA512Update.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00159.c => intel64/ippsSM3Duplicate.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00164.c => intel64/ippsSM3Final.c} (72%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00157.c => intel64/ippsSM3GetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00163.c => intel64/ippsSM3GetTag.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00158.c => intel64/ippsSM3Init.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00165.c => intel64/ippsSM3MessageDigest.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00160.c => intel64/ippsSM3Pack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00161.c => intel64/ippsSM3Unpack.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00162.c => intel64/ippsSM3Update.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00048.c => intel64/ippsSMS4DecryptCBC.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00049.c => intel64/ippsSMS4DecryptCBC_CS1.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00050.c => intel64/ippsSMS4DecryptCBC_CS2.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00051.c => intel64/ippsSMS4DecryptCBC_CS3.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00053.c => intel64/ippsSMS4DecryptCFB.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00057.c => intel64/ippsSMS4DecryptCTR.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00043.c => intel64/ippsSMS4DecryptECB.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00055.c => intel64/ippsSMS4DecryptOFB.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00044.c => intel64/ippsSMS4EncryptCBC.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00045.c => intel64/ippsSMS4EncryptCBC_CS1.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00046.c => intel64/ippsSMS4EncryptCBC_CS2.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00047.c => intel64/ippsSMS4EncryptCBC_CS3.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00052.c => intel64/ippsSMS4EncryptCFB.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00056.c => intel64/ippsSMS4EncryptCTR.c} (67%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00042.c => intel64/ippsSMS4EncryptECB.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00054.c => intel64/ippsSMS4EncryptOFB.c} (68%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00039.c => intel64/ippsSMS4GetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00040.c => intel64/ippsSMS4Init.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00041.c => intel64/ippsSMS4SetKey.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00064.c => intel64/ippsSMS4_CCMDecrypt.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00063.c => intel64/ippsSMS4_CCMEncrypt.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00058.c => intel64/ippsSMS4_CCMGetSize.c} (73%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00065.c => intel64/ippsSMS4_CCMGetTag.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00059.c => intel64/ippsSMS4_CCMInit.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00060.c => intel64/ippsSMS4_CCMMessageLen.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00062.c => intel64/ippsSMS4_CCMStart.c} (69%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00061.c => intel64/ippsSMS4_CCMTagLen.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00255.c => intel64/ippsSetOctString_BN.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00243.c => intel64/ippsSet_BN.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00248.c => intel64/ippsSub_BN.c} (70%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00008.c => intel64/ippsTDESDecryptCBC.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00010.c => intel64/ippsTDESDecryptCFB.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00014.c => intel64/ippsTDESDecryptCTR.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00006.c => intel64/ippsTDESDecryptECB.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00012.c => intel64/ippsTDESDecryptOFB.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00007.c => intel64/ippsTDESEncryptCBC.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00009.c => intel64/ippsTDESEncryptCFB.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00013.c => intel64/ippsTDESEncryptCTR.c} (65%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00005.c => intel64/ippsTDESEncryptECB.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00011.c => intel64/ippsTDESEncryptOFB.c} (66%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00275.c => intel64/ippsTRNGenRDSEED.c} (71%) rename sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/{ippcpsgx_disp00276.c => intel64/ippsTRNGenRDSEED_BN.c} (70%) delete mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00078.c delete mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00500.c delete mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00501.c delete mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00502.c delete mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00503.c delete mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00504.c delete mode 100644 sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00505.c create mode 100644 sgx_libc/sgx_tlibc_sys/tlibc/stdlib/aligned_alloc.c create mode 100644 sgx_trts/src/aexnotify.rs create mode 100644 sgx_trts/src/inst/hw/aexnotify.S create mode 100644 sgx_trts/src/inst/hyper/aexnotify.S create mode 100644 sgx_trts/src/inst/sim/aexnotify.S diff --git a/common/inc/internal/arch.h b/common/inc/internal/arch.h index 14585ad64..1d44e6271 100644 --- a/common/inc/internal/arch.h +++ b/common/inc/internal/arch.h @@ -99,7 +99,7 @@ flags definitions typedef struct _tcs_t { uint64_t reserved0; /* (0) */ - uint64_t flags; /* (8)bit 0: DBGOPTION */ + uint64_t flags; /* (8)bit 0: DBGOPTION, bit 1: AEXNOTIFY */ uint64_t ossa; /* (16)State Save Area */ uint32_t cssa; /* (24)Current SSA slot */ uint32_t nssa; /* (28)Number of SSA slots */ @@ -131,10 +131,14 @@ typedef struct _exit_info_t #define SE_VECTOR_BP 3 #define SE_VECTOR_BR 5 #define SE_VECTOR_UD 6 +#define SE_VECTOR_GP 13 +#define SE_VECTOR_PF 14 #define SE_VECTOR_MF 16 #define SE_VECTOR_AC 17 #define SE_VECTOR_XM 19 +#define SSA_AEXNOTIFY_MASK 0x1U /* Only set the first bit */ + typedef struct _ssa_gpr_t { REGISTER( ax); /* (0) */ @@ -153,16 +157,26 @@ typedef struct _ssa_gpr_t uint64_t r13; /* (104) */ uint64_t r14; /* (112) */ uint64_t r15; /* (120) */ - REGISTER(flags); /* (128) */ - REGISTER( ip); /* (136) */ - REGISTER( sp_u); /* (144) untrusted stack pointer. saved by EENTER */ - REGISTER( bp_u); /* (152) untrusted frame pointer. saved by EENTER */ + REGISTER(flags); /* (128) */ + REGISTER( ip); /* (136) */ + REGISTER( sp_u); /* (144) untrusted stack pointer. saved by EENTER */ + REGISTER( bp_u); /* (152) untrusted frame pointer. saved by EENTER */ exit_info_t exit_info; /* (160) contain information for exits */ - uint32_t reserved; /* (164) padding to multiple of 8 bytes */ + uint8_t reserved[3]; /* (164) padding */ + uint8_t aex_notify; /* (167) AEX Notify */ uint64_t fs; /* (168) FS register */ uint64_t gs; /* (176) GS register */ } ssa_gpr_t; +typedef struct _misc_exinfo +{ + uint64_t maddr; // address for #PF, #GP. + uint32_t errcd; + uint32_t reserved; +} misc_exinfo_t; + +#define MISC_BYTE_SIZE sizeof(misc_exinfo_t) + typedef uint64_t si_flags_t; #define SI_FLAG_NONE 0x0 diff --git a/common/inc/internal/inst.h b/common/inc/internal/inst.h index 4f2b35756..e7baa7959 100644 --- a/common/inc/internal/inst.h +++ b/common/inc/internal/inst.h @@ -46,7 +46,10 @@ typedef enum { SE_ERESUME, SE_EEXIT, SE_EACCEPT, + SE_EMODPE, + SE_EACCEPTCOPY, SE_EVERIFYREPORT2 = 0x8, + SE_EDECCSSA = 0x9, SE_LAST_RING3, SE_ECREATE = 0x0, diff --git a/common/inc/internal/metadata.h b/common/inc/internal/metadata.h index 1968576c2..303052f7c 100644 --- a/common/inc/internal/metadata.h +++ b/common/inc/internal/metadata.h @@ -36,10 +36,10 @@ #pragma pack(1) /* version of metadata */ -#define MAJOR_VERSION 2 //MAJOR_VERSION should not larger than 0ffffffff -#define MINOR_VERSION 4 //MINOR_VERSION should not larger than 0ffffffff +#define MAJOR_VERSION 3 //MAJOR_VERSION should not larger than 0ffffffff +#define MINOR_VERSION 0 //MINOR_VERSION should not larger than 0ffffffff -#define SGX_2_ELRANGE_MAJOR_VERSION 12 +#define SGX_2_ELRANGE_MAJOR_VERSION 13 #define SGX_1_ELRANGE_MAJOR_VERSION 11 #define SGX_MAJOR_VERSION_GAP 10 @@ -71,18 +71,17 @@ #define TCS_POLICY_BIND 0x00000000 /* If set, the TCS is bound to the application thread */ #define TCS_POLICY_UNBIND 0x00000001 -#define MAX_SAVE_BUF_SIZE 2632 - #define TCS_NUM_MIN 1 #define SSA_NUM_MIN 2 #define SSA_FRAME_SIZE_MIN 1 -#define SSA_FRAME_SIZE_MAX 2 +#define SSA_FRAME_SIZE_MAX 4 #define STACK_SIZE_MIN 0x0002000 /* 8 KB */ #define STACK_SIZE_MAX 0x0040000 /* 256 KB */ #define HEAP_SIZE_MIN 0x0001000 /* 4 KB */ #define HEAP_SIZE_MAX 0x1000000 /* 16 MB */ #define RSRV_SIZE_MIN 0x0000000 /* 0 KB */ #define RSRV_SIZE_MAX 0x0000000 /* 0 KB */ +#define USER_REGION_SIZE 0x0000000 /* 0 KB */ #define DEFAULT_MISC_SELECT 0 #define DEFAULT_MISC_MASK 0xFFFFFFFF #define ISVFAMILYID_MAX 0xFFFFFFFFFFFFFFFFULL @@ -127,6 +126,7 @@ typedef enum #define LAYOUT_ID_RSRV_MIN (20) #define LAYOUT_ID_RSRV_INIT (21) #define LAYOUT_ID_RSRV_MAX (22) +#define LAYOUT_ID_USER_REGION (23) extern const char * layout_id_str[]; diff --git a/common/inc/sgx_attributes.h b/common/inc/sgx_attributes.h index 4f5e18008..b9be439cf 100644 --- a/common/inc/sgx_attributes.h +++ b/common/inc/sgx_attributes.h @@ -40,16 +40,20 @@ #define SGX_FLAGS_MODE64BIT 0x0000000000000004ULL /* If set, then the enclave is 64 bit */ #define SGX_FLAGS_PROVISION_KEY 0x0000000000000010ULL /* If set, then the enclave has access to provision key */ #define SGX_FLAGS_EINITTOKEN_KEY 0x0000000000000020ULL /* If set, then the enclave has access to EINITTOKEN key */ -#define SGX_FLAGS_KSS 0x0000000000000080ULL /* If set enclave uses KSS */ +#define SGX_FLAGS_KSS 0x0000000000000080ULL /* If set, then the enclave uses KSS */ +#define SGX_FLAGS_AEX_NOTIFY 0x0000000000000400ULL /* If set, then the enclave enables AEX Notify */ + +#define SGX_FLAGS_NON_CHECK_BITS 0x00FF000000000000ULL /* BIT[55-48] will not be checked */ /* XSAVE Feature Request Mask */ #define SGX_XFRM_LEGACY 0x0000000000000003ULL /* Legacy XFRM which includes the basic feature bits required by SGX, x87 state(0x01) and SSE state(0x02) */ #define SGX_XFRM_AVX 0x0000000000000006ULL /* AVX XFRM which includes AVX state(0x04) and SSE state(0x02) required by AVX */ -#define SGX_XFRM_AVX512 0x00000000000000E6ULL /* AVX-512 XFRM - not supported */ +#define SGX_XFRM_AVX512 0x00000000000000E6ULL /* AVX-512 XFRM */ #define SGX_XFRM_MPX 0x0000000000000018ULL /* MPX XFRM - not supported */ #define SGX_XFRM_PKRU 0x0000000000000200ULL /* PKRU state */ +#define SGX_XFRM_AMX 0x0000000000060000ULL /* AMX XFRM, including XTILEDATA(0x40000) and XTILECFG(0x20000) */ -#define SGX_XFRM_RESERVED (~(SGX_XFRM_LEGACY | SGX_XFRM_AVX | SGX_XFRM_AVX512 | SGX_XFRM_PKRU)) +#define SGX_XFRM_RESERVED (~(SGX_XFRM_LEGACY | SGX_XFRM_AVX | SGX_XFRM_AVX512 | SGX_XFRM_PKRU | SGX_XFRM_AMX)) typedef struct _attributes_t { @@ -57,7 +61,9 @@ typedef struct _attributes_t uint64_t xfrm; } sgx_attributes_t; -/* define MISCSELECT - all bits are currently reserved */ +/* Define MISCSELECT + * bit 0: EXINFO + * bit 31-1: reserved(0) */ typedef uint32_t sgx_misc_select_t; typedef struct _sgx_misc_attribute_t { diff --git a/common/inc/sgx_tprotected_fs.h b/common/inc/sgx_tprotected_fs.h index cd90b921a..568387b8f 100644 --- a/common/inc/sgx_tprotected_fs.h +++ b/common/inc/sgx_tprotected_fs.h @@ -107,6 +107,28 @@ SGX_FILE* SGXAPI sgx_fopen_auto_key(const char* filename, const char* mode); */ SGX_FILE* SGXAPI sgx_fopen_integrity_only(const char* filename, const char* mode); +/* sgx_fopen_ex + * Purpose: Expert version of sgx_fopen/sgx_fopen_auto_key which is used if you want to control the internal `cache size`. + * The specified `cache size` must be page (4KB by default) aligned. + * Note that `sgx_fexport_auto_key` and `sgx_fimport_auto_key` don't support configuring `cache_size` right now + * + * Parameters: + * filename - [IN] the name of the file to open/create. + * mode - [IN] open mode. only supports 'r' or 'w' or 'a' (one and only one of them must be present), and optionally 'b' and/or '+'. + * key - [IN] encryption key that will be used for the file encryption. + * If it's NULL, we will swtich back to `sgx_fopen_auto_key and use enclave's seal key to protect the file + * NOTE - the key is actually used as a KDK (key derivation key) and only for the meta-data node, and not used directly for the encryption of any part of the file + * this is important in order to prevent hitting the key wear-out problem, and some other issues with GCM encryptions using the same key + * cache_size - [IN] Internal cache size in byte, which used to cache R/W data in enclave before flush to actual file + * It must larger than default cache size (192KB), and must be page (4KB by default) aligned + * a) Please make sure enclave heap is enough for the `cache`, e.g. Configure enough heap in enclave config file + * b) All the data in cache may lost after exeception, please try to call `sgx_fflush` explicitly to avoid data loss + * + * Return value: + * SGX_FILE* - pointer to the newly created file handle, NULL if an error occurred - check errno for the error code. +*/ +SGX_FILE* SGXAPI sgx_fopen_ex(const char* filename, const char* mode, const sgx_key_128bit_t *key, const uint16_t key_policy, const uint64_t cache_size); + /* sgx_fwrite * Purpose: write data to a file (see c++ fwrite documentation for more details). * @@ -276,7 +298,7 @@ int32_t SGXAPI sgx_fexport_auto_key(const char* filename, sgx_key_128bit_t *key) * Return value: * int32_t - result, 0 - success, 1 - there was an error, check errno for the error code */ -int32_t SGXAPI sgx_fimport_auto_key(const char* filename, const sgx_key_128bit_t *key); +int32_t SGXAPI sgx_fimport_auto_key(const char* filename, const sgx_key_128bit_t *key, const uint16_t key_policy); /* sgx_fclear_cache @@ -316,7 +338,7 @@ int32_t SGXAPI sgx_fget_mac(SGX_FILE* stream, sgx_aes_gcm_128bit_tag_t* mac); * Return value: * int32_t - result, 0 - success, -1 - there was an error, check sgx_ferror for error code */ -int32_t SGXAPI sgx_rename_meta(SGX_FILE* stream, const char* old_name, const char* new_name); +int32_t SGXAPI sgx_frename(SGX_FILE* stream, const char* old_name, const char* new_name); #ifdef __cplusplus } diff --git a/common/inc/sgx_trts_aex.h b/common/inc/sgx_trts_aex.h new file mode 100644 index 000000000..ea28ffc0a --- /dev/null +++ b/common/inc/sgx_trts_aex.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2011-2021 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: sgx_trts_aex.h + * Description: + * Header file for aex notify handling APIs. + */ + +#ifndef _SGX_TRTS_AEX_H_ +#define _SGX_TRTS_AEX_H_ + +#include +#include +#include "sgx_defs.h" +#include "sgx_trts_exception.h" +#include "sgx_error.h" + +typedef void (*sgx_aex_mitigation_fn_t)(const sgx_exception_info_t *info, const void * args); + +typedef struct _aex_mitigation_node_t +{ + sgx_aex_mitigation_fn_t handler; + const void *args; + struct _aex_mitigation_node_t * next; +} sgx_aex_mitigation_node_t; + + +#ifdef __cplusplus +extern "C" { +#endif + +/* sgx_set_ssa_aexnotify() + * Parameters: + * flag - 0 to disable AEX-Notify + * non-zero to enable AEX-Notify + * Return Value: + * SGX_SUCCESS - success + * SGX_ERROR_UNEXPECTED - unexpected error + */ +sgx_status_t SGXAPI sgx_set_ssa_aexnotify(int flag); + + +/* sgx_register_aex_handler() + * Parameters: + * aex_node - A pointer to an AEX mitigation node. The mitigation node must exist and be valid until it is unregistered. + * handler - A function handler to call after being notified of an AEX + * args - Arguments to pass to the handler + * Return Value: + * SGX_SUCCESS - success + * SGX_ERROR_INVALID_PARAMETER - aex_node or handler are NULL + */ +sgx_status_t SGXAPI sgx_register_aex_handler(sgx_aex_mitigation_node_t *aex_node, sgx_aex_mitigation_fn_t handler, const void *args); + +/* sgx_unregister_aex_handler() + * Parameters: + * handler - A function handler that was previously registered + * Return Value: + * SGX_SUCCESS - success + * SGX_ERROR_INVALID_PARAMETER - handler was NULL or has not been previously registered + * SGX_ERROR_UNEXPECTED - There currently are no registered handlers + */ +sgx_status_t SGXAPI sgx_unregister_aex_handler(sgx_aex_mitigation_fn_t handler); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/common/inc/sgx_trts_exception.h b/common/inc/sgx_trts_exception.h index c47dccca9..6990f55ae 100644 --- a/common/inc/sgx_trts_exception.h +++ b/common/inc/sgx_trts_exception.h @@ -106,11 +106,29 @@ typedef struct _cpu_context_t } sgx_cpu_context_t; #endif +typedef struct _exinfo_t +{ + uint64_t faulting_address; + uint32_t error_code; + uint32_t reserved; +}sgx_misc_exinfo_t; + + __attribute__((aligned(64))) typedef struct _exception_info_t { sgx_cpu_context_t cpu_context; sgx_exception_vector_t exception_vector; sgx_exception_type_t exception_type; + sgx_misc_exinfo_t exinfo; + uint32_t exception_valid; + uint32_t do_aex_mitigation; + uint64_t xsave_size; +#if defined (_M_X64) || defined (__x86_64__) + uint64_t reserved[1]; +#else + uint64_t reserved[6]; +#endif + uint8_t xsave_area[0]; // 64-byte aligned } sgx_exception_info_t; typedef int (*sgx_exception_handler_t)(sgx_exception_info_t *info); diff --git a/common/inc/tlibc/stdalign.h b/common/inc/tlibc/stdalign.h new file mode 100644 index 000000000..380a0f1c2 --- /dev/null +++ b/common/inc/tlibc/stdalign.h @@ -0,0 +1,14 @@ +#ifndef _STDALIGN_H +#define _STDALIGN_H +#ifndef __cplusplus +/* this whole header only works in C11 or with compiler extensions */ +#if __STDC_VERSION__ < 201112L && defined( __GNUC__) +#define _Alignas(t) __attribute__((__aligned__(t))) +#define _Alignof(t) __alignof__(t) +#endif +#define alignas _Alignas +#define alignof _Alignof +#endif +#define __alignas_is_defined 1 +#define __alignof_is_defined 1 +#endif diff --git a/common/inc/tlibc/stdlib.h b/common/inc/tlibc/stdlib.h index b4019e6e9..9e839fd5f 100644 --- a/common/inc/tlibc/stdlib.h +++ b/common/inc/tlibc/stdlib.h @@ -99,6 +99,8 @@ long _TLIBC_CDECL_ labs(long); ldiv_t _TLIBC_CDECL_ ldiv(long, long); void * _TLIBC_CDECL_ malloc(size_t); void * _TLIBC_CDECL_ memalign(size_t, size_t); +int _TLIBC_CDECL_ posix_memalign(void **, size_t, size_t); +void * _TLIBC_CDECL_ aligned_alloc(size_t, size_t); void _TLIBC_CDECL_ qsort(void *, size_t, size_t, int (*)(const void *, const void *)); void * _TLIBC_CDECL_ realloc(void *, size_t); double _TLIBC_CDECL_ strtod(const char *, char **); diff --git a/sgx_build_helper/download_prebuilt/download_prebuilt.sh b/sgx_build_helper/download_prebuilt/download_prebuilt.sh index 22fcfdc75..613acf1c4 100755 --- a/sgx_build_helper/download_prebuilt/download_prebuilt.sh +++ b/sgx_build_helper/download_prebuilt/download_prebuilt.sh @@ -20,9 +20,9 @@ set -e # change this on every release -optlibs_name=optimized_libs_2.17.tar.gz -checksum_file_name=SHA256SUM_prebuilt_2.17.cfg -server_url_path=https://download.01.org/intel-sgx/sgx-linux/2.17 +optlibs_name=optimized_libs_2.20.tar.gz +checksum_file_name=SHA256SUM_prebuilt_2.20.cfg +server_url_path=https://download.01.org/intel-sgx/sgx-linux/2.20 # unlikely to change unless opt lib structure changes top_dir=$(dirname "$(realpath "$0")") diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/Makefile b/sgx_crypto/sgx_crypto_sys/tcrypto/Makefile index f99e2e98d..d4c1b6865 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/Makefile +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/Makefile @@ -77,7 +77,7 @@ CFLAGS += $(CPPFLAGS) $(ENCLAVE_CFLAGS) $(SGX_COMMON_FLAGS) -Werror -fno-excepti OBJ += sgx_tcrypto_common.o sgx_rsa_internal.o SRCDIR := ipp -DISPDIR := $(SRCDIR)/ipp_disp +DISPDIR := $(SRCDIR)/ipp_disp/intel64 LIB_NAME := libsgx_tcrypto_ipp.a diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00000.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippcpGetLibVersion.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00000.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippcpGetLibVersion.c index af7275142..fe4bb3f3f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00000.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippcpGetLibVersion.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppLibraryVersion*, y8_ippcpGetLibVersion, (void) ) -IPPAPI( const IppLibraryVersion*, l9_ippcpGetLibVersion, (void) ) IPPAPI( const IppLibraryVersion*, k1_ippcpGetLibVersion, (void) ) +IPPAPI( const IppLibraryVersion*, l9_ippcpGetLibVersion, (void) ) +IPPAPI( const IppLibraryVersion*, y8_ippcpGetLibVersion, (void) ) -IPPFUN( const IppLibraryVersion*,sgx_disp_ippcpGetLibVersion, (void) ) +IPPFUN( const IppLibraryVersion*, sgx_disp_ippcpGetLibVersion, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippcpGetLibVersion( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippcpGetLibVersion( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippcpGetLibVersion( ); - } else + } 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 )) { - return h9_ippcpGetLibVersion( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippcpGetLibVersion( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00026.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCBC.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00026.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCBC.c index 8640f4a2f..ff36a5999 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00026.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCBC.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESDecryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESDecryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESDecryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsAESDecryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESDecryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00027.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCBC_CS1.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00027.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCBC_CS1.c index 8a877c9a1..45701bffc 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00027.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCBC_CS1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESDecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESDecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESDecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESDecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsAESDecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESDecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00028.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCBC_CS2.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00028.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCBC_CS2.c index f38b6d528..0c0a6b7c7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00028.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCBC_CS2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESDecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESDecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESDecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESDecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsAESDecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESDecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00029.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCBC_CS3.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00029.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCBC_CS3.c index eaf668f64..bd1256849 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00029.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCBC_CS3.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESDecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESDecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESDecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESDecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsAESDecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESDecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00031.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCFB.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00031.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCFB.c index b389dc67f..08f5b9e6b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00031.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCFB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsAESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00035.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCTR.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00035.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCTR.c index 364e1cea2..ee3edd2ea 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00035.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptCTR.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESDecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESDecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESDecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESDecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else + } 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 )) { - return h9_ippsAESDecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESDecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00021.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptECB.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00021.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptECB.c index feaba5884..66bb3701a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00021.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptECB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESDecryptECB( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESDecryptECB( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESDecryptECB( pSrc, pDst, len, pCtx ); - } else + } 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 )) { - return h9_ippsAESDecryptECB( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESDecryptECB( pSrc, pDst, len, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00033.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptOFB.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00033.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptOFB.c index 4c679a138..8724414c4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00033.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptOFB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESDecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsAESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00037.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptXTS_Direct.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00037.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptXTS_Direct.c index 871e32805..a8bf50ebb 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00037.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESDecryptXTS_Direct.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESDecryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESDecryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESDecryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); - } else + } 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 )) { - return h9_ippsAESDecryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESDecryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00022.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCBC.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00022.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCBC.c index cbc25d5e0..6d7ae7985 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00022.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCBC.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESEncryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESEncryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESEncryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsAESEncryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESEncryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00023.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCBC_CS1.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00023.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCBC_CS1.c index 9518854fb..8691fa94a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00023.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCBC_CS1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESEncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESEncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESEncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESEncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsAESEncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESEncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00024.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCBC_CS2.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00024.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCBC_CS2.c index 5b108febe..293f64551 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00024.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCBC_CS2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESEncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESEncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESEncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESEncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsAESEncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESEncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00025.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCBC_CS3.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00025.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCBC_CS3.c index 7c1c38365..a88d463d3 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00025.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCBC_CS3.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESEncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESEncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESEncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESEncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsAESEncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESEncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00030.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCFB.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00030.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCFB.c index 11eba7dfb..1a664f91e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00030.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCFB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsAESSpec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsAESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00034.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCTR.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00034.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCTR.c index c764963fb..a0b318416 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00034.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptCTR.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESEncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESEncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESEncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESEncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else + } 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 )) { - return h9_ippsAESEncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESEncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00020.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptECB.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00020.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptECB.c index f04fb4f9a..071d7f559 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00020.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptECB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsAESSpec* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESEncryptECB( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESEncryptECB( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESEncryptECB( pSrc, pDst, len, pCtx ); - } else + } 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 )) { - return h9_ippsAESEncryptECB( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESEncryptECB( pSrc, pDst, len, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00032.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptOFB.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00032.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptOFB.c index 4adf930f1..b1cca949f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00032.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptOFB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAESEncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsAESSpec* pCtx, Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsAESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00036.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptXTS_Direct.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00036.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptXTS_Direct.c index 94cd95a3c..089bbf9fd 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00036.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESEncryptXTS_Direct.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESEncryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESEncryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESEncryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); - } else + } 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 )) { - return h9_ippsAESEncryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESEncryptXTS_Direct( pSrc, pDst, encBitsize, aesBlkNo, pTweakPT, pKey, keyBitsize, dataUnitBitsize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00015.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESGetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00015.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESGetSize.c index 6fb991355..5f2f2e5be 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00015.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAESGetSize,(int *pSize)) -IPPAPI(IppStatus, l9_ippsAESGetSize,(int *pSize)) IPPAPI(IppStatus, k1_ippsAESGetSize,(int *pSize)) +IPPAPI(IppStatus, l9_ippsAESGetSize,(int *pSize)) +IPPAPI(IppStatus, y8_ippsAESGetSize,(int *pSize)) -IPPFUN(IppStatus,sgx_disp_ippsAESGetSize,(int *pSize)) +IPPFUN(IppStatus, sgx_disp_ippsAESGetSize,(int *pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESGetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESGetSize( pSize ); - } else + } 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 )) { - return h9_ippsAESGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESGetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00016.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESInit.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00016.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESInit.c index 0d6634592..1eafc8180 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00016.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsAESInit,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx, int ctxSize)) +IPPAPI(IppStatus, l9_ippsAESInit,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx, int ctxSize)) +IPPAPI(IppStatus, y8_ippsAESInit,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx, int ctxSize)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESInit( pKey, keyLen, pCtx, ctxSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESInit( pKey, keyLen, pCtx, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESInit( pKey, keyLen, pCtx, ctxSize ); - } else + } 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 )) { - return h9_ippsAESInit( pKey, keyLen, pCtx, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESInit( pKey, keyLen, pCtx, ctxSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00018.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESPack.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00018.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESPack.c index 2b6feed3d..eb016f608 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00018.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESPack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int bufSize)) -IPPAPI(IppStatus, l9_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int bufSize)) IPPAPI(IppStatus, k1_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, l9_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, y8_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int bufSize)) -IPPFUN(IppStatus,sgx_disp_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPFUN(IppStatus, sgx_disp_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int bufSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESPack( pCtx, pBuffer, bufSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESPack( pCtx, pBuffer, bufSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESPack( pCtx, pBuffer, bufSize ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int bufSize)) -IPPAPI(IppStatus, h9_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int bufSize)) - -IPPFUN(IppStatus,sgx_disp_ippsAESPack,(const IppsAESSpec* pCtx, Ipp8u* pBuffer, int bufSize)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsAESPack( pCtx, pBuffer, bufSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESPack( pCtx, pBuffer, bufSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00017.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESSetKey.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00017.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESSetKey.c index 02f6c6383..ed5903b24 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00017.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESSetKey.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAESSetKey,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx)) -IPPAPI(IppStatus, l9_ippsAESSetKey,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx)) IPPAPI(IppStatus, k1_ippsAESSetKey,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx)) +IPPAPI(IppStatus, l9_ippsAESSetKey,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx)) +IPPAPI(IppStatus, y8_ippsAESSetKey,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsAESSetKey,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsAESSetKey,(const Ipp8u* pKey, int keyLen, IppsAESSpec* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESSetKey( pKey, keyLen, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESSetKey( pKey, keyLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESSetKey( pKey, keyLen, pCtx ); - } else + } 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 )) { - return h9_ippsAESSetKey( pKey, keyLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESSetKey( pKey, keyLen, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESSetupNoise.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESSetupNoise.c new file mode 100644 index 000000000..166c24e36 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESSetupNoise.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsAESSetupNoise,(Ipp32u noiseLevel, IppsAESSpec* pCtx)) +IPPAPI(IppStatus, l9_ippsAESSetupNoise,(Ipp32u noiseLevel, IppsAESSpec* pCtx)) +IPPAPI(IppStatus, y8_ippsAESSetupNoise,(Ipp32u noiseLevel, IppsAESSpec* pCtx)) + +IPPFUN(IppStatus, sgx_disp_ippsAESSetupNoise,(Ipp32u noiseLevel, IppsAESSpec* pCtx)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsAESSetupNoise( noiseLevel, pCtx ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsAESSetupNoise( noiseLevel, pCtx ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsAESSetupNoise( noiseLevel, pCtx ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00019.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESUnpack.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00019.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESUnpack.c index 8daa3eff7..9dff7b8ad 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00019.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAESUnpack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAESUnpack,(const Ipp8u* pBuffer, IppsAESSpec* pCtx, int ctxSize)) -IPPAPI(IppStatus, l9_ippsAESUnpack,(const Ipp8u* pBuffer, IppsAESSpec* pCtx, int ctxSize)) IPPAPI(IppStatus, k1_ippsAESUnpack,(const Ipp8u* pBuffer, IppsAESSpec* pCtx, int ctxSize)) +IPPAPI(IppStatus, l9_ippsAESUnpack,(const Ipp8u* pBuffer, IppsAESSpec* pCtx, int ctxSize)) +IPPAPI(IppStatus, y8_ippsAESUnpack,(const Ipp8u* pBuffer, IppsAESSpec* pCtx, int ctxSize)) -IPPFUN(IppStatus,sgx_disp_ippsAESUnpack,(const Ipp8u* pBuffer, IppsAESSpec* pCtx, int ctxSize)) +IPPFUN(IppStatus, sgx_disp_ippsAESUnpack,(const Ipp8u* pBuffer, IppsAESSpec* pCtx, int ctxSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAESUnpack( pBuffer, pCtx, ctxSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAESUnpack( pBuffer, pCtx, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAESUnpack( pBuffer, pCtx, ctxSize ); - } else + } 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 )) { - return h9_ippsAESUnpack( pBuffer, pCtx, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAESUnpack( pBuffer, pCtx, ctxSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00072.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMDecrypt.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00072.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMDecrypt.c index f64003477..1354e65ce 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00072.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMDecrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) -IPPAPI(IppStatus, l9_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) IPPAPI(IppStatus, k1_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) +IPPAPI(IppStatus, y8_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) +IPPFUN(IppStatus, sgx_disp_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_CCMDecrypt( pSrc, pDst, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_CCMDecrypt( pSrc, pDst, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_CCMDecrypt( pSrc, pDst, len, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) -IPPAPI(IppStatus, h9_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsAES_CCMDecrypt( pSrc, pDst, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_CCMDecrypt( pSrc, pDst, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00071.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMEncrypt.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00071.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMEncrypt.c index c4c657517..26ccc56cf 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00071.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMEncrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) -IPPAPI(IppStatus, l9_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) IPPAPI(IppStatus, k1_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) +IPPAPI(IppStatus, y8_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) +IPPFUN(IppStatus, sgx_disp_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_CCMEncrypt( pSrc, pDst, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_CCMEncrypt( pSrc, pDst, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_CCMEncrypt( pSrc, pDst, len, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) -IPPAPI(IppStatus, h9_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_CCMState* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsAES_CCMEncrypt( pSrc, pDst, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_CCMEncrypt( pSrc, pDst, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00066.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMGetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00066.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMGetSize.c index 2efa0843a..17657fa30 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00066.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_CCMGetSize,(int* pSize)) -IPPAPI(IppStatus, l9_ippsAES_CCMGetSize,(int* pSize)) IPPAPI(IppStatus, k1_ippsAES_CCMGetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsAES_CCMGetSize,(int* pSize)) +IPPAPI(IppStatus, y8_ippsAES_CCMGetSize,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMGetSize,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsAES_CCMGetSize,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_CCMGetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_CCMGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_CCMGetSize( pSize ); - } else + } 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 )) { - return h9_ippsAES_CCMGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_CCMGetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00073.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMGetTag.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00073.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMGetTag.c index f7d008f15..24f213836 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00073.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMGetTag.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pState)) -IPPAPI(IppStatus, l9_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pState)) IPPAPI(IppStatus, k1_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pState)) +IPPAPI(IppStatus, y8_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pState)) -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pState)) +IPPFUN(IppStatus, sgx_disp_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_CCMGetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_CCMGetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_CCMGetTag( pTag, tagLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pState)) -IPPAPI(IppStatus, h9_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsAES_CCMState* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsAES_CCMGetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_CCMGetTag( pTag, tagLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00067.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMInit.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00067.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMInit.c index 6f6319064..ab83f2288 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00067.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pState, int ctxSize)) -IPPAPI(IppStatus, l9_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pState, int ctxSize)) IPPAPI(IppStatus, k1_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pState, int ctxSize)) +IPPAPI(IppStatus, l9_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pState, int ctxSize)) +IPPAPI(IppStatus, y8_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pState, int ctxSize)) -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pState, int ctxSize)) +IPPFUN(IppStatus, sgx_disp_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pState, int ctxSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_CCMInit( pKey, keyLen, pState, ctxSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_CCMInit( pKey, keyLen, pState, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_CCMInit( pKey, keyLen, pState, ctxSize ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pState, int ctxSize)) -IPPAPI(IppStatus, h9_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pState, int ctxSize)) - -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_CCMState* pState, int ctxSize)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsAES_CCMInit( pKey, keyLen, pState, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_CCMInit( pKey, keyLen, pState, ctxSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00068.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMMessageLen.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00068.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMMessageLen.c index 41674960d..15d72dce7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00068.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMMessageLen.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pState)) -IPPAPI(IppStatus, l9_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pState)) IPPAPI(IppStatus, k1_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pState)) +IPPAPI(IppStatus, y8_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pState)) -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pState)) +IPPFUN(IppStatus, sgx_disp_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_CCMMessageLen( msgLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_CCMMessageLen( msgLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_CCMMessageLen( msgLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pState)) -IPPAPI(IppStatus, h9_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMMessageLen,(Ipp64u msgLen, IppsAES_CCMState* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsAES_CCMMessageLen( msgLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_CCMMessageLen( msgLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00070.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMStart.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00070.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMStart.c index ee61d86b0..e6d525988 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00070.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMStart.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pState)) -IPPAPI(IppStatus, l9_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pState)) IPPAPI(IppStatus, k1_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pState)) +IPPAPI(IppStatus, y8_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pState)) -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pState)) +IPPFUN(IppStatus, sgx_disp_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_CCMStart( pIV, ivLen, pAD, adLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_CCMStart( pIV, ivLen, pAD, adLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_CCMStart( pIV, ivLen, pAD, adLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pState)) -IPPAPI(IppStatus, h9_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsAES_CCMState* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsAES_CCMStart( pIV, ivLen, pAD, adLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_CCMStart( pIV, ivLen, pAD, adLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00069.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMTagLen.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00069.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMTagLen.c index e4d144b98..a8d729bb6 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00069.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CCMTagLen.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pState)) -IPPAPI(IppStatus, l9_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pState)) IPPAPI(IppStatus, k1_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pState)) +IPPAPI(IppStatus, y8_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pState)) -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pState)) +IPPFUN(IppStatus, sgx_disp_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_CCMTagLen( tagLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_CCMTagLen( tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_CCMTagLen( tagLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pState)) -IPPAPI(IppStatus, h9_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsAES_CCMTagLen,(int tagLen, IppsAES_CCMState* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsAES_CCMTagLen( tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_CCMTagLen( tagLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00093.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACFinal.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00093.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACFinal.c index 2998da092..fcac840ec 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00093.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACFinal.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pState)) -IPPAPI(IppStatus, l9_ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pState)) IPPAPI(IppStatus, k1_ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pState)) +IPPAPI(IppStatus, l9_ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pState)) +IPPAPI(IppStatus, y8_ippsAES_CMACFinal,(Ipp8u* pMD, int mdLen, IppsAES_CMACState* pState)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_CMACFinal( pMD, mdLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_CMACFinal( pMD, mdLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_CMACFinal( pMD, mdLen, pState ); - } else + } 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 )) { - return h9_ippsAES_CMACFinal( pMD, mdLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_CMACFinal( pMD, mdLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00090.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACGetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00090.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACGetSize.c index 35fe89b82..7dd0ef21d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00090.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_CMACGetSize,(int* pSize)) -IPPAPI(IppStatus, l9_ippsAES_CMACGetSize,(int* pSize)) IPPAPI(IppStatus, k1_ippsAES_CMACGetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsAES_CMACGetSize,(int* pSize)) +IPPAPI(IppStatus, y8_ippsAES_CMACGetSize,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsAES_CMACGetSize,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsAES_CMACGetSize,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_CMACGetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_CMACGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_CMACGetSize( pSize ); - } else + } 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 )) { - return h9_ippsAES_CMACGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_CMACGetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00094.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACGetTag.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00094.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACGetTag.c index dba8be557..6e44435ed 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00094.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACGetTag.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsAES_CMACGetTag,(Ipp8u* pMD, int mdLen, const IppsAES_CMACState* pState)) +IPPAPI(IppStatus, l9_ippsAES_CMACGetTag,(Ipp8u* pMD, int mdLen, const IppsAES_CMACState* pState)) +IPPAPI(IppStatus, y8_ippsAES_CMACGetTag,(Ipp8u* pMD, int mdLen, const IppsAES_CMACState* pState)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_CMACGetTag( pMD, mdLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_CMACGetTag( pMD, mdLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_CMACGetTag( pMD, mdLen, pState ); - } else + } 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 )) { - return h9_ippsAES_CMACGetTag( pMD, mdLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_CMACGetTag( pMD, mdLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00091.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACInit.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00091.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACInit.c index 89539adb7..3a6fbd3be 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00091.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAES_CMACInit,(const Ipp8u* pKey, int keyLen, IppsAES_CMACState* pState, int ctxSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_CMACInit( pKey, keyLen, pState, ctxSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_CMACInit( pKey, keyLen, pState, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_CMACInit( pKey, keyLen, pState, ctxSize ); - } else + } 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 )) { - return h9_ippsAES_CMACInit( pKey, keyLen, pState, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_CMACInit( pKey, keyLen, pState, ctxSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACSetupNoise.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACSetupNoise.c new file mode 100644 index 000000000..4ad9b1b60 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACSetupNoise.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsAES_CMACSetupNoise,(Ipp32u noiseLevel, IppsAES_CMACState* pState)) +IPPAPI(IppStatus, l9_ippsAES_CMACSetupNoise,(Ipp32u noiseLevel, IppsAES_CMACState* pState)) +IPPAPI(IppStatus, y8_ippsAES_CMACSetupNoise,(Ipp32u noiseLevel, IppsAES_CMACState* pState)) + +IPPFUN(IppStatus, sgx_disp_ippsAES_CMACSetupNoise,(Ipp32u noiseLevel, IppsAES_CMACState* pState)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsAES_CMACSetupNoise( noiseLevel, pState ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsAES_CMACSetupNoise( noiseLevel, pState ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsAES_CMACSetupNoise( noiseLevel, pState ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00092.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACUpdate.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00092.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACUpdate.c index 69ca6e259..addc2b229 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00092.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_CMACUpdate.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsAES_CMACUpdate,(const Ipp8u* pSrc, int len, IppsAES_CMACState* pState)) +IPPAPI(IppStatus, l9_ippsAES_CMACUpdate,(const Ipp8u* pSrc, int len, IppsAES_CMACState* pState)) +IPPAPI(IppStatus, y8_ippsAES_CMACUpdate,(const Ipp8u* pSrc, int len, IppsAES_CMACState* pState)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_CMACUpdate( pSrc, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_CMACUpdate( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_CMACUpdate( pSrc, len, pState ); - } else + } 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 )) { - return h9_ippsAES_CMACUpdate( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_CMACUpdate( pSrc, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00038.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_EncryptCFB16_MB.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00038.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_EncryptCFB16_MB.c index 47fac89d2..588d85cfb 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00038.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_EncryptCFB16_MB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_EncryptCFB16_MB, (const Ipp8u* pSrc[], Ipp8u* pDst[], int len[], const IppsAESSpec* pCtx[], const Ipp8u* pIV[], IppStatus status[], int numBuffers)) -IPPAPI(IppStatus, l9_ippsAES_EncryptCFB16_MB, (const Ipp8u* pSrc[], Ipp8u* pDst[], int len[], const IppsAESSpec* pCtx[], const Ipp8u* pIV[], IppStatus status[], int numBuffers)) IPPAPI(IppStatus, k1_ippsAES_EncryptCFB16_MB, (const Ipp8u* pSrc[], Ipp8u* pDst[], int len[], const IppsAESSpec* pCtx[], const Ipp8u* pIV[], IppStatus status[], int numBuffers)) +IPPAPI(IppStatus, l9_ippsAES_EncryptCFB16_MB, (const Ipp8u* pSrc[], Ipp8u* pDst[], int len[], const IppsAESSpec* pCtx[], const Ipp8u* pIV[], IppStatus status[], int numBuffers)) +IPPAPI(IppStatus, y8_ippsAES_EncryptCFB16_MB, (const Ipp8u* pSrc[], Ipp8u* pDst[], int len[], const IppsAESSpec* pCtx[], const Ipp8u* pIV[], IppStatus status[], int numBuffers)) -IPPFUN(IppStatus,sgx_disp_ippsAES_EncryptCFB16_MB, (const Ipp8u* pSrc[], Ipp8u* pDst[], int len[], const IppsAESSpec* pCtx[], const Ipp8u* pIV[], IppStatus status[], int numBuffers)) +IPPFUN(IppStatus, sgx_disp_ippsAES_EncryptCFB16_MB, (const Ipp8u* pSrc[], Ipp8u* pDst[], int len[], const IppsAESSpec* pCtx[], const Ipp8u* pIV[], IppStatus status[], int numBuffers)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_EncryptCFB16_MB( pSrc, pDst, len, pCtx, pIV, status, numBuffers ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_EncryptCFB16_MB( pSrc, pDst, len, pCtx, pIV, status, numBuffers ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_EncryptCFB16_MB( pSrc, pDst, len, pCtx, pIV, status, numBuffers ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsAES_EncryptCFB16_MB, (const Ipp8u* pSrc[], Ipp8u* pDst[], int len[], const IppsAESSpec* pCtx[], const Ipp8u* pIV[], IppStatus status[], int numBuffers)) -IPPAPI(IppStatus, h9_ippsAES_EncryptCFB16_MB, (const Ipp8u* pSrc[], Ipp8u* pDst[], int len[], const IppsAESSpec* pCtx[], const Ipp8u* pIV[], IppStatus status[], int numBuffers)) - -IPPFUN(IppStatus,sgx_disp_ippsAES_EncryptCFB16_MB, (const Ipp8u* pSrc[], Ipp8u* pDst[], int len[], const IppsAESSpec* pCtx[], const Ipp8u* pIV[], IppStatus status[], int numBuffers)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsAES_EncryptCFB16_MB( pSrc, pDst, len, pCtx, pIV, status, numBuffers ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_EncryptCFB16_MB( pSrc, pDst, len, pCtx, pIV, status, numBuffers ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00081.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMDecrypt.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00081.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMDecrypt.c index a70b6c340..fc11d7249 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00081.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMDecrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAES_GCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_GCMDecrypt( pSrc, pDst, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_GCMDecrypt( pSrc, pDst, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_GCMDecrypt( pSrc, pDst, len, pState ); - } else + } 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 )) { - return h9_ippsAES_GCMDecrypt( pSrc, pDst, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_GCMDecrypt( pSrc, pDst, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00080.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMEncrypt.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00080.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMEncrypt.c index fdbc59710..ee71f6fdb 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00080.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMEncrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAES_GCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsAES_GCMState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_GCMEncrypt( pSrc, pDst, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_GCMEncrypt( pSrc, pDst, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_GCMEncrypt( pSrc, pDst, len, pState ); - } else + } 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 )) { - return h9_ippsAES_GCMEncrypt( pSrc, pDst, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_GCMEncrypt( pSrc, pDst, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00074.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMGetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00074.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMGetSize.c index 86540a114..80f0b3b17 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00074.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_GCMGetSize,(int * pSize)) -IPPAPI(IppStatus, l9_ippsAES_GCMGetSize,(int * pSize)) IPPAPI(IppStatus, k1_ippsAES_GCMGetSize,(int * pSize)) +IPPAPI(IppStatus, l9_ippsAES_GCMGetSize,(int * pSize)) +IPPAPI(IppStatus, y8_ippsAES_GCMGetSize,(int * pSize)) -IPPFUN(IppStatus,sgx_disp_ippsAES_GCMGetSize,(int * pSize)) +IPPFUN(IppStatus, sgx_disp_ippsAES_GCMGetSize,(int * pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_GCMGetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_GCMGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_GCMGetSize( pSize ); - } else + } 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 )) { - return h9_ippsAES_GCMGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_GCMGetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00082.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMGetTag.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00082.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMGetTag.c index 058fc1c2f..9d03d278a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00082.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMGetTag.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsAES_GCMGetTag,(Ipp8u* pDstTag, int tagLen, const IppsAES_GCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_GCMGetTag,(Ipp8u* pDstTag, int tagLen, const IppsAES_GCMState* pState)) +IPPAPI(IppStatus, y8_ippsAES_GCMGetTag,(Ipp8u* pDstTag, int tagLen, const IppsAES_GCMState* pState)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_GCMGetTag( pDstTag, tagLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_GCMGetTag( pDstTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_GCMGetTag( pDstTag, tagLen, pState ); - } else + } 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 )) { - return h9_ippsAES_GCMGetTag( pDstTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_GCMGetTag( pDstTag, tagLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00075.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMInit.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00075.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMInit.c index 71a2f67da..f31d1cb9b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00075.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAES_GCMInit,(const Ipp8u* pKey, int keyLen, IppsAES_GCMState* pState, int ctxSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_GCMInit( pKey, keyLen, pState, ctxSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_GCMInit( pKey, keyLen, pState, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_GCMInit( pKey, keyLen, pState, ctxSize ); - } else + } 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 )) { - return h9_ippsAES_GCMInit( pKey, keyLen, pState, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_GCMInit( pKey, keyLen, pState, ctxSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMProcessAAD.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMProcessAAD.c new file mode 100644 index 000000000..2a4bd0201 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMProcessAAD.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsAES_GCMProcessAAD,(const Ipp8u* pAAD, int aadLen, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_GCMProcessAAD,(const Ipp8u* pAAD, int aadLen, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, y8_ippsAES_GCMProcessAAD,(const Ipp8u* pAAD, int aadLen, IppsAES_GCMState* pState)) + +IPPFUN(IppStatus, sgx_disp_ippsAES_GCMProcessAAD,(const Ipp8u* pAAD, int aadLen, IppsAES_GCMState* pState)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsAES_GCMProcessAAD( pAAD, aadLen, pState ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsAES_GCMProcessAAD( pAAD, aadLen, pState ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsAES_GCMProcessAAD( pAAD, aadLen, pState ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00077.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMProcessIV.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00077.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMProcessIV.c index be6a5523d..63788a8d5 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00077.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMProcessIV.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsAES_GCMProcessIV,(const Ipp8u* pIV, int ivLen, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_GCMProcessIV,(const Ipp8u* pIV, int ivLen, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, y8_ippsAES_GCMProcessIV,(const Ipp8u* pIV, int ivLen, IppsAES_GCMState* pState)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_GCMProcessIV( pIV, ivLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_GCMProcessIV( pIV, ivLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_GCMProcessIV( pIV, ivLen, pState ); - } else + } 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 )) { - return h9_ippsAES_GCMProcessIV( pIV, ivLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_GCMProcessIV( pIV, ivLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00076.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMReset.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00076.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMReset.c index 110b8d7dc..a50a1f7b7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00076.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMReset.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_GCMReset,(IppsAES_GCMState* pState)) -IPPAPI(IppStatus, l9_ippsAES_GCMReset,(IppsAES_GCMState* pState)) IPPAPI(IppStatus, k1_ippsAES_GCMReset,(IppsAES_GCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_GCMReset,(IppsAES_GCMState* pState)) +IPPAPI(IppStatus, y8_ippsAES_GCMReset,(IppsAES_GCMState* pState)) -IPPFUN(IppStatus,sgx_disp_ippsAES_GCMReset,(IppsAES_GCMState* pState)) +IPPFUN(IppStatus, sgx_disp_ippsAES_GCMReset,(IppsAES_GCMState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_GCMReset( pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_GCMReset( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_GCMReset( pState ); - } else + } 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 )) { - return h9_ippsAES_GCMReset( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_GCMReset( pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMSetupNoise.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMSetupNoise.c new file mode 100644 index 000000000..78fb4728d --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMSetupNoise.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsAES_GCMSetupNoise,(Ipp32u noiseLevel, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, l9_ippsAES_GCMSetupNoise,(Ipp32u noiseLevel, IppsAES_GCMState* pState)) +IPPAPI(IppStatus, y8_ippsAES_GCMSetupNoise,(Ipp32u noiseLevel, IppsAES_GCMState* pState)) + +IPPFUN(IppStatus, sgx_disp_ippsAES_GCMSetupNoise,(Ipp32u noiseLevel, IppsAES_GCMState* pState)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsAES_GCMSetupNoise( noiseLevel, pState ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsAES_GCMSetupNoise( noiseLevel, pState ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsAES_GCMSetupNoise( noiseLevel, pState ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00079.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMStart.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00079.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMStart.c index 3f5fb2f9d..606080f30 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00079.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_GCMStart.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAES_GCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAAD, int aadLen, IppsAES_GCMState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_GCMStart( pIV, ivLen, pAAD, aadLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_GCMStart( pIV, ivLen, pAAD, aadLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_GCMStart( pIV, ivLen, pAAD, aadLen, pState ); - } else + } 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 )) { - return h9_ippsAES_GCMStart( pIV, ivLen, pAAD, aadLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_GCMStart( pIV, ivLen, pAAD, aadLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00087.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_S2V_CMAC.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00087.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_S2V_CMAC.c index 2225165aa..ef349cd9d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00087.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_S2V_CMAC.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_S2V_CMAC( pKey, keyLen, pAD, pADlen, numAD, pV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_S2V_CMAC( pKey, keyLen, pAD, pADlen, numAD, pV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_S2V_CMAC( pKey, keyLen, pAD, pADlen, numAD, pV ); - } else + } 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 )) { - return h9_ippsAES_S2V_CMAC( pKey, keyLen, pAD, pADlen, numAD, pV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_S2V_CMAC( pKey, keyLen, pAD, pADlen, numAD, pV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00089.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_SIVDecrypt.c similarity index 64% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00089.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_SIVDecrypt.c index e63b28193..03d5f5d9b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00089.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_SIVDecrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +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)) -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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_SIVDecrypt( pSrc, pDst, len, pAuthPassed, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD, pSIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_SIVDecrypt( pSrc, pDst, len, pAuthPassed, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD, pSIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_SIVDecrypt( pSrc, pDst, len, pAuthPassed, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD, pSIV ); - } else + } 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 )) { - return h9_ippsAES_SIVDecrypt( pSrc, pDst, len, pAuthPassed, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD, pSIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_SIVDecrypt( pSrc, pDst, len, pAuthPassed, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD, pSIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00088.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_SIVEncrypt.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00088.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_SIVEncrypt.c index c2fd7088c..04f19a4fb 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00088.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_SIVEncrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +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)) -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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_SIVEncrypt( pSrc, pDst, len, pSIV, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_SIVEncrypt( pSrc, pDst, len, pSIV, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_SIVEncrypt( pSrc, pDst, len, pSIV, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD ); - } else + } 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 )) { - return h9_ippsAES_SIVEncrypt( pSrc, pDst, len, pSIV, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_SIVEncrypt( pSrc, pDst, len, pSIV, pAuthKey, pConfKey, keyLen, pAD, pADlen, numAD ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00086.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_XTSDecrypt.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00086.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_XTSDecrypt.c index f4db2a5e8..6691d14b1 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00086.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_XTSDecrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_XTSDecrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_XTSDecrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_XTSDecrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); - } else + } 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 )) { - return h9_ippsAES_XTSDecrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_XTSDecrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00085.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_XTSEncrypt.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00085.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_XTSEncrypt.c index 2f7d35da7..01d7ed02b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00085.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_XTSEncrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_XTSEncrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_XTSEncrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_XTSEncrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); - } else + } 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 )) { - return h9_ippsAES_XTSEncrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_XTSEncrypt( pSrc, pDst, bitSizeLen, pCtx, pTweak, startCipherBlkNo ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00083.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_XTSGetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00083.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_XTSGetSize.c index 04c5b16e6..16340b3c9 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00083.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_XTSGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAES_XTSGetSize,(int * pSize)) -IPPAPI(IppStatus, l9_ippsAES_XTSGetSize,(int * pSize)) IPPAPI(IppStatus, k1_ippsAES_XTSGetSize,(int * pSize)) +IPPAPI(IppStatus, l9_ippsAES_XTSGetSize,(int * pSize)) +IPPAPI(IppStatus, y8_ippsAES_XTSGetSize,(int * pSize)) -IPPFUN(IppStatus,sgx_disp_ippsAES_XTSGetSize,(int * pSize)) +IPPFUN(IppStatus, sgx_disp_ippsAES_XTSGetSize,(int * pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_XTSGetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_XTSGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_XTSGetSize( pSize ); - } else + } 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 )) { - return h9_ippsAES_XTSGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_XTSGetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00084.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_XTSInit.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00084.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_XTSInit.c index 7f3556102..f4d2c3d90 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00084.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAES_XTSInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsAES_XTSInit,(const Ipp8u* pKey, int keyLen, int duBitsize, IppsAES_XTSSpec* pCtx,int ctxSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAES_XTSInit( pKey, keyLen, duBitsize, pCtx, ctxSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAES_XTSInit( pKey, keyLen, duBitsize, pCtx, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAES_XTSInit( pKey, keyLen, duBitsize, pCtx, ctxSize ); - } else + } 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 )) { - return h9_ippsAES_XTSInit( pKey, keyLen, duBitsize, pCtx, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_XTSInit( pKey, keyLen, duBitsize, pCtx, ctxSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00095.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourCheckKey.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00095.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourCheckKey.c index 8d9e2d37d..d1ca7f2e1 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00095.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourCheckKey.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsARCFourCheckKey, (const Ipp8u *pKey, int keyLen, IppBool* pIsWeak)) -IPPAPI(IppStatus, l9_ippsARCFourCheckKey, (const Ipp8u *pKey, int keyLen, IppBool* pIsWeak)) IPPAPI(IppStatus, k1_ippsARCFourCheckKey, (const Ipp8u *pKey, int keyLen, IppBool* pIsWeak)) +IPPAPI(IppStatus, l9_ippsARCFourCheckKey, (const Ipp8u *pKey, int keyLen, IppBool* pIsWeak)) +IPPAPI(IppStatus, y8_ippsARCFourCheckKey, (const Ipp8u *pKey, int keyLen, IppBool* pIsWeak)) -IPPFUN(IppStatus,sgx_disp_ippsARCFourCheckKey, (const Ipp8u *pKey, int keyLen, IppBool* pIsWeak)) +IPPFUN(IppStatus, sgx_disp_ippsARCFourCheckKey, (const Ipp8u *pKey, int keyLen, IppBool* pIsWeak)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsARCFourCheckKey( pKey, keyLen, pIsWeak ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsARCFourCheckKey( pKey, keyLen, pIsWeak ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsARCFourCheckKey( pKey, keyLen, pIsWeak ); - } else + } 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 )) { - return h9_ippsARCFourCheckKey( pKey, keyLen, pIsWeak ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsARCFourCheckKey( pKey, keyLen, pIsWeak ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00102.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourDecrypt.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00102.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourDecrypt.c index 4d80ae7c2..0715e5e5a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00102.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourDecrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsARCFourDecrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) +IPPAPI(IppStatus, l9_ippsARCFourDecrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) +IPPAPI(IppStatus, y8_ippsARCFourDecrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsARCFourDecrypt( pSrc, pDst, length, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsARCFourDecrypt( pSrc, pDst, length, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsARCFourDecrypt( pSrc, pDst, length, pCtx ); - } else + } 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 )) { - return h9_ippsARCFourDecrypt( pSrc, pDst, length, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsARCFourDecrypt( pSrc, pDst, length, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00101.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourEncrypt.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00101.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourEncrypt.c index 0dbb41523..d079366f4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00101.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourEncrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsARCFourEncrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) +IPPAPI(IppStatus, l9_ippsARCFourEncrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) +IPPAPI(IppStatus, y8_ippsARCFourEncrypt, (const Ipp8u *pSrc, Ipp8u *pDst, int length, IppsARCFourState *pCtx)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsARCFourEncrypt( pSrc, pDst, length, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsARCFourEncrypt( pSrc, pDst, length, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsARCFourEncrypt( pSrc, pDst, length, pCtx ); - } else + } 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 )) { - return h9_ippsARCFourEncrypt( pSrc, pDst, length, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsARCFourEncrypt( pSrc, pDst, length, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00096.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourGetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00096.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourGetSize.c index 8bb94204c..9f0306049 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00096.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsARCFourGetSize, (int* pSize)) -IPPAPI(IppStatus, l9_ippsARCFourGetSize, (int* pSize)) IPPAPI(IppStatus, k1_ippsARCFourGetSize, (int* pSize)) +IPPAPI(IppStatus, l9_ippsARCFourGetSize, (int* pSize)) +IPPAPI(IppStatus, y8_ippsARCFourGetSize, (int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsARCFourGetSize, (int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsARCFourGetSize, (int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsARCFourGetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsARCFourGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsARCFourGetSize( pSize ); - } else + } 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 )) { - return h9_ippsARCFourGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsARCFourGetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00097.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourInit.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00097.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourInit.c index 085c66e70..5a22c25b0 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00097.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsARCFourInit, (const Ipp8u *pKey, int keyLen, IppsARCFourState *pCtx)) -IPPAPI(IppStatus, l9_ippsARCFourInit, (const Ipp8u *pKey, int keyLen, IppsARCFourState *pCtx)) IPPAPI(IppStatus, k1_ippsARCFourInit, (const Ipp8u *pKey, int keyLen, IppsARCFourState *pCtx)) +IPPAPI(IppStatus, l9_ippsARCFourInit, (const Ipp8u *pKey, int keyLen, IppsARCFourState *pCtx)) +IPPAPI(IppStatus, y8_ippsARCFourInit, (const Ipp8u *pKey, int keyLen, IppsARCFourState *pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsARCFourInit, (const Ipp8u *pKey, int keyLen, IppsARCFourState *pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsARCFourInit, (const Ipp8u *pKey, int keyLen, IppsARCFourState *pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsARCFourInit( pKey, keyLen, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsARCFourInit( pKey, keyLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsARCFourInit( pKey, keyLen, pCtx ); - } else + } 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 )) { - return h9_ippsARCFourInit( pKey, keyLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsARCFourInit( pKey, keyLen, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00099.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourPack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00099.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourPack.c index 1d7a5e179..259394916 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00099.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourPack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsARCFourPack,(const IppsARCFourState* pCtx, Ipp8u* pBuffer)) -IPPAPI(IppStatus, l9_ippsARCFourPack,(const IppsARCFourState* pCtx, Ipp8u* pBuffer)) IPPAPI(IppStatus, k1_ippsARCFourPack,(const IppsARCFourState* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsARCFourPack,(const IppsARCFourState* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, y8_ippsARCFourPack,(const IppsARCFourState* pCtx, Ipp8u* pBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsARCFourPack,(const IppsARCFourState* pCtx, Ipp8u* pBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsARCFourPack,(const IppsARCFourState* pCtx, Ipp8u* pBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsARCFourPack( pCtx, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsARCFourPack( pCtx, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsARCFourPack( pCtx, pBuffer ); - } else + } 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 )) { - return h9_ippsARCFourPack( pCtx, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsARCFourPack( pCtx, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00098.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourReset.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00098.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourReset.c index fc2e91b30..eb957d781 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00098.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourReset.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsARCFourReset, (IppsARCFourState* pCtx)) -IPPAPI(IppStatus, l9_ippsARCFourReset, (IppsARCFourState* pCtx)) IPPAPI(IppStatus, k1_ippsARCFourReset, (IppsARCFourState* pCtx)) +IPPAPI(IppStatus, l9_ippsARCFourReset, (IppsARCFourState* pCtx)) +IPPAPI(IppStatus, y8_ippsARCFourReset, (IppsARCFourState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsARCFourReset, (IppsARCFourState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsARCFourReset, (IppsARCFourState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsARCFourReset( pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsARCFourReset( pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsARCFourReset( pCtx ); - } else + } 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 )) { - return h9_ippsARCFourReset( pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsARCFourReset( pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00100.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourUnpack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00100.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourUnpack.c index 963644e87..c350f8947 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00100.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsARCFourUnpack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsARCFourUnpack,(const Ipp8u* pBuffer, IppsARCFourState* pCtx)) -IPPAPI(IppStatus, l9_ippsARCFourUnpack,(const Ipp8u* pBuffer, IppsARCFourState* pCtx)) IPPAPI(IppStatus, k1_ippsARCFourUnpack,(const Ipp8u* pBuffer, IppsARCFourState* pCtx)) +IPPAPI(IppStatus, l9_ippsARCFourUnpack,(const Ipp8u* pBuffer, IppsARCFourState* pCtx)) +IPPAPI(IppStatus, y8_ippsARCFourUnpack,(const Ipp8u* pBuffer, IppsARCFourState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsARCFourUnpack,(const Ipp8u* pBuffer, IppsARCFourState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsARCFourUnpack,(const Ipp8u* pBuffer, IppsARCFourState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsARCFourUnpack( pBuffer, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsARCFourUnpack( pBuffer, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsARCFourUnpack( pBuffer, pCtx ); - } else + } 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 )) { - return h9_ippsARCFourUnpack( pBuffer, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsARCFourUnpack( pBuffer, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00247.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAdd_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00247.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAdd_BN.c index a13d92f30..425d83fae 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00247.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsAdd_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) -IPPAPI(IppStatus, l9_ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) IPPAPI(IppStatus, k1_ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, y8_ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) -IPPFUN(IppStatus,sgx_disp_ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPFUN(IppStatus, sgx_disp_ippsAdd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsAdd_BN( pA, pB, pR ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsAdd_BN( pA, pB, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsAdd_BN( pA, pB, pR ); - } else + } 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 )) { - return h9_ippsAdd_BN( pA, pB, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAdd_BN( pA, pB, pR ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00238.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsBigNumGetSize.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00238.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsBigNumGetSize.c index 4debdfeab..30aea76b7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00238.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsBigNumGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsBigNumGetSize,(int length, int* pSize)) -IPPAPI(IppStatus, l9_ippsBigNumGetSize,(int length, int* pSize)) IPPAPI(IppStatus, k1_ippsBigNumGetSize,(int length, int* pSize)) +IPPAPI(IppStatus, l9_ippsBigNumGetSize,(int length, int* pSize)) +IPPAPI(IppStatus, y8_ippsBigNumGetSize,(int length, int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsBigNumGetSize,(int length, int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsBigNumGetSize,(int length, int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsBigNumGetSize( length, pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsBigNumGetSize( length, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsBigNumGetSize( length, pSize ); - } else + } 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 )) { - return h9_ippsBigNumGetSize( length, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsBigNumGetSize( length, pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00239.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsBigNumInit.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00239.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsBigNumInit.c index f0316b20a..b3274f812 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00239.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsBigNumInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsBigNumInit,(int length, IppsBigNumState* pBN)) -IPPAPI(IppStatus, l9_ippsBigNumInit,(int length, IppsBigNumState* pBN)) IPPAPI(IppStatus, k1_ippsBigNumInit,(int length, IppsBigNumState* pBN)) +IPPAPI(IppStatus, l9_ippsBigNumInit,(int length, IppsBigNumState* pBN)) +IPPAPI(IppStatus, y8_ippsBigNumInit,(int length, IppsBigNumState* pBN)) -IPPFUN(IppStatus,sgx_disp_ippsBigNumInit,(int length, IppsBigNumState* pBN)) +IPPFUN(IppStatus, sgx_disp_ippsBigNumInit,(int length, IppsBigNumState* pBN)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsBigNumInit( length, pBN ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsBigNumInit( length, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsBigNumInit( length, pBN ); - } else + } 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 )) { - return h9_ippsBigNumInit( length, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsBigNumInit( length, pBN ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00240.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsCmpZero_BN.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00240.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsCmpZero_BN.c index 45ce49b1f..a0d28d945 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00240.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsCmpZero_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) -IPPAPI(IppStatus, l9_ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) IPPAPI(IppStatus, k1_ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) +IPPAPI(IppStatus, l9_ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) +IPPAPI(IppStatus, y8_ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) -IPPFUN(IppStatus,sgx_disp_ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) +IPPFUN(IppStatus, sgx_disp_ippsCmpZero_BN,(const IppsBigNumState* pBN, Ipp32u* pResult)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsCmpZero_BN( pBN, pResult ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsCmpZero_BN( pBN, pResult ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsCmpZero_BN( pBN, pResult ); - } else + } 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 )) { - return h9_ippsCmpZero_BN( pBN, pResult ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsCmpZero_BN( pBN, pResult ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00241.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsCmp_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00241.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsCmp_BN.c index 66774d955..7a08e1b7c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00241.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsCmp_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsCmp_BN,(const IppsBigNumState* pA, const IppsBigNumState* pB, Ipp32u* pResult)) +IPPAPI(IppStatus, l9_ippsCmp_BN,(const IppsBigNumState* pA, const IppsBigNumState* pB, Ipp32u* pResult)) +IPPAPI(IppStatus, y8_ippsCmp_BN,(const IppsBigNumState* pA, const IppsBigNumState* pB, Ipp32u* pResult)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsCmp_BN( pA, pB, pResult ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsCmp_BN( pA, pB, pResult ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsCmp_BN( pA, pB, pResult ); - } else + } 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 )) { - return h9_ippsCmp_BN( pA, pB, pResult ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsCmp_BN( pA, pB, pResult ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00001.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDESGetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00001.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDESGetSize.c index f8baca34d..d12993d08 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00001.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDESGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsDESGetSize,(int *size)) -IPPAPI(IppStatus, l9_ippsDESGetSize,(int *size)) IPPAPI(IppStatus, k1_ippsDESGetSize,(int *size)) +IPPAPI(IppStatus, l9_ippsDESGetSize,(int *size)) +IPPAPI(IppStatus, y8_ippsDESGetSize,(int *size)) -IPPFUN(IppStatus,sgx_disp_ippsDESGetSize,(int *size)) +IPPFUN(IppStatus, sgx_disp_ippsDESGetSize,(int *size)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDESGetSize( size ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDESGetSize( size ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDESGetSize( size ); - } else + } 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 )) { - return h9_ippsDESGetSize( size ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDESGetSize( size ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00002.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDESInit.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00002.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDESInit.c index 310861e1b..f59ad337d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00002.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDESInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsDESInit,(const Ipp8u* pKey, IppsDESSpec* pCtx)) -IPPAPI(IppStatus, l9_ippsDESInit,(const Ipp8u* pKey, IppsDESSpec* pCtx)) IPPAPI(IppStatus, k1_ippsDESInit,(const Ipp8u* pKey, IppsDESSpec* pCtx)) +IPPAPI(IppStatus, l9_ippsDESInit,(const Ipp8u* pKey, IppsDESSpec* pCtx)) +IPPAPI(IppStatus, y8_ippsDESInit,(const Ipp8u* pKey, IppsDESSpec* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsDESInit,(const Ipp8u* pKey, IppsDESSpec* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsDESInit,(const Ipp8u* pKey, IppsDESSpec* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDESInit( pKey, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDESInit( pKey, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDESInit( pKey, pCtx ); - } else + } 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 )) { - return h9_ippsDESInit( pKey, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDESInit( pKey, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00003.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDESPack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00003.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDESPack.c index 2545e617a..af93a528c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00003.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDESPack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsDESPack,(const IppsDESSpec* pCtx, Ipp8u* pBuffer)) -IPPAPI(IppStatus, l9_ippsDESPack,(const IppsDESSpec* pCtx, Ipp8u* pBuffer)) IPPAPI(IppStatus, k1_ippsDESPack,(const IppsDESSpec* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsDESPack,(const IppsDESSpec* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, y8_ippsDESPack,(const IppsDESSpec* pCtx, Ipp8u* pBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsDESPack,(const IppsDESSpec* pCtx, Ipp8u* pBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsDESPack,(const IppsDESSpec* pCtx, Ipp8u* pBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDESPack( pCtx, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDESPack( pCtx, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDESPack( pCtx, pBuffer ); - } else + } 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 )) { - return h9_ippsDESPack( pCtx, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDESPack( pCtx, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00004.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDESUnpack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00004.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDESUnpack.c index 704251b9e..3108912ea 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00004.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDESUnpack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsDESUnpack,(const Ipp8u* pBuffer, IppsDESSpec* pCtx)) -IPPAPI(IppStatus, l9_ippsDESUnpack,(const Ipp8u* pBuffer, IppsDESSpec* pCtx)) IPPAPI(IppStatus, k1_ippsDESUnpack,(const Ipp8u* pBuffer, IppsDESSpec* pCtx)) +IPPAPI(IppStatus, l9_ippsDESUnpack,(const Ipp8u* pBuffer, IppsDESSpec* pCtx)) +IPPAPI(IppStatus, y8_ippsDESUnpack,(const Ipp8u* pBuffer, IppsDESSpec* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsDESUnpack,(const Ipp8u* pBuffer, IppsDESSpec* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsDESUnpack,(const Ipp8u* pBuffer, IppsDESSpec* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDESUnpack( pBuffer, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDESUnpack( pBuffer, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDESUnpack( pBuffer, pCtx ); - } else + } 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 )) { - return h9_ippsDESUnpack( pBuffer, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDESUnpack( pBuffer, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00319.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLGetResultString.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00319.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLGetResultString.c index da081db12..5b2b988de 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00319.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLGetResultString.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const char*, y8_ippsDLGetResultString, (IppDLResult code)) -IPPAPI( const char*, l9_ippsDLGetResultString, (IppDLResult code)) IPPAPI( const char*, k1_ippsDLGetResultString, (IppDLResult code)) +IPPAPI( const char*, l9_ippsDLGetResultString, (IppDLResult code)) +IPPAPI( const char*, y8_ippsDLGetResultString, (IppDLResult code)) -IPPFUN( const char*,sgx_disp_ippsDLGetResultString, (IppDLResult code)) +IPPFUN( const char*, sgx_disp_ippsDLGetResultString, (IppDLResult code)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLGetResultString( code ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLGetResultString( code ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLGetResultString( code ); - } else + } 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 )) { - return h9_ippsDLGetResultString( code ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLGetResultString( code ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00328.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGenKeyPair.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00328.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGenKeyPair.c index 05d22d3fc..0236dc3c5 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00328.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGenKeyPair.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsDLPGenKeyPair,(IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPGenKeyPair( pPrvKey, pPubKey, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPGenKeyPair( pPrvKey, pPubKey, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPGenKeyPair( pPrvKey, pPubKey, pCtx, rndFunc, pRndParam ); - } else + } 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 )) { - return h9_ippsDLPGenKeyPair( pPrvKey, pPubKey, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPGenKeyPair( pPrvKey, pPubKey, pCtx, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00337.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGenerateDH.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00337.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGenerateDH.c index 800d7b9ca..280050c6c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00337.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGenerateDH.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsDLPGenerateDH,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPGenerateDH( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPGenerateDH( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPGenerateDH( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); - } else + } 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 )) { - return h9_ippsDLPGenerateDH( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPGenerateDH( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00335.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGenerateDSA.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00335.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGenerateDSA.c index f92ab6891..388a62974 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00335.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGenerateDSA.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsDLPGenerateDSA,(const IppsBigNumState* pSeedIn, int nTrials, IppsDLPState* pCtx, IppsBigNumState* pSeedOut, int* pCounter, IppBitSupplier rndFunc, void* pRndParam)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPGenerateDSA( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPGenerateDSA( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPGenerateDSA( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); - } else + } 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 )) { - return h9_ippsDLPGenerateDSA( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPGenerateDSA( pSeedIn, nTrials, pCtx, pSeedOut, pCounter, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00325.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGet.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00325.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGet.c index b0da9c899..d229f584d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00325.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGet.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsDLPGet,(IppsBigNumState* pP, IppsBigNumState* pR, IppsBigNumState* pG, IppsDLPState* pCtx)) -IPPAPI(IppStatus, l9_ippsDLPGet,(IppsBigNumState* pP, IppsBigNumState* pR, IppsBigNumState* pG, IppsDLPState* pCtx)) IPPAPI(IppStatus, k1_ippsDLPGet,(IppsBigNumState* pP, IppsBigNumState* pR, IppsBigNumState* pG, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPGet,(IppsBigNumState* pP, IppsBigNumState* pR, IppsBigNumState* pG, IppsDLPState* pCtx)) +IPPAPI(IppStatus, y8_ippsDLPGet,(IppsBigNumState* pP, IppsBigNumState* pR, IppsBigNumState* pG, IppsDLPState* pCtx)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPGet( pP, pR, pG, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPGet( pP, pR, pG, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPGet( pP, pR, pG, pCtx ); - } else + } 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 )) { - return h9_ippsDLPGet( pP, pR, pG, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPGet( pP, pR, pG, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00327.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGetDP.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00327.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGetDP.c index ce3b9d6b2..47d52b61a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00327.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGetDP.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsDLPGetDP,(IppsBigNumState* pDP, IppDLPKeyTag tag, const IppsDLPState* pCtx)) -IPPAPI(IppStatus, l9_ippsDLPGetDP,(IppsBigNumState* pDP, IppDLPKeyTag tag, const IppsDLPState* pCtx)) IPPAPI(IppStatus, k1_ippsDLPGetDP,(IppsBigNumState* pDP, IppDLPKeyTag tag, const IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPGetDP,(IppsBigNumState* pDP, IppDLPKeyTag tag, const IppsDLPState* pCtx)) +IPPAPI(IppStatus, y8_ippsDLPGetDP,(IppsBigNumState* pDP, IppDLPKeyTag tag, const IppsDLPState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsDLPGetDP,(IppsBigNumState* pDP, IppDLPKeyTag tag, const IppsDLPState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsDLPGetDP,(IppsBigNumState* pDP, IppDLPKeyTag tag, const IppsDLPState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPGetDP( pDP, tag, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPGetDP( pDP, tag, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPGetDP( pDP, tag, pCtx ); - } else + } 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 )) { - return h9_ippsDLPGetDP( pDP, tag, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPGetDP( pDP, tag, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00320.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGetSize.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00320.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGetSize.c index 8ba6b2592..e67084661 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00320.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsDLPGetSize,(int bitSizeP, int bitSizeR, int* pSize)) -IPPAPI(IppStatus, l9_ippsDLPGetSize,(int bitSizeP, int bitSizeR, int* pSize)) IPPAPI(IppStatus, k1_ippsDLPGetSize,(int bitSizeP, int bitSizeR, int* pSize)) +IPPAPI(IppStatus, l9_ippsDLPGetSize,(int bitSizeP, int bitSizeR, int* pSize)) +IPPAPI(IppStatus, y8_ippsDLPGetSize,(int bitSizeP, int bitSizeR, int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsDLPGetSize,(int bitSizeP, int bitSizeR, int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsDLPGetSize,(int bitSizeP, int bitSizeR, int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPGetSize( bitSizeP, bitSizeR, pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPGetSize( bitSizeP, bitSizeR, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPGetSize( bitSizeP, bitSizeR, pSize ); - } else + } 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 )) { - return h9_ippsDLPGetSize( bitSizeP, bitSizeR, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPGetSize( bitSizeP, bitSizeR, pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00321.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPInit.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00321.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPInit.c index 5681c8643..a4ac5c06f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00321.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsDLPInit, (int bitSizeP, int bitSizeR, IppsDLPState* pCtx)) -IPPAPI(IppStatus, l9_ippsDLPInit, (int bitSizeP, int bitSizeR, IppsDLPState* pCtx)) IPPAPI(IppStatus, k1_ippsDLPInit, (int bitSizeP, int bitSizeR, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPInit, (int bitSizeP, int bitSizeR, IppsDLPState* pCtx)) +IPPAPI(IppStatus, y8_ippsDLPInit, (int bitSizeP, int bitSizeR, IppsDLPState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsDLPInit, (int bitSizeP, int bitSizeR, IppsDLPState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsDLPInit, (int bitSizeP, int bitSizeR, IppsDLPState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPInit( bitSizeP, bitSizeR, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPInit( bitSizeP, bitSizeR, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPInit( bitSizeP, bitSizeR, pCtx ); - } else + } 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 )) { - return h9_ippsDLPInit( bitSizeP, bitSizeR, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPInit( bitSizeP, bitSizeR, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00322.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPPack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00322.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPPack.c index 29a849be9..4563315c8 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00322.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPPack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsDLPPack,(const IppsDLPState* pCtx, Ipp8u* pBuffer)) -IPPAPI(IppStatus, l9_ippsDLPPack,(const IppsDLPState* pCtx, Ipp8u* pBuffer)) IPPAPI(IppStatus, k1_ippsDLPPack,(const IppsDLPState* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsDLPPack,(const IppsDLPState* pCtx, Ipp8u* pBuffer)) +IPPAPI(IppStatus, y8_ippsDLPPack,(const IppsDLPState* pCtx, Ipp8u* pBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsDLPPack,(const IppsDLPState* pCtx, Ipp8u* pBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsDLPPack,(const IppsDLPState* pCtx, Ipp8u* pBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPPack( pCtx, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPPack( pCtx, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPPack( pCtx, pBuffer ); - } else + } 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 )) { - return h9_ippsDLPPack( pCtx, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPPack( pCtx, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00329.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPPublicKey.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00329.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPPublicKey.c index c54b51830..632ddbca7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00329.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPPublicKey.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsDLPPublicKey, (const IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx)) -IPPAPI(IppStatus, l9_ippsDLPPublicKey, (const IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx)) IPPAPI(IppStatus, k1_ippsDLPPublicKey, (const IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPPublicKey, (const IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx)) +IPPAPI(IppStatus, y8_ippsDLPPublicKey, (const IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsDLPPublicKey, (const IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsDLPPublicKey, (const IppsBigNumState* pPrvKey, IppsBigNumState* pPubKey, IppsDLPState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPPublicKey( pPrvKey, pPubKey, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPPublicKey( pPrvKey, pPubKey, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPPublicKey( pPrvKey, pPubKey, pCtx ); - } else + } 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 )) { - return h9_ippsDLPPublicKey( pPrvKey, pPubKey, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPPublicKey( pPrvKey, pPubKey, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00324.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSet.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00324.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSet.c index 169c892b5..70d677f4a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00324.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSet.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsDLPSet,(const IppsBigNumState* pP, const IppsBigNumState* pR, const IppsBigNumState* pG, IppsDLPState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPSet( pP, pR, pG, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPSet( pP, pR, pG, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPSet( pP, pR, pG, pCtx ); - } else + } 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 )) { - return h9_ippsDLPSet( pP, pR, pG, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPSet( pP, pR, pG, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00326.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSetDP.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00326.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSetDP.c index 1b4b7a540..b16f35b2b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00326.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSetDP.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsDLPSetDP,(const IppsBigNumState* pDP, IppDLPKeyTag tag, IppsDLPState* pCtx)) -IPPAPI(IppStatus, l9_ippsDLPSetDP,(const IppsBigNumState* pDP, IppDLPKeyTag tag, IppsDLPState* pCtx)) IPPAPI(IppStatus, k1_ippsDLPSetDP,(const IppsBigNumState* pDP, IppDLPKeyTag tag, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPSetDP,(const IppsBigNumState* pDP, IppDLPKeyTag tag, IppsDLPState* pCtx)) +IPPAPI(IppStatus, y8_ippsDLPSetDP,(const IppsBigNumState* pDP, IppDLPKeyTag tag, IppsDLPState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsDLPSetDP,(const IppsBigNumState* pDP, IppDLPKeyTag tag, IppsDLPState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsDLPSetDP,(const IppsBigNumState* pDP, IppDLPKeyTag tag, IppsDLPState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPSetDP( pDP, tag, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPSetDP( pDP, tag, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPSetDP( pDP, tag, pCtx ); - } else + } 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 )) { - return h9_ippsDLPSetDP( pDP, tag, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPSetDP( pDP, tag, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00331.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSetKeyPair.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00331.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSetKeyPair.c index 092906f6c..b796cbee5 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00331.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSetKeyPair.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsDLPSetKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppsDLPState* pCtx)) -IPPAPI(IppStatus, l9_ippsDLPSetKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppsDLPState* pCtx)) IPPAPI(IppStatus, k1_ippsDLPSetKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPSetKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppsDLPState* pCtx)) +IPPAPI(IppStatus, y8_ippsDLPSetKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppsDLPState* pCtx)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPSetKeyPair( pPrvKey, pPubKey, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPSetKeyPair( pPrvKey, pPubKey, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPSetKeyPair( pPrvKey, pPubKey, pCtx ); - } else + } 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 )) { - return h9_ippsDLPSetKeyPair( pPrvKey, pPubKey, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPSetKeyPair( pPrvKey, pPubKey, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00334.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSharedSecretDH.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00334.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSharedSecretDH.c index fd2d42abf..bb7f28486 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00334.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSharedSecretDH.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsDLPSharedSecretDH,(const IppsBigNumState* pPrvKeyA, const IppsBigNumState* pPubKeyB, IppsBigNumState* pShare, IppsDLPState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPSharedSecretDH( pPrvKeyA, pPubKeyB, pShare, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPSharedSecretDH( pPrvKeyA, pPubKeyB, pShare, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPSharedSecretDH( pPrvKeyA, pPubKeyB, pShare, pCtx ); - } else + } 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 )) { - return h9_ippsDLPSharedSecretDH( pPrvKeyA, pPubKeyB, pShare, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPSharedSecretDH( pPrvKeyA, pPubKeyB, pShare, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00332.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSignDSA.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00332.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSignDSA.c index d31b80875..bb8f99456 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00332.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPSignDSA.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsDLPSignDSA, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrvKey, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsDLPState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPSignDSA( pMsgDigest, pPrvKey, pSignR, pSignS, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPSignDSA( pMsgDigest, pPrvKey, pSignR, pSignS, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPSignDSA( pMsgDigest, pPrvKey, pSignR, pSignS, pCtx ); - } else + } 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 )) { - return h9_ippsDLPSignDSA( pMsgDigest, pPrvKey, pSignR, pSignS, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPSignDSA( pMsgDigest, pPrvKey, pSignR, pSignS, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00323.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPUnpack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00323.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPUnpack.c index 8bb6a8c97..4e95c4d27 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00323.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPUnpack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsDLPUnpack,(const Ipp8u* pBuffer, IppsDLPState* pCtx)) -IPPAPI(IppStatus, l9_ippsDLPUnpack,(const Ipp8u* pBuffer, IppsDLPState* pCtx)) IPPAPI(IppStatus, k1_ippsDLPUnpack,(const Ipp8u* pBuffer, IppsDLPState* pCtx)) +IPPAPI(IppStatus, l9_ippsDLPUnpack,(const Ipp8u* pBuffer, IppsDLPState* pCtx)) +IPPAPI(IppStatus, y8_ippsDLPUnpack,(const Ipp8u* pBuffer, IppsDLPState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsDLPUnpack,(const Ipp8u* pBuffer, IppsDLPState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsDLPUnpack,(const Ipp8u* pBuffer, IppsDLPState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPUnpack( pBuffer, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPUnpack( pBuffer, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPUnpack( pBuffer, pCtx ); - } else + } 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 )) { - return h9_ippsDLPUnpack( pBuffer, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPUnpack( pBuffer, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00338.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPValidateDH.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00338.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPValidateDH.c index 3b58c4313..8bca6e18b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00338.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPValidateDH.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsDLPValidateDH,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPValidateDH( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPValidateDH( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPValidateDH( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else + } 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 )) { - return h9_ippsDLPValidateDH( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPValidateDH( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00336.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPValidateDSA.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00336.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPValidateDSA.c index c9914ac42..32ce65a11 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00336.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPValidateDSA.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsDLPValidateDSA,(int nTrials, IppDLResult* pResult, IppsDLPState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPValidateDSA( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPValidateDSA( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPValidateDSA( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else + } 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 )) { - return h9_ippsDLPValidateDSA( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPValidateDSA( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00330.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPValidateKeyPair.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00330.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPValidateKeyPair.c index bb0d4547c..370c52b48 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00330.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPValidateKeyPair.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsDLPValidateKeyPair,(const IppsBigNumState* pPrvKey, const IppsBigNumState* pPubKey, IppDLResult* pResult, IppsDLPState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPValidateKeyPair( pPrvKey, pPubKey, pResult, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPValidateKeyPair( pPrvKey, pPubKey, pResult, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPValidateKeyPair( pPrvKey, pPubKey, pResult, pCtx ); - } else + } 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 )) { - return h9_ippsDLPValidateKeyPair( pPrvKey, pPubKey, pResult, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPValidateKeyPair( pPrvKey, pPubKey, pResult, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00333.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPVerifyDSA.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00333.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPVerifyDSA.c index 8df0f483d..c0805f1c0 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00333.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDLPVerifyDSA.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsDLPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppDLResult* pResult, IppsDLPState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDLPVerifyDSA( pMsgDigest, pSignR, pSignS, pResult, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDLPVerifyDSA( pMsgDigest, pSignR, pSignS, pResult, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDLPVerifyDSA( pMsgDigest, pSignR, pSignS, pResult, pCtx ); - } else + } 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 )) { - return h9_ippsDLPVerifyDSA( pMsgDigest, pSignR, pSignS, pResult, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDLPVerifyDSA( pMsgDigest, pSignR, pSignS, pResult, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00251.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDiv_BN.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00251.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDiv_BN.c index 7108956b2..6e0cea27c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00251.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsDiv_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsDiv_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pQ, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsDiv_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pQ, IppsBigNumState* pR)) +IPPAPI(IppStatus, y8_ippsDiv_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pQ, IppsBigNumState* pR)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsDiv_BN( pA, pB, pQ, pR ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsDiv_BN( pA, pB, pQ, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsDiv_BN( pA, pB, pQ, pR ); - } else + } 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 )) { - return h9_ippsDiv_BN( pA, pB, pQ, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsDiv_BN( pA, pB, pQ, pR ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00339.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCGetResultString.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00339.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCGetResultString.c index 0c3fa4464..567085a5d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00339.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCGetResultString.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const char*, y8_ippsECCGetResultString, (IppECResult code)) -IPPAPI( const char*, l9_ippsECCGetResultString, (IppECResult code)) IPPAPI( const char*, k1_ippsECCGetResultString, (IppECResult code)) +IPPAPI( const char*, l9_ippsECCGetResultString, (IppECResult code)) +IPPAPI( const char*, y8_ippsECCGetResultString, (IppECResult code)) -IPPFUN( const char*,sgx_disp_ippsECCGetResultString, (IppECResult code)) +IPPFUN( const char*, sgx_disp_ippsECCGetResultString, (IppECResult code)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCGetResultString( code ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCGetResultString( code ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCGetResultString( code ); - } else + } 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 )) { - return h9_ippsECCGetResultString( code ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCGetResultString( code ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00385.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPAddPoint.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00385.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPAddPoint.c index 88bac81ed..c8e0d5990 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00385.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPAddPoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPAddPoint( pP, pQ, pR, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPAddPoint( pP, pQ, pR, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPAddPoint( pP, pQ, pR, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPAddPoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppsECCPPointState* pR, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPAddPoint( pP, pQ, pR, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPAddPoint( pP, pQ, pR, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00368.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd192r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00368.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd192r1.c index 9eed10d44..efb4f2be2 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00368.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd192r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPBindGxyTblStd192r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPBindGxyTblStd192r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPBindGxyTblStd192r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd192r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPBindGxyTblStd192r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPBindGxyTblStd192r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00369.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd224r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00369.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd224r1.c index 59a348ee2..2dcbba9bb 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00369.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd224r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPBindGxyTblStd224r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPBindGxyTblStd224r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPBindGxyTblStd224r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd224r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPBindGxyTblStd224r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPBindGxyTblStd224r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00370.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd256r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00370.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd256r1.c index fc37553ac..aa93559e1 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00370.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd256r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPBindGxyTblStd256r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPBindGxyTblStd256r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPBindGxyTblStd256r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd256r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPBindGxyTblStd256r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPBindGxyTblStd256r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00371.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd384r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00371.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd384r1.c index 0dd7d0ff4..6cd0edcce 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00371.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd384r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPBindGxyTblStd384r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPBindGxyTblStd384r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPBindGxyTblStd384r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd384r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPBindGxyTblStd384r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPBindGxyTblStd384r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00372.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd521r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00372.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd521r1.c index bfbf0c7ad..f7cfd03ac 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00372.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStd521r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPBindGxyTblStd521r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPBindGxyTblStd521r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPBindGxyTblStd521r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStd521r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPBindGxyTblStd521r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPBindGxyTblStd521r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00373.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStdSM2.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00373.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStdSM2.c index 19afabf8a..2947e5bcf 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00373.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPBindGxyTblStdSM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPBindGxyTblStdSM2( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPBindGxyTblStdSM2( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPBindGxyTblStdSM2( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPBindGxyTblStdSM2, (IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPBindGxyTblStdSM2( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPBindGxyTblStdSM2( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00382.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPCheckPoint.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00382.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPCheckPoint.c index 648ba3c4a..2ddc31166 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00382.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPCheckPoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPCheckPoint( pP, pResult, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPCheckPoint( pP, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPCheckPoint( pP, pResult, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPCheckPoint,(const IppsECCPPointState* pP, IppECResult* pResult, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPCheckPoint( pP, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPCheckPoint( pP, pResult, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00383.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPComparePoint.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00383.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPComparePoint.c index d6b63c4b7..bd3f7e16c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00383.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPComparePoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPComparePoint( pP, pQ, pResult, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPComparePoint( pP, pQ, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPComparePoint( pP, pQ, pResult, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPComparePoint,(const IppsECCPPointState* pP, const IppsECCPPointState* pQ, IppECResult* pResult, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPComparePoint( pP, pQ, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPComparePoint( pP, pQ, pResult, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00387.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGenKeyPair.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00387.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGenKeyPair.c index e5ee2a631..0ef6065e2 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00387.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGenKeyPair.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) -IPPAPI(IppStatus, l9_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) IPPAPI(IppStatus, k1_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, y8_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) -IPPFUN(IppStatus,sgx_disp_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) +IPPFUN(IppStatus, sgx_disp_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPGenKeyPair( pPrivate, pPublic, pEC, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPGenKeyPair( pPrivate, pPublic, pEC, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPGenKeyPair( pPrivate, pPublic, pEC, rndFunc, pRndParam ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) -IPPAPI(IppStatus, h9_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPGenKeyPair,(IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPGenKeyPair( pPrivate, pPublic, pEC, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPGenKeyPair( pPrivate, pPublic, pEC, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00374.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGet.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00374.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGet.c index 257b83fc4..6ab76ac17 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00374.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGet.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPGet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPGet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPGet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPGet,(IppsBigNumState* pPrime, IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGX,IppsBigNumState* pGY,IppsBigNumState* pOrder, int* cofactor, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPGet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPGet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00375.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetOrderBitSize.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00375.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetOrderBitSize.c index 935e46cdb..1654880e4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00375.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetOrderBitSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPGetOrderBitSize( pBitSize, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPGetOrderBitSize( pBitSize, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPGetOrderBitSize( pBitSize, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPGetOrderBitSize,(int* pBitSize, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPGetOrderBitSize( pBitSize, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPGetOrderBitSize( pBitSize, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00381.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetPoint.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00381.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetPoint.c index a871f361a..4c0805ba4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00381.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetPoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPGetPoint( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPGetPoint( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPGetPoint( pX, pY, pPoint, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPGetPoint,(IppsBigNumState* pX, IppsBigNumState* pY, const IppsECCPPointState* pPoint, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPGetPoint( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPGetPoint( pX, pY, pPoint, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00340.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSize.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00340.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSize.c index 4fb028285..c4f563ba6 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00340.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPGetSize,(int feBitSize, int* pSize)) -IPPAPI(IppStatus, l9_ippsECCPGetSize,(int feBitSize, int* pSize)) IPPAPI(IppStatus, k1_ippsECCPGetSize,(int feBitSize, int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSize,(int feBitSize, int* pSize)) +IPPAPI(IppStatus, y8_ippsECCPGetSize,(int feBitSize, int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsECCPGetSize,(int feBitSize, int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsECCPGetSize,(int feBitSize, int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPGetSize( feBitSize, pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPGetSize( feBitSize, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPGetSize( feBitSize, pSize ); - } else + } 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 )) { - return h9_ippsECCPGetSize( feBitSize, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPGetSize( feBitSize, pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00341.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd128r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00341.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd128r1.c index 727a0c104..f828805d2 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00341.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd128r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPGetSizeStd128r1,(int* pSize)) -IPPAPI(IppStatus, l9_ippsECCPGetSizeStd128r1,(int* pSize)) IPPAPI(IppStatus, k1_ippsECCPGetSizeStd128r1,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd128r1,(int* pSize)) +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd128r1,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd128r1,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsECCPGetSizeStd128r1,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPGetSizeStd128r1( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPGetSizeStd128r1( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPGetSizeStd128r1( pSize ); - } else + } 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 )) { - return h9_ippsECCPGetSizeStd128r1( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPGetSizeStd128r1( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00342.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd128r2.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00342.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd128r2.c index 49eecd6b5..7d208acde 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00342.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd128r2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPGetSizeStd128r2,(int* pSize)) -IPPAPI(IppStatus, l9_ippsECCPGetSizeStd128r2,(int* pSize)) IPPAPI(IppStatus, k1_ippsECCPGetSizeStd128r2,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd128r2,(int* pSize)) +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd128r2,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd128r2,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsECCPGetSizeStd128r2,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPGetSizeStd128r2( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPGetSizeStd128r2( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPGetSizeStd128r2( pSize ); - } else + } 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 )) { - return h9_ippsECCPGetSizeStd128r2( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPGetSizeStd128r2( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00343.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd192r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00343.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd192r1.c index 84df48b7f..99692f064 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00343.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd192r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPGetSizeStd192r1,(int* pSize)) -IPPAPI(IppStatus, l9_ippsECCPGetSizeStd192r1,(int* pSize)) IPPAPI(IppStatus, k1_ippsECCPGetSizeStd192r1,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd192r1,(int* pSize)) +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd192r1,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd192r1,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsECCPGetSizeStd192r1,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPGetSizeStd192r1( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPGetSizeStd192r1( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPGetSizeStd192r1( pSize ); - } else + } 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 )) { - return h9_ippsECCPGetSizeStd192r1( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPGetSizeStd192r1( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00344.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd224r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00344.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd224r1.c index 0190ceb38..50d346cb1 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00344.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd224r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPGetSizeStd224r1,(int* pSize)) -IPPAPI(IppStatus, l9_ippsECCPGetSizeStd224r1,(int* pSize)) IPPAPI(IppStatus, k1_ippsECCPGetSizeStd224r1,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd224r1,(int* pSize)) +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd224r1,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd224r1,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsECCPGetSizeStd224r1,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPGetSizeStd224r1( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPGetSizeStd224r1( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPGetSizeStd224r1( pSize ); - } else + } 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 )) { - return h9_ippsECCPGetSizeStd224r1( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPGetSizeStd224r1( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00345.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd256r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00345.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd256r1.c index 3a2a1dd4d..2edeb151f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00345.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd256r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPGetSizeStd256r1,(int* pSize)) -IPPAPI(IppStatus, l9_ippsECCPGetSizeStd256r1,(int* pSize)) IPPAPI(IppStatus, k1_ippsECCPGetSizeStd256r1,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd256r1,(int* pSize)) +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd256r1,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd256r1,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsECCPGetSizeStd256r1,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPGetSizeStd256r1( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPGetSizeStd256r1( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPGetSizeStd256r1( pSize ); - } else + } 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 )) { - return h9_ippsECCPGetSizeStd256r1( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPGetSizeStd256r1( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00346.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd384r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00346.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd384r1.c index 6517501f8..ef24bf5ae 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00346.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd384r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPGetSizeStd384r1,(int* pSize)) -IPPAPI(IppStatus, l9_ippsECCPGetSizeStd384r1,(int* pSize)) IPPAPI(IppStatus, k1_ippsECCPGetSizeStd384r1,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd384r1,(int* pSize)) +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd384r1,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd384r1,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsECCPGetSizeStd384r1,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPGetSizeStd384r1( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPGetSizeStd384r1( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPGetSizeStd384r1( pSize ); - } else + } 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 )) { - return h9_ippsECCPGetSizeStd384r1( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPGetSizeStd384r1( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00347.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd521r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00347.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd521r1.c index 9898b1764..9b034c615 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00347.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStd521r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPGetSizeStd521r1,(int* pSize)) -IPPAPI(IppStatus, l9_ippsECCPGetSizeStd521r1,(int* pSize)) IPPAPI(IppStatus, k1_ippsECCPGetSizeStd521r1,(int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStd521r1,(int* pSize)) +IPPAPI(IppStatus, y8_ippsECCPGetSizeStd521r1,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStd521r1,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsECCPGetSizeStd521r1,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPGetSizeStd521r1( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPGetSizeStd521r1( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPGetSizeStd521r1( pSize ); - } else + } 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 )) { - return h9_ippsECCPGetSizeStd521r1( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPGetSizeStd521r1( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00348.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStdSM2.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00348.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStdSM2.c index a296affa1..5938d68e0 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00348.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPGetSizeStdSM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPGetSizeStdSM2, (int* pSize)) -IPPAPI(IppStatus, l9_ippsECCPGetSizeStdSM2, (int* pSize)) IPPAPI(IppStatus, k1_ippsECCPGetSizeStdSM2, (int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPGetSizeStdSM2, (int* pSize)) +IPPAPI(IppStatus, y8_ippsECCPGetSizeStdSM2, (int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsECCPGetSizeStdSM2, (int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsECCPGetSizeStdSM2, (int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPGetSizeStdSM2( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPGetSizeStdSM2( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPGetSizeStdSM2( pSize ); - } else + } 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 )) { - return h9_ippsECCPGetSizeStdSM2( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPGetSizeStdSM2( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00349.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInit.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00349.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInit.c index 548bdde79..50a85a15f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00349.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPInit,(int feBitSize, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPInit,(int feBitSize, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPInit,(int feBitSize, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPInit,(int feBitSize, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPInit,(int feBitSize, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPInit,(int feBitSize, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPInit,(int feBitSize, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPInit( feBitSize, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPInit( feBitSize, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPInit( feBitSize, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPInit,(int feBitSize, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPInit,(int feBitSize, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPInit,(int feBitSize, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPInit( feBitSize, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPInit( feBitSize, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00350.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd128r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00350.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd128r1.c index 7cb83651b..dd9febd23 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00350.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd128r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPInitStd128r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPInitStd128r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPInitStd128r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd128r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPInitStd128r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd128r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPInitStd128r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPInitStd128r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPInitStd128r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPInitStd128r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPInitStd128r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPInitStd128r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd128r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPInitStd128r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPInitStd128r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00351.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd128r2.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00351.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd128r2.c index 22ce5dc9c..204628cf2 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00351.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd128r2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPInitStd128r2,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPInitStd128r2,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPInitStd128r2,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd128r2,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPInitStd128r2,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd128r2,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPInitStd128r2,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPInitStd128r2( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPInitStd128r2( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPInitStd128r2( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPInitStd128r2,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPInitStd128r2,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd128r2,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPInitStd128r2( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPInitStd128r2( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00352.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd192r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00352.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd192r1.c index a5f36efab..352b3d4ba 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00352.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd192r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPInitStd192r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPInitStd192r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPInitStd192r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd192r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPInitStd192r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd192r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPInitStd192r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPInitStd192r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPInitStd192r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPInitStd192r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPInitStd192r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPInitStd192r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd192r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPInitStd192r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPInitStd192r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00353.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd224r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00353.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd224r1.c index ed9bbfb32..ec39a7406 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00353.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd224r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPInitStd224r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPInitStd224r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPInitStd224r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd224r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPInitStd224r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd224r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPInitStd224r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPInitStd224r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPInitStd224r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPInitStd224r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPInitStd224r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPInitStd224r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd224r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPInitStd224r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPInitStd224r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00354.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd256r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00354.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd256r1.c index b1fc30857..4749c1bf3 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00354.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd256r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPInitStd256r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPInitStd256r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPInitStd256r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd256r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPInitStd256r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd256r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPInitStd256r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPInitStd256r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPInitStd256r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPInitStd256r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPInitStd256r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPInitStd256r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd256r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPInitStd256r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPInitStd256r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00355.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd384r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00355.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd384r1.c index 98838c17e..d4d65ca19 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00355.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd384r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPInitStd384r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPInitStd384r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPInitStd384r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd384r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPInitStd384r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd384r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPInitStd384r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPInitStd384r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPInitStd384r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPInitStd384r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPInitStd384r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPInitStd384r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd384r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPInitStd384r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPInitStd384r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00356.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd521r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00356.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd521r1.c index de0ed78ab..913fc907d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00356.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStd521r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPInitStd521r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPInitStd521r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPInitStd521r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPInitStd521r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPInitStd521r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd521r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPInitStd521r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPInitStd521r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPInitStd521r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPInitStd521r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPInitStd521r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPInitStd521r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStd521r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPInitStd521r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPInitStd521r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00357.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStdSM2.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00357.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStdSM2.c index 56d7d5452..47b9f70e7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00357.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPInitStdSM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPInitStdSM2, (IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPInitStdSM2, (IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPInitStdSM2, (IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPInitStdSM2, (IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPInitStdSM2, (IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStdSM2, (IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPInitStdSM2, (IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPInitStdSM2( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPInitStdSM2( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPInitStdSM2( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPInitStdSM2, (IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPInitStdSM2, (IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPInitStdSM2, (IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPInitStdSM2( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPInitStdSM2( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00386.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPMulPointScalar.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00386.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPMulPointScalar.c index 3f35060d0..b808d3f07 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00386.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPMulPointScalar.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPMulPointScalar( pP, pK, pR, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPMulPointScalar( pP, pK, pR, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPMulPointScalar( pP, pK, pR, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPMulPointScalar,(const IppsECCPPointState* pP, const IppsBigNumState* pK, IppsECCPPointState* pR, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPMulPointScalar( pP, pK, pR, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPMulPointScalar( pP, pK, pR, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00384.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPNegativePoint.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00384.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPNegativePoint.c index 25cb0c1a4..dc8eb6100 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00384.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPNegativePoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPNegativePoint( pP, pR, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPNegativePoint( pP, pR, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPNegativePoint( pP, pR, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPNegativePoint,(const IppsECCPPointState* pP, IppsECCPPointState* pR, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPNegativePoint( pP, pR, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPNegativePoint( pP, pR, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00377.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPPointGetSize.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00377.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPPointGetSize.c index f98591adb..58faabca9 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00377.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPPointGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPPointGetSize,(int feBitSize, int* pSize)) -IPPAPI(IppStatus, l9_ippsECCPPointGetSize,(int feBitSize, int* pSize)) IPPAPI(IppStatus, k1_ippsECCPPointGetSize,(int feBitSize, int* pSize)) +IPPAPI(IppStatus, l9_ippsECCPPointGetSize,(int feBitSize, int* pSize)) +IPPAPI(IppStatus, y8_ippsECCPPointGetSize,(int feBitSize, int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsECCPPointGetSize,(int feBitSize, int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsECCPPointGetSize,(int feBitSize, int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPPointGetSize( feBitSize, pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPPointGetSize( feBitSize, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPPointGetSize( feBitSize, pSize ); - } else + } 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 )) { - return h9_ippsECCPPointGetSize( feBitSize, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPPointGetSize( feBitSize, pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00378.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPPointInit.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00378.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPPointInit.c index 32c907176..b4b8b887c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00378.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPPointInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) -IPPAPI(IppStatus, l9_ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) IPPAPI(IppStatus, k1_ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) +IPPAPI(IppStatus, l9_ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) +IPPAPI(IppStatus, y8_ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) -IPPFUN(IppStatus,sgx_disp_ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) +IPPFUN(IppStatus, sgx_disp_ippsECCPPointInit,(int feBitSize, IppsECCPPointState* pPoint)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPPointInit( feBitSize, pPoint ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPPointInit( feBitSize, pPoint ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPPointInit( feBitSize, pPoint ); - } else + } 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 )) { - return h9_ippsECCPPointInit( feBitSize, pPoint ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPPointInit( feBitSize, pPoint ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00388.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPPublicKey.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00388.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPPublicKey.c index d7c98ff3f..d2e283d80 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00388.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPPublicKey.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPPublicKey( pPrivate, pPublic, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPPublicKey( pPrivate, pPublic, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPPublicKey( pPrivate, pPublic, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPPublicKey,(const IppsBigNumState* pPrivate, IppsECCPPointState* pPublic, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPPublicKey( pPrivate, pPublic, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPPublicKey( pPrivate, pPublic, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00358.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSet.c similarity index 64% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00358.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSet.c index 7bd05a531..2d31a2b57 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00358.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSet.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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* pEC)) -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* pEC)) IPPAPI(IppStatus, k1_ippsECCPSet,(const IppsBigNumState* pPrime, const IppsBigNumState* pA, const IppsBigNumState* pB, const IppsBigNumState* pGX,const IppsBigNumState* pGY,const IppsBigNumState* pOrder, int cofactor, IppsECCPState* pEC)) +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* pEC)) +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* pEC)) -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* pEC)) +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* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pEC ); - } else + } 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* pEC)) -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* pEC)) - -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* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSet( pPrime, pA, pB, pGX, pGY, pOrder, cofactor, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00390.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetKeyPair.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00390.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetKeyPair.c index abed86072..6241f8bac 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00390.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetKeyPair.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSetKeyPair( pPrivate, pPublic, regular, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSetKeyPair( pPrivate, pPublic, regular, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSetKeyPair( pPrivate, pPublic, regular, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSetKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppBool regular, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSetKeyPair( pPrivate, pPublic, regular, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSetKeyPair( pPrivate, pPublic, regular, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00379.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetPoint.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00379.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetPoint.c index 227530c96..d37c4db38 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00379.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetPoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSetPoint( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSetPoint( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSetPoint( pX, pY, pPoint, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSetPoint,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsECCPPointState* pPoint, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSetPoint( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSetPoint( pX, pY, pPoint, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00380.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetPointAtInfinity.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00380.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetPointAtInfinity.c index 3e19a5083..9c90b668e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00380.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetPointAtInfinity.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSetPointAtInfinity( pPoint, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSetPointAtInfinity( pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSetPointAtInfinity( pPoint, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSetPointAtInfinity,(IppsECCPPointState* pPoint, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSetPointAtInfinity( pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSetPointAtInfinity( pPoint, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00359.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00359.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd.c index 8df6e279c..78bd0a916 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00359.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSetStd( flag, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSetStd( flag, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSetStd( flag, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd,(IppECCType flag, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSetStd( flag, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSetStd( flag, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00360.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd128r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00360.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd128r1.c index 1fe36fe41..f7f82db22 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00360.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd128r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSetStd128r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSetStd128r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSetStd128r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd128r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSetStd128r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd128r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSetStd128r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSetStd128r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSetStd128r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSetStd128r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSetStd128r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSetStd128r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd128r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSetStd128r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSetStd128r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00361.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd128r2.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00361.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd128r2.c index 30337bc3d..807596969 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00361.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd128r2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSetStd128r2,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSetStd128r2,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSetStd128r2,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd128r2,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSetStd128r2,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd128r2,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSetStd128r2,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSetStd128r2( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSetStd128r2( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSetStd128r2( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSetStd128r2,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSetStd128r2,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd128r2,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSetStd128r2( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSetStd128r2( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00362.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd192r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00362.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd192r1.c index 012d8479f..75dccae9d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00362.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd192r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSetStd192r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSetStd192r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSetStd192r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd192r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSetStd192r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd192r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSetStd192r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSetStd192r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSetStd192r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSetStd192r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSetStd192r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSetStd192r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd192r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSetStd192r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSetStd192r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00363.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd224r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00363.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd224r1.c index a218a820a..77a9c6dc3 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00363.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd224r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSetStd224r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSetStd224r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSetStd224r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd224r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSetStd224r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd224r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSetStd224r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSetStd224r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSetStd224r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSetStd224r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSetStd224r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSetStd224r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd224r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSetStd224r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSetStd224r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00364.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd256r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00364.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd256r1.c index d52c657c8..cb20f02b7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00364.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd256r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSetStd256r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSetStd256r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSetStd256r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd256r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSetStd256r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd256r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSetStd256r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSetStd256r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSetStd256r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSetStd256r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSetStd256r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSetStd256r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd256r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSetStd256r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSetStd256r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00365.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd384r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00365.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd384r1.c index ab650c853..3e1ce3d96 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00365.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd384r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSetStd384r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSetStd384r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSetStd384r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd384r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSetStd384r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd384r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSetStd384r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSetStd384r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSetStd384r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSetStd384r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSetStd384r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSetStd384r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd384r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSetStd384r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSetStd384r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00366.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd521r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00366.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd521r1.c index 27336eb20..5354012a0 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00366.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStd521r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSetStd521r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSetStd521r1,(IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSetStd521r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSetStd521r1,(IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSetStd521r1,(IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd521r1,(IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSetStd521r1,(IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSetStd521r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSetStd521r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSetStd521r1( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSetStd521r1,(IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSetStd521r1,(IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStd521r1,(IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSetStd521r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSetStd521r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00367.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStdSM2.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00367.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStdSM2.c index 0a55b7714..3f2fb608d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00367.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSetStdSM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSetStdSM2, (IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSetStdSM2, (IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSetStdSM2, (IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSetStdSM2, (IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSetStdSM2, (IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStdSM2, (IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSetStdSM2, (IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSetStdSM2( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSetStdSM2( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSetStdSM2( pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSetStdSM2, (IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSetStdSM2, (IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSetStdSM2, (IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSetStdSM2( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSetStdSM2( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00391.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSharedSecretDH.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00391.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSharedSecretDH.c index 67f79b632..03fbde341 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00391.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSharedSecretDH.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSharedSecretDH( pPrivateA, pPublicB, pShare, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSharedSecretDH( pPrivateA, pPublicB, pShare, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSharedSecretDH( pPrivateA, pPublicB, pShare, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSharedSecretDH( pPrivateA, pPublicB, pShare, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSharedSecretDH( pPrivateA, pPublicB, pShare, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00392.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSharedSecretDHC.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00392.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSharedSecretDHC.c index a449e0e17..fa1f58c9e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00392.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSharedSecretDHC.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsECCPPointState* pPublicB, IppsBigNumState* pShare, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00393.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSignDSA.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00393.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSignDSA.c index 6d535ba46..392ff1b2d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00393.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSignDSA.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSignDSA( pMsgDigest, pPrivate, pSignX, pSignY, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSignDSA( pMsgDigest, pPrivate, pSignX, pSignY, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSignDSA( pMsgDigest, pPrivate, pSignX, pSignY, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSignDSA( pMsgDigest, pPrivate, pSignX, pSignY, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSignDSA( pMsgDigest, pPrivate, pSignX, pSignY, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00395.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSignNR.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00395.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSignNR.c index 22d49da7c..ccf49a53d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00395.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSignNR.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSignNR( pMsgDigest, pPrivate, pSignX, pSignY, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSignNR( pMsgDigest, pPrivate, pSignX, pSignY, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSignNR( pMsgDigest, pPrivate, pSignX, pSignY, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pPrivate, IppsBigNumState* pSignX, IppsBigNumState* pSignY, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSignNR( pMsgDigest, pPrivate, pSignX, pSignY, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSignNR( pMsgDigest, pPrivate, pSignX, pSignY, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00397.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSignSM2.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00397.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSignSM2.c index e3359b307..4cbc6d435 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00397.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPSignSM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00376.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPValidate.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00376.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPValidate.c index bd5701f73..8b7a2e245 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00376.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPValidate.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) -IPPAPI(IppStatus, l9_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) IPPAPI(IppStatus, k1_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, y8_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) -IPPFUN(IppStatus,sgx_disp_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) +IPPFUN(IppStatus, sgx_disp_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPValidate( nTrials, pResult, pEC, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPValidate( nTrials, pResult, pEC, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPValidate( nTrials, pResult, pEC, rndFunc, pRndParam ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) -IPPAPI(IppStatus, h9_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPValidate,(int nTrials, IppECResult* pResult, IppsECCPState* pEC, IppBitSupplier rndFunc, void* pRndParam)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPValidate( nTrials, pResult, pEC, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPValidate( nTrials, pResult, pEC, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00389.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPValidateKeyPair.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00389.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPValidateKeyPair.c index 25d963a95..c1c1a9380 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00389.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPValidateKeyPair.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPValidateKeyPair( pPrivate, pPublic, pResult, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPValidateKeyPair( pPrivate, pPublic, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPValidateKeyPair( pPrivate, pPublic, pResult, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPValidateKeyPair,(const IppsBigNumState* pPrivate, const IppsECCPPointState* pPublic, IppECResult* pResult, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPValidateKeyPair( pPrivate, pPublic, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPValidateKeyPair( pPrivate, pPublic, pResult, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00394.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPVerifyDSA.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00394.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPVerifyDSA.c index ad62521fb..7dfd3824f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00394.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPVerifyDSA.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPVerifyDSA( pMsgDigest, pSignX, pSignY, pResult, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPVerifyDSA( pMsgDigest, pSignX, pSignY, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPVerifyDSA( pMsgDigest, pSignX, pSignY, pResult, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPVerifyDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPVerifyDSA( pMsgDigest, pSignX, pSignY, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPVerifyDSA( pMsgDigest, pSignX, pSignY, pResult, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00396.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPVerifyNR.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00396.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPVerifyNR.c index d3ac7f44d..28e316846 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00396.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPVerifyNR.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPVerifyNR( pMsgDigest, pSignX, pSignY, pResult, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPVerifyNR( pMsgDigest, pSignX, pSignY, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPVerifyNR( pMsgDigest, pSignX, pSignY, pResult, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPVerifyNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pSignX, const IppsBigNumState* pSignY, IppECResult* pResult, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPVerifyNR( pMsgDigest, pSignX, pSignY, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPVerifyNR( pMsgDigest, pSignX, pSignY, pResult, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00398.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPVerifySM2.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00398.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPVerifySM2.c index 456054c4c..b3737f9b1 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00398.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsECCPVerifySM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pEC)) -IPPAPI(IppStatus, l9_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pEC)) IPPAPI(IppStatus, k1_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pEC)) +IPPAPI(IppStatus, l9_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pEC)) +IPPAPI(IppStatus, y8_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsECCPVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsECCPVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsECCPVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pEC)) -IPPAPI(IppStatus, h9_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsECCPVerifySM2,(const IppsBigNumState* pMsgDigest, const IppsECCPPointState* pRegPublic, const IppsBigNumState* pSignR, const IppsBigNumState* pSignS, IppECResult* pResult, IppsECCPState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsECCPVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsECCPVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00246.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsExtGet_BN.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00246.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsExtGet_BN.c index 967bfcf3b..077294736 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00246.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsExtGet_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsExtGet_BN,(IppsBigNumSGN* pSgn, int* pBitSize, Ipp32u* pData, const IppsBigNumState* pBN)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsExtGet_BN( pSgn, pBitSize, pData, pBN ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsExtGet_BN( pSgn, pBitSize, pData, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsExtGet_BN( pSgn, pBitSize, pData, pBN ); - } else + } 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 )) { - return h9_ippsExtGet_BN( pSgn, pBitSize, pData, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsExtGet_BN( pSgn, pBitSize, pData, pBN ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00441.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpAdd.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00441.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpAdd.c index 76a8a76d3..ceb8efb90 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00441.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpAdd.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpAdd, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpAdd( pA, pB, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpAdd( pA, pB, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpAdd( pA, pB, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpAdd( pA, pB, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpAdd( pA, pB, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00446.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpAdd_PE.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00446.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpAdd_PE.c index 62df5a1c4..3030b3129 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00446.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpAdd_PE.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpAdd_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpAdd_PE( pA, pParentB, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpAdd_PE( pA, pParentB, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpAdd_PE( pA, pParentB, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpAdd_PE( pA, pParentB, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpAdd_PE( pA, pParentB, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00433.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpCmpElement.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00433.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpCmpElement.c index 00a6c7e40..aaed7d3c2 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00433.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpCmpElement.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpCmpElement,(const IppsGFpElement* pA, const IppsGFpElement* pB, int* pResult, const IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpCmpElement( pA, pB, pResult, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpCmpElement( pA, pB, pResult, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpCmpElement( pA, pB, pResult, pGFp ); - } else + } 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 )) { - return h9_ippsGFpCmpElement( pA, pB, pResult, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpCmpElement( pA, pB, pResult, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00436.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpConj.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00436.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpConj.c index af340af93..2b06fc817 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00436.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpConj.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPFUN(IppStatus, sgx_disp_ippsGFpConj,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpConj( pA, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpConj( pA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpConj( pA, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpConj( pA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpConj( pA, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00430.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpCpyElement.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00430.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpCpyElement.c index eded3fb53..58fdaed25 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00430.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpCpyElement.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPFUN(IppStatus, sgx_disp_ippsGFpCpyElement,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpCpyElement( pA, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpCpyElement( pA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpCpyElement( pA, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpCpyElement( pA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpCpyElement( pA, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00493.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECAddPoint.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00493.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECAddPoint.c index 570c5113e..ef705415b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00493.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECAddPoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECAddPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppsGFpECPoint* pR, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECAddPoint( pP, pQ, pR, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECAddPoint( pP, pQ, pR, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECAddPoint( pP, pQ, pR, pEC ); - } else + } 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 )) { - return h9_ippsGFpECAddPoint( pP, pQ, pR, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECAddPoint( pP, pQ, pR, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00463.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd192r1.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00463.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd192r1.c index 622dfb6ca..1a2521f0a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00463.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd192r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECBindGxyTblStd192r1,(IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECBindGxyTblStd192r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECBindGxyTblStd192r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECBindGxyTblStd192r1( pEC ); - } else + } 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 )) { - return h9_ippsGFpECBindGxyTblStd192r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECBindGxyTblStd192r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00464.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd224r1.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00464.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd224r1.c index 73a08ad9e..901bd1d99 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00464.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd224r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECBindGxyTblStd224r1,(IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECBindGxyTblStd224r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECBindGxyTblStd224r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECBindGxyTblStd224r1( pEC ); - } else + } 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 )) { - return h9_ippsGFpECBindGxyTblStd224r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECBindGxyTblStd224r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00465.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd256r1.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00465.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd256r1.c index 69f0d30c7..68ca27e7b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00465.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd256r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECBindGxyTblStd256r1,(IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECBindGxyTblStd256r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECBindGxyTblStd256r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECBindGxyTblStd256r1( pEC ); - } else + } 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 )) { - return h9_ippsGFpECBindGxyTblStd256r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECBindGxyTblStd256r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00466.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd384r1.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00466.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd384r1.c index ee3f98c8f..6955f1d2d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00466.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd384r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECBindGxyTblStd384r1,(IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECBindGxyTblStd384r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECBindGxyTblStd384r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECBindGxyTblStd384r1( pEC ); - } else + } 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 )) { - return h9_ippsGFpECBindGxyTblStd384r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECBindGxyTblStd384r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00467.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd521r1.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00467.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd521r1.c index 9a4cf9089..ef380ce20 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00467.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStd521r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECBindGxyTblStd521r1,(IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECBindGxyTblStd521r1( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECBindGxyTblStd521r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECBindGxyTblStd521r1( pEC ); - } else + } 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 )) { - return h9_ippsGFpECBindGxyTblStd521r1( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECBindGxyTblStd521r1( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00468.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStdSM2.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00468.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStdSM2.c index adeb6404f..234f6431a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00468.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECBindGxyTblStdSM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECBindGxyTblStdSM2, (IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECBindGxyTblStdSM2( pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECBindGxyTblStdSM2( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECBindGxyTblStdSM2( pEC ); - } else + } 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 )) { - return h9_ippsGFpECBindGxyTblStdSM2( pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECBindGxyTblStdSM2( pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00491.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECCmpPoint.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00491.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECCmpPoint.c index 13da6cb02..074e85d4f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00491.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECCmpPoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECCmpPoint,(const IppsGFpECPoint* pP, const IppsGFpECPoint* pQ, IppECResult* pResult, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECCmpPoint( pP, pQ, pResult, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECCmpPoint( pP, pQ, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECCmpPoint( pP, pQ, pResult, pEC ); - } else + } 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 )) { - return h9_ippsGFpECCmpPoint( pP, pQ, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECCmpPoint( pP, pQ, pResult, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00490.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECCpyPoint.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00490.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECCpyPoint.c index 8def8247d..3dcd8a898 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00490.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECCpyPoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECCpyPoint,(const IppsGFpECPoint* pA, IppsGFpECPoint* pR, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECCpyPoint( pA, pR, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECCpyPoint( pA, pR, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECCpyPoint( pA, pR, pEC ); - } else + } 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 )) { - return h9_ippsGFpECCpyPoint( pA, pR, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECCpyPoint( pA, pR, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECDecryptSM2_Ext.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECDecryptSM2_Ext.c new file mode 100644 index 000000000..458fac799 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECDecryptSM2_Ext.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECDecryptSM2_Ext, (Ipp8u *pOut, int maxOutLen, int *pOutSize, const Ipp8u *pInp, int inpLen, const IppsBigNumState *pPrvKey, IppsGFpECState *pEC, Ipp8u *pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECDecryptSM2_Ext, (Ipp8u *pOut, int maxOutLen, int *pOutSize, const Ipp8u *pInp, int inpLen, const IppsBigNumState *pPrvKey, IppsGFpECState *pEC, Ipp8u *pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECDecryptSM2_Ext, (Ipp8u *pOut, int maxOutLen, int *pOutSize, const Ipp8u *pInp, int inpLen, const IppsBigNumState *pPrvKey, IppsGFpECState *pEC, Ipp8u *pScratchBuffer)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECDecryptSM2_Ext, (Ipp8u *pOut, int maxOutLen, int *pOutSize, const Ipp8u *pInp, int inpLen, const IppsBigNumState *pPrvKey, IppsGFpECState *pEC, Ipp8u *pScratchBuffer)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECDecryptSM2_Ext( pOut, maxOutLen, pOutSize, pInp, inpLen, pPrvKey, pEC, pScratchBuffer ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECDecryptSM2_Ext( pOut, maxOutLen, pOutSize, pInp, inpLen, pPrvKey, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECDecryptSM2_Ext( pOut, maxOutLen, pOutSize, pInp, inpLen, pPrvKey, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECDecryptSM2_Ext_DecMsgSize.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECDecryptSM2_Ext_DecMsgSize.c new file mode 100644 index 000000000..f829ebcc1 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECDecryptSM2_Ext_DecMsgSize.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECDecryptSM2_Ext_DecMsgSize, (const IppsGFpECState *pEC, int ctMsgSize, int *pSize)) +IPPAPI(IppStatus, l9_ippsGFpECDecryptSM2_Ext_DecMsgSize, (const IppsGFpECState *pEC, int ctMsgSize, int *pSize)) +IPPAPI(IppStatus, y8_ippsGFpECDecryptSM2_Ext_DecMsgSize, (const IppsGFpECState *pEC, int ctMsgSize, int *pSize)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECDecryptSM2_Ext_DecMsgSize, (const IppsGFpECState *pEC, int ctMsgSize, int *pSize)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECDecryptSM2_Ext_DecMsgSize( pEC, ctMsgSize, pSize ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECDecryptSM2_Ext_DecMsgSize( pEC, ctMsgSize, pSize ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECDecryptSM2_Ext_DecMsgSize( pEC, ctMsgSize, pSize ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00512.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESDecrypt_SM2.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00512.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESDecrypt_SM2.c index c2f020f6f..959c9a54f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00512.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESDecrypt_SM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECESDecrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) -IPPAPI(IppStatus, l9_ippsGFpECESDecrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) IPPAPI(IppStatus, k1_ippsGFpECESDecrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) +IPPAPI(IppStatus, l9_ippsGFpECESDecrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) +IPPAPI(IppStatus, y8_ippsGFpECESDecrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECESDecrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECESDecrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECESDecrypt_SM2( pInput, pOutput, dataLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECESDecrypt_SM2( pInput, pOutput, dataLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECESDecrypt_SM2( pInput, pOutput, dataLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECESDecrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) -IPPAPI(IppStatus, h9_ippsGFpECESDecrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECESDecrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECESDecrypt_SM2( pInput, pOutput, dataLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECESDecrypt_SM2( pInput, pOutput, dataLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00511.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESEncrypt_SM2.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00511.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESEncrypt_SM2.c index 675e2b0c7..9028ef9de 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00511.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESEncrypt_SM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECESEncrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) -IPPAPI(IppStatus, l9_ippsGFpECESEncrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) IPPAPI(IppStatus, k1_ippsGFpECESEncrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) +IPPAPI(IppStatus, l9_ippsGFpECESEncrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) +IPPAPI(IppStatus, y8_ippsGFpECESEncrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECESEncrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECESEncrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECESEncrypt_SM2( pInput, pOutput, dataLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECESEncrypt_SM2( pInput, pOutput, dataLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECESEncrypt_SM2( pInput, pOutput, dataLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECESEncrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) -IPPAPI(IppStatus, h9_ippsGFpECESEncrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECESEncrypt_SM2, (const Ipp8u* pInput, Ipp8u* pOutput, int dataLen, IppsECESState_SM2* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECESEncrypt_SM2( pInput, pOutput, dataLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECESEncrypt_SM2( pInput, pOutput, dataLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00513.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESFinal_SM2.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00513.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESFinal_SM2.c index afa1f8581..9584682a8 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00513.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESFinal_SM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECESFinal_SM2, (Ipp8u* pTag, int tagLen, IppsECESState_SM2* pState)) -IPPAPI(IppStatus, l9_ippsGFpECESFinal_SM2, (Ipp8u* pTag, int tagLen, IppsECESState_SM2* pState)) IPPAPI(IppStatus, k1_ippsGFpECESFinal_SM2, (Ipp8u* pTag, int tagLen, IppsECESState_SM2* pState)) +IPPAPI(IppStatus, l9_ippsGFpECESFinal_SM2, (Ipp8u* pTag, int tagLen, IppsECESState_SM2* pState)) +IPPAPI(IppStatus, y8_ippsGFpECESFinal_SM2, (Ipp8u* pTag, int tagLen, IppsECESState_SM2* pState)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECESFinal_SM2, (Ipp8u* pTag, int tagLen, IppsECESState_SM2* pState)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECESFinal_SM2, (Ipp8u* pTag, int tagLen, IppsECESState_SM2* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECESFinal_SM2( pTag, tagLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECESFinal_SM2( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECESFinal_SM2( pTag, tagLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECESFinal_SM2, (Ipp8u* pTag, int tagLen, IppsECESState_SM2* pState)) -IPPAPI(IppStatus, h9_ippsGFpECESFinal_SM2, (Ipp8u* pTag, int tagLen, IppsECESState_SM2* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECESFinal_SM2, (Ipp8u* pTag, int tagLen, IppsECESState_SM2* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECESFinal_SM2( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECESFinal_SM2( pTag, tagLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00514.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESGetBuffersSize_SM2.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00514.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESGetBuffersSize_SM2.c index fd43139f1..f03e2edfc 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00514.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESGetBuffersSize_SM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECESGetBuffersSize_SM2, (int* pPublicKeySize, int* pMaximumTagSize, const IppsECESState_SM2* pState)) -IPPAPI(IppStatus, l9_ippsGFpECESGetBuffersSize_SM2, (int* pPublicKeySize, int* pMaximumTagSize, const IppsECESState_SM2* pState)) IPPAPI(IppStatus, k1_ippsGFpECESGetBuffersSize_SM2, (int* pPublicKeySize, int* pMaximumTagSize, const IppsECESState_SM2* pState)) +IPPAPI(IppStatus, l9_ippsGFpECESGetBuffersSize_SM2, (int* pPublicKeySize, int* pMaximumTagSize, const IppsECESState_SM2* pState)) +IPPAPI(IppStatus, y8_ippsGFpECESGetBuffersSize_SM2, (int* pPublicKeySize, int* pMaximumTagSize, const IppsECESState_SM2* pState)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECESGetBuffersSize_SM2, (int* pPublicKeySize, int* pMaximumTagSize, const IppsECESState_SM2* pState)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECESGetBuffersSize_SM2, (int* pPublicKeySize, int* pMaximumTagSize, const IppsECESState_SM2* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECESGetBuffersSize_SM2( pPublicKeySize, pMaximumTagSize, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECESGetBuffersSize_SM2( pPublicKeySize, pMaximumTagSize, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECESGetBuffersSize_SM2( pPublicKeySize, pMaximumTagSize, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECESGetBuffersSize_SM2, (int* pPublicKeySize, int* pMaximumTagSize, const IppsECESState_SM2* pState)) -IPPAPI(IppStatus, h9_ippsGFpECESGetBuffersSize_SM2, (int* pPublicKeySize, int* pMaximumTagSize, const IppsECESState_SM2* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECESGetBuffersSize_SM2, (int* pPublicKeySize, int* pMaximumTagSize, const IppsECESState_SM2* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECESGetBuffersSize_SM2( pPublicKeySize, pMaximumTagSize, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECESGetBuffersSize_SM2( pPublicKeySize, pMaximumTagSize, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00507.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESGetSize_SM2.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00507.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESGetSize_SM2.c index 1b9922ced..5b81053a6 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00507.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESGetSize_SM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECESGetSize_SM2, (const IppsGFpECState* pEC, int* pSize)) -IPPAPI(IppStatus, l9_ippsGFpECESGetSize_SM2, (const IppsGFpECState* pEC, int* pSize)) IPPAPI(IppStatus, k1_ippsGFpECESGetSize_SM2, (const IppsGFpECState* pEC, int* pSize)) +IPPAPI(IppStatus, l9_ippsGFpECESGetSize_SM2, (const IppsGFpECState* pEC, int* pSize)) +IPPAPI(IppStatus, y8_ippsGFpECESGetSize_SM2, (const IppsGFpECState* pEC, int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECESGetSize_SM2, (const IppsGFpECState* pEC, int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECESGetSize_SM2, (const IppsGFpECState* pEC, int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECESGetSize_SM2( pEC, pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECESGetSize_SM2( pEC, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECESGetSize_SM2( pEC, pSize ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECESGetSize_SM2, (const IppsGFpECState* pEC, int* pSize)) -IPPAPI(IppStatus, h9_ippsGFpECESGetSize_SM2, (const IppsGFpECState* pEC, int* pSize)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECESGetSize_SM2, (const IppsGFpECState* pEC, int* pSize)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECESGetSize_SM2( pEC, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECESGetSize_SM2( pEC, pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00508.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESInit_SM2.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00508.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESInit_SM2.c index 8ea7b4636..47406068b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00508.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESInit_SM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECESInit_SM2, (IppsGFpECState* pEC, IppsECESState_SM2* pState, int avaliableCtxSize)) -IPPAPI(IppStatus, l9_ippsGFpECESInit_SM2, (IppsGFpECState* pEC, IppsECESState_SM2* pState, int avaliableCtxSize)) IPPAPI(IppStatus, k1_ippsGFpECESInit_SM2, (IppsGFpECState* pEC, IppsECESState_SM2* pState, int avaliableCtxSize)) +IPPAPI(IppStatus, l9_ippsGFpECESInit_SM2, (IppsGFpECState* pEC, IppsECESState_SM2* pState, int avaliableCtxSize)) +IPPAPI(IppStatus, y8_ippsGFpECESInit_SM2, (IppsGFpECState* pEC, IppsECESState_SM2* pState, int avaliableCtxSize)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECESInit_SM2, (IppsGFpECState* pEC, IppsECESState_SM2* pState, int avaliableCtxSize)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECESInit_SM2, (IppsGFpECState* pEC, IppsECESState_SM2* pState, int avaliableCtxSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECESInit_SM2( pEC, pState, avaliableCtxSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECESInit_SM2( pEC, pState, avaliableCtxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECESInit_SM2( pEC, pState, avaliableCtxSize ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECESInit_SM2, (IppsGFpECState* pEC, IppsECESState_SM2* pState, int avaliableCtxSize)) -IPPAPI(IppStatus, h9_ippsGFpECESInit_SM2, (IppsGFpECState* pEC, IppsECESState_SM2* pState, int avaliableCtxSize)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECESInit_SM2, (IppsGFpECState* pEC, IppsECESState_SM2* pState, int avaliableCtxSize)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECESInit_SM2( pEC, pState, avaliableCtxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECESInit_SM2( pEC, pState, avaliableCtxSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00509.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESSetKey_SM2.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00509.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESSetKey_SM2.c index de901594c..d3d47848e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00509.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESSetKey_SM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECESSetKey_SM2, (const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppsECESState_SM2* pState, IppsGFpECState* pEC, Ipp8u* pEcScratchBuffer)) -IPPAPI(IppStatus, l9_ippsGFpECESSetKey_SM2, (const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppsECESState_SM2* pState, IppsGFpECState* pEC, Ipp8u* pEcScratchBuffer)) IPPAPI(IppStatus, k1_ippsGFpECESSetKey_SM2, (const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppsECESState_SM2* pState, IppsGFpECState* pEC, Ipp8u* pEcScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECESSetKey_SM2, (const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppsECESState_SM2* pState, IppsGFpECState* pEC, Ipp8u* pEcScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECESSetKey_SM2, (const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppsECESState_SM2* pState, IppsGFpECState* pEC, Ipp8u* pEcScratchBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECESSetKey_SM2, (const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppsECESState_SM2* pState, IppsGFpECState* pEC, Ipp8u* pEcScratchBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECESSetKey_SM2, (const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppsECESState_SM2* pState, IppsGFpECState* pEC, Ipp8u* pEcScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECESSetKey_SM2( pPrivate, pPublic, pState, pEC, pEcScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECESSetKey_SM2( pPrivate, pPublic, pState, pEC, pEcScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECESSetKey_SM2( pPrivate, pPublic, pState, pEC, pEcScratchBuffer ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECESSetKey_SM2, (const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppsECESState_SM2* pState, IppsGFpECState* pEC, Ipp8u* pEcScratchBuffer)) -IPPAPI(IppStatus, h9_ippsGFpECESSetKey_SM2, (const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppsECESState_SM2* pState, IppsGFpECState* pEC, Ipp8u* pEcScratchBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECESSetKey_SM2, (const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppsECESState_SM2* pState, IppsGFpECState* pEC, Ipp8u* pEcScratchBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECESSetKey_SM2( pPrivate, pPublic, pState, pEC, pEcScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECESSetKey_SM2( pPrivate, pPublic, pState, pEC, pEcScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00510.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESStart_SM2.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00510.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESStart_SM2.c index 502dd6a9c..8fdb22f3d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00510.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECESStart_SM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECESStart_SM2, (IppsECESState_SM2* pState)) -IPPAPI(IppStatus, l9_ippsGFpECESStart_SM2, (IppsECESState_SM2* pState)) IPPAPI(IppStatus, k1_ippsGFpECESStart_SM2, (IppsECESState_SM2* pState)) +IPPAPI(IppStatus, l9_ippsGFpECESStart_SM2, (IppsECESState_SM2* pState)) +IPPAPI(IppStatus, y8_ippsGFpECESStart_SM2, (IppsECESState_SM2* pState)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECESStart_SM2, (IppsECESState_SM2* pState)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECESStart_SM2, (IppsECESState_SM2* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECESStart_SM2( pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECESStart_SM2( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECESStart_SM2( pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECESStart_SM2, (IppsECESState_SM2* pState)) -IPPAPI(IppStatus, h9_ippsGFpECESStart_SM2, (IppsECESState_SM2* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECESStart_SM2, (IppsECESState_SM2* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECESStart_SM2( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECESStart_SM2( pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECEncryptSM2_Ext.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECEncryptSM2_Ext.c new file mode 100644 index 000000000..547c2e9a5 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECEncryptSM2_Ext.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECEncryptSM2_Ext, (Ipp8u *pOut, int maxOutLen, int *pOutSize, const Ipp8u *pInp, int inpLen, const IppsGFpECPoint *pPublicKey, IppsGFpECPoint *pEhpPublicKey, IppsBigNumState *pEphPrvKey, IppsGFpECState *pEC, Ipp8u *pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECEncryptSM2_Ext, (Ipp8u *pOut, int maxOutLen, int *pOutSize, const Ipp8u *pInp, int inpLen, const IppsGFpECPoint *pPublicKey, IppsGFpECPoint *pEhpPublicKey, IppsBigNumState *pEphPrvKey, IppsGFpECState *pEC, Ipp8u *pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECEncryptSM2_Ext, (Ipp8u *pOut, int maxOutLen, int *pOutSize, const Ipp8u *pInp, int inpLen, const IppsGFpECPoint *pPublicKey, IppsGFpECPoint *pEhpPublicKey, IppsBigNumState *pEphPrvKey, IppsGFpECState *pEC, Ipp8u *pScratchBuffer)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECEncryptSM2_Ext, (Ipp8u *pOut, int maxOutLen, int *pOutSize, const Ipp8u *pInp, int inpLen, const IppsGFpECPoint *pPublicKey, IppsGFpECPoint *pEhpPublicKey, IppsBigNumState *pEphPrvKey, IppsGFpECState *pEC, Ipp8u *pScratchBuffer)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECEncryptSM2_Ext( pOut, maxOutLen, pOutSize, pInp, inpLen, pPublicKey, pEhpPublicKey, pEphPrvKey, pEC, pScratchBuffer ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECEncryptSM2_Ext( pOut, maxOutLen, pOutSize, pInp, inpLen, pPublicKey, pEhpPublicKey, pEphPrvKey, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECEncryptSM2_Ext( pOut, maxOutLen, pOutSize, pInp, inpLen, pPublicKey, pEhpPublicKey, pEphPrvKey, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECEncryptSM2_Ext_EncMsgSize.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECEncryptSM2_Ext_EncMsgSize.c new file mode 100644 index 000000000..bf3d8dba1 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECEncryptSM2_Ext_EncMsgSize.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECEncryptSM2_Ext_EncMsgSize, (const IppsGFpECState *pEC, int ptMsgSize, int *pSize)) +IPPAPI(IppStatus, l9_ippsGFpECEncryptSM2_Ext_EncMsgSize, (const IppsGFpECState *pEC, int ptMsgSize, int *pSize)) +IPPAPI(IppStatus, y8_ippsGFpECEncryptSM2_Ext_EncMsgSize, (const IppsGFpECState *pEC, int ptMsgSize, int *pSize)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECEncryptSM2_Ext_EncMsgSize, (const IppsGFpECState *pEC, int ptMsgSize, int *pSize)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECEncryptSM2_Ext_EncMsgSize( pEC, ptMsgSize, pSize ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECEncryptSM2_Ext_EncMsgSize( pEC, ptMsgSize, pSize ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECEncryptSM2_Ext_EncMsgSize( pEC, ptMsgSize, pSize ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00469.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGet.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00469.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGet.c index e506a1d47..406f7255c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00469.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGet.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECGet,(IppsGFpState** const ppGFp, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECGet,(IppsGFpState** const ppGFp, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECGet,(IppsGFpState** const ppGFp, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECGet,(IppsGFpState** const ppGFp, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECGet,(IppsGFpState** const ppGFp, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECGet,(IppsGFpState** const ppGFp, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECGet,(IppsGFpState** const ppGFp, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECGet( ppGFp, pA, pB, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECGet( ppGFp, pA, pB, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECGet( ppGFp, pA, pB, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECGet,(IppsGFpState** const ppGFp, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECGet,(IppsGFpState** const ppGFp, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECGet,(IppsGFpState** const ppGFp, IppsGFpElement* pA, IppsGFpElement* pB, const IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECGet( ppGFp, pA, pB, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECGet( ppGFp, pA, pB, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00506.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetInfo_GF.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00506.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetInfo_GF.c index 64fd3414d..be189da32 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00506.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetInfo_GF.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECGetInfo_GF,(IppsGFpInfo* pInfo, const IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECGetInfo_GF,(IppsGFpInfo* pInfo, const IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECGetInfo_GF,(IppsGFpInfo* pInfo, const IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECGetInfo_GF,(IppsGFpInfo* pInfo, const IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECGetInfo_GF,(IppsGFpInfo* pInfo, const IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECGetInfo_GF,(IppsGFpInfo* pInfo, const IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECGetInfo_GF,(IppsGFpInfo* pInfo, const IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECGetInfo_GF( pInfo, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECGetInfo_GF( pInfo, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECGetInfo_GF( pInfo, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECGetInfo_GF,(IppsGFpInfo* pInfo, const IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECGetInfo_GF,(IppsGFpInfo* pInfo, const IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECGetInfo_GF,(IppsGFpInfo* pInfo, const IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECGetInfo_GF( pInfo, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECGetInfo_GF( pInfo, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00484.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetPoint.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00484.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetPoint.c index 5e8ce3cee..c3f5dfd4c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00484.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetPoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsGFpECGetPoint,(const IppsGFpECPoint* pPoint, IppsGFpElement* pX, IppsGFpElement* pY, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECGetPoint,(const IppsGFpECPoint* pPoint, IppsGFpElement* pX, IppsGFpElement* pY, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECGetPoint,(const IppsGFpECPoint* pPoint, IppsGFpElement* pX, IppsGFpElement* pY, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECGetPoint( pPoint, pX, pY, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECGetPoint( pPoint, pX, pY, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECGetPoint( pPoint, pX, pY, pEC ); - } else + } 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 )) { - return h9_ippsGFpECGetPoint( pPoint, pX, pY, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECGetPoint( pPoint, pX, pY, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00487.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetPointOctString.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00487.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetPointOctString.c index 9c4b010aa..e5ffb8505 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00487.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetPointOctString.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECGetPointOctString,(const IppsGFpECPoint* pPoint, Ipp8u* pStr, int strLen, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECGetPointOctString,(const IppsGFpECPoint* pPoint, Ipp8u* pStr, int strLen, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECGetPointOctString,(const IppsGFpECPoint* pPoint, Ipp8u* pStr, int strLen, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECGetPointOctString,(const IppsGFpECPoint* pPoint, Ipp8u* pStr, int strLen, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECGetPointOctString,(const IppsGFpECPoint* pPoint, Ipp8u* pStr, int strLen, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECGetPointOctString,(const IppsGFpECPoint* pPoint, Ipp8u* pStr, int strLen, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECGetPointOctString,(const IppsGFpECPoint* pPoint, Ipp8u* pStr, int strLen, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECGetPointOctString( pPoint, pStr, strLen, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECGetPointOctString( pPoint, pStr, strLen, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECGetPointOctString( pPoint, pStr, strLen, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECGetPointOctString,(const IppsGFpECPoint* pPoint, Ipp8u* pStr, int strLen, IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECGetPointOctString,(const IppsGFpECPoint* pPoint, Ipp8u* pStr, int strLen, IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECGetPointOctString,(const IppsGFpECPoint* pPoint, Ipp8u* pStr, int strLen, IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECGetPointOctString( pPoint, pStr, strLen, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECGetPointOctString( pPoint, pStr, strLen, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00485.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetPointRegular.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00485.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetPointRegular.c index fe88faea6..7645e5e5d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00485.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetPointRegular.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsGFpECGetPointRegular,(const IppsGFpECPoint* pPoint, IppsBigNumState* pX, IppsBigNumState* pY, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECGetPointRegular,(const IppsGFpECPoint* pPoint, IppsBigNumState* pX, IppsBigNumState* pY, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECGetPointRegular,(const IppsGFpECPoint* pPoint, IppsBigNumState* pX, IppsBigNumState* pY, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECGetPointRegular( pPoint, pX, pY, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECGetPointRegular( pPoint, pX, pY, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECGetPointRegular( pPoint, pX, pY, pEC ); - } else + } 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 )) { - return h9_ippsGFpECGetPointRegular( pPoint, pX, pY, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECGetPointRegular( pPoint, pX, pY, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00450.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetSize.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00450.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetSize.c index 9852c43f4..69ed99f88 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00450.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECGetSize,(const IppsGFpState* pGFp, int* pSize)) -IPPAPI(IppStatus, l9_ippsGFpECGetSize,(const IppsGFpState* pGFp, int* pSize)) IPPAPI(IppStatus, k1_ippsGFpECGetSize,(const IppsGFpState* pGFp, int* pSize)) +IPPAPI(IppStatus, l9_ippsGFpECGetSize,(const IppsGFpState* pGFp, int* pSize)) +IPPAPI(IppStatus, y8_ippsGFpECGetSize,(const IppsGFpState* pGFp, int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECGetSize,(const IppsGFpState* pGFp, int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECGetSize,(const IppsGFpState* pGFp, int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECGetSize( pGFp, pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECGetSize( pGFp, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECGetSize( pGFp, pSize ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECGetSize,(const IppsGFpState* pGFp, int* pSize)) -IPPAPI(IppStatus, h9_ippsGFpECGetSize,(const IppsGFpState* pGFp, int* pSize)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECGetSize,(const IppsGFpState* pGFp, int* pSize)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECGetSize( pGFp, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECGetSize( pGFp, pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00470.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetSubgroup.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00470.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetSubgroup.c index 595895ea8..4bb0ee2e1 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00470.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECGetSubgroup.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECGetSubgroup,(IppsGFpState** const ppGFp, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECGetSubgroup,(IppsGFpState** const ppGFp, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECGetSubgroup,(IppsGFpState** const ppGFp, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECGetSubgroup,(IppsGFpState** const ppGFp, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECGetSubgroup,(IppsGFpState** const ppGFp, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECGetSubgroup,(IppsGFpState** const ppGFp, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECGetSubgroup,(IppsGFpState** const ppGFp, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECGetSubgroup( ppGFp, pX, pY, pOrder, pCofactor, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECGetSubgroup( ppGFp, pX, pY, pOrder, pCofactor, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECGetSubgroup( ppGFp, pX, pY, pOrder, pCofactor, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECGetSubgroup,(IppsGFpState** const ppGFp, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECGetSubgroup,(IppsGFpState** const ppGFp, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECGetSubgroup,(IppsGFpState** const ppGFp, IppsGFpElement* pX, IppsGFpElement* pY, IppsBigNumState* pOrder,IppsBigNumState* pCofactor, const IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECGetSubgroup( ppGFp, pX, pY, pOrder, pCofactor, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECGetSubgroup( ppGFp, pX, pY, pOrder, pCofactor, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00451.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInit.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00451.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInit.c index 003465970..d582ce813 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00451.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECInit, (const IppsGFpState* pGFp, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECInit, (const IppsGFpState* pGFp, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECInit, (const IppsGFpState* pGFp, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInit, (const IppsGFpState* pGFp, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECInit, (const IppsGFpState* pGFp, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECInit, (const IppsGFpState* pGFp, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECInit, (const IppsGFpState* pGFp, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECInit( pGFp, pA, pB, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECInit( pGFp, pA, pB, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECInit( pGFp, pA, pB, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECInit, (const IppsGFpState* pGFp, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECInit, (const IppsGFpState* pGFp, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECInit, (const IppsGFpState* pGFp, const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECInit( pGFp, pA, pB, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECInit( pGFp, pA, pB, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00454.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd128r1.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00454.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd128r1.c index 7cf228e3f..92167daab 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00454.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd128r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECInitStd128r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECInitStd128r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECInitStd128r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd128r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECInitStd128r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd128r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECInitStd128r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECInitStd128r1( pGFp, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECInitStd128r1( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECInitStd128r1( pGFp, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECInitStd128r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECInitStd128r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd128r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECInitStd128r1( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECInitStd128r1( pGFp, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00455.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd128r2.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00455.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd128r2.c index dbac72f62..16ee7450a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00455.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd128r2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECInitStd128r2,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECInitStd128r2,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECInitStd128r2,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd128r2,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECInitStd128r2,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd128r2,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECInitStd128r2,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECInitStd128r2( pGFp, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECInitStd128r2( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECInitStd128r2( pGFp, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECInitStd128r2,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECInitStd128r2,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd128r2,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECInitStd128r2( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECInitStd128r2( pGFp, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00456.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd192r1.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00456.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd192r1.c index 0c2c01d70..1989171f3 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00456.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd192r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECInitStd192r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECInitStd192r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECInitStd192r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd192r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECInitStd192r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd192r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECInitStd192r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECInitStd192r1( pGFp, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECInitStd192r1( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECInitStd192r1( pGFp, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECInitStd192r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECInitStd192r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd192r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECInitStd192r1( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECInitStd192r1( pGFp, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00457.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd224r1.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00457.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd224r1.c index e08a9a2f3..82059508c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00457.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd224r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECInitStd224r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECInitStd224r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECInitStd224r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd224r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECInitStd224r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd224r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECInitStd224r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECInitStd224r1( pGFp, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECInitStd224r1( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECInitStd224r1( pGFp, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECInitStd224r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECInitStd224r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd224r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECInitStd224r1( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECInitStd224r1( pGFp, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00458.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd256r1.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00458.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd256r1.c index 9ba571045..585a9019e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00458.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd256r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECInitStd256r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECInitStd256r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECInitStd256r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd256r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECInitStd256r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd256r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECInitStd256r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECInitStd256r1( pGFp, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECInitStd256r1( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECInitStd256r1( pGFp, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECInitStd256r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECInitStd256r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd256r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECInitStd256r1( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECInitStd256r1( pGFp, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00459.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd384r1.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00459.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd384r1.c index ad0f2f89f..376bda965 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00459.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd384r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECInitStd384r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECInitStd384r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECInitStd384r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd384r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECInitStd384r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd384r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECInitStd384r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECInitStd384r1( pGFp, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECInitStd384r1( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECInitStd384r1( pGFp, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECInitStd384r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECInitStd384r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd384r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECInitStd384r1( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECInitStd384r1( pGFp, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00460.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd521r1.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00460.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd521r1.c index 98da42912..2d64a508e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00460.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStd521r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECInitStd521r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECInitStd521r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECInitStd521r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStd521r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECInitStd521r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd521r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECInitStd521r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECInitStd521r1( pGFp, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECInitStd521r1( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECInitStd521r1( pGFp, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECInitStd521r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECInitStd521r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStd521r1,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECInitStd521r1( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECInitStd521r1( pGFp, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00462.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStdBN256.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00462.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStdBN256.c index 0960b220e..b8b83ff82 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00462.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStdBN256.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECInitStdBN256,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECInitStdBN256,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECInitStdBN256,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStdBN256,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECInitStdBN256,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStdBN256,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECInitStdBN256,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECInitStdBN256( pGFp, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECInitStdBN256( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECInitStdBN256( pGFp, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECInitStdBN256,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECInitStdBN256,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStdBN256,(const IppsGFpState* pGFp, IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECInitStdBN256( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECInitStdBN256( pGFp, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00461.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStdSM2.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00461.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStdSM2.c index 0bf42c534..53de49dd5 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00461.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECInitStdSM2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECInitStdSM2, (const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECInitStdSM2, (const IppsGFpState* pGFp, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECInitStdSM2, (const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECInitStdSM2, (const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECInitStdSM2, (const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStdSM2, (const IppsGFpState* pGFp, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECInitStdSM2, (const IppsGFpState* pGFp, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECInitStdSM2( pGFp, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECInitStdSM2( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECInitStdSM2( pGFp, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECInitStdSM2, (const IppsGFpState* pGFp, IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECInitStdSM2, (const IppsGFpState* pGFp, IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECInitStdSM2, (const IppsGFpState* pGFp, IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECInitStdSM2( pGFp, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECInitStdSM2( pGFp, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_Confirm.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_Confirm.c new file mode 100644 index 000000000..f57b8d3d6 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_Confirm.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECKeyExchangeSM2_Confirm, (const Ipp8u pSPeer[IPP_SM3_DIGEST_BYTESIZE], int* pStatus, IppsGFpECKeyExchangeSM2State* pKE)) +IPPAPI(IppStatus, l9_ippsGFpECKeyExchangeSM2_Confirm, (const Ipp8u pSPeer[IPP_SM3_DIGEST_BYTESIZE], int* pStatus, IppsGFpECKeyExchangeSM2State* pKE)) +IPPAPI(IppStatus, y8_ippsGFpECKeyExchangeSM2_Confirm, (const Ipp8u pSPeer[IPP_SM3_DIGEST_BYTESIZE], int* pStatus, IppsGFpECKeyExchangeSM2State* pKE)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECKeyExchangeSM2_Confirm, (const Ipp8u pSPeer[IPP_SM3_DIGEST_BYTESIZE], int* pStatus, IppsGFpECKeyExchangeSM2State* pKE)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECKeyExchangeSM2_Confirm( pSPeer, pStatus, pKE ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECKeyExchangeSM2_Confirm( pSPeer, pStatus, pKE ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECKeyExchangeSM2_Confirm( pSPeer, pStatus, pKE ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_GetSize.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_GetSize.c new file mode 100644 index 000000000..2889695dd --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_GetSize.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECKeyExchangeSM2_GetSize, (const IppsGFpECState* pEC, int* pSize)) +IPPAPI(IppStatus, l9_ippsGFpECKeyExchangeSM2_GetSize, (const IppsGFpECState* pEC, int* pSize)) +IPPAPI(IppStatus, y8_ippsGFpECKeyExchangeSM2_GetSize, (const IppsGFpECState* pEC, int* pSize)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECKeyExchangeSM2_GetSize, (const IppsGFpECState* pEC, int* pSize)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECKeyExchangeSM2_GetSize( pEC, pSize ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECKeyExchangeSM2_GetSize( pEC, pSize ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECKeyExchangeSM2_GetSize( pEC, pSize ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_Init.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_Init.c new file mode 100644 index 000000000..3d10f9e57 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_Init.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECKeyExchangeSM2_Init, (IppsGFpECKeyExchangeSM2State* pKE, IppsKeyExchangeRoleSM2 role, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECKeyExchangeSM2_Init, (IppsGFpECKeyExchangeSM2State* pKE, IppsKeyExchangeRoleSM2 role, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECKeyExchangeSM2_Init, (IppsGFpECKeyExchangeSM2State* pKE, IppsKeyExchangeRoleSM2 role, IppsGFpECState* pEC)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECKeyExchangeSM2_Init, (IppsGFpECKeyExchangeSM2State* pKE, IppsKeyExchangeRoleSM2 role, IppsGFpECState* pEC)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECKeyExchangeSM2_Init( pKE, role, pEC ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECKeyExchangeSM2_Init( pKE, role, pEC ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECKeyExchangeSM2_Init( pKE, role, pEC ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_Setup.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_Setup.c new file mode 100644 index 000000000..4882b99d0 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_Setup.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECKeyExchangeSM2_Setup, (const Ipp8u pZSelf[IPP_SM3_DIGEST_BYTESIZE], const Ipp8u pZPeer[IPP_SM3_DIGEST_BYTESIZE], const IppsGFpECPoint *pPublicKeySelf, const IppsGFpECPoint *pPublicKeyPeer, const IppsGFpECPoint *pEphPublicKeySelf, const IppsGFpECPoint *pEphPublicKeyPeer, IppsGFpECKeyExchangeSM2State *pKE)) +IPPAPI(IppStatus, l9_ippsGFpECKeyExchangeSM2_Setup, (const Ipp8u pZSelf[IPP_SM3_DIGEST_BYTESIZE], const Ipp8u pZPeer[IPP_SM3_DIGEST_BYTESIZE], const IppsGFpECPoint *pPublicKeySelf, const IppsGFpECPoint *pPublicKeyPeer, const IppsGFpECPoint *pEphPublicKeySelf, const IppsGFpECPoint *pEphPublicKeyPeer, IppsGFpECKeyExchangeSM2State *pKE)) +IPPAPI(IppStatus, y8_ippsGFpECKeyExchangeSM2_Setup, (const Ipp8u pZSelf[IPP_SM3_DIGEST_BYTESIZE], const Ipp8u pZPeer[IPP_SM3_DIGEST_BYTESIZE], const IppsGFpECPoint *pPublicKeySelf, const IppsGFpECPoint *pPublicKeyPeer, const IppsGFpECPoint *pEphPublicKeySelf, const IppsGFpECPoint *pEphPublicKeyPeer, IppsGFpECKeyExchangeSM2State *pKE)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECKeyExchangeSM2_Setup, (const Ipp8u pZSelf[IPP_SM3_DIGEST_BYTESIZE], const Ipp8u pZPeer[IPP_SM3_DIGEST_BYTESIZE], const IppsGFpECPoint *pPublicKeySelf, const IppsGFpECPoint *pPublicKeyPeer, const IppsGFpECPoint *pEphPublicKeySelf, const IppsGFpECPoint *pEphPublicKeyPeer, IppsGFpECKeyExchangeSM2State *pKE)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECKeyExchangeSM2_Setup( pZSelf, pZPeer, pPublicKeySelf, pPublicKeyPeer, pEphPublicKeySelf, pEphPublicKeyPeer, pKE ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECKeyExchangeSM2_Setup( pZSelf, pZPeer, pPublicKeySelf, pPublicKeyPeer, pEphPublicKeySelf, pEphPublicKeyPeer, pKE ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECKeyExchangeSM2_Setup( pZSelf, pZPeer, pPublicKeySelf, pPublicKeyPeer, pEphPublicKeySelf, pEphPublicKeyPeer, pKE ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_SharedKey.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_SharedKey.c new file mode 100644 index 000000000..1f36a272d --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECKeyExchangeSM2_SharedKey.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECKeyExchangeSM2_SharedKey, (Ipp8u* pSharedKey, int sharedKeySize, Ipp8u* pSSelf, const IppsBigNumState* pPrvKey, IppsBigNumState* pEphPrvKey, IppsGFpECKeyExchangeSM2State *pKE, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECKeyExchangeSM2_SharedKey, (Ipp8u* pSharedKey, int sharedKeySize, Ipp8u* pSSelf, const IppsBigNumState* pPrvKey, IppsBigNumState* pEphPrvKey, IppsGFpECKeyExchangeSM2State *pKE, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECKeyExchangeSM2_SharedKey, (Ipp8u* pSharedKey, int sharedKeySize, Ipp8u* pSSelf, const IppsBigNumState* pPrvKey, IppsBigNumState* pEphPrvKey, IppsGFpECKeyExchangeSM2State *pKE, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECKeyExchangeSM2_SharedKey, (Ipp8u* pSharedKey, int sharedKeySize, Ipp8u* pSSelf, const IppsBigNumState* pPrvKey, IppsBigNumState* pEphPrvKey, IppsGFpECKeyExchangeSM2State *pKE, Ipp8u* pScratchBuffer)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECKeyExchangeSM2_SharedKey( pSharedKey, sharedKeySize, pSSelf, pPrvKey, pEphPrvKey, pKE, pScratchBuffer ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECKeyExchangeSM2_SharedKey( pSharedKey, sharedKeySize, pSSelf, pPrvKey, pEphPrvKey, pKE, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECKeyExchangeSM2_SharedKey( pSharedKey, sharedKeySize, pSSelf, pPrvKey, pEphPrvKey, pKE, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00479.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECMakePoint.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00479.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECMakePoint.c index 89ead03d7..5e6a0c18a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00479.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECMakePoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECMakePoint,(const IppsGFpElement* pX, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECMakePoint( pX, pPoint, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECMakePoint( pX, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECMakePoint( pX, pPoint, pEC ); - } else + } 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 )) { - return h9_ippsGFpECMakePoint( pX, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECMakePoint( pX, pPoint, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECMessageRepresentationSM2.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECMessageRepresentationSM2.c new file mode 100644 index 000000000..d98a2038d --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECMessageRepresentationSM2.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECMessageRepresentationSM2, (IppsBigNumState* pMsgDigest, const Ipp8u* pMsg, int msgLen, const Ipp8u* pUserID, int userIDLen, const IppsGFpECPoint* pRegPublic, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECMessageRepresentationSM2, (IppsBigNumState* pMsgDigest, const Ipp8u* pMsg, int msgLen, const Ipp8u* pUserID, int userIDLen, const IppsGFpECPoint* pRegPublic, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECMessageRepresentationSM2, (IppsBigNumState* pMsgDigest, const Ipp8u* pMsg, int msgLen, const Ipp8u* pUserID, int userIDLen, const IppsGFpECPoint* pRegPublic, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECMessageRepresentationSM2, (IppsBigNumState* pMsgDigest, const Ipp8u* pMsg, int msgLen, const Ipp8u* pUserID, int userIDLen, const IppsGFpECPoint* pRegPublic, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECMessageRepresentationSM2( pMsgDigest, pMsg, msgLen, pUserID, userIDLen, pRegPublic, pEC, pScratchBuffer ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECMessageRepresentationSM2( pMsgDigest, pMsg, msgLen, pUserID, userIDLen, pRegPublic, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECMessageRepresentationSM2( pMsgDigest, pMsg, msgLen, pUserID, userIDLen, pRegPublic, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00494.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECMulPoint.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00494.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECMulPoint.c index aaf601c8f..aa30dbf33 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00494.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECMulPoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECMulPoint,(const IppsGFpECPoint* pP, const IppsBigNumState* pN, IppsGFpECPoint* pR, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECMulPoint( pP, pN, pR, pEC, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECMulPoint( pP, pN, pR, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECMulPoint( pP, pN, pR, pEC, pScratchBuffer ); - } else + } 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 )) { - return h9_ippsGFpECMulPoint( pP, pN, pR, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECMulPoint( pP, pN, pR, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00492.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECNegPoint.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00492.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECNegPoint.c index dcd972e53..fdbea9b24 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00492.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECNegPoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECNegPoint,(const IppsGFpECPoint* pP, IppsGFpECPoint* pR, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECNegPoint( pP, pR, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECNegPoint( pP, pR, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECNegPoint( pP, pR, pEC ); - } else + } 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 )) { - return h9_ippsGFpECNegPoint( pP, pR, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECNegPoint( pP, pR, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00473.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECPointGetSize.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00473.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECPointGetSize.c index 56e5c0eba..bdbdd0e32 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00473.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECPointGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSize)) -IPPAPI(IppStatus, l9_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSize)) IPPAPI(IppStatus, k1_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSize)) +IPPAPI(IppStatus, l9_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSize)) +IPPAPI(IppStatus, y8_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECPointGetSize( pEC, pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECPointGetSize( pEC, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECPointGetSize( pEC, pSize ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSize)) -IPPAPI(IppStatus, h9_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSize)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECPointGetSize,(const IppsGFpECState* pEC, int* pSize)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECPointGetSize( pEC, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECPointGetSize( pEC, pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00474.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECPointInit.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00474.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECPointInit.c index 53d7b0f53..1c5495930 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00474.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECPointInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECPointInit, (const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECPointInit( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECPointInit( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECPointInit( pX, pY, pPoint, pEC ); - } else + } 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 )) { - return h9_ippsGFpECPointInit( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECPointInit( pX, pY, pPoint, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00495.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECPrivateKey.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00495.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECPrivateKey.c index e94f9c75a..8140f4bb4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00495.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECPrivateKey.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECPrivateKey,(IppsBigNumState* pPrivate, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam)) -IPPAPI(IppStatus, l9_ippsGFpECPrivateKey,(IppsBigNumState* pPrivate, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam)) IPPAPI(IppStatus, k1_ippsGFpECPrivateKey,(IppsBigNumState* pPrivate, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsGFpECPrivateKey,(IppsBigNumState* pPrivate, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, y8_ippsGFpECPrivateKey,(IppsBigNumState* pPrivate, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECPrivateKey( pPrivate, pEC, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECPrivateKey( pPrivate, pEC, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECPrivateKey( pPrivate, pEC, rndFunc, pRndParam ); - } else + } 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 )) { - return h9_ippsGFpECPrivateKey( pPrivate, pEC, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECPrivateKey( pPrivate, pEC, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00496.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECPublicKey.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00496.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECPublicKey.c index 92a59fc24..b0e851568 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00496.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECPublicKey.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsGFpECPublicKey,(const IppsBigNumState* pPrivate, IppsGFpECPoint* pPublic, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECPublicKey,(const IppsBigNumState* pPrivate, IppsGFpECPoint* pPublic, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECPublicKey,(const IppsBigNumState* pPrivate, IppsGFpECPoint* pPublic, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECPublicKey( pPrivate, pPublic, pEC, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECPublicKey( pPrivate, pPublic, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECPublicKey( pPrivate, pPublic, pEC, pScratchBuffer ); - } else + } 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 )) { - return h9_ippsGFpECPublicKey( pPrivate, pPublic, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECPublicKey( pPrivate, pPublic, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00471.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECScratchBufferSize.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00471.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECScratchBufferSize.c index af64a48f5..25e21b076 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00471.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECScratchBufferSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) -IPPAPI(IppStatus, l9_ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) IPPAPI(IppStatus, k1_ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) +IPPAPI(IppStatus, l9_ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) +IPPAPI(IppStatus, y8_ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECScratchBufferSize,(int nScalars, const IppsGFpECState* pEC, int* pBufferSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECScratchBufferSize( nScalars, pEC, pBufferSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECScratchBufferSize( nScalars, pEC, pBufferSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECScratchBufferSize( nScalars, pEC, pBufferSize ); - } else + } 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 )) { - return h9_ippsGFpECScratchBufferSize( nScalars, pEC, pBufferSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECScratchBufferSize( nScalars, pEC, pBufferSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00452.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSet.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00452.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSet.c index 3be6b5a14..6e6961b04 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00452.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSet.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECSet,(const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECSet,(const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECSet,(const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECSet,(const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECSet,(const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECSet( pA, pB, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECSet( pA, pB, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECSet( pA, pB, pEC ); - } else + } 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 )) { - return h9_ippsGFpECSet( pA, pB, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSet( pA, pB, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00476.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPoint.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00476.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPoint.c index 5afda40bc..1680a601b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00476.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECSetPoint,(const IppsGFpElement* pX, const IppsGFpElement* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECSetPoint( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECSetPoint( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECSetPoint( pX, pY, pPoint, pEC ); - } else + } 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 )) { - return h9_ippsGFpECSetPoint( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSetPoint( pX, pY, pPoint, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00475.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointAtInfinity.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00475.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointAtInfinity.c index 4f46f4926..6b198143a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00475.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointAtInfinity.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECSetPointAtInfinity,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECSetPointAtInfinity( pPoint, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECSetPointAtInfinity( pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECSetPointAtInfinity( pPoint, pEC ); - } else + } 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 )) { - return h9_ippsGFpECSetPointAtInfinity( pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSetPointAtInfinity( pPoint, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00480.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointHash.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00480.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointHash.c index 97e6a93c6..f6a8948ec 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00480.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointHash.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECSetPointHash,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECSetPointHash( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECSetPointHash( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECSetPointHash( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); - } else + } 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 )) { - return h9_ippsGFpECSetPointHash( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSetPointHash( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00481.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointHashBackCompatible.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00481.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointHashBackCompatible.c index 8041e2564..4ace24968 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00481.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointHashBackCompatible.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECSetPointHashBackCompatible,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, l9_ippsGFpECSetPointHashBackCompatible,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) IPPAPI(IppStatus, k1_ippsGFpECSetPointHashBackCompatible,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECSetPointHashBackCompatible,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECSetPointHashBackCompatible,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointHashBackCompatible,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECSetPointHashBackCompatible,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECSetPointHashBackCompatible( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECSetPointHashBackCompatible( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECSetPointHashBackCompatible( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECSetPointHashBackCompatible,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, h9_ippsGFpECSetPointHashBackCompatible,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppHashAlgId hashID, Ipp8u* pScratchBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointHashBackCompatible,(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 )) { - return h9_ippsGFpECSetPointHashBackCompatible( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSetPointHashBackCompatible( hdr, pMsg, msgLen, pPoint, pEC, hashID, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00483.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointHashBackCompatible_rmf.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00483.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointHashBackCompatible_rmf.c index ea1c754e4..59973e41a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00483.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointHashBackCompatible_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECSetPointHashBackCompatible_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, l9_ippsGFpECSetPointHashBackCompatible_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) IPPAPI(IppStatus, k1_ippsGFpECSetPointHashBackCompatible_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECSetPointHashBackCompatible_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECSetPointHashBackCompatible_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointHashBackCompatible_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECSetPointHashBackCompatible_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECSetPointHashBackCompatible_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECSetPointHashBackCompatible_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECSetPointHashBackCompatible_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECSetPointHashBackCompatible_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, h9_ippsGFpECSetPointHashBackCompatible_rmf,(Ipp32u hdr, const Ipp8u* pMsg, int msgLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC, const IppsHashMethod* pMethod, Ipp8u* pScratchBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointHashBackCompatible_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 )) { - return h9_ippsGFpECSetPointHashBackCompatible_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSetPointHashBackCompatible_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00482.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointHash_rmf.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00482.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointHash_rmf.c index 596f91203..654156148 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00482.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointHash_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECSetPointHash_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECSetPointHash_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECSetPointHash_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); - } else + } 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 )) { - return h9_ippsGFpECSetPointHash_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSetPointHash_rmf( hdr, pMsg, msgLen, pPoint, pEC, pMethod, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00486.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointOctString.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00486.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointOctString.c index 264f5f537..d64f9e4f7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00486.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointOctString.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECSetPointOctString,(const Ipp8u* pStr, int strLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECSetPointOctString,(const Ipp8u* pStr, int strLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECSetPointOctString,(const Ipp8u* pStr, int strLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECSetPointOctString,(const Ipp8u* pStr, int strLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECSetPointOctString,(const Ipp8u* pStr, int strLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointOctString,(const Ipp8u* pStr, int strLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECSetPointOctString,(const Ipp8u* pStr, int strLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECSetPointOctString( pStr, strLen, pPoint, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECSetPointOctString( pStr, strLen, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECSetPointOctString( pStr, strLen, pPoint, pEC ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpECSetPointOctString,(const Ipp8u* pStr, int strLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -IPPAPI(IppStatus, h9_ippsGFpECSetPointOctString,(const Ipp8u* pStr, int strLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECSetPointOctString,(const Ipp8u* pStr, int strLen, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECSetPointOctString( pStr, strLen, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSetPointOctString( pStr, strLen, pPoint, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00478.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointRandom.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00478.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointRandom.c index 6bcdb99bf..5c6b7b891 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00478.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointRandom.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECSetPointRandom,(IppsGFpECPoint* pPoint, IppsGFpECState* pEC, IppBitSupplier rndFunc, void* pRndParam, Ipp8u* pScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECSetPointRandom( pPoint, pEC, rndFunc, pRndParam, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECSetPointRandom( pPoint, pEC, rndFunc, pRndParam, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECSetPointRandom( pPoint, pEC, rndFunc, pRndParam, pScratchBuffer ); - } else + } 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 )) { - return h9_ippsGFpECSetPointRandom( pPoint, pEC, rndFunc, pRndParam, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSetPointRandom( pPoint, pEC, rndFunc, pRndParam, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00477.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointRegular.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00477.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointRegular.c index 7d55b17f7..3f6fbbcf4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00477.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetPointRegular.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECSetPointRegular,(const IppsBigNumState* pX, const IppsBigNumState* pY, IppsGFpECPoint* pPoint, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECSetPointRegular( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECSetPointRegular( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECSetPointRegular( pX, pY, pPoint, pEC ); - } else + } 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 )) { - return h9_ippsGFpECSetPointRegular( pX, pY, pPoint, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSetPointRegular( pX, pY, pPoint, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00453.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetSubgroup.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00453.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetSubgroup.c index 770cac9b9..dea90103d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00453.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSetSubgroup.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECSetSubgroup,(const IppsGFpElement* pX, const IppsGFpElement* pY, const IppsBigNumState* pOrder, const IppsBigNumState* pCofactor, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECSetSubgroup( pX, pY, pOrder, pCofactor, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECSetSubgroup( pX, pY, pOrder, pCofactor, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECSetSubgroup( pX, pY, pOrder, pCofactor, pEC ); - } else + } 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 )) { - return h9_ippsGFpECSetSubgroup( pX, pY, pOrder, pCofactor, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSetSubgroup( pX, pY, pOrder, pCofactor, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00498.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSharedSecretDH.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00498.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSharedSecretDH.c index f1f184c2d..bc645bea4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00498.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSharedSecretDH.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECSharedSecretDH,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECSharedSecretDH( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECSharedSecretDH( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECSharedSecretDH( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); - } else + } 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 )) { - return h9_ippsGFpECSharedSecretDH( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSharedSecretDH( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00499.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSharedSecretDHC.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00499.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSharedSecretDHC.c index e33ee2597..318ca5706 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00499.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSharedSecretDHC.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECSharedSecretDHC,(const IppsBigNumState* pPrivateA, const IppsGFpECPoint* pPublicB, IppsBigNumState* pShare, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); - } else + } 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 )) { - return h9_ippsGFpECSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSharedSecretDHC( pPrivateA, pPublicB, pShare, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSignDSA.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSignDSA.c new file mode 100644 index 000000000..e4228f723 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSignDSA.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECSignDSA, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECSignDSA, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECSignDSA, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECSignDSA, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECSignDSA( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECSignDSA( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECSignDSA( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSignNR.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSignNR.c new file mode 100644 index 000000000..d03150332 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSignNR.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECSignNR, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECSignNR, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECSignNR, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECSignNR, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECSignNR( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECSignNR( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECSignNR( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSignSM2.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSignSM2.c new file mode 100644 index 000000000..c2bc626ab --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECSignSM2.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECSignSM2, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECSignSM2, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECSignSM2, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECSignSM2, (const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00497.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECTstKeyPair.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00497.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECTstKeyPair.c index 8b671aa1e..5c86a9cdd 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00497.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECTstKeyPair.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECTstKeyPair,(const IppsBigNumState* pPrivate, const IppsGFpECPoint* pPublic, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECTstKeyPair( pPrivate, pPublic, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECTstKeyPair( pPrivate, pPublic, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECTstKeyPair( pPrivate, pPublic, pResult, pEC, pScratchBuffer ); - } else + } 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 )) { - return h9_ippsGFpECTstKeyPair( pPrivate, pPublic, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECTstKeyPair( pPrivate, pPublic, pResult, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00488.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECTstPoint.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00488.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECTstPoint.c index 524a4f02e..1ae5e0d5b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00488.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECTstPoint.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) -IPPAPI(IppStatus, l9_ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) IPPAPI(IppStatus, k1_ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) +IPPAPI(IppStatus, l9_ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) +IPPAPI(IppStatus, y8_ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECTstPoint,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECTstPoint( pP, pResult, pEC ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECTstPoint( pP, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECTstPoint( pP, pResult, pEC ); - } else + } 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 )) { - return h9_ippsGFpECTstPoint( pP, pResult, pEC ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECTstPoint( pP, pResult, pEC ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00489.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECTstPointInSubgroup.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00489.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECTstPointInSubgroup.c index 95dd530de..f95328d3e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00489.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECTstPointInSubgroup.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsGFpECTstPointInSubgroup,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECTstPointInSubgroup,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECTstPointInSubgroup,(const IppsGFpECPoint* pP, IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECTstPointInSubgroup( pP, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECTstPointInSubgroup( pP, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECTstPointInSubgroup( pP, pResult, pEC, pScratchBuffer ); - } else + } 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 )) { - return h9_ippsGFpECTstPointInSubgroup( pP, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECTstPointInSubgroup( pP, pResult, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECUserIDHashSM2.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECUserIDHashSM2.c new file mode 100644 index 000000000..96ad52269 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECUserIDHashSM2.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_ippsGFpECUserIDHashSM2, (Ipp8u* pZaDigest, const Ipp8u* pUserID, int userIDLen, const IppsGFpECPoint* pPublicKey, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECUserIDHashSM2, (Ipp8u* pZaDigest, const Ipp8u* pUserID, int userIDLen, const IppsGFpECPoint* pPublicKey, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECUserIDHashSM2, (Ipp8u* pZaDigest, const Ipp8u* pUserID, int userIDLen, const IppsGFpECPoint* pPublicKey, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) + +IPPFUN(IppStatus, sgx_disp_ippsGFpECUserIDHashSM2, (Ipp8u* pZaDigest, const Ipp8u* pUserID, int userIDLen, const IppsGFpECPoint* pPublicKey, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECUserIDHashSM2( pZaDigest, pUserID, userIDLen, pPublicKey, pEC, pScratchBuffer ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECUserIDHashSM2( pZaDigest, pUserID, userIDLen, pPublicKey, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECUserIDHashSM2( pZaDigest, pUserID, userIDLen, pPublicKey, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00472.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerify.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00472.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerify.c index c441f18bf..1c295152c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00472.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerify.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, l9_ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) IPPAPI(IppStatus, k1_ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsGFpECVerify,(IppECResult* pResult, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpECVerify( pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpECVerify( pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpECVerify( pResult, pEC, pScratchBuffer ); - } else + } 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 )) { - return h9_ippsGFpECVerify( pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECVerify( pResult, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerifyDSA.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerifyDSA.c new file mode 100644 index 000000000..1ce8d5b44 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerifyDSA.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECVerifyDSA( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECVerifyDSA( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECVerifyDSA( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerifyNR.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerifyNR.c new file mode 100644 index 000000000..cd26ad18c --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerifyNR.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECVerifyNR( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECVerifyNR( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECVerifyNR( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerifySM2.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerifySM2.c new file mode 100644 index 000000000..7bc0126a0 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpECVerifySM2.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsGFpECVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsGFpECVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsGFpECVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00422.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpElementGetSize.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00422.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpElementGetSize.c index ab9e50d17..7b39871b9 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00422.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpElementGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) -IPPAPI(IppStatus, l9_ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) IPPAPI(IppStatus, k1_ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) +IPPAPI(IppStatus, l9_ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) +IPPAPI(IppStatus, y8_ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) -IPPFUN(IppStatus,sgx_disp_ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) +IPPFUN(IppStatus, sgx_disp_ippsGFpElementGetSize,(const IppsGFpState* pGFp, int* pElementSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpElementGetSize( pGFp, pElementSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpElementGetSize( pGFp, pElementSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpElementGetSize( pGFp, pElementSize ); - } else + } 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 )) { - return h9_ippsGFpElementGetSize( pGFp, pElementSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpElementGetSize( pGFp, pElementSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00423.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpElementInit.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00423.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpElementInit.c index ff948a1e4..0669cb1ad 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00423.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpElementInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsGFpElementInit, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpElementInit, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpElementInit, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpElementInit( pA, lenA, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpElementInit( pA, lenA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpElementInit( pA, lenA, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpElementInit( pA, lenA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpElementInit( pA, lenA, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00444.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpExp.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00444.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpExp.c index 17c412837..e628e90f0 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00444.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpExp.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpExp, (const IppsGFpElement* pA, const IppsBigNumState* pE, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpExp( pA, pE, pR, pGFp, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpExp( pA, pE, pR, pGFp, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpExp( pA, pE, pR, pGFp, pScratchBuffer ); - } else + } 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 )) { - return h9_ippsGFpExp( pA, pE, pR, pGFp, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpExp( pA, pE, pR, pGFp, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00431.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpGetElement.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00431.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpGetElement.c index 78cbf94c8..90b984acd 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00431.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpGetElement.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int lenA, IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int lenA, IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int lenA, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int lenA, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int lenA, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int lenA, IppsGFpState* pGFp)) +IPPFUN(IppStatus, sgx_disp_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int lenA, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpGetElement( pA, pDataA, lenA, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpGetElement( pA, pDataA, lenA, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpGetElement( pA, pDataA, lenA, pGFp ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int lenA, IppsGFpState* pGFp)) -IPPAPI(IppStatus, h9_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int lenA, IppsGFpState* pGFp)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpGetElement,(const IppsGFpElement* pA, Ipp32u* pDataA, int lenA, IppsGFpState* pGFp)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpGetElement( pA, pDataA, lenA, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpGetElement( pA, pDataA, lenA, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00432.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpGetElementOctString.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00432.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpGetElementOctString.c index 9f2b1a17d..66a24ab87 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00432.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpGetElementOctString.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsGFpGetElementOctString,(const IppsGFpElement* pA, Ipp8u* pStr, int strSize, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpGetElementOctString,(const IppsGFpElement* pA, Ipp8u* pStr, int strSize, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpGetElementOctString,(const IppsGFpElement* pA, Ipp8u* pStr, int strSize, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpGetElementOctString( pA, pStr, strSize, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpGetElementOctString( pA, pStr, strSize, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpGetElementOctString( pA, pStr, strSize, pGFp ); - } else + } 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 )) { - return h9_ippsGFpGetElementOctString( pA, pStr, strSize, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpGetElementOctString( pA, pStr, strSize, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00449.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpGetInfo.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00449.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpGetInfo.c index 559e7855b..51dd52782 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00449.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpGetInfo.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpGetInfo, (IppsGFpInfo* pInfo, const IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpGetInfo, (IppsGFpInfo* pInfo, const IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpGetInfo, (IppsGFpInfo* pInfo, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpGetInfo, (IppsGFpInfo* pInfo, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpGetInfo, (IppsGFpInfo* pInfo, const IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_ippsGFpGetInfo, (IppsGFpInfo* pInfo, const IppsGFpState* pGFp)) +IPPFUN(IppStatus, sgx_disp_ippsGFpGetInfo, (IppsGFpInfo* pInfo, const IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpGetInfo( pInfo, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpGetInfo( pInfo, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpGetInfo( pInfo, pGFp ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpGetInfo, (IppsGFpInfo* pInfo, const IppsGFpState* pGFp)) -IPPAPI(IppStatus, h9_ippsGFpGetInfo, (IppsGFpInfo* pInfo, const IppsGFpState* pGFp)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpGetInfo, (IppsGFpInfo* pInfo, const IppsGFpState* pGFp)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpGetInfo( pInfo, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpGetInfo( pInfo, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00399.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpGetSize.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00399.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpGetSize.c index c06b06223..9217a63a2 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00399.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpGetSize, (int feBitSize, int* pSize)) -IPPAPI(IppStatus, l9_ippsGFpGetSize, (int feBitSize, int* pSize)) IPPAPI(IppStatus, k1_ippsGFpGetSize, (int feBitSize, int* pSize)) +IPPAPI(IppStatus, l9_ippsGFpGetSize, (int feBitSize, int* pSize)) +IPPAPI(IppStatus, y8_ippsGFpGetSize, (int feBitSize, int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsGFpGetSize, (int feBitSize, int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsGFpGetSize, (int feBitSize, int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpGetSize( feBitSize, pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpGetSize( feBitSize, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpGetSize( feBitSize, pSize ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpGetSize, (int feBitSize, int* pSize)) -IPPAPI(IppStatus, h9_ippsGFpGetSize, (int feBitSize, int* pSize)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpGetSize, (int feBitSize, int* pSize)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpGetSize( feBitSize, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpGetSize( feBitSize, pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00402.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpInit.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00402.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpInit.c index 129e0292a..e89c22bf0 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00402.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) +IPPFUN(IppStatus, sgx_disp_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpInit( pPrime, primeBitSize, pGFpMethod, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpInit( pPrime, primeBitSize, pGFpMethod, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpInit( pPrime, primeBitSize, pGFpMethod, pGFp ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) -IPPAPI(IppStatus, h9_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpInit, (const IppsBigNumState* pPrime, int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpInit( pPrime, primeBitSize, pGFpMethod, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpInit( pPrime, primeBitSize, pGFpMethod, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00400.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpInitArbitrary.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00400.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpInitArbitrary.c index 1a6e33a3f..1c2660e8a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00400.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpInitArbitrary.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGFp)) +IPPFUN(IppStatus, sgx_disp_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpInitArbitrary( pPrime, primeBitSize, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpInitArbitrary( pPrime, primeBitSize, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpInitArbitrary( pPrime, primeBitSize, pGFp ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGFp)) -IPPAPI(IppStatus, h9_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGFp)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpInitArbitrary,(const IppsBigNumState* pPrime, int primeBitSize, IppsGFpState* pGFp)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpInitArbitrary( pPrime, primeBitSize, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpInitArbitrary( pPrime, primeBitSize, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00401.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpInitFixed.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00401.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpInitFixed.c index 1a775bc54..b446c1af2 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00401.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpInitFixed.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) +IPPFUN(IppStatus, sgx_disp_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpInitFixed( primeBitSize, pGFpMethod, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpInitFixed( primeBitSize, pGFpMethod, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpInitFixed( primeBitSize, pGFpMethod, pGFp ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) -IPPAPI(IppStatus, h9_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpInitFixed,(int primeBitSize, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFp)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpInitFixed( primeBitSize, pGFpMethod, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpInitFixed( primeBitSize, pGFpMethod, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00438.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpInv.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00438.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpInv.c index e94d60521..9eaf47650 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00438.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpInv.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPFUN(IppStatus, sgx_disp_ippsGFpInv, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpInv( pA, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpInv( pA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpInv( pA, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpInv( pA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpInv( pA, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00435.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpIsUnityElement.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00435.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpIsUnityElement.c index 6c83019b9..a14ba7c80 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00435.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpIsUnityElement.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpIsUnityElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpIsUnityElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpIsUnityElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpIsUnityElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpIsUnityElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpIsUnityElement( pA, pResult, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpIsUnityElement( pA, pResult, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpIsUnityElement( pA, pResult, pGFp ); - } else + } 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 )) { - return h9_ippsGFpIsUnityElement( pA, pResult, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpIsUnityElement( pA, pResult, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00434.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpIsZeroElement.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00434.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpIsZeroElement.c index b242896af..c892ebc05 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00434.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpIsZeroElement.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpIsZeroElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpIsZeroElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpIsZeroElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpIsZeroElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpIsZeroElement,(const IppsGFpElement* pA, int* pResult, const IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpIsZeroElement( pA, pResult, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpIsZeroElement( pA, pResult, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpIsZeroElement( pA, pResult, pGFp ); - } else + } 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 )) { - return h9_ippsGFpIsZeroElement( pA, pResult, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpIsZeroElement( pA, pResult, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00403.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p192r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00403.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p192r1.c index 93b0a8d1d..2fb95de19 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00403.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p192r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p192r1, (void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p192r1, (void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpMethod_p192r1, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p192r1, (void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p192r1, (void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p192r1, (void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpMethod_p192r1, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpMethod_p192r1( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpMethod_p192r1( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpMethod_p192r1( ); - } else + } 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 )) { - return h9_ippsGFpMethod_p192r1( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpMethod_p192r1( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00404.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p224r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00404.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p224r1.c index 97ecfc9aa..aa0fa6bad 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00404.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p224r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p224r1, (void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p224r1, (void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpMethod_p224r1, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p224r1, (void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p224r1, (void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p224r1, (void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpMethod_p224r1, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpMethod_p224r1( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpMethod_p224r1( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpMethod_p224r1( ); - } else + } 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 )) { - return h9_ippsGFpMethod_p224r1( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpMethod_p224r1( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00410.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p256.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00410.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p256.c index 5ce757540..cbcaa6e06 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00410.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p256.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p256, (void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p256, (void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpMethod_p256, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p256, (void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p256, (void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p256, (void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpMethod_p256, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpMethod_p256( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpMethod_p256( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpMethod_p256( ); - } else + } 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 )) { - return h9_ippsGFpMethod_p256( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpMethod_p256( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00409.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p256bn.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00409.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p256bn.c index 259e5ed06..5ffaa507a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00409.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p256bn.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p256bn, (void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p256bn, (void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpMethod_p256bn, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p256bn, (void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p256bn, (void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p256bn, (void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpMethod_p256bn, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpMethod_p256bn( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpMethod_p256bn( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpMethod_p256bn( ); - } else + } 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 )) { - return h9_ippsGFpMethod_p256bn( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpMethod_p256bn( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00405.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p256r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00405.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p256r1.c index dbb53b434..8168b3540 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00405.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p256r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p256r1, (void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p256r1, (void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpMethod_p256r1, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p256r1, (void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p256r1, (void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p256r1, (void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpMethod_p256r1, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpMethod_p256r1( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpMethod_p256r1( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpMethod_p256r1( ); - } else + } 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 )) { - return h9_ippsGFpMethod_p256r1( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpMethod_p256r1( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00408.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p256sm2.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00408.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p256sm2.c index fa4567e31..0967af995 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00408.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p256sm2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p256sm2,(void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p256sm2,(void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpMethod_p256sm2,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p256sm2,(void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p256sm2,(void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p256sm2,(void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpMethod_p256sm2,(void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpMethod_p256sm2( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpMethod_p256sm2( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpMethod_p256sm2( ); - } else + } 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 )) { - return h9_ippsGFpMethod_p256sm2( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpMethod_p256sm2( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00406.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p384r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00406.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p384r1.c index 3171bfe48..572eee4f4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00406.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p384r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p384r1, (void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p384r1, (void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpMethod_p384r1, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p384r1, (void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p384r1, (void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p384r1, (void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpMethod_p384r1, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpMethod_p384r1( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpMethod_p384r1( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpMethod_p384r1( ); - } else + } 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 )) { - return h9_ippsGFpMethod_p384r1( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpMethod_p384r1( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00407.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p521r1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00407.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p521r1.c index 4faccbf07..5e8ce6f6e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00407.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_p521r1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p521r1, (void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p521r1, (void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpMethod_p521r1, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_p521r1, (void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_p521r1, (void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_p521r1, (void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpMethod_p521r1, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpMethod_p521r1( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpMethod_p521r1( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpMethod_p521r1( ); - } else + } 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 )) { - return h9_ippsGFpMethod_p521r1( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpMethod_p521r1( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00411.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_pArb.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00411.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_pArb.c index 0ef1a1b6c..db3914725 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00411.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMethod_pArb.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_pArb, (void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_pArb, (void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpMethod_pArb, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpMethod_pArb, (void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpMethod_pArb, (void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpMethod_pArb, (void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpMethod_pArb, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpMethod_pArb( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpMethod_pArb( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpMethod_pArb( ); - } else + } 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 )) { - return h9_ippsGFpMethod_pArb( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpMethod_pArb( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00443.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMul.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00443.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMul.c index 809d22557..61bd884c2 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00443.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMul.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpMul, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpMul( pA, pB, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpMul( pA, pB, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpMul( pA, pB, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpMul( pA, pB, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpMul( pA, pB, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00448.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMul_PE.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00448.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMul_PE.c index 09023668c..641752df7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00448.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMul_PE.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpMul_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpMul_PE( pA, pParentB, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpMul_PE( pA, pParentB, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpMul_PE( pA, pParentB, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpMul_PE( pA, pParentB, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpMul_PE( pA, pParentB, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00445.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMultiExp.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00445.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMultiExp.c index c57c0964b..32ba1bf9e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00445.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpMultiExp.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, l9_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) IPPAPI(IppStatus, k1_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, l9_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) +IPPAPI(IppStatus, y8_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpMultiExp( ppElmA, ppE, nItems, pR, pGFp, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpMultiExp( ppElmA, ppE, nItems, pR, pGFp, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpMultiExp( ppElmA, ppE, nItems, pR, pGFp, pScratchBuffer ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, h9_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpMultiExp,(const IppsGFpElement* const ppElmA[], const IppsBigNumState* const ppE[], int nItems, IppsGFpElement* pR, IppsGFpState* pGFp, Ipp8u* pScratchBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpMultiExp( ppElmA, ppE, nItems, pR, pGFp, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpMultiExp( ppElmA, ppE, nItems, pR, pGFp, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00437.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpNeg.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00437.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpNeg.c index fb75555b0..7a50ef285 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00437.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpNeg.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPFUN(IppStatus, sgx_disp_ippsGFpNeg, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpNeg( pA, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpNeg( pA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpNeg( pA, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpNeg( pA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpNeg( pA, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00421.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpScratchBufferSize.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00421.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpScratchBufferSize.c index f399a3a55..f8672b395 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00421.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpScratchBufferSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGFp, int* pBufferSize)) -IPPAPI(IppStatus, l9_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGFp, int* pBufferSize)) IPPAPI(IppStatus, k1_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGFp, int* pBufferSize)) +IPPAPI(IppStatus, l9_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGFp, int* pBufferSize)) +IPPAPI(IppStatus, y8_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGFp, int* pBufferSize)) -IPPFUN(IppStatus,sgx_disp_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGFp, int* pBufferSize)) +IPPFUN(IppStatus, sgx_disp_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGFp, int* pBufferSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpScratchBufferSize( nExponents, ExpBitSize, pGFp, pBufferSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpScratchBufferSize( nExponents, ExpBitSize, pGFp, pBufferSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpScratchBufferSize( nExponents, ExpBitSize, pGFp, pBufferSize ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGFp, int* pBufferSize)) -IPPAPI(IppStatus, h9_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGFp, int* pBufferSize)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpScratchBufferSize,(int nExponents, int ExpBitSize, const IppsGFpState* pGFp, int* pBufferSize)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpScratchBufferSize( nExponents, ExpBitSize, pGFp, pBufferSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpScratchBufferSize( nExponents, ExpBitSize, pGFp, pBufferSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00424.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElement.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00424.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElement.c index 2964fafe4..fad6aae00 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00424.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElement.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpSetElement, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpSetElement, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpSetElement, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpSetElement, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpSetElement, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_ippsGFpSetElement, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPFUN(IppStatus, sgx_disp_ippsGFpSetElement, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpSetElement( pA, lenA, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpSetElement( pA, lenA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpSetElement( pA, lenA, pR, pGFp ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpSetElement, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, h9_ippsGFpSetElement, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpSetElement, (const Ipp32u* pA, int lenA, IppsGFpElement* pR, IppsGFpState* pGFp)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpSetElement( pA, lenA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpSetElement( pA, lenA, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00428.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementHash.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00428.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementHash.c index e6ee8a16f..f0c92ccb4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00428.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementHash.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, IppHashAlgId hashID)) -IPPAPI(IppStatus, l9_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, IppHashAlgId hashID)) IPPAPI(IppStatus, k1_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, IppHashAlgId hashID)) +IPPAPI(IppStatus, l9_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, IppHashAlgId hashID)) +IPPAPI(IppStatus, y8_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, IppHashAlgId hashID)) -IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, IppHashAlgId hashID)) +IPPFUN(IppStatus, sgx_disp_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, IppHashAlgId hashID)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpSetElementHash( pMsg, msgLen, pElm, pGFp, hashID ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpSetElementHash( pMsg, msgLen, pElm, pGFp, hashID ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpSetElementHash( pMsg, msgLen, pElm, pGFp, hashID ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, IppHashAlgId hashID)) -IPPAPI(IppStatus, h9_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, IppHashAlgId hashID)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementHash,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, IppHashAlgId hashID)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpSetElementHash( pMsg, msgLen, pElm, pGFp, hashID ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpSetElementHash( pMsg, msgLen, pElm, pGFp, hashID ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00429.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementHash_rmf.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00429.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementHash_rmf.c index b35f07435..e7c99d2d4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00429.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementHash_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, const IppsHashMethod* pMethod)) -IPPAPI(IppStatus, l9_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, const IppsHashMethod* pMethod)) IPPAPI(IppStatus, k1_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, l9_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, y8_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, const IppsHashMethod* pMethod)) -IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, const IppsHashMethod* pMethod)) +IPPFUN(IppStatus, sgx_disp_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, const IppsHashMethod* pMethod)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpSetElementHash_rmf( pMsg, msgLen, pElm, pGFp, pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpSetElementHash_rmf( pMsg, msgLen, pElm, pGFp, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpSetElementHash_rmf( pMsg, msgLen, pElm, pGFp, pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, const IppsHashMethod* pMethod)) -IPPAPI(IppStatus, h9_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, const IppsHashMethod* pMethod)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementHash_rmf,(const Ipp8u* pMsg, int msgLen, IppsGFpElement* pElm, IppsGFpState* pGFp, const IppsHashMethod* pMethod)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpSetElementHash_rmf( pMsg, msgLen, pElm, pGFp, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpSetElementHash_rmf( pMsg, msgLen, pElm, pGFp, pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00426.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementOctString.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00426.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementOctString.c index 58b75786b..bd8d1476f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00426.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementOctString.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsGFpSetElementOctString,(const Ipp8u* pStr, int strSize, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpSetElementOctString,(const Ipp8u* pStr, int strSize, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpSetElementOctString,(const Ipp8u* pStr, int strSize, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpSetElementOctString( pStr, strSize, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpSetElementOctString( pStr, strSize, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpSetElementOctString( pStr, strSize, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpSetElementOctString( pStr, strSize, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpSetElementOctString( pStr, strSize, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00427.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementRandom.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00427.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementRandom.c index ab24f3abe..192259705 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00427.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementRandom.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpSetElementRandom,(IppsGFpElement* pR, IppsGFpState* pGFp, IppBitSupplier rndFunc, void* pRndParam)) -IPPAPI(IppStatus, l9_ippsGFpSetElementRandom,(IppsGFpElement* pR, IppsGFpState* pGFp, IppBitSupplier rndFunc, void* pRndParam)) IPPAPI(IppStatus, k1_ippsGFpSetElementRandom,(IppsGFpElement* pR, IppsGFpState* pGFp, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, l9_ippsGFpSetElementRandom,(IppsGFpElement* pR, IppsGFpState* pGFp, IppBitSupplier rndFunc, void* pRndParam)) +IPPAPI(IppStatus, y8_ippsGFpSetElementRandom,(IppsGFpElement* pR, IppsGFpState* pGFp, IppBitSupplier rndFunc, void* pRndParam)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpSetElementRandom( pR, pGFp, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpSetElementRandom( pR, pGFp, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpSetElementRandom( pR, pGFp, rndFunc, pRndParam ); - } else + } 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 )) { - return h9_ippsGFpSetElementRandom( pR, pGFp, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpSetElementRandom( pR, pGFp, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00425.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementRegular.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00425.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementRegular.c index 1deff464f..41e80c601 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00425.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSetElementRegular.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pR, IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPFUN(IppStatus, sgx_disp_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpSetElementRegular( pBN, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpSetElementRegular( pBN, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpSetElementRegular( pBN, pR, pGFp ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, h9_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pR, IppsGFpState* pGFp)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpSetElementRegular,(const IppsBigNumState* pBN, IppsGFpElement* pR, IppsGFpState* pGFp)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpSetElementRegular( pBN, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpSetElementRegular( pBN, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00440.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSqr.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00440.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSqr.c index 1c596b1b4..4d62f4ba8 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00440.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSqr.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPFUN(IppStatus, sgx_disp_ippsGFpSqr, (const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpSqr( pA, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpSqr( pA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpSqr( pA, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpSqr( pA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpSqr( pA, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00439.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSqrt.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00439.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSqrt.c index 812dfecdb..4b2ae0d49 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00439.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSqrt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPAPI(IppStatus, l9_ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) IPPAPI(IppStatus, k1_ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, l9_ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPAPI(IppStatus, y8_ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) -IPPFUN(IppStatus,sgx_disp_ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) +IPPFUN(IppStatus, sgx_disp_ippsGFpSqrt,(const IppsGFpElement* pA, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpSqrt( pA, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpSqrt( pA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpSqrt( pA, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpSqrt( pA, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpSqrt( pA, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00442.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSub.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00442.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSub.c index 95eb94c35..7af4d6863 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00442.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSub.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpSub, (const IppsGFpElement* pA, const IppsGFpElement* pB, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpSub( pA, pB, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpSub( pA, pB, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpSub( pA, pB, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpSub( pA, pB, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpSub( pA, pB, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00447.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSub_PE.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00447.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSub_PE.c index 4d53d862f..964830f6f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00447.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpSub_PE.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGFpSub_PE,(const IppsGFpElement* pA, const IppsGFpElement* pParentB, IppsGFpElement* pR, IppsGFpState* pGFp)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpSub_PE( pA, pParentB, pR, pGFp ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpSub_PE( pA, pParentB, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpSub_PE( pA, pParentB, pR, pGFp ); - } else + } 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 )) { - return h9_ippsGFpSub_PE( pA, pParentB, pR, pGFp ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpSub_PE( pA, pParentB, pR, pGFp ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00412.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxGetSize.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00412.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxGetSize.c index e3f53292f..50d443bdc 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00412.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pSize)) -IPPAPI(IppStatus, l9_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pSize)) IPPAPI(IppStatus, k1_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pSize)) +IPPAPI(IppStatus, l9_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pSize)) +IPPAPI(IppStatus, y8_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpxGetSize( pGroundGF, degree, pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpxGetSize( pGroundGF, degree, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpxGetSize( pGroundGF, degree, pSize ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pSize)) -IPPAPI(IppStatus, h9_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pSize)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpxGetSize,(const IppsGFpState* pGroundGF, int degree, int* pSize)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpxGetSize( pGroundGF, degree, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpxGetSize( pGroundGF, degree, pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00413.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxInit.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00413.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxInit.c index 08315ec24..b5b8853b9 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00413.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int nElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) -IPPAPI(IppStatus, l9_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int nElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) IPPAPI(IppStatus, k1_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int nElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) +IPPAPI(IppStatus, l9_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int nElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) +IPPAPI(IppStatus, y8_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int nElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) -IPPFUN(IppStatus,sgx_disp_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int nElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) +IPPFUN(IppStatus, sgx_disp_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int nElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpxInit( pGroundGF, extDeg, ppGroundElm, nElm, pGFpMethod, pGFpx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpxInit( pGroundGF, extDeg, ppGroundElm, nElm, pGFpMethod, pGFpx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpxInit( pGroundGF, extDeg, ppGroundElm, nElm, pGFpMethod, pGFpx ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int nElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) -IPPAPI(IppStatus, h9_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int nElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpxInit, (const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* const ppGroundElm[], int nElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpxInit( pGroundGF, extDeg, ppGroundElm, nElm, pGFpMethod, pGFpx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpxInit( pGroundGF, extDeg, ppGroundElm, nElm, pGFpMethod, pGFpx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00414.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxInitBinomial.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00414.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxInitBinomial.c index cc5b4ec4a..5095c9cbc 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00414.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxInitBinomial.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) -IPPAPI(IppStatus, l9_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) IPPAPI(IppStatus, k1_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) +IPPAPI(IppStatus, l9_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) +IPPAPI(IppStatus, y8_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) -IPPFUN(IppStatus,sgx_disp_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) +IPPFUN(IppStatus, sgx_disp_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpxInitBinomial( pGroundGF, extDeg, pGroundElm, pGFpMethod, pGFpx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpxInitBinomial( pGroundGF, extDeg, pGroundElm, pGFpMethod, pGFpx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpxInitBinomial( pGroundGF, extDeg, pGroundElm, pGFpMethod, pGFpx ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) -IPPAPI(IppStatus, h9_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpxInitBinomial,(const IppsGFpState* pGroundGF, int extDeg, const IppsGFpElement* pGroundElm, const IppsGFpMethod* pGFpMethod, IppsGFpState* pGFpx)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpxInitBinomial( pGroundGF, extDeg, pGroundElm, pGFpMethod, pGFpx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpxInitBinomial( pGroundGF, extDeg, pGroundElm, pGFpMethod, pGFpx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00419.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00419.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom.c index d5ea80e1d..7c0f894e1 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00419.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom, (void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom, (void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpxMethod_binom, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom, (void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom, (void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom, (void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpxMethod_binom, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpxMethod_binom( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpxMethod_binom( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpxMethod_binom( ); - } else + } 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 )) { - return h9_ippsGFpxMethod_binom( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpxMethod_binom( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00417.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom2.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00417.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom2.c index d1bba7724..615633268 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00417.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom2, (void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom2, (void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpxMethod_binom2, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom2, (void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom2, (void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom2, (void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpxMethod_binom2, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpxMethod_binom2( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpxMethod_binom2( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpxMethod_binom2( ); - } else + } 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 )) { - return h9_ippsGFpxMethod_binom2( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpxMethod_binom2( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00415.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom2_epid2.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00415.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom2_epid2.c index 96cb69028..47124df67 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00415.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom2_epid2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom2_epid2,(void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom2_epid2,(void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpxMethod_binom2_epid2,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom2_epid2,(void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom2_epid2,(void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom2_epid2,(void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpxMethod_binom2_epid2,(void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpxMethod_binom2_epid2( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpxMethod_binom2_epid2( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpxMethod_binom2_epid2( ); - } else + } 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 )) { - return h9_ippsGFpxMethod_binom2_epid2( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpxMethod_binom2_epid2( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00418.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom3.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00418.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom3.c index 3ce759c8e..72f68e39e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00418.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom3.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom3, (void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom3, (void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpxMethod_binom3, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom3, (void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom3, (void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom3, (void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpxMethod_binom3, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpxMethod_binom3( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpxMethod_binom3( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpxMethod_binom3( ); - } else + } 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 )) { - return h9_ippsGFpxMethod_binom3( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpxMethod_binom3( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00416.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom3_epid2.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00416.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom3_epid2.c index c4782e75a..7ddcca3f9 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00416.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_binom3_epid2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom3_epid2,(void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom3_epid2,(void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpxMethod_binom3_epid2,(void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_binom3_epid2,(void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_binom3_epid2,(void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_binom3_epid2,(void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpxMethod_binom3_epid2,(void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpxMethod_binom3_epid2( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpxMethod_binom3_epid2( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpxMethod_binom3_epid2( ); - } else + } 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 )) { - return h9_ippsGFpxMethod_binom3_epid2( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpxMethod_binom3_epid2( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00420.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_com.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00420.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_com.c index a450768b6..5abfc2002 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00420.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGFpxMethod_com.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_com, (void) ) -IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_com, (void) ) IPPAPI( const IppsGFpMethod*, k1_ippsGFpxMethod_com, (void) ) +IPPAPI( const IppsGFpMethod*, l9_ippsGFpxMethod_com, (void) ) +IPPAPI( const IppsGFpMethod*, y8_ippsGFpxMethod_com, (void) ) -IPPFUN( const IppsGFpMethod*,sgx_disp_ippsGFpxMethod_com, (void) ) +IPPFUN( const IppsGFpMethod*, sgx_disp_ippsGFpxMethod_com, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGFpxMethod_com( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGFpxMethod_com( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGFpxMethod_com( ); - } else + } 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 )) { - return h9_ippsGFpxMethod_com( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpxMethod_com( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00253.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGcd_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00253.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGcd_BN.c index 5fc14e768..885b309a4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00253.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGcd_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) -IPPAPI(IppStatus, l9_ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) IPPAPI(IppStatus, k1_ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) +IPPAPI(IppStatus, l9_ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) +IPPAPI(IppStatus, y8_ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) -IPPFUN(IppStatus,sgx_disp_ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) +IPPFUN(IppStatus, sgx_disp_ippsGcd_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pGCD)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGcd_BN( pA, pB, pGCD ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGcd_BN( pA, pB, pGCD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGcd_BN( pA, pB, pGCD ); - } else + } 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 )) { - return h9_ippsGcd_BN( pA, pB, pGCD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGcd_BN( pA, pB, pGCD ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00256.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGetOctString_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00256.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGetOctString_BN.c index b08b283c7..50cae0536 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00256.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGetOctString_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGetOctString_BN,(Ipp8u* pStr, int strLen, const IppsBigNumState* pBN)) -IPPAPI(IppStatus, l9_ippsGetOctString_BN,(Ipp8u* pStr, int strLen, const IppsBigNumState* pBN)) IPPAPI(IppStatus, k1_ippsGetOctString_BN,(Ipp8u* pStr, int strLen, const IppsBigNumState* pBN)) +IPPAPI(IppStatus, l9_ippsGetOctString_BN,(Ipp8u* pStr, int strLen, const IppsBigNumState* pBN)) +IPPAPI(IppStatus, y8_ippsGetOctString_BN,(Ipp8u* pStr, int strLen, const IppsBigNumState* pBN)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGetOctString_BN( pStr, strLen, pBN ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGetOctString_BN( pStr, strLen, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGetOctString_BN( pStr, strLen, pBN ); - } else + } 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 )) { - return h9_ippsGetOctString_BN( pStr, strLen, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGetOctString_BN( pStr, strLen, pBN ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00242.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGetSize_BN.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00242.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGetSize_BN.c index e2b152494..3df66c04d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00242.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGetSize_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsGetSize_BN,(const IppsBigNumState* pBN, int* pSize)) -IPPAPI(IppStatus, l9_ippsGetSize_BN,(const IppsBigNumState* pBN, int* pSize)) IPPAPI(IppStatus, k1_ippsGetSize_BN,(const IppsBigNumState* pBN, int* pSize)) +IPPAPI(IppStatus, l9_ippsGetSize_BN,(const IppsBigNumState* pBN, int* pSize)) +IPPAPI(IppStatus, y8_ippsGetSize_BN,(const IppsBigNumState* pBN, int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsGetSize_BN,(const IppsBigNumState* pBN, int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsGetSize_BN,(const IppsBigNumState* pBN, int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGetSize_BN( pBN, pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGetSize_BN( pBN, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGetSize_BN( pBN, pSize ); - } else + } 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 )) { - return h9_ippsGetSize_BN( pBN, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGetSize_BN( pBN, pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00244.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGet_BN.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00244.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGet_BN.c index fef8739a7..c9ad5a8a1 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00244.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsGet_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsGet_BN,(IppsBigNumSGN* pSgn, int* pLength, Ipp32u* pData, const IppsBigNumState* pBN)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsGet_BN( pSgn, pLength, pData, pBN ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsGet_BN( pSgn, pLength, pData, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsGet_BN( pSgn, pLength, pData, pBN ); - } else + } 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 )) { - return h9_ippsGet_BN( pSgn, pLength, pData, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGet_BN( pSgn, pLength, pData, pBN ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00233.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACDuplicate_rmf.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00233.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACDuplicate_rmf.c index e92ab7717..f569c4a91 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00233.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACDuplicate_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHMACDuplicate_rmf,(const IppsHMACState_rmf* pSrcCtx, IppsHMACState_rmf* pDstCtx)) -IPPAPI(IppStatus, l9_ippsHMACDuplicate_rmf,(const IppsHMACState_rmf* pSrcCtx, IppsHMACState_rmf* pDstCtx)) IPPAPI(IppStatus, k1_ippsHMACDuplicate_rmf,(const IppsHMACState_rmf* pSrcCtx, IppsHMACState_rmf* pDstCtx)) +IPPAPI(IppStatus, l9_ippsHMACDuplicate_rmf,(const IppsHMACState_rmf* pSrcCtx, IppsHMACState_rmf* pDstCtx)) +IPPAPI(IppStatus, y8_ippsHMACDuplicate_rmf,(const IppsHMACState_rmf* pSrcCtx, IppsHMACState_rmf* pDstCtx)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMACDuplicate_rmf( pSrcCtx, pDstCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMACDuplicate_rmf( pSrcCtx, pDstCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMACDuplicate_rmf( pSrcCtx, pDstCtx ); - } else + } 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 )) { - return h9_ippsHMACDuplicate_rmf( pSrcCtx, pDstCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMACDuplicate_rmf( pSrcCtx, pDstCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00235.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACFinal_rmf.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00235.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACFinal_rmf.c index e035b2885..8e258d309 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00235.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACFinal_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHMACFinal_rmf,(Ipp8u* pMD, int mdLen, IppsHMACState_rmf* pCtx)) -IPPAPI(IppStatus, l9_ippsHMACFinal_rmf,(Ipp8u* pMD, int mdLen, IppsHMACState_rmf* pCtx)) IPPAPI(IppStatus, k1_ippsHMACFinal_rmf,(Ipp8u* pMD, int mdLen, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, l9_ippsHMACFinal_rmf,(Ipp8u* pMD, int mdLen, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, y8_ippsHMACFinal_rmf,(Ipp8u* pMD, int mdLen, IppsHMACState_rmf* pCtx)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMACFinal_rmf( pMD, mdLen, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMACFinal_rmf( pMD, mdLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMACFinal_rmf( pMD, mdLen, pCtx ); - } else + } 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 )) { - return h9_ippsHMACFinal_rmf( pMD, mdLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMACFinal_rmf( pMD, mdLen, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00229.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACGetSize_rmf.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00229.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACGetSize_rmf.c index 9704c400f..8da676a7b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00229.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACGetSize_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHMACGetSize_rmf,(int* pSize)) -IPPAPI(IppStatus, l9_ippsHMACGetSize_rmf,(int* pSize)) IPPAPI(IppStatus, k1_ippsHMACGetSize_rmf,(int* pSize)) +IPPAPI(IppStatus, l9_ippsHMACGetSize_rmf,(int* pSize)) +IPPAPI(IppStatus, y8_ippsHMACGetSize_rmf,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsHMACGetSize_rmf,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsHMACGetSize_rmf,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMACGetSize_rmf( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMACGetSize_rmf( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMACGetSize_rmf( pSize ); - } else + } 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 )) { - return h9_ippsHMACGetSize_rmf( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMACGetSize_rmf( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00236.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACGetTag_rmf.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00236.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACGetTag_rmf.c index 118fb4ca6..e5b963e14 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00236.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACGetTag_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsHMACGetTag_rmf,(Ipp8u* pMD, int mdLen, const IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, l9_ippsHMACGetTag_rmf,(Ipp8u* pMD, int mdLen, const IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, y8_ippsHMACGetTag_rmf,(Ipp8u* pMD, int mdLen, const IppsHMACState_rmf* pCtx)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMACGetTag_rmf( pMD, mdLen, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMACGetTag_rmf( pMD, mdLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMACGetTag_rmf( pMD, mdLen, pCtx ); - } else + } 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 )) { - return h9_ippsHMACGetTag_rmf( pMD, mdLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMACGetTag_rmf( pMD, mdLen, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00230.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACInit_rmf.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00230.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACInit_rmf.c index 70f4f007e..8fd83e1ca 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00230.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACInit_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsHMACInit_rmf,(const Ipp8u* pKey, int keyLen, IppsHMACState_rmf* pCtx, const IppsHashMethod* pMethod)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMACInit_rmf( pKey, keyLen, pCtx, pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMACInit_rmf( pKey, keyLen, pCtx, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMACInit_rmf( pKey, keyLen, pCtx, pMethod ); - } else + } 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 )) { - return h9_ippsHMACInit_rmf( pKey, keyLen, pCtx, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMACInit_rmf( pKey, keyLen, pCtx, pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00237.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACMessage_rmf.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00237.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACMessage_rmf.c index 41accb773..c98315c19 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00237.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACMessage_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMACMessage_rmf( pMsg, msgLen, pKey, keyLen, pMD, mdLen, pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMACMessage_rmf( pMsg, msgLen, pKey, keyLen, pMD, mdLen, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMACMessage_rmf( pMsg, msgLen, pKey, keyLen, pMD, mdLen, pMethod ); - } else + } 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 )) { - return h9_ippsHMACMessage_rmf( pMsg, msgLen, pKey, keyLen, pMD, mdLen, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMACMessage_rmf( pMsg, msgLen, pKey, keyLen, pMD, mdLen, pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00231.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACPack_rmf.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00231.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACPack_rmf.c index 773172050..98aea09f4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00231.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACPack_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsHMACPack_rmf,(const IppsHMACState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, l9_ippsHMACPack_rmf,(const IppsHMACState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, y8_ippsHMACPack_rmf,(const IppsHMACState_rmf* pCtx, Ipp8u* pBuffer, int bufSize)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMACPack_rmf( pCtx, pBuffer, bufSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMACPack_rmf( pCtx, pBuffer, bufSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMACPack_rmf( pCtx, pBuffer, bufSize ); - } else + } 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 )) { - return h9_ippsHMACPack_rmf( pCtx, pBuffer, bufSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMACPack_rmf( pCtx, pBuffer, bufSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00232.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACUnpack_rmf.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00232.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACUnpack_rmf.c index 99f4bdf58..0718ed4fb 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00232.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACUnpack_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) -IPPAPI(IppStatus, l9_ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) IPPAPI(IppStatus, k1_ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, l9_ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, y8_ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsHMACUnpack_rmf,(const Ipp8u* pBuffer, IppsHMACState_rmf* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMACUnpack_rmf( pBuffer, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMACUnpack_rmf( pBuffer, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMACUnpack_rmf( pBuffer, pCtx ); - } else + } 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 )) { - return h9_ippsHMACUnpack_rmf( pBuffer, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMACUnpack_rmf( pBuffer, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00234.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACUpdate_rmf.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00234.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACUpdate_rmf.c index 056668a90..ef6ad5250 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00234.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMACUpdate_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsHMACUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, l9_ippsHMACUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHMACState_rmf* pCtx)) +IPPAPI(IppStatus, y8_ippsHMACUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHMACState_rmf* pCtx)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMACUpdate_rmf( pSrc, len, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMACUpdate_rmf( pSrc, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMACUpdate_rmf( pSrc, len, pCtx ); - } else + } 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 )) { - return h9_ippsHMACUpdate_rmf( pSrc, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMACUpdate_rmf( pSrc, len, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00224.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Duplicate.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00224.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Duplicate.c index 6763e40f3..12d034f5a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00224.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Duplicate.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHMAC_Duplicate,(const IppsHMACState* pSrcCtx, IppsHMACState* pDstCtx)) -IPPAPI(IppStatus, l9_ippsHMAC_Duplicate,(const IppsHMACState* pSrcCtx, IppsHMACState* pDstCtx)) IPPAPI(IppStatus, k1_ippsHMAC_Duplicate,(const IppsHMACState* pSrcCtx, IppsHMACState* pDstCtx)) +IPPAPI(IppStatus, l9_ippsHMAC_Duplicate,(const IppsHMACState* pSrcCtx, IppsHMACState* pDstCtx)) +IPPAPI(IppStatus, y8_ippsHMAC_Duplicate,(const IppsHMACState* pSrcCtx, IppsHMACState* pDstCtx)) -IPPFUN(IppStatus,sgx_disp_ippsHMAC_Duplicate,(const IppsHMACState* pSrcCtx, IppsHMACState* pDstCtx)) +IPPFUN(IppStatus, sgx_disp_ippsHMAC_Duplicate,(const IppsHMACState* pSrcCtx, IppsHMACState* pDstCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMAC_Duplicate( pSrcCtx, pDstCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMAC_Duplicate( pSrcCtx, pDstCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMAC_Duplicate( pSrcCtx, pDstCtx ); - } else + } 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 )) { - return h9_ippsHMAC_Duplicate( pSrcCtx, pDstCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMAC_Duplicate( pSrcCtx, pDstCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00226.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Final.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00226.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Final.c index 12997aeb7..2149a3e1a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00226.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Final.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) -IPPAPI(IppStatus, l9_ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) IPPAPI(IppStatus, k1_ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) +IPPAPI(IppStatus, l9_ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) +IPPAPI(IppStatus, y8_ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsHMAC_Final,(Ipp8u* pMD, int mdLen, IppsHMACState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMAC_Final( pMD, mdLen, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMAC_Final( pMD, mdLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMAC_Final( pMD, mdLen, pCtx ); - } else + } 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 )) { - return h9_ippsHMAC_Final( pMD, mdLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMAC_Final( pMD, mdLen, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00220.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_GetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00220.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_GetSize.c index 9a8097a56..27737af6f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00220.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_GetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHMAC_GetSize,(int* pSize)) -IPPAPI(IppStatus, l9_ippsHMAC_GetSize,(int* pSize)) IPPAPI(IppStatus, k1_ippsHMAC_GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsHMAC_GetSize,(int* pSize)) +IPPAPI(IppStatus, y8_ippsHMAC_GetSize,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsHMAC_GetSize,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsHMAC_GetSize,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMAC_GetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMAC_GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMAC_GetSize( pSize ); - } else + } 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 )) { - return h9_ippsHMAC_GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMAC_GetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00227.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_GetTag.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00227.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_GetTag.c index fee1eae92..d6e860b68 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00227.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_GetTag.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHMAC_GetTag,(Ipp8u* pMD, int mdLen, const IppsHMACState* pCtx)) -IPPAPI(IppStatus, l9_ippsHMAC_GetTag,(Ipp8u* pMD, int mdLen, const IppsHMACState* pCtx)) IPPAPI(IppStatus, k1_ippsHMAC_GetTag,(Ipp8u* pMD, int mdLen, const IppsHMACState* pCtx)) +IPPAPI(IppStatus, l9_ippsHMAC_GetTag,(Ipp8u* pMD, int mdLen, const IppsHMACState* pCtx)) +IPPAPI(IppStatus, y8_ippsHMAC_GetTag,(Ipp8u* pMD, int mdLen, const IppsHMACState* pCtx)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMAC_GetTag( pMD, mdLen, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMAC_GetTag( pMD, mdLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMAC_GetTag( pMD, mdLen, pCtx ); - } else + } 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 )) { - return h9_ippsHMAC_GetTag( pMD, mdLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMAC_GetTag( pMD, mdLen, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00221.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Init.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00221.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Init.c index f15933813..f4d882da2 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00221.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Init.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsHMAC_Init,(const Ipp8u* pKey, int keyLen, IppsHMACState* pCtx, IppHashAlgId hashAlg)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMAC_Init( pKey, keyLen, pCtx, hashAlg ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMAC_Init( pKey, keyLen, pCtx, hashAlg ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMAC_Init( pKey, keyLen, pCtx, hashAlg ); - } else + } 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 )) { - return h9_ippsHMAC_Init( pKey, keyLen, pCtx, hashAlg ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMAC_Init( pKey, keyLen, pCtx, hashAlg ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00228.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Message.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00228.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Message.c index 3095326bf..e6eba4eb6 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00228.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Message.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMAC_Message( pMsg, msgLen, pKey, keyLen, pMD, mdLen, hashAlg ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMAC_Message( pMsg, msgLen, pKey, keyLen, pMD, mdLen, hashAlg ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMAC_Message( pMsg, msgLen, pKey, keyLen, pMD, mdLen, hashAlg ); - } else + } 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 )) { - return h9_ippsHMAC_Message( pMsg, msgLen, pKey, keyLen, pMD, mdLen, hashAlg ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMAC_Message( pMsg, msgLen, pKey, keyLen, pMD, mdLen, hashAlg ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00222.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Pack.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00222.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Pack.c index 1c242fa79..ef5c8c73c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00222.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Pack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHMAC_Pack,(const IppsHMACState* pCtx, Ipp8u* pBuffer, int bufSize)) -IPPAPI(IppStatus, l9_ippsHMAC_Pack,(const IppsHMACState* pCtx, Ipp8u* pBuffer, int bufSize)) IPPAPI(IppStatus, k1_ippsHMAC_Pack,(const IppsHMACState* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, l9_ippsHMAC_Pack,(const IppsHMACState* pCtx, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, y8_ippsHMAC_Pack,(const IppsHMACState* pCtx, Ipp8u* pBuffer, int bufSize)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMAC_Pack( pCtx, pBuffer, bufSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMAC_Pack( pCtx, pBuffer, bufSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMAC_Pack( pCtx, pBuffer, bufSize ); - } else + } 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 )) { - return h9_ippsHMAC_Pack( pCtx, pBuffer, bufSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMAC_Pack( pCtx, pBuffer, bufSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00223.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Unpack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00223.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Unpack.c index 923027d4c..ff388771b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00223.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Unpack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHMAC_Unpack,(const Ipp8u* pBuffer, IppsHMACState* pCtx)) -IPPAPI(IppStatus, l9_ippsHMAC_Unpack,(const Ipp8u* pBuffer, IppsHMACState* pCtx)) IPPAPI(IppStatus, k1_ippsHMAC_Unpack,(const Ipp8u* pBuffer, IppsHMACState* pCtx)) +IPPAPI(IppStatus, l9_ippsHMAC_Unpack,(const Ipp8u* pBuffer, IppsHMACState* pCtx)) +IPPAPI(IppStatus, y8_ippsHMAC_Unpack,(const Ipp8u* pBuffer, IppsHMACState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsHMAC_Unpack,(const Ipp8u* pBuffer, IppsHMACState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsHMAC_Unpack,(const Ipp8u* pBuffer, IppsHMACState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMAC_Unpack( pBuffer, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMAC_Unpack( pBuffer, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMAC_Unpack( pBuffer, pCtx ); - } else + } 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 )) { - return h9_ippsHMAC_Unpack( pBuffer, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMAC_Unpack( pBuffer, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00225.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Update.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00225.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Update.c index 45c84f02b..39cd5878e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00225.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHMAC_Update.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHMAC_Update,(const Ipp8u* pSrc, int len, IppsHMACState* pCtx)) -IPPAPI(IppStatus, l9_ippsHMAC_Update,(const Ipp8u* pSrc, int len, IppsHMACState* pCtx)) IPPAPI(IppStatus, k1_ippsHMAC_Update,(const Ipp8u* pSrc, int len, IppsHMACState* pCtx)) +IPPAPI(IppStatus, l9_ippsHMAC_Update,(const Ipp8u* pSrc, int len, IppsHMACState* pCtx)) +IPPAPI(IppStatus, y8_ippsHMAC_Update,(const Ipp8u* pSrc, int len, IppsHMACState* pCtx)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHMAC_Update( pSrc, len, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHMAC_Update( pSrc, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHMAC_Update( pSrc, len, pCtx ); - } else + } 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 )) { - return h9_ippsHMAC_Update( pSrc, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHMAC_Update( pSrc, len, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00170.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashDuplicate.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00170.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashDuplicate.c index c1727569f..4d73af125 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00170.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashDuplicate.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashDuplicate,(const IppsHashState* pSrcState, IppsHashState* pDstState)) -IPPAPI(IppStatus, l9_ippsHashDuplicate,(const IppsHashState* pSrcState, IppsHashState* pDstState)) IPPAPI(IppStatus, k1_ippsHashDuplicate,(const IppsHashState* pSrcState, IppsHashState* pDstState)) +IPPAPI(IppStatus, l9_ippsHashDuplicate,(const IppsHashState* pSrcState, IppsHashState* pDstState)) +IPPAPI(IppStatus, y8_ippsHashDuplicate,(const IppsHashState* pSrcState, IppsHashState* pDstState)) -IPPFUN(IppStatus,sgx_disp_ippsHashDuplicate,(const IppsHashState* pSrcState, IppsHashState* pDstState)) +IPPFUN(IppStatus, sgx_disp_ippsHashDuplicate,(const IppsHashState* pSrcState, IppsHashState* pDstState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashDuplicate( pSrcState, pDstState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashDuplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashDuplicate( pSrcState, pDstState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashDuplicate,(const IppsHashState* pSrcState, IppsHashState* pDstState)) -IPPAPI(IppStatus, h9_ippsHashDuplicate,(const IppsHashState* pSrcState, IppsHashState* pDstState)) - -IPPFUN(IppStatus,sgx_disp_ippsHashDuplicate,(const IppsHashState* pSrcState, IppsHashState* pDstState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashDuplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashDuplicate( pSrcState, pDstState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00210.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashDuplicate_rmf.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00210.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashDuplicate_rmf.c index 4a90dd8a5..5c64ca44c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00210.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashDuplicate_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcState, IppsHashState_rmf* pDstState)) -IPPAPI(IppStatus, l9_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcState, IppsHashState_rmf* pDstState)) IPPAPI(IppStatus, k1_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcState, IppsHashState_rmf* pDstState)) +IPPAPI(IppStatus, l9_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcState, IppsHashState_rmf* pDstState)) +IPPAPI(IppStatus, y8_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcState, IppsHashState_rmf* pDstState)) -IPPFUN(IppStatus,sgx_disp_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcState, IppsHashState_rmf* pDstState)) +IPPFUN(IppStatus, sgx_disp_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcState, IppsHashState_rmf* pDstState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashDuplicate_rmf( pSrcState, pDstState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashDuplicate_rmf( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashDuplicate_rmf( pSrcState, pDstState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcState, IppsHashState_rmf* pDstState)) -IPPAPI(IppStatus, h9_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcState, IppsHashState_rmf* pDstState)) - -IPPFUN(IppStatus,sgx_disp_ippsHashDuplicate_rmf,(const IppsHashState_rmf* pSrcState, IppsHashState_rmf* pDstState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashDuplicate_rmf( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashDuplicate_rmf( pSrcState, pDstState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00173.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashFinal.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00173.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashFinal.c index 9bb9149d6..0884187d8 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00173.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashFinal.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pState)) -IPPAPI(IppStatus, l9_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pState)) IPPAPI(IppStatus, k1_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pState)) +IPPAPI(IppStatus, l9_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pState)) +IPPAPI(IppStatus, y8_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pState)) -IPPFUN(IppStatus,sgx_disp_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pState)) +IPPFUN(IppStatus, sgx_disp_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashFinal( pMD, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashFinal( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashFinal( pMD, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pState)) -IPPAPI(IppStatus, h9_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsHashFinal,(Ipp8u* pMD, IppsHashState* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashFinal( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashFinal( pMD, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00213.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashFinal_rmf.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00213.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashFinal_rmf.c index 4e6027d09..59f7825d7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00213.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashFinal_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pState)) -IPPAPI(IppStatus, l9_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pState)) IPPAPI(IppStatus, k1_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pState)) +IPPAPI(IppStatus, l9_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pState)) +IPPAPI(IppStatus, y8_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pState)) -IPPFUN(IppStatus,sgx_disp_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pState)) +IPPFUN(IppStatus, sgx_disp_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashFinal_rmf( pMD, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashFinal_rmf( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashFinal_rmf( pMD, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pState)) -IPPAPI(IppStatus, h9_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsHashFinal_rmf,(Ipp8u* pMD, IppsHashState_rmf* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashFinal_rmf( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashFinal_rmf( pMD, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00216.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetInfo_rmf.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00216.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetInfo_rmf.c index 6cff30c62..603af841f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00216.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetInfo_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashGetInfo_rmf,(IppsHashInfo* pInfo, const IppsHashState_rmf* pState)) -IPPAPI(IppStatus, l9_ippsHashGetInfo_rmf,(IppsHashInfo* pInfo, const IppsHashState_rmf* pState)) IPPAPI(IppStatus, k1_ippsHashGetInfo_rmf,(IppsHashInfo* pInfo, const IppsHashState_rmf* pState)) +IPPAPI(IppStatus, l9_ippsHashGetInfo_rmf,(IppsHashInfo* pInfo, const IppsHashState_rmf* pState)) +IPPAPI(IppStatus, y8_ippsHashGetInfo_rmf,(IppsHashInfo* pInfo, const IppsHashState_rmf* pState)) -IPPFUN(IppStatus,sgx_disp_ippsHashGetInfo_rmf,(IppsHashInfo* pInfo, const IppsHashState_rmf* pState)) +IPPFUN(IppStatus, sgx_disp_ippsHashGetInfo_rmf,(IppsHashInfo* pInfo, const IppsHashState_rmf* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashGetInfo_rmf( pInfo, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashGetInfo_rmf( pInfo, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashGetInfo_rmf( pInfo, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashGetInfo_rmf,(IppsHashInfo* pInfo, const IppsHashState_rmf* pState)) -IPPAPI(IppStatus, h9_ippsHashGetInfo_rmf,(IppsHashInfo* pInfo, const IppsHashState_rmf* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsHashGetInfo_rmf,(IppsHashInfo* pInfo, const IppsHashState_rmf* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashGetInfo_rmf( pInfo, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashGetInfo_rmf( pInfo, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00166.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00166.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetSize.c index 7e9f05f24..ac7e3250a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00166.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashGetSize,(int* pSize)) -IPPAPI(IppStatus, l9_ippsHashGetSize,(int* pSize)) IPPAPI(IppStatus, k1_ippsHashGetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsHashGetSize,(int* pSize)) +IPPAPI(IppStatus, y8_ippsHashGetSize,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsHashGetSize,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsHashGetSize,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashGetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashGetSize( pSize ); - } else + } 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 )) { - return h9_ippsHashGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashGetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00206.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetSize_rmf.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00206.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetSize_rmf.c index eb58e4d18..2f12eadfc 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00206.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetSize_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashGetSize_rmf,(int* pSize)) -IPPAPI(IppStatus, l9_ippsHashGetSize_rmf,(int* pSize)) IPPAPI(IppStatus, k1_ippsHashGetSize_rmf,(int* pSize)) +IPPAPI(IppStatus, l9_ippsHashGetSize_rmf,(int* pSize)) +IPPAPI(IppStatus, y8_ippsHashGetSize_rmf,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsHashGetSize_rmf,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsHashGetSize_rmf,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashGetSize_rmf( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashGetSize_rmf( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashGetSize_rmf( pSize ); - } else + } 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 )) { - return h9_ippsHashGetSize_rmf( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashGetSize_rmf( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00172.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetTag.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00172.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetTag.c index 63f1ad335..a8a93d774 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00172.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetTag.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashGetTag,(Ipp8u* pTag, int tagLen, const IppsHashState* pState)) -IPPAPI(IppStatus, l9_ippsHashGetTag,(Ipp8u* pTag, int tagLen, const IppsHashState* pState)) IPPAPI(IppStatus, k1_ippsHashGetTag,(Ipp8u* pTag, int tagLen, const IppsHashState* pState)) +IPPAPI(IppStatus, l9_ippsHashGetTag,(Ipp8u* pTag, int tagLen, const IppsHashState* pState)) +IPPAPI(IppStatus, y8_ippsHashGetTag,(Ipp8u* pTag, int tagLen, const IppsHashState* pState)) -IPPFUN(IppStatus,sgx_disp_ippsHashGetTag,(Ipp8u* pTag, int tagLen, const IppsHashState* pState)) +IPPFUN(IppStatus, sgx_disp_ippsHashGetTag,(Ipp8u* pTag, int tagLen, const IppsHashState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashGetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashGetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashGetTag( pTag, tagLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashGetTag,(Ipp8u* pTag, int tagLen, const IppsHashState* pState)) -IPPAPI(IppStatus, h9_ippsHashGetTag,(Ipp8u* pTag, int tagLen, const IppsHashState* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsHashGetTag,(Ipp8u* pTag, int tagLen, const IppsHashState* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashGetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashGetTag( pTag, tagLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00212.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetTag_rmf.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00212.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetTag_rmf.c index 6155f9cb4..bbd8e764d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00212.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashGetTag_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pState)) -IPPAPI(IppStatus, l9_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pState)) IPPAPI(IppStatus, k1_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pState)) +IPPAPI(IppStatus, l9_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pState)) +IPPAPI(IppStatus, y8_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pState)) -IPPFUN(IppStatus,sgx_disp_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pState)) +IPPFUN(IppStatus, sgx_disp_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashGetTag_rmf( pMD, tagLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashGetTag_rmf( pMD, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashGetTag_rmf( pMD, tagLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pState)) -IPPAPI(IppStatus, h9_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsHashGetTag_rmf,(Ipp8u* pMD, int tagLen, const IppsHashState_rmf* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashGetTag_rmf( pMD, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashGetTag_rmf( pMD, tagLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00167.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashInit.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00167.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashInit.c index 4ee4ebfce..20431a58e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00167.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashInit,(IppsHashState* pState, IppHashAlgId hashAlg)) -IPPAPI(IppStatus, l9_ippsHashInit,(IppsHashState* pState, IppHashAlgId hashAlg)) IPPAPI(IppStatus, k1_ippsHashInit,(IppsHashState* pState, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, l9_ippsHashInit,(IppsHashState* pState, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, y8_ippsHashInit,(IppsHashState* pState, IppHashAlgId hashAlg)) -IPPFUN(IppStatus,sgx_disp_ippsHashInit,(IppsHashState* pState, IppHashAlgId hashAlg)) +IPPFUN(IppStatus, sgx_disp_ippsHashInit,(IppsHashState* pState, IppHashAlgId hashAlg)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashInit( pState, hashAlg ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashInit( pState, hashAlg ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashInit( pState, hashAlg ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashInit,(IppsHashState* pState, IppHashAlgId hashAlg)) -IPPAPI(IppStatus, h9_ippsHashInit,(IppsHashState* pState, IppHashAlgId hashAlg)) - -IPPFUN(IppStatus,sgx_disp_ippsHashInit,(IppsHashState* pState, IppHashAlgId hashAlg)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashInit( pState, hashAlg ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashInit( pState, hashAlg ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00207.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashInit_rmf.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00207.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashInit_rmf.c index 995c28739..cb2eacb63 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00207.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashInit_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashInit_rmf,(IppsHashState_rmf* pState, const IppsHashMethod* pMethod)) -IPPAPI(IppStatus, l9_ippsHashInit_rmf,(IppsHashState_rmf* pState, const IppsHashMethod* pMethod)) IPPAPI(IppStatus, k1_ippsHashInit_rmf,(IppsHashState_rmf* pState, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, l9_ippsHashInit_rmf,(IppsHashState_rmf* pState, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, y8_ippsHashInit_rmf,(IppsHashState_rmf* pState, const IppsHashMethod* pMethod)) -IPPFUN(IppStatus,sgx_disp_ippsHashInit_rmf,(IppsHashState_rmf* pState, const IppsHashMethod* pMethod)) +IPPFUN(IppStatus, sgx_disp_ippsHashInit_rmf,(IppsHashState_rmf* pState, const IppsHashMethod* pMethod)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashInit_rmf( pState, pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashInit_rmf( pState, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashInit_rmf( pState, pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashInit_rmf,(IppsHashState_rmf* pState, const IppsHashMethod* pMethod)) -IPPAPI(IppStatus, h9_ippsHashInit_rmf,(IppsHashState_rmf* pState, const IppsHashMethod* pMethod)) - -IPPFUN(IppStatus,sgx_disp_ippsHashInit_rmf,(IppsHashState_rmf* pState, const IppsHashMethod* pMethod)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashInit_rmf( pState, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashInit_rmf( pState, pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00174.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMessage.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00174.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMessage.c index 39610e427..e350c8b4e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00174.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMessage.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsHashMessage,(const Ipp8u* pMsg, int len, Ipp8u* pMD, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, l9_ippsHashMessage,(const Ipp8u* pMsg, int len, Ipp8u* pMD, IppHashAlgId hashAlg)) +IPPAPI(IppStatus, y8_ippsHashMessage,(const Ipp8u* pMsg, int len, Ipp8u* pMD, IppHashAlgId hashAlg)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMessage( pMsg, len, pMD, hashAlg ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMessage( pMsg, len, pMD, hashAlg ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMessage( pMsg, len, pMD, hashAlg ); - } else + } 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 )) { - return h9_ippsHashMessage( pMsg, len, pMD, hashAlg ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMessage( pMsg, len, pMD, hashAlg ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00214.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMessage_rmf.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00214.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMessage_rmf.c index 7d7a57904..1c6f4fdde 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00214.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMessage_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsHashMessage_rmf,(const Ipp8u* pMsg, int len, Ipp8u* pMD, const IppsHashMethod* pMethod)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMessage_rmf( pMsg, len, pMD, pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMessage_rmf( pMsg, len, pMD, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMessage_rmf( pMsg, len, pMD, pMethod ); - } else + } 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 )) { - return h9_ippsHashMessage_rmf( pMsg, len, pMD, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMessage_rmf( pMsg, len, pMD, pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00215.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodGetInfo.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00215.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodGetInfo.c index e9d140369..49855124a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00215.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodGetInfo.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashMethodGetInfo,(IppsHashInfo* pInfo, const IppsHashMethod* pMethod)) -IPPAPI(IppStatus, l9_ippsHashMethodGetInfo,(IppsHashInfo* pInfo, const IppsHashMethod* pMethod)) IPPAPI(IppStatus, k1_ippsHashMethodGetInfo,(IppsHashInfo* pInfo, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, l9_ippsHashMethodGetInfo,(IppsHashInfo* pInfo, const IppsHashMethod* pMethod)) +IPPAPI(IppStatus, y8_ippsHashMethodGetInfo,(IppsHashInfo* pInfo, const IppsHashMethod* pMethod)) -IPPFUN(IppStatus,sgx_disp_ippsHashMethodGetInfo,(IppsHashInfo* pInfo, const IppsHashMethod* pMethod)) +IPPFUN(IppStatus, sgx_disp_ippsHashMethodGetInfo,(IppsHashInfo* pInfo, const IppsHashMethod* pMethod)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodGetInfo( pInfo, pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodGetInfo( pInfo, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodGetInfo( pInfo, pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashMethodGetInfo,(IppsHashInfo* pInfo, const IppsHashMethod* pMethod)) -IPPAPI(IppStatus, h9_ippsHashMethodGetInfo,(IppsHashInfo* pInfo, const IppsHashMethod* pMethod)) - -IPPFUN(IppStatus,sgx_disp_ippsHashMethodGetInfo,(IppsHashInfo* pInfo, const IppsHashMethod* pMethod)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodGetInfo( pInfo, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodGetInfo( pInfo, pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00190.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodGetSize.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00190.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodGetSize.c index 64d8329f3..1d82cab89 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00190.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodGetSize, (int* pSize) ) -IPPAPI( IppStatus, l9_ippsHashMethodGetSize, (int* pSize) ) IPPAPI( IppStatus, k1_ippsHashMethodGetSize, (int* pSize) ) +IPPAPI( IppStatus, l9_ippsHashMethodGetSize, (int* pSize) ) +IPPAPI( IppStatus, y8_ippsHashMethodGetSize, (int* pSize) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodGetSize, (int* pSize) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodGetSize, (int* pSize) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodGetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodGetSize( pSize ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodGetSize, (int* pSize) ) -IPPAPI( IppStatus, h9_ippsHashMethodGetSize, (int* pSize) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodGetSize, (int* pSize) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodGetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00191.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_MD5.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00191.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_MD5.c index 590421cfb..55e28d14b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00191.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_MD5.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_MD5, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_MD5, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_MD5, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_MD5, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_MD5, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_MD5, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_MD5, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_MD5( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_MD5( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_MD5( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_MD5, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_MD5, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_MD5, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_MD5( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_MD5( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00193.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA1.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00193.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA1.c index 03bf66589..1b82fd7d0 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00193.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA1, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA1, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SHA1, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA1, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA1, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA1, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SHA1, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SHA1( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SHA1( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SHA1( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SHA1, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SHA1, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA1, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SHA1( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SHA1( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00194.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA1_NI.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00194.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA1_NI.c index dc2c8d8a5..a81067c0d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00194.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA1_NI.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA1_NI, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA1_NI, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SHA1_NI, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA1_NI, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA1_NI, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA1_NI, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SHA1_NI, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SHA1_NI( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SHA1_NI( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SHA1_NI( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SHA1_NI, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SHA1_NI, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA1_NI, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SHA1_NI( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SHA1_NI( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00195.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA1_TT.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00195.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA1_TT.c index 8ef07de58..55f9e416b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00195.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA1_TT.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA1_TT, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA1_TT, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SHA1_TT, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA1_TT, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA1_TT, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA1_TT, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SHA1_TT, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SHA1_TT( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SHA1_TT( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SHA1_TT( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SHA1_TT, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SHA1_TT, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA1_TT, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SHA1_TT( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SHA1_TT( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00199.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA224.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00199.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA224.c index be4c61cbe..9a86c13b7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00199.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA224.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA224, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA224, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SHA224, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA224, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA224, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA224, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SHA224, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SHA224( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SHA224( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SHA224( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SHA224, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SHA224, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA224, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SHA224( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SHA224( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00200.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA224_NI.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00200.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA224_NI.c index e780d60ad..79186d59a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00200.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA224_NI.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA224_NI, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA224_NI, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SHA224_NI, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA224_NI, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA224_NI, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA224_NI, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SHA224_NI, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SHA224_NI( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SHA224_NI( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SHA224_NI( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SHA224_NI, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SHA224_NI, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA224_NI, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SHA224_NI( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SHA224_NI( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00201.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA224_TT.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00201.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA224_TT.c index 330f7f5a6..ac57a19f9 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00201.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA224_TT.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA224_TT, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA224_TT, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SHA224_TT, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA224_TT, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA224_TT, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA224_TT, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SHA224_TT, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SHA224_TT( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SHA224_TT( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SHA224_TT( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SHA224_TT, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SHA224_TT, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA224_TT, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SHA224_TT( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SHA224_TT( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00196.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA256.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00196.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA256.c index f42df9cb4..a0dd3df48 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00196.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA256.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA256, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA256, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SHA256, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA256, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA256, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA256, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SHA256, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SHA256( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SHA256( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SHA256( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SHA256, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SHA256, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA256, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SHA256( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SHA256( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00197.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA256_NI.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00197.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA256_NI.c index 4575d093b..6f62c601c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00197.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA256_NI.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA256_NI, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA256_NI, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SHA256_NI, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA256_NI, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA256_NI, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA256_NI, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SHA256_NI, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SHA256_NI( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SHA256_NI( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SHA256_NI( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SHA256_NI, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SHA256_NI, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA256_NI, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SHA256_NI( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SHA256_NI( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00198.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA256_TT.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00198.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA256_TT.c index 9c4025839..2315646a1 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00198.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA256_TT.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA256_TT, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA256_TT, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SHA256_TT, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA256_TT, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA256_TT, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA256_TT, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SHA256_TT, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SHA256_TT( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SHA256_TT( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SHA256_TT( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SHA256_TT, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SHA256_TT, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA256_TT, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SHA256_TT( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SHA256_TT( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00203.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA384.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00203.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA384.c index b99d7e84e..6eab7d3c6 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00203.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA384.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA384, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA384, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SHA384, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA384, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA384, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA384, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SHA384, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SHA384( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SHA384( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SHA384( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SHA384, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SHA384, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA384, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SHA384( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SHA384( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00202.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA512.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00202.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA512.c index 84c12c8b6..d46f08d1c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00202.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA512.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA512, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA512, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SHA512, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA512, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA512, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA512, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SHA512, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SHA512( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SHA512( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SHA512( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SHA512, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SHA512, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA512, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SHA512( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SHA512( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00205.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA512_224.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00205.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA512_224.c index 76804815d..3500b6548 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00205.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA512_224.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA512_224, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA512_224, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SHA512_224, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA512_224, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA512_224, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA512_224, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SHA512_224, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SHA512_224( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SHA512_224( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SHA512_224( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SHA512_224, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SHA512_224, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA512_224, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SHA512_224( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SHA512_224( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00204.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA512_256.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00204.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA512_256.c index 8952ab85a..15f1a3b36 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00204.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SHA512_256.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA512_256, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA512_256, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SHA512_256, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SHA512_256, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SHA512_256, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA512_256, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SHA512_256, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SHA512_256( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SHA512_256( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SHA512_256( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SHA512_256, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SHA512_256, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SHA512_256, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SHA512_256( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SHA512_256( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00192.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SM3.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00192.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SM3.c index 3ce7cc6fa..8e1ef35d6 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00192.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethodSet_SM3.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( IppStatus, y8_ippsHashMethodSet_SM3, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, l9_ippsHashMethodSet_SM3, (IppsHashMethod* pMethod) ) IPPAPI( IppStatus, k1_ippsHashMethodSet_SM3, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashMethodSet_SM3, (IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashMethodSet_SM3, (IppsHashMethod* pMethod) ) -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SM3, (IppsHashMethod* pMethod) ) +IPPFUN( IppStatus, sgx_disp_ippsHashMethodSet_SM3, (IppsHashMethod* pMethod) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethodSet_SM3( pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethodSet_SM3( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethodSet_SM3( pMethod ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI( IppStatus, p8_ippsHashMethodSet_SM3, (IppsHashMethod* pMethod) ) -IPPAPI( IppStatus, h9_ippsHashMethodSet_SM3, (IppsHashMethod* pMethod) ) - -IPPFUN( IppStatus,sgx_disp_ippsHashMethodSet_SM3, (IppsHashMethod* pMethod) ) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashMethodSet_SM3( pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethodSet_SM3( pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00175.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_MD5.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00175.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_MD5.c index 6dc25f830..8f1acf2c5 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00175.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_MD5.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_MD5, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_MD5, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_MD5, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_MD5, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_MD5, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_MD5, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_MD5, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_MD5( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_MD5( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_MD5( ); - } else + } 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 )) { - return h9_ippsHashMethod_MD5( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_MD5( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00177.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA1.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00177.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA1.c index 72e1c8af8..a7b3810c0 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00177.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA1, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA1, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SHA1, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA1, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA1, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA1, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SHA1, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SHA1( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SHA1( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SHA1( ); - } else + } 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 )) { - return h9_ippsHashMethod_SHA1( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SHA1( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00178.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA1_NI.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00178.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA1_NI.c index c62850ff3..a84bde762 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00178.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA1_NI.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA1_NI, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA1_NI, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SHA1_NI, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA1_NI, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA1_NI, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA1_NI, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SHA1_NI, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SHA1_NI( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SHA1_NI( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SHA1_NI( ); - } else + } 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 )) { - return h9_ippsHashMethod_SHA1_NI( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SHA1_NI( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00179.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA1_TT.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00179.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA1_TT.c index 5fe504516..32d4f1bb0 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00179.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA1_TT.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA1_TT, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA1_TT, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SHA1_TT, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA1_TT, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA1_TT, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA1_TT, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SHA1_TT, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SHA1_TT( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SHA1_TT( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SHA1_TT( ); - } else + } 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 )) { - return h9_ippsHashMethod_SHA1_TT( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SHA1_TT( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00183.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA224.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00183.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA224.c index 8c3368d72..47b8b22d9 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00183.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA224.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA224, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA224, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SHA224, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA224, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA224, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA224, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SHA224, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SHA224( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SHA224( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SHA224( ); - } else + } 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 )) { - return h9_ippsHashMethod_SHA224( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SHA224( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00184.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA224_NI.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00184.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA224_NI.c index e546f916c..37d70475d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00184.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA224_NI.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA224_NI, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA224_NI, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SHA224_NI, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA224_NI, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA224_NI, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA224_NI, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SHA224_NI, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SHA224_NI( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SHA224_NI( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SHA224_NI( ); - } else + } 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 )) { - return h9_ippsHashMethod_SHA224_NI( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SHA224_NI( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00185.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA224_TT.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00185.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA224_TT.c index 2e43a4b9f..64a56a020 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00185.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA224_TT.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA224_TT, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA224_TT, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SHA224_TT, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA224_TT, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA224_TT, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA224_TT, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SHA224_TT, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SHA224_TT( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SHA224_TT( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SHA224_TT( ); - } else + } 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 )) { - return h9_ippsHashMethod_SHA224_TT( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SHA224_TT( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00180.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA256.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00180.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA256.c index 05d4ac6a4..ce118ef98 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00180.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA256.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA256, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA256, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SHA256, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA256, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA256, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA256, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SHA256, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SHA256( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SHA256( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SHA256( ); - } else + } 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 )) { - return h9_ippsHashMethod_SHA256( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SHA256( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00181.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA256_NI.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00181.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA256_NI.c index bc06781f8..938954dfb 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00181.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA256_NI.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA256_NI, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA256_NI, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SHA256_NI, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA256_NI, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA256_NI, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA256_NI, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SHA256_NI, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SHA256_NI( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SHA256_NI( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SHA256_NI( ); - } else + } 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 )) { - return h9_ippsHashMethod_SHA256_NI( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SHA256_NI( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00182.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA256_TT.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00182.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA256_TT.c index 6b9c91ddc..0bd67389b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00182.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA256_TT.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA256_TT, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA256_TT, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SHA256_TT, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA256_TT, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA256_TT, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA256_TT, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SHA256_TT, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SHA256_TT( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SHA256_TT( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SHA256_TT( ); - } else + } 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 )) { - return h9_ippsHashMethod_SHA256_TT( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SHA256_TT( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00187.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA384.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00187.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA384.c index 4afac172e..7c77b1309 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00187.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA384.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA384, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA384, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SHA384, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA384, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA384, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA384, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SHA384, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SHA384( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SHA384( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SHA384( ); - } else + } 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 )) { - return h9_ippsHashMethod_SHA384( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SHA384( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00186.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA512.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00186.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA512.c index cf75736aa..aa774b47f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00186.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA512.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA512, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA512, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SHA512, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA512, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA512, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA512, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SHA512, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SHA512( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SHA512( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SHA512( ); - } else + } 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 )) { - return h9_ippsHashMethod_SHA512( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SHA512( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00189.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA512_224.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00189.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA512_224.c index 01aeac84e..b090f0dcc 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00189.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA512_224.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA512_224, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA512_224, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SHA512_224, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA512_224, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA512_224, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA512_224, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SHA512_224, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SHA512_224( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SHA512_224( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SHA512_224( ); - } else + } 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 )) { - return h9_ippsHashMethod_SHA512_224( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SHA512_224( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00188.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA512_256.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00188.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA512_256.c index a24110c55..fb1cd7bd0 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00188.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SHA512_256.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA512_256, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA512_256, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SHA512_256, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SHA512_256, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SHA512_256, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SHA512_256, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SHA512_256, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SHA512_256( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SHA512_256( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SHA512_256( ); - } else + } 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 )) { - return h9_ippsHashMethod_SHA512_256( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SHA512_256( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00176.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SM3.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00176.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SM3.c index 2983a8c00..81b8e1720 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00176.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashMethod_SM3.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SM3, (void) ) -IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SM3, (void) ) IPPAPI( const IppsHashMethod*, k1_ippsHashMethod_SM3, (void) ) +IPPAPI( const IppsHashMethod*, l9_ippsHashMethod_SM3, (void) ) +IPPAPI( const IppsHashMethod*, y8_ippsHashMethod_SM3, (void) ) -IPPFUN( const IppsHashMethod*,sgx_disp_ippsHashMethod_SM3, (void) ) +IPPFUN( const IppsHashMethod*, sgx_disp_ippsHashMethod_SM3, (void) ) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashMethod_SM3( ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashMethod_SM3( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashMethod_SM3( ); - } else + } 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 )) { - return h9_ippsHashMethod_SM3( ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashMethod_SM3( ); - } else - return NULL; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00168.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashPack.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00168.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashPack.c index e2ad120a7..838baca79 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00168.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashPack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashPack,(const IppsHashState* pState, Ipp8u* pBuffer, int bufSize)) -IPPAPI(IppStatus, l9_ippsHashPack,(const IppsHashState* pState, Ipp8u* pBuffer, int bufSize)) IPPAPI(IppStatus, k1_ippsHashPack,(const IppsHashState* pState, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, l9_ippsHashPack,(const IppsHashState* pState, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, y8_ippsHashPack,(const IppsHashState* pState, Ipp8u* pBuffer, int bufSize)) -IPPFUN(IppStatus,sgx_disp_ippsHashPack,(const IppsHashState* pState, Ipp8u* pBuffer, int bufSize)) +IPPFUN(IppStatus, sgx_disp_ippsHashPack,(const IppsHashState* pState, Ipp8u* pBuffer, int bufSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashPack( pState, pBuffer, bufSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashPack( pState, pBuffer, bufSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashPack( pState, pBuffer, bufSize ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashPack,(const IppsHashState* pState, Ipp8u* pBuffer, int bufSize)) -IPPAPI(IppStatus, h9_ippsHashPack,(const IppsHashState* pState, Ipp8u* pBuffer, int bufSize)) - -IPPFUN(IppStatus,sgx_disp_ippsHashPack,(const IppsHashState* pState, Ipp8u* pBuffer, int bufSize)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashPack( pState, pBuffer, bufSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashPack( pState, pBuffer, bufSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00208.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashPack_rmf.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00208.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashPack_rmf.c index fef0e67d0..ff37a744b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00208.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashPack_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashPack_rmf,(const IppsHashState_rmf* pState, Ipp8u* pBuffer, int bufSize)) -IPPAPI(IppStatus, l9_ippsHashPack_rmf,(const IppsHashState_rmf* pState, Ipp8u* pBuffer, int bufSize)) IPPAPI(IppStatus, k1_ippsHashPack_rmf,(const IppsHashState_rmf* pState, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, l9_ippsHashPack_rmf,(const IppsHashState_rmf* pState, Ipp8u* pBuffer, int bufSize)) +IPPAPI(IppStatus, y8_ippsHashPack_rmf,(const IppsHashState_rmf* pState, Ipp8u* pBuffer, int bufSize)) -IPPFUN(IppStatus,sgx_disp_ippsHashPack_rmf,(const IppsHashState_rmf* pState, Ipp8u* pBuffer, int bufSize)) +IPPFUN(IppStatus, sgx_disp_ippsHashPack_rmf,(const IppsHashState_rmf* pState, Ipp8u* pBuffer, int bufSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashPack_rmf( pState, pBuffer, bufSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashPack_rmf( pState, pBuffer, bufSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashPack_rmf( pState, pBuffer, bufSize ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashPack_rmf,(const IppsHashState_rmf* pState, Ipp8u* pBuffer, int bufSize)) -IPPAPI(IppStatus, h9_ippsHashPack_rmf,(const IppsHashState_rmf* pState, Ipp8u* pBuffer, int bufSize)) - -IPPFUN(IppStatus,sgx_disp_ippsHashPack_rmf,(const IppsHashState_rmf* pState, Ipp8u* pBuffer, int bufSize)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashPack_rmf( pState, pBuffer, bufSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashPack_rmf( pState, pBuffer, bufSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA224.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA224.c new file mode 100644 index 000000000..39630722e --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA224.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI( IppStatus, k1_ippsHashStateMethodSet_SHA224, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashStateMethodSet_SHA224, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashStateMethodSet_SHA224, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) + +IPPFUN( IppStatus, sgx_disp_ippsHashStateMethodSet_SHA224, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsHashStateMethodSet_SHA224( pState, pMethod ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsHashStateMethodSet_SHA224( pState, pMethod ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsHashStateMethodSet_SHA224( pState, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA224_NI.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA224_NI.c new file mode 100644 index 000000000..c856dd0a2 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA224_NI.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI( IppStatus, k1_ippsHashStateMethodSet_SHA224_NI, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashStateMethodSet_SHA224_NI, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashStateMethodSet_SHA224_NI, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) + +IPPFUN( IppStatus, sgx_disp_ippsHashStateMethodSet_SHA224_NI, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsHashStateMethodSet_SHA224_NI( pState, pMethod ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsHashStateMethodSet_SHA224_NI( pState, pMethod ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsHashStateMethodSet_SHA224_NI( pState, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA224_TT.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA224_TT.c new file mode 100644 index 000000000..db94f24a2 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA224_TT.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI( IppStatus, k1_ippsHashStateMethodSet_SHA224_TT, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashStateMethodSet_SHA224_TT, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashStateMethodSet_SHA224_TT, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) + +IPPFUN( IppStatus, sgx_disp_ippsHashStateMethodSet_SHA224_TT, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsHashStateMethodSet_SHA224_TT( pState, pMethod ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsHashStateMethodSet_SHA224_TT( pState, pMethod ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsHashStateMethodSet_SHA224_TT( pState, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA256.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA256.c new file mode 100644 index 000000000..78cebdff4 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA256.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI( IppStatus, k1_ippsHashStateMethodSet_SHA256, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashStateMethodSet_SHA256, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashStateMethodSet_SHA256, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) + +IPPFUN( IppStatus, sgx_disp_ippsHashStateMethodSet_SHA256, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsHashStateMethodSet_SHA256( pState, pMethod ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsHashStateMethodSet_SHA256( pState, pMethod ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsHashStateMethodSet_SHA256( pState, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA256_NI.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA256_NI.c new file mode 100644 index 000000000..e9e8358f5 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA256_NI.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI( IppStatus, k1_ippsHashStateMethodSet_SHA256_NI, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashStateMethodSet_SHA256_NI, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashStateMethodSet_SHA256_NI, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) + +IPPFUN( IppStatus, sgx_disp_ippsHashStateMethodSet_SHA256_NI, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsHashStateMethodSet_SHA256_NI( pState, pMethod ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsHashStateMethodSet_SHA256_NI( pState, pMethod ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsHashStateMethodSet_SHA256_NI( pState, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA256_TT.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA256_TT.c new file mode 100644 index 000000000..ad6ef2956 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA256_TT.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI( IppStatus, k1_ippsHashStateMethodSet_SHA256_TT, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashStateMethodSet_SHA256_TT, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashStateMethodSet_SHA256_TT, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) + +IPPFUN( IppStatus, sgx_disp_ippsHashStateMethodSet_SHA256_TT, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsHashStateMethodSet_SHA256_TT( pState, pMethod ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsHashStateMethodSet_SHA256_TT( pState, pMethod ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsHashStateMethodSet_SHA256_TT( pState, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA384.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA384.c new file mode 100644 index 000000000..f8218e9b7 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA384.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI( IppStatus, k1_ippsHashStateMethodSet_SHA384, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashStateMethodSet_SHA384, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashStateMethodSet_SHA384, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) + +IPPFUN( IppStatus, sgx_disp_ippsHashStateMethodSet_SHA384, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsHashStateMethodSet_SHA384( pState, pMethod ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsHashStateMethodSet_SHA384( pState, pMethod ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsHashStateMethodSet_SHA384( pState, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA512.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA512.c new file mode 100644 index 000000000..dd4b43dc4 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA512.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI( IppStatus, k1_ippsHashStateMethodSet_SHA512, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashStateMethodSet_SHA512, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashStateMethodSet_SHA512, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) + +IPPFUN( IppStatus, sgx_disp_ippsHashStateMethodSet_SHA512, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsHashStateMethodSet_SHA512( pState, pMethod ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsHashStateMethodSet_SHA512( pState, pMethod ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsHashStateMethodSet_SHA512( pState, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA512_224.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA512_224.c new file mode 100644 index 000000000..4b321ee06 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA512_224.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI( IppStatus, k1_ippsHashStateMethodSet_SHA512_224, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashStateMethodSet_SHA512_224, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashStateMethodSet_SHA512_224, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) + +IPPFUN( IppStatus, sgx_disp_ippsHashStateMethodSet_SHA512_224, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsHashStateMethodSet_SHA512_224( pState, pMethod ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsHashStateMethodSet_SHA512_224( pState, pMethod ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsHashStateMethodSet_SHA512_224( pState, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA512_256.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA512_256.c new file mode 100644 index 000000000..dd4196db5 --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SHA512_256.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI( IppStatus, k1_ippsHashStateMethodSet_SHA512_256, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashStateMethodSet_SHA512_256, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashStateMethodSet_SHA512_256, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) + +IPPFUN( IppStatus, sgx_disp_ippsHashStateMethodSet_SHA512_256, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsHashStateMethodSet_SHA512_256( pState, pMethod ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsHashStateMethodSet_SHA512_256( pState, pMethod ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsHashStateMethodSet_SHA512_256( pState, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SM3.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SM3.c new file mode 100644 index 000000000..fc8a7396f --- /dev/null +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashStateMethodSet_SM3.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2011-2021 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 "ippcp.h" + +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if defined (_M_AMD64) || defined (__x86_64__) + +#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) +#define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) +#define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) + +#ifdef __cplusplus +extern "C" { +#endif + +IPPAPI( IppStatus, k1_ippsHashStateMethodSet_SM3, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, l9_ippsHashStateMethodSet_SM3, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +IPPAPI( IppStatus, y8_ippsHashStateMethodSet_SM3, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) + +IPPFUN( IppStatus, sgx_disp_ippsHashStateMethodSet_SM3, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) ) +{ + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); + + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { + return k1_ippsHashStateMethodSet_SM3( pState, pMethod ); + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { + return l9_ippsHashStateMethodSet_SM3( pState, pMethod ); + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { + return y8_ippsHashStateMethodSet_SM3( pState, pMethod ); + } else + return ippStsCpuNotSupportedErr; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00169.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashUnpack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00169.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashUnpack.c index 72e06670f..6dd3ba3d8 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00169.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashUnpack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pState)) -IPPAPI(IppStatus, l9_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pState)) IPPAPI(IppStatus, k1_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pState)) +IPPAPI(IppStatus, l9_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pState)) +IPPAPI(IppStatus, y8_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pState)) -IPPFUN(IppStatus,sgx_disp_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pState)) +IPPFUN(IppStatus, sgx_disp_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashUnpack( pBuffer, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashUnpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashUnpack( pBuffer, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pState)) -IPPAPI(IppStatus, h9_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsHashUnpack,(const Ipp8u* pBuffer, IppsHashState* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashUnpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashUnpack( pBuffer, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00209.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashUnpack_rmf.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00209.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashUnpack_rmf.c index 2ecc8d05d..8a142d62a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00209.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashUnpack_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pState)) -IPPAPI(IppStatus, l9_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pState)) IPPAPI(IppStatus, k1_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pState)) +IPPAPI(IppStatus, l9_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pState)) +IPPAPI(IppStatus, y8_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pState)) -IPPFUN(IppStatus,sgx_disp_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pState)) +IPPFUN(IppStatus, sgx_disp_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashUnpack_rmf( pBuffer, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashUnpack_rmf( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashUnpack_rmf( pBuffer, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pState)) -IPPAPI(IppStatus, h9_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsHashUnpack_rmf,(const Ipp8u* pBuffer, IppsHashState_rmf* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashUnpack_rmf( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashUnpack_rmf( pBuffer, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00171.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashUpdate.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00171.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashUpdate.c index a173c8112..1708a7f5f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00171.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashUpdate.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pState)) -IPPAPI(IppStatus, l9_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pState)) IPPAPI(IppStatus, k1_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pState)) +IPPAPI(IppStatus, l9_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pState)) +IPPAPI(IppStatus, y8_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pState)) -IPPFUN(IppStatus,sgx_disp_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pState)) +IPPFUN(IppStatus, sgx_disp_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashUpdate( pSrc, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashUpdate( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashUpdate( pSrc, len, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pState)) -IPPAPI(IppStatus, h9_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsHashUpdate,(const Ipp8u* pSrc, int len, IppsHashState* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashUpdate( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashUpdate( pSrc, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00211.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashUpdate_rmf.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00211.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashUpdate_rmf.c index e77bb2e1b..291444f0f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00211.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsHashUpdate_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pState)) -IPPAPI(IppStatus, l9_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pState)) IPPAPI(IppStatus, k1_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pState)) +IPPAPI(IppStatus, l9_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pState)) +IPPAPI(IppStatus, y8_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pState)) -IPPFUN(IppStatus,sgx_disp_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pState)) +IPPFUN(IppStatus, sgx_disp_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsHashUpdate_rmf( pSrc, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsHashUpdate_rmf( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsHashUpdate_rmf( pSrc, len, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pState)) -IPPAPI(IppStatus, h9_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsHashUpdate_rmf,(const Ipp8u* pSrc, int len, IppsHashState_rmf* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsHashUpdate_rmf( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsHashUpdate_rmf( pSrc, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00250.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMAC_BN_I.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00250.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMAC_BN_I.c index da5035c29..df35c0e33 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00250.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMAC_BN_I.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMAC_BN_I, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) -IPPAPI(IppStatus, l9_ippsMAC_BN_I, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) IPPAPI(IppStatus, k1_ippsMAC_BN_I, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsMAC_BN_I, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, y8_ippsMAC_BN_I, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMAC_BN_I( pA, pB, pR ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMAC_BN_I( pA, pB, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMAC_BN_I( pA, pB, pR ); - } else + } 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 )) { - return h9_ippsMAC_BN_I( pA, pB, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMAC_BN_I( pA, pB, pR ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00150.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Duplicate.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00150.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Duplicate.c index 9397a0b2c..e40a5122d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00150.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Duplicate.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMD5Duplicate,(const IppsMD5State* pSrcState, IppsMD5State* pDstState)) -IPPAPI(IppStatus, l9_ippsMD5Duplicate,(const IppsMD5State* pSrcState, IppsMD5State* pDstState)) IPPAPI(IppStatus, k1_ippsMD5Duplicate,(const IppsMD5State* pSrcState, IppsMD5State* pDstState)) +IPPAPI(IppStatus, l9_ippsMD5Duplicate,(const IppsMD5State* pSrcState, IppsMD5State* pDstState)) +IPPAPI(IppStatus, y8_ippsMD5Duplicate,(const IppsMD5State* pSrcState, IppsMD5State* pDstState)) -IPPFUN(IppStatus,sgx_disp_ippsMD5Duplicate,(const IppsMD5State* pSrcState, IppsMD5State* pDstState)) +IPPFUN(IppStatus, sgx_disp_ippsMD5Duplicate,(const IppsMD5State* pSrcState, IppsMD5State* pDstState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMD5Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMD5Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMD5Duplicate( pSrcState, pDstState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsMD5Duplicate,(const IppsMD5State* pSrcState, IppsMD5State* pDstState)) -IPPAPI(IppStatus, h9_ippsMD5Duplicate,(const IppsMD5State* pSrcState, IppsMD5State* pDstState)) - -IPPFUN(IppStatus,sgx_disp_ippsMD5Duplicate,(const IppsMD5State* pSrcState, IppsMD5State* pDstState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsMD5Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMD5Duplicate( pSrcState, pDstState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00155.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Final.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00155.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Final.c index 16f20d298..2c10b8f25 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00155.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Final.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pState)) -IPPAPI(IppStatus, l9_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pState)) IPPAPI(IppStatus, k1_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pState)) +IPPAPI(IppStatus, l9_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pState)) +IPPAPI(IppStatus, y8_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMD5Final( pMD, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMD5Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMD5Final( pMD, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pState)) -IPPAPI(IppStatus, h9_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsMD5Final,(Ipp8u* pMD, IppsMD5State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsMD5Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMD5Final( pMD, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00148.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5GetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00148.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5GetSize.c index 32a5bd472..662512216 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00148.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5GetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMD5GetSize,(int* pSize)) -IPPAPI(IppStatus, l9_ippsMD5GetSize,(int* pSize)) IPPAPI(IppStatus, k1_ippsMD5GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsMD5GetSize,(int* pSize)) +IPPAPI(IppStatus, y8_ippsMD5GetSize,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsMD5GetSize,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsMD5GetSize,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMD5GetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMD5GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMD5GetSize( pSize ); - } else + } 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 )) { - return h9_ippsMD5GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMD5GetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00154.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5GetTag.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00154.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5GetTag.c index 39ffa7839..dce8b00b4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00154.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5GetTag.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pState)) -IPPAPI(IppStatus, l9_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pState)) IPPAPI(IppStatus, k1_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pState)) +IPPAPI(IppStatus, l9_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pState)) +IPPAPI(IppStatus, y8_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMD5GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMD5GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMD5GetTag( pTag, tagLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pState)) -IPPAPI(IppStatus, h9_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsMD5GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsMD5State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsMD5GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMD5GetTag( pTag, tagLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00149.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Init.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00149.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Init.c index 2329a852e..facf95149 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00149.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Init.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMD5Init,(IppsMD5State* pState)) -IPPAPI(IppStatus, l9_ippsMD5Init,(IppsMD5State* pState)) IPPAPI(IppStatus, k1_ippsMD5Init,(IppsMD5State* pState)) +IPPAPI(IppStatus, l9_ippsMD5Init,(IppsMD5State* pState)) +IPPAPI(IppStatus, y8_ippsMD5Init,(IppsMD5State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsMD5Init,(IppsMD5State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsMD5Init,(IppsMD5State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMD5Init( pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMD5Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMD5Init( pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsMD5Init,(IppsMD5State* pState)) -IPPAPI(IppStatus, h9_ippsMD5Init,(IppsMD5State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsMD5Init,(IppsMD5State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsMD5Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMD5Init( pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00156.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5MessageDigest.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00156.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5MessageDigest.c index d95818298..16cf2eefc 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00156.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5MessageDigest.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMD5MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPAPI(IppStatus, l9_ippsMD5MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) IPPAPI(IppStatus, k1_ippsMD5MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsMD5MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, y8_ippsMD5MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPFUN(IppStatus,sgx_disp_ippsMD5MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPFUN(IppStatus, sgx_disp_ippsMD5MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMD5MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMD5MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMD5MessageDigest( pMsg, len, pMD ); - } else + } 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 )) { - return h9_ippsMD5MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMD5MessageDigest( pMsg, len, pMD ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00151.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Pack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00151.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Pack.c index b7420a551..e92a3d077 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00151.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Pack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMD5Pack,(const IppsMD5State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, l9_ippsMD5Pack,(const IppsMD5State* pState, Ipp8u* pBuffer)) IPPAPI(IppStatus, k1_ippsMD5Pack,(const IppsMD5State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsMD5Pack,(const IppsMD5State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, y8_ippsMD5Pack,(const IppsMD5State* pState, Ipp8u* pBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsMD5Pack,(const IppsMD5State* pState, Ipp8u* pBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsMD5Pack,(const IppsMD5State* pState, Ipp8u* pBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMD5Pack( pState, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMD5Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMD5Pack( pState, pBuffer ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsMD5Pack,(const IppsMD5State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, h9_ippsMD5Pack,(const IppsMD5State* pState, Ipp8u* pBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsMD5Pack,(const IppsMD5State* pState, Ipp8u* pBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsMD5Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMD5Pack( pState, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00152.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Unpack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00152.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Unpack.c index 78797cb33..a771838a6 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00152.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Unpack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pState)) -IPPAPI(IppStatus, l9_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pState)) IPPAPI(IppStatus, k1_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pState)) +IPPAPI(IppStatus, l9_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pState)) +IPPAPI(IppStatus, y8_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMD5Unpack( pBuffer, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMD5Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMD5Unpack( pBuffer, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pState)) -IPPAPI(IppStatus, h9_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsMD5Unpack,(const Ipp8u* pBuffer, IppsMD5State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsMD5Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMD5Unpack( pBuffer, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00153.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Update.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00153.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Update.c index d99c422be..5de972334 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00153.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMD5Update.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pState)) -IPPAPI(IppStatus, l9_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pState)) IPPAPI(IppStatus, k1_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pState)) +IPPAPI(IppStatus, l9_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pState)) +IPPAPI(IppStatus, y8_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMD5Update( pSrc, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMD5Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMD5Update( pSrc, len, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pState)) -IPPAPI(IppStatus, h9_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsMD5Update,(const Ipp8u* pSrc, int len, IppsMD5State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsMD5Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMD5Update( pSrc, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00217.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMGF.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00217.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMGF.c index 13871400c..cd125e5fa 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00217.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMGF.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsMGF,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, IppHashAlgId hashAlg)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMGF( pSeed, seedLen, pMask, maskLen, hashAlg ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMGF( pSeed, seedLen, pMask, maskLen, hashAlg ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMGF( pSeed, seedLen, pMask, maskLen, hashAlg ); - } else + } 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 )) { - return h9_ippsMGF( pSeed, seedLen, pMask, maskLen, hashAlg ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMGF( pSeed, seedLen, pMask, maskLen, hashAlg ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00218.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMGF1_rmf.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00218.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMGF1_rmf.c index eefb0508e..7580ded2e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00218.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMGF1_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsMGF1_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMGF1_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMGF1_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMGF1_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); - } else + } 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 )) { - return h9_ippsMGF1_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMGF1_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00219.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMGF2_rmf.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00219.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMGF2_rmf.c index 033aa2c7e..cdcb2fcd0 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00219.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMGF2_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsMGF2_rmf,(const Ipp8u* pSeed, int seedLen, Ipp8u* pMask, int maskLen, const IppsHashMethod* pMethod)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMGF2_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMGF2_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMGF2_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); - } else + } 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 )) { - return h9_ippsMGF2_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMGF2_rmf( pSeed, seedLen, pMask, maskLen, pMethod ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00254.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsModInv_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00254.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsModInv_BN.c index 46bd61fc9..5e6c9fa97 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00254.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsModInv_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) -IPPAPI(IppStatus, l9_ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) IPPAPI(IppStatus, k1_ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) +IPPAPI(IppStatus, l9_ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) +IPPAPI(IppStatus, y8_ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) -IPPFUN(IppStatus,sgx_disp_ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) +IPPFUN(IppStatus, sgx_disp_ippsModInv_BN,(IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pInv)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsModInv_BN( pA, pM, pInv ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsModInv_BN( pA, pM, pInv ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsModInv_BN( pA, pM, pInv ); - } else + } 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 )) { - return h9_ippsModInv_BN( pA, pM, pInv ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsModInv_BN( pA, pM, pInv ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00252.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMod_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00252.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMod_BN.c index 9da0c39b9..f2499a29c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00252.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMod_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) -IPPAPI(IppStatus, l9_ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) IPPAPI(IppStatus, k1_ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) +IPPAPI(IppStatus, y8_ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) -IPPFUN(IppStatus,sgx_disp_ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) +IPPFUN(IppStatus, sgx_disp_ippsMod_BN, (IppsBigNumState* pA, IppsBigNumState* pM, IppsBigNumState* pR)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMod_BN( pA, pM, pR ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMod_BN( pA, pM, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMod_BN( pA, pM, pR ); - } else + } 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 )) { - return h9_ippsMod_BN( pA, pM, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMod_BN( pA, pM, pR ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00263.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontExp.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00263.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontExp.c index 90aa90bb4..fac540ba3 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00263.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontExp.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsMontExp, (const IppsBigNumState* pA, const IppsBigNumState* pE, IppsMontState* m, IppsBigNumState* pR)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMontExp( pA, pE, m, pR ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMontExp( pA, pE, m, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMontExp( pA, pE, m, pR ); - } else + } 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 )) { - return h9_ippsMontExp( pA, pE, m, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMontExp( pA, pE, m, pR ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00261.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontForm.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00261.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontForm.c index 09eea04d0..e8b0f8b26 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00261.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontForm.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pCtx, IppsBigNumState* pR)) -IPPAPI(IppStatus, l9_ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pCtx, IppsBigNumState* pR)) IPPAPI(IppStatus, k1_ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pCtx, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pCtx, IppsBigNumState* pR)) +IPPAPI(IppStatus, y8_ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pCtx, IppsBigNumState* pR)) -IPPFUN(IppStatus,sgx_disp_ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pCtx, IppsBigNumState* pR)) +IPPFUN(IppStatus, sgx_disp_ippsMontForm,(const IppsBigNumState* pA, IppsMontState* pCtx, IppsBigNumState* pR)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMontForm( pA, pCtx, pR ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMontForm( pA, pCtx, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMontForm( pA, pCtx, pR ); - } else + } 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 )) { - return h9_ippsMontForm( pA, pCtx, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMontForm( pA, pCtx, pR ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00260.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontGet.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00260.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontGet.c index 03eee0737..c4f3fdfaf 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00260.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontGet.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMontGet,(Ipp32u* pModulo, int* pSize, const IppsMontState* pCtx)) -IPPAPI(IppStatus, l9_ippsMontGet,(Ipp32u* pModulo, int* pSize, const IppsMontState* pCtx)) IPPAPI(IppStatus, k1_ippsMontGet,(Ipp32u* pModulo, int* pSize, const IppsMontState* pCtx)) +IPPAPI(IppStatus, l9_ippsMontGet,(Ipp32u* pModulo, int* pSize, const IppsMontState* pCtx)) +IPPAPI(IppStatus, y8_ippsMontGet,(Ipp32u* pModulo, int* pSize, const IppsMontState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsMontGet,(Ipp32u* pModulo, int* pSize, const IppsMontState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsMontGet,(Ipp32u* pModulo, int* pSize, const IppsMontState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMontGet( pModulo, pSize, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMontGet( pModulo, pSize, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMontGet( pModulo, pSize, pCtx ); - } else + } 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 )) { - return h9_ippsMontGet( pModulo, pSize, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMontGet( pModulo, pSize, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00257.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontGetSize.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00257.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontGetSize.c index a32e11495..887076099 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00257.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) -IPPAPI(IppStatus, l9_ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) IPPAPI(IppStatus, k1_ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) +IPPAPI(IppStatus, l9_ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) +IPPAPI(IppStatus, y8_ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsMontGetSize,(IppsExpMethod method, int length, int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMontGetSize( method, length, pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMontGetSize( method, length, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMontGetSize( method, length, pSize ); - } else + } 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 )) { - return h9_ippsMontGetSize( method, length, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMontGetSize( method, length, pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00258.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontInit.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00258.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontInit.c index 90227e3eb..a6e4b080f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00258.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) -IPPAPI(IppStatus, l9_ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) IPPAPI(IppStatus, k1_ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) +IPPAPI(IppStatus, l9_ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) +IPPAPI(IppStatus, y8_ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsMontInit,(IppsExpMethod method, int length, IppsMontState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMontInit( method, length, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMontInit( method, length, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMontInit( method, length, pCtx ); - } else + } 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 )) { - return h9_ippsMontInit( method, length, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMontInit( method, length, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00262.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontMul.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00262.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontMul.c index 553da8b43..296d322cc 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00262.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontMul.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsMontMul, (const IppsBigNumState* pA, const IppsBigNumState* pB, IppsMontState* m, IppsBigNumState* pR)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMontMul( pA, pB, m, pR ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMontMul( pA, pB, m, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMontMul( pA, pB, m, pR ); - } else + } 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 )) { - return h9_ippsMontMul( pA, pB, m, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMontMul( pA, pB, m, pR ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00259.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontSet.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00259.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontSet.c index 6f8ba97bd..df84d94e8 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00259.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMontSet.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) -IPPAPI(IppStatus, l9_ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) IPPAPI(IppStatus, k1_ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) +IPPAPI(IppStatus, l9_ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) +IPPAPI(IppStatus, y8_ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsMontSet,(const Ipp32u* pModulo, int size, IppsMontState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMontSet( pModulo, size, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMontSet( pModulo, size, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMontSet( pModulo, size, pCtx ); - } else + } 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 )) { - return h9_ippsMontSet( pModulo, size, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMontSet( pModulo, size, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00249.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMul_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00249.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMul_BN.c index 07fbbc723..0f51bf4ab 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00249.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsMul_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) -IPPAPI(IppStatus, l9_ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) IPPAPI(IppStatus, k1_ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, y8_ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) -IPPFUN(IppStatus,sgx_disp_ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPFUN(IppStatus, sgx_disp_ippsMul_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsMul_BN( pA, pB, pR ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsMul_BN( pA, pB, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsMul_BN( pA, pB, pR ); - } else + } 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 )) { - return h9_ippsMul_BN( pA, pB, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsMul_BN( pA, pB, pR ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00270.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGGetSeed.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00270.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGGetSeed.c index 8d4977886..6e8e0b807 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00270.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGGetSeed.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPRNGGetSeed, (const IppsPRNGState* pCtx,IppsBigNumState* pSeed)) -IPPAPI(IppStatus, l9_ippsPRNGGetSeed, (const IppsPRNGState* pCtx,IppsBigNumState* pSeed)) IPPAPI(IppStatus, k1_ippsPRNGGetSeed, (const IppsPRNGState* pCtx,IppsBigNumState* pSeed)) +IPPAPI(IppStatus, l9_ippsPRNGGetSeed, (const IppsPRNGState* pCtx,IppsBigNumState* pSeed)) +IPPAPI(IppStatus, y8_ippsPRNGGetSeed, (const IppsPRNGState* pCtx,IppsBigNumState* pSeed)) -IPPFUN(IppStatus,sgx_disp_ippsPRNGGetSeed, (const IppsPRNGState* pCtx,IppsBigNumState* pSeed)) +IPPFUN(IppStatus, sgx_disp_ippsPRNGGetSeed, (const IppsPRNGState* pCtx,IppsBigNumState* pSeed)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPRNGGetSeed( pCtx, pSeed ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPRNGGetSeed( pCtx, pSeed ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPRNGGetSeed( pCtx, pSeed ); - } else + } 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 )) { - return h9_ippsPRNGGetSeed( pCtx, pSeed ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPRNGGetSeed( pCtx, pSeed ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00264.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGGetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00264.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGGetSize.c index 1140ecaec..9d0c0ab4c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00264.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPRNGGetSize,(int* pSize)) -IPPAPI(IppStatus, l9_ippsPRNGGetSize,(int* pSize)) IPPAPI(IppStatus, k1_ippsPRNGGetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsPRNGGetSize,(int* pSize)) +IPPAPI(IppStatus, y8_ippsPRNGGetSize,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsPRNGGetSize,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsPRNGGetSize,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPRNGGetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPRNGGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPRNGGetSize( pSize ); - } else + } 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 )) { - return h9_ippsPRNGGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPRNGGetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00265.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGInit.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00265.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGInit.c index aa5655ed7..a7423800d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00265.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) -IPPAPI(IppStatus, l9_ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) IPPAPI(IppStatus, k1_ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, y8_ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPRNGInit, (int seedBits, IppsPRNGState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPRNGInit( seedBits, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPRNGInit( seedBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPRNGInit( seedBits, pCtx ); - } else + } 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 )) { - return h9_ippsPRNGInit( seedBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPRNGInit( seedBits, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00268.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGSetAugment.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00268.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGSetAugment.c index 71d164055..93a2aa429 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00268.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGSetAugment.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPRNGSetAugment,(const IppsBigNumState* pAug, IppsPRNGState* pCtx)) -IPPAPI(IppStatus, l9_ippsPRNGSetAugment,(const IppsBigNumState* pAug, IppsPRNGState* pCtx)) IPPAPI(IppStatus, k1_ippsPRNGSetAugment,(const IppsBigNumState* pAug, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGSetAugment,(const IppsBigNumState* pAug, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, y8_ippsPRNGSetAugment,(const IppsBigNumState* pAug, IppsPRNGState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPRNGSetAugment,(const IppsBigNumState* pAug, IppsPRNGState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPRNGSetAugment,(const IppsBigNumState* pAug, IppsPRNGState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPRNGSetAugment( pAug, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPRNGSetAugment( pAug, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPRNGSetAugment( pAug, pCtx ); - } else + } 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 )) { - return h9_ippsPRNGSetAugment( pAug, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPRNGSetAugment( pAug, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00267.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGSetH0.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00267.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGSetH0.c index abced3471..79880e740 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00267.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGSetH0.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPRNGSetH0, (const IppsBigNumState* pH0, IppsPRNGState* pCtx)) -IPPAPI(IppStatus, l9_ippsPRNGSetH0, (const IppsBigNumState* pH0, IppsPRNGState* pCtx)) IPPAPI(IppStatus, k1_ippsPRNGSetH0, (const IppsBigNumState* pH0, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGSetH0, (const IppsBigNumState* pH0, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, y8_ippsPRNGSetH0, (const IppsBigNumState* pH0, IppsPRNGState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPRNGSetH0, (const IppsBigNumState* pH0, IppsPRNGState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPRNGSetH0, (const IppsBigNumState* pH0, IppsPRNGState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPRNGSetH0( pH0, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPRNGSetH0( pH0, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPRNGSetH0( pH0, pCtx ); - } else + } 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 )) { - return h9_ippsPRNGSetH0( pH0, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPRNGSetH0( pH0, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00266.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGSetModulus.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00266.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGSetModulus.c index 4f12eb6be..938e4182c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00266.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGSetModulus.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPRNGSetModulus,(const IppsBigNumState* pMod, IppsPRNGState* pCtx)) -IPPAPI(IppStatus, l9_ippsPRNGSetModulus,(const IppsBigNumState* pMod, IppsPRNGState* pCtx)) IPPAPI(IppStatus, k1_ippsPRNGSetModulus,(const IppsBigNumState* pMod, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGSetModulus,(const IppsBigNumState* pMod, IppsPRNGState* pCtx)) +IPPAPI(IppStatus, y8_ippsPRNGSetModulus,(const IppsBigNumState* pMod, IppsPRNGState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPRNGSetModulus,(const IppsBigNumState* pMod, IppsPRNGState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPRNGSetModulus,(const IppsBigNumState* pMod, IppsPRNGState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPRNGSetModulus( pMod, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPRNGSetModulus( pMod, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPRNGSetModulus( pMod, pCtx ); - } else + } 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 )) { - return h9_ippsPRNGSetModulus( pMod, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPRNGSetModulus( pMod, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00269.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGSetSeed.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00269.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGSetSeed.c index 7a43b5dec..64441f1ab 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00269.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGSetSeed.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPRNGSetSeed, (const IppsBigNumState* pSeed,IppsPRNGState* pCtx)) -IPPAPI(IppStatus, l9_ippsPRNGSetSeed, (const IppsBigNumState* pSeed,IppsPRNGState* pCtx)) IPPAPI(IppStatus, k1_ippsPRNGSetSeed, (const IppsBigNumState* pSeed,IppsPRNGState* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGSetSeed, (const IppsBigNumState* pSeed,IppsPRNGState* pCtx)) +IPPAPI(IppStatus, y8_ippsPRNGSetSeed, (const IppsBigNumState* pSeed,IppsPRNGState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPRNGSetSeed, (const IppsBigNumState* pSeed,IppsPRNGState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPRNGSetSeed, (const IppsBigNumState* pSeed,IppsPRNGState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPRNGSetSeed( pSeed, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPRNGSetSeed( pSeed, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPRNGSetSeed( pSeed, pCtx ); - } else + } 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 )) { - return h9_ippsPRNGSetSeed( pSeed, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPRNGSetSeed( pSeed, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00271.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGen.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00271.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGen.c index a85bfe213..0f54d9227 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00271.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGen.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) -IPPAPI(IppStatus, l9_ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) IPPAPI(IppStatus, k1_ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, y8_ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPRNGen, (Ipp32u* pRand, int nBits, void* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPRNGen( pRand, nBits, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPRNGen( pRand, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPRNGen( pRand, nBits, pCtx ); - } else + } 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 )) { - return h9_ippsPRNGen( pRand, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPRNGen( pRand, nBits, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00273.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGenRDRAND.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00273.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGenRDRAND.c index df270e2a5..7723ae488 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00273.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGenRDRAND.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPRNGenRDRAND, (Ipp32u* pRand, int nBits, void* pCtx)) -IPPAPI(IppStatus, l9_ippsPRNGenRDRAND, (Ipp32u* pRand, int nBits, void* pCtx)) IPPAPI(IppStatus, k1_ippsPRNGenRDRAND, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGenRDRAND, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, y8_ippsPRNGenRDRAND, (Ipp32u* pRand, int nBits, void* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPRNGenRDRAND, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPRNGenRDRAND, (Ipp32u* pRand, int nBits, void* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPRNGenRDRAND( pRand, nBits, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPRNGenRDRAND( pRand, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPRNGenRDRAND( pRand, nBits, pCtx ); - } else + } 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 )) { - return h9_ippsPRNGenRDRAND( pRand, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPRNGenRDRAND( pRand, nBits, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00274.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGenRDRAND_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00274.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGenRDRAND_BN.c index 026213aa3..d2cb38bc1 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00274.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGenRDRAND_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPRNGenRDRAND_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) -IPPAPI(IppStatus, l9_ippsPRNGenRDRAND_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) IPPAPI(IppStatus, k1_ippsPRNGenRDRAND_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGenRDRAND_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, y8_ippsPRNGenRDRAND_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPRNGenRDRAND_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPRNGenRDRAND_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPRNGenRDRAND_BN( pRand, nBits, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPRNGenRDRAND_BN( pRand, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPRNGenRDRAND_BN( pRand, nBits, pCtx ); - } else + } 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 )) { - return h9_ippsPRNGenRDRAND_BN( pRand, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPRNGenRDRAND_BN( pRand, nBits, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00272.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGen_BN.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00272.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGen_BN.c index bc58ec184..5f59ea47a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00272.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPRNGen_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPRNGen_BN, (IppsBigNumState* pRand, int nBits, void* pCtx)) -IPPAPI(IppStatus, l9_ippsPRNGen_BN, (IppsBigNumState* pRand, int nBits, void* pCtx)) IPPAPI(IppStatus, k1_ippsPRNGen_BN, (IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, l9_ippsPRNGen_BN, (IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, y8_ippsPRNGen_BN, (IppsBigNumState* pRand, int nBits, void* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPRNGen_BN, (IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPRNGen_BN, (IppsBigNumState* pRand, int nBits, void* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPRNGen_BN( pRand, nBits, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPRNGen_BN( pRand, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPRNGen_BN( pRand, nBits, pCtx ); - } else + } 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 )) { - return h9_ippsPRNGen_BN( pRand, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPRNGen_BN( pRand, nBits, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00279.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGen.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00279.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGen.c index fecdfb0d6..dbfca4823 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00279.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGen.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsPrimeGen, (int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPrimeGen( nBits, nTrials, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPrimeGen( nBits, nTrials, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPrimeGen( nBits, nTrials, pCtx, rndFunc, pRndParam ); - } else + } 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 )) { - return h9_ippsPrimeGen( nBits, nTrials, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPrimeGen( nBits, nTrials, pCtx, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00281.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGen_BN.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00281.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGen_BN.c index 9151e2e6d..4d368b5a8 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00281.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGen_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsPrimeGen_BN,(IppsBigNumState* pPrime, int nBits, int nTrials, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPrimeGen_BN( pPrime, nBits, nTrials, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPrimeGen_BN( pPrime, nBits, nTrials, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPrimeGen_BN( pPrime, nBits, nTrials, pCtx, rndFunc, pRndParam ); - } else + } 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 )) { - return h9_ippsPrimeGen_BN( pPrime, nBits, nTrials, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPrimeGen_BN( pPrime, nBits, nTrials, pCtx, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00283.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGet.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00283.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGet.c index 263f2e9df..ee0c46b1e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00283.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGet.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPrimeGet, (Ipp32u* pPrime, int* pLen, const IppsPrimeState* pCtx)) -IPPAPI(IppStatus, l9_ippsPrimeGet, (Ipp32u* pPrime, int* pLen, const IppsPrimeState* pCtx)) IPPAPI(IppStatus, k1_ippsPrimeGet, (Ipp32u* pPrime, int* pLen, const IppsPrimeState* pCtx)) +IPPAPI(IppStatus, l9_ippsPrimeGet, (Ipp32u* pPrime, int* pLen, const IppsPrimeState* pCtx)) +IPPAPI(IppStatus, y8_ippsPrimeGet, (Ipp32u* pPrime, int* pLen, const IppsPrimeState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPrimeGet, (Ipp32u* pPrime, int* pLen, const IppsPrimeState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPrimeGet, (Ipp32u* pPrime, int* pLen, const IppsPrimeState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPrimeGet( pPrime, pLen, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPrimeGet( pPrime, pLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPrimeGet( pPrime, pLen, pCtx ); - } else + } 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 )) { - return h9_ippsPrimeGet( pPrime, pLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPrimeGet( pPrime, pLen, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00277.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGetSize.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00277.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGetSize.c index 1e4f43426..69926e62b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00277.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPrimeGetSize,(int nMaxBits, int* pSize)) -IPPAPI(IppStatus, l9_ippsPrimeGetSize,(int nMaxBits, int* pSize)) IPPAPI(IppStatus, k1_ippsPrimeGetSize,(int nMaxBits, int* pSize)) +IPPAPI(IppStatus, l9_ippsPrimeGetSize,(int nMaxBits, int* pSize)) +IPPAPI(IppStatus, y8_ippsPrimeGetSize,(int nMaxBits, int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsPrimeGetSize,(int nMaxBits, int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsPrimeGetSize,(int nMaxBits, int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPrimeGetSize( nMaxBits, pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPrimeGetSize( nMaxBits, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPrimeGetSize( nMaxBits, pSize ); - } else + } 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 )) { - return h9_ippsPrimeGetSize( nMaxBits, pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPrimeGetSize( nMaxBits, pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00284.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGet_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00284.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGet_BN.c index 12fcdb41c..ff4b9a51f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00284.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeGet_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPrimeGet_BN,(IppsBigNumState* pPrime, const IppsPrimeState* pCtx)) -IPPAPI(IppStatus, l9_ippsPrimeGet_BN,(IppsBigNumState* pPrime, const IppsPrimeState* pCtx)) IPPAPI(IppStatus, k1_ippsPrimeGet_BN,(IppsBigNumState* pPrime, const IppsPrimeState* pCtx)) +IPPAPI(IppStatus, l9_ippsPrimeGet_BN,(IppsBigNumState* pPrime, const IppsPrimeState* pCtx)) +IPPAPI(IppStatus, y8_ippsPrimeGet_BN,(IppsBigNumState* pPrime, const IppsPrimeState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPrimeGet_BN,(IppsBigNumState* pPrime, const IppsPrimeState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPrimeGet_BN,(IppsBigNumState* pPrime, const IppsPrimeState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPrimeGet_BN( pPrime, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPrimeGet_BN( pPrime, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPrimeGet_BN( pPrime, pCtx ); - } else + } 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 )) { - return h9_ippsPrimeGet_BN( pPrime, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPrimeGet_BN( pPrime, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00278.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeInit.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00278.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeInit.c index 8f6103e9a..6ceb594a6 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00278.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) -IPPAPI(IppStatus, l9_ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) IPPAPI(IppStatus, k1_ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) +IPPAPI(IppStatus, l9_ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) +IPPAPI(IppStatus, y8_ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPrimeInit, (int nMaxBits, IppsPrimeState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPrimeInit( nMaxBits, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPrimeInit( nMaxBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPrimeInit( nMaxBits, pCtx ); - } else + } 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 )) { - return h9_ippsPrimeInit( nMaxBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPrimeInit( nMaxBits, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00285.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeSet.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00285.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeSet.c index 7a0357e27..8a4c22008 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00285.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeSet.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPrimeSet, (const Ipp32u* pPrime, int nBits, IppsPrimeState* pCtx)) -IPPAPI(IppStatus, l9_ippsPrimeSet, (const Ipp32u* pPrime, int nBits, IppsPrimeState* pCtx)) IPPAPI(IppStatus, k1_ippsPrimeSet, (const Ipp32u* pPrime, int nBits, IppsPrimeState* pCtx)) +IPPAPI(IppStatus, l9_ippsPrimeSet, (const Ipp32u* pPrime, int nBits, IppsPrimeState* pCtx)) +IPPAPI(IppStatus, y8_ippsPrimeSet, (const Ipp32u* pPrime, int nBits, IppsPrimeState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPrimeSet, (const Ipp32u* pPrime, int nBits, IppsPrimeState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPrimeSet, (const Ipp32u* pPrime, int nBits, IppsPrimeState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPrimeSet( pPrime, nBits, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPrimeSet( pPrime, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPrimeSet( pPrime, nBits, pCtx ); - } else + } 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 )) { - return h9_ippsPrimeSet( pPrime, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPrimeSet( pPrime, nBits, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00286.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeSet_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00286.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeSet_BN.c index ef1f3e3d0..43ccd07eb 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00286.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeSet_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsPrimeSet_BN,(const IppsBigNumState* pPrime, IppsPrimeState* pCtx)) -IPPAPI(IppStatus, l9_ippsPrimeSet_BN,(const IppsBigNumState* pPrime, IppsPrimeState* pCtx)) IPPAPI(IppStatus, k1_ippsPrimeSet_BN,(const IppsBigNumState* pPrime, IppsPrimeState* pCtx)) +IPPAPI(IppStatus, l9_ippsPrimeSet_BN,(const IppsBigNumState* pPrime, IppsPrimeState* pCtx)) +IPPAPI(IppStatus, y8_ippsPrimeSet_BN,(const IppsBigNumState* pPrime, IppsPrimeState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsPrimeSet_BN,(const IppsBigNumState* pPrime, IppsPrimeState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsPrimeSet_BN,(const IppsBigNumState* pPrime, IppsPrimeState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPrimeSet_BN( pPrime, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPrimeSet_BN( pPrime, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPrimeSet_BN( pPrime, pCtx ); - } else + } 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 )) { - return h9_ippsPrimeSet_BN( pPrime, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPrimeSet_BN( pPrime, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00280.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeTest.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00280.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeTest.c index d12adc0e9..8ee64f96c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00280.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeTest.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsPrimeTest,(int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPrimeTest( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPrimeTest( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPrimeTest( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else + } 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 )) { - return h9_ippsPrimeTest( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPrimeTest( nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00282.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeTest_BN.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00282.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeTest_BN.c index 65770fe3b..bcbca8fd4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00282.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsPrimeTest_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsPrimeTest_BN,(const IppsBigNumState* pPrime, int nTrials, Ipp32u* pResult, IppsPrimeState* pCtx, IppBitSupplier rndFunc, void* pRndParam)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsPrimeTest_BN( pPrime, nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsPrimeTest_BN( pPrime, nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsPrimeTest_BN( pPrime, nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else + } 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 )) { - return h9_ippsPrimeTest_BN( pPrime, nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsPrimeTest_BN( pPrime, nTrials, pResult, pCtx, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00306.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSADecrypt_OAEP.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00306.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSADecrypt_OAEP.c index 26f6e0336..352ab1577 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00306.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSADecrypt_OAEP.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSADecrypt_OAEP( pSrc, pLab, labLen, pDst, pDstLen, pKey, hashAlg, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSADecrypt_OAEP( pSrc, pLab, labLen, pDst, pDstLen, pKey, hashAlg, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSADecrypt_OAEP( pSrc, pLab, labLen, pDst, pDstLen, pKey, hashAlg, pBuffer ); - } else + } 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 )) { - return h9_ippsRSADecrypt_OAEP( pSrc, pLab, labLen, pDst, pDstLen, pKey, hashAlg, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSADecrypt_OAEP( pSrc, pLab, labLen, pDst, pDstLen, pKey, hashAlg, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00308.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSADecrypt_OAEP_rmf.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00308.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSADecrypt_OAEP_rmf.c index 96f0a8c8b..09232d53d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00308.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSADecrypt_OAEP_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +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)) -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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSADecrypt_OAEP_rmf( pSrc, pLab, labLen, pDst, pDstLen, pKey, pMethod, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSADecrypt_OAEP_rmf( pSrc, pLab, labLen, pDst, pDstLen, pKey, pMethod, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSADecrypt_OAEP_rmf( pSrc, pLab, labLen, pDst, pDstLen, pKey, pMethod, pBuffer ); - } else + } 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 )) { - return h9_ippsRSADecrypt_OAEP_rmf( pSrc, pLab, labLen, pDst, pDstLen, pKey, pMethod, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSADecrypt_OAEP_rmf( pSrc, pLab, labLen, pDst, pDstLen, pKey, pMethod, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00310.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSADecrypt_PKCSv15.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00310.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSADecrypt_PKCSv15.c index 196e93060..71ac07972 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00310.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSADecrypt_PKCSv15.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsRSADecrypt_PKCSv15,(const Ipp8u* pSrc, Ipp8u* pDst, int* pDstLen, const IppsRSAPrivateKeyState* pKey, Ipp8u* pBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSADecrypt_PKCSv15( pSrc, pDst, pDstLen, pKey, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSADecrypt_PKCSv15( pSrc, pDst, pDstLen, pKey, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSADecrypt_PKCSv15( pSrc, pDst, pDstLen, pKey, pBuffer ); - } else + } 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 )) { - return h9_ippsRSADecrypt_PKCSv15( pSrc, pDst, pDstLen, pKey, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSADecrypt_PKCSv15( pSrc, pDst, pDstLen, pKey, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00305.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAEncrypt_OAEP.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00305.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAEncrypt_OAEP.c index 026621731..46120d905 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00305.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAEncrypt_OAEP.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +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)) -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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSAEncrypt_OAEP( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, hashAlg, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSAEncrypt_OAEP( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, hashAlg, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSAEncrypt_OAEP( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, hashAlg, pBuffer ); - } else + } 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 )) { - return h9_ippsRSAEncrypt_OAEP( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, hashAlg, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSAEncrypt_OAEP( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, hashAlg, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00307.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAEncrypt_OAEP_rmf.c similarity index 64% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00307.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAEncrypt_OAEP_rmf.c index 689b19a17..ab493f150 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00307.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAEncrypt_OAEP_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +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)) -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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSAEncrypt_OAEP_rmf( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, pMethod, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSAEncrypt_OAEP_rmf( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, pMethod, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSAEncrypt_OAEP_rmf( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, pMethod, pBuffer ); - } else + } 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 )) { - return h9_ippsRSAEncrypt_OAEP_rmf( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, pMethod, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSAEncrypt_OAEP_rmf( pSrc, srcLen, pLabel, labLen, pSeed, pDst, pKey, pMethod, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00309.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAEncrypt_PKCSv15.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00309.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAEncrypt_PKCSv15.c index c397fa50a..e0ca19533 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00309.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAEncrypt_PKCSv15.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSAEncrypt_PKCSv15( pSrc, srcLen, pRndPS, pDst, pKey, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSAEncrypt_PKCSv15( pSrc, srcLen, pRndPS, pDst, pKey, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSAEncrypt_PKCSv15( pSrc, srcLen, pRndPS, pDst, pKey, pBuffer ); - } else + } 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 )) { - return h9_ippsRSAEncrypt_PKCSv15( pSrc, srcLen, pRndPS, pDst, pKey, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSAEncrypt_PKCSv15( pSrc, srcLen, pRndPS, pDst, pKey, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00315.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSASign_PKCS1v15.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00315.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSASign_PKCS1v15.c index ca38ff789..a0d481791 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00315.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSASign_PKCS1v15.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSASign_PKCS1v15( pMsg, msgLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSASign_PKCS1v15( pMsg, msgLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSASign_PKCS1v15( pMsg, msgLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); - } else + } 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 )) { - return h9_ippsRSASign_PKCS1v15( pMsg, msgLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSASign_PKCS1v15( pMsg, msgLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00317.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSASign_PKCS1v15_rmf.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00317.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSASign_PKCS1v15_rmf.c index d71e41533..da4a962c5 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00317.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSASign_PKCS1v15_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSASign_PKCS1v15_rmf( pMsg, msgLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSASign_PKCS1v15_rmf( pMsg, msgLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSASign_PKCS1v15_rmf( pMsg, msgLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); - } else + } 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 )) { - return h9_ippsRSASign_PKCS1v15_rmf( pMsg, msgLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSASign_PKCS1v15_rmf( pMsg, msgLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00311.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSASign_PSS.c similarity index 64% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00311.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSASign_PSS.c index 4824e1ce4..a9f561b65 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00311.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSASign_PSS.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +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)) -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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSASign_PSS( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSASign_PSS( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSASign_PSS( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); - } else + } 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 )) { - return h9_ippsRSASign_PSS( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSASign_PSS( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, hashAlg, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00313.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSASign_PSS_rmf.c similarity index 64% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00313.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSASign_PSS_rmf.c index 0e1e009cf..119392b37 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00313.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSASign_PSS_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +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)) -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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSASign_PSS_rmf( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSASign_PSS_rmf( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSASign_PSS_rmf( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); - } else + } 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 )) { - return h9_ippsRSASign_PSS_rmf( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSASign_PSS_rmf( pMsg, msgLen, pSalt, saltLen, pSign, pPrvKey, pPubKey, pMethod, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00316.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAVerify_PKCS1v15.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00316.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAVerify_PKCS1v15.c index cad90c3a6..1c4860d5f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00316.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAVerify_PKCS1v15.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSAVerify_PKCS1v15( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSAVerify_PKCS1v15( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSAVerify_PKCS1v15( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); - } else + } 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 )) { - return h9_ippsRSAVerify_PKCS1v15( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSAVerify_PKCS1v15( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00318.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAVerify_PKCS1v15_rmf.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00318.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAVerify_PKCS1v15_rmf.c index 33405ba8e..e8f3d7985 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00318.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAVerify_PKCS1v15_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSAVerify_PKCS1v15_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSAVerify_PKCS1v15_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSAVerify_PKCS1v15_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); - } else + } 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 )) { - return h9_ippsRSAVerify_PKCS1v15_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSAVerify_PKCS1v15_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00312.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAVerify_PSS.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00312.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAVerify_PSS.c index bcb69ceaa..1f786e3ed 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00312.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAVerify_PSS.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSAVerify_PSS( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSAVerify_PSS( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSAVerify_PSS( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); - } else + } 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 )) { - return h9_ippsRSAVerify_PSS( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSAVerify_PSS( pMsg, msgLen, pSign, pIsValid, pKey, hashAlg, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00314.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAVerify_PSS_rmf.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00314.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAVerify_PSS_rmf.c index e0df2c779..5f95bfe3a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00314.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSAVerify_PSS_rmf.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSAVerify_PSS_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSAVerify_PSS_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSAVerify_PSS_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); - } else + } 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 )) { - return h9_ippsRSAVerify_PSS_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSAVerify_PSS_rmf( pMsg, msgLen, pSign, pIsValid, pKey, pMethod, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00302.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_Decrypt.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00302.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_Decrypt.c index caac0a97c..6d7d601e1 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00302.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_Decrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsRSA_Decrypt,(const IppsBigNumState* pCtxt, IppsBigNumState* pPtxt, const IppsRSAPrivateKeyState* pKey, Ipp8u* pScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_Decrypt( pCtxt, pPtxt, pKey, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_Decrypt( pCtxt, pPtxt, pKey, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_Decrypt( pCtxt, pPtxt, pKey, pScratchBuffer ); - } else + } 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 )) { - return h9_ippsRSA_Decrypt( pCtxt, pPtxt, pKey, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_Decrypt( pCtxt, pPtxt, pKey, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00301.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_Encrypt.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00301.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_Encrypt.c index 573e554b2..95f2a26cd 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00301.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_Encrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsRSA_Encrypt,(const IppsBigNumState* pPtxt, IppsBigNumState* pCtxt, const IppsRSAPublicKeyState* pKey, Ipp8u* pScratchBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_Encrypt( pPtxt, pCtxt, pKey, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_Encrypt( pPtxt, pCtxt, pKey, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_Encrypt( pPtxt, pCtxt, pKey, pScratchBuffer ); - } else + } 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 )) { - return h9_ippsRSA_Encrypt( pPtxt, pCtxt, pKey, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_Encrypt( pPtxt, pCtxt, pKey, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00303.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GenerateKeys.c similarity index 62% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00303.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GenerateKeys.c index f3b39d4ea..44c401386 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00303.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GenerateKeys.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +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)) -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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_GenerateKeys( pSrcPublicExp, pModulus, pPublicExp, pPrivateExp, pPrivateKeyType2, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_GenerateKeys( pSrcPublicExp, pModulus, pPublicExp, pPrivateExp, pPrivateKeyType2, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_GenerateKeys( pSrcPublicExp, pModulus, pPublicExp, pPrivateExp, pPrivateKeyType2, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); - } else + } 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 )) { - return h9_ippsRSA_GenerateKeys( pSrcPublicExp, pModulus, pPublicExp, pPrivateExp, pPrivateKeyType2, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_GenerateKeys( pSrcPublicExp, pModulus, pPublicExp, pPrivateExp, pPrivateKeyType2, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00300.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetBufferSizePrivateKey.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00300.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetBufferSizePrivateKey.c index c395387fd..86ea72a91 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00300.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetBufferSizePrivateKey.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) -IPPAPI(IppStatus, l9_ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) IPPAPI(IppStatus, k1_ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, y8_ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) -IPPFUN(IppStatus,sgx_disp_ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) +IPPFUN(IppStatus, sgx_disp_ippsRSA_GetBufferSizePrivateKey,(int* pBufferSize, const IppsRSAPrivateKeyState* pKey)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_GetBufferSizePrivateKey( pBufferSize, pKey ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_GetBufferSizePrivateKey( pBufferSize, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_GetBufferSizePrivateKey( pBufferSize, pKey ); - } else + } 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 )) { - return h9_ippsRSA_GetBufferSizePrivateKey( pBufferSize, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_GetBufferSizePrivateKey( pBufferSize, pKey ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00299.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetBufferSizePublicKey.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00299.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetBufferSizePublicKey.c index ac3f9c3d2..2887876ed 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00299.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetBufferSizePublicKey.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) -IPPAPI(IppStatus, l9_ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) IPPAPI(IppStatus, k1_ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, y8_ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) -IPPFUN(IppStatus,sgx_disp_ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) +IPPFUN(IppStatus, sgx_disp_ippsRSA_GetBufferSizePublicKey,(int* pBufferSize, const IppsRSAPublicKeyState* pKey)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_GetBufferSizePublicKey( pBufferSize, pKey ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_GetBufferSizePublicKey( pBufferSize, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_GetBufferSizePublicKey( pBufferSize, pKey ); - } else + } 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 )) { - return h9_ippsRSA_GetBufferSizePublicKey( pBufferSize, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_GetBufferSizePublicKey( pBufferSize, pKey ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00294.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetPrivateKeyType1.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00294.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetPrivateKeyType1.c index 3ff7b963e..50dbf2de5 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00294.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetPrivateKeyType1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsRSA_GetPrivateKeyType1,(IppsBigNumState* pModulus, IppsBigNumState* pPrivateExp, const IppsRSAPrivateKeyState* pKey)) -IPPAPI(IppStatus, l9_ippsRSA_GetPrivateKeyType1,(IppsBigNumState* pModulus, IppsBigNumState* pPrivateExp, const IppsRSAPrivateKeyState* pKey)) IPPAPI(IppStatus, k1_ippsRSA_GetPrivateKeyType1,(IppsBigNumState* pModulus, IppsBigNumState* pPrivateExp, const IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_GetPrivateKeyType1,(IppsBigNumState* pModulus, IppsBigNumState* pPrivateExp, const IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, y8_ippsRSA_GetPrivateKeyType1,(IppsBigNumState* pModulus, IppsBigNumState* pPrivateExp, const IppsRSAPrivateKeyState* pKey)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_GetPrivateKeyType1( pModulus, pPrivateExp, pKey ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_GetPrivateKeyType1( pModulus, pPrivateExp, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_GetPrivateKeyType1( pModulus, pPrivateExp, pKey ); - } else + } 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 )) { - return h9_ippsRSA_GetPrivateKeyType1( pModulus, pPrivateExp, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_GetPrivateKeyType1( pModulus, pPrivateExp, pKey ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00298.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetPrivateKeyType2.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00298.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetPrivateKeyType2.c index 3d5f89a21..365ca362d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00298.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetPrivateKeyType2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsRSA_GetPrivateKeyType2,(IppsBigNumState* pFactorP, IppsBigNumState* pFactorQ, IppsBigNumState* pCrtExpP, IppsBigNumState* pCrtExpQ, IppsBigNumState* pInverseQ, const IppsRSAPrivateKeyState* pKey)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_GetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_GetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_GetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); - } else + } 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 )) { - return h9_ippsRSA_GetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_GetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00290.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetPublicKey.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00290.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetPublicKey.c index 0662188a9..2390fedf8 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00290.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetPublicKey.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsRSA_GetPublicKey,(IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, const IppsRSAPublicKeyState* pKey)) -IPPAPI(IppStatus, l9_ippsRSA_GetPublicKey,(IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, const IppsRSAPublicKeyState* pKey)) IPPAPI(IppStatus, k1_ippsRSA_GetPublicKey,(IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, const IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_GetPublicKey,(IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, const IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, y8_ippsRSA_GetPublicKey,(IppsBigNumState* pModulus, IppsBigNumState* pPublicExp, const IppsRSAPublicKeyState* pKey)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_GetPublicKey( pModulus, pPublicExp, pKey ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_GetPublicKey( pModulus, pPublicExp, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_GetPublicKey( pModulus, pPublicExp, pKey ); - } else + } 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 )) { - return h9_ippsRSA_GetPublicKey( pModulus, pPublicExp, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_GetPublicKey( pModulus, pPublicExp, pKey ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00291.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetSizePrivateKeyType1.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00291.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetSizePrivateKeyType1.c index 859d99d5e..f7ca0d1a8 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00291.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetSizePrivateKeyType1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) -IPPAPI(IppStatus, l9_ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) IPPAPI(IppStatus, k1_ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) +IPPAPI(IppStatus, l9_ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) +IPPAPI(IppStatus, y8_ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) -IPPFUN(IppStatus,sgx_disp_ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) +IPPFUN(IppStatus, sgx_disp_ippsRSA_GetSizePrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, int* pKeySize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_GetSizePrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKeySize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_GetSizePrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKeySize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_GetSizePrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKeySize ); - } else + } 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 )) { - return h9_ippsRSA_GetSizePrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKeySize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_GetSizePrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKeySize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00295.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetSizePrivateKeyType2.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00295.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetSizePrivateKeyType2.c index 569e852df..c62bfaf8b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00295.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetSizePrivateKeyType2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) -IPPAPI(IppStatus, l9_ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) IPPAPI(IppStatus, k1_ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) +IPPAPI(IppStatus, l9_ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) +IPPAPI(IppStatus, y8_ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) -IPPFUN(IppStatus,sgx_disp_ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) +IPPFUN(IppStatus, sgx_disp_ippsRSA_GetSizePrivateKeyType2,(int factorPbitSize, int factorQbitSize, int* pKeySize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_GetSizePrivateKeyType2( factorPbitSize, factorQbitSize, pKeySize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_GetSizePrivateKeyType2( factorPbitSize, factorQbitSize, pKeySize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_GetSizePrivateKeyType2( factorPbitSize, factorQbitSize, pKeySize ); - } else + } 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 )) { - return h9_ippsRSA_GetSizePrivateKeyType2( factorPbitSize, factorQbitSize, pKeySize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_GetSizePrivateKeyType2( factorPbitSize, factorQbitSize, pKeySize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00287.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetSizePublicKey.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00287.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetSizePublicKey.c index 13870c71d..8e9a8274f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00287.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_GetSizePublicKey.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) -IPPAPI(IppStatus, l9_ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) IPPAPI(IppStatus, k1_ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) +IPPAPI(IppStatus, l9_ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) +IPPAPI(IppStatus, y8_ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) -IPPFUN(IppStatus,sgx_disp_ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) +IPPFUN(IppStatus, sgx_disp_ippsRSA_GetSizePublicKey,(int rsaModulusBitSize, int pubicExpBitSize, int* pKeySize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_GetSizePublicKey( rsaModulusBitSize, pubicExpBitSize, pKeySize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_GetSizePublicKey( rsaModulusBitSize, pubicExpBitSize, pKeySize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_GetSizePublicKey( rsaModulusBitSize, pubicExpBitSize, pKeySize ); - } else + } 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 )) { - return h9_ippsRSA_GetSizePublicKey( rsaModulusBitSize, pubicExpBitSize, pKeySize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_GetSizePublicKey( rsaModulusBitSize, pubicExpBitSize, pKeySize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00292.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_InitPrivateKeyType1.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00292.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_InitPrivateKeyType1.c index 0cb3e600e..d3cc2fe08 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00292.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_InitPrivateKeyType1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsRSA_InitPrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, l9_ippsRSA_InitPrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, y8_ippsRSA_InitPrivateKeyType1,(int rsaModulusBitSize, int privateExpBitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_InitPrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKey, keyCtxSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_InitPrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKey, keyCtxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_InitPrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKey, keyCtxSize ); - } else + } 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 )) { - return h9_ippsRSA_InitPrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKey, keyCtxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_InitPrivateKeyType1( rsaModulusBitSize, privateExpBitSize, pKey, keyCtxSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00296.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_InitPrivateKeyType2.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00296.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_InitPrivateKeyType2.c index 465859a09..ed5ef6061 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00296.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_InitPrivateKeyType2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsRSA_InitPrivateKeyType2,(int factorPbitSize, int factorQbitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, l9_ippsRSA_InitPrivateKeyType2,(int factorPbitSize, int factorQbitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, y8_ippsRSA_InitPrivateKeyType2,(int factorPbitSize, int factorQbitSize, IppsRSAPrivateKeyState* pKey, int keyCtxSize)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_InitPrivateKeyType2( factorPbitSize, factorQbitSize, pKey, keyCtxSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_InitPrivateKeyType2( factorPbitSize, factorQbitSize, pKey, keyCtxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_InitPrivateKeyType2( factorPbitSize, factorQbitSize, pKey, keyCtxSize ); - } else + } 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 )) { - return h9_ippsRSA_InitPrivateKeyType2( factorPbitSize, factorQbitSize, pKey, keyCtxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_InitPrivateKeyType2( factorPbitSize, factorQbitSize, pKey, keyCtxSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00288.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_InitPublicKey.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00288.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_InitPublicKey.c index d8929fa9c..8d34cf1de 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00288.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_InitPublicKey.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsRSA_InitPublicKey,(int rsaModulusBitSize, int publicExpBitSize, IppsRSAPublicKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, l9_ippsRSA_InitPublicKey,(int rsaModulusBitSize, int publicExpBitSize, IppsRSAPublicKeyState* pKey, int keyCtxSize)) +IPPAPI(IppStatus, y8_ippsRSA_InitPublicKey,(int rsaModulusBitSize, int publicExpBitSize, IppsRSAPublicKeyState* pKey, int keyCtxSize)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_InitPublicKey( rsaModulusBitSize, publicExpBitSize, pKey, keyCtxSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_InitPublicKey( rsaModulusBitSize, publicExpBitSize, pKey, keyCtxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_InitPublicKey( rsaModulusBitSize, publicExpBitSize, pKey, keyCtxSize ); - } else + } 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 )) { - return h9_ippsRSA_InitPublicKey( rsaModulusBitSize, publicExpBitSize, pKey, keyCtxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_InitPublicKey( rsaModulusBitSize, publicExpBitSize, pKey, keyCtxSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00293.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_SetPrivateKeyType1.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00293.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_SetPrivateKeyType1.c index b1caf4b74..03f0f9803 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00293.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_SetPrivateKeyType1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsRSA_SetPrivateKeyType1,(const IppsBigNumState* pModulus, const IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_SetPrivateKeyType1,(const IppsBigNumState* pModulus, const IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pKey)) +IPPAPI(IppStatus, y8_ippsRSA_SetPrivateKeyType1,(const IppsBigNumState* pModulus, const IppsBigNumState* pPrivateExp, IppsRSAPrivateKeyState* pKey)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_SetPrivateKeyType1( pModulus, pPrivateExp, pKey ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_SetPrivateKeyType1( pModulus, pPrivateExp, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_SetPrivateKeyType1( pModulus, pPrivateExp, pKey ); - } else + } 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 )) { - return h9_ippsRSA_SetPrivateKeyType1( pModulus, pPrivateExp, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_SetPrivateKeyType1( pModulus, pPrivateExp, pKey ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00297.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_SetPrivateKeyType2.c similarity index 64% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00297.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_SetPrivateKeyType2.c index e837efcd2..09f19f411 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00297.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_SetPrivateKeyType2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_SetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_SetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_SetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); - } else + } 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 )) { - return h9_ippsRSA_SetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_SetPrivateKeyType2( pFactorP, pFactorQ, pCrtExpP, pCrtExpQ, pInverseQ, pKey ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00289.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_SetPublicKey.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00289.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_SetPublicKey.c index 64684aa63..5190b4c57 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00289.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_SetPublicKey.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsRSA_SetPublicKey,(const IppsBigNumState* pModulus, const IppsBigNumState* pPublicExp, IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, l9_ippsRSA_SetPublicKey,(const IppsBigNumState* pModulus, const IppsBigNumState* pPublicExp, IppsRSAPublicKeyState* pKey)) +IPPAPI(IppStatus, y8_ippsRSA_SetPublicKey,(const IppsBigNumState* pModulus, const IppsBigNumState* pPublicExp, IppsRSAPublicKeyState* pKey)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_SetPublicKey( pModulus, pPublicExp, pKey ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_SetPublicKey( pModulus, pPublicExp, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_SetPublicKey( pModulus, pPublicExp, pKey ); - } else + } 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 )) { - return h9_ippsRSA_SetPublicKey( pModulus, pPublicExp, pKey ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_SetPublicKey( pModulus, pPublicExp, pKey ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00304.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_ValidateKeys.c similarity index 62% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00304.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_ValidateKeys.c index fca61cf62..867ecec1e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00304.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRSA_ValidateKeys.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +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)) -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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRSA_ValidateKeys( pResult, pPublicKey, pPrivateKeyType2, pPrivateKeyType1, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRSA_ValidateKeys( pResult, pPublicKey, pPrivateKeyType2, pPrivateKeyType1, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRSA_ValidateKeys( pResult, pPublicKey, pPrivateKeyType2, pPrivateKeyType1, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); - } else + } 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 )) { - return h9_ippsRSA_ValidateKeys( pResult, pPublicKey, pPrivateKeyType2, pPrivateKeyType1, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRSA_ValidateKeys( pResult, pPublicKey, pPrivateKeyType2, pPrivateKeyType1, pScratchBuffer, nTrials, pPrimeGen, rndFunc, pRndParam ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00245.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRef_BN.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00245.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRef_BN.c index c1ca34670..a520daec2 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00245.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsRef_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsRef_BN,(IppsBigNumSGN* pSgn, int* bitSize, Ipp32u** const ppData, const IppsBigNumState* pBN)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsRef_BN( pSgn, bitSize, ppData, pBN ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsRef_BN( pSgn, bitSize, ppData, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsRef_BN( pSgn, bitSize, ppData, pBN ); - } else + } 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 )) { - return h9_ippsRef_BN( pSgn, bitSize, ppData, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsRef_BN( pSgn, bitSize, ppData, pBN ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00105.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Duplicate.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00105.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Duplicate.c index 159aac3ec..3d696695f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00105.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Duplicate.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA1Duplicate,(const IppsSHA1State* pSrcState, IppsSHA1State* pDstState)) -IPPAPI(IppStatus, l9_ippsSHA1Duplicate,(const IppsSHA1State* pSrcState, IppsSHA1State* pDstState)) IPPAPI(IppStatus, k1_ippsSHA1Duplicate,(const IppsSHA1State* pSrcState, IppsSHA1State* pDstState)) +IPPAPI(IppStatus, l9_ippsSHA1Duplicate,(const IppsSHA1State* pSrcState, IppsSHA1State* pDstState)) +IPPAPI(IppStatus, y8_ippsSHA1Duplicate,(const IppsSHA1State* pSrcState, IppsSHA1State* pDstState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA1Duplicate,(const IppsSHA1State* pSrcState, IppsSHA1State* pDstState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA1Duplicate,(const IppsSHA1State* pSrcState, IppsSHA1State* pDstState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA1Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA1Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA1Duplicate( pSrcState, pDstState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA1Duplicate,(const IppsSHA1State* pSrcState, IppsSHA1State* pDstState)) -IPPAPI(IppStatus, h9_ippsSHA1Duplicate,(const IppsSHA1State* pSrcState, IppsSHA1State* pDstState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA1Duplicate,(const IppsSHA1State* pSrcState, IppsSHA1State* pDstState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA1Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA1Duplicate( pSrcState, pDstState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00110.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Final.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00110.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Final.c index 81dafa132..92c5ec4b4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00110.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Final.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pState)) -IPPAPI(IppStatus, l9_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pState)) IPPAPI(IppStatus, k1_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pState)) +IPPAPI(IppStatus, l9_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pState)) +IPPAPI(IppStatus, y8_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA1Final( pMD, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA1Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA1Final( pMD, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pState)) -IPPAPI(IppStatus, h9_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA1Final,(Ipp8u* pMD, IppsSHA1State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA1Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA1Final( pMD, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00103.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1GetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00103.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1GetSize.c index 829b0eb1b..a623a5491 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00103.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1GetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA1GetSize,(int* pSize)) -IPPAPI(IppStatus, l9_ippsSHA1GetSize,(int* pSize)) IPPAPI(IppStatus, k1_ippsSHA1GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSHA1GetSize,(int* pSize)) +IPPAPI(IppStatus, y8_ippsSHA1GetSize,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsSHA1GetSize,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsSHA1GetSize,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA1GetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA1GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA1GetSize( pSize ); - } else + } 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 )) { - return h9_ippsSHA1GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA1GetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00109.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1GetTag.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00109.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1GetTag.c index f020bb75e..383f649aa 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00109.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1GetTag.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pState)) -IPPAPI(IppStatus, l9_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pState)) IPPAPI(IppStatus, k1_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pState)) +IPPAPI(IppStatus, l9_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pState)) +IPPAPI(IppStatus, y8_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA1GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA1GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA1GetTag( pTag, tagLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pState)) -IPPAPI(IppStatus, h9_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA1GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA1State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA1GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA1GetTag( pTag, tagLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00104.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Init.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00104.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Init.c index dd8732d7e..e94ed519d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00104.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Init.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA1Init,(IppsSHA1State* pState)) -IPPAPI(IppStatus, l9_ippsSHA1Init,(IppsSHA1State* pState)) IPPAPI(IppStatus, k1_ippsSHA1Init,(IppsSHA1State* pState)) +IPPAPI(IppStatus, l9_ippsSHA1Init,(IppsSHA1State* pState)) +IPPAPI(IppStatus, y8_ippsSHA1Init,(IppsSHA1State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA1Init,(IppsSHA1State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA1Init,(IppsSHA1State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA1Init( pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA1Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA1Init( pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA1Init,(IppsSHA1State* pState)) -IPPAPI(IppStatus, h9_ippsSHA1Init,(IppsSHA1State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA1Init,(IppsSHA1State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA1Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA1Init( pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00111.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1MessageDigest.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00111.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1MessageDigest.c index 5fb2bc34d..4a51a3873 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00111.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1MessageDigest.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA1MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPAPI(IppStatus, l9_ippsSHA1MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) IPPAPI(IppStatus, k1_ippsSHA1MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsSHA1MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, y8_ippsSHA1MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPFUN(IppStatus,sgx_disp_ippsSHA1MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPFUN(IppStatus, sgx_disp_ippsSHA1MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA1MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA1MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA1MessageDigest( pMsg, len, pMD ); - } else + } 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 )) { - return h9_ippsSHA1MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA1MessageDigest( pMsg, len, pMD ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00106.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Pack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00106.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Pack.c index ceb78974a..cb26b14f0 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00106.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Pack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA1Pack,(const IppsSHA1State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, l9_ippsSHA1Pack,(const IppsSHA1State* pState, Ipp8u* pBuffer)) IPPAPI(IppStatus, k1_ippsSHA1Pack,(const IppsSHA1State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsSHA1Pack,(const IppsSHA1State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, y8_ippsSHA1Pack,(const IppsSHA1State* pState, Ipp8u* pBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsSHA1Pack,(const IppsSHA1State* pState, Ipp8u* pBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsSHA1Pack,(const IppsSHA1State* pState, Ipp8u* pBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA1Pack( pState, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA1Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA1Pack( pState, pBuffer ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA1Pack,(const IppsSHA1State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, h9_ippsSHA1Pack,(const IppsSHA1State* pState, Ipp8u* pBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA1Pack,(const IppsSHA1State* pState, Ipp8u* pBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA1Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA1Pack( pState, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00107.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Unpack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00107.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Unpack.c index af9fb99d1..334c77d26 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00107.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Unpack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pState)) -IPPAPI(IppStatus, l9_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pState)) IPPAPI(IppStatus, k1_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pState)) +IPPAPI(IppStatus, l9_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pState)) +IPPAPI(IppStatus, y8_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA1Unpack( pBuffer, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA1Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA1Unpack( pBuffer, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pState)) -IPPAPI(IppStatus, h9_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA1Unpack,(const Ipp8u* pBuffer, IppsSHA1State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA1Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA1Unpack( pBuffer, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00108.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Update.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00108.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Update.c index 054495401..dee3a61e0 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00108.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA1Update.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pState)) -IPPAPI(IppStatus, l9_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pState)) IPPAPI(IppStatus, k1_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pState)) +IPPAPI(IppStatus, l9_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pState)) +IPPAPI(IppStatus, y8_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA1Update( pSrc, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA1Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA1Update( pSrc, len, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pState)) -IPPAPI(IppStatus, h9_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA1Update,(const Ipp8u* pSrc, int len, IppsSHA1State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA1Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA1Update( pSrc, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00114.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Duplicate.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00114.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Duplicate.c index e2455ea17..1d624c3f5 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00114.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Duplicate.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA224Duplicate,(const IppsSHA224State* pSrcState, IppsSHA224State* pDstState)) -IPPAPI(IppStatus, l9_ippsSHA224Duplicate,(const IppsSHA224State* pSrcState, IppsSHA224State* pDstState)) IPPAPI(IppStatus, k1_ippsSHA224Duplicate,(const IppsSHA224State* pSrcState, IppsSHA224State* pDstState)) +IPPAPI(IppStatus, l9_ippsSHA224Duplicate,(const IppsSHA224State* pSrcState, IppsSHA224State* pDstState)) +IPPAPI(IppStatus, y8_ippsSHA224Duplicate,(const IppsSHA224State* pSrcState, IppsSHA224State* pDstState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA224Duplicate,(const IppsSHA224State* pSrcState, IppsSHA224State* pDstState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA224Duplicate,(const IppsSHA224State* pSrcState, IppsSHA224State* pDstState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA224Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA224Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA224Duplicate( pSrcState, pDstState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA224Duplicate,(const IppsSHA224State* pSrcState, IppsSHA224State* pDstState)) -IPPAPI(IppStatus, h9_ippsSHA224Duplicate,(const IppsSHA224State* pSrcState, IppsSHA224State* pDstState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA224Duplicate,(const IppsSHA224State* pSrcState, IppsSHA224State* pDstState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA224Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA224Duplicate( pSrcState, pDstState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00119.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Final.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00119.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Final.c index 603652dda..ab7a5fda2 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00119.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Final.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pState)) -IPPAPI(IppStatus, l9_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pState)) IPPAPI(IppStatus, k1_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pState)) +IPPAPI(IppStatus, l9_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pState)) +IPPAPI(IppStatus, y8_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA224Final( pMD, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA224Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA224Final( pMD, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pState)) -IPPAPI(IppStatus, h9_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA224Final,(Ipp8u* pMD, IppsSHA224State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA224Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA224Final( pMD, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00112.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224GetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00112.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224GetSize.c index c73bc3782..e7f801086 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00112.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224GetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA224GetSize,(int* pSize)) -IPPAPI(IppStatus, l9_ippsSHA224GetSize,(int* pSize)) IPPAPI(IppStatus, k1_ippsSHA224GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSHA224GetSize,(int* pSize)) +IPPAPI(IppStatus, y8_ippsSHA224GetSize,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsSHA224GetSize,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsSHA224GetSize,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA224GetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA224GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA224GetSize( pSize ); - } else + } 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 )) { - return h9_ippsSHA224GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA224GetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00118.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224GetTag.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00118.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224GetTag.c index 3ba4e6cb9..50d1ca64f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00118.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224GetTag.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pState)) -IPPAPI(IppStatus, l9_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pState)) IPPAPI(IppStatus, k1_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pState)) +IPPAPI(IppStatus, l9_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pState)) +IPPAPI(IppStatus, y8_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA224GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA224GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA224GetTag( pTag, tagLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pState)) -IPPAPI(IppStatus, h9_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA224GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA224State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA224GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA224GetTag( pTag, tagLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00113.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Init.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00113.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Init.c index fb009cd6f..da1d4d7d2 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00113.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Init.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA224Init,(IppsSHA224State* pState)) -IPPAPI(IppStatus, l9_ippsSHA224Init,(IppsSHA224State* pState)) IPPAPI(IppStatus, k1_ippsSHA224Init,(IppsSHA224State* pState)) +IPPAPI(IppStatus, l9_ippsSHA224Init,(IppsSHA224State* pState)) +IPPAPI(IppStatus, y8_ippsSHA224Init,(IppsSHA224State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA224Init,(IppsSHA224State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA224Init,(IppsSHA224State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA224Init( pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA224Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA224Init( pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA224Init,(IppsSHA224State* pState)) -IPPAPI(IppStatus, h9_ippsSHA224Init,(IppsSHA224State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA224Init,(IppsSHA224State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA224Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA224Init( pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00120.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224MessageDigest.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00120.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224MessageDigest.c index d314029ff..cf78bd16f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00120.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224MessageDigest.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA224MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPAPI(IppStatus, l9_ippsSHA224MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) IPPAPI(IppStatus, k1_ippsSHA224MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsSHA224MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, y8_ippsSHA224MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPFUN(IppStatus,sgx_disp_ippsSHA224MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPFUN(IppStatus, sgx_disp_ippsSHA224MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA224MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA224MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA224MessageDigest( pMsg, len, pMD ); - } else + } 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 )) { - return h9_ippsSHA224MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA224MessageDigest( pMsg, len, pMD ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00115.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Pack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00115.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Pack.c index 49be24ae8..5364a9e66 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00115.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Pack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA224Pack,(const IppsSHA224State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, l9_ippsSHA224Pack,(const IppsSHA224State* pState, Ipp8u* pBuffer)) IPPAPI(IppStatus, k1_ippsSHA224Pack,(const IppsSHA224State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsSHA224Pack,(const IppsSHA224State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, y8_ippsSHA224Pack,(const IppsSHA224State* pState, Ipp8u* pBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsSHA224Pack,(const IppsSHA224State* pState, Ipp8u* pBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsSHA224Pack,(const IppsSHA224State* pState, Ipp8u* pBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA224Pack( pState, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA224Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA224Pack( pState, pBuffer ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA224Pack,(const IppsSHA224State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, h9_ippsSHA224Pack,(const IppsSHA224State* pState, Ipp8u* pBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA224Pack,(const IppsSHA224State* pState, Ipp8u* pBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA224Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA224Pack( pState, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00116.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Unpack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00116.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Unpack.c index 5dabc8a5b..f79d1c5b3 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00116.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Unpack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pState)) -IPPAPI(IppStatus, l9_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pState)) IPPAPI(IppStatus, k1_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pState)) +IPPAPI(IppStatus, l9_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pState)) +IPPAPI(IppStatus, y8_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA224Unpack( pBuffer, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA224Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA224Unpack( pBuffer, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pState)) -IPPAPI(IppStatus, h9_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA224Unpack,(const Ipp8u* pBuffer, IppsSHA224State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA224Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA224Unpack( pBuffer, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00117.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Update.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00117.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Update.c index 2adcf5842..f8afd7e75 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00117.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA224Update.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pState)) -IPPAPI(IppStatus, l9_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pState)) IPPAPI(IppStatus, k1_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pState)) +IPPAPI(IppStatus, l9_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pState)) +IPPAPI(IppStatus, y8_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA224Update( pSrc, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA224Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA224Update( pSrc, len, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pState)) -IPPAPI(IppStatus, h9_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA224Update,(const Ipp8u* pSrc, int len, IppsSHA224State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA224Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA224Update( pSrc, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00123.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Duplicate.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00123.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Duplicate.c index 52523fa3e..01df16096 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00123.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Duplicate.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA256Duplicate,(const IppsSHA256State* pSrcState, IppsSHA256State* pDstState)) -IPPAPI(IppStatus, l9_ippsSHA256Duplicate,(const IppsSHA256State* pSrcState, IppsSHA256State* pDstState)) IPPAPI(IppStatus, k1_ippsSHA256Duplicate,(const IppsSHA256State* pSrcState, IppsSHA256State* pDstState)) +IPPAPI(IppStatus, l9_ippsSHA256Duplicate,(const IppsSHA256State* pSrcState, IppsSHA256State* pDstState)) +IPPAPI(IppStatus, y8_ippsSHA256Duplicate,(const IppsSHA256State* pSrcState, IppsSHA256State* pDstState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA256Duplicate,(const IppsSHA256State* pSrcState, IppsSHA256State* pDstState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA256Duplicate,(const IppsSHA256State* pSrcState, IppsSHA256State* pDstState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA256Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA256Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA256Duplicate( pSrcState, pDstState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA256Duplicate,(const IppsSHA256State* pSrcState, IppsSHA256State* pDstState)) -IPPAPI(IppStatus, h9_ippsSHA256Duplicate,(const IppsSHA256State* pSrcState, IppsSHA256State* pDstState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA256Duplicate,(const IppsSHA256State* pSrcState, IppsSHA256State* pDstState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA256Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA256Duplicate( pSrcState, pDstState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00128.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Final.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00128.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Final.c index 0ab67c085..f8c43ef10 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00128.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Final.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pState)) -IPPAPI(IppStatus, l9_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pState)) IPPAPI(IppStatus, k1_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pState)) +IPPAPI(IppStatus, l9_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pState)) +IPPAPI(IppStatus, y8_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA256Final( pMD, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA256Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA256Final( pMD, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pState)) -IPPAPI(IppStatus, h9_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA256Final,(Ipp8u* pMD, IppsSHA256State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA256Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA256Final( pMD, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00121.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256GetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00121.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256GetSize.c index c0618bd94..765706204 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00121.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256GetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA256GetSize,(int* pSize)) -IPPAPI(IppStatus, l9_ippsSHA256GetSize,(int* pSize)) IPPAPI(IppStatus, k1_ippsSHA256GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSHA256GetSize,(int* pSize)) +IPPAPI(IppStatus, y8_ippsSHA256GetSize,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsSHA256GetSize,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsSHA256GetSize,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA256GetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA256GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA256GetSize( pSize ); - } else + } 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 )) { - return h9_ippsSHA256GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA256GetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00127.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256GetTag.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00127.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256GetTag.c index 93038d447..01a560880 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00127.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256GetTag.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pState)) -IPPAPI(IppStatus, l9_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pState)) IPPAPI(IppStatus, k1_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pState)) +IPPAPI(IppStatus, l9_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pState)) +IPPAPI(IppStatus, y8_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA256GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA256GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA256GetTag( pTag, tagLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pState)) -IPPAPI(IppStatus, h9_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA256GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA256State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA256GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA256GetTag( pTag, tagLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00122.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Init.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00122.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Init.c index 262f4368e..f781e0e83 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00122.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Init.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA256Init,(IppsSHA256State* pState)) -IPPAPI(IppStatus, l9_ippsSHA256Init,(IppsSHA256State* pState)) IPPAPI(IppStatus, k1_ippsSHA256Init,(IppsSHA256State* pState)) +IPPAPI(IppStatus, l9_ippsSHA256Init,(IppsSHA256State* pState)) +IPPAPI(IppStatus, y8_ippsSHA256Init,(IppsSHA256State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA256Init,(IppsSHA256State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA256Init,(IppsSHA256State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA256Init( pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA256Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA256Init( pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA256Init,(IppsSHA256State* pState)) -IPPAPI(IppStatus, h9_ippsSHA256Init,(IppsSHA256State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA256Init,(IppsSHA256State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA256Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA256Init( pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00129.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256MessageDigest.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00129.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256MessageDigest.c index 0659945f2..0f0f374ed 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00129.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256MessageDigest.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA256MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPAPI(IppStatus, l9_ippsSHA256MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) IPPAPI(IppStatus, k1_ippsSHA256MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsSHA256MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, y8_ippsSHA256MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPFUN(IppStatus,sgx_disp_ippsSHA256MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPFUN(IppStatus, sgx_disp_ippsSHA256MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA256MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA256MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA256MessageDigest( pMsg, len, pMD ); - } else + } 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 )) { - return h9_ippsSHA256MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA256MessageDigest( pMsg, len, pMD ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00124.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Pack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00124.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Pack.c index 05dc26c3a..65ecbb330 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00124.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Pack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA256Pack,(const IppsSHA256State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, l9_ippsSHA256Pack,(const IppsSHA256State* pState, Ipp8u* pBuffer)) IPPAPI(IppStatus, k1_ippsSHA256Pack,(const IppsSHA256State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsSHA256Pack,(const IppsSHA256State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, y8_ippsSHA256Pack,(const IppsSHA256State* pState, Ipp8u* pBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsSHA256Pack,(const IppsSHA256State* pState, Ipp8u* pBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsSHA256Pack,(const IppsSHA256State* pState, Ipp8u* pBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA256Pack( pState, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA256Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA256Pack( pState, pBuffer ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA256Pack,(const IppsSHA256State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, h9_ippsSHA256Pack,(const IppsSHA256State* pState, Ipp8u* pBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA256Pack,(const IppsSHA256State* pState, Ipp8u* pBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA256Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA256Pack( pState, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00125.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Unpack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00125.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Unpack.c index 62a67ca90..bfe9d6c10 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00125.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Unpack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pState)) -IPPAPI(IppStatus, l9_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pState)) IPPAPI(IppStatus, k1_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pState)) +IPPAPI(IppStatus, l9_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pState)) +IPPAPI(IppStatus, y8_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA256Unpack( pBuffer, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA256Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA256Unpack( pBuffer, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pState)) -IPPAPI(IppStatus, h9_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA256Unpack,(const Ipp8u* pBuffer, IppsSHA256State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA256Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA256Unpack( pBuffer, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00126.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Update.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00126.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Update.c index 9f6758696..6e560afc1 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00126.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA256Update.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pState)) -IPPAPI(IppStatus, l9_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pState)) IPPAPI(IppStatus, k1_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pState)) +IPPAPI(IppStatus, l9_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pState)) +IPPAPI(IppStatus, y8_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA256Update( pSrc, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA256Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA256Update( pSrc, len, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pState)) -IPPAPI(IppStatus, h9_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA256Update,(const Ipp8u* pSrc, int len, IppsSHA256State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA256Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA256Update( pSrc, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00132.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Duplicate.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00132.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Duplicate.c index 27c97a5e6..e708bcecf 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00132.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Duplicate.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA384Duplicate,(const IppsSHA384State* pSrcState, IppsSHA384State* pDstState)) -IPPAPI(IppStatus, l9_ippsSHA384Duplicate,(const IppsSHA384State* pSrcState, IppsSHA384State* pDstState)) IPPAPI(IppStatus, k1_ippsSHA384Duplicate,(const IppsSHA384State* pSrcState, IppsSHA384State* pDstState)) +IPPAPI(IppStatus, l9_ippsSHA384Duplicate,(const IppsSHA384State* pSrcState, IppsSHA384State* pDstState)) +IPPAPI(IppStatus, y8_ippsSHA384Duplicate,(const IppsSHA384State* pSrcState, IppsSHA384State* pDstState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA384Duplicate,(const IppsSHA384State* pSrcState, IppsSHA384State* pDstState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA384Duplicate,(const IppsSHA384State* pSrcState, IppsSHA384State* pDstState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA384Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA384Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA384Duplicate( pSrcState, pDstState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA384Duplicate,(const IppsSHA384State* pSrcState, IppsSHA384State* pDstState)) -IPPAPI(IppStatus, h9_ippsSHA384Duplicate,(const IppsSHA384State* pSrcState, IppsSHA384State* pDstState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA384Duplicate,(const IppsSHA384State* pSrcState, IppsSHA384State* pDstState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA384Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA384Duplicate( pSrcState, pDstState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00137.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Final.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00137.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Final.c index ca6616e3c..d5d3f79e5 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00137.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Final.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pState)) -IPPAPI(IppStatus, l9_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pState)) IPPAPI(IppStatus, k1_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pState)) +IPPAPI(IppStatus, l9_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pState)) +IPPAPI(IppStatus, y8_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA384Final( pMD, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA384Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA384Final( pMD, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pState)) -IPPAPI(IppStatus, h9_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA384Final,(Ipp8u* pMD, IppsSHA384State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA384Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA384Final( pMD, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00130.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384GetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00130.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384GetSize.c index af84e0ef7..d7ddc38e1 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00130.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384GetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA384GetSize,(int* pSize)) -IPPAPI(IppStatus, l9_ippsSHA384GetSize,(int* pSize)) IPPAPI(IppStatus, k1_ippsSHA384GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSHA384GetSize,(int* pSize)) +IPPAPI(IppStatus, y8_ippsSHA384GetSize,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsSHA384GetSize,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsSHA384GetSize,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA384GetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA384GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA384GetSize( pSize ); - } else + } 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 )) { - return h9_ippsSHA384GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA384GetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00136.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384GetTag.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00136.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384GetTag.c index bd3d1321e..0db3c1d7a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00136.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384GetTag.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pState)) -IPPAPI(IppStatus, l9_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pState)) IPPAPI(IppStatus, k1_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pState)) +IPPAPI(IppStatus, l9_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pState)) +IPPAPI(IppStatus, y8_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA384GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA384GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA384GetTag( pTag, tagLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pState)) -IPPAPI(IppStatus, h9_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA384GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA384State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA384GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA384GetTag( pTag, tagLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00131.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Init.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00131.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Init.c index c0f28db48..0d078f18a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00131.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Init.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA384Init,(IppsSHA384State* pState)) -IPPAPI(IppStatus, l9_ippsSHA384Init,(IppsSHA384State* pState)) IPPAPI(IppStatus, k1_ippsSHA384Init,(IppsSHA384State* pState)) +IPPAPI(IppStatus, l9_ippsSHA384Init,(IppsSHA384State* pState)) +IPPAPI(IppStatus, y8_ippsSHA384Init,(IppsSHA384State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA384Init,(IppsSHA384State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA384Init,(IppsSHA384State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA384Init( pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA384Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA384Init( pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA384Init,(IppsSHA384State* pState)) -IPPAPI(IppStatus, h9_ippsSHA384Init,(IppsSHA384State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA384Init,(IppsSHA384State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA384Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA384Init( pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00138.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384MessageDigest.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00138.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384MessageDigest.c index be9f63230..95b3f7842 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00138.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384MessageDigest.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA384MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPAPI(IppStatus, l9_ippsSHA384MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) IPPAPI(IppStatus, k1_ippsSHA384MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsSHA384MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, y8_ippsSHA384MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPFUN(IppStatus,sgx_disp_ippsSHA384MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPFUN(IppStatus, sgx_disp_ippsSHA384MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA384MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA384MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA384MessageDigest( pMsg, len, pMD ); - } else + } 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 )) { - return h9_ippsSHA384MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA384MessageDigest( pMsg, len, pMD ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00133.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Pack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00133.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Pack.c index 6c7aa366d..1f319b871 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00133.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Pack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA384Pack,(const IppsSHA384State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, l9_ippsSHA384Pack,(const IppsSHA384State* pState, Ipp8u* pBuffer)) IPPAPI(IppStatus, k1_ippsSHA384Pack,(const IppsSHA384State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsSHA384Pack,(const IppsSHA384State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, y8_ippsSHA384Pack,(const IppsSHA384State* pState, Ipp8u* pBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsSHA384Pack,(const IppsSHA384State* pState, Ipp8u* pBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsSHA384Pack,(const IppsSHA384State* pState, Ipp8u* pBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA384Pack( pState, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA384Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA384Pack( pState, pBuffer ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA384Pack,(const IppsSHA384State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, h9_ippsSHA384Pack,(const IppsSHA384State* pState, Ipp8u* pBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA384Pack,(const IppsSHA384State* pState, Ipp8u* pBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA384Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA384Pack( pState, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00134.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Unpack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00134.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Unpack.c index 829c4b8f1..d6a90536b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00134.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Unpack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pState)) -IPPAPI(IppStatus, l9_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pState)) IPPAPI(IppStatus, k1_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pState)) +IPPAPI(IppStatus, l9_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pState)) +IPPAPI(IppStatus, y8_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA384Unpack( pBuffer, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA384Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA384Unpack( pBuffer, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pState)) -IPPAPI(IppStatus, h9_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA384Unpack,(const Ipp8u* pBuffer, IppsSHA384State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA384Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA384Unpack( pBuffer, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00135.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Update.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00135.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Update.c index 894388b11..d7e21c9f7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00135.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA384Update.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pState)) -IPPAPI(IppStatus, l9_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pState)) IPPAPI(IppStatus, k1_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pState)) +IPPAPI(IppStatus, l9_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pState)) +IPPAPI(IppStatus, y8_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA384Update( pSrc, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA384Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA384Update( pSrc, len, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pState)) -IPPAPI(IppStatus, h9_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA384Update,(const Ipp8u* pSrc, int len, IppsSHA384State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA384Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA384Update( pSrc, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00141.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Duplicate.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00141.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Duplicate.c index 78494d127..82082ffd5 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00141.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Duplicate.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA512Duplicate,(const IppsSHA512State* pSrcState, IppsSHA512State* pDstState)) -IPPAPI(IppStatus, l9_ippsSHA512Duplicate,(const IppsSHA512State* pSrcState, IppsSHA512State* pDstState)) IPPAPI(IppStatus, k1_ippsSHA512Duplicate,(const IppsSHA512State* pSrcState, IppsSHA512State* pDstState)) +IPPAPI(IppStatus, l9_ippsSHA512Duplicate,(const IppsSHA512State* pSrcState, IppsSHA512State* pDstState)) +IPPAPI(IppStatus, y8_ippsSHA512Duplicate,(const IppsSHA512State* pSrcState, IppsSHA512State* pDstState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA512Duplicate,(const IppsSHA512State* pSrcState, IppsSHA512State* pDstState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA512Duplicate,(const IppsSHA512State* pSrcState, IppsSHA512State* pDstState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA512Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA512Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA512Duplicate( pSrcState, pDstState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA512Duplicate,(const IppsSHA512State* pSrcState, IppsSHA512State* pDstState)) -IPPAPI(IppStatus, h9_ippsSHA512Duplicate,(const IppsSHA512State* pSrcState, IppsSHA512State* pDstState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA512Duplicate,(const IppsSHA512State* pSrcState, IppsSHA512State* pDstState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA512Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA512Duplicate( pSrcState, pDstState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00146.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Final.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00146.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Final.c index aa535c052..826d6e7f8 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00146.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Final.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pState)) -IPPAPI(IppStatus, l9_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pState)) IPPAPI(IppStatus, k1_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pState)) +IPPAPI(IppStatus, l9_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pState)) +IPPAPI(IppStatus, y8_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA512Final( pMD, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA512Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA512Final( pMD, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pState)) -IPPAPI(IppStatus, h9_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA512Final,(Ipp8u* pMD, IppsSHA512State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA512Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA512Final( pMD, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00139.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512GetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00139.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512GetSize.c index a85a2c055..312d8ae7c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00139.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512GetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA512GetSize,(int* pSize)) -IPPAPI(IppStatus, l9_ippsSHA512GetSize,(int* pSize)) IPPAPI(IppStatus, k1_ippsSHA512GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSHA512GetSize,(int* pSize)) +IPPAPI(IppStatus, y8_ippsSHA512GetSize,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsSHA512GetSize,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsSHA512GetSize,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA512GetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA512GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA512GetSize( pSize ); - } else + } 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 )) { - return h9_ippsSHA512GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA512GetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00145.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512GetTag.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00145.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512GetTag.c index b874c8e95..00404c522 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00145.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512GetTag.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pState)) -IPPAPI(IppStatus, l9_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pState)) IPPAPI(IppStatus, k1_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pState)) +IPPAPI(IppStatus, l9_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pState)) +IPPAPI(IppStatus, y8_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA512GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA512GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA512GetTag( pTag, tagLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pState)) -IPPAPI(IppStatus, h9_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA512GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSHA512State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA512GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA512GetTag( pTag, tagLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00140.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Init.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00140.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Init.c index e0034133d..bd98c260e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00140.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Init.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA512Init,(IppsSHA512State* pState)) -IPPAPI(IppStatus, l9_ippsSHA512Init,(IppsSHA512State* pState)) IPPAPI(IppStatus, k1_ippsSHA512Init,(IppsSHA512State* pState)) +IPPAPI(IppStatus, l9_ippsSHA512Init,(IppsSHA512State* pState)) +IPPAPI(IppStatus, y8_ippsSHA512Init,(IppsSHA512State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA512Init,(IppsSHA512State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA512Init,(IppsSHA512State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA512Init( pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA512Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA512Init( pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA512Init,(IppsSHA512State* pState)) -IPPAPI(IppStatus, h9_ippsSHA512Init,(IppsSHA512State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA512Init,(IppsSHA512State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA512Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA512Init( pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00147.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512MessageDigest.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00147.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512MessageDigest.c index 9002052f7..70d0ec4e4 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00147.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512MessageDigest.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA512MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPAPI(IppStatus, l9_ippsSHA512MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) IPPAPI(IppStatus, k1_ippsSHA512MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsSHA512MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, y8_ippsSHA512MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPFUN(IppStatus,sgx_disp_ippsSHA512MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPFUN(IppStatus, sgx_disp_ippsSHA512MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA512MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA512MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA512MessageDigest( pMsg, len, pMD ); - } else + } 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 )) { - return h9_ippsSHA512MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA512MessageDigest( pMsg, len, pMD ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00142.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Pack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00142.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Pack.c index 7d5b8cbb8..9316ca3af 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00142.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Pack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA512Pack,(const IppsSHA512State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, l9_ippsSHA512Pack,(const IppsSHA512State* pState, Ipp8u* pBuffer)) IPPAPI(IppStatus, k1_ippsSHA512Pack,(const IppsSHA512State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsSHA512Pack,(const IppsSHA512State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, y8_ippsSHA512Pack,(const IppsSHA512State* pState, Ipp8u* pBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsSHA512Pack,(const IppsSHA512State* pState, Ipp8u* pBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsSHA512Pack,(const IppsSHA512State* pState, Ipp8u* pBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA512Pack( pState, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA512Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA512Pack( pState, pBuffer ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA512Pack,(const IppsSHA512State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, h9_ippsSHA512Pack,(const IppsSHA512State* pState, Ipp8u* pBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA512Pack,(const IppsSHA512State* pState, Ipp8u* pBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA512Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA512Pack( pState, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00143.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Unpack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00143.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Unpack.c index 079d0831c..b5a78915e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00143.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Unpack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pState)) -IPPAPI(IppStatus, l9_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pState)) IPPAPI(IppStatus, k1_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pState)) +IPPAPI(IppStatus, l9_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pState)) +IPPAPI(IppStatus, y8_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA512Unpack( pBuffer, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA512Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA512Unpack( pBuffer, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pState)) -IPPAPI(IppStatus, h9_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA512Unpack,(const Ipp8u* pBuffer, IppsSHA512State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA512Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA512Unpack( pBuffer, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00144.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Update.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00144.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Update.c index 02b7480fb..b59451b14 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00144.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSHA512Update.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pState)) -IPPAPI(IppStatus, l9_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pState)) IPPAPI(IppStatus, k1_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pState)) +IPPAPI(IppStatus, l9_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pState)) +IPPAPI(IppStatus, y8_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSHA512Update( pSrc, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSHA512Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSHA512Update( pSrc, len, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pState)) -IPPAPI(IppStatus, h9_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSHA512Update,(const Ipp8u* pSrc, int len, IppsSHA512State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSHA512Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSHA512Update( pSrc, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00159.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Duplicate.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00159.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Duplicate.c index c86eab3cf..ae0d2cf35 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00159.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Duplicate.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSM3Duplicate,(const IppsSM3State* pSrcState, IppsSM3State* pDstState)) -IPPAPI(IppStatus, l9_ippsSM3Duplicate,(const IppsSM3State* pSrcState, IppsSM3State* pDstState)) IPPAPI(IppStatus, k1_ippsSM3Duplicate,(const IppsSM3State* pSrcState, IppsSM3State* pDstState)) +IPPAPI(IppStatus, l9_ippsSM3Duplicate,(const IppsSM3State* pSrcState, IppsSM3State* pDstState)) +IPPAPI(IppStatus, y8_ippsSM3Duplicate,(const IppsSM3State* pSrcState, IppsSM3State* pDstState)) -IPPFUN(IppStatus,sgx_disp_ippsSM3Duplicate,(const IppsSM3State* pSrcState, IppsSM3State* pDstState)) +IPPFUN(IppStatus, sgx_disp_ippsSM3Duplicate,(const IppsSM3State* pSrcState, IppsSM3State* pDstState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSM3Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSM3Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSM3Duplicate( pSrcState, pDstState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSM3Duplicate,(const IppsSM3State* pSrcState, IppsSM3State* pDstState)) -IPPAPI(IppStatus, h9_ippsSM3Duplicate,(const IppsSM3State* pSrcState, IppsSM3State* pDstState)) - -IPPFUN(IppStatus,sgx_disp_ippsSM3Duplicate,(const IppsSM3State* pSrcState, IppsSM3State* pDstState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSM3Duplicate( pSrcState, pDstState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSM3Duplicate( pSrcState, pDstState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00164.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Final.c similarity index 72% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00164.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Final.c index e41749d6d..3e093c57e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00164.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Final.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pState)) -IPPAPI(IppStatus, l9_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pState)) IPPAPI(IppStatus, k1_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pState)) +IPPAPI(IppStatus, l9_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pState)) +IPPAPI(IppStatus, y8_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSM3Final( pMD, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSM3Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSM3Final( pMD, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pState)) -IPPAPI(IppStatus, h9_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSM3Final,(Ipp8u* pMD, IppsSM3State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSM3Final( pMD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSM3Final( pMD, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00157.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3GetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00157.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3GetSize.c index 7c2f64714..46b3d619c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00157.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3GetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSM3GetSize,(int* pSize)) -IPPAPI(IppStatus, l9_ippsSM3GetSize,(int* pSize)) IPPAPI(IppStatus, k1_ippsSM3GetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSM3GetSize,(int* pSize)) +IPPAPI(IppStatus, y8_ippsSM3GetSize,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsSM3GetSize,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsSM3GetSize,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSM3GetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSM3GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSM3GetSize( pSize ); - } else + } 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 )) { - return h9_ippsSM3GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSM3GetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00163.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3GetTag.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00163.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3GetTag.c index d437359b4..d6691ad2d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00163.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3GetTag.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pState)) -IPPAPI(IppStatus, l9_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pState)) IPPAPI(IppStatus, k1_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pState)) +IPPAPI(IppStatus, l9_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pState)) +IPPAPI(IppStatus, y8_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSM3GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSM3GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSM3GetTag( pTag, tagLen, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pState)) -IPPAPI(IppStatus, h9_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSM3GetTag,(Ipp8u* pTag, Ipp32u tagLen, const IppsSM3State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSM3GetTag( pTag, tagLen, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSM3GetTag( pTag, tagLen, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00158.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Init.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00158.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Init.c index af5180247..c740148ed 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00158.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Init.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSM3Init,(IppsSM3State* pState)) -IPPAPI(IppStatus, l9_ippsSM3Init,(IppsSM3State* pState)) IPPAPI(IppStatus, k1_ippsSM3Init,(IppsSM3State* pState)) +IPPAPI(IppStatus, l9_ippsSM3Init,(IppsSM3State* pState)) +IPPAPI(IppStatus, y8_ippsSM3Init,(IppsSM3State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSM3Init,(IppsSM3State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSM3Init,(IppsSM3State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSM3Init( pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSM3Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSM3Init( pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSM3Init,(IppsSM3State* pState)) -IPPAPI(IppStatus, h9_ippsSM3Init,(IppsSM3State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSM3Init,(IppsSM3State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSM3Init( pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSM3Init( pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00165.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3MessageDigest.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00165.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3MessageDigest.c index 4eba930f1..ef6d4a05f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00165.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3MessageDigest.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSM3MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPAPI(IppStatus, l9_ippsSM3MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) IPPAPI(IppStatus, k1_ippsSM3MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, l9_ippsSM3MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPAPI(IppStatus, y8_ippsSM3MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) -IPPFUN(IppStatus,sgx_disp_ippsSM3MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) +IPPFUN(IppStatus, sgx_disp_ippsSM3MessageDigest,(const Ipp8u* pMsg, int len, Ipp8u* pMD)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSM3MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSM3MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSM3MessageDigest( pMsg, len, pMD ); - } else + } 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 )) { - return h9_ippsSM3MessageDigest( pMsg, len, pMD ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSM3MessageDigest( pMsg, len, pMD ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00160.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Pack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00160.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Pack.c index 37ce9b17d..2a90376d3 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00160.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Pack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSM3Pack,(const IppsSM3State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, l9_ippsSM3Pack,(const IppsSM3State* pState, Ipp8u* pBuffer)) IPPAPI(IppStatus, k1_ippsSM3Pack,(const IppsSM3State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, l9_ippsSM3Pack,(const IppsSM3State* pState, Ipp8u* pBuffer)) +IPPAPI(IppStatus, y8_ippsSM3Pack,(const IppsSM3State* pState, Ipp8u* pBuffer)) -IPPFUN(IppStatus,sgx_disp_ippsSM3Pack,(const IppsSM3State* pState, Ipp8u* pBuffer)) +IPPFUN(IppStatus, sgx_disp_ippsSM3Pack,(const IppsSM3State* pState, Ipp8u* pBuffer)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSM3Pack( pState, pBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSM3Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSM3Pack( pState, pBuffer ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSM3Pack,(const IppsSM3State* pState, Ipp8u* pBuffer)) -IPPAPI(IppStatus, h9_ippsSM3Pack,(const IppsSM3State* pState, Ipp8u* pBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsSM3Pack,(const IppsSM3State* pState, Ipp8u* pBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSM3Pack( pState, pBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSM3Pack( pState, pBuffer ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00161.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Unpack.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00161.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Unpack.c index 9f697070b..690714e09 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00161.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Unpack.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pState)) -IPPAPI(IppStatus, l9_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pState)) IPPAPI(IppStatus, k1_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pState)) +IPPAPI(IppStatus, l9_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pState)) +IPPAPI(IppStatus, y8_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSM3Unpack( pBuffer, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSM3Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSM3Unpack( pBuffer, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pState)) -IPPAPI(IppStatus, h9_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSM3Unpack,(const Ipp8u* pBuffer, IppsSM3State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSM3Unpack( pBuffer, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSM3Unpack( pBuffer, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00162.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Update.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00162.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Update.c index 9eb60b711..39bcad78a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00162.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSM3Update.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pState)) -IPPAPI(IppStatus, l9_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pState)) IPPAPI(IppStatus, k1_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pState)) +IPPAPI(IppStatus, l9_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pState)) +IPPAPI(IppStatus, y8_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pState)) -IPPFUN(IppStatus,sgx_disp_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pState)) +IPPFUN(IppStatus, sgx_disp_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pState)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSM3Update( pSrc, len, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSM3Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSM3Update( pSrc, len, pState ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pState)) -IPPAPI(IppStatus, h9_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pState)) - -IPPFUN(IppStatus,sgx_disp_ippsSM3Update,(const Ipp8u* pSrc, int len, IppsSM3State* pState)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsSM3Update( pSrc, len, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSM3Update( pSrc, len, pState ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00048.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCBC.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00048.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCBC.c index 83ebdc0ce..aff7791cc 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00048.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCBC.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4DecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4DecryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4DecryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4DecryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsSMS4DecryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4DecryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00049.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCBC_CS1.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00049.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCBC_CS1.c index d26d3b449..2b7e8e44f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00049.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCBC_CS1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4DecryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4DecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4DecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4DecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsSMS4DecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4DecryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00050.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCBC_CS2.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00050.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCBC_CS2.c index ec5a4625a..a39d7e195 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00050.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCBC_CS2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4DecryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4DecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4DecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4DecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsSMS4DecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4DecryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00051.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCBC_CS3.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00051.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCBC_CS3.c index 5e08c0520..aa6301513 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00051.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCBC_CS3.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4DecryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4DecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4DecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4DecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsSMS4DecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4DecryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00053.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCFB.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00053.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCFB.c index 6ba30b449..b4d1a6c18 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00053.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCFB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4DecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4DecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4DecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4DecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsSMS4DecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4DecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00057.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCTR.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00057.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCTR.c index 9b494adc9..fd8e6ee2b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00057.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptCTR.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4DecryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4DecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4DecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4DecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else + } 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 )) { - return h9_ippsSMS4DecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4DecryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00043.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptECB.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00043.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptECB.c index af5801a33..1a9b4f26f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00043.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptECB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4DecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4DecryptECB( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4DecryptECB( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4DecryptECB( pSrc, pDst, len, pCtx ); - } else + } 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 )) { - return h9_ippsSMS4DecryptECB( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4DecryptECB( pSrc, pDst, len, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00055.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptOFB.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00055.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptOFB.c index abda7e7dc..24a5aceec 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00055.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4DecryptOFB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4DecryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4DecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4DecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4DecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsSMS4DecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4DecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00044.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCBC.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00044.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCBC.c index b62788b4a..8412bb6a7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00044.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCBC.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4EncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4EncryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4EncryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4EncryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsSMS4EncryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4EncryptCBC( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00045.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCBC_CS1.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00045.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCBC_CS1.c index aee63ea2e..ebfdd92b7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00045.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCBC_CS1.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4EncryptCBC_CS1,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4EncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4EncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4EncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsSMS4EncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4EncryptCBC_CS1( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00046.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCBC_CS2.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00046.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCBC_CS2.c index 11aaf656e..0f1c9ebf7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00046.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCBC_CS2.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4EncryptCBC_CS2,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4EncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4EncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4EncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsSMS4EncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4EncryptCBC_CS2( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00047.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCBC_CS3.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00047.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCBC_CS3.c index 3533a72aa..7c41090f3 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00047.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCBC_CS3.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4EncryptCBC_CS3,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4EncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4EncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4EncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsSMS4EncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4EncryptCBC_CS3( pSrc, pDst, len, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00052.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCFB.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00052.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCFB.c index 1c6a1bf84..64eeced64 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00052.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCFB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4EncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int cfbBlkSize, const IppsSMS4Spec* pCtx, const Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4EncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4EncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4EncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsSMS4EncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4EncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00056.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCTR.c similarity index 67% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00056.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCTR.c index dcf4f4d03..4154f615b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00056.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptCTR.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4EncryptCTR,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx, Ipp8u* pCtrValue, int ctrNumBitSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4EncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4EncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4EncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else + } 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 )) { - return h9_ippsSMS4EncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4EncryptCTR( pSrc, pDst, len, pCtx, pCtrValue, ctrNumBitSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00042.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptECB.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00042.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptECB.c index 42f47c726..b7cd73259 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00042.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptECB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4EncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsSMS4Spec* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4EncryptECB( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4EncryptECB( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4EncryptECB( pSrc, pDst, len, pCtx ); - } else + } 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 )) { - return h9_ippsSMS4EncryptECB( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4EncryptECB( pSrc, pDst, len, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00054.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptOFB.c similarity index 68% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00054.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptOFB.c index 934d27488..0eb3b7bd7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00054.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4EncryptOFB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4EncryptOFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, int ofbBlkSize, const IppsSMS4Spec* pCtx, Ipp8u* pIV)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4EncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4EncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4EncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else + } 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 )) { - return h9_ippsSMS4EncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4EncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00039.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4GetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00039.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4GetSize.c index 69c4f843d..80dbc8c3d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00039.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4GetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSMS4GetSize,(int *pSize)) -IPPAPI(IppStatus, l9_ippsSMS4GetSize,(int *pSize)) IPPAPI(IppStatus, k1_ippsSMS4GetSize,(int *pSize)) +IPPAPI(IppStatus, l9_ippsSMS4GetSize,(int *pSize)) +IPPAPI(IppStatus, y8_ippsSMS4GetSize,(int *pSize)) -IPPFUN(IppStatus,sgx_disp_ippsSMS4GetSize,(int *pSize)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4GetSize,(int *pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4GetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4GetSize( pSize ); - } else + } 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 )) { - return h9_ippsSMS4GetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4GetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00040.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4Init.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00040.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4Init.c index bfe0e1cc5..b1845c755 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00040.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4Init.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsSMS4Init,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx, int ctxSize)) +IPPAPI(IppStatus, l9_ippsSMS4Init,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx, int ctxSize)) +IPPAPI(IppStatus, y8_ippsSMS4Init,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx, int ctxSize)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4Init( pKey, keyLen, pCtx, ctxSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4Init( pKey, keyLen, pCtx, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4Init( pKey, keyLen, pCtx, ctxSize ); - } else + } 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 )) { - return h9_ippsSMS4Init( pKey, keyLen, pCtx, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4Init( pKey, keyLen, pCtx, ctxSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00041.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4SetKey.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00041.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4SetKey.c index 5456dbd76..09172933c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00041.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4SetKey.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSMS4SetKey,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx)) -IPPAPI(IppStatus, l9_ippsSMS4SetKey,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx)) IPPAPI(IppStatus, k1_ippsSMS4SetKey,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx)) +IPPAPI(IppStatus, l9_ippsSMS4SetKey,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx)) +IPPAPI(IppStatus, y8_ippsSMS4SetKey,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsSMS4SetKey,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4SetKey,(const Ipp8u* pKey, int keyLen, IppsSMS4Spec* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4SetKey( pKey, keyLen, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4SetKey( pKey, keyLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4SetKey( pKey, keyLen, pCtx ); - } else + } 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 )) { - return h9_ippsSMS4SetKey( pKey, keyLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4SetKey( pKey, keyLen, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00064.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMDecrypt.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00064.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMDecrypt.c index 440e2a48b..03306391c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00064.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMDecrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4_CCMDecrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4_CCMDecrypt( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4_CCMDecrypt( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4_CCMDecrypt( pSrc, pDst, len, pCtx ); - } else + } 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 )) { - return h9_ippsSMS4_CCMDecrypt( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4_CCMDecrypt( pSrc, pDst, len, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00063.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMEncrypt.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00063.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMEncrypt.c index 8a1575563..22817efbb 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00063.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMEncrypt.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4_CCMEncrypt,(const Ipp8u* pSrc, Ipp8u* pDst, int len, IppsSMS4_CCMState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4_CCMEncrypt( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4_CCMEncrypt( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4_CCMEncrypt( pSrc, pDst, len, pCtx ); - } else + } 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 )) { - return h9_ippsSMS4_CCMEncrypt( pSrc, pDst, len, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4_CCMEncrypt( pSrc, pDst, len, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00058.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMGetSize.c similarity index 73% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00058.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMGetSize.c index ea268852b..f118c802e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00058.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMGetSize.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSMS4_CCMGetSize,(int* pSize)) -IPPAPI(IppStatus, l9_ippsSMS4_CCMGetSize,(int* pSize)) IPPAPI(IppStatus, k1_ippsSMS4_CCMGetSize,(int* pSize)) +IPPAPI(IppStatus, l9_ippsSMS4_CCMGetSize,(int* pSize)) +IPPAPI(IppStatus, y8_ippsSMS4_CCMGetSize,(int* pSize)) -IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMGetSize,(int* pSize)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4_CCMGetSize,(int* pSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4_CCMGetSize( pSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4_CCMGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4_CCMGetSize( pSize ); - } else + } 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 )) { - return h9_ippsSMS4_CCMGetSize( pSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4_CCMGetSize( pSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00065.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMGetTag.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00065.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMGetTag.c index 616c7f2bf..aa9455bc2 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00065.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMGetTag.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_ippsSMS4_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsSMS4_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, y8_ippsSMS4_CCMGetTag,(Ipp8u* pTag, int tagLen, const IppsSMS4_CCMState* pCtx)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4_CCMGetTag( pTag, tagLen, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4_CCMGetTag( pTag, tagLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4_CCMGetTag( pTag, tagLen, pCtx ); - } else + } 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 )) { - return h9_ippsSMS4_CCMGetTag( pTag, tagLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4_CCMGetTag( pTag, tagLen, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00059.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMInit.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00059.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMInit.c index 6963e2287..bbdb66189 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00059.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMInit.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4_CCMInit,(const Ipp8u* pKey, int keyLen, IppsSMS4_CCMState* pCtx, int ctxSize)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4_CCMInit( pKey, keyLen, pCtx, ctxSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4_CCMInit( pKey, keyLen, pCtx, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4_CCMInit( pKey, keyLen, pCtx, ctxSize ); - } else + } 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 )) { - return h9_ippsSMS4_CCMInit( pKey, keyLen, pCtx, ctxSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4_CCMInit( pKey, keyLen, pCtx, ctxSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00060.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMMessageLen.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00060.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMMessageLen.c index 4a2cd10be..a8cd0381b 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00060.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMMessageLen.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) -IPPAPI(IppStatus, l9_ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) IPPAPI(IppStatus, k1_ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, y8_ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4_CCMMessageLen,(Ipp64u msgLen, IppsSMS4_CCMState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4_CCMMessageLen( msgLen, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4_CCMMessageLen( msgLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4_CCMMessageLen( msgLen, pCtx ); - } else + } 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 )) { - return h9_ippsSMS4_CCMMessageLen( msgLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4_CCMMessageLen( msgLen, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00062.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMStart.c similarity index 69% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00062.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMStart.c index 79809d216..744e5ae6e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00062.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMStart.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4_CCMStart,(const Ipp8u* pIV, int ivLen, const Ipp8u* pAD, int adLen, IppsSMS4_CCMState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4_CCMStart( pIV, ivLen, pAD, adLen, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4_CCMStart( pIV, ivLen, pAD, adLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4_CCMStart( pIV, ivLen, pAD, adLen, pCtx ); - } else + } 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 )) { - return h9_ippsSMS4_CCMStart( pIV, ivLen, pAD, adLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4_CCMStart( pIV, ivLen, pAD, adLen, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00061.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMTagLen.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00061.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMTagLen.c index 7c9006118..eb801212c 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00061.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSMS4_CCMTagLen.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) -IPPAPI(IppStatus, l9_ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) IPPAPI(IppStatus, k1_ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, l9_ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) +IPPAPI(IppStatus, y8_ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsSMS4_CCMTagLen,(int tagLen, IppsSMS4_CCMState* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSMS4_CCMTagLen( tagLen, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSMS4_CCMTagLen( tagLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSMS4_CCMTagLen( tagLen, pCtx ); - } else + } 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 )) { - return h9_ippsSMS4_CCMTagLen( tagLen, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSMS4_CCMTagLen( tagLen, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00255.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSetOctString_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00255.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSetOctString_BN.c index 0b7218a71..49743e662 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00255.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSetOctString_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSetOctString_BN,(const Ipp8u* pStr, int strLen, IppsBigNumState* pBN)) -IPPAPI(IppStatus, l9_ippsSetOctString_BN,(const Ipp8u* pStr, int strLen, IppsBigNumState* pBN)) IPPAPI(IppStatus, k1_ippsSetOctString_BN,(const Ipp8u* pStr, int strLen, IppsBigNumState* pBN)) +IPPAPI(IppStatus, l9_ippsSetOctString_BN,(const Ipp8u* pStr, int strLen, IppsBigNumState* pBN)) +IPPAPI(IppStatus, y8_ippsSetOctString_BN,(const Ipp8u* pStr, int strLen, IppsBigNumState* pBN)) -IPPFUN(IppStatus,sgx_disp_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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSetOctString_BN( pStr, strLen, pBN ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSetOctString_BN( pStr, strLen, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSetOctString_BN( pStr, strLen, pBN ); - } else + } 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 )) { - return h9_ippsSetOctString_BN( pStr, strLen, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSetOctString_BN( pStr, strLen, pBN ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00243.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSet_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00243.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSet_BN.c index c1658c7d1..9af25431e 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00243.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSet_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +IPPFUN(IppStatus, sgx_disp_ippsSet_BN,(IppsBigNumSGN sgn, int length, const Ipp32u* pData, IppsBigNumState* pBN)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSet_BN( sgn, length, pData, pBN ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSet_BN( sgn, length, pData, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSet_BN( sgn, length, pData, pBN ); - } else + } 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 )) { - return h9_ippsSet_BN( sgn, length, pData, pBN ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSet_BN( sgn, length, pData, pBN ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00248.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSub_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00248.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSub_BN.c index d8fd33f25..7a3abc295 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00248.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsSub_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) -IPPAPI(IppStatus, l9_ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) IPPAPI(IppStatus, k1_ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, l9_ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPAPI(IppStatus, y8_ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) -IPPFUN(IppStatus,sgx_disp_ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) +IPPFUN(IppStatus, sgx_disp_ippsSub_BN, (IppsBigNumState* pA, IppsBigNumState* pB, IppsBigNumState* pR)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsSub_BN( pA, pB, pR ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsSub_BN( pA, pB, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsSub_BN( pA, pB, pR ); - } else + } 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 )) { - return h9_ippsSub_BN( pA, pB, pR ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsSub_BN( pA, pB, pR ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00008.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptCBC.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00008.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptCBC.c index 4e33f907e..85da7632d 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00008.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptCBC.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsTDESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) -IPPAPI(IppStatus, l9_ippsTDESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) IPPAPI(IppStatus, k1_ippsTDESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, l9_ippsTDESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, y8_ippsTDESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, 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 len, 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 len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsTDESDecryptCBC( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsTDESDecryptCBC( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsTDESDecryptCBC( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsTDESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) -IPPAPI(IppStatus, h9_ippsTDESDecryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, 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 len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsTDESDecryptCBC( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsTDESDecryptCBC( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00010.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptCFB.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00010.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptCFB.c index 88b994b92..c7a499b06 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00010.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptCFB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsTDESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, 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 len, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) IPPAPI(IppStatus, k1_ippsTDESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, 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 len, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, y8_ippsTDESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, 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 len, 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 len, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsTDESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsTDESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsTDESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsTDESDecryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, 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 len, 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 len, 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 )) { - return h9_ippsTDESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsTDESDecryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00014.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptCTR.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00014.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptCTR.c index dc535cce5..4a82c4d74 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00014.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptCTR.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsTDESDecryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsTDESDecryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsTDESDecryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); - } else + } 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 )) { - return h9_ippsTDESDecryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsTDESDecryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00006.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptECB.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00006.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptECB.c index 077a084d2..5bcd29859 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00006.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptECB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) -IPPAPI(IppStatus, l9_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) IPPAPI(IppStatus, k1_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +IPPAPI(IppStatus, l9_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +IPPAPI(IppStatus, y8_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) -IPPFUN(IppStatus,sgx_disp_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +IPPFUN(IppStatus, sgx_disp_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsTDESDecryptECB( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, padding ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsTDESDecryptECB( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, padding ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsTDESDecryptECB( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, padding ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) -IPPAPI(IppStatus, h9_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) - -IPPFUN(IppStatus,sgx_disp_ippsTDESDecryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsTDESDecryptECB( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, padding ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsTDESDecryptECB( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, padding ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00012.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptOFB.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00012.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptOFB.c index 858e3f63f..876a1bdfe 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00012.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESDecryptOFB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsTDESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsTDESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsTDESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); - } else + } 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 )) { - return h9_ippsTDESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsTDESDecryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00007.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptCBC.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00007.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptCBC.c index 4fe7c4950..2f9fc5ccc 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00007.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptCBC.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsTDESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) -IPPAPI(IppStatus, l9_ippsTDESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) IPPAPI(IppStatus, k1_ippsTDESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, l9_ippsTDESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, y8_ippsTDESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, 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 len, 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 len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsTDESEncryptCBC( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsTDESEncryptCBC( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsTDESEncryptCBC( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsTDESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) -IPPAPI(IppStatus, h9_ippsTDESEncryptCBC,(const Ipp8u* pSrc, Ipp8u* pDst, int len, 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 len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsTDESEncryptCBC( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsTDESEncryptCBC( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00009.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptCFB.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00009.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptCFB.c index 73b9f67aa..87ce91706 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00009.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptCFB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsTDESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, 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 len, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) IPPAPI(IppStatus, k1_ippsTDESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, 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 len, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) +IPPAPI(IppStatus, y8_ippsTDESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, 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 len, 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 len, int cfbBlkSize, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, const Ipp8u* pIV, IppsCPPadding padding)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsTDESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsTDESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsTDESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsTDESEncryptCFB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, 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 len, 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 len, 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 )) { - return h9_ippsTDESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsTDESEncryptCFB( pSrc, pDst, len, cfbBlkSize, pCtx1, pCtx2, pCtx3, pIV, padding ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00013.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptCTR.c similarity index 65% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00013.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptCTR.c index e76957bec..6e5b50b49 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00013.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptCTR.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsTDESEncryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsTDESEncryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsTDESEncryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); - } else + } 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 )) { - return h9_ippsTDESEncryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsTDESEncryptCTR( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, pCtrValue, ctrNumBitSize ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00005.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptECB.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00005.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptECB.c index 8cdc8e3c5..67d95614a 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00005.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptECB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) -IPPAPI(IppStatus, l9_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) IPPAPI(IppStatus, k1_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +IPPAPI(IppStatus, l9_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +IPPAPI(IppStatus, y8_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) -IPPFUN(IppStatus,sgx_disp_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) +IPPFUN(IppStatus, sgx_disp_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsTDESEncryptECB( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, padding ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsTDESEncryptECB( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, padding ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsTDESEncryptECB( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, padding ); - } else + } else return ippStsCpuNotSupportedErr; } -#else - -IPPAPI(IppStatus, p8_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) -IPPAPI(IppStatus, h9_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) - -IPPFUN(IppStatus,sgx_disp_ippsTDESEncryptECB,(const Ipp8u* pSrc, Ipp8u* pDst, int len, const IppsDESSpec* pCtx1, const IppsDESSpec* pCtx2, const IppsDESSpec* pCtx3, IppsCPPadding padding)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsTDESEncryptECB( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, padding ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsTDESEncryptECB( pSrc, pDst, len, pCtx1, pCtx2, pCtx3, padding ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00011.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptOFB.c similarity index 66% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00011.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptOFB.c index 674979398..3d4af1130 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00011.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTDESEncryptOFB.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -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)) IPPAPI(IppStatus, k1_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)) +IPPAPI(IppStatus, y8_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)) +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 ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsTDESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsTDESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsTDESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); - } else + } 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 )) { - return h9_ippsTDESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsTDESEncryptOFB( pSrc, pDst, len, ofbBlkSize, pCtx1, pCtx2, pCtx3, pIV ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00275.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTRNGenRDSEED.c similarity index 71% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00275.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTRNGenRDSEED.c index 71d178303..dcc2fe28f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00275.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTRNGenRDSEED.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsTRNGenRDSEED, (Ipp32u* pRand, int nBits, void* pCtx)) -IPPAPI(IppStatus, l9_ippsTRNGenRDSEED, (Ipp32u* pRand, int nBits, void* pCtx)) IPPAPI(IppStatus, k1_ippsTRNGenRDSEED, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, l9_ippsTRNGenRDSEED, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, y8_ippsTRNGenRDSEED, (Ipp32u* pRand, int nBits, void* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsTRNGenRDSEED, (Ipp32u* pRand, int nBits, void* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsTRNGenRDSEED, (Ipp32u* pRand, int nBits, void* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsTRNGenRDSEED( pRand, nBits, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsTRNGenRDSEED( pRand, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsTRNGenRDSEED( pRand, nBits, pCtx ); - } else + } 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 )) { - return h9_ippsTRNGenRDSEED( pRand, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsTRNGenRDSEED( pRand, nBits, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00276.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTRNGenRDSEED_BN.c similarity index 70% rename from sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00276.c rename to sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTRNGenRDSEED_BN.c index da7f6d792..54fba285f 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00276.c +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/intel64/ippsTRNGenRDSEED_BN.c @@ -31,7 +31,10 @@ #include "ippcp.h" -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg +#ifndef IPP_CALL +#define IPP_CALL IPP_STDCALL +#endif +#define IPPFUN(type,name,arg) extern type IPP_CALL name arg #ifndef NULL #ifdef __cplusplus @@ -43,49 +46,37 @@ #if defined (_M_AMD64) || defined (__x86_64__) - #define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) #define AVX3X_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512VL|ippCPUID_AVX512BW|ippCPUID_AVX512DQ ) #define AVX3M_FEATURES ( ippCPUID_AVX512F|ippCPUID_AVX512CD|ippCPUID_AVX512PF|ippCPUID_AVX512ER ) +#ifdef __cplusplus +extern "C" { +#endif -IPPAPI(IppStatus, y8_ippsTRNGenRDSEED_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) -IPPAPI(IppStatus, l9_ippsTRNGenRDSEED_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) IPPAPI(IppStatus, k1_ippsTRNGenRDSEED_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, l9_ippsTRNGenRDSEED_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPAPI(IppStatus, y8_ippsTRNGenRDSEED_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) -IPPFUN(IppStatus,sgx_disp_ippsTRNGenRDSEED_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) +IPPFUN(IppStatus, sgx_disp_ippsTRNGenRDSEED_BN,(IppsBigNumState* pRand, int nBits, void* pCtx)) { - Ipp64u features; - ippcpGetCpuFeatures( &features ); + Ipp64u _features; + _features = ippcpGetEnabledCpuFeatures(); - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { + if( AVX3I_FEATURES == ( _features & AVX3I_FEATURES )) { return k1_ippsTRNGenRDSEED_BN( pRand, nBits, pCtx ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { + } else + if( ippCPUID_AVX2 == ( _features & ippCPUID_AVX2 )) { return l9_ippsTRNGenRDSEED_BN( pRand, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { + } else + if( ippCPUID_SSE42 == ( _features & ippCPUID_SSE42 )) { return y8_ippsTRNGenRDSEED_BN( pRand, nBits, pCtx ); - } else + } 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 )) { - return h9_ippsTRNGenRDSEED_BN( pRand, nBits, pCtx ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsTRNGenRDSEED_BN( pRand, nBits, pCtx ); - } else - return ippStsCpuNotSupportedErr; +#ifdef __cplusplus } #endif + +#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00078.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00078.c deleted file mode 100644 index 58b3f893a..000000000 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00078.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2011-2021 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 "ippcp.h" - -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#if defined (_M_AMD64) || defined (__x86_64__) - - -#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) -#define AVX3X_FEATURES ( 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)) -IPPAPI(IppStatus, k1_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( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { - return k1_ippsAES_GCMProcessAAD( pAAD, ivAAD, pState ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return l9_ippsAES_GCMProcessAAD( pAAD, ivAAD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - 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 )) { - return h9_ippsAES_GCMProcessAAD( pAAD, ivAAD, pState ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsAES_GCMProcessAAD( pAAD, ivAAD, pState ); - } else - return ippStsCpuNotSupportedErr; -} -#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00500.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00500.c deleted file mode 100644 index 55c44f562..000000000 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00500.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2011-2021 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 "ippcp.h" - -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#if defined (_M_AMD64) || defined (__x86_64__) - - -#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) -#define AVX3X_FEATURES ( 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, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, l9_ippsGFpECSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, k1_ippsGFpECSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { - return k1_ippsGFpECSignDSA( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return l9_ippsGFpECSignDSA( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return y8_ippsGFpECSignDSA( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; -} -#else - - -IPPAPI(IppStatus, p8_ippsGFpECSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, h9_ippsGFpECSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECSignDSA,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECSignDSA( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSignDSA( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; -} -#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00501.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00501.c deleted file mode 100644 index 04deb9d3a..000000000 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00501.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2011-2021 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 "ippcp.h" - -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#if defined (_M_AMD64) || defined (__x86_64__) - - -#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) -#define AVX3X_FEATURES ( 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)) -IPPAPI(IppStatus, k1_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( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { - return k1_ippsGFpECVerifyDSA( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return l9_ippsGFpECVerifyDSA( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - 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 )) { - return h9_ippsGFpECVerifyDSA( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECVerifyDSA( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; -} -#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00502.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00502.c deleted file mode 100644 index 4e2d6bfa0..000000000 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00502.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2011-2021 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 "ippcp.h" - -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#if defined (_M_AMD64) || defined (__x86_64__) - - -#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) -#define AVX3X_FEATURES ( 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, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, l9_ippsGFpECSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, k1_ippsGFpECSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { - return k1_ippsGFpECSignNR( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return l9_ippsGFpECSignNR( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return y8_ippsGFpECSignNR( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; -} -#else - - -IPPAPI(IppStatus, p8_ippsGFpECSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, h9_ippsGFpECSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECSignNR,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECSignNR( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSignNR( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; -} -#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00503.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00503.c deleted file mode 100644 index baa383f20..000000000 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00503.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2011-2021 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 "ippcp.h" - -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#if defined (_M_AMD64) || defined (__x86_64__) - - -#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) -#define AVX3X_FEATURES ( 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)) -IPPAPI(IppStatus, k1_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( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { - return k1_ippsGFpECVerifyNR( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return l9_ippsGFpECVerifyNR( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - 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 )) { - return h9_ippsGFpECVerifyNR( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECVerifyNR( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; -} -#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00504.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00504.c deleted file mode 100644 index dd215f6d2..000000000 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00504.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2011-2021 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 "ippcp.h" - -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#if defined (_M_AMD64) || defined (__x86_64__) - - -#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) -#define AVX3X_FEATURES ( 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, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, l9_ippsGFpECSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, k1_ippsGFpECSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { - return k1_ippsGFpECSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return l9_ippsGFpECSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return y8_ippsGFpECSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; -} -#else - - -IPPAPI(IppStatus, p8_ippsGFpECSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -IPPAPI(IppStatus, h9_ippsGFpECSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) - -IPPFUN(IppStatus,sgx_disp_ippsGFpECSignSM2,(const IppsBigNumState* pMsgDigest, const IppsBigNumState* pRegPrivate, IppsBigNumState* pEphPrivate, IppsBigNumState* pSignR, IppsBigNumState* pSignS, IppsGFpECState* pEC, Ipp8u* pScratchBuffer)) -{ - Ipp64u features; - ippcpGetCpuFeatures( &features ); - - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return h9_ippsGFpECSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECSignSM2( pMsgDigest, pRegPrivate, pEphPrivate, pSignR, pSignS, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; -} -#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00505.c b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00505.c deleted file mode 100644 index 36d08f915..000000000 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/ipp_disp/ippcpsgx_disp00505.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2011-2021 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 "ippcp.h" - -#define IPPFUN(type,name,arg) extern type IPP_STDCALL name arg - -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#if defined (_M_AMD64) || defined (__x86_64__) - - -#define AVX3I_FEATURES ( ippCPUID_SHA|ippCPUID_AVX512VBMI|ippCPUID_AVX512VBMI2|ippCPUID_AVX512IFMA|ippCPUID_AVX512GFNI|ippCPUID_AVX512VAES|ippCPUID_AVX512VCLMUL ) -#define AVX3X_FEATURES ( 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)) -IPPAPI(IppStatus, k1_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( AVX3I_FEATURES == ( features & AVX3I_FEATURES )) { - return k1_ippsGFpECVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_AVX2 == ( features & ippCPUID_AVX2 )) { - return l9_ippsGFpECVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - 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 )) { - return h9_ippsGFpECVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); - } else - if( ippCPUID_SSE42 == ( features & ippCPUID_SSE42 )) { - return p8_ippsGFpECVerifySM2( pMsgDigest, pRegPublic, pSignR, pSignS, pResult, pEC, pScratchBuffer ); - } else - return ippStsCpuNotSupportedErr; -} -#endif diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/sgx_sm2.cpp b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/sgx_sm2.cpp index 8c2b83fc6..ea197da55 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/sgx_sm2.cpp +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/sgx_sm2.cpp @@ -524,8 +524,8 @@ sgx_status_t sgx_calculate_sm2_priv_key(const unsigned char* hash_drg, int hash_ const unsigned char* sgx_sm2_order, int sgx_sm2_order_len, unsigned char* out_key, int out_key_len) { - if (out_key == NULL || hash_drg_len <= 0 || sgx_sm2_order <= 0 || - out_key_len <= 0 || hash_drg == NULL || sgx_sm2_order_len == NULL) { + if (out_key == NULL || hash_drg_len <= 0 || sgx_sm2_order == NULL || + out_key_len <= 0 || hash_drg == NULL || sgx_sm2_order_len <= 0) { return SGX_ERROR_INVALID_PARAMETER; } diff --git a/sgx_libc/sgx_tlibc_sys/tlibc/gen/sbrk.c b/sgx_libc/sgx_tlibc_sys/tlibc/gen/sbrk.c index 0f4c28d0e..422d9781c 100644 --- a/sgx_libc/sgx_tlibc_sys/tlibc/gen/sbrk.c +++ b/sgx_libc/sgx_tlibc_sys/tlibc/gen/sbrk.c @@ -78,6 +78,7 @@ void* sbrk(intptr_t n) size_t prev_heap_used = heap_used; void * start_addr; size_t size = 0; + assert((heap_used & (SE_PAGE_SIZE - 1)) == 0); if (!heap_base) return (void *)(~(size_t)0); @@ -113,6 +114,7 @@ void* sbrk(intptr_t n) start_addr = (void *)((size_t)(heap_base) + heap_min_size); size = prev_heap_used - heap_min_size; } + assert((size & (SE_PAGE_SIZE - 1)) == 0); int ret = sgx_trim_epc_pages(start_addr, size >> SE_PAGE_SHIFT); if (ret != 0) { @@ -131,6 +133,8 @@ void* sbrk(intptr_t n) there's no integer overflow here. */ heap_ptr = (void *)((size_t)heap_base + (size_t)heap_used); + if(n == 0) return heap_ptr; + heap_used += n; /* update g_peak_heap_used */ @@ -154,6 +158,7 @@ void* sbrk(intptr_t n) start_addr = (void *)((size_t)(heap_base) + heap_min_size); size = heap_used - heap_min_size; } + assert((size & (SE_PAGE_SIZE - 1)) == 0); int ret = sgx_apply_epc_pages(start_addr, size >> SE_PAGE_SHIFT); if (ret != 0) { diff --git a/sgx_libc/sgx_tlibc_sys/tlibc/gen/spinlock.c b/sgx_libc/sgx_tlibc_sys/tlibc/gen/spinlock.c index b0bc40847..c1f2d24c5 100644 --- a/sgx_libc/sgx_tlibc_sys/tlibc/gen/spinlock.c +++ b/sgx_libc/sgx_tlibc_sys/tlibc/gen/spinlock.c @@ -58,15 +58,23 @@ static inline int _InterlockedExchange(int volatile * dst, int val) } +#define MIN_BACKOFF 2 +#define MAX_BACKOFF 1024 uint32_t sgx_spin_lock(sgx_spinlock_t *lock) { - while(_InterlockedExchange((volatile int *)lock, 1) != 0) { - while (*lock) { - /* tell cpu we are spinning */ - _mm_pause(); - } + while(_InterlockedExchange((volatile int *)lock, 1) != 0) { + int b = MIN_BACKOFF; + do + { /* tell cpu we are spinning */ + for (int i=0; i < b; i++) { + _mm_pause(); + } + b <<= 1; + if (b > MAX_BACKOFF) { + b = MAX_BACKOFF; + } + } while (*lock); } - return (0); } @@ -76,4 +84,3 @@ uint32_t sgx_spin_unlock(sgx_spinlock_t *lock) return (0); } - diff --git a/sgx_libc/sgx_tlibc_sys/tlibc/stdlib/aligned_alloc.c b/sgx_libc/sgx_tlibc_sys/tlibc/stdlib/aligned_alloc.c new file mode 100644 index 000000000..f3dcc46c2 --- /dev/null +++ b/sgx_libc/sgx_tlibc_sys/tlibc/stdlib/aligned_alloc.c @@ -0,0 +1,6 @@ +#include + +void *aligned_alloc(size_t align, size_t len) +{ + return memalign(align, len); +} diff --git a/sgx_libc/sgx_tlibc_sys/tlibc/stdlib/malloc.c b/sgx_libc/sgx_tlibc_sys/tlibc/stdlib/malloc.c index 31ac4f714..29879572a 100644 --- a/sgx_libc/sgx_tlibc_sys/tlibc/stdlib/malloc.c +++ b/sgx_libc/sgx_tlibc_sys/tlibc/stdlib/malloc.c @@ -845,8 +845,8 @@ extern "C" { void* __attribute__((weak)) calloc(size_t n, size_t size) ALIAS(dlcalloc); void* __attribute__((weak)) memalign(size_t align, size_t s) ALIAS(dlmemalign); struct mallinfo __attribute__((weak)) mallinfo(void) ALIAS(dlmallinfo); + int __attribute__((weak)) posix_memalign(void** pp, size_t alignment, size_t n) ALIAS(dlposix_memalign); #ifdef USE_MALLOC_DEPRECATED -#define dlposix_memalign posix_memalign #define dlrealloc_in_place realloc_in_place #define dlvalloc valloc #define dlpvalloc pvalloc @@ -952,7 +952,6 @@ DLMALLOC_EXPORT void* dlrealloc_in_place(void*, size_t); */ DLMALLOC_EXPORT void* dlmemalign(size_t, size_t); -#ifdef USE_MALLOC_DEPRECATED /* int posix_memalign(void** pp, size_t alignment, size_t n); Allocates a chunk of n bytes, aligned in accord with the alignment @@ -963,6 +962,7 @@ DLMALLOC_EXPORT void* dlmemalign(size_t, size_t); */ DLMALLOC_EXPORT int dlposix_memalign(void**, size_t, size_t); +#ifdef USE_MALLOC_DEPRECATED /* valloc(size_t n); Equivalent to memalign(pagesize, n), where pagesize is the page @@ -5336,7 +5336,6 @@ void* dlmemalign(size_t alignment, size_t bytes) { return internal_memalign(gm, alignment, bytes); } -#ifdef USE_MALLOC_DEPRECATED int dlposix_memalign(void** pp, size_t alignment, size_t bytes) { void* mem = 0; if (alignment == MALLOC_ALIGNMENT) @@ -5360,6 +5359,7 @@ int dlposix_memalign(void** pp, size_t alignment, size_t bytes) { } } +#ifdef USE_MALLOC_DEPRECATED void* dlvalloc(size_t bytes) { size_t pagesz; ensure_initialization(); diff --git a/sgx_libc/sgx_tlibc_sys/tlibc/string/memcpy.c b/sgx_libc/sgx_tlibc_sys/tlibc/string/memcpy.c index a83c3744d..526b21495 100644 --- a/sgx_libc/sgx_tlibc_sys/tlibc/string/memcpy.c +++ b/sgx_libc/sgx_tlibc_sys/tlibc/string/memcpy.c @@ -110,12 +110,13 @@ void* memcpy_verw(void *dst0, const void *src0, size_t len) } while (len >= 8) { - if((unsigned long long)dst%8 == 0) { + if(((unsigned long long)dst%8 == 0) && ((unsigned long long)src%8 == 0)) { // 8-byte-aligned - don't need bracketing - __memcpy_8a(dst, src); - src += 8; - dst += 8; - len -= 8; + size_t len0 = len - len%8; + memcpy_nochecks(dst, src, len0); + src += len0; + dst += len0; + len -= len0; } else{ // not 8-byte-aligned - need bracketing @@ -127,9 +128,9 @@ void* memcpy_verw(void *dst0, const void *src0, size_t len) } // less than 8 bytes left - need bracketing for (unsigned i = 0; i < len; i++) { - __memcpy_verw(dst, src); - src++; - dst++; + __memcpy_verw(dst, src); + src++; + dst++; } return dst0; } @@ -152,27 +153,35 @@ memcpy_nochecks(void *dst0, const void *src0, size_t length) static void copy_external_memory(void* dst, const void* src, size_t count, bool is_dst_external) { - unsigned char tmp_buf[16]={0}; + char tmp_buf[16]={0}; unsigned int off_src = (unsigned long long)src%8; + char* src_buf = NULL; if(count == 0) { return; } - - //if src is 8-byte-aligned, copy 8 bytes from outside the enclave to the buffer - //if src is not 8-byte-aligned and off_src + count > 8, copy 16 bytes from outside the enclave to the buffer - __memcpy_8a(tmp_buf, src - off_src); - if(off_src != 0 && off_src + count > 8) + //if external src is not 8-byte-aligned or count != 8 + if(off_src != 0 || count != 8) { - __memcpy_8a(tmp_buf + 8, src - off_src + 8); + //if external src is not 8-byte-aligned, need to copy from src-off_src to a tmp_buf inside the enclave + __memcpy_8a(tmp_buf, src - off_src); + if(off_src != 0 && off_src + count > 8) + { + __memcpy_8a(tmp_buf + 8, src - off_src + 8); + } + src_buf = tmp_buf + off_src; + } + else + { + src_buf = (char*)src; } if(is_dst_external) { - memcpy_verw(dst, tmp_buf + off_src, count); + memcpy_verw(dst, src_buf, count); } else { - memcpy_nochecks(dst, tmp_buf + off_src, count); + memcpy_nochecks(dst, src_buf, count); } return; } @@ -202,16 +211,28 @@ memcpy(void *dst0, const void *src0, size_t length) } //src is outside the enclave - unsigned int len = 0; + size_t len = 0; char* dst = dst0; const char *src = (const char *)src0; while(length >= 8) { - len = 8 - (unsigned long long)dst%8; - copy_external_memory(dst, src, len, is_dst_external); - src += len; - dst += len; - length -= len; + //if dst and src are both 8-byte-aligned, direct call memcpy_nochecks + if(((unsigned long long)dst%8 == 0) && ((unsigned long long)src%8 == 0)) + { + len = length - length%8; + memcpy_nochecks(dst, src, len); + src += len; + dst += len; + length -= len; + } + else + { + len = 8 - (unsigned long long)dst%8; + copy_external_memory(dst, src, len, is_dst_external); + src += len; + dst += len; + length -= len; + } } //less than 8 bytes left copy_external_memory(dst, src, length, is_dst_external); diff --git a/sgx_trts/src/aexnotify.rs b/sgx_trts/src/aexnotify.rs new file mode 100644 index 000000000..33a7b57f3 --- /dev/null +++ b/sgx_trts/src/aexnotify.rs @@ -0,0 +1,58 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT 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 crate::arch::SsaGpr; +use crate::se::AlignReport; +use crate::tcs; +use sgx_types::error::{SgxResult, SgxStatus}; +use sgx_types::types::AttributesFlags; + +pub struct AEXNotify; + +impl AEXNotify { + const SSA_AEXNOTIFY_MASK: u8 = 1; + + pub fn set(is_enable: bool) -> SgxResult { + let report = AlignReport::get_self(); + if !report + .0 + .body + .attributes + .flags + .intersects(AttributesFlags::AEXNOTIFY) + { + bail!(SgxStatus::Unexpected); + } + + let mut tc = tcs::current(); + let tds = tc.tds_mut(); + let ssa_gpr = tds.ssa_gpr_mut(); + + if is_enable { + ssa_gpr.aex_notify |= Self::SSA_AEXNOTIFY_MASK; + } else { + ssa_gpr.aex_notify &= !Self::SSA_AEXNOTIFY_MASK; + } + + Ok(()) + } + + #[inline] + pub(crate) fn is_enable(ssa_gpr: &SsaGpr) -> bool { + (ssa_gpr.aex_notify & Self::SSA_AEXNOTIFY_MASK) != 0 + } +} diff --git a/sgx_trts/src/arch.rs b/sgx_trts/src/arch.rs index c1d695a53..4764f1fe1 100644 --- a/sgx_trts/src/arch.rs +++ b/sgx_trts/src/arch.rs @@ -20,9 +20,11 @@ use crate::edmm::{PageInfo, PageType}; use crate::tcs::tc; use crate::version::*; +use crate::xsave; use core::convert::From; use core::fmt; use core::mem; +use core::slice; use sgx_types::types::{Attributes, ConfigId, Measurement, MiscSelect}; pub const SE_PAGE_SHIFT: usize = 12; @@ -30,6 +32,7 @@ pub const SE_PAGE_SIZE: usize = 0x1000; pub const SE_GUARD_PAGE_SHIFT: usize = 16; pub const SE_GUARD_PAGE_SIZE: usize = 0x10000; pub const RED_ZONE_SIZE: usize = 128; +pub const RSVD_SIZE_OF_MITIGATION_STACK_AREA: usize = 15 * 8; macro_rules! is_page_aligned { ($num:expr) => { @@ -228,11 +231,20 @@ impl fmt::Debug for Secs { pub const TCS_RESERVED_BYTES: usize = 4024; +impl_bitflags! { + #[repr(C)] + #[derive(Clone, Copy, Debug, Eq, PartialEq)] + pub struct TcsFlags: u64 { + const DBGOPTIN = 0x0001; + const AEXNOTIFY = 0x0002; + } +} + impl_copy_clone! { #[repr(C, align(4096))] pub struct Tcs { pub reserved0: u64, - pub flags: u64, + pub flags: TcsFlags, pub ossa: u64, pub cssa: u32, pub nssa: u32, @@ -319,12 +331,17 @@ pub struct Tds { pub flags: usize, pub xsave_size: usize, pub last_error: usize, + pub aex_mitigation_list: usize, + pub aex_notify_flag: usize, + pub first_ssa_xsave: usize, pub m_next: usize, pub tls_addr: usize, pub tls_array: usize, pub exception_flag: isize, pub cxx_thread_info: [usize; 6], pub stack_commit: usize, + pub aex_notify_entropy_cache: u32, + pub aex_notify_entropy_remaining: i32, #[cfg(feature = "hyper")] pub index: usize, } @@ -358,15 +375,25 @@ impl Tds { } #[inline] - pub fn ssa_gpr(&mut self) -> &mut SsaGpr { + pub fn ssa_gpr_mut(&mut self) -> &mut SsaGpr { unsafe { &mut *(self.first_ssa_gpr as *mut SsaGpr) } } + + #[inline] + pub fn ssa_gpr(&self) -> &SsaGpr { + unsafe { &*(self.first_ssa_gpr as *const SsaGpr) } + } + + #[inline] + pub fn xsave_area(&self) -> &[u8] { + unsafe { slice::from_raw_parts(self.first_ssa_xsave as *const u8, xsave::xsave_size()) } + } } -pub const TCS_POLICY_BIND: usize = 0x0000_0000; /* If set, the TCS is bound to the application thread */ +pub const TCS_POLICY_BIND: usize = 0x0000_0000; //If set, the TCS is bound to the application thread pub const TCS_POLICY_UNBIND: usize = 0x0000_0001; -pub const LAYOUT_ENTRY_NUM: usize = 42; +pub const LAYOUT_ENTRY_NUM: usize = 43; pub const TCS_TEMPLATE_SIZE: usize = 72; #[repr(C)] @@ -389,6 +416,7 @@ pub struct Global { pub enclave_image_base: u64, pub elrange_start_base: u64, pub elrange_size: u64, + pub edmm_bk_overhead: usize, } #[repr(C, packed)] @@ -480,6 +508,7 @@ pub const LAYOUT_ID_THREAD_GROUP_DYN: u16 = group_id!(19); pub const LAYOUT_ID_RSRV_MIN: u16 = 20; pub const LAYOUT_ID_RSRV_INIT: u16 = 21; pub const LAYOUT_ID_RSRV_MAX: u16 = 22; +pub const LAYOUT_ID_USER_REGION: u16 = 23; // se_page_attr.h pub const PAGE_ATTR_EADD: u16 = 1 << 0; @@ -501,20 +530,20 @@ pub const PAGE_ATTR_MASK: u16 = !(PAGE_ATTR_EADD // arch.h pub const SI_FLAG_NONE: u64 = 0x0; -pub const SI_FLAG_R: u64 = 0x1; /* Read Access */ -pub const SI_FLAG_W: u64 = 0x2; /* Write Access */ -pub const SI_FLAG_X: u64 = 0x4; /* Execute Access */ -pub const SI_FLAG_PT_LOW_BIT: u64 = 0x8; /* PT low bit */ -pub const SI_FLAG_PT_MASK: u64 = 0xFF << SI_FLAG_PT_LOW_BIT; /* Page Type Mask [15:8] */ -pub const SI_FLAG_SECS: u64 = 0x00 << SI_FLAG_PT_LOW_BIT; /* SECS */ -pub const SI_FLAG_TCS: u64 = 0x01 << SI_FLAG_PT_LOW_BIT; /* TCS */ -pub const SI_FLAG_REG: u64 = 0x02 << SI_FLAG_PT_LOW_BIT; /* Regular Page */ -pub const SI_FLAG_TRIM: u64 = 0x04 << SI_FLAG_PT_LOW_BIT; /* Trim Page */ +pub const SI_FLAG_R: u64 = 0x1; //Read Access +pub const SI_FLAG_W: u64 = 0x2; //Write Access +pub const SI_FLAG_X: u64 = 0x4; //Execute Access +pub const SI_FLAG_PT_LOW_BIT: u64 = 0x8; // PT low bit +pub const SI_FLAG_PT_MASK: u64 = 0xFF << SI_FLAG_PT_LOW_BIT; //Page Type Mask [15:8] +pub const SI_FLAG_SECS: u64 = 0x00 << SI_FLAG_PT_LOW_BIT; //SECS +pub const SI_FLAG_TCS: u64 = 0x01 << SI_FLAG_PT_LOW_BIT; //TCS +pub const SI_FLAG_REG: u64 = 0x02 << SI_FLAG_PT_LOW_BIT; //Regular Page +pub const SI_FLAG_TRIM: u64 = 0x04 << SI_FLAG_PT_LOW_BIT; //Trim Page pub const SI_FLAG_PENDING: u64 = 0x8; pub const SI_FLAG_MODIFIED: u64 = 0x10; pub const SI_FLAG_PR: u64 = 0x20; -pub const SI_FLAGS_EXTERNAL: u64 = SI_FLAG_PT_MASK | SI_FLAG_R | SI_FLAG_W | SI_FLAG_X; /* Flags visible/usable by instructions */ +pub const SI_FLAGS_EXTERNAL: u64 = SI_FLAG_PT_MASK | SI_FLAG_R | SI_FLAG_W | SI_FLAG_X; //Flags visible/usable by instructions pub const SI_FLAGS_R: u64 = SI_FLAG_R | SI_FLAG_REG; pub const SI_FLAGS_RW: u64 = SI_FLAG_R | SI_FLAG_W | SI_FLAG_REG; pub const SI_FLAGS_RX: u64 = SI_FLAG_R | SI_FLAG_X | SI_FLAG_REG; @@ -575,11 +604,38 @@ pub struct SsaGpr { pub rsp_u: u64, /* (144) untrusted stack pointer. saved by EENTER */ pub rbp_u: u64, /* (152) untrusted frame pointer. saved by EENTE */ pub exit_info: ExitInfo, /* (160) contain information for exits */ - pub reserved: u32, /* (164) padding to multiple of 8 bytes */ + pub reserved: [u8; 3], /* (164) padding */ + pub aex_notify: u8, /* (167) AEX Notify */ pub fs: u64, /* (168) FS register */ pub gs: u64, /* (176) GS register */ } +impl SsaGpr { + pub const BYTE_SIZE: usize = mem::size_of::(); +} + +#[repr(C, packed)] +#[derive(Clone, Copy, Debug)] +pub struct MiscExInfo { + pub maddr: u64, + pub error_code: u32, + pub reserved: u32, +} + +impl MiscExInfo { + pub const BYTE_SIZE: usize = mem::size_of::(); + + #[inline] + pub fn from_ssa_gpr(ssa_gpr: &SsaGpr) -> &MiscExInfo { + unsafe { &*((ssa_gpr as *const _ as usize - Self::BYTE_SIZE) as *const MiscExInfo) } + } + + #[inline] + pub fn from_ssa_gpr_mut(ssa_gpr: &mut SsaGpr) -> &mut MiscExInfo { + unsafe { &mut *((ssa_gpr as *mut _ as usize - Self::BYTE_SIZE) as *mut MiscExInfo) } + } +} + #[repr(C, packed)] #[derive(Clone, Copy, Debug)] pub struct ExitInfo(u32); diff --git a/sgx_trts/src/asm/macro.S b/sgx_trts/src/asm/macro.S index b416669d6..4de0804b3 100644 --- a/sgx_trts/src/asm/macro.S +++ b/sgx_trts/src/asm/macro.S @@ -26,11 +26,15 @@ .equ SE_EACCEPT, 5 .equ SE_EMODPE, 6 .equ SE_EVERIFYREPORT2, 8 +.equ SE_EDECCSSA, 9 .equ SE_ECREATE, 0 .equ SE_EADD, 1 .equ SE_EINIT, 2 .equ SE_EREMOVE, 3 +.equ SE_EDBGRD, 4 +.equ SE_EDBGWR, 5 +.equ SE_EEXTEND, 6 .macro DECLARE_GLOBAL_FUNC name .globl \name diff --git a/sgx_trts/src/asm/mod.rs b/sgx_trts/src/asm/mod.rs index 5ea7afe35..61acd766d 100644 --- a/sgx_trts/src/asm/mod.rs +++ b/sgx_trts/src/asm/mod.rs @@ -25,12 +25,15 @@ cfg_if! { if #[cfg(feature = "sim")] { global_asm!(include_str!("../inst/sim/td.S"), options(att_syntax)); global_asm!(include_str!("../inst/sim/enclu.S"), options(att_syntax)); + global_asm!(include_str!("../inst/sim/aexnotify.S"), options(att_syntax)); } else if #[cfg(feature = "hyper")] { global_asm!(include_str!("../inst/hyper/td.S"), options(att_syntax)); global_asm!(include_str!("../inst/hyper/enclu.S"), options(att_syntax)); + global_asm!(include_str!("../inst/hyper/aexnotify.S"), options(att_syntax)); } else { global_asm!(include_str!("../inst/hw/td.S"), options(att_syntax)); global_asm!(include_str!("../inst/hw/enclu.S"), options(att_syntax)); + global_asm!(include_str!("../inst/hw/aexnotify.S"), options(att_syntax)); } } diff --git a/sgx_trts/src/asm/pic.S b/sgx_trts/src/asm/pic.S index 1be1b4996..47cea6cda 100644 --- a/sgx_trts/src/asm/pic.S +++ b/sgx_trts/src/asm/pic.S @@ -35,12 +35,14 @@ __ImageBase: .equ xsave_size, (SE_WORDSIZE * 7) .equ self_addr, 0 .equ stack_guard, (SE_WORDSIZE * 5) +.equ aex_notify_flag, (SE_WORDSIZE * 10) /* SSA GPR */ .equ ssa_sp_t, 32 .equ ssa_sp_u, 144 .equ ssa_bp_u, 152 .equ ssa_exit_info, 160 +.equ aex_notify, 167 .equ EXIT_INFO_VALID, 0x80000000 /* OCALL command */ @@ -168,6 +170,8 @@ _start: call restore_xregs lfence + DISABLE_AEXNOTIFY_ECALL +.Lrestore_untrust_stack: /* set xdi and xsi */ mov $OCMD_ERET, %rdi mov %rbx, %rsi @@ -339,6 +343,9 @@ DECLARE_LOCAL_FUNC __do_ocall /* restore outside stack context */ mov first_ssa_gpr(%rbx), %rdx + + DISABLE_AEXNOTIFY_OCALL +.Lrestore_outside_stack: mov ssa_bp_u(%rdx), %rbp mov ssa_sp_u(%rdx), %rsp /* @@ -453,17 +460,6 @@ Lereport_inst: SE_EPILOG */ -/* - * ------------------------------------------------------------------------- - * extern "C" void abort(void) __attribute__(__noreturn__); - * ------------------------------------------------------------------------- - */ -/* -DECLARE_GLOBAL_FUNC abort - lea_pic ENCLAVE_STATE, %rax - movl $ENCLAVE_CRASHED, (%rax) - ud2 -*/ /* * ------------------------------------------------------------------------- * extern "C" __attribute__((regparm(1))) void continue_execution(sgx_exception_info_t *info); @@ -506,15 +502,3 @@ DECLARE_LOCAL_FUNC continue_execution pop %rsp /* xsp: xax */ xchg %rax, %rsp ret $(RED_ZONE_SIZE) /* pop xip and red zone (if any) */ - -/* -DECLARE_GLOBAL_FUNC lfence - pop %r11 - lfence - jmp *%r11 - -DECLARE_GLOBAL_FUNC mfence - pop %r11 - mfence - jmp *%r11 -*/ diff --git a/sgx_trts/src/call/ecall.rs b/sgx_trts/src/call/ecall.rs index a5d9d10ad..c9c2f5025 100644 --- a/sgx_trts/src/call/ecall.rs +++ b/sgx_trts/src/call/ecall.rs @@ -254,6 +254,15 @@ pub fn ecall(idx: ECallIndex, tcs: &mut Tcs, ms: *mut T, tidx: usize) -> SgxR tc.init(tidx, false)?; } + #[cfg(not(any(feature = "sim", feature = "hyper")))] + { + let tds = tc.tds_mut(); + if tds.aex_notify_flag == 1 { + tds.aex_notify_flag = 0; + let _ = crate::aexnotify::AEXNotify::set(true); + } + } + #[cfg(not(feature = "hyper"))] if is_root_ecall { let _ = crate::pkru::Pkru::write(0); diff --git a/sgx_trts/src/call/ocall.rs b/sgx_trts/src/call/ocall.rs index ea1af72f7..ea60ea485 100644 --- a/sgx_trts/src/call/ocall.rs +++ b/sgx_trts/src/call/ocall.rs @@ -127,6 +127,13 @@ pub fn oret(ret: usize) -> SgxResult { let mut tc = tcs::current(); let tds = tc.tds_mut(); + + #[cfg(not(any(feature = "sim", feature = "hyper")))] + if tds.aex_notify_flag == 1 { + tds.aex_notify_flag = 0; + let _ = crate::aexnotify::AEXNotify::set(true); + } + let last_sp = tds.last_sp; let context = unsafe { &*(tds.last_sp as *const OCallContext) }; if last_sp == 0 || last_sp <= &context as *const _ as usize { diff --git a/sgx_trts/src/call/ocalloc.rs b/sgx_trts/src/call/ocalloc.rs index 34be04480..a0858f15f 100644 --- a/sgx_trts/src/call/ocalloc.rs +++ b/sgx_trts/src/call/ocalloc.rs @@ -129,7 +129,7 @@ impl DerefMut for OcBuffer { #[cfg(not(feature = "hyper"))] mod stack { - use crate::arch::{self, SsaGpr}; + use crate::arch; use crate::enclave; use crate::tcs; use core::alloc::{AllocError, Allocator, Layout}; @@ -166,10 +166,10 @@ mod stack { let align = cmp::min(layout.align(), OcAlloc::OC_MAX_ALIGN); let size = layout.size(); - let tc = tcs::current(); - let tds = tc.tds(); + let mut tc = tcs::current(); + let tds = tc.tds_mut(); - let ssa_gpr = unsafe { &mut *(tds.first_ssa_gpr as *mut SsaGpr) }; + let ssa_gpr = tds.ssa_gpr_mut(); let mut addr = ssa_gpr.rsp_u as usize; // check u_rsp points to the untrusted address. @@ -233,11 +233,12 @@ mod stack { // | xbp_u | // | xsp_u | pub(super) unsafe fn oc_free(&self) -> SgxResult { - let tc = tcs::current(); - let tds = tc.tds(); + let mut tc = tcs::current(); + let tds = tc.tds_mut(); + let last_sp = tds.last_sp; - let ssa_gpr = &mut *(tds.first_ssa_gpr as *mut SsaGpr); - let addr = tds.last_sp - 3 * mem::size_of::(); + let ssa_gpr = tds.ssa_gpr_mut(); + let addr = last_sp - 3 * mem::size_of::(); let usp = *(addr as *const usize); if enclave::is_within_host(usp as *const u8, mem::size_of::()) { diff --git a/sgx_trts/src/edmm/layout.rs b/sgx_trts/src/edmm/layout.rs index 55b0cbd22..a3e0e309c 100644 --- a/sgx_trts/src/edmm/layout.rs +++ b/sgx_trts/src/edmm/layout.rs @@ -161,4 +161,12 @@ impl<'a> LayoutTable<'a> { false } } + + pub fn is_user_region_exist(&self) -> bool { + if SysFeatures::get().is_edmm() { + self.layout_by_id(arch::LAYOUT_ID_USER_REGION).is_some() + } else { + false + } + } } diff --git a/sgx_trts/src/enclave/entry.rs b/sgx_trts/src/enclave/entry.rs index 57fd6b183..3bf7cac59 100644 --- a/sgx_trts/src/enclave/entry.rs +++ b/sgx_trts/src/enclave/entry.rs @@ -70,16 +70,11 @@ pub unsafe extern "C" fn enter_enclave(index: u64, ms: usize, tcs: *mut Tcs, css _ => Err(SgxStatus::Unexpected), } } else if cssa == 1 { - match ecall { - ECallIndex::Except => { - let mut result = veh::handle(tcs); - if !tc::check_static_stack_guard(tcs) { - result = Err(SgxStatus::StackOverRun); - } - result - } - _ => Err(SgxStatus::Unexpected), + let mut result = veh::handle(tcs); + if !tc::check_static_stack_guard(tcs) { + result = Err(SgxStatus::StackOverRun); } + result } else { Err(SgxStatus::Unexpected) }; diff --git a/sgx_trts/src/enclave/mem.rs b/sgx_trts/src/enclave/mem.rs index db578f84f..bed5bf3c2 100644 --- a/sgx_trts/src/enclave/mem.rs +++ b/sgx_trts/src/enclave/mem.rs @@ -90,6 +90,16 @@ impl MmLayout { pub fn rsrvmm_default_perm() -> ProtectPerm { RsrvMem::get_or_init().perm } + + #[inline] + pub fn user_region_mem_base() -> usize { + UserRegionMem::get_or_init().base + } + + #[inline] + pub fn user_region_mem_size() -> usize { + UserRegionMem::get_or_init().size + } } #[derive(Clone, Copy, Default, Debug)] @@ -344,6 +354,58 @@ impl RsrvMem { } } +pub struct UserRegionMem { + pub base: usize, + pub size: usize, +} + +static mut USER_REGION_MEM: Option = None; + +impl UserRegionMem { + pub fn get_or_init() -> &'static UserRegionMem { + unsafe { + if let Some(ref user_region_mem) = USER_REGION_MEM { + user_region_mem + } else { + let (base, size) = Self::layout(); + USER_REGION_MEM = Some(UserRegionMem { base, size }); + USER_REGION_MEM.as_ref().unwrap() + } + } + } + + fn layout() -> (usize, usize) { + if SysFeatures::get().is_edmm() { + let layout_table = arch::Global::get().layout_table(); + layout_table + .iter() + .find(|layout| unsafe { layout.entry.id == arch::LAYOUT_ID_USER_REGION }) + .map(|layout| unsafe { + ( + MmLayout::image_base() + layout.entry.rva as usize, + (layout.entry.page_count as usize) << arch::SE_PAGE_SHIFT, + ) + }) + .unwrap_or((0, 0)) + } else { + (0, 0) + } + } + + pub fn check(&self) -> bool { + if self.base == 0 { + return true; + } + if !(is_page_aligned!(self.base) && is_page_aligned!(self.size)) { + return false; + } + if self.size > usize::MAX - self.base { + return false; + } + true + } +} + pub fn is_within_enclave(p: *const u8, len: usize) -> bool { let start = p as usize; let end = if len > 0 { diff --git a/sgx_trts/src/feature/sys.rs b/sgx_trts/src/feature/sys.rs index 537b5a5b1..da2a076e3 100644 --- a/sgx_trts/src/feature/sys.rs +++ b/sgx_trts/src/feature/sys.rs @@ -39,6 +39,7 @@ impl_enum! { Sdk2_1 = 2, Sdk2_2 = 3, Sdk2_3 = 4, + Sdk3_0 = 5, } } @@ -60,8 +61,10 @@ pub struct SystemFeatures { unsafe impl ContiguousMemory for SystemFeatures {} impl SystemFeatures { + const SYS_FEATURE_MSB: u64 = 63; const SYS_FEATURE_EXTEND: u64 = 62; const EDMM_ENABLE_BIT: u64 = 1; + const AEX_NOTIFY_BIT: u64 = 2; pub unsafe fn from_raw(features: NonNull) -> SgxResult { ensure!(features.as_ref().is_host_range(), SgxStatus::Unexpected); @@ -99,11 +102,18 @@ impl SystemFeatures { pub fn is_edmm(&self) -> bool { match self.version { - 0 => false, + 0 | 1 | 2 | 3 | 4 => false, _ => (self.system_feature_set[0] & SystemFeatures::EDMM_ENABLE_BIT) != 0, } } + pub fn is_aexnotify(&self) -> bool { + match self.version { + 0 | 1 | 2 | 3 | 4 => false, + _ => (self.system_feature_set[0] & SystemFeatures::AEX_NOTIFY_BIT) != 0, + } + } + pub fn cpu_features_bit(&self, xfrm: u64) -> SgxResult { const XFEATURE_ENABLED_AVX: u64 = 0x06; const XFEATURE_ENABLED_AVX3: u64 = 0xE0; @@ -204,6 +214,7 @@ pub struct SysFeatures { cpu_core_num: u32, cpuinfo_table: [[u32; 4]; 8], is_edmm: bool, + is_aexnotify: bool, } unsafe impl ContiguousMemory for SysFeatures {} @@ -216,6 +227,7 @@ static mut SYS_FEATURES: SysFeatures = SysFeatures { cpu_core_num: 0, cpuinfo_table: [[0; 4]; 8], is_edmm: false, + is_aexnotify: false, }; // Improve compatibility @@ -230,11 +242,17 @@ impl SysFeatures { let version = Version::try_from(raw.version).map_err(|_| SgxStatus::Unexpected)?; let feature = unsafe { SysFeatures::get_mut() }; + match version { + Version::Sdk1_5 | Version::Sdk3_0 => (), + _ => return Err(SgxStatus::Unexpected), + }; + feature.version = version; feature.xfrm = xsave::get_xfrm(); feature.cpu_core_num = raw.cpu_core_num; feature.cpuinfo_table = raw.cpuinfo_table; feature.is_edmm = raw.is_edmm(); + feature.is_aexnotify = raw.is_aexnotify(); feature.cpu_features = raw.cpu_features_bit(feature.xfrm)?; unsafe { @@ -258,6 +276,11 @@ impl SysFeatures { self.is_edmm } + #[inline] + pub fn is_aexnotify(&self) -> bool { + self.is_aexnotify + } + #[inline] pub fn version(&self) -> Version { self.version diff --git a/sgx_trts/src/inst/hw/aexnotify.S b/sgx_trts/src/inst/hw/aexnotify.S new file mode 100644 index 000000000..9eed8df8f --- /dev/null +++ b/sgx_trts/src/inst/hw/aexnotify.S @@ -0,0 +1,59 @@ +/* Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT 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 "aexnotify.S" + +DECLARE_LOCAL_FUNC second_phase + movq %rsi, %rsp + mov $SE_EDECCSSA, %rax + ENCLU /* DECCSSA */ + jmp *%rdx + +.macro DISABLE_AEXNOTIFY_ECALL + mov -3*SE_WORDSIZE(%rbp), %rax /* cssa */ + cmp $0, %rax + jne .Lrestore_untrust_stack + + mov %gs:0, %rax /* read td data */ + cmp $0, %rax /* check if td is initialized */ + je .Lrestore_untrust_stack + mov first_ssa_gpr(%rax), %rdx + movb aex_notify(%rdx), %cl + cmpb $0, %cl + je .Lrestore_untrust_stack + /* + * clear aexnotify bit to disable aexnotify temporarily and + * set td.aex_notify_flag to indicate aexnotify is enabled + * before EEXIT + */ + movb $0, aex_notify(%rdx) + movl $0x1, aex_notify_flag(%rax) +.endm + +.macro DISABLE_AEXNOTIFY_OCALL + movb aex_notify(%rdx), %cl + cmpb $0, %cl + je .Lrestore_outside_stack + + /* + * clear aexnotify to disable aexnotify temporarily and + * set td.aex_notify_flag to indicate aexnotify is enabled + * before EEXIT + */ + movb $0, aex_notify(%rdx) + movl $0x1, aex_notify_flag(%rbx) +.endm diff --git a/sgx_trts/src/inst/hw/inst.rs b/sgx_trts/src/inst/hw/inst.rs index c5264f2bc..497ea05db 100644 --- a/sgx_trts/src/inst/hw/inst.rs +++ b/sgx_trts/src/inst/hw/inst.rs @@ -94,6 +94,26 @@ impl EncluInst { } } + pub fn eacceptcopy(info: &Secinfo, addr: usize, source: usize) -> Result<(), u32> { + unsafe { + let error; + asm!( + "xchg rbx, {0}", + "enclu", + "mov rbx, {0}", + inout(reg) info => _, + inlateout("eax") Enclu::EAccept as u32 => error, + in("rcx") addr, + in("rdx") source, + options(nostack), + ); + match error { + 0 => Ok(()), + _ => Err(error), + } + } + } + pub fn emodpe(info: &Secinfo, addr: usize) -> Result<(), u32> { unsafe { asm!( diff --git a/sgx_trts/src/inst/hyper/aexnotify.S b/sgx_trts/src/inst/hyper/aexnotify.S new file mode 100644 index 000000000..4871ce873 --- /dev/null +++ b/sgx_trts/src/inst/hyper/aexnotify.S @@ -0,0 +1,24 @@ +/* Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT 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 "aexnotify.S" + +.macro DISABLE_AEXNOTIFY_ECALL +.endm + +.macro DISABLE_AEXNOTIFY_OCALL +.endm diff --git a/sgx_trts/src/inst/hyper/inst.rs b/sgx_trts/src/inst/hyper/inst.rs index be4c2da5d..fcf8a689c 100644 --- a/sgx_trts/src/inst/hyper/inst.rs +++ b/sgx_trts/src/inst/hyper/inst.rs @@ -97,6 +97,11 @@ impl EncluInst { Ok(()) } + #[inline] + pub fn eacceptcopy(_info: &Secinfo, _addr: usize, _source: usize) -> Result<(), u32> { + Ok(()) + } + #[inline] pub fn emodpe(_info: &Secinfo, _addr: usize) -> Result<(), u32> { Ok(()) diff --git a/sgx_trts/src/inst/sim/aexnotify.S b/sgx_trts/src/inst/sim/aexnotify.S new file mode 100644 index 000000000..4871ce873 --- /dev/null +++ b/sgx_trts/src/inst/sim/aexnotify.S @@ -0,0 +1,24 @@ +/* Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT 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 "aexnotify.S" + +.macro DISABLE_AEXNOTIFY_ECALL +.endm + +.macro DISABLE_AEXNOTIFY_OCALL +.endm diff --git a/sgx_trts/src/inst/sim/inst.rs b/sgx_trts/src/inst/sim/inst.rs index dc8fb43d0..30af1fe9e 100644 --- a/sgx_trts/src/inst/sim/inst.rs +++ b/sgx_trts/src/inst/sim/inst.rs @@ -408,6 +408,11 @@ impl EncluInst { Ok(()) } + #[inline] + pub fn eacceptcopy(_info: &Secinfo, _addr: usize, _source: usize) -> Result<(), u32> { + Ok(()) + } + #[inline] pub fn emodpe(_info: &Secinfo, _addr: usize) -> Result<(), u32> { Ok(()) diff --git a/sgx_trts/src/lib.rs b/sgx_trts/src/lib.rs index 2a1babfc1..84cb59690 100644 --- a/sgx_trts/src/lib.rs +++ b/sgx_trts/src/lib.rs @@ -60,8 +60,10 @@ mod version; mod xsave; pub mod capi; -pub mod edmm; +#[cfg(not(any(feature = "sim", feature = "hyper")))] +pub mod aexnotify; +pub mod edmm; pub mod error; #[macro_use] pub mod feature; diff --git a/sgx_trts/src/tcs/tc.rs b/sgx_trts/src/tcs/tc.rs index 09e4bcfcf..629426e7a 100644 --- a/sgx_trts/src/tcs/tc.rs +++ b/sgx_trts/src/tcs/tc.rs @@ -154,6 +154,8 @@ impl<'a> ThreadControl<'a> { self.tds.stack_limit = tcs_base.wrapping_offset(self.tds.stack_limit as isize) as usize; self.tds.stack_commit = self.tds.stack_limit; self.tds.first_ssa_gpr = tcs_base.wrapping_offset(self.tds.first_ssa_gpr as isize) as usize; + self.tds.first_ssa_xsave = + tcs_base.wrapping_offset(self.tds.first_ssa_xsave as isize) as usize; self.tds.tls_array = tcs_base.wrapping_offset(self.tds.tls_array as isize) as usize; self.tds.tls_addr = tcs_base.wrapping_offset(self.tds.tls_addr as isize) as usize; self.tds.last_sp -= STATIC_STACK_SIZE; diff --git a/sgx_trts/src/veh/exception.rs b/sgx_trts/src/veh/exception.rs index 92d5fb851..a05a2afa5 100644 --- a/sgx_trts/src/veh/exception.rs +++ b/sgx_trts/src/veh/exception.rs @@ -15,18 +15,19 @@ // specific language governing permissions and limitations // under the License.. -use crate::arch::{self, Tcs}; +use crate::arch::{self, MiscExInfo, SsaGpr, Tcs, Tds}; use crate::edmm; use crate::enclave::state::{self, State}; use crate::error; +use crate::feature::SysFeatures; use crate::tcs::tc::{self, ThreadControl}; use crate::trts; use crate::veh::list; use crate::veh::MAX_REGISTER_COUNT; use crate::veh::{ExceptionHandler, ExceptionInfo, ExceptionType, ExceptionVector, HandleResult}; +use crate::xsave; use core::convert::TryFrom; -use core::mem; -use core::mem::MaybeUninit; +use core::mem::{self, MaybeUninit}; use sgx_types::error::{SgxResult, SgxStatus}; macro_rules! try_error { @@ -36,6 +37,32 @@ macro_rules! try_error { bail!(SgxStatus::EnclaveCrashed); } }; + ($cond:expr, $e:expr) => { + if !($cond) { + bail!($e); + } + }; +} + +#[allow(unused_macros)] +macro_rules! bool_to_integer { + ($cond:expr) => { + if $cond { + 1 + } else { + 0 + } + }; +} + +extern "C" { + fn restore_xregs(buf: *const u8); + fn continue_execution(info: *const ExceptionInfo); + fn second_phase( + info: *const ExceptionInfo, + new_sp: *const u8, + second_phase_handler_addr: usize, + ); } pub fn handle(tcs: &mut Tcs) -> SgxResult { @@ -50,7 +77,10 @@ pub fn handle(tcs: &mut Tcs) -> SgxResult { // check if the exception is raised from 2nd phrase try_error!(tds.exception_flag == -1); - try_error!(((tds.first_ssa_gpr & (!0xFFF)) - arch::SE_PAGE_SIZE) != tcs as *const _ as usize); + try_error!( + ((tds.first_ssa_gpr & (!0xFFF)) - round_to_page!(xsave::xsave_size() + SsaGpr::BYTE_SIZE)) + != tcs as *const _ as usize + ); // no need to check the result of ssa_gpr because thread_data is always trusted let mut sp = { @@ -58,40 +88,45 @@ pub fn handle(tcs: &mut Tcs) -> SgxResult { let sp_u = ssa_gpr.rsp_u as usize; let sp = ssa_gpr.rsp as usize; - try_error!(!trts::is_within_host( - sp_u as *const u8, - mem::size_of::() - )); - try_error!(sp_u == sp); + try_error!( + !trts::is_within_host(sp_u as *const u8, mem::size_of::()), + SgxStatus::StackOverRun + ); + try_error!(sp_u == sp, SgxStatus::StackOverRun); + // check stack overrun only, alignment will be checked after exception handled + try_error!(!tds.is_stack_addr(sp, 0), SgxStatus::StackOverRun); sp }; - // check stack overrun only, alignment will be checked after exception handled - try_error!(!tds.is_stack_addr(sp, 0)); - + let xsave_size = tds.xsave_size; let mut size = 0_usize; // x86_64 requires a 128-bytes red zone, which begins directly // after the return addr and includes func's arguments size += arch::RED_ZONE_SIZE; + // Add space for reserved slot for GPRs that will be used by mitigation + // assembly code RIP, RAX, RBX, RCX, RDX, RBP, RSI, RDI Saved flags, 1st + // D/QWORD of red zone, &SSA[0].GPRSGX.AEXNOTIFY, stack_tickle_pages, + // code_tickle_page, data_tickle_page, c3_byte_address + size += arch::RSVD_SIZE_OF_MITIGATION_STACK_AREA; + // decrease the stack to give space for info size += mem::size_of::(); - + size += xsave_size; sp -= size; sp &= !0xF; // check the decreased sp to make sure it is in the trusted stack range - try_error!(!tds.is_stack_addr(sp, 0)); + try_error!(!tds.is_stack_addr(sp, 0), SgxStatus::StackOverRun); let info = unsafe { &mut *(sp as *mut ExceptionInfo) }; - // decrease the stack to save the SSA[0]->ip - size = mem::size_of::(); - sp -= size; + sp -= mem::size_of::(); try_error!(!tds.is_stack_addr(sp, size)); - // sp is within limit_addr and commit_addr, currently only SGX 2.0 under hardware mode will enter this branch. - if sp < tds.stack_commit { + let mut is_exception_handled = false; + let exit_info_valid = tds.ssa_gpr_mut().exit_info.valid(); + if exit_info_valid == 1 && sp < tds.stack_commit { // EDMM: // stack expand let mut result = SgxResult::<()>::Err(SgxStatus::StackOverRun); @@ -108,13 +143,14 @@ pub fn handle(tcs: &mut Tcs) -> SgxResult { } if result.is_ok() { tds.stack_commit -= page_aligned_delta; + is_exception_handled = true; } else { state::set_state(State::Crashed); + bail!(SgxStatus::StackOverRun); } - return result; } - let ssa_gpr = tds.ssa_gpr(); + let ssa_gpr = tds.ssa_gpr_mut(); #[cfg(all(not(feature = "sim"), not(feature = "hyper")))] unsafe { @@ -132,7 +168,8 @@ pub fn handle(tcs: &mut Tcs) -> SgxResult { // ssa_gpr.rflags |= 1; // return Ok(()); // } - if (&Leverifyreport2_inst as *const _ as u64 == ssa_gpr.rip) + if (!is_exception_handled) + && (&Leverifyreport2_inst as *const _ as u64 == ssa_gpr.rip) && (ssa_gpr.rax == Enclu::EVerifyReport2 as u64) { // Handle the exception raised by everifyreport2 instruction @@ -141,19 +178,28 @@ pub fn handle(tcs: &mut Tcs) -> SgxResult { // Set ZF to indicate error condition, see implementation of everify_report2() ssa_gpr.rflags |= 64; ssa_gpr.rax = inst::INVALID_LEAF as u64; - return Ok(()); + is_exception_handled = true; } } // exception handlers are not allowed to call in a non-exception state - try_error!(ssa_gpr.exit_info.valid() != 1); + // add aexnotify check here to skip the case of interrupts + let is_aexnotify = SysFeatures::get().is_aexnotify(); + try_error!(!is_aexnotify && exit_info_valid != 1); // initialize the info with SSA[0] + let exception_valid = if is_exception_handled { + 0_u32 + } else { + exit_info_valid + }; let vector = ExceptionVector::try_from(ssa_gpr.exit_info.vector()); let exception_type = ExceptionType::try_from(ssa_gpr.exit_info.exit_type()); try_error!(vector.is_err() || exception_type.is_err()); + info.exception_valid = exception_valid; info.vector = vector.unwrap(); info.exception_type = exception_type.unwrap(); + info.xsave_size = xsave_size as u64; info.context.rax = ssa_gpr.rax; info.context.rcx = ssa_gpr.rcx; @@ -174,22 +220,54 @@ pub fn handle(tcs: &mut Tcs) -> SgxResult { info.context.r14 = ssa_gpr.r14; info.context.r15 = ssa_gpr.r15; + if info.vector == ExceptionVector::PF || info.vector == ExceptionVector::GP { + let exinfo = MiscExInfo::from_ssa_gpr(ssa_gpr); + info.exinfo.faulting_address = exinfo.maddr; + info.exinfo.error_code = exinfo.error_code; + } let new_sp = sp as *mut u64; - // prepare the ip for 2nd phrase handling - ssa_gpr.rip = internal_handle as usize as u64; - // new stack for internal_handle_exception - ssa_gpr.rsp = new_sp as u64; - // 1st parameter (info) for LINUX32 - ssa_gpr.rax = info as *mut _ as u64; - // 1st parameter (info) for LINUX64, LINUX32 also uses it while restoring the context - ssa_gpr.rdi = info as *mut _ as u64; + + if !(is_aexnotify || is_exception_handled) { + // Two cases that we don't need to run below code: + // 1. AEXNotify is enabled + // 2. stack expansion or EREPORT exception. We have handled it + // in the first phase and we should not change anything in the ssa_gpr + + // prepare the ip for 2nd phrase handling + ssa_gpr.rip = internal_handle as usize as u64; + // new stack for internal_handle_exception + ssa_gpr.rsp = new_sp as u64; + // 1st parameter (info) for LINUX32 + ssa_gpr.rax = info as *mut _ as u64; + // 1st parameter (info) for LINUX64, LINUX32 also uses it while restoring the context + ssa_gpr.rdi = info as *mut _ as u64; + } unsafe { // for debugger to get call trace *new_sp = info.context.rip; } - // mark valid to 0 to prevent eenter again - ssa_gpr.exit_info.set_valid(0); + #[cfg(not(any(feature = "sim", feature = "hyper")))] + { + use crate::aexnotify::AEXNotify; + if is_aexnotify { + info.do_aex_mitigation = bool_to_integer!(AEXNotify::is_enable(ssa_gpr)); + unsafe { + restore_xregs(tds.first_ssa_xsave as *const u8); + } + + if info.do_aex_mitigation == 1 { + let _ = AEXNotify::set(false); + } + unsafe { + second_phase( + info as *const _, + new_sp as *const _, + internal_handle as usize, + ); + } + } + } Ok(()) } @@ -203,34 +281,44 @@ macro_rules! try_abort { }; } -macro_rules! abort { - ($tds:ident) => { - $tds.exception_flag = -1; +#[inline] +fn exception_continue_execution(info: &ExceptionInfo, tds: &mut Tds) -> ! { + // TODO: apply aex mitigations + unsafe { + restore_xregs((&info.xsave_area) as *const u8); + continue_execution(info); + // Should not come here + tds.exception_flag = -1; error::abort(); - }; + } } extern "C" fn internal_handle(info: &mut ExceptionInfo) { - extern "C" { - fn continue_execution(info: *mut ExceptionInfo); - } - let mut tc = tc::current(); let tds = tc.tds_mut(); + try_abort!(info.exception_valid == 0, tds); try_abort!(tds.exception_flag < 0, tds); + + info.xsave_area_mut().copy_from_slice(tds.xsave_area()); tds.exception_flag += 1; + if info.vector == ExceptionVector::PF { + tds.exception_flag -= 1; + + // EMM_TODO: + // if mm_fault_handler(&info.exinfo) == SGX_MM_EXCEPTION_CONTINUE_EXECUTION { + // exception_continue_execution(info); + // } + tds.exception_flag += 1; + } + let (handlers, len) = { let list_guard = list::EXCEPTION_LIST.lock(); if list_guard.len() == 0 { drop(list_guard); tds.exception_flag = -1; - unsafe { - continue_execution(info); - } - // Should not come here - error::abort(); + exception_continue_execution(info, tds); } let mut handlers: [MaybeUninit; MAX_REGISTER_COUNT] = @@ -265,10 +353,5 @@ extern "C" fn internal_handle(info: &mut ExceptionInfo) { tds.exception_flag = -1; } - //instruction triggering the exception will be executed again. - unsafe { - continue_execution(info); - } - - abort!(tds); + exception_continue_execution(info, tds); } diff --git a/sgx_trts/src/veh/register.rs b/sgx_trts/src/veh/register.rs index b70751e4b..30233f40a 100644 --- a/sgx_trts/src/veh/register.rs +++ b/sgx_trts/src/veh/register.rs @@ -20,6 +20,7 @@ use crate::error; use crate::sync::SpinMutex; use crate::veh::list; use core::num::NonZeroU64; +use core::slice; use sgx_types::error::{SgxResult, SgxStatus}; pub const MAX_REGISTER_COUNT: usize = 64; @@ -79,13 +80,45 @@ impl_struct! { impl_struct! { #[repr(C)] #[derive(Debug)] - pub struct ExceptionInfo { - pub context: CpuContext, - pub vector: ExceptionVector, - pub exception_type: ExceptionType, + pub struct MiscExInfo { + pub faulting_address: u64, + pub error_code: u32, + pub reserved: u32, } } +#[repr(C)] +#[derive(Debug)] +pub struct ExceptionInfo { + pub context: CpuContext, + pub vector: ExceptionVector, + pub exception_type: ExceptionType, + pub exinfo: MiscExInfo, + pub exception_valid: u32, + pub do_aex_mitigation: u32, + pub xsave_size: u64, + pub reserved: [u64; 1], + pub xsave_area: [u8; 0], +} + +impl ExceptionInfo { + #[inline] + pub fn xsave_area(&self) -> &[u8] { + unsafe { slice::from_raw_parts(&self.xsave_area as *const u8, self.xsave_size as usize) } + } + + #[inline] + pub fn xsave_area_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut(&mut self.xsave_area as *mut u8, self.xsave_size as usize) + } + } +} + +impl_struct_ContiguousMemory! { + ExceptionInfo; +} + impl_enum! { #[repr(u32)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] diff --git a/sgx_trts/src/version.rs b/sgx_trts/src/version.rs index e253c711b..93bb9598c 100644 --- a/sgx_trts/src/version.rs +++ b/sgx_trts/src/version.rs @@ -16,6 +16,6 @@ // under the License.. pub const MAJOR_VERSION: usize = 2; -pub const MINOR_VERSION: usize = 17; -pub const REVISION_VERSION: usize = 101; +pub const MINOR_VERSION: usize = 20; +pub const REVISION_VERSION: usize = 100; pub const VERSION_UINT: usize = (MAJOR_VERSION << 32) | (MINOR_VERSION << 16) | REVISION_VERSION; diff --git a/sgx_trts/src/xsave.rs b/sgx_trts/src/xsave.rs index 6dd6d5972..8be142aca 100644 --- a/sgx_trts/src/xsave.rs +++ b/sgx_trts/src/xsave.rs @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License.. +use crate::arch::Global; use sgx_types::types; pub fn get_xfrm() -> u64 { @@ -59,3 +60,8 @@ pub fn is_enabled() -> bool { } unsafe { get_xsave_enabled() != 0 } } + +#[inline] +pub fn xsave_size() -> usize { + Global::get().td_template.xsave_size +} diff --git a/sgx_types/src/metadata.rs b/sgx_types/src/metadata.rs index 9a16664f0..4a25c973d 100644 --- a/sgx_types/src/metadata.rs +++ b/sgx_types/src/metadata.rs @@ -24,9 +24,9 @@ pub const SE_KEY_SIZE: usize = 384; pub const SE_EXPONENT_SIZE: usize = 4; /* version of metadata */ -pub const MAJOR_VERSION: u32 = 2; -pub const MINOR_VERSION: u32 = 4; -pub const SGX_2_ELRANGE_MAJOR_VERSION: u32 = 12; //MAJOR_VERSION should not larger than 0FFFFFFFF +pub const MAJOR_VERSION: u32 = 3; +pub const MINOR_VERSION: u32 = 0; +pub const SGX_2_ELRANGE_MAJOR_VERSION: u32 = 13; //MAJOR_VERSION should not larger than 0FFFFFFFF pub const SGX_1_ELRANGE_MAJOR_VERSION: u32 = 11; //MINOR_VERSION should not larger than 0FFFFFFFF pub const SGX_2_1_MAJOR_VERSION: u32 = 2; //MAJOR_VERSION should not larger than 0FFFFFFFF pub const SGX_2_1_MINOR_VERSION: u32 = 2; //MINOR_VERSION should not larger than 0FFFFFFFF @@ -44,17 +44,17 @@ pub const TCS_TEMPLATE_SIZE: usize = 72; pub const TCS_POLICY_BIND: u32 = 0x0000_0000; /* If set, the TCS is bound to the application thread */ pub const TCS_POLICY_UNBIND: u32 = 0x0000_0001; -pub const MAX_SAVE_BUF_SIZE: u32 = 2632; pub const TCS_NUM_MIN: u32 = 1; pub const SSA_NUM_MIN: u32 = 2; pub const SSA_FRAME_SIZE_MIN: u32 = 1; -pub const SSA_FRAME_SIZE_MAX: u32 = 2; -pub const STACK_SIZE_MIN: u32 = 0x0000_2000; /* 8 KB */ -pub const STACK_SIZE_MAX: u32 = 0x0004_0000; /* 256 KB */ -pub const HEAP_SIZE_MIN: u32 = 0x0000_1000; /* 4 KB */ -pub const HEAP_SIZE_MAX: u32 = 0x0100_0000; /* 16 MB */ -pub const RSRV_SIZE_MIN: u32 = 0x0000_0000; /* 0 KB */ -pub const RSRV_SIZE_MAX: u32 = 0x0000_0000; /* 0 KB */ +pub const SSA_FRAME_SIZE_MAX: u32 = 4; +pub const STACK_SIZE_MIN: u64 = 0x0000_2000; //8 KB +pub const STACK_SIZE_MAX: u64 = 0x0004_0000; //256 KB +pub const HEAP_SIZE_MIN: u64 = 0x0000_1000; //4 KB +pub const HEAP_SIZE_MAX: u64 = 0x0100_0000; //16 MB +pub const RSRV_SIZE_MIN: u64 = 0x0000_0000; //0 KB +pub const RSRV_SIZE_MAX: u64 = 0x0000_0000; //0 KB +pub const USER_REGION_SIZE: u64 = 0x0000_0000; //0 KB pub const DEFAULT_MISC_SELECT: u32 = 0; pub const DEFAULT_MISC_MASK: u32 = 0xFFFF_FFFF; pub const ISVFAMILYID_MAX: u64 = 0xFFFF_FFFF_FFFF_FFFF; diff --git a/sgx_types/src/types/mod.rs b/sgx_types/src/types/mod.rs index da37b1363..b6fb85504 100644 --- a/sgx_types/src/types/mod.rs +++ b/sgx_types/src/types/mod.rs @@ -73,7 +73,8 @@ impl_bitflags! { const EINITTOKENKEY = 0x0000_0000_0000_0020; const CET = 0x0000_0000_0000_0040; const KSS = 0x0000_0000_0000_0080; - const NON_SECURITY = 0x0000_0000_0000_0004 | 0x0000_0000_0000_0010 | 0x0000_0000_0000_0020; + const AEXNOTIFY = 0x0000_0000_0000_0400; + const NON_SECURITY = 0x00FF_FFFF_FFFF_FFC0 | 0x0000_0000_0000_0004 | 0x0000_0000_0000_0010 | 0x0000_0000_0000_0020; const DEFAULT_MASK = !(0x00FF_FFFF_FFFF_FFC0 | 0x0000_0000_0000_0004 | 0x0000_0000_0000_0010 | 0x0000_0000_0000_0020); } } @@ -84,7 +85,8 @@ pub const XFRM_AVX: u64 = 0x0000_0000_0000_0006; // AVX pub const XFRM_AVX512: u64 = 0x0000_0000_0000_00E6; // AVX-512 - not supported pub const XFRM_MPX: u64 = 0x0000_0000_0000_0018; // MPX - not supported pub const XFRM_PKRU: u64 = 0x0000_0000_0000_0200; // PKRU state -pub const XFRM_RESERVED: u64 = !(XFRM_LEGACY | XFRM_AVX | XFRM_AVX512 | XFRM_PKRU); +pub const XFRM_AMX: u64 = 0x0000_0000_0006_0000; // AMX XFRM, including XTILEDATA(0x40000) and XTILECFG(0x20000) +pub const XFRM_RESERVED: u64 = !(XFRM_LEGACY | XFRM_AVX | XFRM_AVX512 | XFRM_PKRU | XFRM_AMX); impl_bitflags! { #[repr(C)] diff --git a/sgx_types/src/types/switchless.rs b/sgx_types/src/types/switchless.rs index f709a6da3..55358b7b2 100644 --- a/sgx_types/src/types/switchless.rs +++ b/sgx_types/src/types/switchless.rs @@ -77,11 +77,11 @@ pub const SL_MAX_TASKS_MAX_QWORDS: u32 = 8; #[repr(C)] #[derive(Clone, Copy, Debug)] pub struct SwitchlessConfig { - pub pool_size_qwords: u32, - pub uworkers: u32, - pub tworkers: u32, - pub retries_before_fallback: u32, - pub retries_before_sleep: u32, + pub pool_size_qwords: u64, + pub uworkers: u64, + pub tworkers: u64, + pub retries_before_fallback: u64, + pub retries_before_sleep: u64, pub callback: [Option; 4], } diff --git a/sgx_urts/src/enclave/mod.rs b/sgx_urts/src/enclave/mod.rs index acfc83d1b..271a8a17f 100644 --- a/sgx_urts/src/enclave/mod.rs +++ b/sgx_urts/src/enclave/mod.rs @@ -181,8 +181,8 @@ impl SgxEnclave { pub fn create_with_switchless>( path: P, debug: bool, - uworkers: u32, - tworkers: u32, + uworkers: u64, + tworkers: u64, ) -> SgxResult { let config = SwitchlessConfig { uworkers, From e21a305a116e17d8f1b717ec440e0a71dba06f53 Mon Sep 17 00:00:00 2001 From: volcano Date: Thu, 24 Aug 2023 15:38:42 +0800 Subject: [PATCH 02/34] Support intel-dcap 1.17 --- sgx_trts/src/veh/register.rs | 2 +- sgx_types/src/error/mod.rs | 132 +++++++++++++++++++++++++++++++++-- sgx_types/src/function.rs | 99 +++++++++++++++++++++++--- sgx_types/src/types/dcap.rs | 26 ++++++- sgx_types/src/types/tdx.rs | 112 +++++++++++++++++++++++++++++ 5 files changed, 354 insertions(+), 17 deletions(-) diff --git a/sgx_trts/src/veh/register.rs b/sgx_trts/src/veh/register.rs index 30233f40a..88a4d4f0d 100644 --- a/sgx_trts/src/veh/register.rs +++ b/sgx_trts/src/veh/register.rs @@ -98,7 +98,7 @@ pub struct ExceptionInfo { pub do_aex_mitigation: u32, pub xsave_size: u64, pub reserved: [u64; 1], - pub xsave_area: [u8; 0], + pub(super) xsave_area: [u8; 0], } impl ExceptionInfo { diff --git a/sgx_types/src/error/mod.rs b/sgx_types/src/error/mod.rs index 2b0f8f9bf..02948ec37 100644 --- a/sgx_types/src/error/mod.rs +++ b/sgx_types/src/error/mod.rs @@ -438,6 +438,13 @@ impl_enum! { PswNotAvailable = 0x0000_E052, CollateralVersionNotSupported = 0x0000_E053, TdxModuleMismatch = 0x0000_E060, + QeQeIdentityNotFound = 0x0000_E061, + TcbInfoNotFound = 0x0000_E062, + InternalServerError = 0x0000_E063, + SupplementalDataVersionNotSupport = 0x0000_E064, + RootCAUntrusted = 0x0000_E065, + TcbNotSupported = 0x0000_E066, + ConfigInvalidJson = 0x0000_E067, ErrorMax = 0x0000_E0FF, } } @@ -557,7 +564,22 @@ impl Quote3Error { "SGX quote verification collateral version not supported by QVL/QvE." } Quote3Error::TdxModuleMismatch => { - "TDX SEAM module identity is NOT match to Intel signed TDX SEAM module" + "TDX SEAM module identity is NOT match to Intel signed TDX SEAM module." + } + Quote3Error::QeQeIdentityNotFound => "QE identity was not found.", + Quote3Error::TcbInfoNotFound => "TCB Info was not found.", + Quote3Error::InternalServerError => "Internal server error.", + Quote3Error::SupplementalDataVersionNotSupport => { + "The supplemental data version is not supported." + } + Quote3Error::RootCAUntrusted => { + "The certificate used to establish SSL session is untrusted." + } + Quote3Error::TcbNotSupported => { + "Current TCB level cannot be found in platform/enclave TCB info." + } + Quote3Error::ConfigInvalidJson => { + "The QPL's config file is in JSON format but has a format error." } Quote3Error::ErrorMax => "Indicate max error to allow better translation.", } @@ -645,6 +667,13 @@ impl Quote3Error { Quote3Error::PswNotAvailable => "PswNotAvailable", Quote3Error::CollateralVersionNotSupported => "CollateralVersionNotSupported", Quote3Error::TdxModuleMismatch => "TdxModuleMismatch", + Quote3Error::QeQeIdentityNotFound => "QeQeIdentityNotFound", + Quote3Error::TcbInfoNotFound => "TcbInfoNotFound", + Quote3Error::InternalServerError => "InternalServerError", + Quote3Error::SupplementalDataVersionNotSupport => "SupplementalDataVersionNotSupport", + Quote3Error::RootCAUntrusted => "RootCAUntrusted", + Quote3Error::TcbNotSupported => "TcbNotSupported", + Quote3Error::ConfigInvalidJson => "ConfigInvalidJson", Quote3Error::ErrorMax => "ErrorMax", } } @@ -681,6 +710,11 @@ impl_enum! { StatusCertsUnavaliable = 0x0000_B012, StatusServiceUnavaliable = 0x0000_B013, InvalidConfig = 0x0000_B030, + CacheMissing = 0x0000_B031, + CacheExpired = 0x0000_B032, + RootCAUntrusted = 0x0000_B033, + ConfigInvalidJson = 0x0000_B035, + ConfigNotJson = 0x0000_B036, } } @@ -694,20 +728,20 @@ impl QcnlError { QcnlError::NetworkProxyFail => "Network error : Couldn't resolve proxy.", QcnlError::NetworkHostFail => "Network error : Couldn't resolve host.", QcnlError::NetworkNotConnected => { - "Network error : Failed to connect() to host or proxy." + "Network error: Failed to connect() to host or proxy." } QcnlError::NetworkHttp2Error => { - "Network error : A problem was detected in the HTTP2 framing layer." + "Network error: A problem was detected in the HTTP2 framing layer." } QcnlError::NetworkWriteError => { - "Network error : an error was returned to libcurl from a write callback." + "Network error: an error was returned to libcurl from a write callback." } QcnlError::NetworkTimeout => "Network error : Operation timeout.", QcnlError::NetworkHttpsError => { - "Network error : A problem occurred somewhere in the SSL/TLS handshake." + "Network error: A problem occurred somewhere in the SSL/TLS handshake." } QcnlError::NetworkUnknownOption => { - "Network error : An option passed to libcurl is not recognized/known." + "Network error: An option passed to libcurl is not recognized/known." } QcnlError::NetworkInitError => "Failed to initialize CURL library.", QcnlError::MsgError => "HTTP message error.", @@ -718,6 +752,15 @@ impl QcnlError { QcnlError::StatusCertsUnavaliable => "Certs not available.", QcnlError::StatusServiceUnavaliable => "Service is currently not available.", QcnlError::InvalidConfig => "Error in configuration file.", + QcnlError::CacheMissing => "Cache missing.", + QcnlError::CacheExpired => "Cache expired.", + QcnlError::RootCAUntrusted => { + "The certificate used to establish SSL session is untrusted." + } + QcnlError::ConfigInvalidJson => { + "The config file is in JSON format but has a format error." + } + QcnlError::ConfigNotJson => "The config file is not in JSON format.", } } @@ -744,6 +787,11 @@ impl QcnlError { QcnlError::StatusCertsUnavaliable => "StatusCertsUnavaliable", QcnlError::StatusServiceUnavaliable => "StatusServiceUnavaliable", QcnlError::InvalidConfig => "InvalidConfig", + QcnlError::CacheMissing => "CacheMissing", + QcnlError::CacheExpired => "CacheExpired", + QcnlError::RootCAUntrusted => "RootCAUntrusted", + QcnlError::ConfigInvalidJson => "ConfigInvalidJson", + QcnlError::ConfigNotJson => "ConfigNotJson", } } } @@ -754,10 +802,82 @@ impl fmt::Display for QcnlError { } } +impl_enum! { + #[repr(u32)] + #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)] + pub enum TdxAttestError { + Success = 0x0000_0000, + Unexpected = 0x0000_0001, + InvalidParameter = 0x0000_0002, + OutOfMemory = 0x0000_0003, + VSockFailure = 0x0000_0004, + ReportFailure = 0x0000_0005, + ExtendFailure = 0x0000_0006, + NotSupported = 0x0000_0007, + QuoteFailure = 0x0000_0008, + DeviceBusy = 0x0000_0009, + DeviceFailure = 0x0000_000A, + InvaildRtmrIndex = 0x0000_000B, + UnsupportedAttKeyId = 0x0000_000C, + ErrorMax = 0x0000_000D, + } +} + +impl TdxAttestError { + pub fn __description(&self) -> &'static str { + match *self { + TdxAttestError::Success => "Success.", + TdxAttestError::Unexpected => "Unexpected error.", + TdxAttestError::InvalidParameter => "The parameter is incorrect.", + TdxAttestError::OutOfMemory => "Out of memory error.", + TdxAttestError::VSockFailure => "vsock related failure.", + TdxAttestError::ReportFailure => "Failed to get the TD Report.", + TdxAttestError::ExtendFailure => "Failed to extend rtmr.", + TdxAttestError::NotSupported => "Request feature is not supported.", + TdxAttestError::QuoteFailure => "Failed to get the TD Quote.", + TdxAttestError::DeviceBusy => "The device driver return busy.", + TdxAttestError::DeviceFailure => "Failed to acess tdx attest device.", + TdxAttestError::InvaildRtmrIndex => "Only supported RTMR index is 2 and 3.", + TdxAttestError::UnsupportedAttKeyId => { + "The platform Quoting infrastructure does not support any of the keys described in att_key_id_list." + } + TdxAttestError::ErrorMax => { + "Indicate max error." + } + } + } + + pub fn as_str(&self) -> &'static str { + match *self { + TdxAttestError::Success => "Success.", + TdxAttestError::Unexpected => "Unexpected", + TdxAttestError::InvalidParameter => "InvalidParameter", + TdxAttestError::OutOfMemory => "OutOfMemory", + TdxAttestError::VSockFailure => "VSockFailure", + TdxAttestError::ReportFailure => "ReportFailure", + TdxAttestError::ExtendFailure => "ExtendFailure", + TdxAttestError::NotSupported => "NotSupported", + TdxAttestError::QuoteFailure => "QuoteFailure", + TdxAttestError::DeviceBusy => "DeviceBusy", + TdxAttestError::DeviceFailure => "DeviceFailure", + TdxAttestError::InvaildRtmrIndex => "InvaildRtmrIndex", + TdxAttestError::UnsupportedAttKeyId => "UnsupportedAttKeyId", + TdxAttestError::ErrorMax => "ErrorMax", + } + } +} + +impl fmt::Display for TdxAttestError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.as_str()) + } +} + pub type SgxResult = result::Result; pub type SgxPceResult = result::Result; pub type SgxQcnlResult = result::Result; pub type SgxQuote3Result = result::Result; +pub type SgxTdxAttestResult = result::Result; pub type OsError = i32; pub type OsResult = result::Result; diff --git a/sgx_types/src/function.rs b/sgx_types/src/function.rs index 83d159161..bd91e3ab6 100644 --- a/sgx_types/src/function.rs +++ b/sgx_types/src/function.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -use crate::error::{PceError, QcnlError, Quote3Error, SgxStatus}; +use crate::error::{PceError, QcnlError, Quote3Error, SgxStatus, TdxAttestError}; use crate::metadata::MetaData; use crate::types::*; @@ -306,10 +306,19 @@ extern "C" { fmspc: *const u8, fmspc_size: u16, pck_ra: *const c_char, - pp_quote_collateral: *mut *mut CQlQveCollateral, + pp_quote_collateral: *mut *mut CTdxQlQvCollateral, + ) -> Quote3Error; + /* intel DCAP 1.17 */ + pub fn tdx_ql_get_quote_verification_collateral_with_params( + fmspc: *const u8, + fmspc_size: u16, + pck_ra: *const c_char, + custom_param: *const c_void, + custom_param_length: u16, + pp_quote_collateral: *mut *mut CTdxQlQvCollateral, ) -> Quote3Error; pub fn tdx_ql_free_quote_verification_collateral( - p_quote_collateral: *const CQlQveCollateral, + p_quote_collateral: *const CTdxQlQvCollateral, ) -> Quote3Error; pub fn sgx_ql_get_qve_identity( @@ -323,14 +332,20 @@ extern "C" { p_qve_identity_issuer_chain: *const c_char, ) -> Quote3Error; - /* intel DCAP 1.4 */ + /* intel DCAP 1.14 */ pub fn sgx_ql_get_root_ca_crl( pp_root_ca_crl: *mut *mut u8, p_root_ca_crl_size: *mut u16, ) -> Quote3Error; pub fn sgx_ql_free_root_ca_crl(p_root_ca_crl: *const uint8_t) -> Quote3Error; - /* intel DCAP 2.14 */ - pub fn sgx_ql_set_logging_callback(logger: QlLoggingCallbackFn) -> Quote3Error; + /* intel DCAP 1.17 */ + pub fn sgx_ql_set_logging_callback( + logger: QlLoggingCallbackFn, + loglevel: QlLogLevel, + ) -> Quote3Error; + pub fn sgx_qpl_clear_cache(cache_type: QplCacheType) -> Quote3Error; + pub fn sgx_qpl_global_init() -> Quote3Error; + pub fn sgx_qpl_global_cleanup() -> Quote3Error; } //#[link(name = "sgx_default_qcnl_wrapper")] @@ -397,7 +412,14 @@ extern "C" { pub fn sgx_qcnl_free_root_ca_crl(p_root_ca_crl: *const u8); /* intel DCAP 1.13 */ pub fn sgx_qcnl_get_api_version(p_major_ver: *mut u16, p_minor_ver: *mut u16) -> bool; - pub fn sgx_qcnl_set_logging_callback(logger: QlLoggingCallbackFn) -> QcnlError; + pub fn sgx_qcnl_set_logging_callback( + logger: QlLoggingCallbackFn, + loglevel: QlLogLevel, + ) -> QcnlError; + /* intel DCAP 1.17 */ + pub fn sgx_qcnl_clear_cache(cache_type: u32) -> QcnlError; + pub fn sgx_qcnl_global_init() -> QcnlError; + pub fn sgx_qcnl_global_cleanup() -> QcnlError; } //#[link(name = "dcap_quoteverify")] @@ -443,7 +465,7 @@ extern "C" { pub fn tdx_qv_verify_quote( p_quote: *const u8, quote_size: u32, - p_quote_collateral: *const CQlQveCollateral, + p_quote_collateral: *const CTdxQlQvCollateral, expiration_check_date: time_t, p_collateral_expiration_status: *mut u32, p_quote_verification_result: *mut QlQvResult, @@ -451,4 +473,65 @@ extern "C" { supplemental_data_size: u32, p_supplemental_data: *mut u8, ) -> Quote3Error; + + /* intel DCAP 1.15 */ + pub fn tee_qv_get_collateral( + p_quote: *const u8, + quote_size: u32, + pp_quote_collateral: *mut *mut u8, + p_collateral_size: *mut u32, + ) -> Quote3Error; + + pub fn tee_qv_free_collateral(p_quote_collateral: *const u8) -> Quote3Error; + pub fn tee_get_supplemental_data_version_and_size( + p_quote: *const u8, + quote_size: u32, + p_version: *mut u32, + p_data_size: *mut u32, + ) -> Quote3Error; + + pub fn tee_verify_quote( + p_quote: *const u8, + quote_size: u32, + p_quote_collateral: *const u8, + expiration_check_date: time_t, + p_collateral_expiration_status: *mut u32, + p_quote_verification_result: *mut QlQvResult, + p_qve_report_info: *mut QlQeReportInfo, + p_supp_data_descriptor: *const CTeeSuppDataDescriptor, + ) -> Quote3Error; + /* intel DCAP 1.16 */ + pub fn tee_get_fmspc_from_quote( + p_quote: *const u8, + quote_size: u32, + p_fmspc_from_quote: *mut u8, + fmspc_from_quote_size: u32, + ) -> Quote3Error; +} + +/* intel DCAP 1.15 */ +//#[link(name = "libtdx_attest")] +extern "C" { + // + // tdx_attes.h + // + pub fn tdx_att_get_quote( + p_tdx_report_data: *const TdxReportData, + att_key_id_list: *const TdxUuid, + list_size: u32, + p_att_key_id: *mut TdxUuid, + pp_quote: *mut *mut u8, + p_quote_size: *mut u32, + flags: u32, + ) -> TdxAttestError; + pub fn tdx_att_free_quote(p_quote: *const u8) -> TdxAttestError; + pub fn tdx_att_get_report( + p_tdx_report_data: *const TdxReportData, + p_tdx_report: *mut TdxReport, + ) -> TdxAttestError; + pub fn tdx_att_extend(p_rtmr_event: *const TdxRtmrEvent) -> TdxAttestError; + pub fn tdx_att_get_supported_att_key_ids( + p_att_key_id_list: *mut TdxUuid, + p_list_size: *mut u32, + ) -> TdxAttestError; } diff --git a/sgx_types/src/types/dcap.rs b/sgx_types/src/types/dcap.rs index b76168ba1..5b68f2b54 100644 --- a/sgx_types/src/types/dcap.rs +++ b/sgx_types/src/types/dcap.rs @@ -159,6 +159,17 @@ impl_enum! { } } +/* intel DCAP 1.17 */ +impl_enum! { + #[repr(u32)] + #[derive(Clone, Copy, Debug, Eq, PartialEq)] + pub enum QplCacheType { + Certificate = 1, + Collateral = 2, + MultiCerts = 4, + } +} + impl_enum! { #[repr(u32)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] @@ -375,10 +386,11 @@ impl_enum! { } // -// qve_header.h +// sgx_qve_header.h // pub const ROOT_KEY_ID_SIZE: usize = 48; pub const PLATFORM_INSTANCE_ID_SIZE: usize = 16; +pub const MAX_SA_LIST_SIZE: usize = 160; /* intel DCAP 1.7 */ impl_enum! { @@ -417,11 +429,13 @@ impl_copy_clone! { pub dynamic_platform: PckCertFlag, pub cached_keys: PckCertFlag, pub smt_enabled: PckCertFlag, + /* intel DCAP 1.15 */ + pub sa_list: [c_char; MAX_SA_LIST_SIZE] } } impl_struct_default! { - QlQvSupplemental; //176 + QlQvSupplemental; //336 } impl_asref_array! { @@ -432,6 +446,14 @@ impl_struct_ContiguousMemory! { QlQvSupplemental; } +/* intel DCAP 1.15 */ +#[repr(C)] +pub struct CTeeSuppDataDescriptor { + pub major_version: u16, + pub data_size: u32, + pub p_data: *mut u8, +} + impl_enum! { #[repr(u32)] #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)] diff --git a/sgx_types/src/types/tdx.rs b/sgx_types/src/types/tdx.rs index e57c48142..f3b7dba0c 100644 --- a/sgx_types/src/types/tdx.rs +++ b/sgx_types/src/types/tdx.rs @@ -20,6 +20,9 @@ use super::*; use core::mem; use core::slice; +/* intel DCAP 1.17 */ +pub type CTdxQlQvCollateral = CQlQveCollateral; + /* intel DCAP 1.14 */ // // sgx_quote_4.h @@ -203,3 +206,112 @@ impl Quote4 { ) } } + +/* intel DCAP 1.15 */ +// +// tdx_attes.h +// +pub const TDX_UUID_SIZE: usize = 16; +pub const TDX_REPORT_DATA_SIZE: usize = 64; +pub const TDX_REPORT_SIZE: usize = 1024; + +impl_struct! { + #[repr(C)] + #[derive(Debug, Eq, PartialEq)] + pub struct TdxUuid { + pub d: [u8; TDX_UUID_SIZE], + } +} + +impl_asref_array! { + TdxUuid; +} +impl_asmut_array! { + TdxUuid; +} +impl_from_array! { + TdxUuid; +} +impl_unsafe_marker_for! { + BytewiseEquality, + TdxUuid +} + +impl_copy_clone! { + #[repr(C)] + #[derive(Debug)] + pub struct TdxReportData { + pub d: [u8; TDX_REPORT_DATA_SIZE], + } +} +impl_copy_clone! { + #[repr(C)] + #[derive(Debug)] + pub struct TdxReport { + pub d: [u8; TDX_REPORT_SIZE], + } +} + +impl_struct_default! { + TdxReportData; //64 + TdxReport; //1024 +} + +impl_struct_ContiguousMemory! { + TdxReportData; + TdxReport; +} + +impl_asref_array! { + TdxReportData; + TdxReport; +} + +impl_asmut_array! { + TdxReportData; +} +impl_from_array! { + TdxReportData; +} + +impl_unsafe_marker_for! { + BytewiseEquality, + TdxReportData +} + +#[derive(Clone, Copy, Debug)] +#[repr(C, packed)] +pub struct TdxRtmrEvent { + pub version: u32, + pub rtmr_index: u64, + pub extend_data: [u8; 48], + pub event_type: u32, + pub event_data_size: u32, + pub event_data: [u8; 0], +} + +impl_struct_default! { + TdxRtmrEvent; //68 +} + +impl_struct_ContiguousMemory! { + TdxRtmrEvent; +} + +impl TdxRtmrEvent { + /// # Safety + pub unsafe fn as_slice_unchecked(&self) -> &[u8] { + slice::from_raw_parts( + self as *const _ as *const u8, + mem::size_of::() + self.event_data_size as usize, + ) + } + + /// # Safety + pub unsafe fn event_data_slice_unchecked(&self) -> &[u8] { + slice::from_raw_parts( + &self.event_data as *const _ as *const u8, + self.event_data_size as usize, + ) + } +} From ae7a48747b0cd4b985d06fdd22b8b9c5297e1ce6 Mon Sep 17 00:00:00 2001 From: volcano Date: Thu, 24 Aug 2023 19:44:45 +0800 Subject: [PATCH 03/34] Update dockerfile --- tools/docker/Dockerfile.centos8 | 14 +++++++------- tools/docker/Dockerfile.ubuntu18.04 | 14 +++++++------- tools/docker/Dockerfile.ubuntu20.04 | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tools/docker/Dockerfile.centos8 b/tools/docker/Dockerfile.centos8 index 2154df76f..1297649c4 100644 --- a/tools/docker/Dockerfile.centos8 +++ b/tools/docker/Dockerfile.centos8 @@ -71,13 +71,13 @@ RUN yum install epel-release -y && \ http://downloads.sourceforge.net/ltp/lcov-1.14-1.noarch.rpm && \ alternatives --set python /usr/bin/python2 -ENV SGX_SDK_RELEASE_VERSION 2.17 -ENV SGX_DCAP_RELEASE_VERSION 1.14 -ENV SGX_SDK_CODE_VERSION 2.17.1 -ENV SGX_DCAP_CODE_VERSION 1.14 -ENV SGX_SDK_BIN_VERSION 2.17.101.1 -ENV SGX_SDK_PKGS_VERSION 2.17.100.3 -ENV SGX_DCAP_PKGS_VERSION 1.14.100.3 +ENV SGX_SDK_RELEASE_VERSION 2.20 +ENV SGX_DCAP_RELEASE_VERSION 1.17 +ENV SGX_SDK_CODE_VERSION 2.20 +ENV SGX_DCAP_CODE_VERSION 1.17 +ENV SGX_SDK_BIN_VERSION 2.20.100.4 +ENV SGX_SDK_PKGS_VERSION 2.20.100.4 +ENV SGX_DCAP_PKGS_VERSION 1.17.100.4 ENV SGX_SDK_VERSION ${SGX_SDK_PKGS_VERSION} ENV SGX_DCAP_VERSION ${SGX_DCAP_PKGS_VERSION} ENV RUST_TOOLCHAIN nightly-2022-10-22 diff --git a/tools/docker/Dockerfile.ubuntu18.04 b/tools/docker/Dockerfile.ubuntu18.04 index 6d747d99f..4c22b1887 100644 --- a/tools/docker/Dockerfile.ubuntu18.04 +++ b/tools/docker/Dockerfile.ubuntu18.04 @@ -78,13 +78,13 @@ RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-i rm -rf /var/lib/apt/lists/* ENV CODENAME bionic -ENV SGX_SDK_RELEASE_VERSION 2.17 -ENV SGX_DCAP_RELEASE_VERSION 1.14 -ENV SGX_SDK_CODE_VERSION 2.17.1 -ENV SGX_DCAP_CODE_VERSION 1.14 -ENV SGX_SDK_BIN_VERSION 2.17.101.1 -ENV SGX_SDK_PKGS_VERSION 2.17.100.3 -ENV SGX_DCAP_PKGS_VERSION 1.14.100.3 +ENV SGX_SDK_RELEASE_VERSION 2.20 +ENV SGX_DCAP_RELEASE_VERSION 1.17 +ENV SGX_SDK_CODE_VERSION 2.20 +ENV SGX_DCAP_CODE_VERSION 1.17 +ENV SGX_SDK_BIN_VERSION 2.20.100.4 +ENV SGX_SDK_PKGS_VERSION 2.20.100.4 +ENV SGX_DCAP_PKGS_VERSION 1.17.100.4 ENV SGX_SDK_VERSION ${SGX_SDK_PKGS_VERSION}-bionic1 ENV SGX_DCAP_VERSION ${SGX_DCAP_PKGS_VERSION}-bionic1 ENV RUST_TOOLCHAIN nightly-2022-10-22 diff --git a/tools/docker/Dockerfile.ubuntu20.04 b/tools/docker/Dockerfile.ubuntu20.04 index 5ff63ff7f..91d0d28eb 100644 --- a/tools/docker/Dockerfile.ubuntu20.04 +++ b/tools/docker/Dockerfile.ubuntu20.04 @@ -77,13 +77,13 @@ RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-i rm -rf /var/lib/apt/lists/* ENV CODENAME focal -ENV SGX_SDK_RELEASE_VERSION 2.17 -ENV SGX_DCAP_RELEASE_VERSION 1.14 -ENV SGX_SDK_CODE_VERSION 2.17.1 -ENV SGX_DCAP_CODE_VERSION 1.14 -ENV SGX_SDK_BIN_VERSION 2.17.101.1 -ENV SGX_SDK_PKGS_VERSION 2.17.100.3 -ENV SGX_DCAP_PKGS_VERSION 1.14.100.3 +ENV SGX_SDK_RELEASE_VERSION 2.20 +ENV SGX_DCAP_RELEASE_VERSION 1.17 +ENV SGX_SDK_CODE_VERSION 2.20 +ENV SGX_DCAP_CODE_VERSION 1.17 +ENV SGX_SDK_BIN_VERSION 2.20.100.4 +ENV SGX_SDK_PKGS_VERSION 2.20.100.4 +ENV SGX_DCAP_PKGS_VERSION 1.17.100.4 ENV SGX_SDK_VERSION ${SGX_SDK_PKGS_VERSION}-focal1 ENV SGX_DCAP_VERSION ${SGX_DCAP_PKGS_VERSION}-focal1 ENV RUST_TOOLCHAIN nightly-2022-10-22 From 6f16f4a111b6bd55717be7bebbe13e822f1bfe5f Mon Sep 17 00:00:00 2001 From: volcano Date: Fri, 1 Sep 2023 15:18:12 +0800 Subject: [PATCH 04/34] Support intel-sgx-sdk 2.21 and DCAP 1.18 --- buildenv.mk | 4 + common/inc/sgx_report2.h | 3 + sgx_libc/sgx_tlibc_sys/tlibc/gen/sbrk.c | 7 + sgx_serialize/src/types.rs | 230 +++++++++++++++++++++--- sgx_trts/src/arch.rs | 80 ++++----- sgx_trts/src/edmm/epc.rs | 6 +- sgx_trts/src/inst/hw/inst.rs | 8 +- sgx_trts/src/inst/hyper/inst.rs | 8 +- sgx_trts/src/inst/hyper/mod.rs | 6 +- sgx_trts/src/inst/sim/inst.rs | 8 +- sgx_trts/src/inst/sim/mod.rs | 6 +- sgx_trts/src/se/report.rs | 22 ++- sgx_trts/src/version.rs | 2 +- sgx_types/src/types/report2.rs | 1 + sgx_types/src/types/tdx.rs | 101 ++++++++++- tools/docker/02_binutils.sh | 2 +- tools/docker/Dockerfile.centos8 | 15 +- tools/docker/Dockerfile.ubuntu18.04 | 15 +- tools/docker/Dockerfile.ubuntu20.04 | 15 +- tools/docker/Dockerfile.ubuntu22.04 | 118 ++++++++++++ 20 files changed, 542 insertions(+), 115 deletions(-) create mode 100644 tools/docker/Dockerfile.ubuntu22.04 diff --git a/buildenv.mk b/buildenv.mk index a2125f5a4..73974b6b0 100644 --- a/buildenv.mk +++ b/buildenv.mk @@ -67,6 +67,10 @@ else COMMON_FLAGS += -fstack-protector-strong endif +ifdef _TD_MIGRATION + COMMON_FLAGS += -D_TD_MIGRATION +endif + COMMON_FLAGS += -ffunction-sections -fdata-sections # turn on compiler warnings as much as possible diff --git a/common/inc/sgx_report2.h b/common/inc/sgx_report2.h index 14f764232..355bee8a9 100644 --- a/common/inc/sgx_report2.h +++ b/common/inc/sgx_report2.h @@ -36,6 +36,8 @@ #ifndef _SGX_REPORT2_H_ #define _SGX_REPORT2_H_ +#include + #define TEE_HASH_384_SIZE 48 /* SHA384 */ #define TEE_MAC_SIZE 32 /* Message SHA 256 HASH Code - 32 bytes */ @@ -67,6 +69,7 @@ typedef struct _tee_attributes_t #define TEE_REPORT2_TYPE 0x81 /* TEE Report Type2 */ #define TEE_REPORT2_SUBTYPE 0x0 /* SUBTYPE for Report Type2 is 0 */ #define TEE_REPORT2_VERSION 0x0 /* VERSION for Report Type2 is 0 */ +#define TEE_REPORT2_VERSION_SERVICETD 0x1 /* VERSION for Report Type2 which mr_servicetd is used */ typedef struct _tee_report_type_t { uint8_t type; /* Trusted Execution Environment(TEE) type: diff --git a/sgx_libc/sgx_tlibc_sys/tlibc/gen/sbrk.c b/sgx_libc/sgx_tlibc_sys/tlibc/gen/sbrk.c index 422d9781c..203714f09 100644 --- a/sgx_libc/sgx_tlibc_sys/tlibc/gen/sbrk.c +++ b/sgx_libc/sgx_tlibc_sys/tlibc/gen/sbrk.c @@ -41,10 +41,17 @@ SE_DECLSPEC_EXPORT size_t g_peak_heap_used = 0; /* Please be aware of: sbrk is not thread safe by default. */ #define RELRO_SECTION_NAME ".data.rel.ro" +#ifndef _TD_MIGRATION static void *heap_base __attribute__((section(RELRO_SECTION_NAME))) = NULL; static size_t heap_size __attribute__((section(RELRO_SECTION_NAME))) = 0; static int is_edmm_supported __attribute__((section(RELRO_SECTION_NAME))) = 0; static size_t heap_min_size __attribute__((section(RELRO_SECTION_NAME))) = 0; +#else +void *heap_base = NULL; +size_t heap_size = 0; +int is_edmm_supported = 0; +size_t heap_min_size = 0; +#endif unsigned int sgx_heap_init(void *_heap_base, size_t _heap_size, size_t _heap_min_size, int _is_edmm_supported) { diff --git a/sgx_serialize/src/types.rs b/sgx_serialize/src/types.rs index 9a4176162..35dc9006c 100644 --- a/sgx_serialize/src/types.rs +++ b/sgx_serialize/src/types.rs @@ -23,9 +23,9 @@ use sgx_types::types::{ }; use sgx_types::types::{ Attributes, AttributesFlags, ConfigId, CpuSvn, KeyId, KeyName, KeyPolicy, KeyRequest, - Measurement, MiscAttribute, MiscSelect, Report, Report2, Report2Body, Report2Mac, ReportBody, - ReportData, TargetInfo, TeeAttributes, TeeCpuSvn, TeeInfo, TeeMeasurement, TeeReportData, - TeeReportType, TeeTcbInfo, TeeTcbSvn, + Measurement, MiscAttribute, MiscSelect, Report, Report2, Report2Body, Report2BodyV15, + Report2Mac, ReportBody, ReportData, TargetInfo, TeeAttributes, TeeCpuSvn, TeeInfo, TeeInfoV15, + TeeMeasurement, TeeReportData, TeeReportType, TeeTcbInfo, TeeTcbInfoV15, TeeTcbSvn, }; use sgx_types::types::{BaseName, PsSecPropDesc, QuoteNonce, Spid}; use sgx_types::types::{Ec256PrivateKey, Ec256PublicKey, Ec256SharedKey, Ec256Signature}; @@ -1608,14 +1608,6 @@ impl Decodable for TeeInfo { impl Encodable for TeeTcbInfo { fn encode(&self, e: &mut S) -> Result<(), S::Error> { - // let TeeTcbInfo { - // valid: ref _valid, - // tee_tcb_svn: ref _tee_tcb_svn, - // mr_seam: ref _mr_seam, - // mr_seam_signer: ref _mr_seam_signer, - // attributes: ref _attributes, - // reserved: ref _reserved, - // } = *self; let _valid = unsafe { &*core::ptr::addr_of!(self.valid) }; let _tee_tcb_svn = unsafe { &*core::ptr::addr_of!(self.tee_tcb_svn) }; let _mr_seam = unsafe { &*core::ptr::addr_of!(self.mr_seam) }; @@ -1661,20 +1653,6 @@ impl Decodable for TeeTcbInfo { impl Encodable for Report2Body { fn encode(&self, e: &mut S) -> Result<(), S::Error> { - // let Report2Body { - // tee_tcb_svn: ref _tee_tcb_svn, - // mr_seam: ref _mr_seam, - // mrsigner_seam: ref _mrsigner_seam, - // seam_attributes: ref _seam_attributes, - // td_attributes: ref _td_attributes, - // xfam: ref _xfam, - // mr_td: ref _mr_td, - // mr_config_id: ref _mr_config_id, - // mr_owner: ref _mr_owner, - // mr_owner_config: ref _mr_owner_config, - // rt_mr: ref _rt_mr, - // report_data: ref _report_data, - // } = *self; let _tee_tcb_svn = unsafe { &*core::ptr::addr_of!(self.tee_tcb_svn) }; let _mr_seam = unsafe { &*core::ptr::addr_of!(self.mr_seam) }; let _mrsigner_seam = unsafe { &*core::ptr::addr_of!(self.mrsigner_seam) }; @@ -1753,3 +1731,205 @@ impl Decodable for Report2Body { }) } } + +impl Encodable for TeeInfoV15 { + fn encode(&self, e: &mut S) -> Result<(), S::Error> { + let TeeInfoV15 { + attributes: ref _attributes, + xfam: ref _xfam, + mr_td: ref _mr_td, + mr_config_id: ref _mr_config_id, + mr_owner: ref _mr_owner, + mr_owner_config: ref _mr_owner_config, + rt_mr: ref _rt_mr, + mr_servicetd: ref _mr_servicetd, + reserved: ref _reserved, + } = *self; + e.emit_struct("TeeInfoV15", 8usize, |e| -> _ { + e.emit_struct_field("attributes", 0usize, |e| -> _ { + Encodable::encode(&*_attributes, e) + })?; + e.emit_struct_field("xfam", 1usize, |e| -> _ { Encodable::encode(&*_xfam, e) })?; + e.emit_struct_field("mr_td", 2usize, |e| -> _ { Encodable::encode(&*_mr_td, e) })?; + e.emit_struct_field("mr_config_id", 3usize, |e| -> _ { + Encodable::encode(&*_mr_config_id, e) + })?; + e.emit_struct_field("mr_owner", 4usize, |e| -> _ { + Encodable::encode(&*_mr_owner, e) + })?; + e.emit_struct_field("mr_owner_config", 5usize, |e| -> _ { + Encodable::encode(&*_mr_owner_config, e) + })?; + e.emit_struct_field("rt_mr", 6usize, |e| -> _ { Encodable::encode(&*_rt_mr, e) })?; + e.emit_struct_field("mr_servicetd", 7usize, |e| -> _ { + Encodable::encode(&*_mr_servicetd, e) + })?; + e.emit_struct_field("reserved", 8usize, |e| -> _ { + Encodable::encode(&*_reserved, e) + }) + }) + } +} + +impl Decodable for TeeInfoV15 { + fn decode(d: &mut D) -> Result { + d.read_struct("TeeInfoV15", 8usize, |d| -> _ { + Ok(TeeInfoV15 { + attributes: d.read_struct_field("attributes", 0usize, Decodable::decode)?, + xfam: d.read_struct_field("xfam", 1usize, Decodable::decode)?, + mr_td: d.read_struct_field("mr_td", 2usize, Decodable::decode)?, + mr_config_id: d.read_struct_field("mr_config_id", 3usize, Decodable::decode)?, + mr_owner: d.read_struct_field("mr_owner", 4usize, Decodable::decode)?, + mr_owner_config: d.read_struct_field( + "mr_owner_config", + 5usize, + Decodable::decode, + )?, + rt_mr: d.read_struct_field("rt_mr", 6usize, Decodable::decode)?, + mr_servicetd: d.read_struct_field("mr_servicetd", 7usize, Decodable::decode)?, + reserved: d.read_struct_field("reserved", 8usize, Decodable::decode)?, + }) + }) + } +} + +impl Encodable for TeeTcbInfoV15 { + fn encode(&self, e: &mut S) -> Result<(), S::Error> { + let _valid = unsafe { &*core::ptr::addr_of!(self.valid) }; + let _tee_tcb_svn = unsafe { &*core::ptr::addr_of!(self.tee_tcb_svn) }; + let _mr_seam = unsafe { &*core::ptr::addr_of!(self.mr_seam) }; + let _mr_seam_signer = unsafe { &*core::ptr::addr_of!(self.mr_seam_signer) }; + let _attributes = unsafe { &*core::ptr::addr_of!(self.attributes) }; + let _tee_tcb_svn2 = unsafe { &*core::ptr::addr_of!(self.tee_tcb_svn2) }; + let _reserved = unsafe { &*core::ptr::addr_of!(self.reserved) }; + + e.emit_struct("TeeTcbInfoV15", 6usize, |e| -> _ { + e.emit_struct_field("valid", 0usize, |e| -> _ { Encodable::encode(&*_valid, e) })?; + e.emit_struct_field("tee_tcb_svn", 1usize, |e| -> _ { + Encodable::encode(&*_tee_tcb_svn, e) + })?; + e.emit_struct_field("mr_seam", 2usize, |e| -> _ { + Encodable::encode(&*_mr_seam, e) + })?; + e.emit_struct_field("mr_seam_signer", 3usize, |e| -> _ { + Encodable::encode(&*_mr_seam_signer, e) + })?; + e.emit_struct_field("attributes", 4usize, |e| -> _ { + Encodable::encode(&*_attributes, e) + })?; + e.emit_struct_field("tee_tcb_svn2", 5usize, |e| -> _ { + Encodable::encode(&*_tee_tcb_svn2, e) + })?; + e.emit_struct_field("reserved", 6usize, |e| -> _ { + Encodable::encode(&*_reserved, e) + }) + }) + } +} + +impl Decodable for TeeTcbInfoV15 { + fn decode(d: &mut D) -> Result { + d.read_struct("TeeTcbInfoV15", 8usize, |d| -> _ { + Ok(TeeTcbInfoV15 { + valid: d.read_struct_field("valid", 0usize, Decodable::decode)?, + tee_tcb_svn: d.read_struct_field("tee_tcb_svn", 1usize, Decodable::decode)?, + mr_seam: d.read_struct_field("mr_seam", 2usize, Decodable::decode)?, + mr_seam_signer: d.read_struct_field("mr_seam_signer", 3usize, Decodable::decode)?, + attributes: d.read_struct_field("attributes", 4usize, Decodable::decode)?, + tee_tcb_svn2: d.read_struct_field("tee_tcb_svn2", 5usize, Decodable::decode)?, + reserved: d.read_struct_field("reserved", 6usize, Decodable::decode)?, + }) + }) + } +} + +impl Encodable for Report2BodyV15 { + fn encode(&self, e: &mut S) -> Result<(), S::Error> { + let _tee_tcb_svn = unsafe { &*core::ptr::addr_of!(self.tee_tcb_svn) }; + let _mr_seam = unsafe { &*core::ptr::addr_of!(self.mr_seam) }; + let _mrsigner_seam = unsafe { &*core::ptr::addr_of!(self.mrsigner_seam) }; + let _seam_attributes = unsafe { &*core::ptr::addr_of!(self.seam_attributes) }; + let _td_attributes = unsafe { &*core::ptr::addr_of!(self.td_attributes) }; + let _xfam = unsafe { &*core::ptr::addr_of!(self.xfam) }; + let _mr_td = unsafe { &*core::ptr::addr_of!(self.mr_td) }; + let _mr_config_id = unsafe { &*core::ptr::addr_of!(self.mr_config_id) }; + let _mr_owner = unsafe { &*core::ptr::addr_of!(self.mr_owner) }; + let _mr_owner_config = unsafe { &*core::ptr::addr_of!(self.mr_owner_config) }; + let _rt_mr = unsafe { &*core::ptr::addr_of!(self.rt_mr) }; + let _report_data = unsafe { &*core::ptr::addr_of!(self.report_data) }; + let _tee_tcb_svn2 = unsafe { &*core::ptr::addr_of!(self.tee_tcb_svn2) }; + let _mr_servicetd = unsafe { &*core::ptr::addr_of!(self.mr_servicetd) }; + + e.emit_struct("Report2BodyV15", 12usize, |e| -> _ { + e.emit_struct_field("tee_tcb_svn", 0usize, |e| -> _ { + Encodable::encode(&*_tee_tcb_svn, e) + })?; + e.emit_struct_field("mr_seam", 1usize, |e| -> _ { + Encodable::encode(&*_mr_seam, e) + })?; + e.emit_struct_field("mrsigner_seam", 2usize, |e| -> _ { + Encodable::encode(&*_mrsigner_seam, e) + })?; + e.emit_struct_field("seam_attributes", 3usize, |e| -> _ { + Encodable::encode(&*_seam_attributes, e) + })?; + e.emit_struct_field("td_attributes", 4usize, |e| -> _ { + Encodable::encode(&*_td_attributes, e) + })?; + e.emit_struct_field("xfam", 5usize, |e| -> _ { Encodable::encode(&*_xfam, e) })?; + e.emit_struct_field("mr_td", 6usize, |e| -> _ { Encodable::encode(&*_mr_td, e) })?; + e.emit_struct_field("mr_config_id", 7usize, |e| -> _ { + Encodable::encode(&*_mr_config_id, e) + })?; + e.emit_struct_field("mr_owner", 8usize, |e| -> _ { + Encodable::encode(&*_mr_owner, e) + })?; + e.emit_struct_field("mr_owner_config", 9usize, |e| -> _ { + Encodable::encode(&*_mr_owner_config, e) + })?; + e.emit_struct_field("rt_mr", 10usize, |e| -> _ { + Encodable::encode(&*_rt_mr, e) + })?; + e.emit_struct_field("report_data", 11usize, |e| -> _ { + Encodable::encode(&*_report_data, e) + })?; + e.emit_struct_field("tee_tcb_svn2", 12usize, |e| -> _ { + Encodable::encode(&*_tee_tcb_svn2, e) + })?; + e.emit_struct_field("mr_servicetd", 13usize, |e| -> _ { + Encodable::encode(&*_mr_servicetd, e) + }) + }) + } +} + +impl Decodable for Report2BodyV15 { + fn decode(d: &mut D) -> Result { + d.read_struct("Report2BodyV15", 8usize, |d| -> _ { + Ok(Report2BodyV15 { + tee_tcb_svn: d.read_struct_field("tee_tcb_svn", 0usize, Decodable::decode)?, + mr_seam: d.read_struct_field("mr_seam", 1usize, Decodable::decode)?, + mrsigner_seam: d.read_struct_field("mrsigner_seam", 2usize, Decodable::decode)?, + seam_attributes: d.read_struct_field( + "seam_attributes", + 3usize, + Decodable::decode, + )?, + td_attributes: d.read_struct_field("td_attributes", 4usize, Decodable::decode)?, + xfam: d.read_struct_field("xfam", 5usize, Decodable::decode)?, + mr_td: d.read_struct_field("mr_td", 6usize, Decodable::decode)?, + mr_config_id: d.read_struct_field("mr_config_id", 7usize, Decodable::decode)?, + mr_owner: d.read_struct_field("mr_owner", 8usize, Decodable::decode)?, + mr_owner_config: d.read_struct_field( + "mr_owner_config", + 9usize, + Decodable::decode, + )?, + rt_mr: d.read_struct_field("rt_mr", 10usize, Decodable::decode)?, + report_data: d.read_struct_field("report_data", 11usize, Decodable::decode)?, + tee_tcb_svn2: d.read_struct_field("tee_tcb_svn2", 12usize, Decodable::decode)?, + mr_servicetd: d.read_struct_field("mr_servicetd", 13usize, Decodable::decode)?, + }) + }) + } +} diff --git a/sgx_trts/src/arch.rs b/sgx_trts/src/arch.rs index 4764f1fe1..d36fb09a9 100644 --- a/sgx_trts/src/arch.rs +++ b/sgx_trts/src/arch.rs @@ -17,7 +17,7 @@ #![allow(clippy::enum_variant_names)] -use crate::edmm::{PageInfo, PageType}; +use crate::edmm::{self, PageType}; use crate::tcs::tc; use crate::version::*; use crate::xsave; @@ -685,7 +685,7 @@ impl ExitInfo { impl_bitflags! { #[repr(C)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] - pub struct SecinfoFlags: u64 { + pub struct SecInfoFlags: u64 { const R = 0b0000_0000_0000_0001; const W = 0b0000_0000_0000_0010; const X = 0b0000_0000_0000_0100; @@ -704,9 +704,9 @@ impl_bitflags! { } } -impl SecinfoFlags { +impl SecInfoFlags { pub fn page_type(&self) -> u8 { - (((*self & SecinfoFlags::PT_MASK).bits()) >> 8) as u8 + (((*self & SecInfoFlags::PT_MASK).bits()) >> 8) as u8 } pub fn page_type_mut(&mut self) -> &mut u8 { @@ -717,102 +717,102 @@ impl SecinfoFlags { } } -impl From for SecinfoFlags { - fn from(data: PageType) -> SecinfoFlags { - SecinfoFlags::from_bits_truncate((data as u64) << 8) +impl From for SecInfoFlags { + fn from(data: PageType) -> SecInfoFlags { + SecInfoFlags::from_bits_truncate((data as u64) << 8) } } -impl From for SecinfoFlags { - fn from(data: PageInfo) -> SecinfoFlags { +impl From for SecInfoFlags { + fn from(data: edmm::PageInfo) -> SecInfoFlags { let typ = data.typ as u64; let flags = data.flags.bits() as u64; - SecinfoFlags::from_bits_truncate((typ << 8) | flags) + SecInfoFlags::from_bits_truncate((typ << 8) | flags) } } #[repr(C, align(64))] #[derive(Clone, Copy)] -pub struct Secinfo { - pub flags: SecinfoFlags, +pub struct SecInfo { + pub flags: SecInfoFlags, pub _reserved1: [u8; 56], } -impl fmt::Debug for Secinfo { +impl fmt::Debug for SecInfo { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt.debug_struct("Secinfo") + fmt.debug_struct("SecInfo") .field("flags", &self.flags.bits()) .finish() } } -impl Secinfo { - pub fn new(flags: SecinfoFlags) -> Secinfo { - Secinfo { +impl SecInfo { + pub fn new(flags: SecInfoFlags) -> SecInfo { + SecInfo { flags, _reserved1: [0_u8; 56], } } } -impl Default for Secinfo { - fn default() -> Secinfo { - Secinfo { - flags: SecinfoFlags::empty(), +impl Default for SecInfo { + fn default() -> SecInfo { + SecInfo { + flags: SecInfoFlags::empty(), _reserved1: [0_u8; 56], } } } -impl Secinfo { - pub const ALIGN_SIZE: usize = mem::size_of::(); +impl SecInfo { + pub const ALIGN_SIZE: usize = mem::size_of::(); } -impl AsRef<[u8; Secinfo::ALIGN_SIZE]> for Secinfo { - fn as_ref(&self) -> &[u8; Secinfo::ALIGN_SIZE] { +impl AsRef<[u8; SecInfo::ALIGN_SIZE]> for SecInfo { + fn as_ref(&self) -> &[u8; SecInfo::ALIGN_SIZE] { unsafe { &*(self as *const _ as *const _) } } } -impl AsRef> for Secinfo { - fn as_ref(&self) -> &Align64<[u8; Secinfo::ALIGN_SIZE]> { +impl AsRef> for SecInfo { + fn as_ref(&self) -> &Align64<[u8; SecInfo::ALIGN_SIZE]> { unsafe { &*(self as *const _ as *const _) } } } -impl From for Secinfo { - fn from(flags: SecinfoFlags) -> Secinfo { - Secinfo::new(flags) +impl From for SecInfo { + fn from(flags: SecInfoFlags) -> SecInfo { + SecInfo::new(flags) } } -impl From for Secinfo { - fn from(data: PageInfo) -> Secinfo { - Secinfo::from(SecinfoFlags::from(data)) +impl From for SecInfo { + fn from(data: edmm::PageInfo) -> SecInfo { + SecInfo::from(SecInfoFlags::from(data)) } } #[repr(C, align(32))] #[derive(Clone, Copy, Debug)] -pub struct Pageinfo { +pub struct PageInfo { pub linaddr: u64, pub srcpage: u64, pub secinfo: u64, pub secs: u64, } -impl Pageinfo { - pub const ALIGN_SIZE: usize = mem::size_of::(); +impl PageInfo { + pub const ALIGN_SIZE: usize = mem::size_of::(); } -impl AsRef<[u8; Pageinfo::ALIGN_SIZE]> for Pageinfo { - fn as_ref(&self) -> &[u8; Pageinfo::ALIGN_SIZE] { +impl AsRef<[u8; PageInfo::ALIGN_SIZE]> for PageInfo { + fn as_ref(&self) -> &[u8; PageInfo::ALIGN_SIZE] { unsafe { &*(self as *const _ as *const _) } } } -impl AsRef> for Pageinfo { - fn as_ref(&self) -> &Align32<[u8; Pageinfo::ALIGN_SIZE]> { +impl AsRef> for PageInfo { + fn as_ref(&self) -> &Align32<[u8; PageInfo::ALIGN_SIZE]> { unsafe { &*(self as *const _ as *const _) } } } diff --git a/sgx_trts/src/edmm/epc.rs b/sgx_trts/src/edmm/epc.rs index 446ecec8d..05c966ad1 100644 --- a/sgx_trts/src/edmm/epc.rs +++ b/sgx_trts/src/edmm/epc.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -use crate::arch::{Secinfo, SE_PAGE_SHIFT, SE_PAGE_SIZE}; +use crate::arch::{SecInfo, SE_PAGE_SHIFT, SE_PAGE_SIZE}; use crate::enclave::is_within_enclave; use crate::inst::EncluInst; use core::num::NonZeroUsize; @@ -204,12 +204,12 @@ impl Page { } pub fn accept(&self) -> SgxResult { - let secinfo: Secinfo = self.info.into(); + let secinfo: SecInfo = self.info.into(); EncluInst::eaccept(&secinfo, self.addr).map_err(|_| SgxStatus::Unexpected) } pub fn modpe(&self) -> SgxResult { - let secinfo: Secinfo = self.info.into(); + let secinfo: SecInfo = self.info.into(); EncluInst::emodpe(&secinfo, self.addr).map_err(|_| SgxStatus::Unexpected) } } diff --git a/sgx_trts/src/inst/hw/inst.rs b/sgx_trts/src/inst/hw/inst.rs index 497ea05db..c97a5a2c8 100644 --- a/sgx_trts/src/inst/hw/inst.rs +++ b/sgx_trts/src/inst/hw/inst.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -use crate::arch::{Enclu, Secinfo}; +use crate::arch::{Enclu, SecInfo}; use crate::se::{ AlignKey, AlignKeyRequest, AlignReport, AlignReport2Mac, AlignReportData, AlignTargetInfo, }; @@ -75,7 +75,7 @@ impl EncluInst { } } - pub fn eaccept(info: &Secinfo, addr: usize) -> Result<(), u32> { + pub fn eaccept(info: &SecInfo, addr: usize) -> Result<(), u32> { unsafe { let error; asm!( @@ -94,7 +94,7 @@ impl EncluInst { } } - pub fn eacceptcopy(info: &Secinfo, addr: usize, source: usize) -> Result<(), u32> { + pub fn eacceptcopy(info: &SecInfo, addr: usize, source: usize) -> Result<(), u32> { unsafe { let error; asm!( @@ -114,7 +114,7 @@ impl EncluInst { } } - pub fn emodpe(info: &Secinfo, addr: usize) -> Result<(), u32> { + pub fn emodpe(info: &SecInfo, addr: usize) -> Result<(), u32> { unsafe { asm!( "xchg rbx, {0}", diff --git a/sgx_trts/src/inst/hyper/inst.rs b/sgx_trts/src/inst/hyper/inst.rs index fcf8a689c..b7b97f21b 100644 --- a/sgx_trts/src/inst/hyper/inst.rs +++ b/sgx_trts/src/inst/hyper/inst.rs @@ -17,7 +17,7 @@ #![allow(clippy::enum_variant_names)] -use crate::arch::Secinfo; +use crate::arch::SecInfo; use crate::inst::INVALID_LEAF; use crate::se::{ AlignKey, AlignKeyRequest, AlignReport, AlignReport2Mac, AlignReportData, AlignTargetInfo, @@ -93,17 +93,17 @@ impl EncluInst { } #[inline] - pub fn eaccept(_info: &Secinfo, _addr: usize) -> Result<(), u32> { + pub fn eaccept(_info: &SecInfo, _addr: usize) -> Result<(), u32> { Ok(()) } #[inline] - pub fn eacceptcopy(_info: &Secinfo, _addr: usize, _source: usize) -> Result<(), u32> { + pub fn eacceptcopy(_info: &SecInfo, _addr: usize, _source: usize) -> Result<(), u32> { Ok(()) } #[inline] - pub fn emodpe(_info: &Secinfo, _addr: usize) -> Result<(), u32> { + pub fn emodpe(_info: &SecInfo, _addr: usize) -> Result<(), u32> { Ok(()) } } diff --git a/sgx_trts/src/inst/hyper/mod.rs b/sgx_trts/src/inst/hyper/mod.rs index 00989896e..9d638b5f9 100644 --- a/sgx_trts/src/inst/hyper/mod.rs +++ b/sgx_trts/src/inst/hyper/mod.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -use crate::arch::{Enclu, Secinfo}; +use crate::arch::{Enclu, SecInfo}; use crate::call::MsbufInfo; use crate::error::abort; use crate::fence::lfence; @@ -63,11 +63,11 @@ pub unsafe extern "C" fn se3( } Err(e) => e as usize, }, - Enclu::EAccept => match EncluInst::eaccept(&*(rbx as *const Secinfo), rcx) { + Enclu::EAccept => match EncluInst::eaccept(&*(rbx as *const SecInfo), rcx) { Ok(_) => 0, Err(e) => e as usize, }, - Enclu::EModpe => match EncluInst::emodpe(&*(rbx as *const Secinfo), rcx) { + Enclu::EModpe => match EncluInst::emodpe(&*(rbx as *const SecInfo), rcx) { Ok(_) => 0, Err(e) => e as usize, }, diff --git a/sgx_trts/src/inst/sim/inst.rs b/sgx_trts/src/inst/sim/inst.rs index 30af1fe9e..93287cd8f 100644 --- a/sgx_trts/src/inst/sim/inst.rs +++ b/sgx_trts/src/inst/sim/inst.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -use crate::arch::{Secinfo, Tcs}; +use crate::arch::{SecInfo, Tcs}; use crate::enclave::EnclaveRange; use crate::error::abort as gp; use crate::inst::sim::derive::{self, DeriveData, SeOwnerEpoch}; @@ -404,17 +404,17 @@ impl EncluInst { } #[inline] - pub fn eaccept(_info: &Secinfo, _addr: usize) -> Result<(), u32> { + pub fn eaccept(_info: &SecInfo, _addr: usize) -> Result<(), u32> { Ok(()) } #[inline] - pub fn eacceptcopy(_info: &Secinfo, _addr: usize, _source: usize) -> Result<(), u32> { + pub fn eacceptcopy(_info: &SecInfo, _addr: usize, _source: usize) -> Result<(), u32> { Ok(()) } #[inline] - pub fn emodpe(_info: &Secinfo, _addr: usize) -> Result<(), u32> { + pub fn emodpe(_info: &SecInfo, _addr: usize) -> Result<(), u32> { Ok(()) } diff --git a/sgx_trts/src/inst/sim/mod.rs b/sgx_trts/src/inst/sim/mod.rs index e89942b10..5d047a838 100644 --- a/sgx_trts/src/inst/sim/mod.rs +++ b/sgx_trts/src/inst/sim/mod.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -use crate::arch::{Enclu, Secinfo, Secs, Tcs}; +use crate::arch::{Enclu, SecInfo, Secs, Tcs}; use crate::error::abort; use crate::se::{AlignKey, AlignKeyRequest, AlignReport, AlignReportData, AlignTargetInfo}; use core::convert::TryFrom; @@ -66,11 +66,11 @@ pub unsafe extern "C" fn se3( } Err(e) => e as usize, }, - Enclu::EAccept => match EncluInst::eaccept(&*(rbx as *const Secinfo), rcx) { + Enclu::EAccept => match EncluInst::eaccept(&*(rbx as *const SecInfo), rcx) { Ok(_) => 0, Err(e) => e as usize, }, - Enclu::EModpe => match EncluInst::emodpe(&*(rbx as *const Secinfo), rcx) { + Enclu::EModpe => match EncluInst::emodpe(&*(rbx as *const SecInfo), rcx) { Ok(_) => 0, Err(e) => e as usize, }, diff --git a/sgx_trts/src/se/report.rs b/sgx_trts/src/se/report.rs index 04b3f5fd9..2f8079496 100644 --- a/sgx_trts/src/se/report.rs +++ b/sgx_trts/src/se/report.rs @@ -31,8 +31,10 @@ use sgx_types::types::{ }; use sgx_types::types::{ CONFIGID_SIZE, CPUSVN_SIZE, HASH_SIZE, ISVEXT_PROD_ID_SIZE, ISV_FAMILY_ID_SIZE, KEYID_SIZE, - MAC_SIZE, REPORT_BODY_RESERVED1_BYTES, REPORT_BODY_RESERVED2_BYTES, - REPORT_BODY_RESERVED3_BYTES, REPORT_BODY_RESERVED4_BYTES, REPORT_DATA_SIZE, + MAC_SIZE, REPORT2_MAC_RESERVED1_BYTES, REPORT2_MAC_RESERVED2_BYTES, + REPORT_BODY_RESERVED1_BYTES, REPORT_BODY_RESERVED2_BYTES, REPORT_BODY_RESERVED3_BYTES, + REPORT_BODY_RESERVED4_BYTES, REPORT_DATA_SIZE, TEE_REPORT2_SUBTYPE, TEE_REPORT2_TYPE, + TEE_REPORT2_VERSION, TEE_REPORT2_VERSION_SERVICETD, }; #[repr(C, align(128))] @@ -149,6 +151,22 @@ impl AlignReport { impl AlignReport2Mac { pub fn verify(&self) -> SgxResult { ensure!(self.is_enclave_range(), SgxStatus::InvalidParameter); + ensure!( + self.0.report_type.report_type == TEE_REPORT2_TYPE, + SgxStatus::InvalidParameter + ); + ensure!( + self.0.report_type.subtype == TEE_REPORT2_SUBTYPE + && (self.0.report_type.version == TEE_REPORT2_VERSION + || self.0.report_type.version == TEE_REPORT2_VERSION_SERVICETD), + SgxStatus::InvalidParameter + ); + ensure!( + self.0.report_type.reserved == 0 + && self.0.reserved1 == [0; REPORT2_MAC_RESERVED1_BYTES] + && self.0.reserved2 == [0; REPORT2_MAC_RESERVED2_BYTES], + SgxStatus::InvalidParameter + ); EncluInst::everify_report2(self).map_err(|e| match e { inst::INVALID_REPORTMACSTRUCT => SgxStatus::MacMismatch, diff --git a/sgx_trts/src/version.rs b/sgx_trts/src/version.rs index 93bb9598c..15a378441 100644 --- a/sgx_trts/src/version.rs +++ b/sgx_trts/src/version.rs @@ -16,6 +16,6 @@ // under the License.. pub const MAJOR_VERSION: usize = 2; -pub const MINOR_VERSION: usize = 20; +pub const MINOR_VERSION: usize = 21; pub const REVISION_VERSION: usize = 100; pub const VERSION_UINT: usize = (MAJOR_VERSION << 32) | (MINOR_VERSION << 16) | REVISION_VERSION; diff --git a/sgx_types/src/types/report2.rs b/sgx_types/src/types/report2.rs index 7f032d4e0..e27af19ff 100644 --- a/sgx_types/src/types/report2.rs +++ b/sgx_types/src/types/report2.rs @@ -107,6 +107,7 @@ pub const LEGACY_REPORT_TYPE: u8 = 0x0; // SGX Legacy Report Type pub const TEE_REPORT2_TYPE: u8 = 0x81; // TEE Report Type2 pub const TEE_REPORT2_SUBTYPE: u8 = 0x0; // SUBTYPE for Report Type2 is 0 pub const TEE_REPORT2_VERSION: u8 = 0x0; // VERSION for Report Type2 is 0 +pub const TEE_REPORT2_VERSION_SERVICETD: u8 = 0x1; // VERSION for Report Type2 which mr_servicetd is used impl_struct! { #[repr(C)] diff --git a/sgx_types/src/types/tdx.rs b/sgx_types/src/types/tdx.rs index f3b7dba0c..d68dff8bd 100644 --- a/sgx_types/src/types/tdx.rs +++ b/sgx_types/src/types/tdx.rs @@ -51,8 +51,8 @@ impl_unsafe_marker_for! { TeeTcbSvn } -pub const TD_INFO_RESERVED_BYTES: usize = 112; -pub const TD_TEE_TCB_INFO_RESERVED_BYTES: usize = 111; +pub const TD_INFO_RESERVED_BYTES_V1: usize = 112; +pub const TD_TEE_TCB_INFO_RESERVED_BYTES_V1: usize = 111; #[derive(Clone, Copy, Debug)] #[repr(C)] @@ -64,7 +64,7 @@ pub struct TeeInfo { pub mr_owner: TeeMeasurement, pub mr_owner_config: TeeMeasurement, pub rt_mr: [TeeMeasurement; 4], - pub reserved: [u8; TD_INFO_RESERVED_BYTES], + pub reserved: [u8; TD_INFO_RESERVED_BYTES_V1], } #[derive(Clone, Copy, Debug)] @@ -75,7 +75,7 @@ pub struct TeeTcbInfo { pub mr_seam: TeeMeasurement, pub mr_seam_signer: TeeMeasurement, pub attributes: TeeAttributes, - pub reserved: [u8; TD_TEE_TCB_INFO_RESERVED_BYTES], + pub reserved: [u8; TD_TEE_TCB_INFO_RESERVED_BYTES_V1], } #[derive(Clone, Copy, Debug)] @@ -144,6 +144,7 @@ impl_struct_ContiguousMemory! { TeeTcbInfo; QeReportCertificationData; EcdsaSigDataV4; + Quote4Header; Quote4; } @@ -207,6 +208,98 @@ impl Quote4 { } } +/* intel DCAP 1.18 */ +// +// sgx_quote_5.h +// + +pub const TD_INFO_RESERVED_BYTES_V15: usize = 64; +pub const TD_TEE_TCB_INFO_RESERVED_BYTES_V15: usize = 95; + +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct TeeInfoV15 { + pub attributes: TeeAttributes, + pub xfam: TeeAttributes, + pub mr_td: TeeMeasurement, + pub mr_config_id: TeeMeasurement, + pub mr_owner: TeeMeasurement, + pub mr_owner_config: TeeMeasurement, + pub rt_mr: [TeeMeasurement; 4], + pub mr_servicetd: TeeMeasurement, + pub reserved: [u8; TD_INFO_RESERVED_BYTES_V15], +} + +#[derive(Clone, Copy, Debug)] +#[repr(C, packed)] +pub struct TeeTcbInfoV15 { + pub valid: [u8; 8], + pub tee_tcb_svn: TeeTcbSvn, + pub mr_seam: TeeMeasurement, + pub mr_seam_signer: TeeMeasurement, + pub attributes: TeeAttributes, + pub tee_tcb_svn2: TeeTcbSvn, + pub reserved: [u8; TD_TEE_TCB_INFO_RESERVED_BYTES_V15], +} + +pub type Quote5Header = Quote4Header; + +#[derive(Clone, Copy, Debug, Default)] +#[repr(C, packed)] +pub struct Report2BodyV15 { + pub tee_tcb_svn: TeeTcbSvn, + pub mr_seam: TeeMeasurement, + pub mrsigner_seam: TeeMeasurement, + pub seam_attributes: TeeAttributes, + pub td_attributes: TeeAttributes, + pub xfam: TeeAttributes, + pub mr_td: TeeMeasurement, + pub mr_config_id: TeeMeasurement, + pub mr_owner: TeeMeasurement, + pub mr_owner_config: TeeMeasurement, + pub rt_mr: [TeeMeasurement; 4], + pub report_data: TeeReportData, + pub tee_tcb_svn2: TeeTcbSvn, + pub mr_servicetd: TeeMeasurement, +} + +#[derive(Clone, Copy, Debug)] +#[repr(C, packed)] +pub struct Quote5 { + pub header: Quote5Header, + pub quote_type: u16, + pub size: u32, + pub body: [u8; 0], +} + +impl_struct_default! { + TeeInfoV15; //512 + TeeTcbInfoV15; //239 +} + +impl_struct_ContiguousMemory! { + TeeInfoV15; + TeeTcbInfoV15; + Report2BodyV15; + Quote5; +} + +impl_asref_array! { + TeeInfoV15; + TeeTcbInfoV15; + Report2BodyV15; +} + +impl Quote5 { + /// # Safety + pub unsafe fn as_slice_unchecked(&self) -> &[u8] { + slice::from_raw_parts( + self as *const _ as *const u8, + mem::size_of::() + self.size as usize, + ) + } +} + /* intel DCAP 1.15 */ // // tdx_attes.h diff --git a/tools/docker/02_binutils.sh b/tools/docker/02_binutils.sh index 26b13e2a6..2ad40137a 100755 --- a/tools/docker/02_binutils.sh +++ b/tools/docker/02_binutils.sh @@ -20,5 +20,5 @@ cd /root && \ wget https://download.01.org/intel-sgx/sgx-linux/$SGX_SDK_RELEASE_VERSION/as.ld.objdump.r4.tar.gz && \ tar xzf as.ld.objdump.r4.tar.gz && \ -cp -r external/toolset/$BINUTILS_DIST/* /usr/bin/ && \ +cp -r external/toolset/$TOOLSET_DIST/* /usr/bin/ && \ rm -rf ./external ./as.ld.objdump.r4.tar.gz diff --git a/tools/docker/Dockerfile.centos8 b/tools/docker/Dockerfile.centos8 index 1297649c4..53b615fdf 100644 --- a/tools/docker/Dockerfile.centos8 +++ b/tools/docker/Dockerfile.centos8 @@ -71,18 +71,19 @@ RUN yum install epel-release -y && \ http://downloads.sourceforge.net/ltp/lcov-1.14-1.noarch.rpm && \ alternatives --set python /usr/bin/python2 -ENV SGX_SDK_RELEASE_VERSION 2.20 -ENV SGX_DCAP_RELEASE_VERSION 1.17 -ENV SGX_SDK_CODE_VERSION 2.20 -ENV SGX_DCAP_CODE_VERSION 1.17 -ENV SGX_SDK_BIN_VERSION 2.20.100.4 -ENV SGX_SDK_PKGS_VERSION 2.20.100.4 -ENV SGX_DCAP_PKGS_VERSION 1.17.100.4 +ENV SGX_SDK_RELEASE_VERSION 2.21 +ENV SGX_DCAP_RELEASE_VERSION 1.18 +ENV SGX_SDK_CODE_VERSION 2.21 +ENV SGX_DCAP_CODE_VERSION 1.18 +ENV SGX_SDK_BIN_VERSION 2.21.100.1 +ENV SGX_SDK_PKGS_VERSION 2.21.100.1 +ENV SGX_DCAP_PKGS_VERSION 1.18.100.1 ENV SGX_SDK_VERSION ${SGX_SDK_PKGS_VERSION} ENV SGX_DCAP_VERSION ${SGX_DCAP_PKGS_VERSION} ENV RUST_TOOLCHAIN nightly-2022-10-22 ENV OS_NAME centos ENV BINUTILS_DIST centos8 +ENV TOOLSET_DIST centos8 ENV SGX_SDK_URL "https://download.01.org/intel-sgx/sgx-linux/${SGX_SDK_CODE_VERSION}/distro/${OS_NAME}-stream/sgx_linux_x64_sdk_${SGX_SDK_BIN_VERSION}.bin" ENV PSW_REPO_URL "https://download.01.org/intel-sgx/sgx-linux/${SGX_SDK_RELEASE_VERSION}/distro/${OS_NAME}-stream/sgx_rpm_local_repo.tgz" diff --git a/tools/docker/Dockerfile.ubuntu18.04 b/tools/docker/Dockerfile.ubuntu18.04 index 4c22b1887..74dd0ed01 100644 --- a/tools/docker/Dockerfile.ubuntu18.04 +++ b/tools/docker/Dockerfile.ubuntu18.04 @@ -78,18 +78,19 @@ RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-i rm -rf /var/lib/apt/lists/* ENV CODENAME bionic -ENV SGX_SDK_RELEASE_VERSION 2.20 -ENV SGX_DCAP_RELEASE_VERSION 1.17 -ENV SGX_SDK_CODE_VERSION 2.20 -ENV SGX_DCAP_CODE_VERSION 1.17 -ENV SGX_SDK_BIN_VERSION 2.20.100.4 -ENV SGX_SDK_PKGS_VERSION 2.20.100.4 -ENV SGX_DCAP_PKGS_VERSION 1.17.100.4 +ENV SGX_SDK_RELEASE_VERSION 2.21 +ENV SGX_DCAP_RELEASE_VERSION 1.18 +ENV SGX_SDK_CODE_VERSION 2.21 +ENV SGX_DCAP_CODE_VERSION 1.18 +ENV SGX_SDK_BIN_VERSION 2.21.100.1 +ENV SGX_SDK_PKGS_VERSION 2.21.100.1 +ENV SGX_DCAP_PKGS_VERSION 1.18.100.1 ENV SGX_SDK_VERSION ${SGX_SDK_PKGS_VERSION}-bionic1 ENV SGX_DCAP_VERSION ${SGX_DCAP_PKGS_VERSION}-bionic1 ENV RUST_TOOLCHAIN nightly-2022-10-22 ENV OS_NAME ubuntu ENV BINUTILS_DIST ubuntu18.04 +ENV TOOLSET_DIST ubuntu20.04 ENV SGX_SDK_URL "https://download.01.org/intel-sgx/sgx-linux/${SGX_SDK_CODE_VERSION}/distro/${BINUTILS_DIST}-server/sgx_linux_x64_sdk_${SGX_SDK_BIN_VERSION}.bin" ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/lib diff --git a/tools/docker/Dockerfile.ubuntu20.04 b/tools/docker/Dockerfile.ubuntu20.04 index 91d0d28eb..7d8d8bc89 100644 --- a/tools/docker/Dockerfile.ubuntu20.04 +++ b/tools/docker/Dockerfile.ubuntu20.04 @@ -77,18 +77,19 @@ RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-i rm -rf /var/lib/apt/lists/* ENV CODENAME focal -ENV SGX_SDK_RELEASE_VERSION 2.20 -ENV SGX_DCAP_RELEASE_VERSION 1.17 -ENV SGX_SDK_CODE_VERSION 2.20 -ENV SGX_DCAP_CODE_VERSION 1.17 -ENV SGX_SDK_BIN_VERSION 2.20.100.4 -ENV SGX_SDK_PKGS_VERSION 2.20.100.4 -ENV SGX_DCAP_PKGS_VERSION 1.17.100.4 +ENV SGX_SDK_RELEASE_VERSION 2.21 +ENV SGX_DCAP_RELEASE_VERSION 1.18 +ENV SGX_SDK_CODE_VERSION 2.21 +ENV SGX_DCAP_CODE_VERSION 1.18 +ENV SGX_SDK_BIN_VERSION 2.21.100.1 +ENV SGX_SDK_PKGS_VERSION 2.21.100.1 +ENV SGX_DCAP_PKGS_VERSION 1.18.100.1 ENV SGX_SDK_VERSION ${SGX_SDK_PKGS_VERSION}-focal1 ENV SGX_DCAP_VERSION ${SGX_DCAP_PKGS_VERSION}-focal1 ENV RUST_TOOLCHAIN nightly-2022-10-22 ENV OS_NAME ubuntu ENV BINUTILS_DIST ubuntu20.04 +ENV TOOLSET_DIST ubuntu20.04 ENV SGX_SDK_URL "https://download.01.org/intel-sgx/sgx-linux/${SGX_SDK_CODE_VERSION}/distro/${BINUTILS_DIST}-server/sgx_linux_x64_sdk_${SGX_SDK_BIN_VERSION}.bin" ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/lib diff --git a/tools/docker/Dockerfile.ubuntu22.04 b/tools/docker/Dockerfile.ubuntu22.04 new file mode 100644 index 000000000..9cedb9247 --- /dev/null +++ b/tools/docker/Dockerfile.ubuntu22.04 @@ -0,0 +1,118 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +FROM ubuntu:22.04 + +LABEL authors="The Teaclave Authors" + +SHELL ["/bin/bash", "-c"] + +RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \ + apt-utils \ + alien \ + astyle \ + autoconf \ + automake \ + bison \ + build-essential \ + ca-certificates \ + cmake \ + curl \ + debhelper \ + dpkg-dev \ + expect \ + g++ \ + gawk \ + flex \ + gdb \ + git-core \ + jq \ + kmod \ + lcov \ + libboost-system-dev \ + libboost-thread-dev \ + libclang-dev \ + libcurl4-openssl-dev \ + libfuse-dev \ + libjsoncpp-dev \ + liblog4cpp5-dev \ + libprotobuf-dev \ + libssl-dev \ + libtool \ + libxml2-dev \ + nano \ + ocaml \ + ocamlbuild \ + pkg-config \ + protobuf-compiler \ + python3 \ + python3-pip \ + sudo \ + unzip \ + uuid-dev \ + vim \ + wget \ + zip \ + gnupg2 \ + aptitude \ + rsync \ + apt-transport-https \ + software-properties-common \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +ENV CODENAME jammy +ENV SGX_SDK_RELEASE_VERSION 2.21 +ENV SGX_DCAP_RELEASE_VERSION 1.18 +ENV SGX_SDK_CODE_VERSION 2.21 +ENV SGX_DCAP_CODE_VERSION 1.18 +ENV SGX_SDK_BIN_VERSION 2.21.100.1 +ENV SGX_SDK_PKGS_VERSION 2.21.100.1 +ENV SGX_DCAP_PKGS_VERSION 1.18.100.1 +ENV SGX_SDK_VERSION ${SGX_SDK_PKGS_VERSION}-jammy1 +ENV SGX_DCAP_VERSION ${SGX_DCAP_PKGS_VERSION}-jammy1 +ENV RUST_TOOLCHAIN nightly-2022-10-22 +ENV OS_NAME ubuntu +ENV BINUTILS_DIST ubuntu22.04 +ENV TOOLSET_DIST ubuntu20.04 +ENV SGX_SDK_URL "https://download.01.org/intel-sgx/sgx-linux/${SGX_SDK_CODE_VERSION}/distro/${BINUTILS_DIST}-server/sgx_linux_x64_sdk_${SGX_SDK_BIN_VERSION}.bin" + +ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/lib +ENV LD_RUN_PATH=/usr/lib:/usr/local/lib + +ADD 02_binutils.sh /root +RUN bash /root/02_binutils.sh + +ADD 03_sdk.sh /root +RUN bash /root/03_sdk.sh + +ADD 04_psw.sh /root +RUN bash /root/04_psw.sh + +ADD 05_optlibs.sh /root +RUN bash /root/05_optlibs.sh + +ADD 06_rust.sh /root +RUN bash /root/06_rust.sh + +RUN rm -rf /root/02_binutils.sh /root/03_sdk.sh /root/04_psw.sh /root/05_optlibs.sh /root/06_rust.sh + +ADD start_aesm.sh /opt/intel/sgx-aesm-service +RUN echo '/opt/intel/sgx-aesm-service/start_aesm.sh' >> /root/.bashrc + +WORKDIR /root From 04825c169a80eea8b4ae000cb10e543fd44860f8 Mon Sep 17 00:00:00 2001 From: volcano Date: Thu, 14 Sep 2023 11:10:15 +0800 Subject: [PATCH 05/34] Fix try_error macro in sgx_trts --- sgx_trts/src/veh/exception.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sgx_trts/src/veh/exception.rs b/sgx_trts/src/veh/exception.rs index a05a2afa5..e55c0cd8e 100644 --- a/sgx_trts/src/veh/exception.rs +++ b/sgx_trts/src/veh/exception.rs @@ -32,13 +32,14 @@ use sgx_types::error::{SgxResult, SgxStatus}; macro_rules! try_error { ($cond:expr) => { - if $cond { + if ($cond) { state::set_state(State::Crashed); bail!(SgxStatus::EnclaveCrashed); } }; ($cond:expr, $e:expr) => { - if !($cond) { + if ($cond) { + state::set_state(State::Crashed); bail!($e); } }; From 1b80455857b16fef02348a5b6db01f2888a49fd5 Mon Sep 17 00:00:00 2001 From: volcano Date: Wed, 20 Sep 2023 16:39:42 +0800 Subject: [PATCH 06/34] Fix ExceptionInfo alignment to 64 bytes --- sgx_trts/src/veh/exception.rs | 2 +- sgx_trts/src/veh/register.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sgx_trts/src/veh/exception.rs b/sgx_trts/src/veh/exception.rs index e55c0cd8e..d24f11e25 100644 --- a/sgx_trts/src/veh/exception.rs +++ b/sgx_trts/src/veh/exception.rs @@ -115,7 +115,7 @@ pub fn handle(tcs: &mut Tcs) -> SgxResult { size += mem::size_of::(); size += xsave_size; sp -= size; - sp &= !0xF; + sp &= !0x3F; // check the decreased sp to make sure it is in the trusted stack range try_error!(!tds.is_stack_addr(sp, 0), SgxStatus::StackOverRun); diff --git a/sgx_trts/src/veh/register.rs b/sgx_trts/src/veh/register.rs index 88a4d4f0d..c72bad563 100644 --- a/sgx_trts/src/veh/register.rs +++ b/sgx_trts/src/veh/register.rs @@ -87,7 +87,7 @@ impl_struct! { } } -#[repr(C)] +#[repr(C, align(64))] #[derive(Debug)] pub struct ExceptionInfo { pub context: CpuContext, From 9b37537daf3116ed176cd2e836063356337479f5 Mon Sep 17 00:00:00 2001 From: volcano Date: Wed, 11 Oct 2023 15:53:28 +0800 Subject: [PATCH 07/34] Fix note.sgxmeta section size --- sgx_trts/src/asm/metadata.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sgx_trts/src/asm/metadata.S b/sgx_trts/src/asm/metadata.S index 6bd96290f..c530d9057 100644 --- a/sgx_trts/src/asm/metadata.S +++ b/sgx_trts/src/asm/metadata.S @@ -17,7 +17,7 @@ .file "metadata.S" -.equ METADATA_SIZE, 0x500 +.equ METADATA_SIZE, 0x5000 .section ".note.sgxmeta", "", @note .p2align 2 /* section alignment */ From 05ead98e52cac2231f35b825a0b41a1ff4107e1e Mon Sep 17 00:00:00 2001 From: volcano Date: Sun, 26 Nov 2023 19:47:42 +0800 Subject: [PATCH 08/34] Support rust nightly-2023-11-17 --- rust-toolchain | 2 +- rustlib/panic_abort/src/lib.rs | 9 +- rustlib/panic_unwind/src/gcc.rs | 34 +- rustlib/panic_unwind/src/lib.rs | 12 +- rustlib/proc_macro/src/bridge/client.rs | 2 +- rustlib/proc_macro/src/bridge/fxhash.rs | 8 +- rustlib/proc_macro/src/bridge/mod.rs | 22 +- rustlib/proc_macro/src/bridge/rpc.rs | 1 - rustlib/proc_macro/src/bridge/server.rs | 2 +- rustlib/proc_macro/src/lib.rs | 159 +- samplecode/crypto/enclave/Xargo.toml | 2 +- .../enclave/Xargo.toml | 2 +- .../enclave/src/lib.rs | 4 +- samplecode/mutual-ra/enclave/Xargo.toml | 2 +- samplecode/rpc/client/Makefile | 3 +- samplecode/rpc/client/enclave/Cargo.toml | 8 +- samplecode/rpc/server/Makefile | 3 +- samplecode/rpc/server/enclave/Cargo.toml | 8 +- .../enclave/Xargo.toml | 2 +- sgx_alloc/src/lib.rs | 1 - sgx_backtrace/src/capture.rs | 8 +- sgx_backtrace/src/symbolize/mod.rs | 3 +- sgx_build_helper/build_helper/src/lib.rs | 4 +- sgx_crypto/src/ecc/mod.rs | 2 +- sgx_crypto/src/sm/sm2/mod.rs | 2 +- sgx_dcap/tkey_exchange/src/capi/initiator.rs | 5 +- sgx_dcap/tkey_exchange/src/capi/responder.rs | 5 +- sgx_dcap/tkey_exchange/src/lib.rs | 2 +- sgx_dcap/tkey_exchange/src/session/manager.rs | 2 +- sgx_dcap/tvl/src/tvl.rs | 12 +- sgx_ffi/src/ascii.rs | 2 + sgx_ffi/src/c_str.rs | 1 + sgx_ffi/src/lib.rs | 1 + sgx_key_exchange/tkey_exchange/src/lib.rs | 2 +- .../tkey_exchange/src/session/manager.rs | 2 +- sgx_key_exchange/ukey_exchange/src/lib.rs | 2 +- sgx_libc/src/linux/pthread/mod.rs | 2 +- sgx_no_tstd/src/lib.rs | 3 +- sgx_oc/src/lib.rs | 1 - sgx_oc/src/linux/mod.rs | 4 +- sgx_oc/src/linux/ocall/mod.rs | 1 + sgx_oc/src/linux/ocall/socket_msg.rs | 2 +- sgx_protected_fs/Cargo.toml | 1 + sgx_protected_fs/tfs/src/sys/mod.rs | 1 + sgx_protected_fs/tfs/src/sys/node.rs | 4 + sgx_rand/src/isaac.rs | 2 +- sgx_rsrvmm/src/lib.rs | 1 - sgx_rsrvmm/src/map.rs | 9 +- sgx_rsrvmm/src/rsrvmm/area.rs | 27 +- sgx_rsrvmm/src/rsrvmm/manager.rs | 11 +- sgx_serialize/src/lib.rs | 1 - sgx_serialize/src/serialize.rs | 4 +- sgx_sync/src/mutex.rs | 8 +- sgx_sync/src/remutex/generic.rs | 4 +- sgx_sync/src/sys/ocall/mod.rs | 2 +- sgx_tdh/src/session/initiator.rs | 9 +- sgx_tdh/src/session/responder.rs | 9 +- sgx_tests/cov/src/lib.rs | 1 - sgx_trts/src/arch.rs | 80 +- sgx_trts/src/edmm/epc.rs | 6 +- sgx_trts/src/enclave/mem.rs | 2 +- sgx_trts/src/enclave/mod.rs | 2 + sgx_trts/src/inst/hw/inst.rs | 6 +- sgx_trts/src/inst/hyper/inst.rs | 6 +- sgx_trts/src/inst/hyper/mod.rs | 6 +- sgx_trts/src/inst/sim/inst.rs | 6 +- sgx_trts/src/inst/sim/mod.rs | 6 +- sgx_trts/src/lib.rs | 3 +- sgx_trts/src/tcs/list.rs | 2 +- sgx_trts/src/thread/native.rs | 2 + sgx_trts/src/veh/list.rs | 2 +- sgx_tstd/hashbrown/Cargo.toml | 29 +- sgx_tstd/hashbrown/benches/bench.rs | 2 +- sgx_tstd/hashbrown/ci/miri.sh | 9 +- sgx_tstd/hashbrown/ci/run.sh | 7 +- sgx_tstd/hashbrown/ci/tools.sh | 5 +- .../hashbrown/src/external_trait_impls/mod.rs | 2 + .../src/external_trait_impls/rayon/map.rs | 47 +- .../src/external_trait_impls/rayon/mod.rs | 1 + .../src/external_trait_impls/rayon/raw.rs | 23 +- .../src/external_trait_impls/rayon/set.rs | 34 +- .../src/external_trait_impls/rayon/table.rs | 252 ++ .../src/external_trait_impls/rkyv/hash_map.rs | 125 + .../src/external_trait_impls/rkyv/hash_set.rs | 123 + .../src/external_trait_impls/rkyv/mod.rs | 2 + .../src/external_trait_impls/serde.rs | 63 +- sgx_tstd/hashbrown/src/lib.rs | 81 +- sgx_tstd/hashbrown/src/macros.rs | 3 +- sgx_tstd/hashbrown/src/map.rs | 3409 ++++++++++++++--- sgx_tstd/hashbrown/src/raw/alloc.rs | 65 +- sgx_tstd/hashbrown/src/raw/bitmask.rs | 99 +- sgx_tstd/hashbrown/src/raw/generic.rs | 59 +- sgx_tstd/hashbrown/src/raw/mod.rs | 3352 +++++++++++++--- sgx_tstd/hashbrown/src/raw/neon.rs | 124 + sgx_tstd/hashbrown/src/raw/sse2.rs | 31 +- sgx_tstd/hashbrown/src/rustc_entry.rs | 44 +- sgx_tstd/hashbrown/src/scopeguard.rs | 25 +- sgx_tstd/hashbrown/src/set.rs | 830 +++- sgx_tstd/hashbrown/src/table.rs | 2030 ++++++++++ sgx_tstd/hashbrown/tests/equivalent_trait.rs | 53 + sgx_tstd/hashbrown/tests/raw.rs | 11 + sgx_tstd/hashbrown/tests/rayon.rs | 4 +- sgx_tstd/hashbrown/tests/set.rs | 2 +- sgx_tstd/src/alloc.rs | 28 +- sgx_tstd/src/backtrace.rs | 73 +- sgx_tstd/src/backtrace/tests.rs | 14 +- sgx_tstd/src/collections/hash/map.rs | 212 +- sgx_tstd/src/collections/hash/map/tests.rs | 29 +- sgx_tstd/src/collections/hash/set.rs | 78 +- sgx_tstd/src/collections/hash/set/tests.rs | 45 +- sgx_tstd/src/collections/mod.rs | 11 +- sgx_tstd/src/env.rs | 38 +- sgx_tstd/src/env/tests.rs | 20 + sgx_tstd/src/error.rs | 20 +- sgx_tstd/src/error/tests.rs | 4 +- sgx_tstd/src/f32.rs | 112 +- sgx_tstd/src/f32/tests.rs | 66 + sgx_tstd/src/f64.rs | 137 +- sgx_tstd/src/f64/tests.rs | 67 + sgx_tstd/src/ffi/mod.rs | 9 + sgx_tstd/src/ffi/os_str.rs | 166 +- sgx_tstd/src/fs.rs | 275 +- sgx_tstd/src/fs/tests.rs | 230 +- sgx_tstd/src/hash/mod.rs | 105 + sgx_tstd/src/hash/random.rs | 169 + sgx_tstd/src/io/buffered/bufreader.rs | 56 +- sgx_tstd/src/io/buffered/bufreader/buffer.rs | 2 +- sgx_tstd/src/io/buffered/bufwriter.rs | 138 +- sgx_tstd/src/io/buffered/linewriter.rs | 48 +- sgx_tstd/src/io/buffered/linewritershim.rs | 6 +- sgx_tstd/src/io/buffered/tests.rs | 17 +- sgx_tstd/src/io/copy.rs | 226 +- sgx_tstd/src/io/copy/tests.rs | 163 + sgx_tstd/src/io/cursor.rs | 2 +- sgx_tstd/src/io/cursor/tests.rs | 8 +- sgx_tstd/src/io/error.rs | 42 +- sgx_tstd/src/io/error/repr_bitpacked.rs | 451 +++ sgx_tstd/src/io/error/repr_unpacked.rs | 23 +- sgx_tstd/src/io/error/tests.rs | 4 +- sgx_tstd/src/io/impls.rs | 86 +- sgx_tstd/src/io/mod.rs | 243 +- sgx_tstd/src/io/readbuf.rs | 324 -- sgx_tstd/src/io/readbuf/tests.rs | 194 - sgx_tstd/src/io/stdio.rs | 37 +- sgx_tstd/src/io/stdio/tests.rs | 1 - sgx_tstd/src/io/tests.rs | 4 +- sgx_tstd/src/io/util.rs | 96 +- sgx_tstd/src/io/util/tests.rs | 74 +- sgx_tstd/src/lib.rs | 44 +- sgx_tstd/src/macros.rs | 16 +- sgx_tstd/src/net/display_buffer.rs | 57 - sgx_tstd/src/net/ip_addr.rs | 1952 +--------- sgx_tstd/src/net/ip_addr/tests.rs | 1035 +---- sgx_tstd/src/net/mod.rs | 4 +- sgx_tstd/src/net/parser.rs | 503 --- sgx_tstd/src/net/parser/tests.rs | 168 - sgx_tstd/src/net/socket_addr.rs | 665 +--- sgx_tstd/src/net/socket_addr/tests.rs | 12 +- sgx_tstd/src/net/tcp.rs | 26 +- sgx_tstd/src/net/tcp/tests.rs | 167 +- sgx_tstd/src/net/test.rs | 6 +- sgx_tstd/src/net/udp.rs | 31 +- sgx_tstd/src/net/udp/tests.rs | 60 +- sgx_tstd/src/os/fd/owned.rs | 21 +- sgx_tstd/src/os/fd/raw.rs | 12 +- sgx_tstd/src/os/fd/tests.rs | 4 +- sgx_tstd/src/os/linux/fs.rs | 13 +- sgx_tstd/src/os/linux/net.rs | 5 +- sgx_tstd/src/os/linux/process.rs | 2 + sgx_tstd/src/os/net/linux_ext/addr.rs | 78 + .../net/linux_ext/mod.rs} | 28 +- sgx_tstd/src/os/net/{ => linux_ext}/tcp.rs | 0 sgx_tstd/src/os/net/{ => linux_ext}/tests.rs | 6 +- sgx_tstd/src/os/net/mod.rs | 7 +- sgx_tstd/src/os/raw/mod.rs | 4 - sgx_tstd/src/os/unix/fs.rs | 64 +- sgx_tstd/src/os/unix/fs/tests.rs | 76 + sgx_tstd/src/os/unix/io/mod.rs | 16 +- sgx_tstd/src/os/unix/net/addr.rs | 82 +- sgx_tstd/src/os/unix/net/ancillary.rs | 11 +- sgx_tstd/src/os/unix/net/datagram.rs | 3 - sgx_tstd/src/os/unix/net/listener.rs | 8 +- sgx_tstd/src/os/unix/net/tests.rs | 44 +- sgx_tstd/src/os/unix/process.rs | 39 + sgx_tstd/src/os/unix/ucred/tests.rs | 1 - sgx_tstd/src/panic.rs | 13 +- sgx_tstd/src/panicking.rs | 259 +- sgx_tstd/src/path.rs | 342 +- sgx_tstd/src/path/tests.rs | 56 +- sgx_tstd/src/prelude/mod.rs | 6 +- sgx_tstd/src/prelude/v1.rs | 14 +- sgx_tstd/src/process.rs | 380 +- sgx_tstd/src/sync/barrier.rs | 21 +- sgx_tstd/src/sync/condvar.rs | 18 +- sgx_tstd/src/sync/condvar/tests.rs | 12 +- sgx_tstd/src/sync/lazy_lock.rs | 171 +- sgx_tstd/src/sync/lazy_lock/tests.rs | 6 + sgx_tstd/src/sync/mod.rs | 12 +- sgx_tstd/src/sync/mpmc/array.rs | 583 +++ sgx_tstd/src/sync/mpmc/context.rs | 174 + sgx_tstd/src/sync/mpmc/counter.rs | 154 + sgx_tstd/src/sync/mpmc/error.rs | 63 + sgx_tstd/src/sync/mpmc/list.rs | 669 ++++ sgx_tstd/src/sync/mpmc/mod.rs | 449 +++ sgx_tstd/src/sync/mpmc/select.rs | 89 + sgx_tstd/src/sync/mpmc/utils.rs | 107 + sgx_tstd/src/sync/mpmc/waker.rs | 227 ++ sgx_tstd/src/sync/mpmc/zero.rs | 335 ++ sgx_tstd/src/sync/mpsc/blocking.rs | 101 - sgx_tstd/src/sync/mpsc/mod.rs | 491 +-- sgx_tstd/src/sync/mpsc/mpsc_queue.rs | 135 - sgx_tstd/src/sync/mpsc/mpsc_queue/tests.rs | 66 - sgx_tstd/src/sync/mpsc/oneshot.rs | 333 -- sgx_tstd/src/sync/mpsc/shared.rs | 515 --- sgx_tstd/src/sync/mpsc/spsc_queue.rs | 253 -- sgx_tstd/src/sync/mpsc/spsc_queue/tests.rs | 121 - sgx_tstd/src/sync/mpsc/stream.rs | 470 --- sgx_tstd/src/sync/mpsc/sync.rs | 514 --- sgx_tstd/src/sync/mpsc/sync_tests.rs | 21 + sgx_tstd/src/sync/mpsc/tests.rs | 15 + sgx_tstd/src/sync/mutex.rs | 46 +- sgx_tstd/src/sync/mutex/tests.rs | 10 +- sgx_tstd/src/sync/once.rs | 20 +- sgx_tstd/src/sync/once_lock.rs | 95 +- sgx_tstd/src/sync/once_lock/tests.rs | 4 +- .../src/{personality.rs => sync/remutex.rs} | 16 +- .../src/{sys_common => sync}/remutex/tests.rs | 5 +- sgx_tstd/src/sync/rwlock.rs | 22 +- sgx_tstd/src/sync/rwlock/tests.rs | 14 +- sgx_tstd/src/sys/backtrace/mod.rs | 2 +- sgx_tstd/src/sys/cmath.rs | 4 + sgx_tstd/src/sys/common/mod.rs | 3 + sgx_tstd/src/sys/common/small_c_string.rs | 2 +- sgx_tstd/src/sys/common/tests.rs | 4 +- .../src/sys/common/thread_local/fast_local.rs | 254 ++ sgx_tstd/src/sys/common/thread_local/mod.rs | 137 + .../src/sys/common/thread_local/os_local.rs | 201 + .../sys/common/thread_local/static_local.rs | 126 + sgx_tstd/src/sys/fd.rs | 36 +- sgx_tstd/src/sys/fs.rs | 60 +- sgx_tstd/src/sys/kernel_copy.rs | 86 +- sgx_tstd/src/sys/kernel_copy/tests.rs | 8 +- sgx_tstd/src/sys/mod.rs | 11 +- sgx_tstd/src/sys/net.rs | 61 +- sgx_tstd/src/sys/os.rs | 29 +- sgx_tstd/src/sys/os_str.rs | 24 +- sgx_tstd/src/sys/os_str/tests.rs | 9 +- sgx_tstd/src/sys/path.rs | 2 +- .../src/{ => sys}/personality/dwarf/eh.rs | 154 +- .../src/{ => sys}/personality/dwarf/mod.rs | 2 +- .../src/{ => sys}/personality/dwarf/tests.rs | 0 sgx_tstd/src/{ => sys}/personality/gcc.rs | 12 +- sgx_tstd/src/sys/personality/mod.rs | 14 + sgx_tstd/src/sys/pipe.rs | 19 +- sgx_tstd/src/sys/stdio.rs | 8 +- sgx_tstd/src/sys/thread.rs | 2 +- sgx_tstd/src/sys/time.rs | 96 +- sgx_tstd/src/sys/unsupported/common.rs | 1 + sgx_tstd/src/sys/unsupported/pipe.rs | 19 +- sgx_tstd/src/sys/unsupported/process.rs | 53 +- sgx_tstd/src/sys_common/at_exit_imp.rs | 2 +- sgx_tstd/src/sys_common/io.rs | 2 +- sgx_tstd/src/sys_common/lazy_box.rs | 107 + sgx_tstd/src/sys_common/mod.rs | 21 +- sgx_tstd/src/sys_common/mutex.rs | 4 +- sgx_tstd/src/sys_common/net.rs | 31 +- sgx_tstd/src/sys_common/net/tests.rs | 2 +- sgx_tstd/src/sys_common/once/futex.rs | 14 +- sgx_tstd/src/sys_common/once/mod.rs | 4 +- .../sys_common/once/{generic.rs => queue.rs} | 11 + sgx_tstd/src/sys_common/process.rs | 48 +- sgx_tstd/src/sys_common/remutex.rs | 3 - sgx_tstd/src/sys_common/rwlock.rs | 4 +- sgx_tstd/src/sys_common/thread_info.rs | 50 +- sgx_tstd/src/sys_common/thread_local_dtor.rs | 17 +- sgx_tstd/src/sys_common/thread_local_key.rs | 27 +- .../futex.rs | 2 +- .../generic.rs | 2 +- .../{thread_parker => thread_parking}/mod.rs | 0 sgx_tstd/src/sys_common/wstr.rs | 76 + sgx_tstd/src/sys_common/wtf8.rs | 2 +- sgx_tstd/src/sys_common/wtf8/tests.rs | 2 +- sgx_tstd/src/thread/local.rs | 628 +-- sgx_tstd/src/thread/local/tests.rs | 78 +- sgx_tstd/src/thread/mod.rs | 170 +- sgx_tstd/src/thread/scoped.rs | 2 +- sgx_tstd/src/thread/tests.rs | 7 +- sgx_tstd/src/time.rs | 45 +- sgx_tstd/src/time/tests.rs | 36 +- sgx_unwind/src/lib.rs | 3 +- sgx_unwind/src/libunwind.rs | 11 +- sgx_urts/src/lib.rs | 1 - tests/enclave/src/lib.rs | 3 + tools/docker/06_rust.sh | 2 +- tools/docker/Dockerfile.centos8 | 2 +- tools/docker/Dockerfile.ubuntu18.04 | 2 +- tools/docker/Dockerfile.ubuntu20.04 | 2 +- 297 files changed, 19143 insertions(+), 12092 deletions(-) create mode 100644 sgx_tstd/hashbrown/src/external_trait_impls/rayon/table.rs create mode 100644 sgx_tstd/hashbrown/src/external_trait_impls/rkyv/hash_map.rs create mode 100644 sgx_tstd/hashbrown/src/external_trait_impls/rkyv/hash_set.rs create mode 100644 sgx_tstd/hashbrown/src/external_trait_impls/rkyv/mod.rs create mode 100644 sgx_tstd/hashbrown/src/raw/neon.rs create mode 100644 sgx_tstd/hashbrown/src/table.rs create mode 100644 sgx_tstd/hashbrown/tests/equivalent_trait.rs create mode 100644 sgx_tstd/hashbrown/tests/raw.rs create mode 100644 sgx_tstd/src/hash/mod.rs create mode 100644 sgx_tstd/src/hash/random.rs create mode 100644 sgx_tstd/src/io/copy/tests.rs create mode 100644 sgx_tstd/src/io/error/repr_bitpacked.rs delete mode 100644 sgx_tstd/src/io/readbuf.rs delete mode 100644 sgx_tstd/src/io/readbuf/tests.rs delete mode 100644 sgx_tstd/src/net/display_buffer.rs delete mode 100644 sgx_tstd/src/net/parser.rs delete mode 100644 sgx_tstd/src/net/parser/tests.rs create mode 100644 sgx_tstd/src/os/net/linux_ext/addr.rs rename sgx_tstd/src/{sync/mpsc/cache_aligned.rs => os/net/linux_ext/mod.rs} (61%) rename sgx_tstd/src/os/net/{ => linux_ext}/tcp.rs (100%) rename sgx_tstd/src/os/net/{ => linux_ext}/tests.rs (89%) create mode 100644 sgx_tstd/src/os/unix/fs/tests.rs create mode 100644 sgx_tstd/src/sync/mpmc/array.rs create mode 100644 sgx_tstd/src/sync/mpmc/context.rs create mode 100644 sgx_tstd/src/sync/mpmc/counter.rs create mode 100644 sgx_tstd/src/sync/mpmc/error.rs create mode 100644 sgx_tstd/src/sync/mpmc/list.rs create mode 100644 sgx_tstd/src/sync/mpmc/mod.rs create mode 100644 sgx_tstd/src/sync/mpmc/select.rs create mode 100644 sgx_tstd/src/sync/mpmc/utils.rs create mode 100644 sgx_tstd/src/sync/mpmc/waker.rs create mode 100644 sgx_tstd/src/sync/mpmc/zero.rs delete mode 100644 sgx_tstd/src/sync/mpsc/blocking.rs delete mode 100644 sgx_tstd/src/sync/mpsc/mpsc_queue.rs delete mode 100644 sgx_tstd/src/sync/mpsc/mpsc_queue/tests.rs delete mode 100644 sgx_tstd/src/sync/mpsc/oneshot.rs delete mode 100644 sgx_tstd/src/sync/mpsc/shared.rs delete mode 100644 sgx_tstd/src/sync/mpsc/spsc_queue.rs delete mode 100644 sgx_tstd/src/sync/mpsc/spsc_queue/tests.rs delete mode 100644 sgx_tstd/src/sync/mpsc/stream.rs delete mode 100644 sgx_tstd/src/sync/mpsc/sync.rs rename sgx_tstd/src/{personality.rs => sync/remutex.rs} (60%) rename sgx_tstd/src/{sys_common => sync}/remutex/tests.rs (95%) create mode 100644 sgx_tstd/src/sys/common/thread_local/fast_local.rs create mode 100644 sgx_tstd/src/sys/common/thread_local/mod.rs create mode 100644 sgx_tstd/src/sys/common/thread_local/os_local.rs create mode 100644 sgx_tstd/src/sys/common/thread_local/static_local.rs rename sgx_tstd/src/{ => sys}/personality/dwarf/eh.rs (54%) rename sgx_tstd/src/{ => sys}/personality/dwarf/mod.rs (98%) rename sgx_tstd/src/{ => sys}/personality/dwarf/tests.rs (100%) rename sgx_tstd/src/{ => sys}/personality/gcc.rs (92%) create mode 100644 sgx_tstd/src/sys/personality/mod.rs create mode 100644 sgx_tstd/src/sys_common/lazy_box.rs rename sgx_tstd/src/sys_common/once/{generic.rs => queue.rs} (97%) rename sgx_tstd/src/sys_common/{thread_parker => thread_parking}/futex.rs (98%) rename sgx_tstd/src/sys_common/{thread_parker => thread_parking}/generic.rs (99%) rename sgx_tstd/src/sys_common/{thread_parker => thread_parking}/mod.rs (100%) create mode 100644 sgx_tstd/src/sys_common/wstr.rs diff --git a/rust-toolchain b/rust-toolchain index cd5e8eb24..33cc62763 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-10-22 +nightly-2023-11-17 diff --git a/rustlib/panic_abort/src/lib.rs b/rustlib/panic_abort/src/lib.rs index 1902efcf4..99b10fdb3 100644 --- a/rustlib/panic_abort/src/lib.rs +++ b/rustlib/panic_abort/src/lib.rs @@ -7,6 +7,7 @@ #![unstable(feature = "panic_abort", issue = "32837")] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] #![panic_runtime] +#![allow(internal_features)] #![allow(unused_features)] #![feature(core_intrinsics)] #![feature(panic_runtime)] @@ -18,7 +19,7 @@ extern crate sgx_trts; use core::any::Any; -use core::panic::BoxMeUp; +use core::panic::PanicPayload; /// # Safety #[rustc_std_internal_symbol] @@ -30,14 +31,14 @@ pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Sen /// # Safety // "Leak" the payload and shim to the relevant abort on the platform in question. #[rustc_std_internal_symbol] -pub unsafe extern "C-unwind" fn __rust_start_panic(_payload: *mut &mut dyn BoxMeUp) -> u32 { +pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 { sgx_trts::error::abort(); } // This... is a bit of an oddity. The tl;dr; is that this is required to link // correctly, the longer explanation is below. // -// Right now the binaries of libcore/libstd that we ship are all compiled with +// Right now the binaries of core/std that we ship are all compiled with // `-C panic=unwind`. This is done to ensure that the binaries are maximally // compatible with as many situations as possible. The compiler, however, // requires a "personality function" for all functions compiled with `-C @@ -57,7 +58,7 @@ pub unsafe extern "C-unwind" fn __rust_start_panic(_payload: *mut &mut dyn BoxMe // library just defines this symbol so there's at least some personality // somewhere. // -// Essentially this symbol is just defined to get wired up to libcore/libstd +// Essentially this symbol is just defined to get wired up to core/std // binaries, but it should never be called as we don't link in an unwinding // runtime at all. pub mod personalities { diff --git a/rustlib/panic_unwind/src/gcc.rs b/rustlib/panic_unwind/src/gcc.rs index a539b5906..9c2c64136 100644 --- a/rustlib/panic_unwind/src/gcc.rs +++ b/rustlib/panic_unwind/src/gcc.rs @@ -38,12 +38,23 @@ use alloc::boxed::Box; use core::any::Any; +use core::ptr; use sgx_unwind as uw; +// In case where multiple copies of std exist in a single process, +// we use address of this static variable to distinguish an exception raised by +// this copy and some other copy (which needs to be treated as foreign exception). +static CANARY: u8 = 0; + +// NOTE(nbdd0121) +// There is an ABI stability requirement on this struct. +// The first two field must be `_Unwind_Exception` and `canary`, +// as it may be accessed by a different version of the std with a different compiler. #[repr(C)] struct Exception { _uwe: uw::_Unwind_Exception, + canary: *const u8, cause: Box, } @@ -52,8 +63,9 @@ pub unsafe fn panic(data: Box) -> u32 { _uwe: uw::_Unwind_Exception { exception_class: rust_exception_class(), exception_cleanup, - private: [0; uw::unwinder_private_data_size], + private: [core::ptr::null(); uw::unwinder_private_data_size], }, + canary: &CANARY, cause: data, }); let exception_param = Box::into_raw(exception) as *mut uw::_Unwind_Exception; @@ -75,15 +87,27 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box { if (*exception).exception_class != rust_exception_class() { uw::_Unwind_DeleteException(exception); super::__rust_foreign_exception(); - } else { - let exception = Box::from_raw(exception as *mut Exception); - exception.cause } + + let exception = exception.cast::(); + // Just access the canary field, avoid accessing the entire `Exception` as + // it can be a foreign Rust exception. + let canary = ptr::addr_of!((*exception).canary).read(); + if !ptr::eq(canary, &CANARY) { + // A foreign Rust exception, treat it slightly differently from other + // foreign exceptions, because call into `_Unwind_DeleteException` will + // call into `__rust_drop_panic` which produces a confusing + // "Rust panic must be rethrown" message. + super::__rust_foreign_exception(); + } + + let exception = Box::from_raw(exception as *mut Exception); + exception.cause } // Rust's exception class identifier. This is used by personality routines to // determine whether the exception was thrown by their own runtime. fn rust_exception_class() -> uw::_Unwind_Exception_Class { // M O Z \0 R U S T -- vendor, language - 0x4d4f_5a00_5255_5354 + 0x4d4f5a_00_52555354 } diff --git a/rustlib/panic_unwind/src/lib.rs b/rustlib/panic_unwind/src/lib.rs index ea3fdd2b5..60d7af26f 100644 --- a/rustlib/panic_unwind/src/lib.rs +++ b/rustlib/panic_unwind/src/lib.rs @@ -19,28 +19,28 @@ #![feature(panic_unwind)] #![feature(staged_api)] #![feature(std_internals)] -#![feature(abi_thiscall)] #![feature(rustc_attrs)] #![panic_runtime] #![feature(panic_runtime)] #![feature(c_unwind)] +#![allow(internal_features)] extern crate alloc; extern crate sgx_unwind; use alloc::boxed::Box; use core::any::Any; -use core::panic::BoxMeUp; +use core::panic::PanicPayload; #[path = "gcc.rs"] mod imp; extern "C" { - /// Handler in libstd called when a panic object is dropped outside of + /// Handler in std called when a panic object is dropped outside of /// `catch_unwind`. fn __rust_drop_panic() -> !; - /// Handler in libstd called when a foreign exception is caught. + /// Handler in std called when a foreign exception is caught. fn __rust_foreign_exception() -> !; } @@ -55,8 +55,8 @@ pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any // Entry point for raising an exception, just delegates to the platform-specific // implementation. #[rustc_std_internal_symbol] -pub unsafe fn __rust_start_panic(payload: *mut &mut dyn BoxMeUp) -> u32 { - let payload = Box::from_raw((*payload).take_box()); +pub unsafe fn __rust_start_panic(payload: &mut dyn PanicPayload) -> u32 { + let payload = Box::from_raw(payload.take_box()); imp::panic(payload) } diff --git a/rustlib/proc_macro/src/bridge/client.rs b/rustlib/proc_macro/src/bridge/client.rs index 506b2a773..52a08cad9 100644 --- a/rustlib/proc_macro/src/bridge/client.rs +++ b/rustlib/proc_macro/src/bridge/client.rs @@ -356,7 +356,7 @@ impl Clone for Client { fn maybe_install_panic_hook(force_show_panics: bool) { // Hide the default panic output within `proc_macro` expansions. - // NB. the server can't do this because it may use a different libstd. + // NB. the server can't do this because it may use a different std. static HIDE_PANICS_DURING_EXPANSION: Once = Once::new(); HIDE_PANICS_DURING_EXPANSION.call_once(|| { let prev = panic::take_hook(); diff --git a/rustlib/proc_macro/src/bridge/fxhash.rs b/rustlib/proc_macro/src/bridge/fxhash.rs index 4b1e412e2..f4e905441 100644 --- a/rustlib/proc_macro/src/bridge/fxhash.rs +++ b/rustlib/proc_macro/src/bridge/fxhash.rs @@ -5,8 +5,6 @@ //! on the `rustc_hash` crate. use std::collections::HashMap; -use std::convert::TryInto; -use std::default::Default; use std::hash::BuildHasherDefault; use std::hash::Hasher; use std::mem::size_of; @@ -15,9 +13,9 @@ use std::ops::BitXor; /// Type alias for a hashmap using the `fx` hash algorithm. pub type FxHashMap = HashMap>; -/// A speedy hash algorithm for use within rustc. The hashmap in liballoc -/// by default uses SipHash which isn't quite as speedy as we want. In the -/// compiler we're not really worried about DOS attempts, so we use a fast +/// A speedy hash algorithm for use within rustc. The hashmap in alloc by +/// default uses SipHash which isn't quite as speedy as we want. In the compiler +/// we're not really worried about DOS attempts, so we use a fast /// non-cryptographic hash. /// /// This is the same as the algorithm used by Firefox -- which is a homespun diff --git a/rustlib/proc_macro/src/bridge/mod.rs b/rustlib/proc_macro/src/bridge/mod.rs index 4c1e196b5..86ce5d9c6 100644 --- a/rustlib/proc_macro/src/bridge/mod.rs +++ b/rustlib/proc_macro/src/bridge/mod.rs @@ -8,12 +8,13 @@ #![deny(unsafe_code)] -use crate::{Delimiter, Level, LineColumn, Spacing}; +use crate::{Delimiter, Level, Spacing}; use std::fmt; use std::hash::Hash; use std::marker; use std::mem; use std::ops::Bound; +use std::ops::Range; use std::panic; use std::sync::atomic::AtomicUsize; use std::sync::Once; @@ -93,10 +94,11 @@ macro_rules! with_api { fn source_file($self: $S::Span) -> $S::SourceFile; fn parent($self: $S::Span) -> Option<$S::Span>; fn source($self: $S::Span) -> $S::Span; - fn start($self: $S::Span) -> LineColumn; - fn end($self: $S::Span) -> LineColumn; - fn before($self: $S::Span) -> $S::Span; - fn after($self: $S::Span) -> $S::Span; + fn byte_range($self: $S::Span) -> Range; + fn start($self: $S::Span) -> $S::Span; + fn end($self: $S::Span) -> $S::Span; + fn line($self: $S::Span) -> usize; + fn column($self: $S::Span) -> usize; fn join($self: $S::Span, other: $S::Span) -> Option<$S::Span>; fn subspan($self: $S::Span, start: Bound, end: Bound) -> Option<$S::Span>; fn resolved_at($self: $S::Span, at: $S::Span) -> $S::Span; @@ -297,7 +299,6 @@ mark_noop! { Delimiter, LitKind, Level, - LineColumn, Spacing, } @@ -317,7 +318,6 @@ rpc_encode_decode!( Help, } ); -rpc_encode_decode!(struct LineColumn { line, column }); rpc_encode_decode!( enum Spacing { Alone, @@ -335,6 +335,8 @@ pub enum LitKind { StrRaw(u8), ByteStr, ByteStrRaw(u8), + CStr, + CStrRaw(u8), Err, } @@ -348,6 +350,8 @@ rpc_encode_decode!( StrRaw(n), ByteStr, ByteStrRaw(n), + CStr, + CStrRaw(n), Err, } ); @@ -519,3 +523,7 @@ pub struct ExpnGlobals { compound_traits!( struct ExpnGlobals { def_site, call_site, mixed_site } ); + +compound_traits!( + struct Range { start, end } +); diff --git a/rustlib/proc_macro/src/bridge/rpc.rs b/rustlib/proc_macro/src/bridge/rpc.rs index e9d7a46c0..5b1bfb309 100644 --- a/rustlib/proc_macro/src/bridge/rpc.rs +++ b/rustlib/proc_macro/src/bridge/rpc.rs @@ -1,7 +1,6 @@ //! Serialization for client-server communication. use std::any::Any; -use std::char; use std::io::Write; use std::num::NonZeroU32; use std::str; diff --git a/rustlib/proc_macro/src/bridge/server.rs b/rustlib/proc_macro/src/bridge/server.rs index 8202c40d6..2ea87d866 100644 --- a/rustlib/proc_macro/src/bridge/server.rs +++ b/rustlib/proc_macro/src/bridge/server.rs @@ -112,7 +112,7 @@ macro_rules! define_dispatcher_impl { $name::$method(server, $($arg),*) }; // HACK(eddyb) don't use `panic::catch_unwind` in a panic. - // If client and server happen to use the same `libstd`, + // If client and server happen to use the same `std`, // `catch_unwind` asserts that the panic counter was 0, // even when the closure passed to it didn't panic. let r = if thread::panicking() { diff --git a/rustlib/proc_macro/src/lib.rs b/rustlib/proc_macro/src/lib.rs index 6f46ccdf8..0a70c488a 100644 --- a/rustlib/proc_macro/src/lib.rs +++ b/rustlib/proc_macro/src/lib.rs @@ -24,17 +24,15 @@ #![feature(staged_api)] #![feature(allow_internal_unstable)] #![feature(decl_macro)] -// duanran -// #![feature(local_key_cell_methods)] #![feature(maybe_uninit_write_slice)] #![feature(negative_impls)] #![feature(new_uninit)] -// duanran -// #![feature(restricted_std)] +#![feature(restricted_std)] #![feature(rustc_attrs)] #![feature(min_specialization)] #![feature(strict_provenance)] #![recursion_limit = "256"] +#![allow(internal_features)] #[unstable(feature = "proc_macro_internals", issue = "27812")] #[doc(hidden)] @@ -45,11 +43,10 @@ mod diagnostic; #[unstable(feature = "proc_macro_diagnostic", issue = "54140")] pub use diagnostic::{Diagnostic, Level, MultiSpan}; -use std::cmp::Ordering; -use std::ops::RangeBounds; +use std::ops::{Range, RangeBounds}; use std::path::PathBuf; use std::str::FromStr; -use std::{error, fmt, iter}; +use std::{error, fmt}; /// Determines whether proc_macro has been made accessible to the currently /// running program. @@ -76,6 +73,7 @@ pub fn is_available() -> bool { /// /// This is both the input and output of `#[proc_macro]`, `#[proc_macro_attribute]` /// and `#[proc_macro_derive]` definitions. +#[rustc_diagnostic_item = "TokenStream"] #[stable(feature = "proc_macro_lib", since = "1.15.0")] #[derive(Clone)] pub struct TokenStream(Option); @@ -179,6 +177,7 @@ impl FromStr for TokenStream { // N.B., the bridge only provides `to_string`, implement `fmt::Display` // based on it (the reverse of the usual relationship between the two). +#[doc(hidden)] #[stable(feature = "proc_macro_lib", since = "1.15.0")] impl ToString for TokenStream { fn to_string(&self) -> String { @@ -311,7 +310,7 @@ impl ConcatStreamsHelper { /// Collects a number of token trees into a single stream. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] -impl iter::FromIterator for TokenStream { +impl FromIterator for TokenStream { fn from_iter>(trees: I) -> Self { let iter = trees.into_iter(); let mut builder = ConcatTreesHelper::new(iter.size_hint().0); @@ -323,7 +322,7 @@ impl iter::FromIterator for TokenStream { /// A "flattening" operation on token streams, collects token trees /// from multiple token streams into a single stream. #[stable(feature = "proc_macro_lib", since = "1.15.0")] -impl iter::FromIterator for TokenStream { +impl FromIterator for TokenStream { fn from_iter>(streams: I) -> Self { let iter = streams.into_iter(); let mut builder = ConcatStreamsHelper::new(iter.size_hint().0); @@ -489,28 +488,38 @@ impl Span { Span(self.0.source()) } - /// Gets the starting line/column in the source file for this span. + /// Returns the span's byte position range in the source file. #[unstable(feature = "proc_macro_span", issue = "54725")] - pub fn start(&self) -> LineColumn { - self.0.start().add_1_to_column() + pub fn byte_range(&self) -> Range { + self.0.byte_range() } - /// Gets the ending line/column in the source file for this span. + /// Creates an empty span pointing to directly before this span. #[unstable(feature = "proc_macro_span", issue = "54725")] - pub fn end(&self) -> LineColumn { - self.0.end().add_1_to_column() + pub fn start(&self) -> Span { + Span(self.0.start()) } - /// Creates an empty span pointing to directly before this span. - #[unstable(feature = "proc_macro_span_shrink", issue = "87552")] - pub fn before(&self) -> Span { - Span(self.0.before()) + /// Creates an empty span pointing to directly after this span. + #[unstable(feature = "proc_macro_span", issue = "54725")] + pub fn end(&self) -> Span { + Span(self.0.end()) } - /// Creates an empty span pointing to directly after this span. - #[unstable(feature = "proc_macro_span_shrink", issue = "87552")] - pub fn after(&self) -> Span { - Span(self.0.after()) + /// The one-indexed line of the source file where the span starts. + /// + /// To obtain the line of the span's end, use `span.end().line()`. + #[unstable(feature = "proc_macro_span", issue = "54725")] + pub fn line(&self) -> usize { + self.0.line() + } + + /// The one-indexed column of the source file where the span starts. + /// + /// To obtain the column of the span's end, use `span.end().column()`. + #[unstable(feature = "proc_macro_span", issue = "54725")] + pub fn column(&self) -> usize { + self.0.column() } /// Creates a new span encompassing `self` and `other`. @@ -548,7 +557,7 @@ impl Span { /// Note: The observable result of a macro should only rely on the tokens and /// not on this source text. The result of this function is a best effort to /// be used for diagnostics only. - #[stable(feature = "proc_macro_source_text", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "proc_macro_source_text", since = "1.66.0")] pub fn source_text(&self) -> Option { self.0.source_text() } @@ -581,44 +590,6 @@ impl fmt::Debug for Span { } } -/// A line-column pair representing the start or end of a `Span`. -#[unstable(feature = "proc_macro_span", issue = "54725")] -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub struct LineColumn { - /// The 1-indexed line in the source file on which the span starts or ends (inclusive). - #[unstable(feature = "proc_macro_span", issue = "54725")] - pub line: usize, - /// The 1-indexed column (number of bytes in UTF-8 encoding) in the source - /// file on which the span starts or ends (inclusive). - #[unstable(feature = "proc_macro_span", issue = "54725")] - pub column: usize, -} - -impl LineColumn { - fn add_1_to_column(self) -> Self { - LineColumn { line: self.line, column: self.column + 1 } - } -} - -#[unstable(feature = "proc_macro_span", issue = "54725")] -impl !Send for LineColumn {} -#[unstable(feature = "proc_macro_span", issue = "54725")] -impl !Sync for LineColumn {} - -#[unstable(feature = "proc_macro_span", issue = "54725")] -impl Ord for LineColumn { - fn cmp(&self, other: &Self) -> Ordering { - self.line.cmp(&other.line).then(self.column.cmp(&other.column)) - } -} - -#[unstable(feature = "proc_macro_span", issue = "54725")] -impl PartialOrd for LineColumn { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - /// The source file of a given `Span`. #[unstable(feature = "proc_macro_span", issue = "54725")] #[derive(Clone)] @@ -768,6 +739,7 @@ impl From for TokenTree { // N.B., the bridge only provides `to_string`, implement `fmt::Display` // based on it (the reverse of the usual relationship between the two). +#[doc(hidden)] #[stable(feature = "proc_macro_lib", since = "1.15.0")] impl ToString for TokenTree { fn to_string(&self) -> String { @@ -902,6 +874,7 @@ impl Group { // N.B., the bridge only provides `to_string`, implement `fmt::Display` // based on it (the reverse of the usual relationship between the two). +#[doc(hidden)] #[stable(feature = "proc_macro_lib", since = "1.15.0")] impl ToString for Group { fn to_string(&self) -> String { @@ -943,21 +916,34 @@ impl !Send for Punct {} #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl !Sync for Punct {} -/// Describes whether a `Punct` is followed immediately by another `Punct` ([`Spacing::Joint`]) or -/// by a different token or whitespace ([`Spacing::Alone`]). +/// Indicates whether a `Punct` token can join with the following token +/// to form a multi-character operator. #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub enum Spacing { - /// A `Punct` is not immediately followed by another `Punct`. - /// E.g. `+` is `Alone` in `+ =`, `+ident` and `+()`. - #[stable(feature = "proc_macro_lib2", since = "1.29.0")] - Alone, - /// A `Punct` is immediately followed by another `Punct`. - /// E.g. `+` is `Joint` in `+=` and `++`. + /// A `Punct` token can join with the following token to form a multi-character operator. + /// + /// In token streams constructed using proc macro interfaces `Joint` punctuation tokens can be + /// followed by any other tokens. \ + /// However, in token streams parsed from source code compiler will only set spacing to `Joint` + /// in the following cases: + /// - A `Punct` is immediately followed by another `Punct` without a whitespace. \ + /// E.g. `+` is `Joint` in `+=` and `++`. + /// - A single quote `'` is immediately followed by an identifier without a whitespace. \ + /// E.g. `'` is `Joint` in `'lifetime`. /// - /// Additionally, single quote `'` can join with identifiers to form lifetimes: `'ident`. + /// This list may be extended in the future to enable more token combinations. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] Joint, + /// A `Punct` token cannot join with the following token to form a multi-character operator. + /// + /// `Alone` punctuation tokens can be followed by any other tokens. \ + /// In token streams parsed from source code compiler will set spacing to `Alone` in all cases + /// not covered by the conditions for `Joint` above. \ + /// E.g. `+` is `Alone` in `+ =`, `+ident` and `+()`. + /// In particular, token not followed by anything will also be marked as `Alone`. + #[stable(feature = "proc_macro_lib2", since = "1.29.0")] + Alone, } impl Punct { @@ -989,10 +975,9 @@ impl Punct { self.0.ch as char } - /// Returns the spacing of this punctuation character, indicating whether it's immediately - /// followed by another `Punct` in the token stream, so they can potentially be combined into - /// a multi-character operator (`Joint`), or it's followed by some other token or whitespace - /// (`Alone`) so the operator has certainly ended. + /// Returns the spacing of this punctuation character, indicating whether it can be potentially + /// combined into a multi-character operator with the following token (`Joint`), or the operator + /// has certainly ended (`Alone`). #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn spacing(&self) -> Spacing { if self.0.joint { Spacing::Joint } else { Spacing::Alone } @@ -1011,6 +996,7 @@ impl Punct { } } +#[doc(hidden)] #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl ToString for Punct { fn to_string(&self) -> String { @@ -1113,8 +1099,7 @@ impl Ident { } } -/// Converts the identifier to a string that should be losslessly convertible -/// back into the same identifier. +#[doc(hidden)] #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl ToString for Ident { fn to_string(&self) -> String { @@ -1352,6 +1337,13 @@ impl Literal { Literal::new(bridge::LitKind::Char, symbol, None) } + /// Byte character literal. + #[unstable(feature = "proc_macro_byte_character", issue = "115268")] + pub fn byte_character(byte: u8) -> Literal { + let string = [byte].escape_ascii().to_string(); + Literal::new(bridge::LitKind::Byte, &string, None) + } + /// Byte string literal. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub fn byte_string(bytes: &[u8]) -> Literal { @@ -1426,7 +1418,15 @@ impl Literal { let hashes = get_hashes_str(n); f(&["br", hashes, "\"", symbol, "\"", hashes, suffix]) } - _ => f(&[symbol, suffix]), + bridge::LitKind::CStr => f(&["c\"", symbol, "\"", suffix]), + bridge::LitKind::CStrRaw(n) => { + let hashes = get_hashes_str(n); + f(&["cr", hashes, "\"", symbol, "\"", hashes, suffix]) + } + + bridge::LitKind::Integer | bridge::LitKind::Float | bridge::LitKind::Err => { + f(&[symbol, suffix]) + } }) } } @@ -1453,6 +1453,7 @@ impl FromStr for Literal { } } +#[doc(hidden)] #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl ToString for Literal { fn to_string(&self) -> String { @@ -1495,7 +1496,7 @@ pub mod tracked_env { use std::ffi::OsStr; /// Retrieve an environment variable and add it to build dependency info. - /// Build system executing the compiler will know that the variable was accessed during + /// The build system executing the compiler will know that the variable was accessed during /// compilation, and will be able to rerun the build when the value of that variable changes. /// Besides the dependency tracking this function should be equivalent to `env::var` from the /// standard library, except that the argument must be UTF-8. diff --git a/samplecode/crypto/enclave/Xargo.toml b/samplecode/crypto/enclave/Xargo.toml index 478f458c0..09f570e99 100644 --- a/samplecode/crypto/enclave/Xargo.toml +++ b/samplecode/crypto/enclave/Xargo.toml @@ -19,6 +19,6 @@ alloc = {} [dependencies.std] -path = "../../../../rustlib/std" +path = "../../../rustlib/std" features = ["net", "thread", "untrusted_fs", "untrusted_time", "unsupported_process"] stage = 1 diff --git a/samplecode/hyper-rustls-https-server/enclave/Xargo.toml b/samplecode/hyper-rustls-https-server/enclave/Xargo.toml index 478f458c0..09f570e99 100644 --- a/samplecode/hyper-rustls-https-server/enclave/Xargo.toml +++ b/samplecode/hyper-rustls-https-server/enclave/Xargo.toml @@ -19,6 +19,6 @@ alloc = {} [dependencies.std] -path = "../../../../rustlib/std" +path = "../../../rustlib/std" features = ["net", "thread", "untrusted_fs", "untrusted_time", "unsupported_process"] stage = 1 diff --git a/samplecode/hyper-rustls-https-server/enclave/src/lib.rs b/samplecode/hyper-rustls-https-server/enclave/src/lib.rs index 66ae597ca..72102bff9 100644 --- a/samplecode/hyper-rustls-https-server/enclave/src/lib.rs +++ b/samplecode/hyper-rustls-https-server/enclave/src/lib.rs @@ -209,7 +209,9 @@ async fn echo(req: Request) -> Result, hyper::Error> { match (req.method(), req.uri().path()) { // Help route. (&Method::GET, "/") => { - *response.body_mut() = Body::from("Try POST /echo\n"); + *response.body_mut() = Body::from( + "Try POSTing data to /echo such as: `curl https://127.0.0.1:1337/echo -XPOST -d 'hello world'`" + ); } // Echo service route. (&Method::POST, "/echo") => { diff --git a/samplecode/mutual-ra/enclave/Xargo.toml b/samplecode/mutual-ra/enclave/Xargo.toml index 478f458c0..09f570e99 100644 --- a/samplecode/mutual-ra/enclave/Xargo.toml +++ b/samplecode/mutual-ra/enclave/Xargo.toml @@ -19,6 +19,6 @@ alloc = {} [dependencies.std] -path = "../../../../rustlib/std" +path = "../../../rustlib/std" features = ["net", "thread", "untrusted_fs", "untrusted_time", "unsupported_process"] stage = 1 diff --git a/samplecode/rpc/client/Makefile b/samplecode/rpc/client/Makefile index 446d07ddc..5baa8177a 100644 --- a/samplecode/rpc/client/Makefile +++ b/samplecode/rpc/client/Makefile @@ -97,9 +97,10 @@ $(error Only supports building with build_std strategy!!) endif endif +enclave: export CARGO_FEATURE_STD=1 ifeq ($(BUILD_STD), cargo) Rust_Build_Std := $(Rust_Build_Flags) -Zbuild-std=core,alloc - Rust_Std_Features := --features net,thread,untrusted_time,untrusted_fs,unsupported_process + Rust_Std_Features := --features net,thread,untrusted_time,untrusted_fs,unsupported_process,capi Rust_Target_Flags := --target $(Rust_Target_Path)/$(Rust_Build_Target).json Rust_Sysroot_Path := $(CURDIR)/sysroot Rust_Sysroot_Flags := RUSTFLAGS="--sysroot $(Rust_Sysroot_Path)" diff --git a/samplecode/rpc/client/enclave/Cargo.toml b/samplecode/rpc/client/enclave/Cargo.toml index 2f46ce208..a0896ace5 100644 --- a/samplecode/rpc/client/enclave/Cargo.toml +++ b/samplecode/rpc/client/enclave/Cargo.toml @@ -29,10 +29,10 @@ crate-type = ["staticlib"] default = [] [dependencies] -prost = "0.11.0" +prost = "0.12" tokio = { version = "1.0", features = ["rt-multi-thread", "time", "fs", "macros", "net"] } -tonic = { version = "0.8.1", features = ["tls", "gzip"] } -sgx_libc = { path = "../../../../sgx_libc" } +tonic = { version = "0.10", features = ["tls", "gzip"] } +sgx_libc = { path = "../../../../sgx_libc", features = ["pthread"] } [build-dependencies] -tonic-build = { version = "0.8.0", features = ["prost"] } +tonic-build = { version = "0.10", features = ["prost"] } diff --git a/samplecode/rpc/server/Makefile b/samplecode/rpc/server/Makefile index 578ce6f42..4cd92d04f 100644 --- a/samplecode/rpc/server/Makefile +++ b/samplecode/rpc/server/Makefile @@ -97,9 +97,10 @@ $(error Only supports building with build_std strategy!!) endif endif +enclave: export CARGO_FEATURE_STD=1 ifeq ($(BUILD_STD), cargo) Rust_Build_Std := $(Rust_Build_Flags) -Z build-std=core,alloc - Rust_Std_Features := --features net,thread,untrusted_time,untrusted_fs,unsupported_process + Rust_Std_Features := --features net,thread,untrusted_time,untrusted_fs,unsupported_process,capi Rust_Target_Flags := --target $(Rust_Target_Path)/$(Rust_Build_Target).json Rust_Sysroot_Path := $(CURDIR)/sysroot Rust_Sysroot_Flags := RUSTFLAGS="--sysroot $(Rust_Sysroot_Path)" diff --git a/samplecode/rpc/server/enclave/Cargo.toml b/samplecode/rpc/server/enclave/Cargo.toml index a953605e4..b13a3b850 100644 --- a/samplecode/rpc/server/enclave/Cargo.toml +++ b/samplecode/rpc/server/enclave/Cargo.toml @@ -29,10 +29,10 @@ crate-type = ["staticlib"] default = [] [dependencies] -prost = "0.11.0" +prost = "0.12" tokio = { version = "1.0", features = ["rt-multi-thread", "time", "fs", "macros", "net"] } -tonic = { version = "0.8.1", features = ["tls", "gzip"] } -sgx_libc = { path = "../../../../sgx_libc" } +tonic = { version = "0.10", features = ["tls", "gzip"] } +sgx_libc = { path = "../../../../sgx_libc", features = ["pthread"] } [build-dependencies] -tonic-build = { version = "0.8.0", features = ["prost"] } +tonic-build = { version = "0.10", features = ["prost"] } diff --git a/samplecode/zlib-lazy-static-sample/enclave/Xargo.toml b/samplecode/zlib-lazy-static-sample/enclave/Xargo.toml index 478f458c0..09f570e99 100644 --- a/samplecode/zlib-lazy-static-sample/enclave/Xargo.toml +++ b/samplecode/zlib-lazy-static-sample/enclave/Xargo.toml @@ -19,6 +19,6 @@ alloc = {} [dependencies.std] -path = "../../../../rustlib/std" +path = "../../../rustlib/std" features = ["net", "thread", "untrusted_fs", "untrusted_time", "unsupported_process"] stage = 1 diff --git a/sgx_alloc/src/lib.rs b/sgx_alloc/src/lib.rs index 94f82717c..8af6102af 100644 --- a/sgx_alloc/src/lib.rs +++ b/sgx_alloc/src/lib.rs @@ -30,7 +30,6 @@ #![feature(alloc_layout_extra)] #![feature(core_intrinsics)] #![feature(dropck_eyepatch)] -#![feature(nonnull_slice_from_raw_parts)] #![feature(ptr_internals)] #![feature(slice_ptr_get)] diff --git a/sgx_backtrace/src/capture.rs b/sgx_backtrace/src/capture.rs index 138ff88da..8d48376b2 100644 --- a/sgx_backtrace/src/capture.rs +++ b/sgx_backtrace/src/capture.rs @@ -278,7 +278,7 @@ impl BacktraceFrame { /// This function requires the `std` feature of the `backtrace` crate to be /// enabled, and the `std` feature is enabled by default. pub fn ip(&self) -> *mut c_void { - self.frame.ip() as *mut c_void + self.frame.ip() } /// Same as `Frame::symbol_address` @@ -288,7 +288,7 @@ impl BacktraceFrame { /// This function requires the `std` feature of the `backtrace` crate to be /// enabled, and the `std` feature is enabled by default. pub fn symbol_address(&self) -> *mut c_void { - self.frame.symbol_address() as *mut c_void + self.frame.symbol_address() } /// Same as `Frame::module_base_address` @@ -298,9 +298,7 @@ impl BacktraceFrame { /// This function requires the `std` feature of the `backtrace` crate to be /// enabled, and the `std` feature is enabled by default. pub fn module_base_address(&self) -> Option<*mut c_void> { - self.frame - .module_base_address() - .map(|addr| addr as *mut c_void) + self.frame.module_base_address() } /// Returns the list of symbols that this frame corresponds to. diff --git a/sgx_backtrace/src/symbolize/mod.rs b/sgx_backtrace/src/symbolize/mod.rs index 8554ba1d6..3abd580f5 100644 --- a/sgx_backtrace/src/symbolize/mod.rs +++ b/sgx_backtrace/src/symbolize/mod.rs @@ -76,9 +76,10 @@ use sgx_demangle::{try_demangle, Demangle}; /// } /// ``` #[cfg(feature = "std")] +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn resolve(addr: *mut c_void, cb: F) { let _guard = crate::lock::lock(); - unsafe { resolve_unsynchronized(addr as *mut c_void, cb) } + unsafe { resolve_unsynchronized(addr, cb) } } /// Resolve a previously capture frame to a symbol, passing the symbol to the diff --git a/sgx_build_helper/build_helper/src/lib.rs b/sgx_build_helper/build_helper/src/lib.rs index fc2655326..f59e28cfb 100644 --- a/sgx_build_helper/build_helper/src/lib.rs +++ b/sgx_build_helper/build_helper/src/lib.rs @@ -61,7 +61,7 @@ pub fn restore_library_path() { println!("cargo:rerun-if-env-changed=REAL_LIBRARY_PATH"); let key = env::var_os("REAL_LIBRARY_PATH_VAR").expect("REAL_LIBRARY_PATH_VAR"); if let Some(env) = env::var_os("REAL_LIBRARY_PATH") { - env::set_var(&key, &env); + env::set_var(&key, env); } else { env::remove_var(&key); } @@ -245,7 +245,7 @@ impl NativeLibBoilerplate { let dir = self.out_dir.join("build/lib/darwin"); let name = format!("clang_rt.{}_osx_dynamic", sanitizer_name); - let src = dir.join(&format!("lib{}.dylib", name)); + let src = dir.join(format!("lib{}.dylib", name)); let new_name = format!("lib__rustc__{}.dylib", name); let dst = dir.join(&new_name); diff --git a/sgx_crypto/src/ecc/mod.rs b/sgx_crypto/src/ecc/mod.rs index dace996e5..4f7657f05 100644 --- a/sgx_crypto/src/ecc/mod.rs +++ b/sgx_crypto/src/ecc/mod.rs @@ -148,7 +148,7 @@ impl EcPrivateKey { sgx_calculate_ecdsa_priv_key( hash_drg.as_ptr(), hash_drg.len() as i32, - EcPrivateKey::NISTP256.as_ptr() as *const u8, + EcPrivateKey::NISTP256.as_ptr(), 32, &mut key.0.key as *mut _ as *mut u8, key.as_ref().len() as i32, diff --git a/sgx_crypto/src/sm/sm2/mod.rs b/sgx_crypto/src/sm/sm2/mod.rs index dbf86cc79..53cff256c 100644 --- a/sgx_crypto/src/sm/sm2/mod.rs +++ b/sgx_crypto/src/sm/sm2/mod.rs @@ -148,7 +148,7 @@ impl Sm2PrivateKey { sgx_calculate_sm2_priv_key( hash_drg.as_ptr(), hash_drg.len() as i32, - Sm2PrivateKey::SM2_ORDER.as_ptr() as *const u8, + Sm2PrivateKey::SM2_ORDER.as_ptr(), 32, &mut key.0.key as *mut _ as *mut u8, key.as_ref().len() as i32, diff --git a/sgx_dcap/tkey_exchange/src/capi/initiator.rs b/sgx_dcap/tkey_exchange/src/capi/initiator.rs index b11c518f5..d642a1f89 100644 --- a/sgx_dcap/tkey_exchange/src/capi/initiator.rs +++ b/sgx_dcap/tkey_exchange/src/capi/initiator.rs @@ -148,10 +148,7 @@ pub unsafe extern "C" fn sgx_dcap_mra_proc_msg2( } if !supplemental_data.is_null() - && !is_within_enclave( - supplemental_data as *const u8, - supplemental_data_size as usize, - ) + && !is_within_enclave(supplemental_data, supplemental_data_size as usize) { return SgxStatus::InvalidParameter; } diff --git a/sgx_dcap/tkey_exchange/src/capi/responder.rs b/sgx_dcap/tkey_exchange/src/capi/responder.rs index e7893602f..11d256c76 100644 --- a/sgx_dcap/tkey_exchange/src/capi/responder.rs +++ b/sgx_dcap/tkey_exchange/src/capi/responder.rs @@ -183,10 +183,7 @@ pub unsafe extern "C" fn sgx_dcap_mra_proc_msg3( } if !supplemental_data.is_null() - && !is_within_enclave( - supplemental_data as *const u8, - supplemental_data_size as usize, - ) + && !is_within_enclave(supplemental_data, supplemental_data_size as usize) { return SgxStatus::InvalidParameter; } diff --git a/sgx_dcap/tkey_exchange/src/lib.rs b/sgx_dcap/tkey_exchange/src/lib.rs index 75e165b57..666ecb990 100644 --- a/sgx_dcap/tkey_exchange/src/lib.rs +++ b/sgx_dcap/tkey_exchange/src/lib.rs @@ -17,7 +17,7 @@ #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] -#![feature(drain_filter)] +#![feature(extract_if)] #![allow(clippy::missing_safety_doc)] extern crate alloc; diff --git a/sgx_dcap/tkey_exchange/src/session/manager.rs b/sgx_dcap/tkey_exchange/src/session/manager.rs index eccf82435..de0f54c86 100644 --- a/sgx_dcap/tkey_exchange/src/session/manager.rs +++ b/sgx_dcap/tkey_exchange/src/session/manager.rs @@ -214,7 +214,7 @@ impl SessionManager { pub fn remove(&mut self, sid: u32) -> Option> { self.list - .drain_filter(|node| node.sid == sid) + .extract_if(|node| node.sid == sid) .next() .map(|node| node.session) } diff --git a/sgx_dcap/tvl/src/tvl.rs b/sgx_dcap/tvl/src/tvl.rs index 628e22b2c..9f95f0cc8 100644 --- a/sgx_dcap/tvl/src/tvl.rs +++ b/sgx_dcap/tvl/src/tvl.rs @@ -98,18 +98,18 @@ impl QveReportInfo<'_, '_> { } fn verify_identity(&self, qve_isvsvn_threshold: u16) -> SgxQuote3Result { + let misc_select = self.qve_report.body.misc_select & QVE_MISC_SELECT_MASK; ensure!( - self.qve_report.body.misc_select & QVE_MISC_SELECT_MASK == QVE_MISC_SELECT, + misc_select == QVE_MISC_SELECT, Quote3Error::QveIdentityMismatch ); + let flags = self.qve_report.body.attributes.flags & QVE_ATTRIBUTE_MASK.flags; ensure!( - self.qve_report.body.attributes.flags & QVE_ATTRIBUTE_MASK.flags == QVE_ATTRIBUTE.flags, - Quote3Error::QveIdentityMismatch - ); - ensure!( - self.qve_report.body.attributes.xfrm & QVE_ATTRIBUTE_MASK.xfrm == QVE_ATTRIBUTE.xfrm, + flags == QVE_ATTRIBUTE.flags, Quote3Error::QveIdentityMismatch ); + let xfrm = self.qve_report.body.attributes.xfrm & QVE_ATTRIBUTE_MASK.xfrm; + ensure!(xfrm == QVE_ATTRIBUTE.xfrm, Quote3Error::QveIdentityMismatch); ensure!( self.qve_report.body.mr_signer.eq(&QVE_MRSIGNER), Quote3Error::QveIdentityMismatch diff --git a/sgx_ffi/src/ascii.rs b/sgx_ffi/src/ascii.rs index 313eeb562..5f96fb86e 100644 --- a/sgx_ffi/src/ascii.rs +++ b/sgx_ffi/src/ascii.rs @@ -33,6 +33,8 @@ use alloc::vec::Vec; pub use core::ascii::{escape_default, EscapeDefault}; +pub use core::ascii::Char; + /// Extension methods for ASCII-subset only operations. /// /// Be aware that operations on seemingly non-ASCII characters can sometimes diff --git a/sgx_ffi/src/c_str.rs b/sgx_ffi/src/c_str.rs index 7c9b0f773..bce0e7ad3 100644 --- a/sgx_ffi/src/c_str.rs +++ b/sgx_ffi/src/c_str.rs @@ -16,4 +16,5 @@ // under the License.. pub use alloc::ffi::{CString, FromVecWithNulError, IntoStringError, NulError}; +pub use core::ffi::FromBytesUntilNulError; pub use core::ffi::{CStr, FromBytesWithNulError}; diff --git a/sgx_ffi/src/lib.rs b/sgx_ffi/src/lib.rs index fd8d5dc18..3c88849b5 100644 --- a/sgx_ffi/src/lib.rs +++ b/sgx_ffi/src/lib.rs @@ -17,6 +17,7 @@ #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] +#![feature(ascii_char)] extern crate alloc; extern crate sgx_types; diff --git a/sgx_key_exchange/tkey_exchange/src/lib.rs b/sgx_key_exchange/tkey_exchange/src/lib.rs index e1a936284..11e066d06 100644 --- a/sgx_key_exchange/tkey_exchange/src/lib.rs +++ b/sgx_key_exchange/tkey_exchange/src/lib.rs @@ -17,7 +17,7 @@ #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] -#![feature(drain_filter)] +#![feature(extract_if)] #![allow(clippy::missing_safety_doc)] extern crate alloc; diff --git a/sgx_key_exchange/tkey_exchange/src/session/manager.rs b/sgx_key_exchange/tkey_exchange/src/session/manager.rs index 2ada71a99..14b1b0432 100644 --- a/sgx_key_exchange/tkey_exchange/src/session/manager.rs +++ b/sgx_key_exchange/tkey_exchange/src/session/manager.rs @@ -162,7 +162,7 @@ impl SessionManager { pub fn remove(&mut self, sid: u32) -> Option> { self.list - .drain_filter(|node| node.sid == sid) + .extract_if(|node| node.sid == sid) .next() .map(|node| node.session) } diff --git a/sgx_key_exchange/ukey_exchange/src/lib.rs b/sgx_key_exchange/ukey_exchange/src/lib.rs index 03a339bfe..852d79e9f 100644 --- a/sgx_key_exchange/ukey_exchange/src/lib.rs +++ b/sgx_key_exchange/ukey_exchange/src/lib.rs @@ -16,7 +16,7 @@ // under the License.. #![feature(allocator_api)] -#![feature(once_cell)] +#![feature(lazy_cell)] #[cfg(all(feature = "sim", feature = "hyper"))] compile_error!("feature \"sim\" and feature \"hyper\" cannot be enabled at the same time"); diff --git a/sgx_libc/src/linux/pthread/mod.rs b/sgx_libc/src/linux/pthread/mod.rs index 4d1412a52..0e3d9627a 100644 --- a/sgx_libc/src/linux/pthread/mod.rs +++ b/sgx_libc/src/linux/pthread/mod.rs @@ -307,7 +307,7 @@ pub unsafe extern "C" fn pthread_once( ) -> c_int { check_param!(once_control, pthread_once_t); - let mut once_control = &mut *once_control; + let once_control = &mut *once_control; pthread_mutex_lock(&mut once_control.mutex); if once_control.state == PTHREAD_NEEDS_INIT { init_routine(); diff --git a/sgx_no_tstd/src/lib.rs b/sgx_no_tstd/src/lib.rs index 986ed9d2e..683511c48 100644 --- a/sgx_no_tstd/src/lib.rs +++ b/sgx_no_tstd/src/lib.rs @@ -20,12 +20,13 @@ #![feature(alloc_error_handler)] #![feature(lang_items)] +#![allow(internal_features)] + extern crate alloc as alloc_crate; extern crate sgx_alloc; extern crate sgx_trts; -use core::alloc::Layout; use core::panic::PanicInfo; use core::sync::atomic::{AtomicPtr, Ordering}; use core::{mem, ptr}; diff --git a/sgx_oc/src/lib.rs b/sgx_oc/src/lib.rs index 58ec7c98d..c891d666a 100644 --- a/sgx_oc/src/lib.rs +++ b/sgx_oc/src/lib.rs @@ -21,7 +21,6 @@ #![feature(error_in_core)] #![feature(const_extern_fn)] #![feature(negative_impls)] -#![feature(nonnull_slice_from_raw_parts)] #![feature(ptr_internals)] #![feature(slice_index_methods)] #![allow(clippy::missing_safety_doc)] diff --git a/sgx_oc/src/linux/mod.rs b/sgx_oc/src/linux/mod.rs index 1e0736ef4..b3f9f59ee 100644 --- a/sgx_oc/src/linux/mod.rs +++ b/sgx_oc/src/linux/mod.rs @@ -140,7 +140,7 @@ f! { { core::ptr::null_mut::() } else { - next as *mut cmsghdr + next } } @@ -184,7 +184,7 @@ pub unsafe extern "C" fn sigemptyset(set: *mut sigset_t) -> c_int { ocall::set_errno(EINVAL); return -1; }; - core::ptr::write_bytes(set as *mut sigset_t, 0, 1); + core::ptr::write_bytes(set, 0, 1); 0 } diff --git a/sgx_oc/src/linux/ocall/mod.rs b/sgx_oc/src/linux/ocall/mod.rs index bfa37a134..e450aa74a 100644 --- a/sgx_oc/src/linux/ocall/mod.rs +++ b/sgx_oc/src/linux/ocall/mod.rs @@ -299,6 +299,7 @@ fn check_host_buffer(buf: &[u8]) -> OCallResult<()> { Ok(()) } +#[allow(useless_ptr_null_checks)] #[inline] fn check_trusted_enclave_buffer(buf: &[u8]) -> OCallResult<()> { ensure!(!buf.as_ptr().is_null(), ecust!("Invalid null buffer.")); diff --git a/sgx_oc/src/linux/ocall/socket_msg.rs b/sgx_oc/src/linux/ocall/socket_msg.rs index 9d2f3de2c..81362ef64 100644 --- a/sgx_oc/src/linux/ocall/socket_msg.rs +++ b/sgx_oc/src/linux/ocall/socket_msg.rs @@ -79,7 +79,7 @@ impl<'a> MsgHdr<'a> { impl<'a> MsgHdrMut<'a> { pub unsafe fn from_raw(c_msg: &mut msghdr) -> Self { let name = new_optional_slice_mut(c_msg.msg_name as *mut u8, c_msg.msg_namelen as usize); - let iovs = new_optional_slice_mut(c_msg.msg_iov as *mut iovec, c_msg.msg_iovlen); + let iovs = new_optional_slice_mut(c_msg.msg_iov, c_msg.msg_iovlen); let control = new_optional_slice_mut(c_msg.msg_control as *mut u8, c_msg.msg_controllen); let flags = MsgHdrFlags::from_bits_truncate(c_msg.msg_flags); let iovs = iovs diff --git a/sgx_protected_fs/Cargo.toml b/sgx_protected_fs/Cargo.toml index 349e2970b..174f32f3d 100644 --- a/sgx_protected_fs/Cargo.toml +++ b/sgx_protected_fs/Cargo.toml @@ -16,6 +16,7 @@ # under the License. [workspace] +resolver = "2" members = [ "tfs", "ufs", diff --git a/sgx_protected_fs/tfs/src/sys/mod.rs b/sgx_protected_fs/tfs/src/sys/mod.rs index d34ed8873..19517eaea 100644 --- a/sgx_protected_fs/tfs/src/sys/mod.rs +++ b/sgx_protected_fs/tfs/src/sys/mod.rs @@ -25,6 +25,7 @@ use std::io::{Result, SeekFrom}; use std::mem::ManuallyDrop; use std::path::Path; +#[allow(unused_imports)] pub use file::DEFAULT_CACHE_SIZE; #[macro_use] diff --git a/sgx_protected_fs/tfs/src/sys/node.rs b/sgx_protected_fs/tfs/src/sys/node.rs index 5df3ec288..813aca3ee 100644 --- a/sgx_protected_fs/tfs/src/sys/node.rs +++ b/sgx_protected_fs/tfs/src/sys/node.rs @@ -15,6 +15,8 @@ // specific language governing permissions and limitations // under the License.. +#![allow(clippy::arc_with_non_send_sync)] + use crate::sys::cache::NodeRef; use crate::sys::error::FsResult; use crate::sys::host::HostFs; @@ -210,6 +212,8 @@ pub struct FileNode { pub parent: Option, } +unsafe impl Send for FileNode {} + impl FileNode { pub fn new( node_type: NodeType, diff --git a/sgx_rand/src/isaac.rs b/sgx_rand/src/isaac.rs index 0ca7194e8..13c5d4f23 100644 --- a/sgx_rand/src/isaac.rs +++ b/sgx_rand/src/isaac.rs @@ -534,7 +534,7 @@ impl Rng for Isaac64Rng { // See corresponding location in IsaacRng.next_u32 for // explanation. debug_assert!(self.cnt < RAND_SIZE_64); - self.rsl[(self.cnt % RAND_SIZE_64)].0 + self.rsl[self.cnt % RAND_SIZE_64].0 } } diff --git a/sgx_rsrvmm/src/lib.rs b/sgx_rsrvmm/src/lib.rs index 240104877..3f60fb0ea 100644 --- a/sgx_rsrvmm/src/lib.rs +++ b/sgx_rsrvmm/src/lib.rs @@ -17,7 +17,6 @@ #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] -#![feature(nonnull_slice_from_raw_parts)] #![feature(slice_ptr_get)] #![allow(clippy::missing_safety_doc)] diff --git a/sgx_rsrvmm/src/map.rs b/sgx_rsrvmm/src/map.rs index 28f1aacb3..6a6ffedc6 100644 --- a/sgx_rsrvmm/src/map.rs +++ b/sgx_rsrvmm/src/map.rs @@ -182,9 +182,10 @@ unsafe fn msync(addr: NonNull, size: NonZeroUsize) -> OsResult { rsrvmem.msync(addr.as_ptr() as usize, size.get()) } -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub enum MapAddr { /// Free to choose any address + #[default] Any, /// Prefer the address, but can use other address Hint(NonNull), @@ -194,12 +195,6 @@ pub enum MapAddr { Force(NonNull), } -impl Default for MapAddr { - fn default() -> MapAddr { - MapAddr::Any - } -} - pub trait Map: Any { /// Reads a number of bytes starting from a given offset. /// diff --git a/sgx_rsrvmm/src/rsrvmm/area.rs b/sgx_rsrvmm/src/rsrvmm/area.rs index 177653031..bb74c9345 100644 --- a/sgx_rsrvmm/src/rsrvmm/area.rs +++ b/sgx_rsrvmm/src/rsrvmm/area.rs @@ -33,8 +33,9 @@ use sgx_types::metadata::SE_PAGE_SHIFT; use sgx_types::types::ProtectPerm; #[allow(clippy::upper_case_acronyms)] -#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd)] pub enum MmPerm { + #[default] None, R, RW, @@ -57,12 +58,6 @@ impl MmPerm { } } -impl Default for MmPerm { - fn default() -> MmPerm { - MmPerm::None - } -} - impl From for MmPerm { fn from(perm: ProtectPerm) -> MmPerm { match perm { @@ -88,23 +83,19 @@ impl From for ProtectPerm { } #[allow(dead_code)] -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub enum MmType { + #[default] None, Reg, Tcs, Trim, } -impl Default for MmType { - fn default() -> MmType { - MmType::None - } -} - #[allow(dead_code)] -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub enum MmState { + #[default] Free, Reserved, SystemReserved, @@ -113,12 +104,6 @@ pub enum MmState { Locked, } -impl Default for MmState { - fn default() -> MmState { - MmState::Free - } -} - #[derive(Clone)] pub struct MmObject { object: Arc, diff --git a/sgx_rsrvmm/src/rsrvmm/manager.rs b/sgx_rsrvmm/src/rsrvmm/manager.rs index ec89dcaef..656bd7a3e 100644 --- a/sgx_rsrvmm/src/rsrvmm/manager.rs +++ b/sgx_rsrvmm/src/rsrvmm/manager.rs @@ -25,20 +25,15 @@ use sgx_trts::trts::MmLayout; use sgx_types::error::errno::*; use sgx_types::error::OsResult; -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub enum MmAllocAddr { - Any, // Free to choose any address + #[default] + Any, // Free to choose any address Hint(usize), // Prefer the address, but can use other address Need(usize), // Need to use the address, otherwise report error Force(usize), // Force using the address by free first } -impl Default for MmAllocAddr { - fn default() -> MmAllocAddr { - MmAllocAddr::Any - } -} - impl From for MmAllocAddr { fn from(addr: MapAddr) -> MmAllocAddr { match addr { diff --git a/sgx_serialize/src/lib.rs b/sgx_serialize/src/lib.rs index fa8f88caf..ff97eef0d 100644 --- a/sgx_serialize/src/lib.rs +++ b/sgx_serialize/src/lib.rs @@ -23,7 +23,6 @@ Core encoding and decoding interfaces. #![cfg_attr(all(feature = "tserialize", not(target_vendor = "teaclave")), no_std)] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] -#![feature(box_syntax)] #![feature(never_type)] #![feature(associated_type_bounds)] #![feature(min_specialization)] diff --git a/sgx_serialize/src/serialize.rs b/sgx_serialize/src/serialize.rs index d89d60159..caf211d7e 100644 --- a/sgx_serialize/src/serialize.rs +++ b/sgx_serialize/src/serialize.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -///! Support code for encoding and decoding types. +// Support code for encoding and decoding types. /* Core encoding and decoding interfaces. */ @@ -727,6 +727,6 @@ impl Encodable for Box { } impl Decodable for Box { fn decode(d: &mut D) -> Result, D::Error> { - Ok(box Decodable::decode(d)?) + Ok(Box::new(Decodable::decode(d)?)) } } diff --git a/sgx_sync/src/mutex.rs b/sgx_sync/src/mutex.rs index 3ba60cc97..ea8fee1d7 100644 --- a/sgx_sync/src/mutex.rs +++ b/sgx_sync/src/mutex.rs @@ -89,7 +89,7 @@ impl MovableMutex { /// Locks the mutex blocking the current thread until it is available. #[inline] - pub fn raw_lock(&self) { + pub fn lock(&self) { unsafe { self.0.lock() } } @@ -105,7 +105,7 @@ impl MovableMutex { /// Behavior is undefined if the current thread does not actually hold the /// mutex. #[inline] - pub unsafe fn raw_unlock(&self) { + pub unsafe fn unlock(&self) { self.0.unlock() } } @@ -118,7 +118,7 @@ impl Default for MovableMutex { impl RawMutex for MovableMutex { fn lock(&self) { - self.raw_lock() + self.lock() } fn try_lock(&self) -> bool { @@ -126,6 +126,6 @@ impl RawMutex for MovableMutex { } unsafe fn unlock(&self) { - self.raw_unlock() + self.unlock() } } diff --git a/sgx_sync/src/remutex/generic.rs b/sgx_sync/src/remutex/generic.rs index 77da8776d..e6d337864 100644 --- a/sgx_sync/src/remutex/generic.rs +++ b/sgx_sync/src/remutex/generic.rs @@ -115,7 +115,7 @@ impl ReentrantMutex { if self.owner.load(Relaxed) == this_thread { self.increment_lock_count(); } else { - self.mutex.raw_lock(); + self.mutex.lock(); self.owner.store(this_thread, Relaxed); debug_assert_eq!(*self.lock_count.get(), 0); *self.lock_count.get() = 1; @@ -177,7 +177,7 @@ impl Drop for ReentrantMutexGuard<'_, T> { *self.lock.lock_count.get() -= 1; if *self.lock.lock_count.get() == 0 { self.lock.owner.store(0, Relaxed); - self.lock.mutex.raw_unlock(); + self.lock.mutex.unlock(); } } } diff --git a/sgx_sync/src/sys/ocall/mod.rs b/sgx_sync/src/sys/ocall/mod.rs index 1d3fcca59..09a5f0016 100644 --- a/sgx_sync/src/sys/ocall/mod.rs +++ b/sgx_sync/src/sys/ocall/mod.rs @@ -314,7 +314,7 @@ pub fn thread_set_multiple_events(tcss: &[TcsId]) -> OsResult { u_thread_set_multiple_events_ocall( &mut result as *mut i32, &mut error as *mut i32, - tcss.as_ptr() as *const TcsId as *const usize, + tcss.as_ptr() as *const usize, tcss.len(), ) }; diff --git a/sgx_tdh/src/session/initiator.rs b/sgx_tdh/src/session/initiator.rs index 339034335..6bb02eabb 100644 --- a/sgx_tdh/src/session/initiator.rs +++ b/sgx_tdh/src/session/initiator.rs @@ -22,20 +22,15 @@ use sgx_trts::trts::EnclaveRange; use sgx_types::error::{SgxResult, SgxStatus}; use sgx_types::types::{AlignKey128bit, DhSessionRole}; -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] enum SessionState { Error, + #[default] WaitMsg1, WaitMsg3, Active, } -impl Default for SessionState { - fn default() -> SessionState { - SessionState::WaitMsg1 - } -} - #[derive(Debug)] pub struct Initiator { role: DhSessionRole, diff --git a/sgx_tdh/src/session/responder.rs b/sgx_tdh/src/session/responder.rs index b01617ce0..b6948cdfb 100644 --- a/sgx_tdh/src/session/responder.rs +++ b/sgx_tdh/src/session/responder.rs @@ -22,20 +22,15 @@ use sgx_trts::trts::EnclaveRange; use sgx_types::error::{SgxResult, SgxStatus}; use sgx_types::types::DhSessionRole; -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] enum SessionState { Error, + #[default] Reset, WaitM2, Active, } -impl Default for SessionState { - fn default() -> SessionState { - SessionState::Reset - } -} - #[derive(Debug)] pub struct Responder { role: DhSessionRole, diff --git a/sgx_tests/cov/src/lib.rs b/sgx_tests/cov/src/lib.rs index eff7f2271..1f8fd66b2 100644 --- a/sgx_tests/cov/src/lib.rs +++ b/sgx_tests/cov/src/lib.rs @@ -17,7 +17,6 @@ #![cfg_attr(not(target_vendor = "teaclave"), no_std)] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] -#![feature(once_cell)] #![allow(clippy::missing_safety_doc)] #[cfg(not(target_vendor = "teaclave"))] diff --git a/sgx_trts/src/arch.rs b/sgx_trts/src/arch.rs index c1d695a53..9ccd1daeb 100644 --- a/sgx_trts/src/arch.rs +++ b/sgx_trts/src/arch.rs @@ -17,7 +17,7 @@ #![allow(clippy::enum_variant_names)] -use crate::edmm::{PageInfo, PageType}; +use crate::edmm::{self, PageType}; use crate::tcs::tc; use crate::version::*; use core::convert::From; @@ -629,7 +629,7 @@ impl ExitInfo { impl_bitflags! { #[repr(C)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] - pub struct SecinfoFlags: u64 { + pub struct SecInfoFlags: u64 { const R = 0b0000_0000_0000_0001; const W = 0b0000_0000_0000_0010; const X = 0b0000_0000_0000_0100; @@ -648,9 +648,9 @@ impl_bitflags! { } } -impl SecinfoFlags { +impl SecInfoFlags { pub fn page_type(&self) -> u8 { - (((*self & SecinfoFlags::PT_MASK).bits()) >> 8) as u8 + (((*self & SecInfoFlags::PT_MASK).bits()) >> 8) as u8 } pub fn page_type_mut(&mut self) -> &mut u8 { @@ -661,102 +661,102 @@ impl SecinfoFlags { } } -impl From for SecinfoFlags { - fn from(data: PageType) -> SecinfoFlags { - SecinfoFlags::from_bits_truncate((data as u64) << 8) +impl From for SecInfoFlags { + fn from(data: PageType) -> SecInfoFlags { + SecInfoFlags::from_bits_truncate((data as u64) << 8) } } -impl From for SecinfoFlags { - fn from(data: PageInfo) -> SecinfoFlags { +impl From for SecInfoFlags { + fn from(data: edmm::PageInfo) -> SecInfoFlags { let typ = data.typ as u64; let flags = data.flags.bits() as u64; - SecinfoFlags::from_bits_truncate((typ << 8) | flags) + SecInfoFlags::from_bits_truncate((typ << 8) | flags) } } #[repr(C, align(64))] #[derive(Clone, Copy)] -pub struct Secinfo { - pub flags: SecinfoFlags, +pub struct SecInfo { + pub flags: SecInfoFlags, pub _reserved1: [u8; 56], } -impl fmt::Debug for Secinfo { +impl fmt::Debug for SecInfo { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt.debug_struct("Secinfo") + fmt.debug_struct("SecInfo") .field("flags", &self.flags.bits()) .finish() } } -impl Secinfo { - pub fn new(flags: SecinfoFlags) -> Secinfo { - Secinfo { +impl SecInfo { + pub fn new(flags: SecInfoFlags) -> SecInfo { + SecInfo { flags, _reserved1: [0_u8; 56], } } } -impl Default for Secinfo { - fn default() -> Secinfo { - Secinfo { - flags: SecinfoFlags::empty(), +impl Default for SecInfo { + fn default() -> SecInfo { + SecInfo { + flags: SecInfoFlags::empty(), _reserved1: [0_u8; 56], } } } -impl Secinfo { - pub const ALIGN_SIZE: usize = mem::size_of::(); +impl SecInfo { + pub const ALIGN_SIZE: usize = mem::size_of::(); } -impl AsRef<[u8; Secinfo::ALIGN_SIZE]> for Secinfo { - fn as_ref(&self) -> &[u8; Secinfo::ALIGN_SIZE] { +impl AsRef<[u8; SecInfo::ALIGN_SIZE]> for SecInfo { + fn as_ref(&self) -> &[u8; SecInfo::ALIGN_SIZE] { unsafe { &*(self as *const _ as *const _) } } } -impl AsRef> for Secinfo { - fn as_ref(&self) -> &Align64<[u8; Secinfo::ALIGN_SIZE]> { +impl AsRef> for SecInfo { + fn as_ref(&self) -> &Align64<[u8; SecInfo::ALIGN_SIZE]> { unsafe { &*(self as *const _ as *const _) } } } -impl From for Secinfo { - fn from(flags: SecinfoFlags) -> Secinfo { - Secinfo::new(flags) +impl From for SecInfo { + fn from(flags: SecInfoFlags) -> SecInfo { + SecInfo::new(flags) } } -impl From for Secinfo { - fn from(data: PageInfo) -> Secinfo { - Secinfo::from(SecinfoFlags::from(data)) +impl From for SecInfo { + fn from(data: edmm::PageInfo) -> SecInfo { + SecInfo::from(SecInfoFlags::from(data)) } } #[repr(C, align(32))] #[derive(Clone, Copy, Debug)] -pub struct Pageinfo { +pub struct PageInfo { pub linaddr: u64, pub srcpage: u64, pub secinfo: u64, pub secs: u64, } -impl Pageinfo { - pub const ALIGN_SIZE: usize = mem::size_of::(); +impl PageInfo { + pub const ALIGN_SIZE: usize = mem::size_of::(); } -impl AsRef<[u8; Pageinfo::ALIGN_SIZE]> for Pageinfo { - fn as_ref(&self) -> &[u8; Pageinfo::ALIGN_SIZE] { +impl AsRef<[u8; PageInfo::ALIGN_SIZE]> for PageInfo { + fn as_ref(&self) -> &[u8; PageInfo::ALIGN_SIZE] { unsafe { &*(self as *const _ as *const _) } } } -impl AsRef> for Pageinfo { - fn as_ref(&self) -> &Align32<[u8; Pageinfo::ALIGN_SIZE]> { +impl AsRef> for PageInfo { + fn as_ref(&self) -> &Align32<[u8; PageInfo::ALIGN_SIZE]> { unsafe { &*(self as *const _ as *const _) } } } diff --git a/sgx_trts/src/edmm/epc.rs b/sgx_trts/src/edmm/epc.rs index 446ecec8d..05c966ad1 100644 --- a/sgx_trts/src/edmm/epc.rs +++ b/sgx_trts/src/edmm/epc.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -use crate::arch::{Secinfo, SE_PAGE_SHIFT, SE_PAGE_SIZE}; +use crate::arch::{SecInfo, SE_PAGE_SHIFT, SE_PAGE_SIZE}; use crate::enclave::is_within_enclave; use crate::inst::EncluInst; use core::num::NonZeroUsize; @@ -204,12 +204,12 @@ impl Page { } pub fn accept(&self) -> SgxResult { - let secinfo: Secinfo = self.info.into(); + let secinfo: SecInfo = self.info.into(); EncluInst::eaccept(&secinfo, self.addr).map_err(|_| SgxStatus::Unexpected) } pub fn modpe(&self) -> SgxResult { - let secinfo: Secinfo = self.info.into(); + let secinfo: SecInfo = self.info.into(); EncluInst::emodpe(&secinfo, self.addr).map_err(|_| SgxStatus::Unexpected) } } diff --git a/sgx_trts/src/enclave/mem.rs b/sgx_trts/src/enclave/mem.rs index db578f84f..003a6b485 100644 --- a/sgx_trts/src/enclave/mem.rs +++ b/sgx_trts/src/enclave/mem.rs @@ -106,7 +106,7 @@ static mut IMAGE: MaybeUninit = MaybeUninit::uninit(); impl Image { pub fn init() { - let mut image = unsafe { IMAGE.assume_init_mut() }; + let image = unsafe { IMAGE.assume_init_mut() }; image.image_base = Self::image_base(); image.image_size = Self::image_size(); image.elrange_base = Self::elrange_base(); diff --git a/sgx_trts/src/enclave/mod.rs b/sgx_trts/src/enclave/mod.rs index afaa2b064..ec05e154c 100644 --- a/sgx_trts/src/enclave/mod.rs +++ b/sgx_trts/src/enclave/mod.rs @@ -15,6 +15,8 @@ // specific language governing permissions and limitations // under the License.. +#![allow(unused_imports)] + mod atexit; mod entry; mod init; diff --git a/sgx_trts/src/inst/hw/inst.rs b/sgx_trts/src/inst/hw/inst.rs index c5264f2bc..69b28cec8 100644 --- a/sgx_trts/src/inst/hw/inst.rs +++ b/sgx_trts/src/inst/hw/inst.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -use crate::arch::{Enclu, Secinfo}; +use crate::arch::{Enclu, SecInfo}; use crate::se::{ AlignKey, AlignKeyRequest, AlignReport, AlignReport2Mac, AlignReportData, AlignTargetInfo, }; @@ -75,7 +75,7 @@ impl EncluInst { } } - pub fn eaccept(info: &Secinfo, addr: usize) -> Result<(), u32> { + pub fn eaccept(info: &SecInfo, addr: usize) -> Result<(), u32> { unsafe { let error; asm!( @@ -94,7 +94,7 @@ impl EncluInst { } } - pub fn emodpe(info: &Secinfo, addr: usize) -> Result<(), u32> { + pub fn emodpe(info: &SecInfo, addr: usize) -> Result<(), u32> { unsafe { asm!( "xchg rbx, {0}", diff --git a/sgx_trts/src/inst/hyper/inst.rs b/sgx_trts/src/inst/hyper/inst.rs index be4c2da5d..ebff9321c 100644 --- a/sgx_trts/src/inst/hyper/inst.rs +++ b/sgx_trts/src/inst/hyper/inst.rs @@ -17,7 +17,7 @@ #![allow(clippy::enum_variant_names)] -use crate::arch::Secinfo; +use crate::arch::SecInfo; use crate::inst::INVALID_LEAF; use crate::se::{ AlignKey, AlignKeyRequest, AlignReport, AlignReport2Mac, AlignReportData, AlignTargetInfo, @@ -93,12 +93,12 @@ impl EncluInst { } #[inline] - pub fn eaccept(_info: &Secinfo, _addr: usize) -> Result<(), u32> { + pub fn eaccept(_info: &SecInfo, _addr: usize) -> Result<(), u32> { Ok(()) } #[inline] - pub fn emodpe(_info: &Secinfo, _addr: usize) -> Result<(), u32> { + pub fn emodpe(_info: &SecInfo, _addr: usize) -> Result<(), u32> { Ok(()) } } diff --git a/sgx_trts/src/inst/hyper/mod.rs b/sgx_trts/src/inst/hyper/mod.rs index 00989896e..9d638b5f9 100644 --- a/sgx_trts/src/inst/hyper/mod.rs +++ b/sgx_trts/src/inst/hyper/mod.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -use crate::arch::{Enclu, Secinfo}; +use crate::arch::{Enclu, SecInfo}; use crate::call::MsbufInfo; use crate::error::abort; use crate::fence::lfence; @@ -63,11 +63,11 @@ pub unsafe extern "C" fn se3( } Err(e) => e as usize, }, - Enclu::EAccept => match EncluInst::eaccept(&*(rbx as *const Secinfo), rcx) { + Enclu::EAccept => match EncluInst::eaccept(&*(rbx as *const SecInfo), rcx) { Ok(_) => 0, Err(e) => e as usize, }, - Enclu::EModpe => match EncluInst::emodpe(&*(rbx as *const Secinfo), rcx) { + Enclu::EModpe => match EncluInst::emodpe(&*(rbx as *const SecInfo), rcx) { Ok(_) => 0, Err(e) => e as usize, }, diff --git a/sgx_trts/src/inst/sim/inst.rs b/sgx_trts/src/inst/sim/inst.rs index dc8fb43d0..3b939ed7d 100644 --- a/sgx_trts/src/inst/sim/inst.rs +++ b/sgx_trts/src/inst/sim/inst.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -use crate::arch::{Secinfo, Tcs}; +use crate::arch::{SecInfo, Tcs}; use crate::enclave::EnclaveRange; use crate::error::abort as gp; use crate::inst::sim::derive::{self, DeriveData, SeOwnerEpoch}; @@ -404,12 +404,12 @@ impl EncluInst { } #[inline] - pub fn eaccept(_info: &Secinfo, _addr: usize) -> Result<(), u32> { + pub fn eaccept(_info: &SecInfo, _addr: usize) -> Result<(), u32> { Ok(()) } #[inline] - pub fn emodpe(_info: &Secinfo, _addr: usize) -> Result<(), u32> { + pub fn emodpe(_info: &SecInfo, _addr: usize) -> Result<(), u32> { Ok(()) } diff --git a/sgx_trts/src/inst/sim/mod.rs b/sgx_trts/src/inst/sim/mod.rs index e89942b10..5d047a838 100644 --- a/sgx_trts/src/inst/sim/mod.rs +++ b/sgx_trts/src/inst/sim/mod.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -use crate::arch::{Enclu, Secinfo, Secs, Tcs}; +use crate::arch::{Enclu, SecInfo, Secs, Tcs}; use crate::error::abort; use crate::se::{AlignKey, AlignKeyRequest, AlignReport, AlignReportData, AlignTargetInfo}; use core::convert::TryFrom; @@ -66,11 +66,11 @@ pub unsafe extern "C" fn se3( } Err(e) => e as usize, }, - Enclu::EAccept => match EncluInst::eaccept(&*(rbx as *const Secinfo), rcx) { + Enclu::EAccept => match EncluInst::eaccept(&*(rbx as *const SecInfo), rcx) { Ok(_) => 0, Err(e) => e as usize, }, - Enclu::EModpe => match EncluInst::emodpe(&*(rbx as *const Secinfo), rcx) { + Enclu::EModpe => match EncluInst::emodpe(&*(rbx as *const SecInfo), rcx) { Ok(_) => 0, Err(e) => e as usize, }, diff --git a/sgx_trts/src/lib.rs b/sgx_trts/src/lib.rs index 2a1babfc1..5bd39df14 100644 --- a/sgx_trts/src/lib.rs +++ b/sgx_trts/src/lib.rs @@ -22,12 +22,11 @@ #![feature(allocator_api)] #![feature(const_trait_impl)] #![feature(core_intrinsics)] -#![feature(drain_filter)] +#![feature(extract_if)] #![feature(maybe_uninit_uninit_array)] #![feature(min_specialization)] #![feature(negative_impls)] #![feature(never_type)] -#![feature(nonnull_slice_from_raw_parts)] #![feature(ptr_internals)] #![feature(thread_local)] #![cfg_attr(feature = "sim", feature(unchecked_math))] diff --git a/sgx_trts/src/tcs/list.rs b/sgx_trts/src/tcs/list.rs index 2111ec197..1358983a6 100644 --- a/sgx_trts/src/tcs/list.rs +++ b/sgx_trts/src/tcs/list.rs @@ -47,7 +47,7 @@ impl TcsList { pub fn del_tcs(&mut self, tcs: NonNull) -> Option> { let node = TcsNode::new(tcs, self.cookie()); - let node = self.list.drain_filter(|n| *n == node).next(); + let node = self.list.extract_if(|n| *n == node).next(); node.map(|n| n.as_tcs(self.cookie())) } diff --git a/sgx_trts/src/thread/native.rs b/sgx_trts/src/thread/native.rs index 7aa42ec8b..83e5c7143 100644 --- a/sgx_trts/src/thread/native.rs +++ b/sgx_trts/src/thread/native.rs @@ -54,6 +54,8 @@ struct Inner { retval: *mut c_void, } +unsafe impl Send for Inner {} + impl Thread { pub fn new(p: F, arg: *mut c_void) -> SgxResult where diff --git a/sgx_trts/src/veh/list.rs b/sgx_trts/src/veh/list.rs index 2cc2eb769..64ad66815 100644 --- a/sgx_trts/src/veh/list.rs +++ b/sgx_trts/src/veh/list.rs @@ -70,7 +70,7 @@ impl ExceptionList { } pub fn remove(&mut self, id: Handle) -> Option { - self.list.drain_filter(|node| node.id() == id).next() + self.list.extract_if(|node| node.id() == id).next() } #[inline] diff --git a/sgx_tstd/hashbrown/Cargo.toml b/sgx_tstd/hashbrown/Cargo.toml index 6927577ae..81b3a9c04 100644 --- a/sgx_tstd/hashbrown/Cargo.toml +++ b/sgx_tstd/hashbrown/Cargo.toml @@ -1,31 +1,39 @@ [package] name = "hashbrown_tstd" -version = "0.12.0" +version = "0.14.2" authors = ["Amanieu d'Antras "] description = "A Rust port of Google's SwissTable hash map" -license = "Apache-2.0/MIT" +license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/hashbrown" readme = "README.md" keywords = ["hash", "no_std", "hashmap", "swisstable"] categories = ["data-structures", "no-std"] -exclude = [".github", "bors.toml", "/ci/*"] +exclude = [".github", "/ci/*"] edition = "2021" [dependencies] # For the default hasher -ahash = { version = "0.7.0", default-features = false, optional = true } +ahash = { version = "0.8.0", default-features = false, optional = true } # For external trait impls rayon = { version = "1.0", optional = true } serde = { version = "1.0.25", default-features = false, optional = true } +rkyv = { version = "0.7.42", optional = true, default-features = false, features = [ + "alloc", +] } # When built as part of libstd # core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" } # compiler_builtins = { version = "0.1.2", optional = true } # alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-alloc" } -# Optional support for bumpalo -bumpalo = { version = "3.5.0", optional = true } +# Support for allocators that use allocator-api2 +allocator-api2 = { version = "0.2.9", optional = true, default-features = false, features = [ + "alloc", +] } + +# Equivalent trait which can be shared with other hash table implementations. +equivalent = { version = "1.0", optional = true, default-features = false } [dev-dependencies] lazy_static = "1.4" @@ -34,12 +42,14 @@ rayon = "1.0" fnv = "1.0.7" serde_test = "1.0" doc-comment = "0.3.1" +bumpalo = { version = "3.13.0", features = ["allocator-api2"] } +rkyv = { version = "0.7.42", features = ["validation"] } [features] -default = ["ahash", "inline-more"] +default = ["ahash", "inline-more", "allocator-api2"] + +nightly = ["allocator-api2?/nightly", "bumpalo/allocator_api"] -ahash-compile-time-rng = ["ahash/compile-time-rng"] -nightly = [] rustc-internal-api = [] # rustc-dep-of-std = [ # "nightly", @@ -61,3 +71,4 @@ inline-more = [] [package.metadata.docs.rs] features = ["nightly", "rayon", "serde", "raw"] +rustdoc-args = ["--generate-link-to-definition"] diff --git a/sgx_tstd/hashbrown/benches/bench.rs b/sgx_tstd/hashbrown/benches/bench.rs index c393b9a70..346bd7ef8 100644 --- a/sgx_tstd/hashbrown/benches/bench.rs +++ b/sgx_tstd/hashbrown/benches/bench.rs @@ -311,7 +311,7 @@ fn rehash_in_place(b: &mut Bencher) { // Each loop triggers one rehash for _ in 0..10 { - for i in 0..224 { + for i in 0..223 { set.insert(i); } diff --git a/sgx_tstd/hashbrown/ci/miri.sh b/sgx_tstd/hashbrown/ci/miri.sh index 6b95c2d97..8ea3e52db 100644 --- a/sgx_tstd/hashbrown/ci/miri.sh +++ b/sgx_tstd/hashbrown/ci/miri.sh @@ -5,11 +5,8 @@ set -ex export CARGO_NET_RETRY=5 export CARGO_NET_TIMEOUT=10 -MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri) -echo "Installing latest nightly with Miri: $MIRI_NIGHTLY" -rustup default "$MIRI_NIGHTLY" - -rustup component add miri +rustup toolchain install nightly --component miri +rustup override set nightly cargo miri setup -cargo miri test +MIRIFLAGS='-Zmiri-strict-provenance' cargo miri test --features nightly diff --git a/sgx_tstd/hashbrown/ci/run.sh b/sgx_tstd/hashbrown/ci/run.sh index a8257e559..3d14c780a 100644 --- a/sgx_tstd/hashbrown/ci/run.sh +++ b/sgx_tstd/hashbrown/ci/run.sh @@ -9,20 +9,23 @@ if [ "${NO_STD}" = "1" ]; then FEATURES="rustc-internal-api" OP="build" else - FEATURES="rustc-internal-api,serde,rayon,raw,bumpalo" + FEATURES="rustc-internal-api,serde,rayon,raw" OP="test" fi if [ "${CHANNEL}" = "nightly" ]; then FEATURES="${FEATURES},nightly" export RUSTFLAGS="$RUSTFLAGS -D warnings" fi +if [ "${CHANNEL}" = "1.63.0" ]; then + cargo update --package allocator-api2 --precise 0.2.9 +fi CARGO=cargo if [ "${CROSS}" = "1" ]; then export CARGO_NET_RETRY=5 export CARGO_NET_TIMEOUT=10 - cargo install --git https://github.com/rust-embedded/cross.git + cargo install --locked cross CARGO=cross fi diff --git a/sgx_tstd/hashbrown/ci/tools.sh b/sgx_tstd/hashbrown/ci/tools.sh index 5ae8b2e8a..4e8040508 100644 --- a/sgx_tstd/hashbrown/ci/tools.sh +++ b/sgx_tstd/hashbrown/ci/tools.sh @@ -30,9 +30,8 @@ if retry rustup component add rustfmt ; then fi if retry rustup component add clippy ; then - cargo clippy --all --tests --features serde,rayon,bumpalo -- -D clippy::all -D clippy::pedantic - cargo clippy --all --tests --features raw -- -D clippy::all -D clippy::pedantic \ - -A clippy::missing_safety_doc -A clippy::missing_errors_doc + cargo clippy --all --tests --features serde,rayon -- -D clippy::all + cargo clippy --all --tests --features raw -- -D clippy::all fi if command -v shellcheck ; then diff --git a/sgx_tstd/hashbrown/src/external_trait_impls/mod.rs b/sgx_tstd/hashbrown/src/external_trait_impls/mod.rs index ef497836c..01d386b04 100644 --- a/sgx_tstd/hashbrown/src/external_trait_impls/mod.rs +++ b/sgx_tstd/hashbrown/src/external_trait_impls/mod.rs @@ -1,4 +1,6 @@ #[cfg(feature = "rayon")] pub(crate) mod rayon; +#[cfg(feature = "rkyv")] +mod rkyv; #[cfg(feature = "serde")] mod serde; diff --git a/sgx_tstd/hashbrown/src/external_trait_impls/rayon/map.rs b/sgx_tstd/hashbrown/src/external_trait_impls/rayon/map.rs index 14d91c220..2534dc9b2 100644 --- a/sgx_tstd/hashbrown/src/external_trait_impls/rayon/map.rs +++ b/sgx_tstd/hashbrown/src/external_trait_impls/rayon/map.rs @@ -232,11 +232,11 @@ impl fmt::Debug for ParValuesMut<'_, K, V> { /// [`into_par_iter`]: /hashbrown/struct.HashMap.html#method.into_par_iter /// [`HashMap`]: /hashbrown/struct.HashMap.html /// [`IntoParallelIterator`]: https://docs.rs/rayon/1.0/rayon/iter/trait.IntoParallelIterator.html -pub struct IntoParIter { +pub struct IntoParIter { inner: RawIntoParIter<(K, V), A>, } -impl ParallelIterator for IntoParIter { +impl ParallelIterator for IntoParIter { type Item = (K, V); #[cfg_attr(feature = "inline-more", inline)] @@ -248,9 +248,7 @@ impl ParallelIterator for IntoPar } } -impl fmt::Debug - for IntoParIter -{ +impl fmt::Debug for IntoParIter { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { ParIter { inner: unsafe { self.inner.par_iter() }, @@ -267,11 +265,11 @@ impl fmt::Debug /// /// [`par_drain`]: /hashbrown/struct.HashMap.html#method.par_drain /// [`HashMap`]: /hashbrown/struct.HashMap.html -pub struct ParDrain<'a, K, V, A: Allocator + Clone = Global> { +pub struct ParDrain<'a, K, V, A: Allocator = Global> { inner: RawParDrain<'a, (K, V), A>, } -impl ParallelIterator for ParDrain<'_, K, V, A> { +impl ParallelIterator for ParDrain<'_, K, V, A> { type Item = (K, V); #[cfg_attr(feature = "inline-more", inline)] @@ -283,9 +281,7 @@ impl ParallelIterator for ParDrai } } -impl fmt::Debug - for ParDrain<'_, K, V, A> -{ +impl fmt::Debug for ParDrain<'_, K, V, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { ParIter { inner: unsafe { self.inner.par_iter() }, @@ -295,7 +291,7 @@ impl fmt::Debug } } -impl HashMap { +impl HashMap { /// Visits (potentially in parallel) immutably borrowed keys in an arbitrary order. #[cfg_attr(feature = "inline-more", inline)] pub fn par_keys(&self) -> ParKeys<'_, K, V> { @@ -315,7 +311,7 @@ impl HashMap { } } -impl HashMap { +impl HashMap { /// Visits (potentially in parallel) mutably borrowed values in an arbitrary order. #[cfg_attr(feature = "inline-more", inline)] pub fn par_values_mut(&mut self) -> ParValuesMut<'_, K, V> { @@ -340,7 +336,7 @@ where K: Eq + Hash + Sync, V: PartialEq + Sync, S: BuildHasher + Sync, - A: Allocator + Clone + Sync, + A: Allocator + Sync, { /// Returns `true` if the map is equal to another, /// i.e. both maps contain the same keys mapped to the same values. @@ -354,9 +350,7 @@ where } } -impl IntoParallelIterator - for HashMap -{ +impl IntoParallelIterator for HashMap { type Item = (K, V); type Iter = IntoParIter; @@ -368,9 +362,7 @@ impl IntoParallelIterator } } -impl<'a, K: Sync, V: Sync, S, A: Allocator + Clone> IntoParallelIterator - for &'a HashMap -{ +impl<'a, K: Sync, V: Sync, S, A: Allocator> IntoParallelIterator for &'a HashMap { type Item = (&'a K, &'a V); type Iter = ParIter<'a, K, V>; @@ -383,9 +375,7 @@ impl<'a, K: Sync, V: Sync, S, A: Allocator + Clone> IntoParallelIterator } } -impl<'a, K: Sync, V: Send, S, A: Allocator + Clone> IntoParallelIterator - for &'a mut HashMap -{ +impl<'a, K: Sync, V: Send, S, A: Allocator> IntoParallelIterator for &'a mut HashMap { type Item = (&'a K, &'a mut V); type Iter = ParIterMut<'a, K, V>; @@ -424,7 +414,7 @@ where K: Eq + Hash + Send, V: Send, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { fn par_extend(&mut self, par_iter: I) where @@ -440,7 +430,7 @@ where K: Copy + Eq + Hash + Sync, V: Copy + Sync, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { fn par_extend(&mut self, par_iter: I) where @@ -456,7 +446,7 @@ where K: Eq + Hash, S: BuildHasher, I: IntoParallelIterator, - A: Allocator + Clone, + A: Allocator, HashMap: Extend, { let (list, len) = super::helpers::collect(par_iter); @@ -561,10 +551,7 @@ mod test_par_map { assert_eq!(value.load(Ordering::Relaxed), 100); // retain only half - let _v: Vec<_> = hm - .into_par_iter() - .filter(|&(ref key, _)| key.k < 50) - .collect(); + let _v: Vec<_> = hm.into_par_iter().filter(|(key, _)| key.k < 50).collect(); assert_eq!(key.load(Ordering::Relaxed), 50); assert_eq!(value.load(Ordering::Relaxed), 50); @@ -611,7 +598,7 @@ mod test_par_map { assert_eq!(value.load(Ordering::Relaxed), 100); // retain only half - let _v: Vec<_> = hm.drain().filter(|&(ref key, _)| key.k < 50).collect(); + let _v: Vec<_> = hm.drain().filter(|(key, _)| key.k < 50).collect(); assert!(hm.is_empty()); assert_eq!(key.load(Ordering::Relaxed), 50); diff --git a/sgx_tstd/hashbrown/src/external_trait_impls/rayon/mod.rs b/sgx_tstd/hashbrown/src/external_trait_impls/rayon/mod.rs index 99337a1ce..61ca69b61 100644 --- a/sgx_tstd/hashbrown/src/external_trait_impls/rayon/mod.rs +++ b/sgx_tstd/hashbrown/src/external_trait_impls/rayon/mod.rs @@ -2,3 +2,4 @@ mod helpers; pub(crate) mod map; pub(crate) mod raw; pub(crate) mod set; +pub(crate) mod table; diff --git a/sgx_tstd/hashbrown/src/external_trait_impls/rayon/raw.rs b/sgx_tstd/hashbrown/src/external_trait_impls/rayon/raw.rs index 883303e27..612be47a5 100644 --- a/sgx_tstd/hashbrown/src/external_trait_impls/rayon/raw.rs +++ b/sgx_tstd/hashbrown/src/external_trait_impls/rayon/raw.rs @@ -1,7 +1,6 @@ use crate::raw::Bucket; use crate::raw::{Allocator, Global, RawIter, RawIterRange, RawTable}; use crate::scopeguard::guard; -use alloc::alloc::dealloc; use core::marker::PhantomData; use core::mem; use core::ptr::NonNull; @@ -76,18 +75,18 @@ impl UnindexedProducer for ParIterProducer { } /// Parallel iterator which consumes a table and returns elements. -pub struct RawIntoParIter { +pub struct RawIntoParIter { table: RawTable, } -impl RawIntoParIter { +impl RawIntoParIter { #[cfg_attr(feature = "inline-more", inline)] pub(super) unsafe fn par_iter(&self) -> RawParIter { self.table.par_iter() } } -impl ParallelIterator for RawIntoParIter { +impl ParallelIterator for RawIntoParIter { type Item = T; #[cfg_attr(feature = "inline-more", inline)] @@ -97,9 +96,9 @@ impl ParallelIterator for RawIntoParIter ParallelIterator for RawIntoParIter { +pub struct RawParDrain<'a, T, A: Allocator = Global> { // We don't use a &'a mut RawTable because we want RawParDrain to be // covariant over T. table: NonNull>, marker: PhantomData<&'a RawTable>, } -unsafe impl Send for RawParDrain<'_, T, A> {} +unsafe impl Send for RawParDrain<'_, T, A> {} -impl RawParDrain<'_, T, A> { +impl RawParDrain<'_, T, A> { #[cfg_attr(feature = "inline-more", inline)] pub(super) unsafe fn par_iter(&self) -> RawParIter { self.table.as_ref().par_iter() } } -impl ParallelIterator for RawParDrain<'_, T, A> { +impl ParallelIterator for RawParDrain<'_, T, A> { type Item = T; #[cfg_attr(feature = "inline-more", inline)] @@ -143,7 +142,7 @@ impl ParallelIterator for RawParDrain<'_, T, A> { } } -impl Drop for RawParDrain<'_, T, A> { +impl Drop for RawParDrain<'_, T, A> { fn drop(&mut self) { // If drive_unindexed is not called then simply clear the table. unsafe { @@ -204,7 +203,7 @@ impl Drop for ParDrainProducer { } } -impl RawTable { +impl RawTable { /// Returns a parallel iterator over the elements in a `RawTable`. #[cfg_attr(feature = "inline-more", inline)] pub unsafe fn par_iter(&self) -> RawParIter { diff --git a/sgx_tstd/hashbrown/src/external_trait_impls/rayon/set.rs b/sgx_tstd/hashbrown/src/external_trait_impls/rayon/set.rs index ee4f6e669..3de98fccb 100644 --- a/sgx_tstd/hashbrown/src/external_trait_impls/rayon/set.rs +++ b/sgx_tstd/hashbrown/src/external_trait_impls/rayon/set.rs @@ -16,11 +16,11 @@ use rayon::iter::{FromParallelIterator, IntoParallelIterator, ParallelExtend, Pa /// [`into_par_iter`]: /hashbrown/struct.HashSet.html#method.into_par_iter /// [`HashSet`]: /hashbrown/struct.HashSet.html /// [`IntoParallelIterator`]: https://docs.rs/rayon/1.0/rayon/iter/trait.IntoParallelIterator.html -pub struct IntoParIter { +pub struct IntoParIter { inner: map::IntoParIter, } -impl ParallelIterator for IntoParIter { +impl ParallelIterator for IntoParIter { type Item = T; fn drive_unindexed(self, consumer: C) -> C::Result @@ -38,11 +38,11 @@ impl ParallelIterator for IntoParIter { +pub struct ParDrain<'a, T, A: Allocator = Global> { inner: map::ParDrain<'a, T, (), A>, } -impl ParallelIterator for ParDrain<'_, T, A> { +impl ParallelIterator for ParDrain<'_, T, A> { type Item = T; fn drive_unindexed(self, consumer: C) -> C::Result @@ -85,7 +85,7 @@ impl<'a, T: Sync> ParallelIterator for ParIter<'a, T> { /// /// [`par_difference`]: /hashbrown/struct.HashSet.html#method.par_difference /// [`HashSet`]: /hashbrown/struct.HashSet.html -pub struct ParDifference<'a, T, S, A: Allocator + Clone = Global> { +pub struct ParDifference<'a, T, S, A: Allocator = Global> { a: &'a HashSet, b: &'a HashSet, } @@ -94,7 +94,7 @@ impl<'a, T, S, A> ParallelIterator for ParDifference<'a, T, S, A> where T: Eq + Hash + Sync, S: BuildHasher + Sync, - A: Allocator + Clone + Sync, + A: Allocator + Sync, { type Item = &'a T; @@ -118,7 +118,7 @@ where /// /// [`par_symmetric_difference`]: /hashbrown/struct.HashSet.html#method.par_symmetric_difference /// [`HashSet`]: /hashbrown/struct.HashSet.html -pub struct ParSymmetricDifference<'a, T, S, A: Allocator + Clone = Global> { +pub struct ParSymmetricDifference<'a, T, S, A: Allocator = Global> { a: &'a HashSet, b: &'a HashSet, } @@ -127,7 +127,7 @@ impl<'a, T, S, A> ParallelIterator for ParSymmetricDifference<'a, T, S, A> where T: Eq + Hash + Sync, S: BuildHasher + Sync, - A: Allocator + Clone + Sync, + A: Allocator + Sync, { type Item = &'a T; @@ -150,7 +150,7 @@ where /// /// [`par_intersection`]: /hashbrown/struct.HashSet.html#method.par_intersection /// [`HashSet`]: /hashbrown/struct.HashSet.html -pub struct ParIntersection<'a, T, S, A: Allocator + Clone = Global> { +pub struct ParIntersection<'a, T, S, A: Allocator = Global> { a: &'a HashSet, b: &'a HashSet, } @@ -159,7 +159,7 @@ impl<'a, T, S, A> ParallelIterator for ParIntersection<'a, T, S, A> where T: Eq + Hash + Sync, S: BuildHasher + Sync, - A: Allocator + Clone + Sync, + A: Allocator + Sync, { type Item = &'a T; @@ -181,7 +181,7 @@ where /// /// [`par_union`]: /hashbrown/struct.HashSet.html#method.par_union /// [`HashSet`]: /hashbrown/struct.HashSet.html -pub struct ParUnion<'a, T, S, A: Allocator + Clone = Global> { +pub struct ParUnion<'a, T, S, A: Allocator = Global> { a: &'a HashSet, b: &'a HashSet, } @@ -190,7 +190,7 @@ impl<'a, T, S, A> ParallelIterator for ParUnion<'a, T, S, A> where T: Eq + Hash + Sync, S: BuildHasher + Sync, - A: Allocator + Clone + Sync, + A: Allocator + Sync, { type Item = &'a T; @@ -216,7 +216,7 @@ impl HashSet where T: Eq + Hash + Sync, S: BuildHasher + Sync, - A: Allocator + Clone + Sync, + A: Allocator + Sync, { /// Visits (potentially in parallel) the values representing the union, /// i.e. all the values in `self` or `other`, without duplicates. @@ -289,7 +289,7 @@ where impl HashSet where T: Eq + Hash + Send, - A: Allocator + Clone + Send, + A: Allocator + Send, { /// Consumes (potentially in parallel) all values in an arbitrary order, /// while preserving the set's allocated memory for reuse. @@ -301,7 +301,7 @@ where } } -impl IntoParallelIterator for HashSet { +impl IntoParallelIterator for HashSet { type Item = T; type Iter = IntoParIter; @@ -313,7 +313,7 @@ impl IntoParallelIterator for HashSet IntoParallelIterator for &'a HashSet { +impl<'a, T: Sync, S, A: Allocator> IntoParallelIterator for &'a HashSet { type Item = &'a T; type Iter = ParIter<'a, T>; @@ -374,7 +374,7 @@ fn extend(set: &mut HashSet, par_iter: I) where T: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, I: IntoParallelIterator, HashSet: Extend, { diff --git a/sgx_tstd/hashbrown/src/external_trait_impls/rayon/table.rs b/sgx_tstd/hashbrown/src/external_trait_impls/rayon/table.rs new file mode 100644 index 000000000..e8e50944a --- /dev/null +++ b/sgx_tstd/hashbrown/src/external_trait_impls/rayon/table.rs @@ -0,0 +1,252 @@ +//! Rayon extensions for `HashTable`. + +use super::raw::{RawIntoParIter, RawParDrain, RawParIter}; +use crate::hash_table::HashTable; +use crate::raw::{Allocator, Global}; +use core::fmt; +use core::marker::PhantomData; +use rayon::iter::plumbing::UnindexedConsumer; +use rayon::iter::{IntoParallelIterator, ParallelIterator}; + +/// Parallel iterator over shared references to entries in a map. +/// +/// This iterator is created by the [`par_iter`] method on [`HashTable`] +/// (provided by the [`IntoParallelRefIterator`] trait). +/// See its documentation for more. +/// +/// [`par_iter`]: /hashbrown/struct.HashTable.html#method.par_iter +/// [`HashTable`]: /hashbrown/struct.HashTable.html +/// [`IntoParallelRefIterator`]: https://docs.rs/rayon/1.0/rayon/iter/trait.IntoParallelRefIterator.html +pub struct ParIter<'a, T> { + inner: RawParIter, + marker: PhantomData<&'a T>, +} + +impl<'a, T: Sync> ParallelIterator for ParIter<'a, T> { + type Item = &'a T; + + #[cfg_attr(feature = "inline-more", inline)] + fn drive_unindexed(self, consumer: C) -> C::Result + where + C: UnindexedConsumer, + { + self.inner + .map(|x| unsafe { x.as_ref() }) + .drive_unindexed(consumer) + } +} + +impl Clone for ParIter<'_, T> { + #[cfg_attr(feature = "inline-more", inline)] + fn clone(&self) -> Self { + Self { + inner: self.inner.clone(), + marker: PhantomData, + } + } +} + +impl fmt::Debug for ParIter<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let iter = unsafe { self.inner.iter() }.map(|x| unsafe { x.as_ref() }); + f.debug_list().entries(iter).finish() + } +} + +/// Parallel iterator over mutable references to entries in a map. +/// +/// This iterator is created by the [`par_iter_mut`] method on [`HashTable`] +/// (provided by the [`IntoParallelRefMutIterator`] trait). +/// See its documentation for more. +/// +/// [`par_iter_mut`]: /hashbrown/struct.HashTable.html#method.par_iter_mut +/// [`HashTable`]: /hashbrown/struct.HashTable.html +/// [`IntoParallelRefMutIterator`]: https://docs.rs/rayon/1.0/rayon/iter/trait.IntoParallelRefMutIterator.html +pub struct ParIterMut<'a, T> { + inner: RawParIter, + marker: PhantomData<&'a mut T>, +} + +impl<'a, T: Send> ParallelIterator for ParIterMut<'a, T> { + type Item = &'a mut T; + + #[cfg_attr(feature = "inline-more", inline)] + fn drive_unindexed(self, consumer: C) -> C::Result + where + C: UnindexedConsumer, + { + self.inner + .map(|x| unsafe { x.as_mut() }) + .drive_unindexed(consumer) + } +} + +impl fmt::Debug for ParIterMut<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + ParIter { + inner: self.inner.clone(), + marker: PhantomData, + } + .fmt(f) + } +} + +/// Parallel iterator over entries of a consumed map. +/// +/// This iterator is created by the [`into_par_iter`] method on [`HashTable`] +/// (provided by the [`IntoParallelIterator`] trait). +/// See its documentation for more. +/// +/// [`into_par_iter`]: /hashbrown/struct.HashTable.html#method.into_par_iter +/// [`HashTable`]: /hashbrown/struct.HashTable.html +/// [`IntoParallelIterator`]: https://docs.rs/rayon/1.0/rayon/iter/trait.IntoParallelIterator.html +pub struct IntoParIter { + inner: RawIntoParIter, +} + +impl ParallelIterator for IntoParIter { + type Item = T; + + #[cfg_attr(feature = "inline-more", inline)] + fn drive_unindexed(self, consumer: C) -> C::Result + where + C: UnindexedConsumer, + { + self.inner.drive_unindexed(consumer) + } +} + +impl fmt::Debug for IntoParIter { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + ParIter { + inner: unsafe { self.inner.par_iter() }, + marker: PhantomData, + } + .fmt(f) + } +} + +/// Parallel draining iterator over entries of a map. +/// +/// This iterator is created by the [`par_drain`] method on [`HashTable`]. +/// See its documentation for more. +/// +/// [`par_drain`]: /hashbrown/struct.HashTable.html#method.par_drain +/// [`HashTable`]: /hashbrown/struct.HashTable.html +pub struct ParDrain<'a, T, A: Allocator = Global> { + inner: RawParDrain<'a, T, A>, +} + +impl ParallelIterator for ParDrain<'_, T, A> { + type Item = T; + + #[cfg_attr(feature = "inline-more", inline)] + fn drive_unindexed(self, consumer: C) -> C::Result + where + C: UnindexedConsumer, + { + self.inner.drive_unindexed(consumer) + } +} + +impl fmt::Debug for ParDrain<'_, T, A> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + ParIter { + inner: unsafe { self.inner.par_iter() }, + marker: PhantomData, + } + .fmt(f) + } +} + +impl HashTable { + /// Consumes (potentially in parallel) all values in an arbitrary order, + /// while preserving the map's allocated memory for reuse. + #[cfg_attr(feature = "inline-more", inline)] + pub fn par_drain(&mut self) -> ParDrain<'_, T, A> { + ParDrain { + inner: self.raw.par_drain(), + } + } +} + +impl IntoParallelIterator for HashTable { + type Item = T; + type Iter = IntoParIter; + + #[cfg_attr(feature = "inline-more", inline)] + fn into_par_iter(self) -> Self::Iter { + IntoParIter { + inner: self.raw.into_par_iter(), + } + } +} + +impl<'a, T: Sync, A: Allocator> IntoParallelIterator for &'a HashTable { + type Item = &'a T; + type Iter = ParIter<'a, T>; + + #[cfg_attr(feature = "inline-more", inline)] + fn into_par_iter(self) -> Self::Iter { + ParIter { + inner: unsafe { self.raw.par_iter() }, + marker: PhantomData, + } + } +} + +impl<'a, T: Send, A: Allocator> IntoParallelIterator for &'a mut HashTable { + type Item = &'a mut T; + type Iter = ParIterMut<'a, T>; + + #[cfg_attr(feature = "inline-more", inline)] + fn into_par_iter(self) -> Self::Iter { + ParIterMut { + inner: unsafe { self.raw.par_iter() }, + marker: PhantomData, + } + } +} + +#[cfg(test)] +mod test_par_table { + use alloc::vec::Vec; + use core::sync::atomic::{AtomicUsize, Ordering}; + + use rayon::prelude::*; + + use crate::{ + hash_map::{make_hash, DefaultHashBuilder}, + hash_table::HashTable, + }; + + #[test] + fn test_iterate() { + let hasher = DefaultHashBuilder::default(); + let mut a = HashTable::new(); + for i in 0..32 { + a.insert_unique(make_hash(&hasher, &i), i, |x| make_hash(&hasher, x)); + } + let observed = AtomicUsize::new(0); + a.par_iter().for_each(|k| { + observed.fetch_or(1 << *k, Ordering::Relaxed); + }); + assert_eq!(observed.into_inner(), 0xFFFF_FFFF); + } + + #[test] + fn test_move_iter() { + let hasher = DefaultHashBuilder::default(); + let hs = { + let mut hs = HashTable::new(); + + hs.insert_unique(make_hash(&hasher, &'a'), 'a', |x| make_hash(&hasher, x)); + hs.insert_unique(make_hash(&hasher, &'b'), 'b', |x| make_hash(&hasher, x)); + + hs + }; + + let v = hs.into_par_iter().collect::>(); + assert!(v == ['a', 'b'] || v == ['b', 'a']); + } +} diff --git a/sgx_tstd/hashbrown/src/external_trait_impls/rkyv/hash_map.rs b/sgx_tstd/hashbrown/src/external_trait_impls/rkyv/hash_map.rs new file mode 100644 index 000000000..fae7f7676 --- /dev/null +++ b/sgx_tstd/hashbrown/src/external_trait_impls/rkyv/hash_map.rs @@ -0,0 +1,125 @@ +use crate::HashMap; +use core::{ + borrow::Borrow, + hash::{BuildHasher, Hash}, +}; +use rkyv::{ + collections::hash_map::{ArchivedHashMap, HashMapResolver}, + ser::{ScratchSpace, Serializer}, + Archive, Deserialize, Fallible, Serialize, +}; + +impl Archive for HashMap +where + K::Archived: Hash + Eq, +{ + type Archived = ArchivedHashMap; + type Resolver = HashMapResolver; + + #[inline] + unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { + ArchivedHashMap::resolve_from_len(self.len(), pos, resolver, out); + } +} + +impl Serialize for HashMap +where + K: Serialize + Hash + Eq, + K::Archived: Hash + Eq, + V: Serialize, + S: Serializer + ScratchSpace + ?Sized, +{ + #[inline] + fn serialize(&self, serializer: &mut S) -> Result { + unsafe { ArchivedHashMap::serialize_from_iter(self.iter(), serializer) } + } +} + +impl + Deserialize, D> for ArchivedHashMap +where + K::Archived: Deserialize + Hash + Eq, + V::Archived: Deserialize, +{ + #[inline] + fn deserialize(&self, deserializer: &mut D) -> Result, D::Error> { + let mut result = HashMap::with_capacity_and_hasher(self.len(), S::default()); + for (k, v) in self.iter() { + result.insert(k.deserialize(deserializer)?, v.deserialize(deserializer)?); + } + Ok(result) + } +} + +impl, V, AK: Hash + Eq, AV: PartialEq, S: BuildHasher> + PartialEq> for ArchivedHashMap +{ + #[inline] + fn eq(&self, other: &HashMap) -> bool { + if self.len() != other.len() { + false + } else { + self.iter() + .all(|(key, value)| other.get(key).map_or(false, |v| value.eq(v))) + } + } +} + +impl, V, AK: Hash + Eq, AV: PartialEq> + PartialEq> for HashMap +{ + #[inline] + fn eq(&self, other: &ArchivedHashMap) -> bool { + other.eq(self) + } +} + +#[cfg(test)] +mod tests { + use crate::HashMap; + use alloc::string::String; + use rkyv::{ + archived_root, check_archived_root, + ser::{serializers::AllocSerializer, Serializer}, + Deserialize, Infallible, + }; + + #[test] + fn index_map() { + let mut value = HashMap::new(); + value.insert(String::from("foo"), 10); + value.insert(String::from("bar"), 20); + value.insert(String::from("baz"), 40); + value.insert(String::from("bat"), 80); + + let mut serializer = AllocSerializer::<4096>::default(); + serializer.serialize_value(&value).unwrap(); + let result = serializer.into_serializer().into_inner(); + let archived = unsafe { archived_root::>(result.as_ref()) }; + + assert_eq!(value.len(), archived.len()); + for (k, v) in value.iter() { + let (ak, av) = archived.get_key_value(k.as_str()).unwrap(); + assert_eq!(k, ak); + assert_eq!(v, av); + } + + let deserialized: HashMap = archived.deserialize(&mut Infallible).unwrap(); + assert_eq!(value, deserialized); + } + + #[test] + fn validate_index_map() { + let mut value = HashMap::new(); + value.insert(String::from("foo"), 10); + value.insert(String::from("bar"), 20); + value.insert(String::from("baz"), 40); + value.insert(String::from("bat"), 80); + + let mut serializer = AllocSerializer::<4096>::default(); + serializer.serialize_value(&value).unwrap(); + let result = serializer.into_serializer().into_inner(); + check_archived_root::>(result.as_ref()) + .expect("failed to validate archived index map"); + } +} diff --git a/sgx_tstd/hashbrown/src/external_trait_impls/rkyv/hash_set.rs b/sgx_tstd/hashbrown/src/external_trait_impls/rkyv/hash_set.rs new file mode 100644 index 000000000..c8a69cf4f --- /dev/null +++ b/sgx_tstd/hashbrown/src/external_trait_impls/rkyv/hash_set.rs @@ -0,0 +1,123 @@ +use crate::HashSet; +use core::{ + borrow::Borrow, + hash::{BuildHasher, Hash}, +}; +use rkyv::{ + collections::hash_set::{ArchivedHashSet, HashSetResolver}, + ser::{ScratchSpace, Serializer}, + Archive, Deserialize, Fallible, Serialize, +}; + +impl Archive for HashSet +where + K::Archived: Hash + Eq, +{ + type Archived = ArchivedHashSet; + type Resolver = HashSetResolver; + + #[inline] + unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { + ArchivedHashSet::::resolve_from_len(self.len(), pos, resolver, out); + } +} + +impl Serialize for HashSet +where + K::Archived: Hash + Eq, + K: Serialize + Hash + Eq, + S: ScratchSpace + Serializer + ?Sized, +{ + #[inline] + fn serialize(&self, serializer: &mut S) -> Result { + unsafe { ArchivedHashSet::serialize_from_iter(self.iter(), serializer) } + } +} + +impl Deserialize, D> for ArchivedHashSet +where + K: Archive + Hash + Eq, + K::Archived: Deserialize + Hash + Eq, + D: Fallible + ?Sized, + S: Default + BuildHasher, +{ + #[inline] + fn deserialize(&self, deserializer: &mut D) -> Result, D::Error> { + let mut result = HashSet::with_hasher(S::default()); + for k in self.iter() { + result.insert(k.deserialize(deserializer)?); + } + Ok(result) + } +} + +impl, AK: Hash + Eq, S: BuildHasher> PartialEq> + for ArchivedHashSet +{ + #[inline] + fn eq(&self, other: &HashSet) -> bool { + if self.len() != other.len() { + false + } else { + self.iter().all(|key| other.get(key).is_some()) + } + } +} + +impl, AK: Hash + Eq, S: BuildHasher> PartialEq> + for HashSet +{ + #[inline] + fn eq(&self, other: &ArchivedHashSet) -> bool { + other.eq(self) + } +} + +#[cfg(test)] +mod tests { + use crate::HashSet; + use alloc::string::String; + use rkyv::{ + archived_root, check_archived_root, + ser::{serializers::AllocSerializer, Serializer}, + Deserialize, Infallible, + }; + + #[test] + fn index_set() { + let mut value = HashSet::new(); + value.insert(String::from("foo")); + value.insert(String::from("bar")); + value.insert(String::from("baz")); + value.insert(String::from("bat")); + + let mut serializer = AllocSerializer::<4096>::default(); + serializer.serialize_value(&value).unwrap(); + let result = serializer.into_serializer().into_inner(); + let archived = unsafe { archived_root::>(result.as_ref()) }; + + assert_eq!(value.len(), archived.len()); + for k in value.iter() { + let ak = archived.get(k.as_str()).unwrap(); + assert_eq!(k, ak); + } + + let deserialized: HashSet = archived.deserialize(&mut Infallible).unwrap(); + assert_eq!(value, deserialized); + } + + #[test] + fn validate_index_set() { + let mut value = HashSet::new(); + value.insert(String::from("foo")); + value.insert(String::from("bar")); + value.insert(String::from("baz")); + value.insert(String::from("bat")); + + let mut serializer = AllocSerializer::<4096>::default(); + serializer.serialize_value(&value).unwrap(); + let result = serializer.into_serializer().into_inner(); + check_archived_root::>(result.as_ref()) + .expect("failed to validate archived index set"); + } +} diff --git a/sgx_tstd/hashbrown/src/external_trait_impls/rkyv/mod.rs b/sgx_tstd/hashbrown/src/external_trait_impls/rkyv/mod.rs new file mode 100644 index 000000000..2bde6a065 --- /dev/null +++ b/sgx_tstd/hashbrown/src/external_trait_impls/rkyv/mod.rs @@ -0,0 +1,2 @@ +mod hash_map; +mod hash_set; diff --git a/sgx_tstd/hashbrown/src/external_trait_impls/serde.rs b/sgx_tstd/hashbrown/src/external_trait_impls/serde.rs index 4d62deeb7..0a76dbec2 100644 --- a/sgx_tstd/hashbrown/src/external_trait_impls/serde.rs +++ b/sgx_tstd/hashbrown/src/external_trait_impls/serde.rs @@ -11,6 +11,7 @@ mod size_hint { } mod map { + use crate::raw::Allocator; use core::fmt; use core::hash::{BuildHasher, Hash}; use core::marker::PhantomData; @@ -21,11 +22,12 @@ mod map { use super::size_hint; - impl Serialize for HashMap + impl Serialize for HashMap where K: Serialize + Eq + Hash, V: Serialize, H: BuildHasher, + A: Allocator, { #[cfg_attr(feature = "inline-more", inline)] fn serialize(&self, serializer: S) -> Result @@ -36,40 +38,46 @@ mod map { } } - impl<'de, K, V, S> Deserialize<'de> for HashMap + impl<'de, K, V, S, A> Deserialize<'de> for HashMap where K: Deserialize<'de> + Eq + Hash, V: Deserialize<'de>, S: BuildHasher + Default, + A: Allocator + Default, { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { - struct MapVisitor { - marker: PhantomData>, + struct MapVisitor + where + A: Allocator, + { + marker: PhantomData>, } - impl<'de, K, V, S> Visitor<'de> for MapVisitor + impl<'de, K, V, S, A> Visitor<'de> for MapVisitor where K: Deserialize<'de> + Eq + Hash, V: Deserialize<'de>, S: BuildHasher + Default, + A: Allocator + Default, { - type Value = HashMap; + type Value = HashMap; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_str("a map") } #[cfg_attr(feature = "inline-more", inline)] - fn visit_map(self, mut map: A) -> Result + fn visit_map(self, mut map: M) -> Result where - A: MapAccess<'de>, + M: MapAccess<'de>, { - let mut values = HashMap::with_capacity_and_hasher( + let mut values = HashMap::with_capacity_and_hasher_in( size_hint::cautious(map.size_hint()), S::default(), + A::default(), ); while let Some((key, value)) = map.next_entry()? { @@ -89,6 +97,7 @@ mod map { } mod set { + use crate::raw::Allocator; use core::fmt; use core::hash::{BuildHasher, Hash}; use core::marker::PhantomData; @@ -99,10 +108,11 @@ mod set { use super::size_hint; - impl Serialize for HashSet + impl Serialize for HashSet where T: Serialize + Eq + Hash, H: BuildHasher, + A: Allocator, { #[cfg_attr(feature = "inline-more", inline)] fn serialize(&self, serializer: S) -> Result @@ -113,38 +123,44 @@ mod set { } } - impl<'de, T, S> Deserialize<'de> for HashSet + impl<'de, T, S, A> Deserialize<'de> for HashSet where T: Deserialize<'de> + Eq + Hash, S: BuildHasher + Default, + A: Allocator + Default, { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { - struct SeqVisitor { - marker: PhantomData>, + struct SeqVisitor + where + A: Allocator, + { + marker: PhantomData>, } - impl<'de, T, S> Visitor<'de> for SeqVisitor + impl<'de, T, S, A> Visitor<'de> for SeqVisitor where T: Deserialize<'de> + Eq + Hash, S: BuildHasher + Default, + A: Allocator + Default, { - type Value = HashSet; + type Value = HashSet; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_str("a sequence") } #[cfg_attr(feature = "inline-more", inline)] - fn visit_seq(self, mut seq: A) -> Result + fn visit_seq(self, mut seq: M) -> Result where - A: SeqAccess<'de>, + M: SeqAccess<'de>, { - let mut values = HashSet::with_capacity_and_hasher( + let mut values = HashSet::with_capacity_and_hasher_in( size_hint::cautious(seq.size_hint()), S::default(), + A::default(), ); while let Some(value) = seq.next_element()? { @@ -166,12 +182,15 @@ mod set { where D: Deserializer<'de>, { - struct SeqInPlaceVisitor<'a, T, S>(&'a mut HashSet); + struct SeqInPlaceVisitor<'a, T, S, A>(&'a mut HashSet) + where + A: Allocator; - impl<'a, 'de, T, S> Visitor<'de> for SeqInPlaceVisitor<'a, T, S> + impl<'a, 'de, T, S, A> Visitor<'de> for SeqInPlaceVisitor<'a, T, S, A> where T: Deserialize<'de> + Eq + Hash, S: BuildHasher + Default, + A: Allocator, { type Value = (); @@ -180,9 +199,9 @@ mod set { } #[cfg_attr(feature = "inline-more", inline)] - fn visit_seq(self, mut seq: A) -> Result + fn visit_seq(self, mut seq: M) -> Result where - A: SeqAccess<'de>, + M: SeqAccess<'de>, { self.0.clear(); self.0.reserve(size_hint::cautious(seq.size_hint())); diff --git a/sgx_tstd/hashbrown/src/lib.rs b/sgx_tstd/hashbrown/src/lib.rs index 701b6ea6b..6e9592abe 100644 --- a/sgx_tstd/hashbrown/src/lib.rs +++ b/sgx_tstd/hashbrown/src/lib.rs @@ -20,9 +20,8 @@ extend_one, allocator_api, slice_ptr_get, - nonnull_slice_from_raw_parts, maybe_uninit_array_assume_init, - build_hasher_simple_hash_one + strict_provenance ) )] #![allow( @@ -31,10 +30,13 @@ clippy::must_use_candidate, clippy::option_if_let_else, clippy::redundant_else, - clippy::manual_map + clippy::manual_map, + clippy::missing_safety_doc, + clippy::missing_errors_doc )] #![warn(missing_docs)] #![warn(rust_2018_idioms)] +#![cfg_attr(feature = "nightly", warn(fuzzy_provenance_casts))] #[cfg(test)] #[macro_use] @@ -79,6 +81,7 @@ mod map; mod rustc_entry; mod scopeguard; mod set; +mod table; pub mod hash_map { //! A hash map implemented with quadratic probing and SIMD lookup. @@ -111,9 +114,63 @@ pub mod hash_set { pub use crate::external_trait_impls::rayon::set::*; } } +pub mod hash_table { + //! A hash table implemented with quadratic probing and SIMD lookup. + pub use crate::table::*; + + #[cfg(feature = "rayon")] + /// [rayon]-based parallel iterator types for hash tables. + /// You will rarely need to interact with it directly unless you have need + /// to name one of the iterator types. + /// + /// [rayon]: https://docs.rs/rayon/1.0/rayon + pub mod rayon { + pub use crate::external_trait_impls::rayon::table::*; + } +} pub use crate::map::HashMap; pub use crate::set::HashSet; +pub use crate::table::HashTable; + +#[cfg(feature = "equivalent")] +pub use equivalent::Equivalent; + +// This is only used as a fallback when building as part of `std`. +#[cfg(not(feature = "equivalent"))] +/// Key equivalence trait. +/// +/// This trait defines the function used to compare the input value with the +/// map keys (or set values) during a lookup operation such as [`HashMap::get`] +/// or [`HashSet::contains`]. +/// It is provided with a blanket implementation based on the +/// [`Borrow`](core::borrow::Borrow) trait. +/// +/// # Correctness +/// +/// Equivalent values must hash to the same value. +pub trait Equivalent { + /// Checks if this value is equivalent to the given key. + /// + /// Returns `true` if both values are equivalent, and `false` otherwise. + /// + /// # Correctness + /// + /// When this function returns `true`, both `self` and `key` must hash to + /// the same value. + fn equivalent(&self, key: &K) -> bool; +} + +#[cfg(not(feature = "equivalent"))] +impl Equivalent for Q +where + Q: Eq, + K: core::borrow::Borrow, +{ + fn equivalent(&self, key: &K) -> bool { + self == key.borrow() + } +} /// The error type for `try_reserve` methods. #[derive(Clone, PartialEq, Eq, Debug)] @@ -128,21 +185,3 @@ pub enum TryReserveError { layout: alloc::alloc::Layout, }, } - -/// Wrapper around `Bump` which allows it to be used as an allocator for -/// `HashMap`, `HashSet` and `RawTable`. -/// -/// `Bump` can be used directly without this wrapper on nightly if you enable -/// the `allocator-api` feature of the `bumpalo` crate. -#[cfg(feature = "bumpalo")] -#[derive(Clone, Copy, Debug)] -pub struct BumpWrapper<'a>(pub &'a bumpalo::Bump); - -#[cfg(feature = "bumpalo")] -#[test] -fn test_bumpalo() { - use bumpalo::Bump; - let bump = Bump::new(); - let mut map = HashMap::new_in(BumpWrapper(&bump)); - map.insert(0, 1); -} diff --git a/sgx_tstd/hashbrown/src/macros.rs b/sgx_tstd/hashbrown/src/macros.rs index 4de6b5aa1..eaba6bed1 100644 --- a/sgx_tstd/hashbrown/src/macros.rs +++ b/sgx_tstd/hashbrown/src/macros.rs @@ -1,4 +1,5 @@ // See the cfg-if crate. +#[allow(unused_macro_rules)] macro_rules! cfg_if { // match if/else chains with a final `else` ($( @@ -36,7 +37,7 @@ macro_rules! cfg_if { // semicolon is all the remaining items (@__items ($($not:meta,)*) ; ) => {}; (@__items ($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ), $($rest:tt)*) => { - // Emit all items within one block, applying an approprate #[cfg]. The + // Emit all items within one block, applying an appropriate #[cfg]. The // #[cfg] will require all `$m` matchers specified and must also negate // all previous matchers. cfg_if! { @__apply cfg(all($($m,)* not(any($($not),*)))), $($it)* } diff --git a/sgx_tstd/hashbrown/src/map.rs b/sgx_tstd/hashbrown/src/map.rs index d0592cb7f..b5e657bc6 100644 --- a/sgx_tstd/hashbrown/src/map.rs +++ b/sgx_tstd/hashbrown/src/map.rs @@ -1,5 +1,7 @@ -use crate::raw::{Allocator, Bucket, Global, RawDrain, RawIntoIter, RawIter, RawTable}; -use crate::TryReserveError; +use crate::raw::{ + Allocator, Bucket, Global, RawDrain, RawExtractIf, RawIntoIter, RawIter, RawTable, +}; +use crate::{Equivalent, TryReserveError}; use core::borrow::Borrow; use core::fmt::{self, Debug}; use core::hash::{BuildHasher, Hash}; @@ -10,7 +12,7 @@ use core::ops::Index; /// Default hasher for `HashMap`. #[cfg(feature = "ahash")] -pub type DefaultHashBuilder = ahash::RandomState; +pub type DefaultHashBuilder = core::hash::BuildHasherDefault; /// Dummy default hasher for `HashMap`. #[cfg(not(feature = "ahash"))] @@ -185,7 +187,7 @@ pub enum DefaultHashBuilder {} /// .iter().cloned().collect(); /// // use the values stored in map /// ``` -pub struct HashMap { +pub struct HashMap { pub(crate) hash_builder: S, pub(crate) table: RawTable<(K, V), A>, } @@ -209,13 +211,12 @@ impl Clone for HashMap(hash_builder: &S) -> impl Fn(&(Q, V)) -> u64 + '_ +pub(crate) fn make_hasher(hash_builder: &S) -> impl Fn(&(Q, V)) -> u64 + '_ where - K: Borrow, Q: Hash, S: BuildHasher, { - move |val| make_hash::(hash_builder, &val.0) + move |val| make_hash::(hash_builder, &val.0) } /// Ensures that a single closure type across uses of this which, in turn prevents multiple @@ -223,10 +224,9 @@ where #[cfg_attr(feature = "inline-more", inline)] fn equivalent_key(k: &Q) -> impl Fn(&(K, V)) -> bool + '_ where - K: Borrow, - Q: ?Sized + Eq, + Q: ?Sized + Equivalent, { - move |x| k.eq(x.0.borrow()) + move |x| k.equivalent(&x.0) } /// Ensures that a single closure type across uses of this which, in turn prevents multiple @@ -234,17 +234,15 @@ where #[cfg_attr(feature = "inline-more", inline)] fn equivalent(k: &Q) -> impl Fn(&K) -> bool + '_ where - K: Borrow, - Q: ?Sized + Eq, + Q: ?Sized + Equivalent, { - move |x| k.eq(x.borrow()) + move |x| k.equivalent(x) } #[cfg(not(feature = "nightly"))] #[cfg_attr(feature = "inline-more", inline)] -pub(crate) fn make_hash(hash_builder: &S, val: &Q) -> u64 +pub(crate) fn make_hash(hash_builder: &S, val: &Q) -> u64 where - K: Borrow, Q: Hash + ?Sized, S: BuildHasher, { @@ -256,38 +254,14 @@ where #[cfg(feature = "nightly")] #[cfg_attr(feature = "inline-more", inline)] -pub(crate) fn make_hash(hash_builder: &S, val: &Q) -> u64 +pub(crate) fn make_hash(hash_builder: &S, val: &Q) -> u64 where - K: Borrow, Q: Hash + ?Sized, S: BuildHasher, { hash_builder.hash_one(val) } -#[cfg(not(feature = "nightly"))] -#[cfg_attr(feature = "inline-more", inline)] -pub(crate) fn make_insert_hash(hash_builder: &S, val: &K) -> u64 -where - K: Hash, - S: BuildHasher, -{ - use core::hash::Hasher; - let mut state = hash_builder.build_hasher(); - val.hash(&mut state); - state.finish() -} - -#[cfg(feature = "nightly")] -#[cfg_attr(feature = "inline-more", inline)] -pub(crate) fn make_insert_hash(hash_builder: &S, val: &K) -> u64 -where - K: Hash, - S: BuildHasher, -{ - hash_builder.hash_one(val) -} - #[cfg(feature = "ahash")] impl HashMap { /// Creates an empty `HashMap`. @@ -295,11 +269,25 @@ impl HashMap { /// The hash map is initially created with a capacity of 0, so it will not allocate until it /// is first inserted into. /// + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashMap` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashMap`], for example with + /// [`with_hasher`](HashMap::with_hasher) method. + /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// /// # Examples /// /// ``` /// use hashbrown::HashMap; /// let mut map: HashMap<&str, i32> = HashMap::new(); + /// assert_eq!(map.len(), 0); + /// assert_eq!(map.capacity(), 0); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn new() -> Self { @@ -311,11 +299,25 @@ impl HashMap { /// The hash map will be able to hold at least `capacity` elements without /// reallocating. If `capacity` is 0, the hash map will not allocate. /// + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashMap` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashMap`], for example with + /// [`with_capacity_and_hasher`](HashMap::with_capacity_and_hasher) method. + /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// /// # Examples /// /// ``` /// use hashbrown::HashMap; /// let mut map: HashMap<&str, i32> = HashMap::with_capacity(10); + /// assert_eq!(map.len(), 0); + /// assert!(map.capacity() >= 10); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn with_capacity(capacity: usize) -> Self { @@ -324,11 +326,46 @@ impl HashMap { } #[cfg(feature = "ahash")] -impl HashMap { +impl HashMap { /// Creates an empty `HashMap` using the given allocator. /// /// The hash map is initially created with a capacity of 0, so it will not allocate until it /// is first inserted into. + /// + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashMap` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashMap`], for example with + /// [`with_hasher_in`](HashMap::with_hasher_in) method. + /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashMap; + /// use bumpalo::Bump; + /// + /// let bump = Bump::new(); + /// let mut map = HashMap::new_in(&bump); + /// + /// // The created HashMap holds none elements + /// assert_eq!(map.len(), 0); + /// + /// // The created HashMap also doesn't allocate memory + /// assert_eq!(map.capacity(), 0); + /// + /// // Now we insert element inside created HashMap + /// map.insert("One", 1); + /// // We can see that the HashMap holds 1 element + /// assert_eq!(map.len(), 1); + /// // And it also allocates some capacity + /// assert!(map.capacity() > 1); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn new_in(alloc: A) -> Self { Self::with_hasher_in(DefaultHashBuilder::default(), alloc) @@ -338,6 +375,46 @@ impl HashMap { /// /// The hash map will be able to hold at least `capacity` elements without /// reallocating. If `capacity` is 0, the hash map will not allocate. + /// + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashMap` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashMap`], for example with + /// [`with_capacity_and_hasher_in`](HashMap::with_capacity_and_hasher_in) method. + /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashMap; + /// use bumpalo::Bump; + /// + /// let bump = Bump::new(); + /// let mut map = HashMap::with_capacity_in(5, &bump); + /// + /// // The created HashMap holds none elements + /// assert_eq!(map.len(), 0); + /// // But it can hold at least 5 elements without reallocating + /// let empty_map_capacity = map.capacity(); + /// assert!(empty_map_capacity >= 5); + /// + /// // Now we insert some 5 elements inside created HashMap + /// map.insert("One", 1); + /// map.insert("Two", 2); + /// map.insert("Three", 3); + /// map.insert("Four", 4); + /// map.insert("Five", 5); + /// + /// // We can see that the HashMap holds 5 elements + /// assert_eq!(map.len(), 5); + /// // But its capacity isn't changed + /// assert_eq!(map.capacity(), empty_map_capacity) + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn with_capacity_in(capacity: usize, alloc: A) -> Self { Self::with_capacity_and_hasher_in(capacity, DefaultHashBuilder::default(), alloc) @@ -348,16 +425,24 @@ impl HashMap { /// Creates an empty `HashMap` which will use the given hash builder to hash /// keys. /// - /// The created map has the default initial capacity. + /// The hash map is initially created with a capacity of 0, so it will not + /// allocate until it is first inserted into. /// - /// Warning: `hash_builder` is normally randomly generated, and - /// is designed to allow HashMaps to be resistant to attacks that - /// cause many collisions and very poor performance. Setting it - /// manually using this function can expose a DoS attack vector. + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashMap` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashMap`]. /// /// The `hash_builder` passed should implement the [`BuildHasher`] trait for /// the HashMap to be useful, see its documentation for details. /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// [`BuildHasher`]: https://doc.rust-lang.org/std/hash/trait.BuildHasher.html + /// /// # Examples /// /// ``` @@ -366,10 +451,11 @@ impl HashMap { /// /// let s = DefaultHashBuilder::default(); /// let mut map = HashMap::with_hasher(s); + /// assert_eq!(map.len(), 0); + /// assert_eq!(map.capacity(), 0); + /// /// map.insert(1, 2); /// ``` - /// - /// [`BuildHasher`]: ../../std/hash/trait.BuildHasher.html #[cfg_attr(feature = "inline-more", inline)] pub const fn with_hasher(hash_builder: S) -> Self { Self { @@ -384,14 +470,21 @@ impl HashMap { /// The hash map will be able to hold at least `capacity` elements without /// reallocating. If `capacity` is 0, the hash map will not allocate. /// - /// Warning: `hash_builder` is normally randomly generated, and - /// is designed to allow HashMaps to be resistant to attacks that - /// cause many collisions and very poor performance. Setting it - /// manually using this function can expose a DoS attack vector. + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashMap` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashMap`]. /// /// The `hash_builder` passed should implement the [`BuildHasher`] trait for /// the HashMap to be useful, see its documentation for details. /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// [`BuildHasher`]: https://doc.rust-lang.org/std/hash/trait.BuildHasher.html + /// /// # Examples /// /// ``` @@ -400,10 +493,11 @@ impl HashMap { /// /// let s = DefaultHashBuilder::default(); /// let mut map = HashMap::with_capacity_and_hasher(10, s); + /// assert_eq!(map.len(), 0); + /// assert!(map.capacity() >= 10); + /// /// map.insert(1, 2); /// ``` - /// - /// [`BuildHasher`]: ../../std/hash/trait.BuildHasher.html #[cfg_attr(feature = "inline-more", inline)] pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self { Self { @@ -413,7 +507,7 @@ impl HashMap { } } -impl HashMap { +impl HashMap { /// Returns a reference to the underlying allocator. #[inline] pub fn allocator(&self) -> &A { @@ -423,12 +517,19 @@ impl HashMap { /// Creates an empty `HashMap` which will use the given hash builder to hash /// keys. It will be allocated with the given allocator. /// - /// The created map has the default initial capacity. + /// The hash map is initially created with a capacity of 0, so it will not allocate until it + /// is first inserted into. + /// + /// # HashDoS resistance /// - /// Warning: `hash_builder` is normally randomly generated, and - /// is designed to allow HashMaps to be resistant to attacks that - /// cause many collisions and very poor performance. Setting it - /// manually using this function can expose a DoS attack vector. + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashMap` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashMap`]. + /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html /// /// # Examples /// @@ -441,7 +542,7 @@ impl HashMap { /// map.insert(1, 2); /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn with_hasher_in(hash_builder: S, alloc: A) -> Self { + pub const fn with_hasher_in(hash_builder: S, alloc: A) -> Self { Self { hash_builder, table: RawTable::new_in(alloc), @@ -454,10 +555,16 @@ impl HashMap { /// The hash map will be able to hold at least `capacity` elements without /// reallocating. If `capacity` is 0, the hash map will not allocate. /// - /// Warning: `hash_builder` is normally randomly generated, and - /// is designed to allow HashMaps to be resistant to attacks that - /// cause many collisions and very poor performance. Setting it - /// manually using this function can expose a DoS attack vector. + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashMap` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashMap`]. + /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html /// /// # Examples /// @@ -506,6 +613,7 @@ impl HashMap { /// ``` /// use hashbrown::HashMap; /// let map: HashMap = HashMap::with_capacity(100); + /// assert_eq!(map.len(), 0); /// assert!(map.capacity() >= 100); /// ``` #[cfg_attr(feature = "inline-more", inline)] @@ -525,10 +633,20 @@ impl HashMap { /// map.insert("a", 1); /// map.insert("b", 2); /// map.insert("c", 3); + /// assert_eq!(map.len(), 3); + /// let mut vec: Vec<&str> = Vec::new(); /// /// for key in map.keys() { /// println!("{}", key); + /// vec.push(*key); /// } + /// + /// // The `Keys` iterator produces keys in arbitrary order, so the + /// // keys must be sorted to test them against a sorted array. + /// vec.sort_unstable(); + /// assert_eq!(vec, ["a", "b", "c"]); + /// + /// assert_eq!(map.len(), 3); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn keys(&self) -> Keys<'_, K, V> { @@ -547,10 +665,20 @@ impl HashMap { /// map.insert("a", 1); /// map.insert("b", 2); /// map.insert("c", 3); + /// assert_eq!(map.len(), 3); + /// let mut vec: Vec = Vec::new(); /// /// for val in map.values() { /// println!("{}", val); + /// vec.push(*val); /// } + /// + /// // The `Values` iterator produces values in arbitrary order, so the + /// // values must be sorted to test them against a sorted array. + /// vec.sort_unstable(); + /// assert_eq!(vec, [1, 2, 3]); + /// + /// assert_eq!(map.len(), 3); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn values(&self) -> Values<'_, K, V> { @@ -575,9 +703,20 @@ impl HashMap { /// *val = *val + 10; /// } /// + /// assert_eq!(map.len(), 3); + /// let mut vec: Vec = Vec::new(); + /// /// for val in map.values() { /// println!("{}", val); + /// vec.push(*val); /// } + /// + /// // The `Values` iterator produces values in arbitrary order, so the + /// // values must be sorted to test them against a sorted array. + /// vec.sort_unstable(); + /// assert_eq!(vec, [11, 12, 13]); + /// + /// assert_eq!(map.len(), 3); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> { @@ -598,10 +737,20 @@ impl HashMap { /// map.insert("a", 1); /// map.insert("b", 2); /// map.insert("c", 3); + /// assert_eq!(map.len(), 3); + /// let mut vec: Vec<(&str, i32)> = Vec::new(); /// /// for (key, val) in map.iter() { /// println!("key: {} val: {}", key, val); + /// vec.push((*key, *val)); /// } + /// + /// // The `Iter` iterator produces items in arbitrary order, so the + /// // items must be sorted to test them against a sorted array. + /// vec.sort_unstable(); + /// assert_eq!(vec, [("a", 1), ("b", 2), ("c", 3)]); + /// + /// assert_eq!(map.len(), 3); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn iter(&self) -> Iter<'_, K, V> { @@ -633,9 +782,20 @@ impl HashMap { /// *val *= 2; /// } /// + /// assert_eq!(map.len(), 3); + /// let mut vec: Vec<(&str, i32)> = Vec::new(); + /// /// for (key, val) in &map { /// println!("key: {} val: {}", key, val); + /// vec.push((*key, *val)); /// } + /// + /// // The `Iter` iterator produces items in arbitrary order, so the + /// // items must be sorted to test them against a sorted array. + /// vec.sort_unstable(); + /// assert_eq!(vec, [("a", 2), ("b", 4), ("c", 6)]); + /// + /// assert_eq!(map.len(), 3); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn iter_mut(&mut self) -> IterMut<'_, K, V> { @@ -691,6 +851,10 @@ impl HashMap { /// Clears the map, returning all key-value pairs as an iterator. Keeps the /// allocated memory for reuse. /// + /// If the returned iterator is dropped before being fully consumed, it + /// drops the remaining key-value pairs. The returned iterator keeps a + /// mutable borrow on the vector to optimize its implementation. + /// /// # Examples /// /// ``` @@ -699,12 +863,27 @@ impl HashMap { /// let mut a = HashMap::new(); /// a.insert(1, "a"); /// a.insert(2, "b"); + /// let capacity_before_drain = a.capacity(); /// /// for (k, v) in a.drain().take(1) { /// assert!(k == 1 || k == 2); /// assert!(v == "a" || v == "b"); /// } /// + /// // As we can see, the map is empty and contains no element. + /// assert!(a.is_empty() && a.len() == 0); + /// // But map capacity is equal to old one. + /// assert_eq!(a.capacity(), capacity_before_drain); + /// + /// let mut a = HashMap::new(); + /// a.insert(1, "a"); + /// a.insert(2, "b"); + /// + /// { // Iterator is dropped without being consumed. + /// let d = a.drain(); + /// } + /// + /// // But the map is empty even if we do not use Drain iterator. /// assert!(a.is_empty()); /// ``` #[cfg_attr(feature = "inline-more", inline)] @@ -714,9 +893,11 @@ impl HashMap { } } - /// Retains only the elements specified by the predicate. + /// Retains only the elements specified by the predicate. Keeps the + /// allocated memory for reuse. /// - /// In other words, remove all pairs `(k, v)` such that `f(&k,&mut v)` returns `false`. + /// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)` returns `false`. + /// The elements are visited in unsorted (and unspecified) order. /// /// # Examples /// @@ -724,8 +905,16 @@ impl HashMap { /// use hashbrown::HashMap; /// /// let mut map: HashMap = (0..8).map(|x|(x, x*10)).collect(); + /// assert_eq!(map.len(), 8); + /// /// map.retain(|&k, _| k % 2 == 0); + /// + /// // We can see, that the number of elements inside map is changed. /// assert_eq!(map.len(), 4); + /// + /// let mut vec: Vec<(i32, i32)> = map.iter().map(|(&k, &v)| (k, v)).collect(); + /// vec.sort_unstable(); + /// assert_eq!(vec, [(0, 0), (2, 20), (4, 40), (6, 60)]); /// ``` pub fn retain(&mut self, mut f: F) where @@ -745,11 +934,19 @@ impl HashMap { /// Drains elements which are true under the given predicate, /// and returns an iterator over the removed items. /// - /// In other words, move all pairs `(k, v)` such that `f(&k,&mut v)` returns `true` out + /// In other words, move all pairs `(k, v)` such that `f(&k, &mut v)` returns `true` out /// into another iterator. /// - /// When the returned DrainedFilter is dropped, any remaining elements that satisfy - /// the predicate are dropped from the table. + /// Note that `extract_if` lets you mutate every value in the filter closure, regardless of + /// whether you choose to keep or remove it. + /// + /// If the returned `ExtractIf` is not exhausted, e.g. because it is dropped without iterating + /// or the iteration short-circuits, then the remaining elements will be retained. + /// Use [`retain()`] with a negated predicate if you do not need the returned iterator. + /// + /// Keeps the allocated memory for reuse. + /// + /// [`retain()`]: HashMap::retain /// /// # Examples /// @@ -757,7 +954,8 @@ impl HashMap { /// use hashbrown::HashMap; /// /// let mut map: HashMap = (0..8).map(|x| (x, x)).collect(); - /// let drained: HashMap = map.drain_filter(|k, _v| k % 2 == 0).collect(); + /// + /// let drained: HashMap = map.extract_if(|k, _v| k % 2 == 0).collect(); /// /// let mut evens = drained.keys().cloned().collect::>(); /// let mut odds = map.keys().cloned().collect::>(); @@ -766,15 +964,24 @@ impl HashMap { /// /// assert_eq!(evens, vec![0, 2, 4, 6]); /// assert_eq!(odds, vec![1, 3, 5, 7]); + /// + /// let mut map: HashMap = (0..8).map(|x| (x, x)).collect(); + /// + /// { // Iterator is dropped without being consumed. + /// let d = map.extract_if(|k, _v| k % 2 != 0); + /// } + /// + /// // ExtractIf was not exhausted, therefore no elements were drained. + /// assert_eq!(map.len(), 8); /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn drain_filter(&mut self, f: F) -> DrainFilter<'_, K, V, F, A> + pub fn extract_if(&mut self, f: F) -> ExtractIf<'_, K, V, F, A> where F: FnMut(&K, &mut V) -> bool, { - DrainFilter { + ExtractIf { f, - inner: DrainFilterInner { + inner: RawExtractIf { iter: unsafe { self.table.iter() }, table: &mut self.table, }, @@ -791,8 +998,14 @@ impl HashMap { /// /// let mut a = HashMap::new(); /// a.insert(1, "a"); + /// let capacity_before_clear = a.capacity(); + /// /// a.clear(); + /// + /// // Map is empty. /// assert!(a.is_empty()); + /// // But map capacity is equal to old one. + /// assert_eq!(a.capacity(), capacity_before_clear); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn clear(&mut self) { @@ -813,7 +1026,12 @@ impl HashMap { /// map.insert("b", 2); /// map.insert("c", 3); /// - /// let vec: Vec<&str> = map.into_keys().collect(); + /// let mut vec: Vec<&str> = map.into_keys().collect(); + /// + /// // The `IntoKeys` iterator produces keys in arbitrary order, so the + /// // keys must be sorted to test them against a sorted array. + /// vec.sort_unstable(); + /// assert_eq!(vec, ["a", "b", "c"]); /// ``` #[inline] pub fn into_keys(self) -> IntoKeys { @@ -836,7 +1054,12 @@ impl HashMap { /// map.insert("b", 2); /// map.insert("c", 3); /// - /// let vec: Vec = map.into_values().collect(); + /// let mut vec: Vec = map.into_values().collect(); + /// + /// // The `IntoValues` iterator produces values in arbitrary order, so + /// // the values must be sorted to test them against a sorted array. + /// vec.sort_unstable(); + /// assert_eq!(vec, [1, 2, 3]); /// ``` #[inline] pub fn into_values(self) -> IntoValues { @@ -850,7 +1073,7 @@ impl HashMap where K: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { /// Reserves capacity for at least `additional` more elements to be inserted /// in the `HashMap`. The collection may reserve more space to avoid @@ -858,21 +1081,30 @@ where /// /// # Panics /// - /// Panics if the new allocation size overflows [`usize`]. + /// Panics if the new capacity exceeds [`isize::MAX`] bytes and [`abort`] the program + /// in case of allocation error. Use [`try_reserve`](HashMap::try_reserve) instead + /// if you want to handle memory allocation failure. /// - /// [`usize`]: https://doc.rust-lang.org/std/primitive.usize.html + /// [`isize::MAX`]: https://doc.rust-lang.org/std/primitive.isize.html + /// [`abort`]: https://doc.rust-lang.org/alloc/alloc/fn.handle_alloc_error.html /// /// # Examples /// /// ``` /// use hashbrown::HashMap; /// let mut map: HashMap<&str, i32> = HashMap::new(); + /// // Map is empty and doesn't allocate memory + /// assert_eq!(map.capacity(), 0); + /// /// map.reserve(10); + /// + /// // And now map can hold at least 10 elements + /// assert!(map.capacity() >= 10); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn reserve(&mut self, additional: usize) { self.table - .reserve(additional, make_hasher::(&self.hash_builder)); + .reserve(additional, make_hasher::<_, V, S>(&self.hash_builder)); } /// Tries to reserve capacity for at least `additional` more elements to be inserted @@ -888,13 +1120,41 @@ where /// /// ``` /// use hashbrown::HashMap; + /// /// let mut map: HashMap<&str, isize> = HashMap::new(); + /// // Map is empty and doesn't allocate memory + /// assert_eq!(map.capacity(), 0); + /// /// map.try_reserve(10).expect("why is the test harness OOMing on 10 bytes?"); + /// + /// // And now map can hold at least 10 elements + /// assert!(map.capacity() >= 10); + /// ``` + /// If the capacity overflows, or the allocator reports a failure, then an error + /// is returned: + /// ``` + /// # fn test() { + /// use hashbrown::HashMap; + /// use hashbrown::TryReserveError; + /// let mut map: HashMap = HashMap::new(); + /// + /// match map.try_reserve(usize::MAX) { + /// Err(error) => match error { + /// TryReserveError::CapacityOverflow => {} + /// _ => panic!("TryReserveError::AllocError ?"), + /// }, + /// _ => panic!(), + /// } + /// # } + /// # fn main() { + /// # #[cfg(not(miri))] + /// # test() + /// # } /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> { self.table - .try_reserve(additional, make_hasher::(&self.hash_builder)) + .try_reserve(additional, make_hasher::<_, V, S>(&self.hash_builder)) } /// Shrinks the capacity of the map as much as possible. It will drop @@ -916,7 +1176,7 @@ where #[cfg_attr(feature = "inline-more", inline)] pub fn shrink_to_fit(&mut self) { self.table - .shrink_to(0, make_hasher::(&self.hash_builder)); + .shrink_to(0, make_hasher::<_, V, S>(&self.hash_builder)); } /// Shrinks the capacity of the map with a lower limit. It will drop @@ -945,7 +1205,7 @@ where #[cfg_attr(feature = "inline-more", inline)] pub fn shrink_to(&mut self, min_capacity: usize) { self.table - .shrink_to(min_capacity, make_hasher::(&self.hash_builder)); + .shrink_to(min_capacity, make_hasher::<_, V, S>(&self.hash_builder)); } /// Gets the given key's corresponding entry in the map for in-place manipulation. @@ -969,7 +1229,7 @@ where /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn entry(&mut self, key: K) -> Entry<'_, K, V, S, A> { - let hash = make_insert_hash::(&self.hash_builder, &key); + let hash = make_hash::(&self.hash_builder, &key); if let Some(elem) = self.table.find(hash, equivalent_key(&key)) { Entry::Occupied(OccupiedEntry { hash, @@ -1006,10 +1266,9 @@ where #[cfg_attr(feature = "inline-more", inline)] pub fn entry_ref<'a, 'b, Q: ?Sized>(&'a mut self, key: &'b Q) -> EntryRef<'a, 'b, K, Q, V, S, A> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { - let hash = make_hash::(&self.hash_builder, key); + let hash = make_hash::(&self.hash_builder, key); if let Some(elem) = self.table.find(hash, equivalent_key(key)) { EntryRef::Occupied(OccupiedEntryRef { hash, @@ -1048,12 +1307,11 @@ where #[inline] pub fn get(&self, k: &Q) -> Option<&V> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.get_inner(k) { - Some(&(_, ref v)) => Some(v), + Some((_, v)) => Some(v), None => None, } } @@ -1080,12 +1338,11 @@ where #[inline] pub fn get_key_value(&self, k: &Q) -> Option<(&K, &V)> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.get_inner(k) { - Some(&(ref key, ref value)) => Some((key, value)), + Some((key, value)) => Some((key, value)), None => None, } } @@ -1093,13 +1350,12 @@ where #[inline] fn get_inner(&self, k: &Q) -> Option<&(K, V)> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { if self.table.is_empty() { None } else { - let hash = make_hash::(&self.hash_builder, k); + let hash = make_hash::(&self.hash_builder, k); self.table.get(hash, equivalent_key(k)) } } @@ -1130,8 +1386,7 @@ where #[inline] pub fn get_key_value_mut(&mut self, k: &Q) -> Option<(&K, &mut V)> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.get_inner_mut(k) { @@ -1162,8 +1417,7 @@ where #[cfg_attr(feature = "inline-more", inline)] pub fn contains_key(&self, k: &Q) -> bool where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { self.get_inner(k).is_some() } @@ -1188,12 +1442,13 @@ where /// *x = "b"; /// } /// assert_eq!(map[&1], "b"); + /// + /// assert_eq!(map.get_mut(&2), None); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn get_mut(&mut self, k: &Q) -> Option<&mut V> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.get_inner_mut(k) { @@ -1205,13 +1460,12 @@ where #[inline] fn get_inner_mut(&mut self, k: &Q) -> Option<&mut (K, V)> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { if self.table.is_empty() { None } else { - let hash = make_hash::(&self.hash_builder, k); + let hash = make_hash::(&self.hash_builder, k); self.table.get_mut(hash, equivalent_key(k)) } } @@ -1261,8 +1515,7 @@ where /// ``` pub fn get_many_mut(&mut self, ks: [&Q; N]) -> Option<[&'_ mut V; N]> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { self.get_many_mut_inner(ks).map(|res| res.map(|(_, v)| v)) } @@ -1273,7 +1526,7 @@ where /// Returns an array of length `N` with the results of each query. `None` will be returned if /// any of the keys are missing. /// - /// For a safe alternative see [`get_many_mut`]. + /// For a safe alternative see [`get_many_mut`](`HashMap::get_many_mut`). /// /// # Safety /// @@ -1317,8 +1570,7 @@ where ks: [&Q; N], ) -> Option<[&'_ mut V; N]> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { self.get_many_unchecked_mut_inner(ks) .map(|res| res.map(|(_, v)| v)) @@ -1373,8 +1625,7 @@ where ks: [&Q; N], ) -> Option<[(&'_ K, &'_ mut V); N]> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { self.get_many_mut_inner(ks) .map(|res| res.map(|(k, v)| (&*k, v))) @@ -1386,7 +1637,7 @@ where /// Returns an array of length `N` with the results of each query. `None` will be returned if /// any of the keys are missing. /// - /// For a safe alternative see [`get_many_key_value_mut`]. + /// For a safe alternative see [`get_many_key_value_mut`](`HashMap::get_many_key_value_mut`). /// /// # Safety /// @@ -1429,8 +1680,7 @@ where ks: [&Q; N], ) -> Option<[(&'_ K, &'_ mut V); N]> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { self.get_many_unchecked_mut_inner(ks) .map(|res| res.map(|(k, v)| (&*k, v))) @@ -1441,12 +1691,11 @@ where ks: [&Q; N], ) -> Option<[&'_ mut (K, V); N]> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { let hashes = self.build_hashes_inner(ks); self.table - .get_many_mut(hashes, |i, (k, _)| ks[i].eq(k.borrow())) + .get_many_mut(hashes, |i, (k, _)| ks[i].equivalent(k)) } unsafe fn get_many_unchecked_mut_inner( @@ -1454,22 +1703,20 @@ where ks: [&Q; N], ) -> Option<[&'_ mut (K, V); N]> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { let hashes = self.build_hashes_inner(ks); self.table - .get_many_unchecked_mut(hashes, |i, (k, _)| ks[i].eq(k.borrow())) + .get_many_unchecked_mut(hashes, |i, (k, _)| ks[i].equivalent(k)) } fn build_hashes_inner(&self, ks: [&Q; N]) -> [u64; N] where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { let mut hashes = [0_u64; N]; for i in 0..N { - hashes[i] = make_hash::(&self.hash_builder, ks[i]); + hashes[i] = make_hash::(&self.hash_builder, ks[i]); } hashes } @@ -1480,11 +1727,12 @@ where /// /// If the map did have this key present, the value is updated, and the old /// value is returned. The key is not updated, though; this matters for - /// types that can be `==` without being identical. See the [module-level - /// documentation] for more. + /// types that can be `==` without being identical. See the [`std::collections`] + /// [module-level documentation] for more. /// /// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.None - /// [module-level documentation]: index.html#insert-and-complex-keys + /// [`std::collections`]: https://doc.rust-lang.org/std/collections/index.html + /// [module-level documentation]: https://doc.rust-lang.org/std/collections/index.html#insert-and-complex-keys /// /// # Examples /// @@ -1501,13 +1749,19 @@ where /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn insert(&mut self, k: K, v: V) -> Option { - let hash = make_insert_hash::(&self.hash_builder, &k); - if let Some((_, item)) = self.table.get_mut(hash, equivalent_key(&k)) { - Some(mem::replace(item, v)) - } else { - self.table - .insert(hash, (k, v), make_hasher::(&self.hash_builder)); - None + let hash = make_hash::(&self.hash_builder, &k); + let hasher = make_hasher::<_, V, S>(&self.hash_builder); + match self + .table + .find_or_find_insert_slot(hash, equivalent_key(&k), hasher) + { + Ok(bucket) => Some(mem::replace(unsafe { &mut bucket.as_mut().1 }, v)), + Err(slot) => { + unsafe { + self.table.insert_in_slot(hash, slot, (k, v)); + } + None + } } } @@ -1531,12 +1785,41 @@ where /// This operation is useful during initial population of the map. /// For example, when constructing a map from another map, we know /// that keys are unique. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashMap; + /// + /// let mut map1 = HashMap::new(); + /// assert_eq!(map1.insert(1, "a"), None); + /// assert_eq!(map1.insert(2, "b"), None); + /// assert_eq!(map1.insert(3, "c"), None); + /// assert_eq!(map1.len(), 3); + /// + /// let mut map2 = HashMap::new(); + /// + /// for (key, value) in map1.into_iter() { + /// map2.insert_unique_unchecked(key, value); + /// } + /// + /// let (key, value) = map2.insert_unique_unchecked(4, "d"); + /// assert_eq!(key, &4); + /// assert_eq!(value, &mut "d"); + /// *value = "e"; + /// + /// assert_eq!(map2[&1], "a"); + /// assert_eq!(map2[&2], "b"); + /// assert_eq!(map2[&3], "c"); + /// assert_eq!(map2[&4], "e"); + /// assert_eq!(map2.len(), 4); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn insert_unique_unchecked(&mut self, k: K, v: V) -> (&K, &mut V) { - let hash = make_insert_hash::(&self.hash_builder, &k); + let hash = make_hash::(&self.hash_builder, &k); let bucket = self .table - .insert(hash, (k, v), make_hasher::(&self.hash_builder)); + .insert(hash, (k, v), make_hasher::<_, V, S>(&self.hash_builder)); let (k_ref, v_ref) = unsafe { bucket.as_mut() }; (k_ref, v_ref) } @@ -1555,14 +1838,19 @@ where /// /// ``` /// use hashbrown::HashMap; + /// use hashbrown::hash_map::OccupiedError; /// /// let mut map = HashMap::new(); /// assert_eq!(map.try_insert(37, "a").unwrap(), &"a"); /// - /// let err = map.try_insert(37, "b").unwrap_err(); - /// assert_eq!(err.entry.key(), &37); - /// assert_eq!(err.entry.get(), &"a"); - /// assert_eq!(err.value, "b"); + /// match map.try_insert(37, "b") { + /// Err(OccupiedError { entry, value }) => { + /// assert_eq!(entry.key(), &37); + /// assert_eq!(entry.get(), &"a"); + /// assert_eq!(value, "b"); + /// } + /// _ => panic!() + /// } /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn try_insert( @@ -1577,7 +1865,7 @@ where } /// Removes a key from the map, returning the value at the key if the key - /// was previously in the map. + /// was previously in the map. Keeps the allocated memory for reuse. /// /// The key may be any borrowed form of the map's key type, but /// [`Hash`] and [`Eq`] on the borrowed form *must* match those for @@ -1592,15 +1880,21 @@ where /// use hashbrown::HashMap; /// /// let mut map = HashMap::new(); + /// // The map is empty + /// assert!(map.is_empty() && map.capacity() == 0); + /// /// map.insert(1, "a"); + /// /// assert_eq!(map.remove(&1), Some("a")); /// assert_eq!(map.remove(&1), None); + /// + /// // Now map holds none elements + /// assert!(map.is_empty()); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn remove(&mut self, k: &Q) -> Option where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.remove_entry(k) { @@ -1610,7 +1904,7 @@ where } /// Removes a key from the map, returning the stored key and value if the - /// key was previously in the map. + /// key was previously in the map. Keeps the allocated memory for reuse. /// /// The key may be any borrowed form of the map's key type, but /// [`Hash`] and [`Eq`] on the borrowed form *must* match those for @@ -1625,22 +1919,28 @@ where /// use hashbrown::HashMap; /// /// let mut map = HashMap::new(); + /// // The map is empty + /// assert!(map.is_empty() && map.capacity() == 0); + /// /// map.insert(1, "a"); + /// /// assert_eq!(map.remove_entry(&1), Some((1, "a"))); /// assert_eq!(map.remove(&1), None); + /// + /// // Now map hold none elements + /// assert!(map.is_empty()); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn remove_entry(&mut self, k: &Q) -> Option<(K, V)> where - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { - let hash = make_hash::(&self.hash_builder, k); + let hash = make_hash::(&self.hash_builder, k); self.table.remove_entry(hash, equivalent_key(k)) } } -impl HashMap { +impl HashMap { /// Creates a raw entry builder for the HashMap. /// /// Raw entries provide the lowest level of control for searching and @@ -1672,6 +1972,72 @@ impl HashMap { /// so that the map now contains keys which compare equal, search may start /// acting erratically, with two keys randomly masking each other. Implementations /// are free to assume this doesn't happen (within the limits of memory-safety). + /// + /// # Examples + /// + /// ``` + /// use core::hash::{BuildHasher, Hash}; + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// let mut map = HashMap::new(); + /// map.extend([("a", 100), ("b", 200), ("c", 300)]); + /// + /// fn compute_hash(hash_builder: &S, key: &K) -> u64 { + /// use core::hash::Hasher; + /// let mut state = hash_builder.build_hasher(); + /// key.hash(&mut state); + /// state.finish() + /// } + /// + /// // Existing key (insert and update) + /// match map.raw_entry_mut().from_key(&"a") { + /// RawEntryMut::Vacant(_) => unreachable!(), + /// RawEntryMut::Occupied(mut view) => { + /// assert_eq!(view.get(), &100); + /// let v = view.get_mut(); + /// let new_v = (*v) * 10; + /// *v = new_v; + /// assert_eq!(view.insert(1111), 1000); + /// } + /// } + /// + /// assert_eq!(map[&"a"], 1111); + /// assert_eq!(map.len(), 3); + /// + /// // Existing key (take) + /// let hash = compute_hash(map.hasher(), &"c"); + /// match map.raw_entry_mut().from_key_hashed_nocheck(hash, &"c") { + /// RawEntryMut::Vacant(_) => unreachable!(), + /// RawEntryMut::Occupied(view) => { + /// assert_eq!(view.remove_entry(), ("c", 300)); + /// } + /// } + /// assert_eq!(map.raw_entry().from_key(&"c"), None); + /// assert_eq!(map.len(), 2); + /// + /// // Nonexistent key (insert and update) + /// let key = "d"; + /// let hash = compute_hash(map.hasher(), &key); + /// match map.raw_entry_mut().from_hash(hash, |q| *q == key) { + /// RawEntryMut::Occupied(_) => unreachable!(), + /// RawEntryMut::Vacant(view) => { + /// let (k, value) = view.insert("d", 4000); + /// assert_eq!((*k, *value), ("d", 4000)); + /// *value = 40000; + /// } + /// } + /// assert_eq!(map[&"d"], 40000); + /// assert_eq!(map.len(), 3); + /// + /// match map.raw_entry_mut().from_hash(hash, |q| *q == key) { + /// RawEntryMut::Vacant(_) => unreachable!(), + /// RawEntryMut::Occupied(view) => { + /// assert_eq!(view.remove_entry(), ("d", 40000)); + /// } + /// } + /// assert_eq!(map.get(&"d"), None); + /// assert_eq!(map.len(), 2); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S, A> { RawEntryBuilderMut { map: self } @@ -1692,10 +2058,112 @@ impl HashMap { /// `get` should be preferred. /// /// Immutable raw entries have very limited use; you might instead want `raw_entry_mut`. + /// + /// # Examples + /// + /// ``` + /// use core::hash::{BuildHasher, Hash}; + /// use hashbrown::HashMap; + /// + /// let mut map = HashMap::new(); + /// map.extend([("a", 100), ("b", 200), ("c", 300)]); + /// + /// fn compute_hash(hash_builder: &S, key: &K) -> u64 { + /// use core::hash::Hasher; + /// let mut state = hash_builder.build_hasher(); + /// key.hash(&mut state); + /// state.finish() + /// } + /// + /// for k in ["a", "b", "c", "d", "e", "f"] { + /// let hash = compute_hash(map.hasher(), k); + /// let v = map.get(&k).cloned(); + /// let kv = v.as_ref().map(|v| (&k, v)); + /// + /// println!("Key: {} and value: {:?}", k, v); + /// + /// assert_eq!(map.raw_entry().from_key(&k), kv); + /// assert_eq!(map.raw_entry().from_hash(hash, |q| *q == k), kv); + /// assert_eq!(map.raw_entry().from_key_hashed_nocheck(hash, &k), kv); + /// } + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S, A> { RawEntryBuilder { map: self } } + + /// Returns a reference to the [`RawTable`] used underneath [`HashMap`]. + /// This function is only available if the `raw` feature of the crate is enabled. + /// + /// See [`raw_table_mut`] for more. + /// + /// [`raw_table_mut`]: Self::raw_table_mut + #[cfg(feature = "raw")] + #[cfg_attr(feature = "inline-more", inline)] + pub fn raw_table(&self) -> &RawTable<(K, V), A> { + &self.table + } + + /// Returns a mutable reference to the [`RawTable`] used underneath [`HashMap`]. + /// This function is only available if the `raw` feature of the crate is enabled. + /// + /// # Note + /// + /// Calling this function is safe, but using the raw hash table API may require + /// unsafe functions or blocks. + /// + /// `RawTable` API gives the lowest level of control under the map that can be useful + /// for extending the HashMap's API, but may lead to *[undefined behavior]*. + /// + /// [`HashMap`]: struct.HashMap.html + /// [`RawTable`]: crate::raw::RawTable + /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + /// + /// # Examples + /// + /// ``` + /// use core::hash::{BuildHasher, Hash}; + /// use hashbrown::HashMap; + /// + /// let mut map = HashMap::new(); + /// map.extend([("a", 10), ("b", 20), ("c", 30)]); + /// assert_eq!(map.len(), 3); + /// + /// // Let's imagine that we have a value and a hash of the key, but not the key itself. + /// // However, if you want to remove the value from the map by hash and value, and you + /// // know exactly that the value is unique, then you can create a function like this: + /// fn remove_by_hash( + /// map: &mut HashMap, + /// hash: u64, + /// is_match: F, + /// ) -> Option<(K, V)> + /// where + /// F: Fn(&(K, V)) -> bool, + /// { + /// let raw_table = map.raw_table_mut(); + /// match raw_table.find(hash, is_match) { + /// Some(bucket) => Some(unsafe { raw_table.remove(bucket).0 }), + /// None => None, + /// } + /// } + /// + /// fn compute_hash(hash_builder: &S, key: &K) -> u64 { + /// use core::hash::Hasher; + /// let mut state = hash_builder.build_hasher(); + /// key.hash(&mut state); + /// state.finish() + /// } + /// + /// let hash = compute_hash(map.hasher(), "a"); + /// assert_eq!(remove_by_hash(&mut map, hash, |(_, v)| *v == 10), Some(("a", 10))); + /// assert_eq!(map.get(&"a"), None); + /// assert_eq!(map.len(), 2); + /// ``` + #[cfg(feature = "raw")] + #[cfg_attr(feature = "inline-more", inline)] + pub fn raw_table_mut(&mut self) -> &mut RawTable<(K, V), A> { + &mut self.table + } } impl PartialEq for HashMap @@ -1703,7 +2171,7 @@ where K: Eq + Hash, V: PartialEq, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { fn eq(&self, other: &Self) -> bool { if self.len() != other.len() { @@ -1720,7 +2188,7 @@ where K: Eq + Hash, V: Eq, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { } @@ -1728,7 +2196,7 @@ impl Debug for HashMap where K: Debug, V: Debug, - A: Allocator + Clone, + A: Allocator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_map().entries(self.iter()).finish() @@ -1738,9 +2206,23 @@ where impl Default for HashMap where S: Default, - A: Default + Allocator + Clone, + A: Default + Allocator, { /// Creates an empty `HashMap`, with the `Default` value for the hasher and allocator. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashMap; + /// use std::collections::hash_map::RandomState; + /// + /// // You can specify all types of HashMap, including hasher and allocator. + /// // Created map is empty and don't allocate memory + /// let map: HashMap = Default::default(); + /// assert_eq!(map.capacity(), 0); + /// let map: HashMap = HashMap::default(); + /// assert_eq!(map.capacity(), 0); + /// ``` #[cfg_attr(feature = "inline-more", inline)] fn default() -> Self { Self::with_hasher_in(Default::default(), Default::default()) @@ -1749,10 +2231,10 @@ where impl Index<&Q> for HashMap where - K: Eq + Hash + Borrow, - Q: Eq + Hash, + K: Eq + Hash, + Q: Hash + Equivalent, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { type Output = V; @@ -1761,6 +2243,17 @@ where /// # Panics /// /// Panics if the key is not present in the `HashMap`. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashMap; + /// + /// let map: HashMap<_, _> = [("a", "One"), ("b", "Two")].into(); + /// + /// assert_eq!(map[&"a"], "One"); + /// assert_eq!(map[&"b"], "Two"); + /// ``` #[cfg_attr(feature = "inline-more", inline)] fn index(&self, key: &Q) -> &V { self.get(key).expect("no entry found for key") @@ -1772,7 +2265,7 @@ where impl From<[(K, V); N]> for HashMap where K: Eq + Hash, - A: Default + Allocator + Clone, + A: Default + Allocator, { /// # Examples /// @@ -1788,13 +2281,34 @@ where } } -/// An iterator over the entries of a `HashMap`. +/// An iterator over the entries of a `HashMap` in arbitrary order. +/// The iterator element type is `(&'a K, &'a V)`. /// /// This `struct` is created by the [`iter`] method on [`HashMap`]. See its /// documentation for more. /// /// [`iter`]: struct.HashMap.html#method.iter /// [`HashMap`]: struct.HashMap.html +/// +/// # Examples +/// +/// ``` +/// use hashbrown::HashMap; +/// +/// let map: HashMap<_, _> = [(1, "a"), (2, "b"), (3, "c")].into(); +/// +/// let mut iter = map.iter(); +/// let mut vec = vec![iter.next(), iter.next(), iter.next()]; +/// +/// // The `Iter` iterator produces items in arbitrary order, so the +/// // items must be sorted to test them against a sorted array. +/// vec.sort_unstable(); +/// assert_eq!(vec, [Some((&1, &"a")), Some((&2, &"b")), Some((&3, &"c"))]); +/// +/// // It is fused iterator +/// assert_eq!(iter.next(), None); +/// assert_eq!(iter.next(), None); +/// ``` pub struct Iter<'a, K, V> { inner: RawIter<(K, V)>, marker: PhantomData<(&'a K, &'a V)>, @@ -1817,13 +2331,33 @@ impl fmt::Debug for Iter<'_, K, V> { } } -/// A mutable iterator over the entries of a `HashMap`. +/// A mutable iterator over the entries of a `HashMap` in arbitrary order. +/// The iterator element type is `(&'a K, &'a mut V)`. /// /// This `struct` is created by the [`iter_mut`] method on [`HashMap`]. See its /// documentation for more. /// /// [`iter_mut`]: struct.HashMap.html#method.iter_mut /// [`HashMap`]: struct.HashMap.html +/// +/// # Examples +/// +/// ``` +/// use hashbrown::HashMap; +/// +/// let mut map: HashMap<_, _> = [(1, "One".to_owned()), (2, "Two".into())].into(); +/// +/// let mut iter = map.iter_mut(); +/// iter.next().map(|(_, v)| v.push_str(" Mississippi")); +/// iter.next().map(|(_, v)| v.push_str(" Mississippi")); +/// +/// // It is fused iterator +/// assert_eq!(iter.next(), None); +/// assert_eq!(iter.next(), None); +/// +/// assert_eq!(map.get(&1).unwrap(), &"One Mississippi".to_owned()); +/// assert_eq!(map.get(&2).unwrap(), &"Two Mississippi".to_owned()); +/// ``` pub struct IterMut<'a, K, V> { inner: RawIter<(K, V)>, // To ensure invariance with respect to V @@ -1846,18 +2380,41 @@ impl IterMut<'_, K, V> { } } -/// An owning iterator over the entries of a `HashMap`. +/// An owning iterator over the entries of a `HashMap` in arbitrary order. +/// The iterator element type is `(K, V)`. /// /// This `struct` is created by the [`into_iter`] method on [`HashMap`] -/// (provided by the `IntoIterator` trait). See its documentation for more. +/// (provided by the [`IntoIterator`] trait). See its documentation for more. +/// The map cannot be used after calling that method. /// /// [`into_iter`]: struct.HashMap.html#method.into_iter /// [`HashMap`]: struct.HashMap.html -pub struct IntoIter { +/// [`IntoIterator`]: https://doc.rust-lang.org/core/iter/trait.IntoIterator.html +/// +/// # Examples +/// +/// ``` +/// use hashbrown::HashMap; +/// +/// let map: HashMap<_, _> = [(1, "a"), (2, "b"), (3, "c")].into(); +/// +/// let mut iter = map.into_iter(); +/// let mut vec = vec![iter.next(), iter.next(), iter.next()]; +/// +/// // The `IntoIter` iterator produces items in arbitrary order, so the +/// // items must be sorted to test them against a sorted array. +/// vec.sort_unstable(); +/// assert_eq!(vec, [Some((1, "a")), Some((2, "b")), Some((3, "c"))]); +/// +/// // It is fused iterator +/// assert_eq!(iter.next(), None); +/// assert_eq!(iter.next(), None); +/// ``` +pub struct IntoIter { inner: RawIntoIter<(K, V), A>, } -impl IntoIter { +impl IntoIter { /// Returns a iterator of references over the remaining items. #[cfg_attr(feature = "inline-more", inline)] pub(super) fn iter(&self) -> Iter<'_, K, V> { @@ -1868,18 +2425,40 @@ impl IntoIter { } } -/// An owning iterator over the keys of a `HashMap`. +/// An owning iterator over the keys of a `HashMap` in arbitrary order. +/// The iterator element type is `K`. /// /// This `struct` is created by the [`into_keys`] method on [`HashMap`]. /// See its documentation for more. +/// The map cannot be used after calling that method. /// /// [`into_keys`]: struct.HashMap.html#method.into_keys /// [`HashMap`]: struct.HashMap.html -pub struct IntoKeys { +/// +/// # Examples +/// +/// ``` +/// use hashbrown::HashMap; +/// +/// let map: HashMap<_, _> = [(1, "a"), (2, "b"), (3, "c")].into(); +/// +/// let mut keys = map.into_keys(); +/// let mut vec = vec![keys.next(), keys.next(), keys.next()]; +/// +/// // The `IntoKeys` iterator produces keys in arbitrary order, so the +/// // keys must be sorted to test them against a sorted array. +/// vec.sort_unstable(); +/// assert_eq!(vec, [Some(1), Some(2), Some(3)]); +/// +/// // It is fused iterator +/// assert_eq!(keys.next(), None); +/// assert_eq!(keys.next(), None); +/// ``` +pub struct IntoKeys { inner: IntoIter, } -impl Iterator for IntoKeys { +impl Iterator for IntoKeys { type Item = K; #[inline] @@ -1892,16 +2471,16 @@ impl Iterator for IntoKeys { } } -impl ExactSizeIterator for IntoKeys { +impl ExactSizeIterator for IntoKeys { #[inline] fn len(&self) -> usize { self.inner.len() } } -impl FusedIterator for IntoKeys {} +impl FusedIterator for IntoKeys {} -impl fmt::Debug for IntoKeys { +impl fmt::Debug for IntoKeys { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list() .entries(self.inner.iter().map(|(k, _)| k)) @@ -1909,18 +2488,39 @@ impl fmt::Debug for IntoKeys } } -/// An owning iterator over the values of a `HashMap`. +/// An owning iterator over the values of a `HashMap` in arbitrary order. +/// The iterator element type is `V`. /// /// This `struct` is created by the [`into_values`] method on [`HashMap`]. -/// See its documentation for more. +/// See its documentation for more. The map cannot be used after calling that method. /// /// [`into_values`]: struct.HashMap.html#method.into_values /// [`HashMap`]: struct.HashMap.html -pub struct IntoValues { +/// +/// # Examples +/// +/// ``` +/// use hashbrown::HashMap; +/// +/// let map: HashMap<_, _> = [(1, "a"), (2, "b"), (3, "c")].into(); +/// +/// let mut values = map.into_values(); +/// let mut vec = vec![values.next(), values.next(), values.next()]; +/// +/// // The `IntoValues` iterator produces values in arbitrary order, so +/// // the values must be sorted to test them against a sorted array. +/// vec.sort_unstable(); +/// assert_eq!(vec, [Some("a"), Some("b"), Some("c")]); +/// +/// // It is fused iterator +/// assert_eq!(values.next(), None); +/// assert_eq!(values.next(), None); +/// ``` +pub struct IntoValues { inner: IntoIter, } -impl Iterator for IntoValues { +impl Iterator for IntoValues { type Item = V; #[inline] @@ -1933,30 +2533,51 @@ impl Iterator for IntoValues { } } -impl ExactSizeIterator for IntoValues { +impl ExactSizeIterator for IntoValues { #[inline] fn len(&self) -> usize { self.inner.len() } } -impl FusedIterator for IntoValues {} +impl FusedIterator for IntoValues {} -impl fmt::Debug for IntoValues { +impl fmt::Debug for IntoValues { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list() - .entries(self.inner.iter().map(|(k, _)| k)) + .entries(self.inner.iter().map(|(_, v)| v)) .finish() } } -/// An iterator over the keys of a `HashMap`. +/// An iterator over the keys of a `HashMap` in arbitrary order. +/// The iterator element type is `&'a K`. /// /// This `struct` is created by the [`keys`] method on [`HashMap`]. See its /// documentation for more. /// /// [`keys`]: struct.HashMap.html#method.keys /// [`HashMap`]: struct.HashMap.html +/// +/// # Examples +/// +/// ``` +/// use hashbrown::HashMap; +/// +/// let map: HashMap<_, _> = [(1, "a"), (2, "b"), (3, "c")].into(); +/// +/// let mut keys = map.keys(); +/// let mut vec = vec![keys.next(), keys.next(), keys.next()]; +/// +/// // The `Keys` iterator produces keys in arbitrary order, so the +/// // keys must be sorted to test them against a sorted array. +/// vec.sort_unstable(); +/// assert_eq!(vec, [Some(&1), Some(&2), Some(&3)]); +/// +/// // It is fused iterator +/// assert_eq!(keys.next(), None); +/// assert_eq!(keys.next(), None); +/// ``` pub struct Keys<'a, K, V> { inner: Iter<'a, K, V>, } @@ -1977,13 +2598,34 @@ impl fmt::Debug for Keys<'_, K, V> { } } -/// An iterator over the values of a `HashMap`. +/// An iterator over the values of a `HashMap` in arbitrary order. +/// The iterator element type is `&'a V`. /// /// This `struct` is created by the [`values`] method on [`HashMap`]. See its /// documentation for more. /// /// [`values`]: struct.HashMap.html#method.values /// [`HashMap`]: struct.HashMap.html +/// +/// # Examples +/// +/// ``` +/// use hashbrown::HashMap; +/// +/// let map: HashMap<_, _> = [(1, "a"), (2, "b"), (3, "c")].into(); +/// +/// let mut values = map.values(); +/// let mut vec = vec![values.next(), values.next(), values.next()]; +/// +/// // The `Values` iterator produces values in arbitrary order, so the +/// // values must be sorted to test them against a sorted array. +/// vec.sort_unstable(); +/// assert_eq!(vec, [Some(&"a"), Some(&"b"), Some(&"c")]); +/// +/// // It is fused iterator +/// assert_eq!(values.next(), None); +/// assert_eq!(values.next(), None); +/// ``` pub struct Values<'a, K, V> { inner: Iter<'a, K, V>, } @@ -2004,18 +2646,39 @@ impl fmt::Debug for Values<'_, K, V> { } } -/// A draining iterator over the entries of a `HashMap`. +/// A draining iterator over the entries of a `HashMap` in arbitrary +/// order. The iterator element type is `(K, V)`. /// /// This `struct` is created by the [`drain`] method on [`HashMap`]. See its /// documentation for more. /// /// [`drain`]: struct.HashMap.html#method.drain /// [`HashMap`]: struct.HashMap.html -pub struct Drain<'a, K, V, A: Allocator + Clone = Global> { +/// +/// # Examples +/// +/// ``` +/// use hashbrown::HashMap; +/// +/// let mut map: HashMap<_, _> = [(1, "a"), (2, "b"), (3, "c")].into(); +/// +/// let mut drain_iter = map.drain(); +/// let mut vec = vec![drain_iter.next(), drain_iter.next(), drain_iter.next()]; +/// +/// // The `Drain` iterator produces items in arbitrary order, so the +/// // items must be sorted to test them against a sorted array. +/// vec.sort_unstable(); +/// assert_eq!(vec, [Some((1, "a")), Some((2, "b")), Some((3, "c"))]); +/// +/// // It is fused iterator +/// assert_eq!(drain_iter.next(), None); +/// assert_eq!(drain_iter.next(), None); +/// ``` +pub struct Drain<'a, K, V, A: Allocator = Global> { inner: RawDrain<'a, (K, V), A>, } -impl Drain<'_, K, V, A> { +impl Drain<'_, K, V, A> { /// Returns a iterator of references over the remaining items. #[cfg_attr(feature = "inline-more", inline)] pub(super) fn iter(&self) -> Iter<'_, K, V> { @@ -2026,55 +2689,56 @@ impl Drain<'_, K, V, A> { } } -/// A draining iterator over entries of a `HashMap` which don't satisfy the predicate `f`. +/// A draining iterator over entries of a `HashMap` which don't satisfy the predicate +/// `f(&k, &mut v)` in arbitrary order. The iterator element type is `(K, V)`. /// -/// This `struct` is created by the [`drain_filter`] method on [`HashMap`]. See its +/// This `struct` is created by the [`extract_if`] method on [`HashMap`]. See its /// documentation for more. /// -/// [`drain_filter`]: struct.HashMap.html#method.drain_filter +/// [`extract_if`]: struct.HashMap.html#method.extract_if /// [`HashMap`]: struct.HashMap.html -pub struct DrainFilter<'a, K, V, F, A: Allocator + Clone = Global> +/// +/// # Examples +/// +/// ``` +/// use hashbrown::HashMap; +/// +/// let mut map: HashMap = [(1, "a"), (2, "b"), (3, "c")].into(); +/// +/// let mut extract_if = map.extract_if(|k, _v| k % 2 != 0); +/// let mut vec = vec![extract_if.next(), extract_if.next()]; +/// +/// // The `ExtractIf` iterator produces items in arbitrary order, so the +/// // items must be sorted to test them against a sorted array. +/// vec.sort_unstable(); +/// assert_eq!(vec, [Some((1, "a")),Some((3, "c"))]); +/// +/// // It is fused iterator +/// assert_eq!(extract_if.next(), None); +/// assert_eq!(extract_if.next(), None); +/// drop(extract_if); +/// +/// assert_eq!(map.len(), 1); +/// ``` +#[must_use = "Iterators are lazy unless consumed"] +pub struct ExtractIf<'a, K, V, F, A: Allocator = Global> where F: FnMut(&K, &mut V) -> bool, { f: F, - inner: DrainFilterInner<'a, K, V, A>, -} - -impl<'a, K, V, F, A> Drop for DrainFilter<'a, K, V, F, A> -where - F: FnMut(&K, &mut V) -> bool, - A: Allocator + Clone, -{ - #[cfg_attr(feature = "inline-more", inline)] - fn drop(&mut self) { - while let Some(item) = self.next() { - let guard = ConsumeAllOnDrop(self); - drop(item); - mem::forget(guard); - } - } -} - -pub(super) struct ConsumeAllOnDrop<'a, T: Iterator>(pub &'a mut T); - -impl Drop for ConsumeAllOnDrop<'_, T> { - #[cfg_attr(feature = "inline-more", inline)] - fn drop(&mut self) { - self.0.for_each(drop); - } + inner: RawExtractIf<'a, (K, V), A>, } -impl Iterator for DrainFilter<'_, K, V, F, A> +impl Iterator for ExtractIf<'_, K, V, F, A> where F: FnMut(&K, &mut V) -> bool, - A: Allocator + Clone, + A: Allocator, { type Item = (K, V); #[cfg_attr(feature = "inline-more", inline)] fn next(&mut self) -> Option { - self.inner.next(&mut self.f) + self.inner.next(|&mut (ref k, ref mut v)| (self.f)(k, v)) } #[inline] @@ -2083,39 +2747,35 @@ where } } -impl FusedIterator for DrainFilter<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool {} +impl FusedIterator for ExtractIf<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool {} -/// Portions of `DrainFilter` shared with `set::DrainFilter` -pub(super) struct DrainFilterInner<'a, K, V, A: Allocator + Clone> { - pub iter: RawIter<(K, V)>, - pub table: &'a mut RawTable<(K, V), A>, -} - -impl DrainFilterInner<'_, K, V, A> { - #[cfg_attr(feature = "inline-more", inline)] - pub(super) fn next(&mut self, f: &mut F) -> Option<(K, V)> - where - F: FnMut(&K, &mut V) -> bool, - { - unsafe { - for item in &mut self.iter { - let &mut (ref key, ref mut value) = item.as_mut(); - if f(key, value) { - return Some(self.table.remove(item)); - } - } - } - None - } -} - -/// A mutable iterator over the values of a `HashMap`. +/// A mutable iterator over the values of a `HashMap` in arbitrary order. +/// The iterator element type is `&'a mut V`. /// /// This `struct` is created by the [`values_mut`] method on [`HashMap`]. See its /// documentation for more. /// /// [`values_mut`]: struct.HashMap.html#method.values_mut /// [`HashMap`]: struct.HashMap.html +/// +/// # Examples +/// +/// ``` +/// use hashbrown::HashMap; +/// +/// let mut map: HashMap<_, _> = [(1, "One".to_owned()), (2, "Two".into())].into(); +/// +/// let mut values = map.values_mut(); +/// values.next().map(|v| v.push_str(" Mississippi")); +/// values.next().map(|v| v.push_str(" Mississippi")); +/// +/// // It is fused iterator +/// assert_eq!(values.next(), None); +/// assert_eq!(values.next(), None); +/// +/// assert_eq!(map.get(&1).unwrap(), &"One Mississippi".to_owned()); +/// assert_eq!(map.get(&2).unwrap(), &"Two Mississippi".to_owned()); +/// ``` pub struct ValuesMut<'a, K, V> { inner: IterMut<'a, K, V>, } @@ -2125,7 +2785,57 @@ pub struct ValuesMut<'a, K, V> { /// See the [`HashMap::raw_entry_mut`] docs for usage examples. /// /// [`HashMap::raw_entry_mut`]: struct.HashMap.html#method.raw_entry_mut -pub struct RawEntryBuilderMut<'a, K, V, S, A: Allocator + Clone = Global> { +/// +/// # Examples +/// +/// ``` +/// use hashbrown::hash_map::{RawEntryBuilderMut, RawEntryMut::Vacant, RawEntryMut::Occupied}; +/// use hashbrown::HashMap; +/// use core::hash::{BuildHasher, Hash}; +/// +/// let mut map = HashMap::new(); +/// map.extend([(1, 11), (2, 12), (3, 13), (4, 14), (5, 15), (6, 16)]); +/// assert_eq!(map.len(), 6); +/// +/// fn compute_hash(hash_builder: &S, key: &K) -> u64 { +/// use core::hash::Hasher; +/// let mut state = hash_builder.build_hasher(); +/// key.hash(&mut state); +/// state.finish() +/// } +/// +/// let builder: RawEntryBuilderMut<_, _, _> = map.raw_entry_mut(); +/// +/// // Existing key +/// match builder.from_key(&6) { +/// Vacant(_) => unreachable!(), +/// Occupied(view) => assert_eq!(view.get(), &16), +/// } +/// +/// for key in 0..12 { +/// let hash = compute_hash(map.hasher(), &key); +/// let value = map.get(&key).cloned(); +/// let key_value = value.as_ref().map(|v| (&key, v)); +/// +/// println!("Key: {} and value: {:?}", key, value); +/// +/// match map.raw_entry_mut().from_key(&key) { +/// Occupied(mut o) => assert_eq!(Some(o.get_key_value()), key_value), +/// Vacant(_) => assert_eq!(value, None), +/// } +/// match map.raw_entry_mut().from_key_hashed_nocheck(hash, &key) { +/// Occupied(mut o) => assert_eq!(Some(o.get_key_value()), key_value), +/// Vacant(_) => assert_eq!(value, None), +/// } +/// match map.raw_entry_mut().from_hash(hash, |q| *q == key) { +/// Occupied(mut o) => assert_eq!(Some(o.get_key_value()), key_value), +/// Vacant(_) => assert_eq!(value, None), +/// } +/// } +/// +/// assert_eq!(map.len(), 6); +/// ``` +pub struct RawEntryBuilderMut<'a, K, V, S, A: Allocator = Global> { map: &'a mut HashMap, } @@ -2140,10 +2850,107 @@ pub struct RawEntryBuilderMut<'a, K, V, S, A: Allocator + Clone = Global> { /// [`Entry`]: enum.Entry.html /// [`raw_entry_mut`]: struct.HashMap.html#method.raw_entry_mut /// [`RawEntryBuilderMut`]: struct.RawEntryBuilderMut.html -pub enum RawEntryMut<'a, K, V, S, A: Allocator + Clone = Global> { +/// +/// # Examples +/// +/// ``` +/// use core::hash::{BuildHasher, Hash}; +/// use hashbrown::hash_map::{HashMap, RawEntryMut, RawOccupiedEntryMut}; +/// +/// let mut map = HashMap::new(); +/// map.extend([('a', 1), ('b', 2), ('c', 3)]); +/// assert_eq!(map.len(), 3); +/// +/// fn compute_hash(hash_builder: &S, key: &K) -> u64 { +/// use core::hash::Hasher; +/// let mut state = hash_builder.build_hasher(); +/// key.hash(&mut state); +/// state.finish() +/// } +/// +/// // Existing key (insert) +/// let raw: RawEntryMut<_, _, _> = map.raw_entry_mut().from_key(&'a'); +/// let _raw_o: RawOccupiedEntryMut<_, _, _> = raw.insert('a', 10); +/// assert_eq!(map.len(), 3); +/// +/// // Nonexistent key (insert) +/// map.raw_entry_mut().from_key(&'d').insert('d', 40); +/// assert_eq!(map.len(), 4); +/// +/// // Existing key (or_insert) +/// let hash = compute_hash(map.hasher(), &'b'); +/// let kv = map +/// .raw_entry_mut() +/// .from_key_hashed_nocheck(hash, &'b') +/// .or_insert('b', 20); +/// assert_eq!(kv, (&mut 'b', &mut 2)); +/// *kv.1 = 20; +/// assert_eq!(map.len(), 4); +/// +/// // Nonexistent key (or_insert) +/// let hash = compute_hash(map.hasher(), &'e'); +/// let kv = map +/// .raw_entry_mut() +/// .from_key_hashed_nocheck(hash, &'e') +/// .or_insert('e', 50); +/// assert_eq!(kv, (&mut 'e', &mut 50)); +/// assert_eq!(map.len(), 5); +/// +/// // Existing key (or_insert_with) +/// let hash = compute_hash(map.hasher(), &'c'); +/// let kv = map +/// .raw_entry_mut() +/// .from_hash(hash, |q| q == &'c') +/// .or_insert_with(|| ('c', 30)); +/// assert_eq!(kv, (&mut 'c', &mut 3)); +/// *kv.1 = 30; +/// assert_eq!(map.len(), 5); +/// +/// // Nonexistent key (or_insert_with) +/// let hash = compute_hash(map.hasher(), &'f'); +/// let kv = map +/// .raw_entry_mut() +/// .from_hash(hash, |q| q == &'f') +/// .or_insert_with(|| ('f', 60)); +/// assert_eq!(kv, (&mut 'f', &mut 60)); +/// assert_eq!(map.len(), 6); +/// +/// println!("Our HashMap: {:?}", map); +/// +/// let mut vec: Vec<_> = map.iter().map(|(&k, &v)| (k, v)).collect(); +/// // The `Iter` iterator produces items in arbitrary order, so the +/// // items must be sorted to test them against a sorted array. +/// vec.sort_unstable(); +/// assert_eq!(vec, [('a', 10), ('b', 20), ('c', 30), ('d', 40), ('e', 50), ('f', 60)]); +/// ``` +pub enum RawEntryMut<'a, K, V, S, A: Allocator = Global> { /// An occupied entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::{hash_map::RawEntryMut, HashMap}; + /// let mut map: HashMap<_, _> = [("a", 100), ("b", 200)].into(); + /// + /// match map.raw_entry_mut().from_key(&"a") { + /// RawEntryMut::Vacant(_) => unreachable!(), + /// RawEntryMut::Occupied(_) => { } + /// } + /// ``` Occupied(RawOccupiedEntryMut<'a, K, V, S, A>), /// A vacant entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::{hash_map::RawEntryMut, HashMap}; + /// let mut map: HashMap<&str, i32> = HashMap::new(); + /// + /// match map.raw_entry_mut().from_key("a") { + /// RawEntryMut::Occupied(_) => unreachable!(), + /// RawEntryMut::Vacant(_) => { } + /// } + /// ``` Vacant(RawVacantEntryMut<'a, K, V, S, A>), } @@ -2151,7 +2958,63 @@ pub enum RawEntryMut<'a, K, V, S, A: Allocator + Clone = Global> { /// It is part of the [`RawEntryMut`] enum. /// /// [`RawEntryMut`]: enum.RawEntryMut.html -pub struct RawOccupiedEntryMut<'a, K, V, S, A: Allocator + Clone = Global> { +/// +/// # Examples +/// +/// ``` +/// use core::hash::{BuildHasher, Hash}; +/// use hashbrown::hash_map::{HashMap, RawEntryMut, RawOccupiedEntryMut}; +/// +/// let mut map = HashMap::new(); +/// map.extend([("a", 10), ("b", 20), ("c", 30)]); +/// +/// fn compute_hash(hash_builder: &S, key: &K) -> u64 { +/// use core::hash::Hasher; +/// let mut state = hash_builder.build_hasher(); +/// key.hash(&mut state); +/// state.finish() +/// } +/// +/// let _raw_o: RawOccupiedEntryMut<_, _, _> = map.raw_entry_mut().from_key(&"a").insert("a", 100); +/// assert_eq!(map.len(), 3); +/// +/// // Existing key (insert and update) +/// match map.raw_entry_mut().from_key(&"a") { +/// RawEntryMut::Vacant(_) => unreachable!(), +/// RawEntryMut::Occupied(mut view) => { +/// assert_eq!(view.get(), &100); +/// let v = view.get_mut(); +/// let new_v = (*v) * 10; +/// *v = new_v; +/// assert_eq!(view.insert(1111), 1000); +/// } +/// } +/// +/// assert_eq!(map[&"a"], 1111); +/// assert_eq!(map.len(), 3); +/// +/// // Existing key (take) +/// let hash = compute_hash(map.hasher(), &"c"); +/// match map.raw_entry_mut().from_key_hashed_nocheck(hash, &"c") { +/// RawEntryMut::Vacant(_) => unreachable!(), +/// RawEntryMut::Occupied(view) => { +/// assert_eq!(view.remove_entry(), ("c", 30)); +/// } +/// } +/// assert_eq!(map.raw_entry().from_key(&"c"), None); +/// assert_eq!(map.len(), 2); +/// +/// let hash = compute_hash(map.hasher(), &"b"); +/// match map.raw_entry_mut().from_hash(hash, |q| *q == "b") { +/// RawEntryMut::Vacant(_) => unreachable!(), +/// RawEntryMut::Occupied(view) => { +/// assert_eq!(view.remove_entry(), ("b", 20)); +/// } +/// } +/// assert_eq!(map.get(&"b"), None); +/// assert_eq!(map.len(), 1); +/// ``` +pub struct RawOccupiedEntryMut<'a, K, V, S, A: Allocator = Global> { elem: Bucket<(K, V)>, table: &'a mut RawTable<(K, V), A>, hash_builder: &'a S, @@ -2162,7 +3025,7 @@ where K: Send, V: Send, S: Send, - A: Send + Allocator + Clone, + A: Send + Allocator, { } unsafe impl Sync for RawOccupiedEntryMut<'_, K, V, S, A> @@ -2170,7 +3033,7 @@ where K: Sync, V: Sync, S: Sync, - A: Sync + Allocator + Clone, + A: Sync + Allocator, { } @@ -2178,7 +3041,51 @@ where /// It is part of the [`RawEntryMut`] enum. /// /// [`RawEntryMut`]: enum.RawEntryMut.html -pub struct RawVacantEntryMut<'a, K, V, S, A: Allocator + Clone = Global> { +/// +/// # Examples +/// +/// ``` +/// use core::hash::{BuildHasher, Hash}; +/// use hashbrown::hash_map::{HashMap, RawEntryMut, RawVacantEntryMut}; +/// +/// let mut map = HashMap::<&str, i32>::new(); +/// +/// fn compute_hash(hash_builder: &S, key: &K) -> u64 { +/// use core::hash::Hasher; +/// let mut state = hash_builder.build_hasher(); +/// key.hash(&mut state); +/// state.finish() +/// } +/// +/// let raw_v: RawVacantEntryMut<_, _, _> = match map.raw_entry_mut().from_key(&"a") { +/// RawEntryMut::Vacant(view) => view, +/// RawEntryMut::Occupied(_) => unreachable!(), +/// }; +/// raw_v.insert("a", 10); +/// assert!(map[&"a"] == 10 && map.len() == 1); +/// +/// // Nonexistent key (insert and update) +/// let hash = compute_hash(map.hasher(), &"b"); +/// match map.raw_entry_mut().from_key_hashed_nocheck(hash, &"b") { +/// RawEntryMut::Occupied(_) => unreachable!(), +/// RawEntryMut::Vacant(view) => { +/// let (k, value) = view.insert("b", 2); +/// assert_eq!((*k, *value), ("b", 2)); +/// *value = 20; +/// } +/// } +/// assert!(map[&"b"] == 20 && map.len() == 2); +/// +/// let hash = compute_hash(map.hasher(), &"c"); +/// match map.raw_entry_mut().from_hash(hash, |q| *q == "c") { +/// RawEntryMut::Occupied(_) => unreachable!(), +/// RawEntryMut::Vacant(view) => { +/// assert_eq!(view.insert("c", 30), (&mut "c", &mut 30)); +/// } +/// } +/// assert!(map[&"c"] == 30 && map.len() == 3); +/// ``` +pub struct RawVacantEntryMut<'a, K, V, S, A: Allocator = Global> { table: &'a mut RawTable<(K, V), A>, hash_builder: &'a S, } @@ -2188,38 +3095,119 @@ pub struct RawVacantEntryMut<'a, K, V, S, A: Allocator + Clone = Global> { /// See the [`HashMap::raw_entry`] docs for usage examples. /// /// [`HashMap::raw_entry`]: struct.HashMap.html#method.raw_entry -pub struct RawEntryBuilder<'a, K, V, S, A: Allocator + Clone = Global> { +/// +/// # Examples +/// +/// ``` +/// use hashbrown::hash_map::{HashMap, RawEntryBuilder}; +/// use core::hash::{BuildHasher, Hash}; +/// +/// let mut map = HashMap::new(); +/// map.extend([(1, 10), (2, 20), (3, 30)]); +/// +/// fn compute_hash(hash_builder: &S, key: &K) -> u64 { +/// use core::hash::Hasher; +/// let mut state = hash_builder.build_hasher(); +/// key.hash(&mut state); +/// state.finish() +/// } +/// +/// for k in 0..6 { +/// let hash = compute_hash(map.hasher(), &k); +/// let v = map.get(&k).cloned(); +/// let kv = v.as_ref().map(|v| (&k, v)); +/// +/// println!("Key: {} and value: {:?}", k, v); +/// let builder: RawEntryBuilder<_, _, _> = map.raw_entry(); +/// assert_eq!(builder.from_key(&k), kv); +/// assert_eq!(map.raw_entry().from_hash(hash, |q| *q == k), kv); +/// assert_eq!(map.raw_entry().from_key_hashed_nocheck(hash, &k), kv); +/// } +/// ``` +pub struct RawEntryBuilder<'a, K, V, S, A: Allocator = Global> { map: &'a HashMap, } -impl<'a, K, V, S, A: Allocator + Clone> RawEntryBuilderMut<'a, K, V, S, A> { +impl<'a, K, V, S, A: Allocator> RawEntryBuilderMut<'a, K, V, S, A> { /// Creates a `RawEntryMut` from the given key. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// let mut map: HashMap<&str, u32> = HashMap::new(); + /// let key = "a"; + /// let entry: RawEntryMut<&str, u32, _> = map.raw_entry_mut().from_key(&key); + /// entry.insert(key, 100); + /// assert_eq!(map[&"a"], 100); + /// ``` #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::wrong_self_convention)] pub fn from_key(self, k: &Q) -> RawEntryMut<'a, K, V, S, A> where S: BuildHasher, - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { - let hash = make_hash::(&self.map.hash_builder, k); + let hash = make_hash::(&self.map.hash_builder, k); self.from_key_hashed_nocheck(hash, k) } /// Creates a `RawEntryMut` from the given key and its hash. + /// + /// # Examples + /// + /// ``` + /// use core::hash::{BuildHasher, Hash}; + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// fn compute_hash(hash_builder: &S, key: &K) -> u64 { + /// use core::hash::Hasher; + /// let mut state = hash_builder.build_hasher(); + /// key.hash(&mut state); + /// state.finish() + /// } + /// + /// let mut map: HashMap<&str, u32> = HashMap::new(); + /// let key = "a"; + /// let hash = compute_hash(map.hasher(), &key); + /// let entry: RawEntryMut<&str, u32, _> = map.raw_entry_mut().from_key_hashed_nocheck(hash, &key); + /// entry.insert(key, 100); + /// assert_eq!(map[&"a"], 100); + /// ``` #[inline] #[allow(clippy::wrong_self_convention)] pub fn from_key_hashed_nocheck(self, hash: u64, k: &Q) -> RawEntryMut<'a, K, V, S, A> where - K: Borrow, - Q: Eq, + Q: Equivalent, { self.from_hash(hash, equivalent(k)) } } -impl<'a, K, V, S, A: Allocator + Clone> RawEntryBuilderMut<'a, K, V, S, A> { - /// Creates a `RawEntryMut` from the given hash. +impl<'a, K, V, S, A: Allocator> RawEntryBuilderMut<'a, K, V, S, A> { + /// Creates a `RawEntryMut` from the given hash and matching function. + /// + /// # Examples + /// + /// ``` + /// use core::hash::{BuildHasher, Hash}; + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// fn compute_hash(hash_builder: &S, key: &K) -> u64 { + /// use core::hash::Hasher; + /// let mut state = hash_builder.build_hasher(); + /// key.hash(&mut state); + /// state.finish() + /// } + /// + /// let mut map: HashMap<&str, u32> = HashMap::new(); + /// let key = "a"; + /// let hash = compute_hash(map.hasher(), &key); + /// let entry: RawEntryMut<&str, u32, _> = map.raw_entry_mut().from_hash(hash, |k| k == &key); + /// entry.insert(key, 100); + /// assert_eq!(map[&"a"], 100); + /// ``` #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::wrong_self_convention)] pub fn from_hash(self, hash: u64, is_match: F) -> RawEntryMut<'a, K, V, S, A> @@ -2248,27 +3236,54 @@ impl<'a, K, V, S, A: Allocator + Clone> RawEntryBuilderMut<'a, K, V, S, A> { } } -impl<'a, K, V, S, A: Allocator + Clone> RawEntryBuilder<'a, K, V, S, A> { - /// Access an entry by key. +impl<'a, K, V, S, A: Allocator> RawEntryBuilder<'a, K, V, S, A> { + /// Access an immutable entry by key. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashMap; + /// + /// let map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// let key = "a"; + /// assert_eq!(map.raw_entry().from_key(&key), Some((&"a", &100))); + /// ``` #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::wrong_self_convention)] pub fn from_key(self, k: &Q) -> Option<(&'a K, &'a V)> where S: BuildHasher, - K: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { - let hash = make_hash::(&self.map.hash_builder, k); + let hash = make_hash::(&self.map.hash_builder, k); self.from_key_hashed_nocheck(hash, k) } - /// Access an entry by a key and its hash. + /// Access an immutable entry by a key and its hash. + /// + /// # Examples + /// + /// ``` + /// use core::hash::{BuildHasher, Hash}; + /// use hashbrown::HashMap; + /// + /// fn compute_hash(hash_builder: &S, key: &K) -> u64 { + /// use core::hash::Hasher; + /// let mut state = hash_builder.build_hasher(); + /// key.hash(&mut state); + /// state.finish() + /// } + /// + /// let map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// let key = "a"; + /// let hash = compute_hash(map.hasher(), &key); + /// assert_eq!(map.raw_entry().from_key_hashed_nocheck(hash, &key), Some((&"a", &100))); + /// ``` #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::wrong_self_convention)] pub fn from_key_hashed_nocheck(self, hash: u64, k: &Q) -> Option<(&'a K, &'a V)> where - K: Borrow, - Q: Eq, + Q: Equivalent, { self.from_hash(hash, equivalent(k)) } @@ -2279,12 +3294,31 @@ impl<'a, K, V, S, A: Allocator + Clone> RawEntryBuilder<'a, K, V, S, A> { F: FnMut(&K) -> bool, { match self.map.table.get(hash, |(k, _)| is_match(k)) { - Some(&(ref key, ref value)) => Some((key, value)), + Some((key, value)) => Some((key, value)), None => None, } } - /// Access an entry by hash. + /// Access an immutable entry by hash and matching function. + /// + /// # Examples + /// + /// ``` + /// use core::hash::{BuildHasher, Hash}; + /// use hashbrown::HashMap; + /// + /// fn compute_hash(hash_builder: &S, key: &K) -> u64 { + /// use core::hash::Hasher; + /// let mut state = hash_builder.build_hasher(); + /// key.hash(&mut state); + /// state.finish() + /// } + /// + /// let map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// let key = "a"; + /// let hash = compute_hash(map.hasher(), &key); + /// assert_eq!(map.raw_entry().from_hash(hash, |k| k == &key), Some((&"a", &100))); + /// ``` #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::wrong_self_convention)] pub fn from_hash(self, hash: u64, is_match: F) -> Option<(&'a K, &'a V)> @@ -2295,7 +3329,7 @@ impl<'a, K, V, S, A: Allocator + Clone> RawEntryBuilder<'a, K, V, S, A> { } } -impl<'a, K, V, S, A: Allocator + Clone> RawEntryMut<'a, K, V, S, A> { +impl<'a, K, V, S, A: Allocator> RawEntryMut<'a, K, V, S, A> { /// Sets the value of the entry, and returns a RawOccupiedEntryMut. /// /// # Examples @@ -2489,14 +3523,52 @@ impl<'a, K, V, S, A: Allocator + Clone> RawEntryMut<'a, K, V, S, A> { } } -impl<'a, K, V, S, A: Allocator + Clone> RawOccupiedEntryMut<'a, K, V, S, A> { +impl<'a, K, V, S, A: Allocator> RawOccupiedEntryMut<'a, K, V, S, A> { /// Gets a reference to the key in the entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// let mut map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// + /// match map.raw_entry_mut().from_key(&"a") { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(o) => assert_eq!(o.key(), &"a") + /// } + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn key(&self) -> &K { unsafe { &self.elem.as_ref().0 } } /// Gets a mutable reference to the key in the entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// use std::rc::Rc; + /// + /// let key_one = Rc::new("a"); + /// let key_two = Rc::new("a"); + /// + /// let mut map: HashMap, u32> = HashMap::new(); + /// map.insert(key_one.clone(), 10); + /// + /// assert_eq!(map[&key_one], 10); + /// assert!(Rc::strong_count(&key_one) == 2 && Rc::strong_count(&key_two) == 1); + /// + /// match map.raw_entry_mut().from_key(&key_one) { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(mut o) => { + /// *o.key_mut() = key_two.clone(); + /// } + /// } + /// assert_eq!(map[&key_two], 10); + /// assert!(Rc::strong_count(&key_one) == 1 && Rc::strong_count(&key_two) == 2); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn key_mut(&mut self) -> &mut K { unsafe { &mut self.elem.as_mut().0 } @@ -2504,12 +3576,52 @@ impl<'a, K, V, S, A: Allocator + Clone> RawOccupiedEntryMut<'a, K, V, S, A> { /// Converts the entry into a mutable reference to the key in the entry /// with a lifetime bound to the map itself. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// use std::rc::Rc; + /// + /// let key_one = Rc::new("a"); + /// let key_two = Rc::new("a"); + /// + /// let mut map: HashMap, u32> = HashMap::new(); + /// map.insert(key_one.clone(), 10); + /// + /// assert_eq!(map[&key_one], 10); + /// assert!(Rc::strong_count(&key_one) == 2 && Rc::strong_count(&key_two) == 1); + /// + /// let inside_key: &mut Rc<&str>; + /// + /// match map.raw_entry_mut().from_key(&key_one) { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(o) => inside_key = o.into_key(), + /// } + /// *inside_key = key_two.clone(); + /// + /// assert_eq!(map[&key_two], 10); + /// assert!(Rc::strong_count(&key_one) == 1 && Rc::strong_count(&key_two) == 2); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn into_key(self) -> &'a mut K { unsafe { &mut self.elem.as_mut().0 } } /// Gets a reference to the value in the entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// let mut map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// + /// match map.raw_entry_mut().from_key(&"a") { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(o) => assert_eq!(o.get(), &100), + /// } + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn get(&self) -> &V { unsafe { &self.elem.as_ref().1 } @@ -2517,27 +3629,100 @@ impl<'a, K, V, S, A: Allocator + Clone> RawOccupiedEntryMut<'a, K, V, S, A> { /// Converts the OccupiedEntry into a mutable reference to the value in the entry /// with a lifetime bound to the map itself. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// let mut map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// + /// let value: &mut u32; + /// + /// match map.raw_entry_mut().from_key(&"a") { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(o) => value = o.into_mut(), + /// } + /// *value += 900; + /// + /// assert_eq!(map[&"a"], 1000); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn into_mut(self) -> &'a mut V { unsafe { &mut self.elem.as_mut().1 } } /// Gets a mutable reference to the value in the entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// let mut map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// + /// match map.raw_entry_mut().from_key(&"a") { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(mut o) => *o.get_mut() += 900, + /// } + /// + /// assert_eq!(map[&"a"], 1000); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn get_mut(&mut self) -> &mut V { unsafe { &mut self.elem.as_mut().1 } } /// Gets a reference to the key and value in the entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// let mut map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// + /// match map.raw_entry_mut().from_key(&"a") { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(o) => assert_eq!(o.get_key_value(), (&"a", &100)), + /// } + /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn get_key_value(&mut self) -> (&K, &V) { + pub fn get_key_value(&self) -> (&K, &V) { unsafe { - let &(ref key, ref value) = self.elem.as_ref(); + let (key, value) = self.elem.as_ref(); (key, value) } } /// Gets a mutable reference to the key and value in the entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// use std::rc::Rc; + /// + /// let key_one = Rc::new("a"); + /// let key_two = Rc::new("a"); + /// + /// let mut map: HashMap, u32> = HashMap::new(); + /// map.insert(key_one.clone(), 10); + /// + /// assert_eq!(map[&key_one], 10); + /// assert!(Rc::strong_count(&key_one) == 2 && Rc::strong_count(&key_two) == 1); + /// + /// match map.raw_entry_mut().from_key(&key_one) { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(mut o) => { + /// let (inside_key, inside_value) = o.get_key_value_mut(); + /// *inside_key = key_two.clone(); + /// *inside_value = 100; + /// } + /// } + /// assert_eq!(map[&key_two], 100); + /// assert!(Rc::strong_count(&key_one) == 1 && Rc::strong_count(&key_two) == 2); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn get_key_value_mut(&mut self) -> (&mut K, &mut V) { unsafe { @@ -2548,6 +3733,37 @@ impl<'a, K, V, S, A: Allocator + Clone> RawOccupiedEntryMut<'a, K, V, S, A> { /// Converts the OccupiedEntry into a mutable reference to the key and value in the entry /// with a lifetime bound to the map itself. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// use std::rc::Rc; + /// + /// let key_one = Rc::new("a"); + /// let key_two = Rc::new("a"); + /// + /// let mut map: HashMap, u32> = HashMap::new(); + /// map.insert(key_one.clone(), 10); + /// + /// assert_eq!(map[&key_one], 10); + /// assert!(Rc::strong_count(&key_one) == 2 && Rc::strong_count(&key_two) == 1); + /// + /// let inside_key: &mut Rc<&str>; + /// let inside_value: &mut u32; + /// match map.raw_entry_mut().from_key(&key_one) { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(o) => { + /// let tuple = o.into_key_value(); + /// inside_key = tuple.0; + /// inside_value = tuple.1; + /// } + /// } + /// *inside_key = key_two.clone(); + /// *inside_value = 100; + /// assert_eq!(map[&key_two], 100); + /// assert!(Rc::strong_count(&key_one) == 1 && Rc::strong_count(&key_two) == 2); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn into_key_value(self) -> (&'a mut K, &'a mut V) { unsafe { @@ -2557,32 +3773,131 @@ impl<'a, K, V, S, A: Allocator + Clone> RawOccupiedEntryMut<'a, K, V, S, A> { } /// Sets the value of the entry, and returns the entry's old value. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// let mut map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// + /// match map.raw_entry_mut().from_key(&"a") { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(mut o) => assert_eq!(o.insert(1000), 100), + /// } + /// + /// assert_eq!(map[&"a"], 1000); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn insert(&mut self, value: V) -> V { mem::replace(self.get_mut(), value) } /// Sets the value of the entry, and returns the entry's old value. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// use std::rc::Rc; + /// + /// let key_one = Rc::new("a"); + /// let key_two = Rc::new("a"); + /// + /// let mut map: HashMap, u32> = HashMap::new(); + /// map.insert(key_one.clone(), 10); + /// + /// assert_eq!(map[&key_one], 10); + /// assert!(Rc::strong_count(&key_one) == 2 && Rc::strong_count(&key_two) == 1); + /// + /// match map.raw_entry_mut().from_key(&key_one) { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(mut o) => { + /// let old_key = o.insert_key(key_two.clone()); + /// assert!(Rc::ptr_eq(&old_key, &key_one)); + /// } + /// } + /// assert_eq!(map[&key_two], 10); + /// assert!(Rc::strong_count(&key_one) == 1 && Rc::strong_count(&key_two) == 2); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn insert_key(&mut self, key: K) -> K { mem::replace(self.key_mut(), key) } /// Takes the value out of the entry, and returns it. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// let mut map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// + /// match map.raw_entry_mut().from_key(&"a") { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(o) => assert_eq!(o.remove(), 100), + /// } + /// assert_eq!(map.get(&"a"), None); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn remove(self) -> V { self.remove_entry().1 } /// Take the ownership of the key and value from the map. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// let mut map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// + /// match map.raw_entry_mut().from_key(&"a") { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(o) => assert_eq!(o.remove_entry(), ("a", 100)), + /// } + /// assert_eq!(map.get(&"a"), None); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn remove_entry(self) -> (K, V) { - unsafe { self.table.remove(self.elem) } + unsafe { self.table.remove(self.elem).0 } } /// Provides shared access to the key and owned access to the value of /// the entry and allows to replace or remove it based on the /// value of the returned option. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// let mut map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// + /// let raw_entry = match map.raw_entry_mut().from_key(&"a") { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(o) => o.replace_entry_with(|k, v| { + /// assert_eq!(k, &"a"); + /// assert_eq!(v, 100); + /// Some(v + 900) + /// }), + /// }; + /// let raw_entry = match raw_entry { + /// RawEntryMut::Vacant(_) => panic!(), + /// RawEntryMut::Occupied(o) => o.replace_entry_with(|k, v| { + /// assert_eq!(k, &"a"); + /// assert_eq!(v, 1000); + /// None + /// }), + /// }; + /// match raw_entry { + /// RawEntryMut::Vacant(_) => { }, + /// RawEntryMut::Occupied(_) => panic!(), + /// }; + /// assert_eq!(map.get(&"a"), None); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn replace_entry_with(self, f: F) -> RawEntryMut<'a, K, V, S, A> where @@ -2607,21 +3922,64 @@ impl<'a, K, V, S, A: Allocator + Clone> RawOccupiedEntryMut<'a, K, V, S, A> { } } -impl<'a, K, V, S, A: Allocator + Clone> RawVacantEntryMut<'a, K, V, S, A> { +impl<'a, K, V, S, A: Allocator> RawVacantEntryMut<'a, K, V, S, A> { /// Sets the value of the entry with the VacantEntry's key, /// and returns a mutable reference to it. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// let mut map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// + /// match map.raw_entry_mut().from_key(&"c") { + /// RawEntryMut::Occupied(_) => panic!(), + /// RawEntryMut::Vacant(v) => assert_eq!(v.insert("c", 300), (&mut "c", &mut 300)), + /// } + /// + /// assert_eq!(map[&"c"], 300); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn insert(self, key: K, value: V) -> (&'a mut K, &'a mut V) where K: Hash, S: BuildHasher, { - let hash = make_insert_hash::(self.hash_builder, &key); + let hash = make_hash::(self.hash_builder, &key); self.insert_hashed_nocheck(hash, key, value) } /// Sets the value of the entry with the VacantEntry's key, /// and returns a mutable reference to it. + /// + /// # Examples + /// + /// ``` + /// use core::hash::{BuildHasher, Hash}; + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// fn compute_hash(hash_builder: &S, key: &K) -> u64 { + /// use core::hash::Hasher; + /// let mut state = hash_builder.build_hasher(); + /// key.hash(&mut state); + /// state.finish() + /// } + /// + /// let mut map: HashMap<&str, u32> = [("a", 100), ("b", 200)].into(); + /// let key = "c"; + /// let hash = compute_hash(map.hasher(), &key); + /// + /// match map.raw_entry_mut().from_key_hashed_nocheck(hash, &key) { + /// RawEntryMut::Occupied(_) => panic!(), + /// RawEntryMut::Vacant(v) => assert_eq!( + /// v.insert_hashed_nocheck(hash, key, 300), + /// (&mut "c", &mut 300) + /// ), + /// } + /// + /// assert_eq!(map[&"c"], 300); + /// ``` #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::shadow_unrelated)] pub fn insert_hashed_nocheck(self, hash: u64, key: K, value: V) -> (&'a mut K, &'a mut V) @@ -2632,12 +3990,47 @@ impl<'a, K, V, S, A: Allocator + Clone> RawVacantEntryMut<'a, K, V, S, A> { let &mut (ref mut k, ref mut v) = self.table.insert_entry( hash, (key, value), - make_hasher::(self.hash_builder), + make_hasher::<_, V, S>(self.hash_builder), ); (k, v) } /// Set the value of an entry with a custom hasher function. + /// + /// # Examples + /// + /// ``` + /// use core::hash::{BuildHasher, Hash}; + /// use hashbrown::hash_map::{HashMap, RawEntryMut}; + /// + /// fn make_hasher(hash_builder: &S) -> impl Fn(&K) -> u64 + '_ + /// where + /// K: Hash + ?Sized, + /// S: BuildHasher, + /// { + /// move |key: &K| { + /// use core::hash::Hasher; + /// let mut state = hash_builder.build_hasher(); + /// key.hash(&mut state); + /// state.finish() + /// } + /// } + /// + /// let mut map: HashMap<&str, u32> = HashMap::new(); + /// let key = "a"; + /// let hash_builder = map.hasher().clone(); + /// let hash = make_hasher(&hash_builder)(&key); + /// + /// match map.raw_entry_mut().from_hash(hash, |q| q == &key) { + /// RawEntryMut::Occupied(_) => panic!(), + /// RawEntryMut::Vacant(v) => assert_eq!( + /// v.insert_with_hasher(hash, key, 100, make_hasher(&hash_builder)), + /// (&mut "a", &mut 100) + /// ), + /// } + /// map.extend([("b", 200), ("c", 300), ("d", 400), ("e", 500), ("f", 600)]); + /// assert_eq!(map[&"a"], 100); + /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn insert_with_hasher( self, @@ -2661,11 +4054,11 @@ impl<'a, K, V, S, A: Allocator + Clone> RawVacantEntryMut<'a, K, V, S, A> { K: Hash, S: BuildHasher, { - let hash = make_insert_hash::(self.hash_builder, &key); + let hash = make_hash::(self.hash_builder, &key); let elem = self.table.insert( hash, (key, value), - make_hasher::(self.hash_builder), + make_hasher::<_, V, S>(self.hash_builder), ); RawOccupiedEntryMut { elem, @@ -2675,13 +4068,13 @@ impl<'a, K, V, S, A: Allocator + Clone> RawVacantEntryMut<'a, K, V, S, A> { } } -impl Debug for RawEntryBuilderMut<'_, K, V, S, A> { +impl Debug for RawEntryBuilderMut<'_, K, V, S, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("RawEntryBuilder").finish() } } -impl Debug for RawEntryMut<'_, K, V, S, A> { +impl Debug for RawEntryMut<'_, K, V, S, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { RawEntryMut::Vacant(ref v) => f.debug_tuple("RawEntry").field(v).finish(), @@ -2690,7 +4083,7 @@ impl Debug for RawEntryMut<'_, K, V } } -impl Debug for RawOccupiedEntryMut<'_, K, V, S, A> { +impl Debug for RawOccupiedEntryMut<'_, K, V, S, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("RawOccupiedEntryMut") .field("key", self.key()) @@ -2699,13 +4092,13 @@ impl Debug for RawOccupiedEntryMut< } } -impl Debug for RawVacantEntryMut<'_, K, V, S, A> { +impl Debug for RawVacantEntryMut<'_, K, V, S, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("RawVacantEntryMut").finish() } } -impl Debug for RawEntryBuilder<'_, K, V, S, A> { +impl Debug for RawEntryBuilder<'_, K, V, S, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("RawEntryBuilder").finish() } @@ -2717,18 +4110,79 @@ impl Debug for RawEntryBuilder<'_, K, V, S, A> { /// /// [`HashMap`]: struct.HashMap.html /// [`entry`]: struct.HashMap.html#method.entry +/// +/// # Examples +/// +/// ``` +/// use hashbrown::hash_map::{Entry, HashMap, OccupiedEntry}; +/// +/// let mut map = HashMap::new(); +/// map.extend([("a", 10), ("b", 20), ("c", 30)]); +/// assert_eq!(map.len(), 3); +/// +/// // Existing key (insert) +/// let entry: Entry<_, _, _> = map.entry("a"); +/// let _raw_o: OccupiedEntry<_, _, _> = entry.insert(1); +/// assert_eq!(map.len(), 3); +/// // Nonexistent key (insert) +/// map.entry("d").insert(4); +/// +/// // Existing key (or_insert) +/// let v = map.entry("b").or_insert(2); +/// assert_eq!(std::mem::replace(v, 2), 20); +/// // Nonexistent key (or_insert) +/// map.entry("e").or_insert(5); +/// +/// // Existing key (or_insert_with) +/// let v = map.entry("c").or_insert_with(|| 3); +/// assert_eq!(std::mem::replace(v, 3), 30); +/// // Nonexistent key (or_insert_with) +/// map.entry("f").or_insert_with(|| 6); +/// +/// println!("Our HashMap: {:?}", map); +/// +/// let mut vec: Vec<_> = map.iter().map(|(&k, &v)| (k, v)).collect(); +/// // The `Iter` iterator produces items in arbitrary order, so the +/// // items must be sorted to test them against a sorted array. +/// vec.sort_unstable(); +/// assert_eq!(vec, [("a", 1), ("b", 2), ("c", 3), ("d", 4), ("e", 5), ("f", 6)]); +/// ``` pub enum Entry<'a, K, V, S, A = Global> where - A: Allocator + Clone, + A: Allocator, { /// An occupied entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{Entry, HashMap}; + /// let mut map: HashMap<_, _> = [("a", 100), ("b", 200)].into(); + /// + /// match map.entry("a") { + /// Entry::Vacant(_) => unreachable!(), + /// Entry::Occupied(_) => { } + /// } + /// ``` Occupied(OccupiedEntry<'a, K, V, S, A>), /// A vacant entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{Entry, HashMap}; + /// let mut map: HashMap<&str, i32> = HashMap::new(); + /// + /// match map.entry("a") { + /// Entry::Occupied(_) => unreachable!(), + /// Entry::Vacant(_) => { } + /// } + /// ``` Vacant(VacantEntry<'a, K, V, S, A>), } -impl Debug for Entry<'_, K, V, S, A> { +impl Debug for Entry<'_, K, V, S, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Entry::Vacant(ref v) => f.debug_tuple("Entry").field(v).finish(), @@ -2741,7 +4195,43 @@ impl Debug for Entry<'_, K, V, S, A /// It is part of the [`Entry`] enum. /// /// [`Entry`]: enum.Entry.html -pub struct OccupiedEntry<'a, K, V, S, A: Allocator + Clone = Global> { +/// +/// # Examples +/// +/// ``` +/// use hashbrown::hash_map::{Entry, HashMap, OccupiedEntry}; +/// +/// let mut map = HashMap::new(); +/// map.extend([("a", 10), ("b", 20), ("c", 30)]); +/// +/// let _entry_o: OccupiedEntry<_, _, _> = map.entry("a").insert(100); +/// assert_eq!(map.len(), 3); +/// +/// // Existing key (insert and update) +/// match map.entry("a") { +/// Entry::Vacant(_) => unreachable!(), +/// Entry::Occupied(mut view) => { +/// assert_eq!(view.get(), &100); +/// let v = view.get_mut(); +/// *v *= 10; +/// assert_eq!(view.insert(1111), 1000); +/// } +/// } +/// +/// assert_eq!(map[&"a"], 1111); +/// assert_eq!(map.len(), 3); +/// +/// // Existing key (take) +/// match map.entry("c") { +/// Entry::Vacant(_) => unreachable!(), +/// Entry::Occupied(view) => { +/// assert_eq!(view.remove_entry(), ("c", 30)); +/// } +/// } +/// assert_eq!(map.get(&"c"), None); +/// assert_eq!(map.len(), 2); +/// ``` +pub struct OccupiedEntry<'a, K, V, S = DefaultHashBuilder, A: Allocator = Global> { hash: u64, key: Option, elem: Bucket<(K, V)>, @@ -2753,7 +4243,7 @@ where K: Send, V: Send, S: Send, - A: Send + Allocator + Clone, + A: Send + Allocator, { } unsafe impl Sync for OccupiedEntry<'_, K, V, S, A> @@ -2761,11 +4251,11 @@ where K: Sync, V: Sync, S: Sync, - A: Sync + Allocator + Clone, + A: Sync + Allocator, { } -impl Debug for OccupiedEntry<'_, K, V, S, A> { +impl Debug for OccupiedEntry<'_, K, V, S, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("OccupiedEntry") .field("key", self.key()) @@ -2778,36 +4268,132 @@ impl Debug for OccupiedEntry<'_, K, /// It is part of the [`Entry`] enum. /// /// [`Entry`]: enum.Entry.html -pub struct VacantEntry<'a, K, V, S, A: Allocator + Clone = Global> { +/// +/// # Examples +/// +/// ``` +/// use hashbrown::hash_map::{Entry, HashMap, VacantEntry}; +/// +/// let mut map = HashMap::<&str, i32>::new(); +/// +/// let entry_v: VacantEntry<_, _, _> = match map.entry("a") { +/// Entry::Vacant(view) => view, +/// Entry::Occupied(_) => unreachable!(), +/// }; +/// entry_v.insert(10); +/// assert!(map[&"a"] == 10 && map.len() == 1); +/// +/// // Nonexistent key (insert and update) +/// match map.entry("b") { +/// Entry::Occupied(_) => unreachable!(), +/// Entry::Vacant(view) => { +/// let value = view.insert(2); +/// assert_eq!(*value, 2); +/// *value = 20; +/// } +/// } +/// assert!(map[&"b"] == 20 && map.len() == 2); +/// ``` +pub struct VacantEntry<'a, K, V, S = DefaultHashBuilder, A: Allocator = Global> { hash: u64, key: K, table: &'a mut HashMap, } -impl Debug for VacantEntry<'_, K, V, S, A> { +impl Debug for VacantEntry<'_, K, V, S, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("VacantEntry").field(self.key()).finish() } } -/// A view into a single entry in a map, which may either be vacant or occupied. +/// A view into a single entry in a map, which may either be vacant or occupied, +/// with any borrowed form of the map's key type. +/// /// /// This `enum` is constructed from the [`entry_ref`] method on [`HashMap`]. /// +/// [`Hash`] and [`Eq`] on the borrowed form of the map's key type *must* match those +/// for the key type. It also require that key may be constructed from the borrowed +/// form through the [`From`] trait. +/// /// [`HashMap`]: struct.HashMap.html /// [`entry_ref`]: struct.HashMap.html#method.entry_ref +/// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html +/// [`Hash`]: https://doc.rust-lang.org/std/hash/trait.Hash.html +/// [`From`]: https://doc.rust-lang.org/std/convert/trait.From.html +/// +/// # Examples +/// +/// ``` +/// use hashbrown::hash_map::{EntryRef, HashMap, OccupiedEntryRef}; +/// +/// let mut map = HashMap::new(); +/// map.extend([("a".to_owned(), 10), ("b".into(), 20), ("c".into(), 30)]); +/// assert_eq!(map.len(), 3); +/// +/// // Existing key (insert) +/// let key = String::from("a"); +/// let entry: EntryRef<_, _, _, _> = map.entry_ref(&key); +/// let _raw_o: OccupiedEntryRef<_, _, _, _> = entry.insert(1); +/// assert_eq!(map.len(), 3); +/// // Nonexistent key (insert) +/// map.entry_ref("d").insert(4); +/// +/// // Existing key (or_insert) +/// let v = map.entry_ref("b").or_insert(2); +/// assert_eq!(std::mem::replace(v, 2), 20); +/// // Nonexistent key (or_insert) +/// map.entry_ref("e").or_insert(5); +/// +/// // Existing key (or_insert_with) +/// let v = map.entry_ref("c").or_insert_with(|| 3); +/// assert_eq!(std::mem::replace(v, 3), 30); +/// // Nonexistent key (or_insert_with) +/// map.entry_ref("f").or_insert_with(|| 6); +/// +/// println!("Our HashMap: {:?}", map); +/// +/// for (key, value) in ["a", "b", "c", "d", "e", "f"].into_iter().zip(1..=6) { +/// assert_eq!(map[key], value) +/// } +/// assert_eq!(map.len(), 6); +/// ``` pub enum EntryRef<'a, 'b, K, Q: ?Sized, V, S, A = Global> where - A: Allocator + Clone, + A: Allocator, { /// An occupied entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{EntryRef, HashMap}; + /// let mut map: HashMap<_, _> = [("a".to_owned(), 100), ("b".into(), 200)].into(); + /// + /// match map.entry_ref("a") { + /// EntryRef::Vacant(_) => unreachable!(), + /// EntryRef::Occupied(_) => { } + /// } + /// ``` Occupied(OccupiedEntryRef<'a, 'b, K, Q, V, S, A>), /// A vacant entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::{EntryRef, HashMap}; + /// let mut map: HashMap = HashMap::new(); + /// + /// match map.entry_ref("a") { + /// EntryRef::Occupied(_) => unreachable!(), + /// EntryRef::Vacant(_) => { } + /// } + /// ``` Vacant(VacantEntryRef<'a, 'b, K, Q, V, S, A>), } -impl, Q: ?Sized + Debug, V: Debug, S, A: Allocator + Clone> Debug +impl, Q: ?Sized + Debug, V: Debug, S, A: Allocator> Debug for EntryRef<'_, '_, K, Q, V, S, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -2848,7 +4434,44 @@ impl<'a, K: Borrow, Q: ?Sized> AsRef for KeyOrRef<'a, K, Q> { /// It is part of the [`EntryRef`] enum. /// /// [`EntryRef`]: enum.EntryRef.html -pub struct OccupiedEntryRef<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone = Global> { +/// +/// # Examples +/// +/// ``` +/// use hashbrown::hash_map::{EntryRef, HashMap, OccupiedEntryRef}; +/// +/// let mut map = HashMap::new(); +/// map.extend([("a".to_owned(), 10), ("b".into(), 20), ("c".into(), 30)]); +/// +/// let key = String::from("a"); +/// let _entry_o: OccupiedEntryRef<_, _, _, _> = map.entry_ref(&key).insert(100); +/// assert_eq!(map.len(), 3); +/// +/// // Existing key (insert and update) +/// match map.entry_ref("a") { +/// EntryRef::Vacant(_) => unreachable!(), +/// EntryRef::Occupied(mut view) => { +/// assert_eq!(view.get(), &100); +/// let v = view.get_mut(); +/// *v *= 10; +/// assert_eq!(view.insert(1111), 1000); +/// } +/// } +/// +/// assert_eq!(map["a"], 1111); +/// assert_eq!(map.len(), 3); +/// +/// // Existing key (take) +/// match map.entry_ref("c") { +/// EntryRef::Vacant(_) => unreachable!(), +/// EntryRef::Occupied(view) => { +/// assert_eq!(view.remove_entry(), ("c".to_owned(), 30)); +/// } +/// } +/// assert_eq!(map.get("c"), None); +/// assert_eq!(map.len(), 2); +/// ``` +pub struct OccupiedEntryRef<'a, 'b, K, Q: ?Sized, V, S, A: Allocator = Global> { hash: u64, key: Option>, elem: Bucket<(K, V)>, @@ -2861,7 +4484,7 @@ where Q: Sync + ?Sized, V: Send, S: Send, - A: Send + Allocator + Clone, + A: Send + Allocator, { } unsafe impl<'a, 'b, K, Q, V, S, A> Sync for OccupiedEntryRef<'a, 'b, K, Q, V, S, A> @@ -2870,16 +4493,16 @@ where Q: Sync + ?Sized, V: Sync, S: Sync, - A: Sync + Allocator + Clone, + A: Sync + Allocator, { } -impl, Q: ?Sized + Debug, V: Debug, S, A: Allocator + Clone> Debug +impl, Q: ?Sized + Debug, V: Debug, S, A: Allocator> Debug for OccupiedEntryRef<'_, '_, K, Q, V, S, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("OccupiedEntryRef") - .field("key", &self.key()) + .field("key", &self.key().borrow()) .field("value", &self.get()) .finish() } @@ -2889,13 +4512,39 @@ impl, Q: ?Sized + Debug, V: Debug, S, A: Allocator + Clone> Debug /// It is part of the [`EntryRef`] enum. /// /// [`EntryRef`]: enum.EntryRef.html -pub struct VacantEntryRef<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone = Global> { +/// +/// # Examples +/// +/// ``` +/// use hashbrown::hash_map::{EntryRef, HashMap, VacantEntryRef}; +/// +/// let mut map = HashMap::::new(); +/// +/// let entry_v: VacantEntryRef<_, _, _, _> = match map.entry_ref("a") { +/// EntryRef::Vacant(view) => view, +/// EntryRef::Occupied(_) => unreachable!(), +/// }; +/// entry_v.insert(10); +/// assert!(map["a"] == 10 && map.len() == 1); +/// +/// // Nonexistent key (insert and update) +/// match map.entry_ref("b") { +/// EntryRef::Occupied(_) => unreachable!(), +/// EntryRef::Vacant(view) => { +/// let value = view.insert(2); +/// assert_eq!(*value, 2); +/// *value = 20; +/// } +/// } +/// assert!(map["b"] == 20 && map.len() == 2); +/// ``` +pub struct VacantEntryRef<'a, 'b, K, Q: ?Sized, V, S, A: Allocator = Global> { hash: u64, key: KeyOrRef<'b, K, Q>, table: &'a mut HashMap, } -impl, Q: ?Sized + Debug, V, S, A: Allocator + Clone> Debug +impl, Q: ?Sized + Debug, V, S, A: Allocator> Debug for VacantEntryRef<'_, '_, K, Q, V, S, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -2906,14 +4555,35 @@ impl, Q: ?Sized + Debug, V, S, A: Allocator + Clone> Debug /// The error returned by [`try_insert`](HashMap::try_insert) when the key already exists. /// /// Contains the occupied entry, and the value that was not inserted. -pub struct OccupiedError<'a, K, V, S, A: Allocator + Clone = Global> { +/// +/// # Examples +/// +/// ``` +/// use hashbrown::hash_map::{HashMap, OccupiedError}; +/// +/// let mut map: HashMap<_, _> = [("a", 10), ("b", 20)].into(); +/// +/// // try_insert method returns mutable reference to the value if keys are vacant, +/// // but if the map did have key present, nothing is updated, and the provided +/// // value is returned inside `Err(_)` variant +/// match map.try_insert("a", 100) { +/// Err(OccupiedError { mut entry, value }) => { +/// assert_eq!(entry.key(), &"a"); +/// assert_eq!(value, 100); +/// assert_eq!(entry.insert(100), 10) +/// } +/// _ => unreachable!(), +/// } +/// assert_eq!(map[&"a"], 100); +/// ``` +pub struct OccupiedError<'a, K, V, S, A: Allocator = Global> { /// The entry in the map that was already occupied. pub entry: OccupiedEntry<'a, K, V, S, A>, /// The value which was not inserted, because the entry was already occupied. pub value: V, } -impl Debug for OccupiedError<'_, K, V, S, A> { +impl Debug for OccupiedError<'_, K, V, S, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("OccupiedError") .field("key", self.entry.key()) @@ -2923,9 +4593,7 @@ impl Debug for OccupiedError<'_, K, } } -impl<'a, K: Debug, V: Debug, S, A: Allocator + Clone> fmt::Display - for OccupiedError<'a, K, V, S, A> -{ +impl<'a, K: Debug, V: Debug, S, A: Allocator> fmt::Display for OccupiedError<'a, K, V, S, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, @@ -2937,27 +4605,76 @@ impl<'a, K: Debug, V: Debug, S, A: Allocator + Clone> fmt::Display } } -impl<'a, K, V, S, A: Allocator + Clone> IntoIterator for &'a HashMap { +impl<'a, K, V, S, A: Allocator> IntoIterator for &'a HashMap { type Item = (&'a K, &'a V); type IntoIter = Iter<'a, K, V>; + /// Creates an iterator over the entries of a `HashMap` in arbitrary order. + /// The iterator element type is `(&'a K, &'a V)`. + /// + /// Return the same `Iter` struct as by the [`iter`] method on [`HashMap`]. + /// + /// [`iter`]: struct.HashMap.html#method.iter + /// [`HashMap`]: struct.HashMap.html + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashMap; + /// let map_one: HashMap<_, _> = [(1, "a"), (2, "b"), (3, "c")].into(); + /// let mut map_two = HashMap::new(); + /// + /// for (key, value) in &map_one { + /// println!("Key: {}, Value: {}", key, value); + /// map_two.insert_unique_unchecked(*key, *value); + /// } + /// + /// assert_eq!(map_one, map_two); + /// ``` #[cfg_attr(feature = "inline-more", inline)] fn into_iter(self) -> Iter<'a, K, V> { self.iter() } } -impl<'a, K, V, S, A: Allocator + Clone> IntoIterator for &'a mut HashMap { +impl<'a, K, V, S, A: Allocator> IntoIterator for &'a mut HashMap { type Item = (&'a K, &'a mut V); type IntoIter = IterMut<'a, K, V>; + /// Creates an iterator over the entries of a `HashMap` in arbitrary order + /// with mutable references to the values. The iterator element type is + /// `(&'a K, &'a mut V)`. + /// + /// Return the same `IterMut` struct as by the [`iter_mut`] method on + /// [`HashMap`]. + /// + /// [`iter_mut`]: struct.HashMap.html#method.iter_mut + /// [`HashMap`]: struct.HashMap.html + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashMap; + /// let mut map: HashMap<_, _> = [("a", 1), ("b", 2), ("c", 3)].into(); + /// + /// for (key, value) in &mut map { + /// println!("Key: {}, Value: {}", key, value); + /// *value *= 2; + /// } + /// + /// let mut vec = map.iter().collect::>(); + /// // The `Iter` iterator produces items in arbitrary order, so the + /// // items must be sorted to test them against a sorted array. + /// vec.sort_unstable(); + /// assert_eq!(vec, [(&"a", &2), (&"b", &4), (&"c", &6)]); + /// ``` #[cfg_attr(feature = "inline-more", inline)] fn into_iter(self) -> IterMut<'a, K, V> { self.iter_mut() } } -impl IntoIterator for HashMap { +impl IntoIterator for HashMap { type Item = (K, V); type IntoIter = IntoIter; @@ -2970,13 +4687,14 @@ impl IntoIterator for HashMap { /// ``` /// use hashbrown::HashMap; /// - /// let mut map = HashMap::new(); - /// map.insert("a", 1); - /// map.insert("b", 2); - /// map.insert("c", 3); + /// let map: HashMap<_, _> = [("a", 1), ("b", 2), ("c", 3)].into(); /// /// // Not possible with .iter() - /// let vec: Vec<(&str, i32)> = map.into_iter().collect(); + /// let mut vec: Vec<(&str, i32)> = map.into_iter().collect(); + /// // The `IntoIter` iterator produces items in arbitrary order, so + /// // the items must be sorted to test them against a sorted array. + /// vec.sort_unstable(); + /// assert_eq!(vec, [("a", 1), ("b", 2), ("c", 3)]); /// ``` #[cfg_attr(feature = "inline-more", inline)] fn into_iter(self) -> IntoIter { @@ -3051,7 +4769,7 @@ where } } -impl Iterator for IntoIter { +impl Iterator for IntoIter { type Item = (K, V); #[cfg_attr(feature = "inline-more", inline)] @@ -3063,15 +4781,15 @@ impl Iterator for IntoIter { self.inner.size_hint() } } -impl ExactSizeIterator for IntoIter { +impl ExactSizeIterator for IntoIter { #[cfg_attr(feature = "inline-more", inline)] fn len(&self) -> usize { self.inner.len() } } -impl FusedIterator for IntoIter {} +impl FusedIterator for IntoIter {} -impl fmt::Debug for IntoIter { +impl fmt::Debug for IntoIter { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.iter()).finish() } @@ -3149,17 +4867,15 @@ impl ExactSizeIterator for ValuesMut<'_, K, V> { } impl FusedIterator for ValuesMut<'_, K, V> {} -impl fmt::Debug for ValuesMut<'_, K, V> -where - K: fmt::Debug, - V: fmt::Debug, -{ +impl fmt::Debug for ValuesMut<'_, K, V> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_list().entries(self.inner.iter()).finish() + f.debug_list() + .entries(self.inner.iter().map(|(_, val)| val)) + .finish() } } -impl<'a, K, V, A: Allocator + Clone> Iterator for Drain<'a, K, V, A> { +impl<'a, K, V, A: Allocator> Iterator for Drain<'a, K, V, A> { type Item = (K, V); #[cfg_attr(feature = "inline-more", inline)] @@ -3171,26 +4887,26 @@ impl<'a, K, V, A: Allocator + Clone> Iterator for Drain<'a, K, V, A> { self.inner.size_hint() } } -impl ExactSizeIterator for Drain<'_, K, V, A> { +impl ExactSizeIterator for Drain<'_, K, V, A> { #[cfg_attr(feature = "inline-more", inline)] fn len(&self) -> usize { self.inner.len() } } -impl FusedIterator for Drain<'_, K, V, A> {} +impl FusedIterator for Drain<'_, K, V, A> {} impl fmt::Debug for Drain<'_, K, V, A> where K: fmt::Debug, V: fmt::Debug, - A: Allocator + Clone, + A: Allocator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.iter()).finish() } } -impl<'a, K, V, S, A: Allocator + Clone> Entry<'a, K, V, S, A> { +impl<'a, K, V, S, A: Allocator> Entry<'a, K, V, S, A> { /// Sets the value of the entry, and returns an OccupiedEntry. /// /// # Examples @@ -3228,9 +4944,11 @@ impl<'a, K, V, S, A: Allocator + Clone> Entry<'a, K, V, S, A> { /// /// let mut map: HashMap<&str, u32> = HashMap::new(); /// + /// // nonexistent key /// map.entry("poneyland").or_insert(3); /// assert_eq!(map["poneyland"], 3); /// + /// // existing key /// *map.entry("poneyland").or_insert(10) *= 2; /// assert_eq!(map["poneyland"], 6); /// ``` @@ -3254,12 +4972,15 @@ impl<'a, K, V, S, A: Allocator + Clone> Entry<'a, K, V, S, A> { /// ``` /// use hashbrown::HashMap; /// - /// let mut map: HashMap<&str, String> = HashMap::new(); - /// let s = "hoho".to_string(); + /// let mut map: HashMap<&str, u32> = HashMap::new(); /// - /// map.entry("poneyland").or_insert_with(|| s); + /// // nonexistent key + /// map.entry("poneyland").or_insert_with(|| 3); + /// assert_eq!(map["poneyland"], 3); /// - /// assert_eq!(map["poneyland"], "hoho".to_string()); + /// // existing key + /// *map.entry("poneyland").or_insert_with(|| 10) *= 2; + /// assert_eq!(map["poneyland"], 6); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn or_insert_with V>(self, default: F) -> &'a mut V @@ -3287,9 +5008,13 @@ impl<'a, K, V, S, A: Allocator + Clone> Entry<'a, K, V, S, A> { /// /// let mut map: HashMap<&str, usize> = HashMap::new(); /// + /// // nonexistent key /// map.entry("poneyland").or_insert_with_key(|key| key.chars().count()); - /// /// assert_eq!(map["poneyland"], 9); + /// + /// // existing key + /// *map.entry("poneyland").or_insert_with_key(|key| key.chars().count() * 10) *= 2; + /// assert_eq!(map["poneyland"], 18); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn or_insert_with_key V>(self, default: F) -> &'a mut V @@ -3314,7 +5039,11 @@ impl<'a, K, V, S, A: Allocator + Clone> Entry<'a, K, V, S, A> { /// use hashbrown::HashMap; /// /// let mut map: HashMap<&str, u32> = HashMap::new(); + /// map.entry("poneyland").or_insert(3); + /// // existing key /// assert_eq!(map.entry("poneyland").key(), &"poneyland"); + /// // nonexistent key + /// assert_eq!(map.entry("horseland").key(), &"horseland"); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn key(&self) -> &K { @@ -3424,7 +5153,7 @@ impl<'a, K, V, S, A: Allocator + Clone> Entry<'a, K, V, S, A> { } } -impl<'a, K, V: Default, S, A: Allocator + Clone> Entry<'a, K, V, S, A> { +impl<'a, K, V: Default, S, A: Allocator> Entry<'a, K, V, S, A> { /// Ensures a value is in the entry by inserting the default value if empty, /// and returns a mutable reference to the value in the entry. /// @@ -3434,9 +5163,15 @@ impl<'a, K, V: Default, S, A: Allocator + Clone> Entry<'a, K, V, S, A> { /// use hashbrown::HashMap; /// /// let mut map: HashMap<&str, Option> = HashMap::new(); - /// map.entry("poneyland").or_default(); /// + /// // nonexistent key + /// map.entry("poneyland").or_default(); /// assert_eq!(map["poneyland"], None); + /// + /// map.insert("horseland", Some(3)); + /// + /// // existing key + /// assert_eq!(map.entry("horseland").or_default(), &mut Some(3)); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn or_default(self) -> &'a mut V @@ -3451,17 +5186,21 @@ impl<'a, K, V: Default, S, A: Allocator + Clone> Entry<'a, K, V, S, A> { } } -impl<'a, K, V, S, A: Allocator + Clone> OccupiedEntry<'a, K, V, S, A> { +impl<'a, K, V, S, A: Allocator> OccupiedEntry<'a, K, V, S, A> { /// Gets a reference to the key in the entry. /// /// # Examples /// /// ``` - /// use hashbrown::HashMap; + /// use hashbrown::hash_map::{Entry, HashMap}; /// /// let mut map: HashMap<&str, u32> = HashMap::new(); /// map.entry("poneyland").or_insert(12); - /// assert_eq!(map.entry("poneyland").key(), &"poneyland"); + /// + /// match map.entry("poneyland") { + /// Entry::Vacant(_) => panic!(), + /// Entry::Occupied(entry) => assert_eq!(entry.key(), &"poneyland"), + /// } /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn key(&self) -> &K { @@ -3469,6 +5208,7 @@ impl<'a, K, V, S, A: Allocator + Clone> OccupiedEntry<'a, K, V, S, A> { } /// Take the ownership of the key and value from the map. + /// Keeps the allocated memory for reuse. /// /// # Examples /// @@ -3477,18 +5217,23 @@ impl<'a, K, V, S, A: Allocator + Clone> OccupiedEntry<'a, K, V, S, A> { /// use hashbrown::hash_map::Entry; /// /// let mut map: HashMap<&str, u32> = HashMap::new(); + /// // The map is empty + /// assert!(map.is_empty() && map.capacity() == 0); + /// /// map.entry("poneyland").or_insert(12); /// /// if let Entry::Occupied(o) = map.entry("poneyland") { /// // We delete the entry from the map. - /// o.remove_entry(); + /// assert_eq!(o.remove_entry(), ("poneyland", 12)); /// } /// /// assert_eq!(map.contains_key("poneyland"), false); + /// // Now map hold none elements + /// assert!(map.is_empty()); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn remove_entry(self) -> (K, V) { - unsafe { self.table.table.remove(self.elem) } + unsafe { self.table.table.remove(self.elem).0 } } /// Gets a reference to the value in the entry. @@ -3502,8 +5247,9 @@ impl<'a, K, V, S, A: Allocator + Clone> OccupiedEntry<'a, K, V, S, A> { /// let mut map: HashMap<&str, u32> = HashMap::new(); /// map.entry("poneyland").or_insert(12); /// - /// if let Entry::Occupied(o) = map.entry("poneyland") { - /// assert_eq!(o.get(), &12); + /// match map.entry("poneyland") { + /// Entry::Vacant(_) => panic!(), + /// Entry::Occupied(entry) => assert_eq!(entry.get(), &12), /// } /// ``` #[cfg_attr(feature = "inline-more", inline)] @@ -3553,16 +5299,19 @@ impl<'a, K, V, S, A: Allocator + Clone> OccupiedEntry<'a, K, V, S, A> { /// # Examples /// /// ``` - /// use hashbrown::HashMap; - /// use hashbrown::hash_map::Entry; + /// use hashbrown::hash_map::{Entry, HashMap}; /// /// let mut map: HashMap<&str, u32> = HashMap::new(); /// map.entry("poneyland").or_insert(12); /// /// assert_eq!(map["poneyland"], 12); - /// if let Entry::Occupied(o) = map.entry("poneyland") { - /// *o.into_mut() += 10; + /// + /// let value: &mut u32; + /// match map.entry("poneyland") { + /// Entry::Occupied(entry) => value = entry.into_mut(), + /// Entry::Vacant(_) => panic!(), /// } + /// *value += 10; /// /// assert_eq!(map["poneyland"], 22); /// ``` @@ -3589,13 +5338,12 @@ impl<'a, K, V, S, A: Allocator + Clone> OccupiedEntry<'a, K, V, S, A> { /// assert_eq!(map["poneyland"], 15); /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn insert(&mut self, mut value: V) -> V { - let old_value = self.get_mut(); - mem::swap(&mut value, old_value); - value + pub fn insert(&mut self, value: V) -> V { + mem::replace(self.get_mut(), value) } /// Takes the value out of the entry, and returns it. + /// Keeps the allocated memory for reuse. /// /// # Examples /// @@ -3604,6 +5352,9 @@ impl<'a, K, V, S, A: Allocator + Clone> OccupiedEntry<'a, K, V, S, A> { /// use hashbrown::hash_map::Entry; /// /// let mut map: HashMap<&str, u32> = HashMap::new(); + /// // The map is empty + /// assert!(map.is_empty() && map.capacity() == 0); + /// /// map.entry("poneyland").or_insert(12); /// /// if let Entry::Occupied(o) = map.entry("poneyland") { @@ -3611,6 +5362,8 @@ impl<'a, K, V, S, A: Allocator + Clone> OccupiedEntry<'a, K, V, S, A> { /// } /// /// assert_eq!(map.contains_key("poneyland"), false); + /// // Now map hold none elements + /// assert!(map.is_empty()); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn remove(self) -> V { @@ -3627,19 +5380,26 @@ impl<'a, K, V, S, A: Allocator + Clone> OccupiedEntry<'a, K, V, S, A> { /// # Examples /// /// ``` - /// use hashbrown::hash_map::{Entry, HashMap}; - /// use std::rc::Rc; + /// use hashbrown::hash_map::{Entry, HashMap}; + /// use std::rc::Rc; /// - /// let mut map: HashMap, u32> = HashMap::new(); - /// map.insert(Rc::new("Stringthing".to_string()), 15); + /// let mut map: HashMap, u32> = HashMap::new(); + /// let key_one = Rc::new("Stringthing".to_string()); + /// let key_two = Rc::new("Stringthing".to_string()); /// - /// let my_key = Rc::new("Stringthing".to_string()); + /// map.insert(key_one.clone(), 15); + /// assert!(Rc::strong_count(&key_one) == 2 && Rc::strong_count(&key_two) == 1); /// - /// if let Entry::Occupied(entry) = map.entry(my_key) { - /// // Also replace the key with a handle to our other key. - /// let (old_key, old_value): (Rc, u32) = entry.replace_entry(16); - /// } + /// match map.entry(key_two.clone()) { + /// Entry::Occupied(entry) => { + /// let (old_key, old_value): (Rc, u32) = entry.replace_entry(16); + /// assert!(Rc::ptr_eq(&key_one, &old_key) && old_value == 15); + /// } + /// Entry::Vacant(_) => panic!(), + /// } /// + /// assert!(Rc::strong_count(&key_one) == 1 && Rc::strong_count(&key_two) == 2); + /// assert_eq!(map[&"Stringthing".to_owned()], 16); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn replace_entry(self, value: V) -> (K, V) { @@ -3663,17 +5423,33 @@ impl<'a, K, V, S, A: Allocator + Clone> OccupiedEntry<'a, K, V, S, A> { /// use hashbrown::hash_map::{Entry, HashMap}; /// use std::rc::Rc; /// - /// let mut map: HashMap, u32> = HashMap::new(); - /// let mut known_strings: Vec> = Vec::new(); + /// let mut map: HashMap, usize> = HashMap::with_capacity(6); + /// let mut keys_one: Vec> = Vec::with_capacity(6); + /// let mut keys_two: Vec> = Vec::with_capacity(6); + /// + /// for (value, key) in ["a", "b", "c", "d", "e", "f"].into_iter().enumerate() { + /// let rc_key = Rc::new(key.to_owned()); + /// keys_one.push(rc_key.clone()); + /// map.insert(rc_key.clone(), value); + /// keys_two.push(Rc::new(key.to_owned())); + /// } + /// + /// assert!( + /// keys_one.iter().all(|key| Rc::strong_count(key) == 2) + /// && keys_two.iter().all(|key| Rc::strong_count(key) == 1) + /// ); /// - /// // Initialise known strings, run program, etc. + /// reclaim_memory(&mut map, &keys_two); /// - /// reclaim_memory(&mut map, &known_strings); + /// assert!( + /// keys_one.iter().all(|key| Rc::strong_count(key) == 1) + /// && keys_two.iter().all(|key| Rc::strong_count(key) == 2) + /// ); /// - /// fn reclaim_memory(map: &mut HashMap, u32>, known_strings: &[Rc] ) { - /// for s in known_strings { - /// if let Entry::Occupied(entry) = map.entry(s.clone()) { - /// // Replaces the entry's key with our version of it in `known_strings`. + /// fn reclaim_memory(map: &mut HashMap, usize>, keys: &[Rc]) { + /// for key in keys { + /// if let Entry::Occupied(entry) = map.entry(key.clone()) { + /// // Replaces the entry's key with our version of it in `keys`. /// entry.replace_key(); /// } /// } @@ -3765,7 +5541,7 @@ impl<'a, K, V, S, A: Allocator + Clone> OccupiedEntry<'a, K, V, S, A> { } } -impl<'a, K, V, S, A: Allocator + Clone> VacantEntry<'a, K, V, S, A> { +impl<'a, K, V, S, A: Allocator> VacantEntry<'a, K, V, S, A> { /// Gets a reference to the key that would be used when inserting a value /// through the `VacantEntry`. /// @@ -3787,13 +5563,13 @@ impl<'a, K, V, S, A: Allocator + Clone> VacantEntry<'a, K, V, S, A> { /// # Examples /// /// ``` - /// use hashbrown::HashMap; - /// use hashbrown::hash_map::Entry; + /// use hashbrown::hash_map::{Entry, HashMap}; /// /// let mut map: HashMap<&str, u32> = HashMap::new(); /// - /// if let Entry::Vacant(v) = map.entry("poneyland") { - /// v.into_key(); + /// match map.entry("poneyland") { + /// Entry::Occupied(_) => panic!(), + /// Entry::Vacant(v) => assert_eq!(v.into_key(), "poneyland"), /// } /// ``` #[cfg_attr(feature = "inline-more", inline)] @@ -3827,13 +5603,13 @@ impl<'a, K, V, S, A: Allocator + Clone> VacantEntry<'a, K, V, S, A> { let entry = table.insert_entry( self.hash, (self.key, value), - make_hasher::(&self.table.hash_builder), + make_hasher::<_, V, S>(&self.table.hash_builder), ); &mut entry.1 } #[cfg_attr(feature = "inline-more", inline)] - fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V, S, A> + pub(crate) fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V, S, A> where K: Hash, S: BuildHasher, @@ -3841,7 +5617,7 @@ impl<'a, K, V, S, A: Allocator + Clone> VacantEntry<'a, K, V, S, A> { let elem = self.table.table.insert( self.hash, (self.key, value), - make_hasher::(&self.table.hash_builder), + make_hasher::<_, V, S>(&self.table.hash_builder), ); OccupiedEntry { hash: self.hash, @@ -3852,7 +5628,7 @@ impl<'a, K, V, S, A: Allocator + Clone> VacantEntry<'a, K, V, S, A> { } } -impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> EntryRef<'a, 'b, K, Q, V, S, A> { +impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator> EntryRef<'a, 'b, K, Q, V, S, A> { /// Sets the value of the entry, and returns an OccupiedEntryRef. /// /// # Examples @@ -3890,9 +5666,11 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> EntryRef<'a, 'b, K, Q, V, /// /// let mut map: HashMap = HashMap::new(); /// + /// // nonexistent key /// map.entry_ref("poneyland").or_insert(3); /// assert_eq!(map["poneyland"], 3); /// + /// // existing key /// *map.entry_ref("poneyland").or_insert(10) *= 2; /// assert_eq!(map["poneyland"], 6); /// ``` @@ -3916,12 +5694,15 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> EntryRef<'a, 'b, K, Q, V, /// ``` /// use hashbrown::HashMap; /// - /// let mut map: HashMap = HashMap::new(); - /// let s = "hoho".to_string(); + /// let mut map: HashMap = HashMap::new(); /// - /// map.entry_ref("poneyland").or_insert_with(|| s); + /// // nonexistent key + /// map.entry_ref("poneyland").or_insert_with(|| 3); + /// assert_eq!(map["poneyland"], 3); /// - /// assert_eq!(map["poneyland"], "hoho".to_string()); + /// // existing key + /// *map.entry_ref("poneyland").or_insert_with(|| 10) *= 2; + /// assert_eq!(map["poneyland"], 6); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn or_insert_with V>(self, default: F) -> &'a mut V @@ -3937,10 +5718,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> EntryRef<'a, 'b, K, Q, V, /// Ensures a value is in the entry by inserting, if empty, the result of the default function. /// This method allows for generating key-derived values for insertion by providing the default - /// function a reference to the key that was moved during the `.entry_ref(key)` method call. - /// - /// The reference to the moved key is provided so that cloning or copying the key is - /// unnecessary, unlike with `.or_insert_with(|| ... )`. + /// function an access to the borrower form of the key. /// /// # Examples /// @@ -3949,9 +5727,13 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> EntryRef<'a, 'b, K, Q, V, /// /// let mut map: HashMap = HashMap::new(); /// + /// // nonexistent key /// map.entry_ref("poneyland").or_insert_with_key(|key| key.chars().count()); - /// /// assert_eq!(map["poneyland"], 9); + /// + /// // existing key + /// *map.entry_ref("poneyland").or_insert_with_key(|key| key.chars().count() * 10) *= 2; + /// assert_eq!(map["poneyland"], 18); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn or_insert_with_key V>(self, default: F) -> &'a mut V @@ -3976,7 +5758,11 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> EntryRef<'a, 'b, K, Q, V, /// use hashbrown::HashMap; /// /// let mut map: HashMap = HashMap::new(); + /// map.entry_ref("poneyland").or_insert(3); + /// // existing key /// assert_eq!(map.entry_ref("poneyland").key(), "poneyland"); + /// // nonexistent key + /// assert_eq!(map.entry_ref("horseland").key(), "horseland"); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn key(&self) -> &Q @@ -3984,7 +5770,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> EntryRef<'a, 'b, K, Q, V, K: Borrow, { match *self { - EntryRef::Occupied(ref entry) => entry.key(), + EntryRef::Occupied(ref entry) => entry.key().borrow(), EntryRef::Vacant(ref entry) => entry.key(), } } @@ -4080,8 +5866,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> EntryRef<'a, 'b, K, Q, V, #[cfg_attr(feature = "inline-more", inline)] pub fn and_replace_entry_with(self, f: F) -> Self where - F: FnOnce(&Q, V) -> Option, - K: Borrow, + F: FnOnce(&K, V) -> Option, { match self { EntryRef::Occupied(entry) => entry.replace_entry_with(f), @@ -4090,7 +5875,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> EntryRef<'a, 'b, K, Q, V, } } -impl<'a, 'b, K, Q: ?Sized, V: Default, S, A: Allocator + Clone> EntryRef<'a, 'b, K, Q, V, S, A> { +impl<'a, 'b, K, Q: ?Sized, V: Default, S, A: Allocator> EntryRef<'a, 'b, K, Q, V, S, A> { /// Ensures a value is in the entry by inserting the default value if empty, /// and returns a mutable reference to the value in the entry. /// @@ -4099,10 +5884,16 @@ impl<'a, 'b, K, Q: ?Sized, V: Default, S, A: Allocator + Clone> EntryRef<'a, 'b, /// ``` /// use hashbrown::HashMap; /// - /// let mut map: HashMap<&str, Option> = HashMap::new(); - /// map.entry("poneyland").or_default(); + /// let mut map: HashMap> = HashMap::new(); /// + /// // nonexistent key + /// map.entry_ref("poneyland").or_default(); /// assert_eq!(map["poneyland"], None); + /// + /// map.insert("horseland".to_string(), Some(3)); + /// + /// // existing key + /// assert_eq!(map.entry_ref("horseland").or_default(), &mut Some(3)); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn or_default(self) -> &'a mut V @@ -4117,27 +5908,29 @@ impl<'a, 'b, K, Q: ?Sized, V: Default, S, A: Allocator + Clone> EntryRef<'a, 'b, } } -impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, K, Q, V, S, A> { +impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator> OccupiedEntryRef<'a, 'b, K, Q, V, S, A> { /// Gets a reference to the key in the entry. /// /// # Examples /// /// ``` - /// use hashbrown::HashMap; + /// use hashbrown::hash_map::{EntryRef, HashMap}; /// /// let mut map: HashMap = HashMap::new(); /// map.entry_ref("poneyland").or_insert(12); - /// assert_eq!(map.entry_ref("poneyland").key(), "poneyland"); + /// + /// match map.entry_ref("poneyland") { + /// EntryRef::Vacant(_) => panic!(), + /// EntryRef::Occupied(entry) => assert_eq!(entry.key(), "poneyland"), + /// } /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn key(&self) -> &Q - where - K: Borrow, - { - unsafe { &self.elem.as_ref().0 }.borrow() + pub fn key(&self) -> &K { + unsafe { &self.elem.as_ref().0 } } /// Take the ownership of the key and value from the map. + /// Keeps the allocated memory for reuse. /// /// # Examples /// @@ -4146,18 +5939,23 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, /// use hashbrown::hash_map::EntryRef; /// /// let mut map: HashMap = HashMap::new(); + /// // The map is empty + /// assert!(map.is_empty() && map.capacity() == 0); + /// /// map.entry_ref("poneyland").or_insert(12); /// /// if let EntryRef::Occupied(o) = map.entry_ref("poneyland") { /// // We delete the entry from the map. - /// o.remove_entry(); + /// assert_eq!(o.remove_entry(), ("poneyland".to_owned(), 12)); /// } /// /// assert_eq!(map.contains_key("poneyland"), false); + /// // Now map hold none elements but capacity is equal to the old one + /// assert!(map.is_empty()); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn remove_entry(self) -> (K, V) { - unsafe { self.table.table.remove(self.elem) } + unsafe { self.table.table.remove(self.elem).0 } } /// Gets a reference to the value in the entry. @@ -4171,8 +5969,9 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, /// let mut map: HashMap = HashMap::new(); /// map.entry_ref("poneyland").or_insert(12); /// - /// if let EntryRef::Occupied(o) = map.entry_ref("poneyland") { - /// assert_eq!(o.get(), &12); + /// match map.entry_ref("poneyland") { + /// EntryRef::Vacant(_) => panic!(), + /// EntryRef::Occupied(entry) => assert_eq!(entry.get(), &12), /// } /// ``` #[cfg_attr(feature = "inline-more", inline)] @@ -4222,16 +6021,17 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, /// # Examples /// /// ``` - /// use hashbrown::HashMap; - /// use hashbrown::hash_map::EntryRef; + /// use hashbrown::hash_map::{EntryRef, HashMap}; /// /// let mut map: HashMap = HashMap::new(); /// map.entry_ref("poneyland").or_insert(12); /// - /// assert_eq!(map["poneyland"], 12); - /// if let EntryRef::Occupied(o) = map.entry_ref("poneyland") { - /// *o.into_mut() += 10; + /// let value: &mut u32; + /// match map.entry_ref("poneyland") { + /// EntryRef::Occupied(entry) => value = entry.into_mut(), + /// EntryRef::Vacant(_) => panic!(), /// } + /// *value += 10; /// /// assert_eq!(map["poneyland"], 22); /// ``` @@ -4258,13 +6058,12 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, /// assert_eq!(map["poneyland"], 15); /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn insert(&mut self, mut value: V) -> V { - let old_value = self.get_mut(); - mem::swap(&mut value, old_value); - value + pub fn insert(&mut self, value: V) -> V { + mem::replace(self.get_mut(), value) } /// Takes the value out of the entry, and returns it. + /// Keeps the allocated memory for reuse. /// /// # Examples /// @@ -4273,6 +6072,9 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, /// use hashbrown::hash_map::EntryRef; /// /// let mut map: HashMap = HashMap::new(); + /// // The map is empty + /// assert!(map.is_empty() && map.capacity() == 0); + /// /// map.entry_ref("poneyland").or_insert(12); /// /// if let EntryRef::Occupied(o) = map.entry_ref("poneyland") { @@ -4280,6 +6082,8 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, /// } /// /// assert_eq!(map.contains_key("poneyland"), false); + /// // Now map hold none elements but capacity is equal to the old one + /// assert!(map.is_empty()); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn remove(self) -> V { @@ -4291,7 +6095,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, /// /// # Panics /// - /// Will panic if this OccupiedEntry was created through [`EntryRef::insert`]. + /// Will panic if this OccupiedEntryRef was created through [`EntryRef::insert`]. /// /// # Examples /// @@ -4300,13 +6104,21 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, /// use std::rc::Rc; /// /// let mut map: HashMap, u32> = HashMap::new(); - /// map.insert(Rc::from("Stringthing"), 15); + /// let key: Rc = Rc::from("Stringthing"); + /// + /// map.insert(key.clone(), 15); + /// assert_eq!(Rc::strong_count(&key), 2); /// - /// if let EntryRef::Occupied(entry) = map.entry_ref("Stringthing") { - /// // Also replace the key with a handle to our other key. - /// let (old_key, old_value): (Rc, u32) = entry.replace_entry(16); + /// match map.entry_ref("Stringthing") { + /// EntryRef::Occupied(entry) => { + /// let (old_key, old_value): (Rc, u32) = entry.replace_entry(16); + /// assert!(Rc::ptr_eq(&key, &old_key) && old_value == 15); + /// } + /// EntryRef::Vacant(_) => panic!(), /// } /// + /// assert_eq!(Rc::strong_count(&key), 1); + /// assert_eq!(map["Stringthing"], 16); /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn replace_entry(self, value: V) -> (K, V) @@ -4325,7 +6137,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, /// /// # Panics /// - /// Will panic if this OccupiedEntry was created through [`Entry::insert`]. + /// Will panic if this OccupiedEntryRef was created through [`EntryRef::insert`]. /// /// # Examples /// @@ -4333,17 +6145,27 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, /// use hashbrown::hash_map::{EntryRef, HashMap}; /// use std::rc::Rc; /// - /// let mut map: HashMap, u32> = HashMap::new(); - /// let mut known_strings: Vec> = Vec::new(); + /// let mut map: HashMap, usize> = HashMap::with_capacity(6); + /// let mut keys: Vec> = Vec::with_capacity(6); + /// + /// for (value, key) in ["a", "b", "c", "d", "e", "f"].into_iter().enumerate() { + /// let rc_key: Rc = Rc::from(key); + /// keys.push(rc_key.clone()); + /// map.insert(rc_key.clone(), value); + /// } /// - /// // Initialise known strings, run program, etc. + /// assert!(keys.iter().all(|key| Rc::strong_count(key) == 2)); /// - /// reclaim_memory(&mut map, &known_strings); + /// // It doesn't matter that we kind of use a vector with the same keys, + /// // because all keys will be newly created from the references + /// reclaim_memory(&mut map, &keys); /// - /// fn reclaim_memory(map: &mut HashMap, u32>, known_strings: &[Rc] ) { - /// for s in known_strings { - /// if let EntryRef::Occupied(entry) = map.entry_ref(s.as_ref()) { - /// // Replaces the entry's key with our version of it in `known_strings`. + /// assert!(keys.iter().all(|key| Rc::strong_count(key) == 1)); + /// + /// fn reclaim_memory(map: &mut HashMap, usize>, keys: &[Rc]) { + /// for key in keys { + /// if let EntryRef::Occupied(entry) = map.entry_ref(key.as_ref()) { + /// // Replaces the entry's key with our version of it in `keys`. /// entry.replace_key(); /// } /// } @@ -4409,8 +6231,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, #[cfg_attr(feature = "inline-more", inline)] pub fn replace_entry_with(self, f: F) -> EntryRef<'a, 'b, K, Q, V, S, A> where - F: FnOnce(&Q, V) -> Option, - K: Borrow, + F: FnOnce(&K, V) -> Option, { unsafe { let mut spare_key = None; @@ -4418,7 +6239,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, self.table .table .replace_bucket_with(self.elem.clone(), |(key, value)| { - if let Some(new_value) = f(key.borrow(), value) { + if let Some(new_value) = f(&key, value) { Some((key, new_value)) } else { spare_key = Some(KeyOrRef::Owned(key)); @@ -4439,7 +6260,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b, } } -impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> VacantEntryRef<'a, 'b, K, Q, V, S, A> { +impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator> VacantEntryRef<'a, 'b, K, Q, V, S, A> { /// Gets a reference to the key that would be used when inserting a value /// through the `VacantEntryRef`. /// @@ -4465,14 +6286,14 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> VacantEntryRef<'a, 'b, K, /// # Examples /// /// ``` - /// use hashbrown::HashMap; - /// use hashbrown::hash_map::EntryRef; + /// use hashbrown::hash_map::{EntryRef, HashMap}; /// /// let mut map: HashMap = HashMap::new(); /// let key: &str = "poneyland"; /// - /// if let EntryRef::Vacant(v) = map.entry_ref(key) { - /// v.into_key(); + /// match map.entry_ref(key) { + /// EntryRef::Occupied(_) => panic!(), + /// EntryRef::Vacant(v) => assert_eq!(v.into_key(), "poneyland".to_owned()), /// } /// ``` #[cfg_attr(feature = "inline-more", inline)] @@ -4510,7 +6331,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> VacantEntryRef<'a, 'b, K, let entry = table.insert_entry( self.hash, (self.key.into_owned(), value), - make_hasher::(&self.table.hash_builder), + make_hasher::<_, V, S>(&self.table.hash_builder), ); &mut entry.1 } @@ -4524,7 +6345,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> VacantEntryRef<'a, 'b, K, let elem = self.table.table.insert( self.hash, (self.key.into_owned(), value), - make_hasher::(&self.table.hash_builder), + make_hasher::<_, V, S>(&self.table.hash_builder), ); OccupiedEntryRef { hash: self.hash, @@ -4539,7 +6360,7 @@ impl FromIterator<(K, V)> for HashMap where K: Eq + Hash, S: BuildHasher + Default, - A: Default + Allocator + Clone, + A: Default + Allocator, { #[cfg_attr(feature = "inline-more", inline)] fn from_iter>(iter: T) -> Self { @@ -4559,8 +6380,43 @@ impl Extend<(K, V)> for HashMap where K: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { + /// Inserts all new key-values from the iterator to existing `HashMap`. + /// Replace values with existing keys with new values returned from the iterator. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::HashMap; + /// + /// let mut map = HashMap::new(); + /// map.insert(1, 100); + /// + /// let some_iter = [(1, 1), (2, 2)].into_iter(); + /// map.extend(some_iter); + /// // Replace values with existing keys with new values returned from the iterator. + /// // So that the map.get(&1) doesn't return Some(&100). + /// assert_eq!(map.get(&1), Some(&1)); + /// + /// let some_vec: Vec<_> = vec![(3, 3), (4, 4)]; + /// map.extend(some_vec); + /// + /// let some_arr = [(5, 5), (6, 6)]; + /// map.extend(some_arr); + /// let old_map_len = map.len(); + /// + /// // You can also extend from another HashMap + /// let mut new_map = HashMap::new(); + /// new_map.extend(map); + /// assert_eq!(new_map.len(), old_map_len); + /// + /// let mut vec: Vec<_> = new_map.into_iter().collect(); + /// // The `IntoIter` iterator produces items in arbitrary order, so the + /// // items must be sorted to test them against a sorted array. + /// vec.sort_unstable(); + /// assert_eq!(vec, [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]); + /// ``` #[cfg_attr(feature = "inline-more", inline)] fn extend>(&mut self, iter: T) { // Keys may be already present or show multiple times in the iterator. @@ -4601,13 +6457,53 @@ where } } +/// Inserts all new key-values from the iterator and replaces values with existing +/// keys with new values returned from the iterator. impl<'a, K, V, S, A> Extend<(&'a K, &'a V)> for HashMap where K: Eq + Hash + Copy, V: Copy, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { + /// Inserts all new key-values from the iterator to existing `HashMap`. + /// Replace values with existing keys with new values returned from the iterator. + /// The keys and values must implement [`Copy`] trait. + /// + /// [`Copy`]: https://doc.rust-lang.org/core/marker/trait.Copy.html + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::HashMap; + /// + /// let mut map = HashMap::new(); + /// map.insert(1, 100); + /// + /// let arr = [(1, 1), (2, 2)]; + /// let some_iter = arr.iter().map(|(k, v)| (k, v)); + /// map.extend(some_iter); + /// // Replace values with existing keys with new values returned from the iterator. + /// // So that the map.get(&1) doesn't return Some(&100). + /// assert_eq!(map.get(&1), Some(&1)); + /// + /// let some_vec: Vec<_> = vec![(3, 3), (4, 4)]; + /// map.extend(some_vec.iter().map(|(k, v)| (k, v))); + /// + /// let some_arr = [(5, 5), (6, 6)]; + /// map.extend(some_arr.iter().map(|(k, v)| (k, v))); + /// + /// // You can also extend from another HashMap + /// let mut new_map = HashMap::new(); + /// new_map.extend(&map); + /// assert_eq!(new_map, map); + /// + /// let mut vec: Vec<_> = new_map.into_iter().collect(); + /// // The `IntoIter` iterator produces items in arbitrary order, so the + /// // items must be sorted to test them against a sorted array. + /// vec.sort_unstable(); + /// assert_eq!(vec, [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]); + /// ``` #[cfg_attr(feature = "inline-more", inline)] fn extend>(&mut self, iter: T) { self.extend(iter.into_iter().map(|(&key, &value)| (key, value))); @@ -4626,6 +6522,66 @@ where } } +/// Inserts all new key-values from the iterator and replaces values with existing +/// keys with new values returned from the iterator. +impl<'a, K, V, S, A> Extend<&'a (K, V)> for HashMap +where + K: Eq + Hash + Copy, + V: Copy, + S: BuildHasher, + A: Allocator, +{ + /// Inserts all new key-values from the iterator to existing `HashMap`. + /// Replace values with existing keys with new values returned from the iterator. + /// The keys and values must implement [`Copy`] trait. + /// + /// [`Copy`]: https://doc.rust-lang.org/core/marker/trait.Copy.html + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_map::HashMap; + /// + /// let mut map = HashMap::new(); + /// map.insert(1, 100); + /// + /// let arr = [(1, 1), (2, 2)]; + /// let some_iter = arr.iter(); + /// map.extend(some_iter); + /// // Replace values with existing keys with new values returned from the iterator. + /// // So that the map.get(&1) doesn't return Some(&100). + /// assert_eq!(map.get(&1), Some(&1)); + /// + /// let some_vec: Vec<_> = vec![(3, 3), (4, 4)]; + /// map.extend(&some_vec); + /// + /// let some_arr = [(5, 5), (6, 6)]; + /// map.extend(&some_arr); + /// + /// let mut vec: Vec<_> = map.into_iter().collect(); + /// // The `IntoIter` iterator produces items in arbitrary order, so the + /// // items must be sorted to test them against a sorted array. + /// vec.sort_unstable(); + /// assert_eq!(vec, [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]); + /// ``` + #[cfg_attr(feature = "inline-more", inline)] + fn extend>(&mut self, iter: T) { + self.extend(iter.into_iter().map(|&(key, value)| (key, value))); + } + + #[inline] + #[cfg(feature = "nightly")] + fn extend_one(&mut self, &(k, v): &'a (K, V)) { + self.insert(k, v); + } + + #[inline] + #[cfg(feature = "nightly")] + fn extend_reserve(&mut self, additional: usize) { + Extend::<(K, V)>::extend_reserve(self, additional); + } +} + #[allow(dead_code)] fn assert_covariance() { fn map_key<'new>(v: HashMap<&'static str, u8>) -> HashMap<&'new str, u8> { @@ -4640,12 +6596,12 @@ fn assert_covariance() { fn iter_val<'a, 'new>(v: Iter<'a, u8, &'static str>) -> Iter<'a, u8, &'new str> { v } - fn into_iter_key<'new, A: Allocator + Clone>( + fn into_iter_key<'new, A: Allocator>( v: IntoIter<&'static str, u8, A>, ) -> IntoIter<&'new str, u8, A> { v } - fn into_iter_val<'new, A: Allocator + Clone>( + fn into_iter_val<'new, A: Allocator>( v: IntoIter, ) -> IntoIter { v @@ -4675,6 +6631,12 @@ mod test_map { use super::Entry::{Occupied, Vacant}; use super::EntryRef; use super::{HashMap, RawEntryMut}; + use alloc::string::{String, ToString}; + use alloc::sync::Arc; + use allocator_api2::alloc::{AllocError, Allocator, Global}; + use core::alloc::Layout; + use core::ptr::NonNull; + use core::sync::atomic::{AtomicI8, Ordering}; use rand::{rngs::SmallRng, Rng, SeedableRng}; use std::borrow::ToOwned; use std::cell::RefCell; @@ -4897,7 +6859,6 @@ mod test_map { } }); - #[allow(clippy::let_underscore_drop)] // kind-of a false positive for _ in half.by_ref() {} DROP_VECTOR.with(|v| { @@ -5042,7 +7003,7 @@ mod test_map { let mut m = HashMap::new(); assert!(m.insert(1, 2).is_none()); assert_eq!(*m.get(&1).unwrap(), 2); - assert!(!m.insert(1, 3).is_none()); + assert!(m.insert(1, 3).is_some()); assert_eq!(*m.get(&1).unwrap(), 3); } @@ -5225,10 +7186,10 @@ mod test_map { map.insert(1, 2); map.insert(3, 4); - let map_str = format!("{:?}", map); + let map_str = format!("{map:?}"); assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}"); - assert_eq!(format!("{:?}", empty), "{}"); + assert_eq!(format!("{empty:?}"), "{}"); } #[test] @@ -5544,7 +7505,7 @@ mod test_map { // Test for #19292 fn check(m: &HashMap) { for k in m.keys() { - assert!(m.contains_key(k), "{} is in keys() but not in the map?", k); + assert!(m.contains_key(k), "{k} is in keys() but not in the map?"); } } @@ -5580,7 +7541,7 @@ mod test_map { // Test for #19292 fn check(m: &HashMap) { for k in m.keys() { - assert!(m.contains_key(k), "{} is in keys() but not in the map?", k); + assert!(m.contains_key(k), "{k} is in keys() but not in the map?"); } } @@ -5613,7 +7574,7 @@ mod test_map { } #[test] - fn test_extend_ref() { + fn test_extend_ref_k_ref_v() { let mut a = HashMap::new(); a.insert(1, "one"); let mut b = HashMap::new(); @@ -5628,6 +7589,38 @@ mod test_map { assert_eq!(a[&3], "three"); } + #[test] + #[allow(clippy::needless_borrow)] + fn test_extend_ref_kv_tuple() { + use std::ops::AddAssign; + let mut a = HashMap::new(); + a.insert(0, 0); + + fn create_arr + Copy, const N: usize>(start: T, step: T) -> [(T, T); N] { + let mut outs: [(T, T); N] = [(start, start); N]; + let mut element = step; + outs.iter_mut().skip(1).for_each(|(k, v)| { + *k += element; + *v += element; + element += step; + }); + outs + } + + let for_iter: Vec<_> = (0..100).map(|i| (i, i)).collect(); + let iter = for_iter.iter(); + let vec: Vec<_> = (100..200).map(|i| (i, i)).collect(); + a.extend(iter); + a.extend(&vec); + a.extend(create_arr::(200, 1)); + + assert_eq!(a.len(), 300); + + for item in 0..300 { + assert_eq!(a[&item], item); + } + } + #[test] fn test_capacity_not_less_than_len() { let mut a = HashMap::new(); @@ -6020,7 +8013,7 @@ mod test_map { // Test for #19292 fn check(m: &HashMap) { for k in m.keys() { - assert!(m.contains_key(k), "{} is in keys() but not in the map?", k); + assert!(m.contains_key(k), "{k} is in keys() but not in the map?"); } } @@ -6050,7 +8043,7 @@ mod test_map { // Test for #19292 fn check(m: &HashMap) { for k in m.keys() { - assert!(m.contains_key(k), "{} is in keys() but not in the map?", k); + assert!(m.contains_key(k), "{k} is in keys() but not in the map?"); } } @@ -6088,10 +8081,10 @@ mod test_map { } #[test] - fn test_drain_filter() { + fn test_extract_if() { { let mut map: HashMap = (0..8).map(|x| (x, x * 10)).collect(); - let drained = map.drain_filter(|&k, _| k % 2 == 0); + let drained = map.extract_if(|&k, _| k % 2 == 0); let mut out = drained.collect::>(); out.sort_unstable(); assert_eq!(vec![(0, 0), (2, 20), (4, 40), (6, 60)], out); @@ -6099,7 +8092,7 @@ mod test_map { } { let mut map: HashMap = (0..8).map(|x| (x, x * 10)).collect(); - drop(map.drain_filter(|&k, _| k % 2 == 0)); + map.extract_if(|&k, _| k % 2 == 0).for_each(drop); assert_eq!(map.len(), 4); } } @@ -6109,27 +8102,32 @@ mod test_map { fn test_try_reserve() { use crate::TryReserveError::{AllocError, CapacityOverflow}; - const MAX_USIZE: usize = usize::MAX; + const MAX_ISIZE: usize = isize::MAX as usize; let mut empty_bytes: HashMap = HashMap::new(); - if let Err(CapacityOverflow) = empty_bytes.try_reserve(MAX_USIZE) { + if let Err(CapacityOverflow) = empty_bytes.try_reserve(usize::MAX) { } else { panic!("usize::MAX should trigger an overflow!"); } - if let Err(AllocError { .. }) = empty_bytes.try_reserve(MAX_USIZE / 16) { + if let Err(CapacityOverflow) = empty_bytes.try_reserve(MAX_ISIZE) { + } else { + panic!("isize::MAX should trigger an overflow!"); + } + + if let Err(AllocError { .. }) = empty_bytes.try_reserve(MAX_ISIZE / 5) { } else { // This may succeed if there is enough free memory. Attempt to // allocate a few more hashmaps to ensure the allocation will fail. let mut empty_bytes2: HashMap = HashMap::new(); - let _ = empty_bytes2.try_reserve(MAX_USIZE / 16); + let _ = empty_bytes2.try_reserve(MAX_ISIZE / 5); let mut empty_bytes3: HashMap = HashMap::new(); - let _ = empty_bytes3.try_reserve(MAX_USIZE / 16); + let _ = empty_bytes3.try_reserve(MAX_ISIZE / 5); let mut empty_bytes4: HashMap = HashMap::new(); - if let Err(AllocError { .. }) = empty_bytes4.try_reserve(MAX_USIZE / 16) { + if let Err(AllocError { .. }) = empty_bytes4.try_reserve(MAX_ISIZE / 5) { } else { - panic!("usize::MAX / 8 should trigger an OOM!"); + panic!("isize::MAX / 5 should trigger an OOM!"); } } } @@ -6143,7 +8141,7 @@ mod test_map { let mut map: HashMap<_, _> = xs.iter().copied().collect(); let compute_hash = |map: &HashMap, k: i32| -> u64 { - super::make_insert_hash::(map.hasher(), &k) + super::make_hash::(map.hasher(), &k) }; // Existing key (insert) @@ -6221,15 +8219,15 @@ mod test_map { assert_eq!(map.raw_entry().from_key_hashed_nocheck(hash, &k), kv); match map.raw_entry_mut().from_key(&k) { - Occupied(mut o) => assert_eq!(Some(o.get_key_value()), kv), + Occupied(o) => assert_eq!(Some(o.get_key_value()), kv), Vacant(_) => assert_eq!(v, None), } match map.raw_entry_mut().from_key_hashed_nocheck(hash, &k) { - Occupied(mut o) => assert_eq!(Some(o.get_key_value()), kv), + Occupied(o) => assert_eq!(Some(o.get_key_value()), kv), Vacant(_) => assert_eq!(v, None), } match map.raw_entry_mut().from_hash(hash, |q| *q == k) { - Occupied(mut o) => assert_eq!(Some(o.get_key_value()), kv), + Occupied(o) => assert_eq!(Some(o.get_key_value()), kv), Vacant(_) => assert_eq!(v, None), } } @@ -6305,21 +8303,21 @@ mod test_map { loop { // occasionally remove some elements if i < n && rng.gen_bool(0.1) { - let hash_value = super::make_insert_hash(&hash_builder, &i); + let hash_value = super::make_hash(&hash_builder, &i); unsafe { let e = map.table.find(hash_value, |q| q.0.eq(&i)); if let Some(e) = e { it.reflect_remove(&e); - let t = map.table.remove(e); + let t = map.table.remove(e).0; removed.push(t); left -= 1; } else { - assert!(removed.contains(&(i, 2 * i)), "{} not in {:?}", i, removed); + assert!(removed.contains(&(i, 2 * i)), "{i} not in {removed:?}"); let e = map.table.insert( hash_value, (i, 2 * i), - super::make_hasher::(&hash_builder), + super::make_hasher::<_, usize, _>(&hash_builder), ); it.reflect_insert(&e); if let Some(p) = removed.iter().position(|e| e == &(i, 2 * i)) { @@ -6400,4 +8398,485 @@ mod test_map { let ys = map.get_many_key_value_mut(["baz", "baz"]); assert_eq!(ys, None); } + + #[test] + #[should_panic = "panic in drop"] + fn test_clone_from_double_drop() { + #[derive(Clone)] + struct CheckedDrop { + panic_in_drop: bool, + dropped: bool, + } + impl Drop for CheckedDrop { + fn drop(&mut self) { + if self.panic_in_drop { + self.dropped = true; + panic!("panic in drop"); + } + if self.dropped { + panic!("double drop"); + } + self.dropped = true; + } + } + const DISARMED: CheckedDrop = CheckedDrop { + panic_in_drop: false, + dropped: false, + }; + const ARMED: CheckedDrop = CheckedDrop { + panic_in_drop: true, + dropped: false, + }; + + let mut map1 = HashMap::new(); + map1.insert(1, DISARMED); + map1.insert(2, DISARMED); + map1.insert(3, DISARMED); + map1.insert(4, DISARMED); + + let mut map2 = HashMap::new(); + map2.insert(1, DISARMED); + map2.insert(2, ARMED); + map2.insert(3, DISARMED); + map2.insert(4, DISARMED); + + map2.clone_from(&map1); + } + + #[test] + #[should_panic = "panic in clone"] + fn test_clone_from_memory_leaks() { + use ::alloc::vec::Vec; + + struct CheckedClone { + panic_in_clone: bool, + need_drop: Vec, + } + impl Clone for CheckedClone { + fn clone(&self) -> Self { + if self.panic_in_clone { + panic!("panic in clone") + } + Self { + panic_in_clone: self.panic_in_clone, + need_drop: self.need_drop.clone(), + } + } + } + let mut map1 = HashMap::new(); + map1.insert( + 1, + CheckedClone { + panic_in_clone: false, + need_drop: vec![0, 1, 2], + }, + ); + map1.insert( + 2, + CheckedClone { + panic_in_clone: false, + need_drop: vec![3, 4, 5], + }, + ); + map1.insert( + 3, + CheckedClone { + panic_in_clone: true, + need_drop: vec![6, 7, 8], + }, + ); + let _map2 = map1.clone(); + } + + struct MyAllocInner { + drop_count: Arc, + } + + #[derive(Clone)] + struct MyAlloc { + _inner: Arc, + } + + impl MyAlloc { + fn new(drop_count: Arc) -> Self { + MyAlloc { + _inner: Arc::new(MyAllocInner { drop_count }), + } + } + } + + impl Drop for MyAllocInner { + fn drop(&mut self) { + println!("MyAlloc freed."); + self.drop_count.fetch_sub(1, Ordering::SeqCst); + } + } + + unsafe impl Allocator for MyAlloc { + fn allocate(&self, layout: Layout) -> std::result::Result, AllocError> { + let g = Global; + g.allocate(layout) + } + + unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) { + let g = Global; + g.deallocate(ptr, layout) + } + } + + #[test] + fn test_hashmap_into_iter_bug() { + let dropped: Arc = Arc::new(AtomicI8::new(1)); + + { + let mut map = HashMap::with_capacity_in(10, MyAlloc::new(dropped.clone())); + for i in 0..10 { + map.entry(i).or_insert_with(|| "i".to_string()); + } + + for (k, v) in map { + println!("{}, {}", k, v); + } + } + + // All allocator clones should already be dropped. + assert_eq!(dropped.load(Ordering::SeqCst), 0); + } + + #[derive(Debug)] + struct CheckedCloneDrop { + panic_in_clone: bool, + panic_in_drop: bool, + dropped: bool, + data: T, + } + + impl CheckedCloneDrop { + fn new(panic_in_clone: bool, panic_in_drop: bool, data: T) -> Self { + CheckedCloneDrop { + panic_in_clone, + panic_in_drop, + dropped: false, + data, + } + } + } + + impl Clone for CheckedCloneDrop { + fn clone(&self) -> Self { + if self.panic_in_clone { + panic!("panic in clone") + } + Self { + panic_in_clone: self.panic_in_clone, + panic_in_drop: self.panic_in_drop, + dropped: self.dropped, + data: self.data.clone(), + } + } + } + + impl Drop for CheckedCloneDrop { + fn drop(&mut self) { + if self.panic_in_drop { + self.dropped = true; + panic!("panic in drop"); + } + if self.dropped { + panic!("double drop"); + } + self.dropped = true; + } + } + + /// Return hashmap with predefined distribution of elements. + /// All elements will be located in the same order as elements + /// returned by iterator. + /// + /// This function does not panic, but returns an error as a `String` + /// to distinguish between a test panic and an error in the input data. + fn get_test_map( + iter: I, + mut fun: impl FnMut(u64) -> T, + alloc: A, + ) -> Result, DefaultHashBuilder, A>, String> + where + I: Iterator + Clone + ExactSizeIterator, + A: Allocator, + T: PartialEq + core::fmt::Debug, + { + use crate::scopeguard::guard; + + let mut map: HashMap, _, A> = + HashMap::with_capacity_in(iter.size_hint().0, alloc); + { + let mut guard = guard(&mut map, |map| { + for (_, value) in map.iter_mut() { + value.panic_in_drop = false + } + }); + + let mut count = 0; + // Hash and Key must be equal to each other for controlling the elements placement. + for (panic_in_clone, panic_in_drop) in iter.clone() { + if core::mem::needs_drop::() && panic_in_drop { + return Err(String::from( + "panic_in_drop can be set with a type that doesn't need to be dropped", + )); + } + guard.table.insert( + count, + ( + count, + CheckedCloneDrop::new(panic_in_clone, panic_in_drop, fun(count)), + ), + |(k, _)| *k, + ); + count += 1; + } + + // Let's check that all elements are located as we wanted + let mut check_count = 0; + for ((key, value), (panic_in_clone, panic_in_drop)) in guard.iter().zip(iter) { + if *key != check_count { + return Err(format!( + "key != check_count,\nkey: `{}`,\ncheck_count: `{}`", + key, check_count + )); + } + if value.dropped + || value.panic_in_clone != panic_in_clone + || value.panic_in_drop != panic_in_drop + || value.data != fun(check_count) + { + return Err(format!( + "Value is not equal to expected,\nvalue: `{:?}`,\nexpected: \ + `CheckedCloneDrop {{ panic_in_clone: {}, panic_in_drop: {}, dropped: {}, data: {:?} }}`", + value, panic_in_clone, panic_in_drop, false, fun(check_count) + )); + } + check_count += 1; + } + + if guard.len() != check_count as usize { + return Err(format!( + "map.len() != check_count,\nmap.len(): `{}`,\ncheck_count: `{}`", + guard.len(), + check_count + )); + } + + if count != check_count { + return Err(format!( + "count != check_count,\ncount: `{}`,\ncheck_count: `{}`", + count, check_count + )); + } + core::mem::forget(guard); + } + Ok(map) + } + + const DISARMED: bool = false; + const ARMED: bool = true; + + const ARMED_FLAGS: [bool; 8] = [ + DISARMED, DISARMED, DISARMED, ARMED, DISARMED, DISARMED, DISARMED, DISARMED, + ]; + + const DISARMED_FLAGS: [bool; 8] = [ + DISARMED, DISARMED, DISARMED, DISARMED, DISARMED, DISARMED, DISARMED, DISARMED, + ]; + + #[test] + #[should_panic = "panic in clone"] + fn test_clone_memory_leaks_and_double_drop_one() { + let dropped: Arc = Arc::new(AtomicI8::new(2)); + + { + assert_eq!(ARMED_FLAGS.len(), DISARMED_FLAGS.len()); + + let map: HashMap>, DefaultHashBuilder, MyAlloc> = + match get_test_map( + ARMED_FLAGS.into_iter().zip(DISARMED_FLAGS), + |n| vec![n], + MyAlloc::new(dropped.clone()), + ) { + Ok(map) => map, + Err(msg) => panic!("{msg}"), + }; + + // Clone should normally clone a few elements, and then (when the + // clone function panics), deallocate both its own memory, memory + // of `dropped: Arc` and the memory of already cloned + // elements (Vec memory inside CheckedCloneDrop). + let _map2 = map.clone(); + } + } + + #[test] + #[should_panic = "panic in drop"] + fn test_clone_memory_leaks_and_double_drop_two() { + let dropped: Arc = Arc::new(AtomicI8::new(2)); + + { + assert_eq!(ARMED_FLAGS.len(), DISARMED_FLAGS.len()); + + let map: HashMap, DefaultHashBuilder, _> = match get_test_map( + DISARMED_FLAGS.into_iter().zip(DISARMED_FLAGS), + |n| n, + MyAlloc::new(dropped.clone()), + ) { + Ok(map) => map, + Err(msg) => panic!("{msg}"), + }; + + let mut map2 = match get_test_map( + DISARMED_FLAGS.into_iter().zip(ARMED_FLAGS), + |n| n, + MyAlloc::new(dropped.clone()), + ) { + Ok(map) => map, + Err(msg) => panic!("{msg}"), + }; + + // The `clone_from` should try to drop the elements of `map2` without + // double drop and leaking the allocator. Elements that have not been + // dropped leak their memory. + map2.clone_from(&map); + } + } + + /// We check that we have a working table if the clone operation from another + /// thread ended in a panic (when buckets of maps are equal to each other). + #[test] + fn test_catch_panic_clone_from_when_len_is_equal() { + use std::thread; + + let dropped: Arc = Arc::new(AtomicI8::new(2)); + + { + assert_eq!(ARMED_FLAGS.len(), DISARMED_FLAGS.len()); + + let mut map = match get_test_map( + DISARMED_FLAGS.into_iter().zip(DISARMED_FLAGS), + |n| vec![n], + MyAlloc::new(dropped.clone()), + ) { + Ok(map) => map, + Err(msg) => panic!("{msg}"), + }; + + thread::scope(|s| { + let result: thread::ScopedJoinHandle<'_, String> = s.spawn(|| { + let scope_map = + match get_test_map(ARMED_FLAGS.into_iter().zip(DISARMED_FLAGS), |n| vec![n * 2], MyAlloc::new(dropped.clone())) { + Ok(map) => map, + Err(msg) => return msg, + }; + if map.table.buckets() != scope_map.table.buckets() { + return format!( + "map.table.buckets() != scope_map.table.buckets(),\nleft: `{}`,\nright: `{}`", + map.table.buckets(), scope_map.table.buckets() + ); + } + map.clone_from(&scope_map); + "We must fail the cloning!!!".to_owned() + }); + if let Ok(msg) = result.join() { + panic!("{msg}") + } + }); + + // Let's check that all iterators work fine and do not return elements + // (especially `RawIterRange`, which does not depend on the number of + // elements in the table, but looks directly at the control bytes) + // + // SAFETY: We know for sure that `RawTable` will outlive + // the returned `RawIter / RawIterRange` iterator. + assert_eq!(map.len(), 0); + assert_eq!(map.iter().count(), 0); + assert_eq!(unsafe { map.table.iter().count() }, 0); + assert_eq!(unsafe { map.table.iter().iter.count() }, 0); + + for idx in 0..map.table.buckets() { + let idx = idx as u64; + assert!( + map.table.find(idx, |(k, _)| *k == idx).is_none(), + "Index: {idx}" + ); + } + } + + // All allocator clones should already be dropped. + assert_eq!(dropped.load(Ordering::SeqCst), 0); + } + + /// We check that we have a working table if the clone operation from another + /// thread ended in a panic (when buckets of maps are not equal to each other). + #[test] + fn test_catch_panic_clone_from_when_len_is_not_equal() { + use std::thread; + + let dropped: Arc = Arc::new(AtomicI8::new(2)); + + { + assert_eq!(ARMED_FLAGS.len(), DISARMED_FLAGS.len()); + + let mut map = match get_test_map( + [DISARMED].into_iter().zip([DISARMED]), + |n| vec![n], + MyAlloc::new(dropped.clone()), + ) { + Ok(map) => map, + Err(msg) => panic!("{msg}"), + }; + + thread::scope(|s| { + let result: thread::ScopedJoinHandle<'_, String> = s.spawn(|| { + let scope_map = match get_test_map( + ARMED_FLAGS.into_iter().zip(DISARMED_FLAGS), + |n| vec![n * 2], + MyAlloc::new(dropped.clone()), + ) { + Ok(map) => map, + Err(msg) => return msg, + }; + if map.table.buckets() == scope_map.table.buckets() { + return format!( + "map.table.buckets() == scope_map.table.buckets(): `{}`", + map.table.buckets() + ); + } + map.clone_from(&scope_map); + "We must fail the cloning!!!".to_owned() + }); + if let Ok(msg) = result.join() { + panic!("{msg}") + } + }); + + // Let's check that all iterators work fine and do not return elements + // (especially `RawIterRange`, which does not depend on the number of + // elements in the table, but looks directly at the control bytes) + // + // SAFETY: We know for sure that `RawTable` will outlive + // the returned `RawIter / RawIterRange` iterator. + assert_eq!(map.len(), 0); + assert_eq!(map.iter().count(), 0); + assert_eq!(unsafe { map.table.iter().count() }, 0); + assert_eq!(unsafe { map.table.iter().iter.count() }, 0); + + for idx in 0..map.table.buckets() { + let idx = idx as u64; + assert!( + map.table.find(idx, |(k, _)| *k == idx).is_none(), + "Index: {idx}" + ); + } + } + + // All allocator clones should already be dropped. + assert_eq!(dropped.load(Ordering::SeqCst), 0); + } } diff --git a/sgx_tstd/hashbrown/src/raw/alloc.rs b/sgx_tstd/hashbrown/src/raw/alloc.rs index 76fe1e923..15299e7b0 100644 --- a/sgx_tstd/hashbrown/src/raw/alloc.rs +++ b/sgx_tstd/hashbrown/src/raw/alloc.rs @@ -1,5 +1,9 @@ pub(crate) use self::inner::{do_alloc, Allocator, Global}; +// Nightly-case. +// Use unstable `allocator_api` feature. +// This is compatible with `allocator-api2` which can be enabled or not. +// This is used when building for `std`. #[cfg(feature = "nightly")] mod inner { use crate::alloc::alloc::Layout; @@ -7,28 +11,44 @@ mod inner { use core::ptr::NonNull; #[allow(clippy::map_err_ignore)] - pub fn do_alloc(alloc: &A, layout: Layout) -> Result, ()> { - alloc - .allocate(layout) - .map(|ptr| ptr.as_non_null_ptr()) - .map_err(|_| ()) + pub(crate) fn do_alloc(alloc: &A, layout: Layout) -> Result, ()> { + match alloc.allocate(layout) { + Ok(ptr) => Ok(ptr.as_non_null_ptr()), + Err(_) => Err(()), + } } +} - #[cfg(feature = "bumpalo")] - unsafe impl Allocator for crate::BumpWrapper<'_> { - #[inline] - fn allocate(&self, layout: Layout) -> Result, core::alloc::AllocError> { - match self.0.try_alloc_layout(layout) { - Ok(ptr) => Ok(NonNull::slice_from_raw_parts(ptr, layout.size())), - Err(_) => Err(core::alloc::AllocError), - } +// Basic non-nightly case. +// This uses `allocator-api2` enabled by default. +// If any crate enables "nightly" in `allocator-api2`, +// this will be equivalent to the nightly case, +// since `allocator_api2::alloc::Allocator` would be re-export of +// `core::alloc::Allocator`. +#[cfg(all(not(feature = "nightly"), feature = "allocator-api2"))] +mod inner { + use crate::alloc::alloc::Layout; + pub use allocator_api2::alloc::{Allocator, Global}; + use core::ptr::NonNull; + + #[allow(clippy::map_err_ignore)] + pub(crate) fn do_alloc(alloc: &A, layout: Layout) -> Result, ()> { + match alloc.allocate(layout) { + Ok(ptr) => Ok(ptr.cast()), + Err(_) => Err(()), } - #[inline] - unsafe fn deallocate(&self, _ptr: NonNull, _layout: Layout) {} } } -#[cfg(not(feature = "nightly"))] +// No-defaults case. +// When building with default-features turned off and +// neither `nightly` nor `allocator-api2` is enabled, +// this will be used. +// Making it impossible to use any custom allocator with collections defined +// in this crate. +// Any crate in build-tree can enable `allocator-api2`, +// or `nightly` without disturbing users that don't want to use it. +#[cfg(not(any(feature = "nightly", feature = "allocator-api2")))] mod inner { use crate::alloc::alloc::{alloc, dealloc, Layout}; use core::ptr::NonNull; @@ -41,6 +61,7 @@ mod inner { #[derive(Copy, Clone)] pub struct Global; + unsafe impl Allocator for Global { #[inline] fn allocate(&self, layout: Layout) -> Result, ()> { @@ -51,6 +72,7 @@ mod inner { dealloc(ptr.as_ptr(), layout); } } + impl Default for Global { #[inline] fn default() -> Self { @@ -58,16 +80,7 @@ mod inner { } } - pub fn do_alloc(alloc: &A, layout: Layout) -> Result, ()> { + pub(crate) fn do_alloc(alloc: &A, layout: Layout) -> Result, ()> { alloc.allocate(layout) } - - #[cfg(feature = "bumpalo")] - unsafe impl Allocator for crate::BumpWrapper<'_> { - #[allow(clippy::map_err_ignore)] - fn allocate(&self, layout: Layout) -> Result, ()> { - self.0.try_alloc_layout(layout).map_err(|_| ()) - } - unsafe fn deallocate(&self, _ptr: NonNull, _layout: Layout) {} - } } diff --git a/sgx_tstd/hashbrown/src/raw/bitmask.rs b/sgx_tstd/hashbrown/src/raw/bitmask.rs index 7d4f9fc38..6576b3c5c 100644 --- a/sgx_tstd/hashbrown/src/raw/bitmask.rs +++ b/sgx_tstd/hashbrown/src/raw/bitmask.rs @@ -1,6 +1,6 @@ -use super::imp::{BitMaskWord, BITMASK_MASK, BITMASK_STRIDE}; -#[cfg(feature = "nightly")] -use core::intrinsics; +use super::imp::{ + BitMaskWord, NonZeroBitMaskWord, BITMASK_ITER_MASK, BITMASK_MASK, BITMASK_STRIDE, +}; /// A bit mask which contains the result of a `Match` operation on a `Group` and /// allows iterating through them. @@ -8,75 +8,55 @@ use core::intrinsics; /// The bit mask is arranged so that low-order bits represent lower memory /// addresses for group match results. /// -/// For implementation reasons, the bits in the set may be sparsely packed, so -/// that there is only one bit-per-byte used (the high bit, 7). If this is the +/// For implementation reasons, the bits in the set may be sparsely packed with +/// groups of 8 bits representing one element. If any of these bits are non-zero +/// then this element is considered to true in the mask. If this is the /// case, `BITMASK_STRIDE` will be 8 to indicate a divide-by-8 should be /// performed on counts/indices to normalize this difference. `BITMASK_MASK` is /// similarly a mask of all the actually-used bits. +/// +/// To iterate over a bit mask, it must be converted to a form where only 1 bit +/// is set per element. This is done by applying `BITMASK_ITER_MASK` on the +/// mask bits. #[derive(Copy, Clone)] -pub struct BitMask(pub BitMaskWord); +pub(crate) struct BitMask(pub(crate) BitMaskWord); #[allow(clippy::use_self)] impl BitMask { /// Returns a new `BitMask` with all bits inverted. #[inline] #[must_use] - pub fn invert(self) -> Self { + #[allow(dead_code)] + pub(crate) fn invert(self) -> Self { BitMask(self.0 ^ BITMASK_MASK) } - /// Flip the bit in the mask for the entry at the given index. - /// - /// Returns the bit's previous state. - #[inline] - #[allow(clippy::cast_ptr_alignment)] - #[cfg(feature = "raw")] - pub unsafe fn flip(&mut self, index: usize) -> bool { - // NOTE: The + BITMASK_STRIDE - 1 is to set the high bit. - let mask = 1 << (index * BITMASK_STRIDE + BITMASK_STRIDE - 1); - self.0 ^= mask; - // The bit was set if the bit is now 0. - self.0 & mask == 0 - } - /// Returns a new `BitMask` with the lowest bit removed. #[inline] #[must_use] - pub fn remove_lowest_bit(self) -> Self { + fn remove_lowest_bit(self) -> Self { BitMask(self.0 & (self.0 - 1)) } + /// Returns whether the `BitMask` has at least one set bit. #[inline] - pub fn any_bit_set(self) -> bool { + pub(crate) fn any_bit_set(self) -> bool { self.0 != 0 } /// Returns the first set bit in the `BitMask`, if there is one. #[inline] - pub fn lowest_set_bit(self) -> Option { - if self.0 == 0 { - None + pub(crate) fn lowest_set_bit(self) -> Option { + if let Some(nonzero) = NonZeroBitMaskWord::new(self.0) { + Some(Self::nonzero_trailing_zeros(nonzero)) } else { - Some(unsafe { self.lowest_set_bit_nonzero() }) + None } } - /// Returns the first set bit in the `BitMask`, if there is one. The - /// bitmask must not be empty. - #[inline] - #[cfg(feature = "nightly")] - pub unsafe fn lowest_set_bit_nonzero(self) -> usize { - intrinsics::cttz_nonzero(self.0) as usize / BITMASK_STRIDE - } - #[inline] - #[cfg(not(feature = "nightly"))] - pub unsafe fn lowest_set_bit_nonzero(self) -> usize { - self.trailing_zeros() - } - /// Returns the number of trailing zeroes in the `BitMask`. #[inline] - pub fn trailing_zeros(self) -> usize { + pub(crate) fn trailing_zeros(self) -> usize { // ARM doesn't have a trailing_zeroes instruction, and instead uses // reverse_bits (RBIT) + leading_zeroes (CLZ). However older ARM // versions (pre-ARMv7) don't have RBIT and need to emulate it @@ -89,9 +69,21 @@ impl BitMask { } } + /// Same as above but takes a `NonZeroBitMaskWord`. + #[inline] + fn nonzero_trailing_zeros(nonzero: NonZeroBitMaskWord) -> usize { + if cfg!(target_arch = "arm") && BITMASK_STRIDE % 8 == 0 { + // SAFETY: A byte-swapped non-zero value is still non-zero. + let swapped = unsafe { NonZeroBitMaskWord::new_unchecked(nonzero.get().swap_bytes()) }; + swapped.leading_zeros() as usize / BITMASK_STRIDE + } else { + nonzero.trailing_zeros() as usize / BITMASK_STRIDE + } + } + /// Returns the number of leading zeroes in the `BitMask`. #[inline] - pub fn leading_zeros(self) -> usize { + pub(crate) fn leading_zeros(self) -> usize { self.0.leading_zeros() as usize / BITMASK_STRIDE } } @@ -102,13 +94,32 @@ impl IntoIterator for BitMask { #[inline] fn into_iter(self) -> BitMaskIter { - BitMaskIter(self) + // A BitMask only requires each element (group of bits) to be non-zero. + // However for iteration we need each element to only contain 1 bit. + BitMaskIter(BitMask(self.0 & BITMASK_ITER_MASK)) } } /// Iterator over the contents of a `BitMask`, returning the indices of set /// bits. -pub struct BitMaskIter(BitMask); +#[derive(Copy, Clone)] +pub(crate) struct BitMaskIter(pub(crate) BitMask); + +impl BitMaskIter { + /// Flip the bit in the mask for the entry at the given index. + /// + /// Returns the bit's previous state. + #[inline] + #[allow(clippy::cast_ptr_alignment)] + #[cfg(feature = "raw")] + pub(crate) unsafe fn flip(&mut self, index: usize) -> bool { + // NOTE: The + BITMASK_STRIDE - 1 is to set the high bit. + let mask = 1 << (index * BITMASK_STRIDE + BITMASK_STRIDE - 1); + self.0 .0 ^= mask; + // The bit was set if the bit is now 0. + self.0 .0 & mask == 0 + } +} impl Iterator for BitMaskIter { type Item = usize; diff --git a/sgx_tstd/hashbrown/src/raw/generic.rs b/sgx_tstd/hashbrown/src/raw/generic.rs index b4d31e62c..c668b0642 100644 --- a/sgx_tstd/hashbrown/src/raw/generic.rs +++ b/sgx_tstd/hashbrown/src/raw/generic.rs @@ -5,26 +5,29 @@ use core::{mem, ptr}; // Use the native word size as the group size. Using a 64-bit group size on // a 32-bit architecture will just end up being more expensive because // shifts and multiplies will need to be emulated. -#[cfg(any( - target_pointer_width = "64", - target_arch = "aarch64", - target_arch = "x86_64", - target_arch = "wasm32", -))] -type GroupWord = u64; -#[cfg(all( - target_pointer_width = "32", - not(target_arch = "aarch64"), - not(target_arch = "x86_64"), - not(target_arch = "wasm32"), -))] -type GroupWord = u32; -pub type BitMaskWord = GroupWord; -pub const BITMASK_STRIDE: usize = 8; +cfg_if! { + if #[cfg(any( + target_pointer_width = "64", + target_arch = "aarch64", + target_arch = "x86_64", + target_arch = "wasm32", + ))] { + type GroupWord = u64; + type NonZeroGroupWord = core::num::NonZeroU64; + } else { + type GroupWord = u32; + type NonZeroGroupWord = core::num::NonZeroU32; + } +} + +pub(crate) type BitMaskWord = GroupWord; +pub(crate) type NonZeroBitMaskWord = NonZeroGroupWord; +pub(crate) const BITMASK_STRIDE: usize = 8; // We only care about the highest bit of each byte for the mask. #[allow(clippy::cast_possible_truncation, clippy::unnecessary_cast)] -pub const BITMASK_MASK: BitMaskWord = 0x8080_8080_8080_8080_u64 as GroupWord; +pub(crate) const BITMASK_MASK: BitMaskWord = 0x8080_8080_8080_8080_u64 as GroupWord; +pub(crate) const BITMASK_ITER_MASK: BitMaskWord = !0; /// Helper function to replicate a byte across a `GroupWord`. #[inline] @@ -37,7 +40,7 @@ fn repeat(byte: u8) -> GroupWord { /// /// This implementation uses a word-sized integer. #[derive(Copy, Clone)] -pub struct Group(GroupWord); +pub(crate) struct Group(GroupWord); // We perform all operations in the native endianness, and convert to // little-endian just before creating a BitMask. The can potentially @@ -46,14 +49,14 @@ pub struct Group(GroupWord); #[allow(clippy::use_self)] impl Group { /// Number of bytes in the group. - pub const WIDTH: usize = mem::size_of::(); + pub(crate) const WIDTH: usize = mem::size_of::(); /// Returns a full group of empty bytes, suitable for use as the initial /// value for an empty hash table. /// /// This is guaranteed to be aligned to the group size. #[inline] - pub const fn static_empty() -> &'static [u8; Group::WIDTH] { + pub(crate) const fn static_empty() -> &'static [u8; Group::WIDTH] { #[repr(C)] struct AlignedBytes { _align: [Group; 0], @@ -69,7 +72,7 @@ impl Group { /// Loads a group of bytes starting at the given address. #[inline] #[allow(clippy::cast_ptr_alignment)] // unaligned load - pub unsafe fn load(ptr: *const u8) -> Self { + pub(crate) unsafe fn load(ptr: *const u8) -> Self { Group(ptr::read_unaligned(ptr.cast())) } @@ -77,7 +80,7 @@ impl Group { /// aligned to `mem::align_of::()`. #[inline] #[allow(clippy::cast_ptr_alignment)] - pub unsafe fn load_aligned(ptr: *const u8) -> Self { + pub(crate) unsafe fn load_aligned(ptr: *const u8) -> Self { // FIXME: use align_offset once it stabilizes debug_assert_eq!(ptr as usize & (mem::align_of::() - 1), 0); Group(ptr::read(ptr.cast())) @@ -87,7 +90,7 @@ impl Group { /// aligned to `mem::align_of::()`. #[inline] #[allow(clippy::cast_ptr_alignment)] - pub unsafe fn store_aligned(self, ptr: *mut u8) { + pub(crate) unsafe fn store_aligned(self, ptr: *mut u8) { // FIXME: use align_offset once it stabilizes debug_assert_eq!(ptr as usize & (mem::align_of::() - 1), 0); ptr::write(ptr.cast(), self.0); @@ -104,7 +107,7 @@ impl Group { /// - This only happens if there is at least 1 true match. /// - The chance of this happening is very low (< 1% chance per byte). #[inline] - pub fn match_byte(self, byte: u8) -> BitMask { + pub(crate) fn match_byte(self, byte: u8) -> BitMask { // This algorithm is derived from // https://graphics.stanford.edu/~seander/bithacks.html##ValueInWord let cmp = self.0 ^ repeat(byte); @@ -114,7 +117,7 @@ impl Group { /// Returns a `BitMask` indicating all bytes in the group which are /// `EMPTY`. #[inline] - pub fn match_empty(self) -> BitMask { + pub(crate) fn match_empty(self) -> BitMask { // If the high bit is set, then the byte must be either: // 1111_1111 (EMPTY) or 1000_0000 (DELETED). // So we can just check if the top two bits are 1 by ANDing them. @@ -124,14 +127,14 @@ impl Group { /// Returns a `BitMask` indicating all bytes in the group which are /// `EMPTY` or `DELETED`. #[inline] - pub fn match_empty_or_deleted(self) -> BitMask { + pub(crate) fn match_empty_or_deleted(self) -> BitMask { // A byte is EMPTY or DELETED iff the high bit is set BitMask((self.0 & repeat(0x80)).to_le()) } /// Returns a `BitMask` indicating all bytes in the group which are full. #[inline] - pub fn match_full(self) -> BitMask { + pub(crate) fn match_full(self) -> BitMask { self.match_empty_or_deleted().invert() } @@ -140,7 +143,7 @@ impl Group { /// - `DELETED => EMPTY` /// - `FULL => DELETED` #[inline] - pub fn convert_special_to_empty_and_full_to_deleted(self) -> Self { + pub(crate) fn convert_special_to_empty_and_full_to_deleted(self) -> Self { // Map high_bit = 1 (EMPTY or DELETED) to 1111_1111 // and high_bit = 0 (FULL) to 1000_0000 // diff --git a/sgx_tstd/hashbrown/src/raw/mod.rs b/sgx_tstd/hashbrown/src/raw/mod.rs index fce54d9f0..25c5d1c4d 100644 --- a/sgx_tstd/hashbrown/src/raw/mod.rs +++ b/sgx_tstd/hashbrown/src/raw/mod.rs @@ -1,10 +1,9 @@ use crate::alloc::alloc::{handle_alloc_error, Layout}; -use crate::scopeguard::guard; +use crate::scopeguard::{guard, ScopeGuard}; use crate::TryReserveError; use core::iter::FusedIterator; use core::marker::PhantomData; use core::mem; -use core::mem::ManuallyDrop; use core::mem::MaybeUninit; use core::ptr::NonNull; use core::{hint, ptr}; @@ -21,12 +20,21 @@ cfg_if! { if #[cfg(all( target_feature = "sse2", any(target_arch = "x86", target_arch = "x86_64"), - not(miri) + not(miri), ))] { mod sse2; use sse2 as imp; + } else if #[cfg(all( + target_arch = "aarch64", + target_feature = "neon", + // NEON intrinsics are currently broken on big-endian targets. + // See https://github.com/rust-lang/stdarch/issues/1484. + target_endian = "little", + not(miri), + ))] { + mod neon; + use neon as imp; } else { - #[path = "generic.rs"] mod generic; use generic as imp; } @@ -37,48 +45,32 @@ pub(crate) use self::alloc::{do_alloc, Allocator, Global}; mod bitmask; -use self::bitmask::{BitMask, BitMaskIter}; +use self::bitmask::BitMaskIter; use self::imp::Group; // Branch prediction hint. This is currently only available on nightly but it // consistently improves performance by 10-15%. +#[cfg(not(feature = "nightly"))] +use core::convert::identity as likely; +#[cfg(not(feature = "nightly"))] +use core::convert::identity as unlikely; #[cfg(feature = "nightly")] use core::intrinsics::{likely, unlikely}; -// On stable we can use #[cold] to get a equivalent effect: this attributes -// suggests that the function is unlikely to be called -#[cfg(not(feature = "nightly"))] -#[inline] -#[cold] -fn cold() {} - -#[cfg(not(feature = "nightly"))] -#[inline] -fn likely(b: bool) -> bool { - if !b { - cold(); - } - b -} +// Use strict provenance functions if available. +#[cfg(feature = "nightly")] +use core::ptr::invalid_mut; +// Implement it with a cast otherwise. #[cfg(not(feature = "nightly"))] -#[inline] -fn unlikely(b: bool) -> bool { - if b { - cold(); - } - b +#[inline(always)] +fn invalid_mut(addr: usize) -> *mut T { + addr as *mut T } -#[cfg(feature = "nightly")] #[inline] unsafe fn offset_from(to: *const T, from: *const T) -> usize { to.offset_from(from) as usize } -#[cfg(not(feature = "nightly"))] -#[inline] -unsafe fn offset_from(to: *const T, from: *const T) -> usize { - (to as usize - from as usize) / mem::size_of::() -} /// Whether memory allocation errors should return an error or abort. #[derive(Copy, Clone)] @@ -107,6 +99,13 @@ impl Fallibility { } } +trait SizedTypeProperties: Sized { + const IS_ZERO_SIZED: bool = mem::size_of::() == 0; + const NEEDS_DROP: bool = mem::needs_drop::(); +} + +impl SizedTypeProperties for T {} + /// Control byte value for an empty bucket. const EMPTY: u8 = 0b1111_1111; @@ -140,6 +139,13 @@ fn h1(hash: u64) -> usize { hash as usize } +// Constant for h2 function that grabing the top 7 bits of the hash. +const MIN_HASH_LEN: usize = if mem::size_of::() < mem::size_of::() { + mem::size_of::() +} else { + mem::size_of::() +}; + /// Secondary hash function, saved in the low 7 bits of the control byte. #[inline] #[allow(clippy::cast_possible_truncation)] @@ -147,8 +153,8 @@ fn h2(hash: u64) -> u8 { // Grab the top 7 bits of the hash. While the hash is normally a full 64-bit // value, some hash functions (such as FxHash) produce a usize result // instead, which means that the top 32 bits are 0 on 32-bit platforms. - let hash_len = usize::min(mem::size_of::(), mem::size_of::()); - let top7 = hash >> (hash_len * 8 - 7); + // So we use MIN_HASH_LEN constant to handle this. + let top7 = hash >> (MIN_HASH_LEN * 8 - 7); (top7 & 0x7f) as u8 // truncation } @@ -236,11 +242,15 @@ struct TableLayout { impl TableLayout { #[inline] - fn new() -> Self { + const fn new() -> Self { let layout = Layout::new::(); Self { size: layout.size(), - ctrl_align: usize::max(layout.align(), Group::WIDTH), + ctrl_align: if layout.align() > Group::WIDTH { + layout.align() + } else { + Group::WIDTH + }, } } @@ -254,6 +264,12 @@ impl TableLayout { size.checked_mul(buckets)?.checked_add(ctrl_align - 1)? & !(ctrl_align - 1); let len = ctrl_offset.checked_add(buckets + Group::WIDTH)?; + // We need an additional check to ensure that the allocation doesn't + // exceed `isize::MAX` (https://github.com/rust-lang/rust/pull/95295). + if len > isize::MAX as usize - (ctrl_align - 1) { + return None; + } + Some(( unsafe { Layout::from_size_align_unchecked(len, ctrl_align) }, ctrl_offset, @@ -261,14 +277,9 @@ impl TableLayout { } } -/// Returns a Layout which describes the allocation required for a hash table, -/// and the offset of the control bytes in the allocation. -/// (the offset is also one past last element of buckets) -/// -/// Returns `None` if an overflow occurs. -#[cfg_attr(feature = "inline-more", inline)] -fn calculate_layout(buckets: usize) -> Option<(Layout, usize)> { - TableLayout::new::().calculate_layout_for(buckets) +/// A reference to an empty bucket into which an can be inserted. +pub struct InsertSlot { + index: usize, } /// A reference to a hash table bucket containing a `T`. @@ -296,11 +307,79 @@ impl Clone for Bucket { } impl Bucket { + /// Creates a [`Bucket`] that contain pointer to the data. + /// The pointer calculation is performed by calculating the + /// offset from given `base` pointer (convenience for + /// `base.as_ptr().sub(index)`). + /// + /// `index` is in units of `T`; e.g., an `index` of 3 represents a pointer + /// offset of `3 * size_of::()` bytes. + /// + /// If the `T` is a ZST, then we instead track the index of the element + /// in the table so that `erase` works properly (return + /// `NonNull::new_unchecked((index + 1) as *mut T)`) + /// + /// # Safety + /// + /// If `mem::size_of::() != 0`, then the safety rules are directly derived + /// from the safety rules for [`<*mut T>::sub`] method of `*mut T` and the safety + /// rules of [`NonNull::new_unchecked`] function. + /// + /// Thus, in order to uphold the safety contracts for the [`<*mut T>::sub`] method + /// and [`NonNull::new_unchecked`] function, as well as for the correct + /// logic of the work of this crate, the following rules are necessary and + /// sufficient: + /// + /// * the `base` pointer must not be `dangling` and must points to the + /// end of the first `value element` from the `data part` of the table, i.e. + /// must be the pointer that returned by [`RawTable::data_end`] or by + /// [`RawTableInner::data_end`]; + /// + /// * `index` must not be greater than `RawTableInner.bucket_mask`, i.e. + /// `index <= RawTableInner.bucket_mask` or, in other words, `(index + 1)` + /// must be no greater than the number returned by the function + /// [`RawTable::buckets`] or [`RawTableInner::buckets`]. + /// + /// If `mem::size_of::() == 0`, then the only requirement is that the + /// `index` must not be greater than `RawTableInner.bucket_mask`, i.e. + /// `index <= RawTableInner.bucket_mask` or, in other words, `(index + 1)` + /// must be no greater than the number returned by the function + /// [`RawTable::buckets`] or [`RawTableInner::buckets`]. + /// + /// [`Bucket`]: crate::raw::Bucket + /// [`<*mut T>::sub`]: https://doc.rust-lang.org/core/primitive.pointer.html#method.sub-1 + /// [`NonNull::new_unchecked`]: https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.new_unchecked + /// [`RawTable::data_end`]: crate::raw::RawTable::data_end + /// [`RawTableInner::data_end`]: RawTableInner::data_end + /// [`RawTable::buckets`]: crate::raw::RawTable::buckets + /// [`RawTableInner::buckets`]: RawTableInner::buckets #[inline] unsafe fn from_base_index(base: NonNull, index: usize) -> Self { - let ptr = if mem::size_of::() == 0 { - // won't overflow because index must be less than length - (index + 1) as *mut T + // If mem::size_of::() != 0 then return a pointer to an `element` in + // the data part of the table (we start counting from "0", so that + // in the expression T[last], the "last" index actually one less than the + // "buckets" number in the table, i.e. "last = RawTableInner.bucket_mask"): + // + // `from_base_index(base, 1).as_ptr()` returns a pointer that + // points here in the data part of the table + // (to the start of T1) + // | + // | `base: NonNull` must point here + // | (to the end of T0 or to the start of C0) + // v v + // [Padding], Tlast, ..., |T1|, T0, |C0, C1, ..., Clast + // ^ + // `from_base_index(base, 1)` returns a pointer + // that points here in the data part of the table + // (to the end of T1) + // + // where: T0...Tlast - our stored data; C0...Clast - control bytes + // or metadata for data. + let ptr = if T::IS_ZERO_SIZED { + // won't overflow because index must be less than length (bucket_mask) + // and bucket_mask is guaranteed to be less than `isize::MAX` + // (see TableLayout::calculate_layout_for method) + invalid_mut(index + 1) } else { base.as_ptr().sub(index) }; @@ -308,27 +387,183 @@ impl Bucket { ptr: NonNull::new_unchecked(ptr), } } + + /// Calculates the index of a [`Bucket`] as distance between two pointers + /// (convenience for `base.as_ptr().offset_from(self.ptr.as_ptr()) as usize`). + /// The returned value is in units of T: the distance in bytes divided by + /// [`core::mem::size_of::()`]. + /// + /// If the `T` is a ZST, then we return the index of the element in + /// the table so that `erase` works properly (return `self.ptr.as_ptr() as usize - 1`). + /// + /// This function is the inverse of [`from_base_index`]. + /// + /// # Safety + /// + /// If `mem::size_of::() != 0`, then the safety rules are directly derived + /// from the safety rules for [`<*const T>::offset_from`] method of `*const T`. + /// + /// Thus, in order to uphold the safety contracts for [`<*const T>::offset_from`] + /// method, as well as for the correct logic of the work of this crate, the + /// following rules are necessary and sufficient: + /// + /// * `base` contained pointer must not be `dangling` and must point to the + /// end of the first `element` from the `data part` of the table, i.e. + /// must be a pointer that returns by [`RawTable::data_end`] or by + /// [`RawTableInner::data_end`]; + /// + /// * `self` also must not contain dangling pointer; + /// + /// * both `self` and `base` must be created from the same [`RawTable`] + /// (or [`RawTableInner`]). + /// + /// If `mem::size_of::() == 0`, this function is always safe. + /// + /// [`Bucket`]: crate::raw::Bucket + /// [`from_base_index`]: crate::raw::Bucket::from_base_index + /// [`RawTable::data_end`]: crate::raw::RawTable::data_end + /// [`RawTableInner::data_end`]: RawTableInner::data_end + /// [`RawTable`]: crate::raw::RawTable + /// [`RawTableInner`]: RawTableInner + /// [`<*const T>::offset_from`]: https://doc.rust-lang.org/nightly/core/primitive.pointer.html#method.offset_from #[inline] unsafe fn to_base_index(&self, base: NonNull) -> usize { - if mem::size_of::() == 0 { + // If mem::size_of::() != 0 then return an index under which we used to store the + // `element` in the data part of the table (we start counting from "0", so + // that in the expression T[last], the "last" index actually is one less than the + // "buckets" number in the table, i.e. "last = RawTableInner.bucket_mask"). + // For example for 5th element in table calculation is performed like this: + // + // mem::size_of::() + // | + // | `self = from_base_index(base, 5)` that returns pointer + // | that points here in tha data part of the table + // | (to the end of T5) + // | | `base: NonNull` must point here + // v | (to the end of T0 or to the start of C0) + // /???\ v v + // [Padding], Tlast, ..., |T10|, ..., T5|, T4, T3, T2, T1, T0, |C0, C1, C2, C3, C4, C5, ..., C10, ..., Clast + // \__________ __________/ + // \/ + // `bucket.to_base_index(base)` = 5 + // (base.as_ptr() as usize - self.ptr.as_ptr() as usize) / mem::size_of::() + // + // where: T0...Tlast - our stored data; C0...Clast - control bytes or metadata for data. + if T::IS_ZERO_SIZED { + // this can not be UB self.ptr.as_ptr() as usize - 1 } else { offset_from(base.as_ptr(), self.ptr.as_ptr()) } } + + /// Acquires the underlying raw pointer `*mut T` to `data`. + /// + /// # Note + /// + /// If `T` is not [`Copy`], do not use `*mut T` methods that can cause calling the + /// destructor of `T` (for example the [`<*mut T>::drop_in_place`] method), because + /// for properly dropping the data we also need to clear `data` control bytes. If we + /// drop data, but do not clear `data control byte` it leads to double drop when + /// [`RawTable`] goes out of scope. + /// + /// If you modify an already initialized `value`, so [`Hash`] and [`Eq`] on the new + /// `T` value and its borrowed form *must* match those for the old `T` value, as the map + /// will not re-evaluate where the new value should go, meaning the value may become + /// "lost" if their location does not reflect their state. + /// + /// [`RawTable`]: crate::raw::RawTable + /// [`<*mut T>::drop_in_place`]: https://doc.rust-lang.org/core/primitive.pointer.html#method.drop_in_place + /// [`Hash`]: https://doc.rust-lang.org/core/hash/trait.Hash.html + /// [`Eq`]: https://doc.rust-lang.org/core/cmp/trait.Eq.html + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "raw")] + /// # fn test() { + /// use core::hash::{BuildHasher, Hash}; + /// use hashbrown::raw::{Bucket, RawTable}; + /// + /// type NewHashBuilder = core::hash::BuildHasherDefault; + /// + /// fn make_hash(hash_builder: &S, key: &K) -> u64 { + /// use core::hash::Hasher; + /// let mut state = hash_builder.build_hasher(); + /// key.hash(&mut state); + /// state.finish() + /// } + /// + /// let hash_builder = NewHashBuilder::default(); + /// let mut table = RawTable::new(); + /// + /// let value = ("a", 100); + /// let hash = make_hash(&hash_builder, &value.0); + /// + /// table.insert(hash, value.clone(), |val| make_hash(&hash_builder, &val.0)); + /// + /// let bucket: Bucket<(&str, i32)> = table.find(hash, |(k1, _)| k1 == &value.0).unwrap(); + /// + /// assert_eq!(unsafe { &*bucket.as_ptr() }, &("a", 100)); + /// # } + /// # fn main() { + /// # #[cfg(feature = "raw")] + /// # test() + /// # } + /// ``` #[inline] pub fn as_ptr(&self) -> *mut T { - if mem::size_of::() == 0 { + if T::IS_ZERO_SIZED { // Just return an arbitrary ZST pointer which is properly aligned - mem::align_of::() as *mut T + // invalid pointer is good enough for ZST + invalid_mut(mem::align_of::()) } else { unsafe { self.ptr.as_ptr().sub(1) } } } + + /// Create a new [`Bucket`] that is offset from the `self` by the given + /// `offset`. The pointer calculation is performed by calculating the + /// offset from `self` pointer (convenience for `self.ptr.as_ptr().sub(offset)`). + /// This function is used for iterators. + /// + /// `offset` is in units of `T`; e.g., a `offset` of 3 represents a pointer + /// offset of `3 * size_of::()` bytes. + /// + /// # Safety + /// + /// If `mem::size_of::() != 0`, then the safety rules are directly derived + /// from the safety rules for [`<*mut T>::sub`] method of `*mut T` and safety + /// rules of [`NonNull::new_unchecked`] function. + /// + /// Thus, in order to uphold the safety contracts for [`<*mut T>::sub`] method + /// and [`NonNull::new_unchecked`] function, as well as for the correct + /// logic of the work of this crate, the following rules are necessary and + /// sufficient: + /// + /// * `self` contained pointer must not be `dangling`; + /// + /// * `self.to_base_index() + ofset` must not be greater than `RawTableInner.bucket_mask`, + /// i.e. `(self.to_base_index() + ofset) <= RawTableInner.bucket_mask` or, in other + /// words, `self.to_base_index() + ofset + 1` must be no greater than the number returned + /// by the function [`RawTable::buckets`] or [`RawTableInner::buckets`]. + /// + /// If `mem::size_of::() == 0`, then the only requirement is that the + /// `self.to_base_index() + ofset` must not be greater than `RawTableInner.bucket_mask`, + /// i.e. `(self.to_base_index() + ofset) <= RawTableInner.bucket_mask` or, in other words, + /// `self.to_base_index() + ofset + 1` must be no greater than the number returned by the + /// function [`RawTable::buckets`] or [`RawTableInner::buckets`]. + /// + /// [`Bucket`]: crate::raw::Bucket + /// [`<*mut T>::sub`]: https://doc.rust-lang.org/core/primitive.pointer.html#method.sub-1 + /// [`NonNull::new_unchecked`]: https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.new_unchecked + /// [`RawTable::buckets`]: crate::raw::RawTable::buckets + /// [`RawTableInner::buckets`]: RawTableInner::buckets #[inline] unsafe fn next_n(&self, offset: usize) -> Self { - let ptr = if mem::size_of::() == 0 { - (self.ptr.as_ptr() as usize + offset) as *mut T + let ptr = if T::IS_ZERO_SIZED { + // invalid pointer is good enough for ZST + invalid_mut(self.ptr.as_ptr() as usize + offset) } else { self.ptr.as_ptr().sub(offset) }; @@ -336,26 +571,212 @@ impl Bucket { ptr: NonNull::new_unchecked(ptr), } } + + /// Executes the destructor (if any) of the pointed-to `data`. + /// + /// # Safety + /// + /// See [`ptr::drop_in_place`] for safety concerns. + /// + /// You should use [`RawTable::erase`] instead of this function, + /// or be careful with calling this function directly, because for + /// properly dropping the data we need also clear `data` control bytes. + /// If we drop data, but do not erase `data control byte` it leads to + /// double drop when [`RawTable`] goes out of scope. + /// + /// [`ptr::drop_in_place`]: https://doc.rust-lang.org/core/ptr/fn.drop_in_place.html + /// [`RawTable`]: crate::raw::RawTable + /// [`RawTable::erase`]: crate::raw::RawTable::erase #[cfg_attr(feature = "inline-more", inline)] - pub unsafe fn drop(&self) { + pub(crate) unsafe fn drop(&self) { self.as_ptr().drop_in_place(); } + + /// Reads the `value` from `self` without moving it. This leaves the + /// memory in `self` unchanged. + /// + /// # Safety + /// + /// See [`ptr::read`] for safety concerns. + /// + /// You should use [`RawTable::remove`] instead of this function, + /// or be careful with calling this function directly, because compiler + /// calls its destructor when readed `value` goes out of scope. It + /// can cause double dropping when [`RawTable`] goes out of scope, + /// because of not erased `data control byte`. + /// + /// [`ptr::read`]: https://doc.rust-lang.org/core/ptr/fn.read.html + /// [`RawTable`]: crate::raw::RawTable + /// [`RawTable::remove`]: crate::raw::RawTable::remove #[inline] - pub unsafe fn read(&self) -> T { + pub(crate) unsafe fn read(&self) -> T { self.as_ptr().read() } + + /// Overwrites a memory location with the given `value` without reading + /// or dropping the old value (like [`ptr::write`] function). + /// + /// # Safety + /// + /// See [`ptr::write`] for safety concerns. + /// + /// # Note + /// + /// [`Hash`] and [`Eq`] on the new `T` value and its borrowed form *must* match + /// those for the old `T` value, as the map will not re-evaluate where the new + /// value should go, meaning the value may become "lost" if their location + /// does not reflect their state. + /// + /// [`ptr::write`]: https://doc.rust-lang.org/core/ptr/fn.write.html + /// [`Hash`]: https://doc.rust-lang.org/core/hash/trait.Hash.html + /// [`Eq`]: https://doc.rust-lang.org/core/cmp/trait.Eq.html #[inline] - pub unsafe fn write(&self, val: T) { + pub(crate) unsafe fn write(&self, val: T) { self.as_ptr().write(val); } + + /// Returns a shared immutable reference to the `value`. + /// + /// # Safety + /// + /// See [`NonNull::as_ref`] for safety concerns. + /// + /// [`NonNull::as_ref`]: https://doc.rust-lang.org/core/ptr/struct.NonNull.html#method.as_ref + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "raw")] + /// # fn test() { + /// use core::hash::{BuildHasher, Hash}; + /// use hashbrown::raw::{Bucket, RawTable}; + /// + /// type NewHashBuilder = core::hash::BuildHasherDefault; + /// + /// fn make_hash(hash_builder: &S, key: &K) -> u64 { + /// use core::hash::Hasher; + /// let mut state = hash_builder.build_hasher(); + /// key.hash(&mut state); + /// state.finish() + /// } + /// + /// let hash_builder = NewHashBuilder::default(); + /// let mut table = RawTable::new(); + /// + /// let value: (&str, String) = ("A pony", "is a small horse".to_owned()); + /// let hash = make_hash(&hash_builder, &value.0); + /// + /// table.insert(hash, value.clone(), |val| make_hash(&hash_builder, &val.0)); + /// + /// let bucket: Bucket<(&str, String)> = table.find(hash, |(k, _)| k == &value.0).unwrap(); + /// + /// assert_eq!( + /// unsafe { bucket.as_ref() }, + /// &("A pony", "is a small horse".to_owned()) + /// ); + /// # } + /// # fn main() { + /// # #[cfg(feature = "raw")] + /// # test() + /// # } + /// ``` #[inline] pub unsafe fn as_ref<'a>(&self) -> &'a T { &*self.as_ptr() } + + /// Returns a unique mutable reference to the `value`. + /// + /// # Safety + /// + /// See [`NonNull::as_mut`] for safety concerns. + /// + /// # Note + /// + /// [`Hash`] and [`Eq`] on the new `T` value and its borrowed form *must* match + /// those for the old `T` value, as the map will not re-evaluate where the new + /// value should go, meaning the value may become "lost" if their location + /// does not reflect their state. + /// + /// [`NonNull::as_mut`]: https://doc.rust-lang.org/core/ptr/struct.NonNull.html#method.as_mut + /// [`Hash`]: https://doc.rust-lang.org/core/hash/trait.Hash.html + /// [`Eq`]: https://doc.rust-lang.org/core/cmp/trait.Eq.html + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "raw")] + /// # fn test() { + /// use core::hash::{BuildHasher, Hash}; + /// use hashbrown::raw::{Bucket, RawTable}; + /// + /// type NewHashBuilder = core::hash::BuildHasherDefault; + /// + /// fn make_hash(hash_builder: &S, key: &K) -> u64 { + /// use core::hash::Hasher; + /// let mut state = hash_builder.build_hasher(); + /// key.hash(&mut state); + /// state.finish() + /// } + /// + /// let hash_builder = NewHashBuilder::default(); + /// let mut table = RawTable::new(); + /// + /// let value: (&str, String) = ("A pony", "is a small horse".to_owned()); + /// let hash = make_hash(&hash_builder, &value.0); + /// + /// table.insert(hash, value.clone(), |val| make_hash(&hash_builder, &val.0)); + /// + /// let bucket: Bucket<(&str, String)> = table.find(hash, |(k, _)| k == &value.0).unwrap(); + /// + /// unsafe { + /// bucket + /// .as_mut() + /// .1 + /// .push_str(" less than 147 cm at the withers") + /// }; + /// assert_eq!( + /// unsafe { bucket.as_ref() }, + /// &( + /// "A pony", + /// "is a small horse less than 147 cm at the withers".to_owned() + /// ) + /// ); + /// # } + /// # fn main() { + /// # #[cfg(feature = "raw")] + /// # test() + /// # } + /// ``` #[inline] pub unsafe fn as_mut<'a>(&self) -> &'a mut T { &mut *self.as_ptr() } + + /// Copies `size_of` bytes from `other` to `self`. The source + /// and destination may *not* overlap. + /// + /// # Safety + /// + /// See [`ptr::copy_nonoverlapping`] for safety concerns. + /// + /// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of + /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values + /// in the region beginning at `*self` and the region beginning at `*other` can + /// [violate memory safety]. + /// + /// # Note + /// + /// [`Hash`] and [`Eq`] on the new `T` value and its borrowed form *must* match + /// those for the old `T` value, as the map will not re-evaluate where the new + /// value should go, meaning the value may become "lost" if their location + /// does not reflect their state. + /// + /// [`ptr::copy_nonoverlapping`]: https://doc.rust-lang.org/core/ptr/fn.copy_nonoverlapping.html + /// [`read`]: https://doc.rust-lang.org/core/ptr/fn.read.html + /// [violate memory safety]: https://doc.rust-lang.org/std/ptr/fn.read.html#ownership-of-the-returned-value + /// [`Hash`]: https://doc.rust-lang.org/core/hash/trait.Hash.html + /// [`Eq`]: https://doc.rust-lang.org/core/cmp/trait.Eq.html #[cfg(feature = "raw")] #[inline] pub unsafe fn copy_from_nonoverlapping(&self, other: &Self) { @@ -364,15 +785,16 @@ impl Bucket { } /// A raw hash table with an unsafe API. -pub struct RawTable { - table: RawTableInner, +pub struct RawTable { + table: RawTableInner, + alloc: A, // Tell dropck that we own instances of T. marker: PhantomData, } /// Non-generic part of `RawTable` which allows functions to be instantiated only once regardless /// of how many different key-value types are used. -struct RawTableInner { +struct RawTableInner { // Mask to get an index from a hash value. The value is one less than the // number of buckets in the table. bucket_mask: usize, @@ -386,8 +808,6 @@ struct RawTableInner { // Number of elements in the table, only really used by len() items: usize, - - alloc: A, } impl RawTable { @@ -399,7 +819,8 @@ impl RawTable { #[inline] pub const fn new() -> Self { Self { - table: RawTableInner::new_in(Global), + table: RawTableInner::NEW, + alloc: Global, marker: PhantomData, } } @@ -418,7 +839,9 @@ impl RawTable { } } -impl RawTable { +impl RawTable { + const TABLE_LAYOUT: TableLayout = TableLayout::new::(); + /// Creates a new empty hash table without allocating any memory, using the /// given allocator. /// @@ -426,9 +849,10 @@ impl RawTable { /// leave the data pointer dangling since that bucket is never written to /// due to our load factor forcing us to always have at least 1 free bucket. #[inline] - pub fn new_in(alloc: A) -> Self { + pub const fn new_in(alloc: A) -> Self { Self { - table: RawTableInner::new_in(alloc), + table: RawTableInner::NEW, + alloc, marker: PhantomData, } } @@ -446,73 +870,99 @@ impl RawTable { Ok(Self { table: RawTableInner::new_uninitialized( - alloc, - TableLayout::new::(), + &alloc, + Self::TABLE_LAYOUT, buckets, fallibility, )?, + alloc, marker: PhantomData, }) } - /// Attempts to allocate a new hash table with at least enough capacity - /// for inserting the given number of elements without reallocating. - fn fallible_with_capacity( - alloc: A, - capacity: usize, - fallibility: Fallibility, - ) -> Result { + /// Attempts to allocate a new hash table using the given allocator, with at least enough + /// capacity for inserting the given number of elements without reallocating. + #[cfg(feature = "raw")] + pub fn try_with_capacity_in(capacity: usize, alloc: A) -> Result { Ok(Self { table: RawTableInner::fallible_with_capacity( - alloc, - TableLayout::new::(), + &alloc, + Self::TABLE_LAYOUT, capacity, - fallibility, + Fallibility::Fallible, )?, + alloc, marker: PhantomData, }) } - /// Attempts to allocate a new hash table using the given allocator, with at least enough - /// capacity for inserting the given number of elements without reallocating. - #[cfg(feature = "raw")] - pub fn try_with_capacity_in(capacity: usize, alloc: A) -> Result { - Self::fallible_with_capacity(alloc, capacity, Fallibility::Fallible) - } - /// Allocates a new hash table using the given allocator, with at least enough capacity for /// inserting the given number of elements without reallocating. pub fn with_capacity_in(capacity: usize, alloc: A) -> Self { - // Avoid `Result::unwrap_or_else` because it bloats LLVM IR. - match Self::fallible_with_capacity(alloc, capacity, Fallibility::Infallible) { - Ok(capacity) => capacity, - Err(_) => unsafe { hint::unreachable_unchecked() }, + Self { + table: RawTableInner::with_capacity(&alloc, Self::TABLE_LAYOUT, capacity), + alloc, + marker: PhantomData, } } /// Returns a reference to the underlying allocator. #[inline] pub fn allocator(&self) -> &A { - &self.table.alloc + &self.alloc } - /// Deallocates the table without dropping any entries. - #[cfg_attr(feature = "inline-more", inline)] - unsafe fn free_buckets(&mut self) { - self.table.free_buckets(TableLayout::new::()); + /// Returns pointer to one past last `data` element in the the table as viewed from + /// the start point of the allocation. + /// + /// The caller must ensure that the `RawTable` outlives the returned [`NonNull`], + /// otherwise using it may result in [`undefined behavior`]. + /// + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + #[inline] + pub fn data_end(&self) -> NonNull { + // SAFETY: `self.table.ctrl` is `NonNull`, so casting it is safe + // + // `self.table.ctrl.as_ptr().cast()` returns pointer that + // points here (to the end of `T0`) + // ∨ + // [Pad], T_n, ..., T1, T0, |CT0, CT1, ..., CT_n|, CTa_0, CTa_1, ..., CTa_m + // \________ ________/ + // \/ + // `n = buckets - 1`, i.e. `RawTable::buckets() - 1` + // + // where: T0...T_n - our stored data; + // CT0...CT_n - control bytes or metadata for `data`. + // CTa_0...CTa_m - additional control bytes, where `m = Group::WIDTH - 1` (so that the search + // with loading `Group` bytes from the heap works properly, even if the result + // of `h1(hash) & self.bucket_mask` is equal to `self.bucket_mask`). See also + // `RawTableInner::set_ctrl` function. + // + // P.S. `h1(hash) & self.bucket_mask` is the same as `hash as usize % self.buckets()` because the number + // of buckets is a power of two, and `self.bucket_mask = self.buckets() - 1`. + unsafe { NonNull::new_unchecked(self.table.ctrl.as_ptr().cast()) } } - /// Returns pointer to one past last element of data table. + /// Returns pointer to start of data table. #[inline] - pub unsafe fn data_end(&self) -> NonNull { - NonNull::new_unchecked(self.table.ctrl.as_ptr().cast()) + #[cfg(any(feature = "raw", feature = "nightly"))] + pub unsafe fn data_start(&self) -> NonNull { + NonNull::new_unchecked(self.data_end().as_ptr().wrapping_sub(self.buckets())) } - /// Returns pointer to start of data table. + /// Return the information about memory allocated by the table. + /// + /// `RawTable` allocates single memory block to store both data and metadata. + /// This function returns allocation size and alignment and the beginning of the area. + /// These are the arguments which will be passed to `dealloc` when the table is dropped. + /// + /// This function might be useful for memory profiling. #[inline] - #[cfg(feature = "nightly")] - pub unsafe fn data_start(&self) -> *mut T { - self.data_end().as_ptr().wrapping_sub(self.buckets()) + #[cfg(feature = "raw")] + pub fn allocation_info(&self) -> (NonNull, Layout) { + // SAFETY: We use the same `table_layout` that was used to allocate + // this table. + unsafe { self.table.allocation_info_or_zero(Self::TABLE_LAYOUT) } } /// Returns the index of a bucket from a `Bucket`. @@ -522,8 +972,55 @@ impl RawTable { } /// Returns a pointer to an element in the table. + /// + /// The caller must ensure that the `RawTable` outlives the returned [`Bucket`], + /// otherwise using it may result in [`undefined behavior`]. + /// + /// # Safety + /// + /// If `mem::size_of::() != 0`, then the caller of this function must observe the + /// following safety rules: + /// + /// * The table must already be allocated; + /// + /// * The `index` must not be greater than the number returned by the [`RawTable::buckets`] + /// function, i.e. `(index + 1) <= self.buckets()`. + /// + /// It is safe to call this function with index of zero (`index == 0`) on a table that has + /// not been allocated, but using the returned [`Bucket`] results in [`undefined behavior`]. + /// + /// If `mem::size_of::() == 0`, then the only requirement is that the `index` must + /// not be greater than the number returned by the [`RawTable::buckets`] function, i.e. + /// `(index + 1) <= self.buckets()`. + /// + /// [`RawTable::buckets`]: RawTable::buckets + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[inline] pub unsafe fn bucket(&self, index: usize) -> Bucket { + // If mem::size_of::() != 0 then return a pointer to the `element` in the `data part` of the table + // (we start counting from "0", so that in the expression T[n], the "n" index actually one less than + // the "buckets" number of our `RawTable`, i.e. "n = RawTable::buckets() - 1"): + // + // `table.bucket(3).as_ptr()` returns a pointer that points here in the `data` + // part of the `RawTable`, i.e. to the start of T3 (see `Bucket::as_ptr`) + // | + // | `base = self.data_end()` points here + // | (to the start of CT0 or to the end of T0) + // v v + // [Pad], T_n, ..., |T3|, T2, T1, T0, |CT0, CT1, CT2, CT3, ..., CT_n, CTa_0, CTa_1, ..., CTa_m + // ^ \__________ __________/ + // `table.bucket(3)` returns a pointer that points \/ + // here in the `data` part of the `RawTable` (to additional control bytes + // the end of T3) `m = Group::WIDTH - 1` + // + // where: T0...T_n - our stored data; + // CT0...CT_n - control bytes or metadata for `data`; + // CTa_0...CTa_m - additional control bytes (so that the search with loading `Group` bytes from + // the heap works properly, even if the result of `h1(hash) & self.table.bucket_mask` + // is equal to `self.table.bucket_mask`). See also `RawTableInner::set_ctrl` function. + // + // P.S. `h1(hash) & self.table.bucket_mask` is the same as `hash as usize % self.buckets()` because the number + // of buckets is a power of two, and `self.table.bucket_mask = self.buckets() - 1`. debug_assert_ne!(self.table.bucket_mask, 0); debug_assert!(index < self.buckets()); Bucket::from_base_index(self.data_end(), index) @@ -531,8 +1028,7 @@ impl RawTable { /// Erases an element from the table without dropping it. #[cfg_attr(feature = "inline-more", inline)] - #[deprecated(since = "0.8.1", note = "use erase or remove instead")] - pub unsafe fn erase_no_drop(&mut self, item: &Bucket) { + unsafe fn erase_no_drop(&mut self, item: &Bucket) { let index = self.bucket_index(item); self.table.erase(index); } @@ -540,7 +1036,6 @@ impl RawTable { /// Erases an element from the table, dropping it in place. #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::needless_pass_by_value)] - #[allow(deprecated)] pub unsafe fn erase(&mut self, item: Bucket) { // Erase the element from the table first since drop might panic. self.erase_no_drop(&item); @@ -564,12 +1059,18 @@ impl RawTable { } /// Removes an element from the table, returning it. + /// + /// This also returns an `InsertSlot` pointing to the newly free bucket. #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::needless_pass_by_value)] - #[allow(deprecated)] - pub unsafe fn remove(&mut self, item: Bucket) -> T { + pub unsafe fn remove(&mut self, item: Bucket) -> (T, InsertSlot) { self.erase_no_drop(&item); - item.read() + ( + item.read(), + InsertSlot { + index: self.bucket_index(&item), + }, + ) } /// Finds and removes an element from the table, returning it. @@ -577,7 +1078,7 @@ impl RawTable { pub fn remove_entry(&mut self, hash: u64, eq: impl FnMut(&T) -> bool) -> Option { // Avoid `Option::map` because it bloats LLVM IR. match self.find(hash, eq) { - Some(bucket) => Some(unsafe { self.remove(bucket) }), + Some(bucket) => Some(unsafe { self.remove(bucket).0 }), None => None, } } @@ -591,18 +1092,17 @@ impl RawTable { /// Removes all elements from the table without freeing the backing memory. #[cfg_attr(feature = "inline-more", inline)] pub fn clear(&mut self) { + if self.is_empty() { + // Special case empty table to avoid surprising O(capacity) time. + return; + } // Ensure that the table is reset even if one of the drops panic let mut self_ = guard(self, |self_| self_.clear_no_drop()); unsafe { - self_.drop_elements(); - } - } - - unsafe fn drop_elements(&mut self) { - if mem::needs_drop::() && !self.is_empty() { - for item in self.iter() { - item.drop(); - } + // SAFETY: ScopeGuard sets to zero the `items` field of the table + // even in case of panic during the dropping of the elements so + // that there will be no double drop of the elements. + self_.table.drop_elements::(); } } @@ -613,7 +1113,16 @@ impl RawTable { // space for. let min_size = usize::max(self.table.items, min_size); if min_size == 0 { - *self = Self::new_in(self.table.alloc.clone()); + let mut old_inner = mem::replace(&mut self.table, RawTableInner::NEW); + unsafe { + // SAFETY: + // 1. We call the function only once; + // 2. We know for sure that `alloc` and `table_layout` matches the [`Allocator`] + // and [`TableLayout`] that were used to allocate this table. + // 3. If any elements' drop function panics, then there will only be a memory leak, + // because we have replaced the inner table with a new one. + old_inner.drop_inner_table::(&self.alloc, Self::TABLE_LAYOUT); + } return; } @@ -630,14 +1139,33 @@ impl RawTable { if min_buckets < self.buckets() { // Fast path if the table is empty if self.table.items == 0 { - *self = Self::with_capacity_in(min_size, self.table.alloc.clone()); + let new_inner = + RawTableInner::with_capacity(&self.alloc, Self::TABLE_LAYOUT, min_size); + let mut old_inner = mem::replace(&mut self.table, new_inner); + unsafe { + // SAFETY: + // 1. We call the function only once; + // 2. We know for sure that `alloc` and `table_layout` matches the [`Allocator`] + // and [`TableLayout`] that were used to allocate this table. + // 3. If any elements' drop function panics, then there will only be a memory leak, + // because we have replaced the inner table with a new one. + old_inner.drop_inner_table::(&self.alloc, Self::TABLE_LAYOUT); + } } else { // Avoid `Result::unwrap_or_else` because it bloats LLVM IR. - if self - .resize(min_size, hasher, Fallibility::Infallible) - .is_err() - { - unsafe { hint::unreachable_unchecked() } + unsafe { + // SAFETY: + // 1. We know for sure that `min_size >= self.table.items`. + // 2. The [`RawTableInner`] must already have properly initialized control bytes since + // we will never expose RawTable::new_uninitialized in a public API. + if self + .resize(min_size, hasher, Fallibility::Infallible) + .is_err() + { + // SAFETY: The result of calling the `resize` function cannot be an error + // because `fallibility == Fallibility::Infallible. + hint::unreachable_unchecked() + } } } } @@ -647,13 +1175,18 @@ impl RawTable { /// without reallocation. #[cfg_attr(feature = "inline-more", inline)] pub fn reserve(&mut self, additional: usize, hasher: impl Fn(&T) -> u64) { - if additional > self.table.growth_left { + if unlikely(additional > self.table.growth_left) { // Avoid `Result::unwrap_or_else` because it bloats LLVM IR. - if self - .reserve_rehash(additional, hasher, Fallibility::Infallible) - .is_err() - { - unsafe { hint::unreachable_unchecked() } + unsafe { + // SAFETY: The [`RawTableInner`] must already have properly initialized control + // bytes since we will never expose RawTable::new_uninitialized in a public API. + if self + .reserve_rehash(additional, hasher, Fallibility::Infallible) + .is_err() + { + // SAFETY: All allocation errors will be caught inside `RawTableInner::reserve_rehash`. + hint::unreachable_unchecked() + } } } } @@ -667,28 +1200,45 @@ impl RawTable { hasher: impl Fn(&T) -> u64, ) -> Result<(), TryReserveError> { if additional > self.table.growth_left { - self.reserve_rehash(additional, hasher, Fallibility::Fallible) + // SAFETY: The [`RawTableInner`] must already have properly initialized control + // bytes since we will never expose RawTable::new_uninitialized in a public API. + unsafe { self.reserve_rehash(additional, hasher, Fallibility::Fallible) } } else { Ok(()) } } /// Out-of-line slow path for `reserve` and `try_reserve`. + /// + /// # Safety + /// + /// The [`RawTableInner`] must have properly initialized control bytes, + /// otherwise calling this function results in [`undefined behavior`] + /// + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[cold] #[inline(never)] - fn reserve_rehash( + unsafe fn reserve_rehash( &mut self, additional: usize, hasher: impl Fn(&T) -> u64, fallibility: Fallibility, ) -> Result<(), TryReserveError> { unsafe { + // SAFETY: + // 1. We know for sure that `alloc` and `layout` matches the [`Allocator`] and + // [`TableLayout`] that were used to allocate this table. + // 2. The `drop` function is the actual drop function of the elements stored in + // the table. + // 3. The caller ensures that the control bytes of the `RawTableInner` + // are already initialized. self.table.reserve_rehash_inner( + &self.alloc, additional, &|table, index| hasher(table.bucket::(index).as_ref()), fallibility, - TableLayout::new::(), - if mem::needs_drop::() { + Self::TABLE_LAYOUT, + if T::NEEDS_DROP { Some(mem::transmute(ptr::drop_in_place:: as unsafe fn(*mut T))) } else { None @@ -699,20 +1249,50 @@ impl RawTable { /// Allocates a new table of a different size and moves the contents of the /// current table into it. - fn resize( + /// + /// # Safety + /// + /// The [`RawTableInner`] must have properly initialized control bytes, + /// otherwise calling this function results in [`undefined behavior`] + /// + /// The caller of this function must ensure that `capacity >= self.table.items` + /// otherwise: + /// + /// * If `self.table.items != 0`, calling of this function with `capacity` + /// equal to 0 (`capacity == 0`) results in [`undefined behavior`]. + /// + /// * If `capacity_to_buckets(capacity) < Group::WIDTH` and + /// `self.table.items > capacity_to_buckets(capacity)` + /// calling this function results in [`undefined behavior`]. + /// + /// * If `capacity_to_buckets(capacity) >= Group::WIDTH` and + /// `self.table.items > capacity_to_buckets(capacity)` + /// calling this function are never return (will go into an + /// infinite loop). + /// + /// See [`RawTableInner::find_insert_slot`] for more information. + /// + /// [`RawTableInner::find_insert_slot`]: RawTableInner::find_insert_slot + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + unsafe fn resize( &mut self, capacity: usize, hasher: impl Fn(&T) -> u64, fallibility: Fallibility, ) -> Result<(), TryReserveError> { - unsafe { - self.table.resize_inner( - capacity, - &|table, index| hasher(table.bucket::(index).as_ref()), - fallibility, - TableLayout::new::(), - ) - } + // SAFETY: + // 1. The caller of this function guarantees that `capacity >= self.table.items`. + // 2. We know for sure that `alloc` and `layout` matches the [`Allocator`] and + // [`TableLayout`] that were used to allocate this table. + // 3. The caller ensures that the control bytes of the `RawTableInner` + // are already initialized. + self.table.resize_inner( + &self.alloc, + capacity, + &|table, index| hasher(table.bucket::(index).as_ref()), + fallibility, + Self::TABLE_LAYOUT, + ) } /// Inserts a new element into the table, and returns its raw bucket. @@ -721,22 +1301,27 @@ impl RawTable { #[cfg_attr(feature = "inline-more", inline)] pub fn insert(&mut self, hash: u64, value: T, hasher: impl Fn(&T) -> u64) -> Bucket { unsafe { - let mut index = self.table.find_insert_slot(hash); + // SAFETY: + // 1. The [`RawTableInner`] must already have properly initialized control bytes since + // we will never expose `RawTable::new_uninitialized` in a public API. + // + // 2. We reserve additional space (if necessary) right after calling this function. + let mut slot = self.table.find_insert_slot(hash); - // We can avoid growing the table once we have reached our load - // factor if we are replacing a tombstone. This works since the - // number of EMPTY slots does not change in this case. - let old_ctrl = *self.table.ctrl(index); + // We can avoid growing the table once we have reached our load factor if we are replacing + // a tombstone. This works since the number of EMPTY slots does not change in this case. + // + // SAFETY: The function is guaranteed to return [`InsertSlot`] that contains an index + // in the range `0..=self.buckets()`. + let old_ctrl = *self.table.ctrl(slot.index); if unlikely(self.table.growth_left == 0 && special_is_empty(old_ctrl)) { self.reserve(1, hasher); - index = self.table.find_insert_slot(hash); + // SAFETY: We know for sure that `RawTableInner` has control bytes + // initialized and that there is extra space in the table. + slot = self.table.find_insert_slot(hash); } - self.table.record_item_insert_at(index, old_ctrl, hash); - - let bucket = self.bucket(index); - bucket.write(value); - bucket + self.insert_in_slot(hash, slot, value) } } @@ -802,9 +1387,9 @@ impl RawTable { { let index = self.bucket_index(&bucket); let old_ctrl = *self.table.ctrl(index); - debug_assert!(is_full(old_ctrl)); + debug_assert!(self.is_bucket_full(index)); let old_growth_left = self.table.growth_left; - let item = self.remove(bucket); + let item = self.remove(bucket).0; if let Some(new_item) = f(item) { self.table.growth_left = old_growth_left; self.table.set_ctrl(index, old_ctrl); @@ -816,17 +1401,78 @@ impl RawTable { } } + /// Searches for an element in the table. If the element is not found, + /// returns `Err` with the position of a slot where an element with the + /// same hash could be inserted. + /// + /// This function may resize the table if additional space is required for + /// inserting an element. + #[inline] + pub fn find_or_find_insert_slot( + &mut self, + hash: u64, + mut eq: impl FnMut(&T) -> bool, + hasher: impl Fn(&T) -> u64, + ) -> Result, InsertSlot> { + self.reserve(1, hasher); + + unsafe { + // SAFETY: + // 1. We know for sure that there is at least one empty `bucket` in the table. + // 2. The [`RawTableInner`] must already have properly initialized control bytes since we will + // never expose `RawTable::new_uninitialized` in a public API. + // 3. The `find_or_find_insert_slot_inner` function returns the `index` of only the full bucket, + // which is in the range `0..self.buckets()` (since there is at least one empty `bucket` in + // the table), so calling `self.bucket(index)` and `Bucket::as_ref` is safe. + match self + .table + .find_or_find_insert_slot_inner(hash, &mut |index| eq(self.bucket(index).as_ref())) + { + // SAFETY: See explanation above. + Ok(index) => Ok(self.bucket(index)), + Err(slot) => Err(slot), + } + } + } + + /// Inserts a new element into the table in the given slot, and returns its + /// raw bucket. + /// + /// # Safety + /// + /// `slot` must point to a slot previously returned by + /// `find_or_find_insert_slot`, and no mutation of the table must have + /// occurred since that call. + #[inline] + pub unsafe fn insert_in_slot(&mut self, hash: u64, slot: InsertSlot, value: T) -> Bucket { + let old_ctrl = *self.table.ctrl(slot.index); + self.table.record_item_insert_at(slot.index, old_ctrl, hash); + + let bucket = self.bucket(slot.index); + bucket.write(value); + bucket + } + /// Searches for an element in the table. #[inline] pub fn find(&self, hash: u64, mut eq: impl FnMut(&T) -> bool) -> Option> { - let result = self.table.find_inner(hash, &mut |index| unsafe { - eq(self.bucket(index).as_ref()) - }); - - // Avoid `Option::map` because it bloats LLVM IR. - match result { - Some(index) => Some(unsafe { self.bucket(index) }), - None => None, + unsafe { + // SAFETY: + // 1. The [`RawTableInner`] must already have properly initialized control bytes since we + // will never expose `RawTable::new_uninitialized` in a public API. + // 1. The `find_inner` function returns the `index` of only the full bucket, which is in + // the range `0..self.buckets()`, so calling `self.bucket(index)` and `Bucket::as_ref` + // is safe. + let result = self + .table + .find_inner(hash, &mut |index| eq(self.bucket(index).as_ref())); + + // Avoid `Option::map` because it bloats LLVM IR. + match result { + // SAFETY: See explanation above. + Some(index) => Some(self.bucket(index)), + None => None, + } } } @@ -934,17 +1580,27 @@ impl RawTable { self.table.bucket_mask + 1 } + /// Checks whether the bucket at `index` is full. + /// + /// # Safety + /// + /// The caller must ensure `index` is less than the number of buckets. + #[inline] + pub unsafe fn is_bucket_full(&self, index: usize) -> bool { + self.table.is_bucket_full(index) + } + /// Returns an iterator over every element in the table. It is up to /// the caller to ensure that the `RawTable` outlives the `RawIter`. /// Because we cannot make the `next` method unsafe on the `RawIter` /// struct, we have to make the `iter` method unsafe. #[inline] pub unsafe fn iter(&self) -> RawIter { - let data = Bucket::from_base_index(self.data_end(), 0); - RawIter { - iter: RawIterRange::new(self.table.ctrl.as_ptr(), data, self.table.buckets()), - items: self.table.items, - } + // SAFETY: + // 1. The caller must uphold the safety contract for `iter` method. + // 2. The [`RawTableInner`] must already have properly initialized control bytes since + // we will never expose RawTable::new_uninitialized in a public API. + self.table.iter() } /// Returns an iterator over occupied buckets that could match a given hash. @@ -958,7 +1614,7 @@ impl RawTable { /// `RawIterHash` struct, we have to make the `iter_hash` method unsafe. #[cfg_attr(feature = "inline-more", inline)] #[cfg(feature = "raw")] - pub unsafe fn iter_hash(&self, hash: u64) -> RawIterHash<'_, T, A> { + pub unsafe fn iter_hash(&self, hash: u64) -> RawIterHash { RawIterHash::new(self, hash) } @@ -984,8 +1640,8 @@ impl RawTable { debug_assert_eq!(iter.len(), self.len()); RawDrain { iter, - table: ManuallyDrop::new(mem::replace(self, Self::new_in(self.table.alloc.clone()))), - orig_table: NonNull::from(self), + table: mem::replace(&mut self.table, RawTableInner::NEW), + orig_table: NonNull::from(&mut self.table), marker: PhantomData, } } @@ -999,31 +1655,31 @@ impl RawTable { pub unsafe fn into_iter_from(self, iter: RawIter) -> RawIntoIter { debug_assert_eq!(iter.len(), self.len()); - let alloc = self.table.alloc.clone(); let allocation = self.into_allocation(); RawIntoIter { iter, allocation, marker: PhantomData, - alloc, } } /// Converts the table into a raw allocation. The contents of the table /// should be dropped using a `RawIter` before freeing the allocation. #[cfg_attr(feature = "inline-more", inline)] - pub(crate) fn into_allocation(self) -> Option<(NonNull, Layout)> { + pub(crate) fn into_allocation(self) -> Option<(NonNull, Layout, A)> { let alloc = if self.table.is_empty_singleton() { None } else { // Avoid `Option::unwrap_or_else` because it bloats LLVM IR. - let (layout, ctrl_offset) = match calculate_layout::(self.table.buckets()) { - Some(lco) => lco, - None => unsafe { hint::unreachable_unchecked() }, - }; + let (layout, ctrl_offset) = + match Self::TABLE_LAYOUT.calculate_layout_for(self.table.buckets()) { + Some(lco) => lco, + None => unsafe { hint::unreachable_unchecked() }, + }; Some(( unsafe { NonNull::new_unchecked(self.table.ctrl.as_ptr().sub(ctrl_offset)) }, layout, + unsafe { ptr::read(&self.alloc) }, )) }; mem::forget(self); @@ -1031,41 +1687,62 @@ impl RawTable { } } -unsafe impl Send for RawTable +unsafe impl Send for RawTable where T: Send, A: Send, { } -unsafe impl Sync for RawTable +unsafe impl Sync for RawTable where T: Sync, A: Sync, { } -impl RawTableInner { +impl RawTableInner { + const NEW: Self = RawTableInner::new(); + + /// Creates a new empty hash table without allocating any memory. + /// + /// In effect this returns a table with exactly 1 bucket. However we can + /// leave the data pointer dangling since that bucket is never accessed + /// due to our load factor forcing us to always have at least 1 free bucket. #[inline] - const fn new_in(alloc: A) -> Self { + const fn new() -> Self { Self { // Be careful to cast the entire slice to a raw pointer. ctrl: unsafe { NonNull::new_unchecked(Group::static_empty() as *const _ as *mut u8) }, bucket_mask: 0, items: 0, growth_left: 0, - alloc, } } } -impl RawTableInner { +impl RawTableInner { + /// Allocates a new [`RawTableInner`] with the given number of buckets. + /// The control bytes and buckets are left uninitialized. + /// + /// # Safety + /// + /// The caller of this function must ensure that the `buckets` is power of two + /// and also initialize all control bytes of the length `self.bucket_mask + 1 + + /// Group::WIDTH` with the [`EMPTY`] bytes. + /// + /// See also [`Allocator`] API for other safety concerns. + /// + /// [`Allocator`]: https://doc.rust-lang.org/alloc/alloc/trait.Allocator.html #[cfg_attr(feature = "inline-more", inline)] - unsafe fn new_uninitialized( - alloc: A, + unsafe fn new_uninitialized( + alloc: &A, table_layout: TableLayout, buckets: usize, fallibility: Fallibility, - ) -> Result { + ) -> Result + where + A: Allocator, + { debug_assert!(buckets.is_power_of_two()); // Avoid `Option::ok_or_else` because it bloats LLVM IR. @@ -1074,45 +1751,48 @@ impl RawTableInner { None => return Err(fallibility.capacity_overflow()), }; - // We need an additional check to ensure that the allocation doesn't - // exceed `isize::MAX`. We can skip this check on 64-bit systems since - // such allocations will never succeed anyways. - // - // This mirrors what Vec does in the standard library. - if mem::size_of::() < 8 && layout.size() > isize::MAX as usize { - return Err(fallibility.capacity_overflow()); - } - - let ptr: NonNull = match do_alloc(&alloc, layout) { + let ptr: NonNull = match do_alloc(alloc, layout) { Ok(block) => block.cast(), Err(_) => return Err(fallibility.alloc_err(layout)), }; + // SAFETY: null pointer will be caught in above check let ctrl = NonNull::new_unchecked(ptr.as_ptr().add(ctrl_offset)); Ok(Self { ctrl, bucket_mask: buckets - 1, items: 0, growth_left: bucket_mask_to_capacity(buckets - 1), - alloc, }) } + /// Attempts to allocate a new [`RawTableInner`] with at least enough + /// capacity for inserting the given number of elements without reallocating. + /// + /// All the control bytes are initialized with the [`EMPTY`] bytes. #[inline] - fn fallible_with_capacity( - alloc: A, + fn fallible_with_capacity( + alloc: &A, table_layout: TableLayout, capacity: usize, fallibility: Fallibility, - ) -> Result { + ) -> Result + where + A: Allocator, + { if capacity == 0 { - Ok(Self::new_in(alloc)) + Ok(Self::NEW) } else { + // SAFETY: We checked that we could successfully allocate the new table, and then + // initialized all control bytes with the constant `EMPTY` byte. unsafe { let buckets = capacity_to_buckets(capacity).ok_or_else(|| fallibility.capacity_overflow())?; let result = Self::new_uninitialized(alloc, table_layout, buckets, fallibility)?; + // SAFETY: We checked that the table is allocated and therefore the table already has + // `self.bucket_mask + 1 + Group::WIDTH` number of control bytes (see TableLayout::calculate_layout_for) + // so writing `self.num_ctrl_bytes() == bucket_mask + 1 + Group::WIDTH` bytes is safe. result.ctrl(0).write_bytes(EMPTY, result.num_ctrl_bytes()); Ok(result) @@ -1120,66 +1800,397 @@ impl RawTableInner { } } - /// Searches for an empty or deleted bucket which is suitable for inserting - /// a new element and sets the hash for that slot. + /// Allocates a new [`RawTableInner`] with at least enough capacity for inserting + /// the given number of elements without reallocating. + /// + /// Panics if the new capacity exceeds [`isize::MAX`] bytes and [`abort`] the program + /// in case of allocation error. Use [`fallible_with_capacity`] instead if you want to + /// handle memory allocation failure. + /// + /// All the control bytes are initialized with the [`EMPTY`] bytes. + /// + /// [`fallible_with_capacity`]: RawTableInner::fallible_with_capacity + /// [`abort`]: https://doc.rust-lang.org/alloc/alloc/fn.handle_alloc_error.html + fn with_capacity(alloc: &A, table_layout: TableLayout, capacity: usize) -> Self + where + A: Allocator, + { + // Avoid `Result::unwrap_or_else` because it bloats LLVM IR. + match Self::fallible_with_capacity(alloc, table_layout, capacity, Fallibility::Infallible) { + Ok(table_inner) => table_inner, + // SAFETY: All allocation errors will be caught inside `RawTableInner::new_uninitialized`. + Err(_) => unsafe { hint::unreachable_unchecked() }, + } + } + + /// Fixes up an insertion slot returned by the [`RawTableInner::find_insert_slot_in_group`] method. + /// + /// In tables smaller than the group width (`self.buckets() < Group::WIDTH`), trailing control + /// bytes outside the range of the table are filled with [`EMPTY`] entries. These will unfortunately + /// trigger a match of [`RawTableInner::find_insert_slot_in_group`] function. This is because + /// the `Some(bit)` returned by `group.match_empty_or_deleted().lowest_set_bit()` after masking + /// (`(probe_seq.pos + bit) & self.bucket_mask`) may point to a full bucket that is already occupied. + /// We detect this situation here and perform a second scan starting at the beginning of the table. + /// This second scan is guaranteed to find an empty slot (due to the load factor) before hitting the + /// trailing control bytes (containing [`EMPTY`] bytes). + /// + /// If this function is called correctly, it is guaranteed to return [`InsertSlot`] with an + /// index of an empty or deleted bucket in the range `0..self.buckets()` (see `Warning` and + /// `Safety`). + /// + /// # Warning + /// + /// The table must have at least 1 empty or deleted `bucket`, otherwise if the table is less than + /// the group width (`self.buckets() < Group::WIDTH`) this function returns an index outside of the + /// table indices range `0..self.buckets()` (`0..=self.bucket_mask`). Attempt to write data at that + /// index will cause immediate [`undefined behavior`]. + /// + /// # Safety + /// + /// The safety rules are directly derived from the safety rules for [`RawTableInner::ctrl`] method. + /// Thus, in order to uphold those safety contracts, as well as for the correct logic of the work + /// of this crate, the following rules are necessary and sufficient: + /// + /// * The [`RawTableInner`] must have properly initialized control bytes otherwise calling this + /// function results in [`undefined behavior`]. + /// + /// * This function must only be used on insertion slots found by [`RawTableInner::find_insert_slot_in_group`] + /// (after the `find_insert_slot_in_group` function, but before insertion into the table). + /// + /// * The `index` must not be greater than the `self.bucket_mask`, i.e. `(index + 1) <= self.buckets()` + /// (this one is provided by the [`RawTableInner::find_insert_slot_in_group`] function). + /// + /// Calling this function with an index not provided by [`RawTableInner::find_insert_slot_in_group`] + /// may result in [`undefined behavior`] even if the index satisfies the safety rules of the + /// [`RawTableInner::ctrl`] function (`index < self.bucket_mask + 1 + Group::WIDTH`). + /// + /// [`RawTableInner::ctrl`]: RawTableInner::ctrl + /// [`RawTableInner::find_insert_slot_in_group`]: RawTableInner::find_insert_slot_in_group + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + #[inline] + unsafe fn fix_insert_slot(&self, mut index: usize) -> InsertSlot { + // SAFETY: The caller of this function ensures that `index` is in the range `0..=self.bucket_mask`. + if unlikely(self.is_bucket_full(index)) { + debug_assert!(self.bucket_mask < Group::WIDTH); + // SAFETY: + // + // * Since the caller of this function ensures that the control bytes are properly + // initialized and `ptr = self.ctrl(0)` points to the start of the array of control + // bytes, therefore: `ctrl` is valid for reads, properly aligned to `Group::WIDTH` + // and points to the properly initialized control bytes (see also + // `TableLayout::calculate_layout_for` and `ptr::read`); + // + // * Because the caller of this function ensures that the index was provided by the + // `self.find_insert_slot_in_group()` function, so for for tables larger than the + // group width (self.buckets() >= Group::WIDTH), we will never end up in the given + // branch, since `(probe_seq.pos + bit) & self.bucket_mask` in `find_insert_slot_in_group` + // cannot return a full bucket index. For tables smaller than the group width, calling + // the `unwrap_unchecked` function is also safe, as the trailing control bytes outside + // the range of the table are filled with EMPTY bytes (and we know for sure that there + // is at least one FULL bucket), so this second scan either finds an empty slot (due to + // the load factor) or hits the trailing control bytes (containing EMPTY). + index = Group::load_aligned(self.ctrl(0)) + .match_empty_or_deleted() + .lowest_set_bit() + .unwrap_unchecked(); + } + InsertSlot { index } + } + + /// Finds the position to insert something in a group. + /// + /// **This may have false positives and must be fixed up with `fix_insert_slot` + /// before it's used.** + /// + /// The function is guaranteed to return the index of an empty or deleted [`Bucket`] + /// in the range `0..self.buckets()` (`0..=self.bucket_mask`). + #[inline] + fn find_insert_slot_in_group(&self, group: &Group, probe_seq: &ProbeSeq) -> Option { + let bit = group.match_empty_or_deleted().lowest_set_bit(); + + if likely(bit.is_some()) { + // This is the same as `(probe_seq.pos + bit) % self.buckets()` because the number + // of buckets is a power of two, and `self.bucket_mask = self.buckets() - 1`. + Some((probe_seq.pos + bit.unwrap()) & self.bucket_mask) + } else { + None + } + } + + /// Searches for an element in the table, or a potential slot where that element could + /// be inserted (an empty or deleted [`Bucket`] index). + /// + /// This uses dynamic dispatch to reduce the amount of code generated, but that is + /// eliminated by LLVM optimizations. + /// + /// This function does not make any changes to the `data` part of the table, or any + /// changes to the `items` or `growth_left` field of the table. + /// + /// The table must have at least 1 empty or deleted `bucket`, otherwise, if the + /// `eq: &mut dyn FnMut(usize) -> bool` function does not return `true`, this function + /// will never return (will go into an infinite loop) for tables larger than the group + /// width, or return an index outside of the table indices range if the table is less + /// than the group width. + /// + /// This function is guaranteed to provide the `eq: &mut dyn FnMut(usize) -> bool` + /// function with only `FULL` buckets' indices and return the `index` of the found + /// element (as `Ok(index)`). If the element is not found and there is at least 1 + /// empty or deleted [`Bucket`] in the table, the function is guaranteed to return + /// [InsertSlot] with an index in the range `0..self.buckets()`, but in any case, + /// if this function returns [`InsertSlot`], it will contain an index in the range + /// `0..=self.buckets()`. + /// + /// # Safety + /// + /// The [`RawTableInner`] must have properly initialized control bytes otherwise calling + /// this function results in [`undefined behavior`]. + /// + /// Attempt to write data at the [`InsertSlot`] returned by this function when the table is + /// less than the group width and if there was not at least one empty or deleted bucket in + /// the table will cause immediate [`undefined behavior`]. This is because in this case the + /// function will return `self.bucket_mask + 1` as an index due to the trailing [`EMPTY] + /// control bytes outside the table range. + /// + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + #[inline] + unsafe fn find_or_find_insert_slot_inner( + &self, + hash: u64, + eq: &mut dyn FnMut(usize) -> bool, + ) -> Result { + let mut insert_slot = None; + + let h2_hash = h2(hash); + let mut probe_seq = self.probe_seq(hash); + + loop { + // SAFETY: + // * Caller of this function ensures that the control bytes are properly initialized. + // + // * `ProbeSeq.pos` cannot be greater than `self.bucket_mask = self.buckets() - 1` + // of the table due to masking with `self.bucket_mask` and also because mumber of + // buckets is a power of two (see `self.probe_seq` function). + // + // * Even if `ProbeSeq.pos` returns `position == self.bucket_mask`, it is safe to + // call `Group::load` due to the extended control bytes range, which is + // `self.bucket_mask + 1 + Group::WIDTH` (in fact, this means that the last control + // byte will never be read for the allocated table); + // + // * Also, even if `RawTableInner` is not already allocated, `ProbeSeq.pos` will + // always return "0" (zero), so Group::load will read unaligned `Group::static_empty()` + // bytes, which is safe (see RawTableInner::new). + let group = unsafe { Group::load(self.ctrl(probe_seq.pos)) }; + + for bit in group.match_byte(h2_hash) { + let index = (probe_seq.pos + bit) & self.bucket_mask; + + if likely(eq(index)) { + return Ok(index); + } + } + + // We didn't find the element we were looking for in the group, try to get an + // insertion slot from the group if we don't have one yet. + if likely(insert_slot.is_none()) { + insert_slot = self.find_insert_slot_in_group(&group, &probe_seq); + } + + // Only stop the search if the group contains at least one empty element. + // Otherwise, the element that we are looking for might be in a following group. + if likely(group.match_empty().any_bit_set()) { + // We must have found a insert slot by now, since the current group contains at + // least one. For tables smaller than the group width, there will still be an + // empty element in the current (and only) group due to the load factor. + unsafe { + // SAFETY: + // * Caller of this function ensures that the control bytes are properly initialized. + // + // * We use this function with the slot / index found by `self.find_insert_slot_in_group` + return Err(self.fix_insert_slot(insert_slot.unwrap_unchecked())); + } + } + + probe_seq.move_next(self.bucket_mask); + } + } + + /// Searches for an empty or deleted bucket which is suitable for inserting a new + /// element and sets the hash for that slot. Returns an index of that slot and the + /// old control byte stored in the found index. + /// + /// This function does not check if the given element exists in the table. Also, + /// this function does not check if there is enough space in the table to insert + /// a new element. Caller of the funtion must make ensure that the table has at + /// least 1 empty or deleted `bucket`, otherwise this function will never return + /// (will go into an infinite loop) for tables larger than the group width, or + /// return an index outside of the table indices range if the table is less than + /// the group width. + /// + /// If there is at least 1 empty or deleted `bucket` in the table, the function is + /// guaranteed to return an `index` in the range `0..self.buckets()`, but in any case, + /// if this function returns an `index` it will be in the range `0..=self.buckets()`. + /// + /// This function does not make any changes to the `data` parts of the table, + /// or any changes to the the `items` or `growth_left` field of the table. + /// + /// # Safety + /// + /// The safety rules are directly derived from the safety rules for the + /// [`RawTableInner::set_ctrl_h2`] and [`RawTableInner::find_insert_slot`] methods. + /// Thus, in order to uphold the safety contracts for that methods, as well as for + /// the correct logic of the work of this crate, you must observe the following rules + /// when calling this function: + /// + /// * The [`RawTableInner`] has already been allocated and has properly initialized + /// control bytes otherwise calling this function results in [`undefined behavior`]. + /// + /// * The caller of this function must ensure that the "data" parts of the table + /// will have an entry in the returned index (matching the given hash) right + /// after calling this function. + /// + /// Attempt to write data at the `index` returned by this function when the table is + /// less than the group width and if there was not at least one empty or deleted bucket in + /// the table will cause immediate [`undefined behavior`]. This is because in this case the + /// function will return `self.bucket_mask + 1` as an index due to the trailing [`EMPTY] + /// control bytes outside the table range. + /// + /// The caller must independently increase the `items` field of the table, and also, + /// if the old control byte was [`EMPTY`], then decrease the table's `growth_left` + /// field, and do not change it if the old control byte was [`DELETED`]. /// - /// There must be at least 1 empty bucket in the table. + /// See also [`Bucket::as_ptr`] method, for more information about of properly removing + /// or saving `element` from / into the [`RawTable`] / [`RawTableInner`]. + /// + /// [`Bucket::as_ptr`]: Bucket::as_ptr + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + /// [`RawTableInner::ctrl`]: RawTableInner::ctrl + /// [`RawTableInner::set_ctrl_h2`]: RawTableInner::set_ctrl_h2 + /// [`RawTableInner::find_insert_slot`]: RawTableInner::find_insert_slot #[inline] - unsafe fn prepare_insert_slot(&self, hash: u64) -> (usize, u8) { - let index = self.find_insert_slot(hash); + unsafe fn prepare_insert_slot(&mut self, hash: u64) -> (usize, u8) { + // SAFETY: Caller of this function ensures that the control bytes are properly initialized. + let index: usize = self.find_insert_slot(hash).index; + // SAFETY: + // 1. The `find_insert_slot` function either returns an `index` less than or + // equal to `self.buckets() = self.bucket_mask + 1` of the table, or never + // returns if it cannot find an empty or deleted slot. + // 2. The caller of this function guarantees that the table has already been + // allocated let old_ctrl = *self.ctrl(index); self.set_ctrl_h2(index, hash); (index, old_ctrl) } /// Searches for an empty or deleted bucket which is suitable for inserting - /// a new element. + /// a new element, returning the `index` for the new [`Bucket`]. + /// + /// This function does not make any changes to the `data` part of the table, or any + /// changes to the `items` or `growth_left` field of the table. + /// + /// The table must have at least 1 empty or deleted `bucket`, otherwise this function + /// will never return (will go into an infinite loop) for tables larger than the group + /// width, or return an index outside of the table indices range if the table is less + /// than the group width. + /// + /// If there is at least 1 empty or deleted `bucket` in the table, the function is + /// guaranteed to return [`InsertSlot`] with an index in the range `0..self.buckets()`, + /// but in any case, if this function returns [`InsertSlot`], it will contain an index + /// in the range `0..=self.buckets()`. + /// + /// # Safety + /// + /// The [`RawTableInner`] must have properly initialized control bytes otherwise calling + /// this function results in [`undefined behavior`]. /// - /// There must be at least 1 empty bucket in the table. + /// Attempt to write data at the [`InsertSlot`] returned by this function when the table is + /// less than the group width and if there was not at least one empty or deleted bucket in + /// the table will cause immediate [`undefined behavior`]. This is because in this case the + /// function will return `self.bucket_mask + 1` as an index due to the trailing [`EMPTY] + /// control bytes outside the table range. + /// + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[inline] - fn find_insert_slot(&self, hash: u64) -> usize { + unsafe fn find_insert_slot(&self, hash: u64) -> InsertSlot { let mut probe_seq = self.probe_seq(hash); loop { - unsafe { - let group = Group::load(self.ctrl(probe_seq.pos)); - if let Some(bit) = group.match_empty_or_deleted().lowest_set_bit() { - let result = (probe_seq.pos + bit) & self.bucket_mask; - - // In tables smaller than the group width, trailing control - // bytes outside the range of the table are filled with - // EMPTY entries. These will unfortunately trigger a - // match, but once masked may point to a full bucket that - // is already occupied. We detect this situation here and - // perform a second scan starting at the beginning of the - // table. This second scan is guaranteed to find an empty - // slot (due to the load factor) before hitting the trailing - // control bytes (containing EMPTY). - if unlikely(is_full(*self.ctrl(result))) { - debug_assert!(self.bucket_mask < Group::WIDTH); - debug_assert_ne!(probe_seq.pos, 0); - return Group::load_aligned(self.ctrl(0)) - .match_empty_or_deleted() - .lowest_set_bit_nonzero(); - } + // SAFETY: + // * Caller of this function ensures that the control bytes are properly initialized. + // + // * `ProbeSeq.pos` cannot be greater than `self.bucket_mask = self.buckets() - 1` + // of the table due to masking with `self.bucket_mask` and also because mumber of + // buckets is a power of two (see `self.probe_seq` function). + // + // * Even if `ProbeSeq.pos` returns `position == self.bucket_mask`, it is safe to + // call `Group::load` due to the extended control bytes range, which is + // `self.bucket_mask + 1 + Group::WIDTH` (in fact, this means that the last control + // byte will never be read for the allocated table); + // + // * Also, even if `RawTableInner` is not already allocated, `ProbeSeq.pos` will + // always return "0" (zero), so Group::load will read unaligned `Group::static_empty()` + // bytes, which is safe (see RawTableInner::new). + let group = unsafe { Group::load(self.ctrl(probe_seq.pos)) }; - return result; + let index = self.find_insert_slot_in_group(&group, &probe_seq); + if likely(index.is_some()) { + // SAFETY: + // * Caller of this function ensures that the control bytes are properly initialized. + // + // * We use this function with the slot / index found by `self.find_insert_slot_in_group` + unsafe { + return self.fix_insert_slot(index.unwrap_unchecked()); } } probe_seq.move_next(self.bucket_mask); } } - /// Searches for an element in the table. This uses dynamic dispatch to reduce the amount of - /// code generated, but it is eliminated by LLVM optimizations. - #[inline] - fn find_inner(&self, hash: u64, eq: &mut dyn FnMut(usize) -> bool) -> Option { + /// Searches for an element in a table, returning the `index` of the found element. + /// This uses dynamic dispatch to reduce the amount of code generated, but it is + /// eliminated by LLVM optimizations. + /// + /// This function does not make any changes to the `data` part of the table, or any + /// changes to the `items` or `growth_left` field of the table. + /// + /// The table must have at least 1 empty `bucket`, otherwise, if the + /// `eq: &mut dyn FnMut(usize) -> bool` function does not return `true`, + /// this function will also never return (will go into an infinite loop). + /// + /// This function is guaranteed to provide the `eq: &mut dyn FnMut(usize) -> bool` + /// function with only `FULL` buckets' indices and return the `index` of the found + /// element as `Some(index)`, so the index will always be in the range + /// `0..self.buckets()`. + /// + /// # Safety + /// + /// The [`RawTableInner`] must have properly initialized control bytes otherwise calling + /// this function results in [`undefined behavior`]. + /// + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + #[inline(always)] + unsafe fn find_inner(&self, hash: u64, eq: &mut dyn FnMut(usize) -> bool) -> Option { let h2_hash = h2(hash); let mut probe_seq = self.probe_seq(hash); loop { + // SAFETY: + // * Caller of this function ensures that the control bytes are properly initialized. + // + // * `ProbeSeq.pos` cannot be greater than `self.bucket_mask = self.buckets() - 1` + // of the table due to masking with `self.bucket_mask`. + // + // * Even if `ProbeSeq.pos` returns `position == self.bucket_mask`, it is safe to + // call `Group::load` due to the extended control bytes range, which is + // `self.bucket_mask + 1 + Group::WIDTH` (in fact, this means that the last control + // byte will never be read for the allocated table); + // + // * Also, even if `RawTableInner` is not already allocated, `ProbeSeq.pos` will + // always return "0" (zero), so Group::load will read unaligned `Group::static_empty()` + // bytes, which is safe (see RawTableInner::new_in). let group = unsafe { Group::load(self.ctrl(probe_seq.pos)) }; for bit in group.match_byte(h2_hash) { + // This is the same as `(probe_seq.pos + bit) % self.buckets()` because the number + // of buckets is a power of two, and `self.bucket_mask = self.buckets() - 1`. let index = (probe_seq.pos + bit) & self.bucket_mask; if likely(eq(index)) { @@ -1195,12 +2206,52 @@ impl RawTableInner { } } + /// Prepares for rehashing data in place (that is, without allocating new memory). + /// Converts all full index `control bytes` to `DELETED` and all `DELETED` control + /// bytes to `EMPTY`, i.e. performs the following conversion: + /// + /// - `EMPTY` control bytes -> `EMPTY`; + /// - `DELETED` control bytes -> `EMPTY`; + /// - `FULL` control bytes -> `DELETED`. + /// + /// This function does not make any changes to the `data` parts of the table, + /// or any changes to the the `items` or `growth_left` field of the table. + /// + /// # Safety + /// + /// You must observe the following safety rules when calling this function: + /// + /// * The [`RawTableInner`] has already been allocated; + /// + /// * The caller of this function must convert the `DELETED` bytes back to `FULL` + /// bytes when re-inserting them into their ideal position (which was impossible + /// to do during the first insert due to tombstones). If the caller does not do + /// this, then calling this function may result in a memory leak. + /// + /// * The [`RawTableInner`] must have properly initialized control bytes otherwise + /// calling this function results in [`undefined behavior`]. + /// + /// Calling this function on a table that has not been allocated results in + /// [`undefined behavior`]. + /// + /// See also [`Bucket::as_ptr`] method, for more information about of properly removing + /// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`]. + /// + /// [`Bucket::as_ptr`]: Bucket::as_ptr + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[allow(clippy::mut_mut)] #[inline] unsafe fn prepare_rehash_in_place(&mut self) { - // Bulk convert all full control bytes to DELETED, and all DELETED - // control bytes to EMPTY. This effectively frees up all buckets - // containing a DELETED entry. + // Bulk convert all full control bytes to DELETED, and all DELETED control bytes to EMPTY. + // This effectively frees up all buckets containing a DELETED entry. + // + // SAFETY: + // 1. `i` is guaranteed to be within bounds since we are iterating from zero to `buckets - 1`; + // 2. Even if `i` will be `i == self.bucket_mask`, it is safe to call `Group::load_aligned` + // due to the extended control bytes range, which is `self.bucket_mask + 1 + Group::WIDTH`; + // 3. The caller of this function guarantees that [`RawTableInner`] has already been allocated; + // 4. We can use `Group::load_aligned` and `Group::store_aligned` here since we start from 0 + // and go to the end with a step equal to `Group::WIDTH` (see TableLayout::calculate_layout_for). for i in (0..self.buckets()).step_by(Group::WIDTH) { let group = Group::load_aligned(self.ctrl(i)); let group = group.convert_special_to_empty_and_full_to_deleted(); @@ -1209,15 +2260,245 @@ impl RawTableInner { // Fix up the trailing control bytes. See the comments in set_ctrl // for the handling of tables smaller than the group width. - if self.buckets() < Group::WIDTH { + // + // SAFETY: The caller of this function guarantees that [`RawTableInner`] + // has already been allocated + if unlikely(self.buckets() < Group::WIDTH) { + // SAFETY: We have `self.bucket_mask + 1 + Group::WIDTH` number of control bytes, + // so copying `self.buckets() == self.bucket_mask + 1` bytes with offset equal to + // `Group::WIDTH` is safe self.ctrl(0) .copy_to(self.ctrl(Group::WIDTH), self.buckets()); } else { + // SAFETY: We have `self.bucket_mask + 1 + Group::WIDTH` number of + // control bytes,so copying `Group::WIDTH` bytes with offset equal + // to `self.buckets() == self.bucket_mask + 1` is safe self.ctrl(0) .copy_to(self.ctrl(self.buckets()), Group::WIDTH); } } + /// Returns an iterator over every element in the table. + /// + /// # Safety + /// + /// If any of the following conditions are violated, the result + /// is [`undefined behavior`]: + /// + /// * The caller has to ensure that the `RawTableInner` outlives the + /// `RawIter`. Because we cannot make the `next` method unsafe on + /// the `RawIter` struct, we have to make the `iter` method unsafe. + /// + /// * The [`RawTableInner`] must have properly initialized control bytes. + /// + /// The type `T` must be the actual type of the elements stored in the table, + /// otherwise using the returned [`RawIter`] results in [`undefined behavior`]. + /// + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + #[inline] + unsafe fn iter(&self) -> RawIter { + // SAFETY: + // 1. Since the caller of this function ensures that the control bytes + // are properly initialized and `self.data_end()` points to the start + // of the array of control bytes, therefore: `ctrl` is valid for reads, + // properly aligned to `Group::WIDTH` and points to the properly initialized + // control bytes. + // 2. `data` bucket index in the table is equal to the `ctrl` index (i.e. + // equal to zero). + // 3. We pass the exact value of buckets of the table to the function. + // + // `ctrl` points here (to the start + // of the first control byte `CT0`) + // ∨ + // [Pad], T_n, ..., T1, T0, |CT0, CT1, ..., CT_n|, CTa_0, CTa_1, ..., CTa_m + // \________ ________/ + // \/ + // `n = buckets - 1`, i.e. `RawTableInner::buckets() - 1` + // + // where: T0...T_n - our stored data; + // CT0...CT_n - control bytes or metadata for `data`. + // CTa_0...CTa_m - additional control bytes, where `m = Group::WIDTH - 1` (so that the search + // with loading `Group` bytes from the heap works properly, even if the result + // of `h1(hash) & self.bucket_mask` is equal to `self.bucket_mask`). See also + // `RawTableInner::set_ctrl` function. + // + // P.S. `h1(hash) & self.bucket_mask` is the same as `hash as usize % self.buckets()` because the number + // of buckets is a power of two, and `self.bucket_mask = self.buckets() - 1`. + let data = Bucket::from_base_index(self.data_end(), 0); + RawIter { + // SAFETY: See explanation above + iter: RawIterRange::new(self.ctrl.as_ptr(), data, self.buckets()), + items: self.items, + } + } + + /// Executes the destructors (if any) of the values stored in the table. + /// + /// # Note + /// + /// This function does not erase the control bytes of the table and does + /// not make any changes to the `items` or `growth_left` fields of the + /// table. If necessary, the caller of this function must manually set + /// up these table fields, for example using the [`clear_no_drop`] function. + /// + /// Be careful during calling this function, because drop function of + /// the elements can panic, and this can leave table in an inconsistent + /// state. + /// + /// # Safety + /// + /// The type `T` must be the actual type of the elements stored in the table, + /// otherwise calling this function may result in [`undefined behavior`]. + /// + /// If `T` is a type that should be dropped and **the table is not empty**, + /// calling this function more than once results in [`undefined behavior`]. + /// + /// If `T` is not [`Copy`], attempting to use values stored in the table after + /// calling this function may result in [`undefined behavior`]. + /// + /// It is safe to call this function on a table that has not been allocated, + /// on a table with uninitialized control bytes, and on a table with no actual + /// data but with `Full` control bytes if `self.items == 0`. + /// + /// See also [`Bucket::drop`] / [`Bucket::as_ptr`] methods, for more information + /// about of properly removing or saving `element` from / into the [`RawTable`] / + /// [`RawTableInner`]. + /// + /// [`Bucket::drop`]: Bucket::drop + /// [`Bucket::as_ptr`]: Bucket::as_ptr + /// [`clear_no_drop`]: RawTableInner::clear_no_drop + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + unsafe fn drop_elements(&mut self) { + // Check that `self.items != 0`. Protects against the possibility + // of creating an iterator on an table with uninitialized control bytes. + if T::NEEDS_DROP && self.items != 0 { + // SAFETY: We know for sure that RawTableInner will outlive the + // returned `RawIter` iterator, and the caller of this function + // must uphold the safety contract for `drop_elements` method. + for item in self.iter::() { + // SAFETY: The caller must uphold the safety contract for + // `drop_elements` method. + item.drop(); + } + } + } + + /// Executes the destructors (if any) of the values stored in the table and than + /// deallocates the table. + /// + /// # Note + /// + /// Calling this function automatically makes invalid (dangling) all instances of + /// buckets ([`Bucket`]) and makes invalid (dangling) the `ctrl` field of the table. + /// + /// This function does not make any changes to the `bucket_mask`, `items` or `growth_left` + /// fields of the table. If necessary, the caller of this function must manually set + /// up these table fields. + /// + /// # Safety + /// + /// If any of the following conditions are violated, the result is [`undefined behavior`]: + /// + /// * Calling this function more than once; + /// + /// * The type `T` must be the actual type of the elements stored in the table. + /// + /// * The `alloc` must be the same [`Allocator`] as the `Allocator` that was used + /// to allocate this table. + /// + /// * The `table_layout` must be the same [`TableLayout`] as the `TableLayout` that + /// was used to allocate this table. + /// + /// The caller of this function should pay attention to the possibility of the + /// elements' drop function panicking, because this: + /// + /// * May leave the table in an inconsistent state; + /// + /// * Memory is never deallocated, so a memory leak may occur. + /// + /// Attempt to use the `ctrl` field of the table (dereference) after calling this + /// function results in [`undefined behavior`]. + /// + /// It is safe to call this function on a table that has not been allocated, + /// on a table with uninitialized control bytes, and on a table with no actual + /// data but with `Full` control bytes if `self.items == 0`. + /// + /// See also [`RawTableInner::drop_elements`] or [`RawTableInner::free_buckets`] + /// for more information. + /// + /// [`RawTableInner::drop_elements`]: RawTableInner::drop_elements + /// [`RawTableInner::free_buckets`]: RawTableInner::free_buckets + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + unsafe fn drop_inner_table(&mut self, alloc: &A, table_layout: TableLayout) { + if !self.is_empty_singleton() { + unsafe { + // SAFETY: The caller must uphold the safety contract for `drop_inner_table` method. + self.drop_elements::(); + // SAFETY: + // 1. We have checked that our table is allocated. + // 2. The caller must uphold the safety contract for `drop_inner_table` method. + self.free_buckets(alloc, table_layout); + } + } + } + + /// Returns a pointer to an element in the table (convenience for + /// `Bucket::from_base_index(self.data_end::(), index)`). + /// + /// The caller must ensure that the `RawTableInner` outlives the returned [`Bucket`], + /// otherwise using it may result in [`undefined behavior`]. + /// + /// # Safety + /// + /// If `mem::size_of::() != 0`, then the safety rules are directly derived from the + /// safety rules of the [`Bucket::from_base_index`] function. Therefore, when calling + /// this function, the following safety rules must be observed: + /// + /// * The table must already be allocated; + /// + /// * The `index` must not be greater than the number returned by the [`RawTableInner::buckets`] + /// function, i.e. `(index + 1) <= self.buckets()`. + /// + /// * The type `T` must be the actual type of the elements stored in the table, otherwise + /// using the returned [`Bucket`] may result in [`undefined behavior`]. + /// + /// It is safe to call this function with index of zero (`index == 0`) on a table that has + /// not been allocated, but using the returned [`Bucket`] results in [`undefined behavior`]. + /// + /// If `mem::size_of::() == 0`, then the only requirement is that the `index` must + /// not be greater than the number returned by the [`RawTable::buckets`] function, i.e. + /// `(index + 1) <= self.buckets()`. + /// + /// ```none + /// If mem::size_of::() != 0 then return a pointer to the `element` in the `data part` of the table + /// (we start counting from "0", so that in the expression T[n], the "n" index actually one less than + /// the "buckets" number of our `RawTableInner`, i.e. "n = RawTableInner::buckets() - 1"): + /// + /// `table.bucket(3).as_ptr()` returns a pointer that points here in the `data` + /// part of the `RawTableInner`, i.e. to the start of T3 (see [`Bucket::as_ptr`]) + /// | + /// | `base = table.data_end::()` points here + /// | (to the start of CT0 or to the end of T0) + /// v v + /// [Pad], T_n, ..., |T3|, T2, T1, T0, |CT0, CT1, CT2, CT3, ..., CT_n, CTa_0, CTa_1, ..., CTa_m + /// ^ \__________ __________/ + /// `table.bucket(3)` returns a pointer that points \/ + /// here in the `data` part of the `RawTableInner` additional control bytes + /// (to the end of T3) `m = Group::WIDTH - 1` + /// + /// where: T0...T_n - our stored data; + /// CT0...CT_n - control bytes or metadata for `data`; + /// CTa_0...CTa_m - additional control bytes (so that the search with loading `Group` bytes from + /// the heap works properly, even if the result of `h1(hash) & self.bucket_mask` + /// is equal to `self.bucket_mask`). See also `RawTableInner::set_ctrl` function. + /// + /// P.S. `h1(hash) & self.bucket_mask` is the same as `hash as usize % self.buckets()` because the number + /// of buckets is a power of two, and `self.bucket_mask = self.buckets() - 1`. + /// ``` + /// + /// [`Bucket::from_base_index`]: Bucket::from_base_index + /// [`RawTableInner::buckets`]: RawTableInner::buckets + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[inline] unsafe fn bucket(&self, index: usize) -> Bucket { debug_assert_ne!(self.bucket_mask, 0); @@ -1225,6 +2506,52 @@ impl RawTableInner { Bucket::from_base_index(self.data_end(), index) } + /// Returns a raw `*mut u8` pointer to the start of the `data` element in the table + /// (convenience for `self.data_end::().as_ptr().sub((index + 1) * size_of)`). + /// + /// The caller must ensure that the `RawTableInner` outlives the returned `*mut u8`, + /// otherwise using it may result in [`undefined behavior`]. + /// + /// # Safety + /// + /// If any of the following conditions are violated, the result is [`undefined behavior`]: + /// + /// * The table must already be allocated; + /// + /// * The `index` must not be greater than the number returned by the [`RawTableInner::buckets`] + /// function, i.e. `(index + 1) <= self.buckets()`; + /// + /// * The `size_of` must be equal to the size of the elements stored in the table; + /// + /// ```none + /// If mem::size_of::() != 0 then return a pointer to the `element` in the `data part` of the table + /// (we start counting from "0", so that in the expression T[n], the "n" index actually one less than + /// the "buckets" number of our `RawTableInner`, i.e. "n = RawTableInner::buckets() - 1"): + /// + /// `table.bucket_ptr(3, mem::size_of::())` returns a pointer that points here in the + /// `data` part of the `RawTableInner`, i.e. to the start of T3 + /// | + /// | `base = table.data_end::()` points here + /// | (to the start of CT0 or to the end of T0) + /// v v + /// [Pad], T_n, ..., |T3|, T2, T1, T0, |CT0, CT1, CT2, CT3, ..., CT_n, CTa_0, CTa_1, ..., CTa_m + /// \__________ __________/ + /// \/ + /// additional control bytes + /// `m = Group::WIDTH - 1` + /// + /// where: T0...T_n - our stored data; + /// CT0...CT_n - control bytes or metadata for `data`; + /// CTa_0...CTa_m - additional control bytes (so that the search with loading `Group` bytes from + /// the heap works properly, even if the result of `h1(hash) & self.bucket_mask` + /// is equal to `self.bucket_mask`). See also `RawTableInner::set_ctrl` function. + /// + /// P.S. `h1(hash) & self.bucket_mask` is the same as `hash as usize % self.buckets()` because the number + /// of buckets is a power of two, and `self.bucket_mask = self.buckets() - 1`. + /// ``` + /// + /// [`RawTableInner::buckets`]: RawTableInner::buckets + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[inline] unsafe fn bucket_ptr(&self, index: usize, size_of: usize) -> *mut u8 { debug_assert_ne!(self.bucket_mask, 0); @@ -1233,9 +2560,47 @@ impl RawTableInner { base.sub((index + 1) * size_of) } + /// Returns pointer to one past last `data` element in the the table as viewed from + /// the start point of the allocation (convenience for `self.ctrl.cast()`). + /// + /// This function actually returns a pointer to the end of the `data element` at + /// index "0" (zero). + /// + /// The caller must ensure that the `RawTableInner` outlives the returned [`NonNull`], + /// otherwise using it may result in [`undefined behavior`]. + /// + /// # Note + /// + /// The type `T` must be the actual type of the elements stored in the table, otherwise + /// using the returned [`NonNull`] may result in [`undefined behavior`]. + /// + /// ```none + /// `table.data_end::()` returns pointer that points here + /// (to the end of `T0`) + /// ∨ + /// [Pad], T_n, ..., T1, T0, |CT0, CT1, ..., CT_n|, CTa_0, CTa_1, ..., CTa_m + /// \________ ________/ + /// \/ + /// `n = buckets - 1`, i.e. `RawTableInner::buckets() - 1` + /// + /// where: T0...T_n - our stored data; + /// CT0...CT_n - control bytes or metadata for `data`. + /// CTa_0...CTa_m - additional control bytes, where `m = Group::WIDTH - 1` (so that the search + /// with loading `Group` bytes from the heap works properly, even if the result + /// of `h1(hash) & self.bucket_mask` is equal to `self.bucket_mask`). See also + /// `RawTableInner::set_ctrl` function. + /// + /// P.S. `h1(hash) & self.bucket_mask` is the same as `hash as usize % self.buckets()` because the number + /// of buckets is a power of two, and `self.bucket_mask = self.buckets() - 1`. + /// ``` + /// + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[inline] - unsafe fn data_end(&self) -> NonNull { - NonNull::new_unchecked(self.ctrl.as_ptr().cast()) + fn data_end(&self) -> NonNull { + unsafe { + // SAFETY: `self.ctrl` is `NonNull`, so casting it is safe + NonNull::new_unchecked(self.ctrl.as_ptr().cast()) + } } /// Returns an iterator-like object for a probe sequence on the table. @@ -1246,6 +2611,8 @@ impl RawTableInner { #[inline] fn probe_seq(&self, hash: u64) -> ProbeSeq { ProbeSeq { + // This is the same as `hash as usize % self.buckets()` because the number + // of buckets is a power of two, and `self.bucket_mask = self.buckets() - 1`. pos: h1(hash) & self.bucket_mask, stride: 0, } @@ -1256,7 +2623,7 @@ impl RawTableInner { #[cfg(feature = "raw")] #[inline] unsafe fn prepare_insert_no_grow(&mut self, hash: u64) -> Result { - let index = self.find_insert_slot(hash); + let index = self.find_insert_slot(hash).index; let old_ctrl = *self.ctrl(index); if unlikely(self.growth_left == 0 && special_is_empty(old_ctrl)) { Err(()) @@ -1268,7 +2635,7 @@ impl RawTableInner { #[inline] unsafe fn record_item_insert_at(&mut self, index: usize, old_ctrl: u8, hash: u64) { - self.growth_left -= special_is_empty(old_ctrl) as usize; + self.growth_left -= usize::from(special_is_empty(old_ctrl)); self.set_ctrl_h2(index, hash); self.items += 1; } @@ -1283,13 +2650,68 @@ impl RawTableInner { /// Sets a control byte to the hash, and possibly also the replicated control byte at /// the end of the array. + /// + /// This function does not make any changes to the `data` parts of the table, + /// or any changes to the the `items` or `growth_left` field of the table. + /// + /// # Safety + /// + /// The safety rules are directly derived from the safety rules for [`RawTableInner::set_ctrl`] + /// method. Thus, in order to uphold the safety contracts for the method, you must observe the + /// following rules when calling this function: + /// + /// * The [`RawTableInner`] has already been allocated; + /// + /// * The `index` must not be greater than the `RawTableInner.bucket_mask`, i.e. + /// `index <= RawTableInner.bucket_mask` or, in other words, `(index + 1)` must + /// be no greater than the number returned by the function [`RawTableInner::buckets`]. + /// + /// Calling this function on a table that has not been allocated results in [`undefined behavior`]. + /// + /// See also [`Bucket::as_ptr`] method, for more information about of properly removing + /// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`]. + /// + /// [`RawTableInner::set_ctrl`]: RawTableInner::set_ctrl + /// [`RawTableInner::buckets`]: RawTableInner::buckets + /// [`Bucket::as_ptr`]: Bucket::as_ptr + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[inline] - unsafe fn set_ctrl_h2(&self, index: usize, hash: u64) { + unsafe fn set_ctrl_h2(&mut self, index: usize, hash: u64) { + // SAFETY: The caller must uphold the safety rules for the [`RawTableInner::set_ctrl_h2`] self.set_ctrl(index, h2(hash)); } + /// Replaces the hash in the control byte at the given index with the provided one, + /// and possibly also replicates the new control byte at the end of the array of control + /// bytes, returning the old control byte. + /// + /// This function does not make any changes to the `data` parts of the table, + /// or any changes to the the `items` or `growth_left` field of the table. + /// + /// # Safety + /// + /// The safety rules are directly derived from the safety rules for [`RawTableInner::set_ctrl_h2`] + /// and [`RawTableInner::ctrl`] methods. Thus, in order to uphold the safety contracts for both + /// methods, you must observe the following rules when calling this function: + /// + /// * The [`RawTableInner`] has already been allocated; + /// + /// * The `index` must not be greater than the `RawTableInner.bucket_mask`, i.e. + /// `index <= RawTableInner.bucket_mask` or, in other words, `(index + 1)` must + /// be no greater than the number returned by the function [`RawTableInner::buckets`]. + /// + /// Calling this function on a table that has not been allocated results in [`undefined behavior`]. + /// + /// See also [`Bucket::as_ptr`] method, for more information about of properly removing + /// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`]. + /// + /// [`RawTableInner::set_ctrl_h2`]: RawTableInner::set_ctrl_h2 + /// [`RawTableInner::buckets`]: RawTableInner::buckets + /// [`Bucket::as_ptr`]: Bucket::as_ptr + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[inline] - unsafe fn replace_ctrl_h2(&self, index: usize, hash: u64) -> u8 { + unsafe fn replace_ctrl_h2(&mut self, index: usize, hash: u64) -> u8 { + // SAFETY: The caller must uphold the safety rules for the [`RawTableInner::replace_ctrl_h2`] let prev_ctrl = *self.ctrl(index); self.set_ctrl_h2(index, hash); prev_ctrl @@ -1297,10 +2719,35 @@ impl RawTableInner { /// Sets a control byte, and possibly also the replicated control byte at /// the end of the array. + /// + /// This function does not make any changes to the `data` parts of the table, + /// or any changes to the the `items` or `growth_left` field of the table. + /// + /// # Safety + /// + /// You must observe the following safety rules when calling this function: + /// + /// * The [`RawTableInner`] has already been allocated; + /// + /// * The `index` must not be greater than the `RawTableInner.bucket_mask`, i.e. + /// `index <= RawTableInner.bucket_mask` or, in other words, `(index + 1)` must + /// be no greater than the number returned by the function [`RawTableInner::buckets`]. + /// + /// Calling this function on a table that has not been allocated results in [`undefined behavior`]. + /// + /// See also [`Bucket::as_ptr`] method, for more information about of properly removing + /// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`]. + /// + /// [`RawTableInner::buckets`]: RawTableInner::buckets + /// [`Bucket::as_ptr`]: Bucket::as_ptr + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[inline] - unsafe fn set_ctrl(&self, index: usize, ctrl: u8) { + unsafe fn set_ctrl(&mut self, index: usize, ctrl: u8) { // Replicate the first Group::WIDTH control bytes at the end of - // the array without using a branch: + // the array without using a branch. If the tables smaller than + // the group width (self.buckets() < Group::WIDTH), + // `index2 = Group::WIDTH + index`, otherwise `index2` is: + // // - If index >= Group::WIDTH then index == index2. // - Otherwise index2 == self.bucket_mask + 1 + index. // @@ -1317,16 +2764,43 @@ impl RawTableInner { // --------------------------------------------- // | [A] | [B] | [EMPTY] | [EMPTY] | [A] | [B] | // --------------------------------------------- + + // This is the same as `(index.wrapping_sub(Group::WIDTH)) % self.buckets() + Group::WIDTH` + // because the number of buckets is a power of two, and `self.bucket_mask = self.buckets() - 1`. let index2 = ((index.wrapping_sub(Group::WIDTH)) & self.bucket_mask) + Group::WIDTH; + // SAFETY: The caller must uphold the safety rules for the [`RawTableInner::set_ctrl`] *self.ctrl(index) = ctrl; *self.ctrl(index2) = ctrl; } /// Returns a pointer to a control byte. + /// + /// # Safety + /// + /// For the allocated [`RawTableInner`], the result is [`Undefined Behavior`], + /// if the `index` is greater than the `self.bucket_mask + 1 + Group::WIDTH`. + /// In that case, calling this function with `index == self.bucket_mask + 1 + Group::WIDTH` + /// will return a pointer to the end of the allocated table and it is useless on its own. + /// + /// Calling this function with `index >= self.bucket_mask + 1 + Group::WIDTH` on a + /// table that has not been allocated results in [`Undefined Behavior`]. + /// + /// So to satisfy both requirements you should always follow the rule that + /// `index < self.bucket_mask + 1 + Group::WIDTH` + /// + /// Calling this function on [`RawTableInner`] that are not already allocated is safe + /// for read-only purpose. + /// + /// See also [`Bucket::as_ptr()`] method, for more information about of properly removing + /// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`]. + /// + /// [`Bucket::as_ptr()`]: Bucket::as_ptr() + /// [`Undefined Behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[inline] unsafe fn ctrl(&self, index: usize) -> *mut u8 { debug_assert!(index < self.num_ctrl_bytes()); + // SAFETY: The caller must uphold the safety rules for the [`RawTableInner::ctrl`] self.ctrl.as_ptr().add(index) } @@ -1335,6 +2809,17 @@ impl RawTableInner { self.bucket_mask + 1 } + /// Checks whether the bucket at `index` is full. + /// + /// # Safety + /// + /// The caller must ensure `index` is less than the number of buckets. + #[inline] + unsafe fn is_bucket_full(&self, index: usize) -> bool { + debug_assert!(index < self.buckets()); + is_full(*self.ctrl(index)) + } + #[inline] fn num_ctrl_bytes(&self) -> usize { self.bucket_mask + 1 + Group::WIDTH @@ -1345,25 +2830,45 @@ impl RawTableInner { self.bucket_mask == 0 } + /// Attempts to allocate a new hash table with at least enough capacity + /// for inserting the given number of elements without reallocating, + /// and return it inside ScopeGuard to protect against panic in the hash + /// function. + /// + /// # Note + /// + /// It is recommended (but not required): + /// + /// * That the new table's `capacity` be greater than or equal to `self.items`. + /// + /// * The `alloc` is the same [`Allocator`] as the `Allocator` used + /// to allocate this table. + /// + /// * The `table_layout` is the same [`TableLayout`] as the `TableLayout` used + /// to allocate this table. + /// + /// If `table_layout` does not match the `TableLayout` that was used to allocate + /// this table, then using `mem::swap` with the `self` and the new table returned + /// by this function results in [`undefined behavior`]. + /// + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[allow(clippy::mut_mut)] #[inline] - unsafe fn prepare_resize( + fn prepare_resize<'a, A>( &self, + alloc: &'a A, table_layout: TableLayout, capacity: usize, fallibility: Fallibility, - ) -> Result, TryReserveError> { + ) -> Result, TryReserveError> + where + A: Allocator, + { debug_assert!(self.items <= capacity); // Allocate and initialize the new table. - let mut new_table = RawTableInner::fallible_with_capacity( - self.alloc.clone(), - table_layout, - capacity, - fallibility, - )?; - new_table.growth_left -= self.items; - new_table.items = self.items; + let new_table = + RawTableInner::fallible_with_capacity(alloc, table_layout, capacity, fallibility)?; // The hash function may panic, in which case we simply free the new // table without dropping any elements that may have been copied into @@ -1373,7 +2878,11 @@ impl RawTableInner { // the comment at the bottom of this function. Ok(guard(new_table, move |self_| { if !self_.is_empty_singleton() { - self_.free_buckets(table_layout); + // SAFETY: + // 1. We have checked that our table is allocated. + // 2. We know for sure that the `alloc` and `table_layout` matches the + // [`Allocator`] and [`TableLayout`] used to allocate this table. + unsafe { self_.free_buckets(alloc, table_layout) }; } })) } @@ -1382,16 +2891,38 @@ impl RawTableInner { /// /// This uses dynamic dispatch to reduce the amount of /// code generated, but it is eliminated by LLVM optimizations when inlined. + /// + /// # Safety + /// + /// If any of the following conditions are violated, the result is + /// [`undefined behavior`]: + /// + /// * The `alloc` must be the same [`Allocator`] as the `Allocator` used + /// to allocate this table. + /// + /// * The `layout` must be the same [`TableLayout`] as the `TableLayout` + /// used to allocate this table. + /// + /// * The `drop` function (`fn(*mut u8)`) must be the actual drop function of + /// the elements stored in the table. + /// + /// * The [`RawTableInner`] must have properly initialized control bytes. + /// + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[allow(clippy::inline_always)] #[inline(always)] - unsafe fn reserve_rehash_inner( + unsafe fn reserve_rehash_inner( &mut self, + alloc: &A, additional: usize, hasher: &dyn Fn(&mut Self, usize) -> u64, fallibility: Fallibility, layout: TableLayout, drop: Option, - ) -> Result<(), TryReserveError> { + ) -> Result<(), TryReserveError> + where + A: Allocator, + { // Avoid `Option::ok_or_else` because it bloats LLVM IR. let new_items = match self.items.checked_add(additional) { Some(new_items) => new_items, @@ -1401,12 +2932,30 @@ impl RawTableInner { if new_items <= full_capacity / 2 { // Rehash in-place without re-allocating if we have plenty of spare // capacity that is locked up due to DELETED entries. + + // SAFETY: + // 1. We know for sure that `[`RawTableInner`]` has already been allocated + // (since new_items <= full_capacity / 2); + // 2. The caller ensures that `drop` function is the actual drop function of + // the elements stored in the table. + // 3. The caller ensures that `layout` matches the [`TableLayout`] that was + // used to allocate this table. + // 4. The caller ensures that the control bytes of the `RawTableInner` + // are already initialized. self.rehash_in_place(hasher, layout.size, drop); Ok(()) } else { // Otherwise, conservatively resize to at least the next size up // to avoid churning deletes into frequent rehashes. + // + // SAFETY: + // 1. We know for sure that `capacity >= self.items`. + // 2. The caller ensures that `alloc` and `layout` matches the [`Allocator`] and + // [`TableLayout`] that were used to allocate this table. + // 3. The caller ensures that the control bytes of the `RawTableInner` + // are already initialized. self.resize_inner( + alloc, usize::max(new_items, full_capacity + 1), hasher, fallibility, @@ -1415,48 +2964,160 @@ impl RawTableInner { } } + /// Returns an iterator over full buckets indices in the table. + /// + /// # Safety + /// + /// Behavior is undefined if any of the following conditions are violated: + /// + /// * The caller has to ensure that the `RawTableInner` outlives the + /// `FullBucketsIndices`. Because we cannot make the `next` method + /// unsafe on the `FullBucketsIndices` struct, we have to make the + /// `full_buckets_indices` method unsafe. + /// + /// * The [`RawTableInner`] must have properly initialized control bytes. + #[inline(always)] + unsafe fn full_buckets_indices(&self) -> FullBucketsIndices { + // SAFETY: + // 1. Since the caller of this function ensures that the control bytes + // are properly initialized and `self.ctrl(0)` points to the start + // of the array of control bytes, therefore: `ctrl` is valid for reads, + // properly aligned to `Group::WIDTH` and points to the properly initialized + // control bytes. + // 2. The value of `items` is equal to the amount of data (values) added + // to the table. + // + // `ctrl` points here (to the start + // of the first control byte `CT0`) + // ∨ + // [Pad], T_n, ..., T1, T0, |CT0, CT1, ..., CT_n|, Group::WIDTH + // \________ ________/ + // \/ + // `n = buckets - 1`, i.e. `RawTableInner::buckets() - 1` + // + // where: T0...T_n - our stored data; + // CT0...CT_n - control bytes or metadata for `data`. + let ctrl = NonNull::new_unchecked(self.ctrl(0)); + + FullBucketsIndices { + // Load the first group + // SAFETY: See explanation above. + current_group: Group::load_aligned(ctrl.as_ptr()).match_full().into_iter(), + group_first_index: 0, + ctrl, + items: self.items, + } + } + /// Allocates a new table of a different size and moves the contents of the /// current table into it. /// /// This uses dynamic dispatch to reduce the amount of /// code generated, but it is eliminated by LLVM optimizations when inlined. + /// + /// # Safety + /// + /// If any of the following conditions are violated, the result is + /// [`undefined behavior`]: + /// + /// * The `alloc` must be the same [`Allocator`] as the `Allocator` used + /// to allocate this table; + /// + /// * The `layout` must be the same [`TableLayout`] as the `TableLayout` + /// used to allocate this table; + /// + /// * The [`RawTableInner`] must have properly initialized control bytes. + /// + /// The caller of this function must ensure that `capacity >= self.items` + /// otherwise: + /// + /// * If `self.items != 0`, calling of this function with `capacity == 0` + /// results in [`undefined behavior`]. + /// + /// * If `capacity_to_buckets(capacity) < Group::WIDTH` and + /// `self.items > capacity_to_buckets(capacity)` calling this function + /// results in [`undefined behavior`]. + /// + /// * If `capacity_to_buckets(capacity) >= Group::WIDTH` and + /// `self.items > capacity_to_buckets(capacity)` calling this function + /// are never return (will go into an infinite loop). + /// + /// Note: It is recommended (but not required) that the new table's `capacity` + /// be greater than or equal to `self.items`. In case if `capacity <= self.items` + /// this function can never return. See [`RawTableInner::find_insert_slot`] for + /// more information. + /// + /// [`RawTableInner::find_insert_slot`]: RawTableInner::find_insert_slot + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[allow(clippy::inline_always)] #[inline(always)] - unsafe fn resize_inner( + unsafe fn resize_inner( &mut self, + alloc: &A, capacity: usize, hasher: &dyn Fn(&mut Self, usize) -> u64, fallibility: Fallibility, layout: TableLayout, - ) -> Result<(), TryReserveError> { - let mut new_table = self.prepare_resize(layout, capacity, fallibility)?; - - // Copy all elements to the new table. - for i in 0..self.buckets() { - if !is_full(*self.ctrl(i)) { - continue; - } - + ) -> Result<(), TryReserveError> + where + A: Allocator, + { + // SAFETY: We know for sure that `alloc` and `layout` matches the [`Allocator`] and [`TableLayout`] + // that were used to allocate this table. + let mut new_table = self.prepare_resize(alloc, layout, capacity, fallibility)?; + + // SAFETY: We know for sure that RawTableInner will outlive the + // returned `FullBucketsIndices` iterator, and the caller of this + // function ensures that the control bytes are properly initialized. + for full_byte_index in self.full_buckets_indices() { // This may panic. - let hash = hasher(self, i); + let hash = hasher(self, full_byte_index); + // SAFETY: // We can use a simpler version of insert() here since: - // - there are no DELETED entries. - // - we know there is enough space in the table. - // - all elements are unique. - let (index, _) = new_table.prepare_insert_slot(hash); - + // 1. There are no DELETED entries. + // 2. We know there is enough space in the table. + // 3. All elements are unique. + // 4. The caller of this function guarantees that `capacity > 0` + // so `new_table` must already have some allocated memory. + // 5. We set `growth_left` and `items` fields of the new table + // after the loop. + // 6. We insert into the table, at the returned index, the data + // matching the given hash immediately after calling this function. + let (new_index, _) = new_table.prepare_insert_slot(hash); + + // SAFETY: + // + // * `src` is valid for reads of `layout.size` bytes, since the + // table is alive and the `full_byte_index` is guaranteed to be + // within bounds (see `FullBucketsIndices::next_impl`); + // + // * `dst` is valid for writes of `layout.size` bytes, since the + // caller ensures that `table_layout` matches the [`TableLayout`] + // that was used to allocate old table and we have the `new_index` + // returned by `prepare_insert_slot`. + // + // * Both `src` and `dst` are properly aligned. + // + // * Both `src` and `dst` point to different region of memory. ptr::copy_nonoverlapping( - self.bucket_ptr(i, layout.size), - new_table.bucket_ptr(index, layout.size), + self.bucket_ptr(full_byte_index, layout.size), + new_table.bucket_ptr(new_index, layout.size), layout.size, ); } + // The hash function didn't panic, so we can safely set the + // `growth_left` and `items` fields of the new table. + new_table.growth_left -= self.items; + new_table.items = self.items; + // We successfully copied all elements without panicking. Now replace // self with the new table. The old table will have its memory freed but // the items will not be dropped (since they have been moved into the // new table). + // SAFETY: The caller ensures that `table_layout` matches the [`TableLayout`] + // that was used to allocate this table. mem::swap(self, &mut new_table); Ok(()) @@ -1469,6 +3130,21 @@ impl RawTableInner { /// /// This uses dynamic dispatch to reduce the amount of /// code generated, but it is eliminated by LLVM optimizations when inlined. + /// + /// # Safety + /// + /// If any of the following conditions are violated, the result is [`undefined behavior`]: + /// + /// * The `size_of` must be equal to the size of the elements stored in the table; + /// + /// * The `drop` function (`fn(*mut u8)`) must be the actual drop function of + /// the elements stored in the table. + /// + /// * The [`RawTableInner`] has already been allocated; + /// + /// * The [`RawTableInner`] must have properly initialized control bytes. + /// + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[allow(clippy::inline_always)] #[cfg_attr(feature = "inline-more", inline(always))] #[cfg_attr(not(feature = "inline-more"), inline)] @@ -1512,8 +3188,10 @@ impl RawTableInner { let hash = hasher(*guard, i); // Search for a suitable place to put it - let new_i = guard.find_insert_slot(hash); - let new_i_p = guard.bucket_ptr(new_i, size_of); + // + // SAFETY: Caller of this function ensures that the control bytes + // are properly initialized. + let new_i = guard.find_insert_slot(hash).index; // Probing works by scanning through all of the control // bytes in groups, which may not be aligned to the group @@ -1525,6 +3203,8 @@ impl RawTableInner { continue 'outer; } + let new_i_p = guard.bucket_ptr(new_i, size_of); + // We are moving the current item to a new position. Write // our H2 to the control byte of the new position. let prev_ctrl = guard.replace_ctrl_h2(new_i, hash); @@ -1551,17 +3231,107 @@ impl RawTableInner { mem::forget(guard); } + /// Deallocates the table without dropping any entries. + /// + /// # Note + /// + /// This function must be called only after [`drop_elements`](RawTableInner::drop_elements), + /// else it can lead to leaking of memory. Also calling this function automatically + /// makes invalid (dangling) all instances of buckets ([`Bucket`]) and makes invalid + /// (dangling) the `ctrl` field of the table. + /// + /// # Safety + /// + /// If any of the following conditions are violated, the result is [`Undefined Behavior`]: + /// + /// * The [`RawTableInner`] has already been allocated; + /// + /// * The `alloc` must be the same [`Allocator`] as the `Allocator` that was used + /// to allocate this table. + /// + /// * The `table_layout` must be the same [`TableLayout`] as the `TableLayout` that was used + /// to allocate this table. + /// + /// See also [`GlobalAlloc::dealloc`] or [`Allocator::deallocate`] for more information. + /// + /// [`Undefined Behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + /// [`GlobalAlloc::dealloc`]: https://doc.rust-lang.org/alloc/alloc/trait.GlobalAlloc.html#tymethod.dealloc + /// [`Allocator::deallocate`]: https://doc.rust-lang.org/alloc/alloc/trait.Allocator.html#tymethod.deallocate #[inline] - unsafe fn free_buckets(&mut self, table_layout: TableLayout) { + unsafe fn free_buckets(&mut self, alloc: &A, table_layout: TableLayout) + where + A: Allocator, + { + // SAFETY: The caller must uphold the safety contract for `free_buckets` + // method. + let (ptr, layout) = self.allocation_info(table_layout); + alloc.deallocate(ptr, layout); + } + + /// Returns a pointer to the allocated memory and the layout that was used to + /// allocate the table. + /// + /// # Safety + /// + /// Caller of this function must observe the following safety rules: + /// + /// * The [`RawTableInner`] has already been allocated, otherwise + /// calling this function results in [`undefined behavior`] + /// + /// * The `table_layout` must be the same [`TableLayout`] as the `TableLayout` + /// that was used to allocate this table. Failure to comply with this condition + /// may result in [`undefined behavior`]. + /// + /// See also [`GlobalAlloc::dealloc`] or [`Allocator::deallocate`] for more information. + /// + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + /// [`GlobalAlloc::dealloc`]: https://doc.rust-lang.org/alloc/alloc/trait.GlobalAlloc.html#tymethod.dealloc + /// [`Allocator::deallocate`]: https://doc.rust-lang.org/alloc/alloc/trait.Allocator.html#tymethod.deallocate + #[inline] + unsafe fn allocation_info(&self, table_layout: TableLayout) -> (NonNull, Layout) { + debug_assert!( + !self.is_empty_singleton(), + "this function can only be called on non-empty tables" + ); + // Avoid `Option::unwrap_or_else` because it bloats LLVM IR. let (layout, ctrl_offset) = match table_layout.calculate_layout_for(self.buckets()) { Some(lco) => lco, - None => hint::unreachable_unchecked(), + None => unsafe { hint::unreachable_unchecked() }, }; - self.alloc.deallocate( - NonNull::new_unchecked(self.ctrl.as_ptr().sub(ctrl_offset)), + ( + // SAFETY: The caller must uphold the safety contract for `allocation_info` method. + unsafe { NonNull::new_unchecked(self.ctrl.as_ptr().sub(ctrl_offset)) }, layout, - ); + ) + } + + /// Returns a pointer to the allocated memory and the layout that was used to + /// allocate the table. If [`RawTableInner`] has not been allocated, this + /// function return `dangling` pointer and `()` (unit) layout. + /// + /// # Safety + /// + /// The `table_layout` must be the same [`TableLayout`] as the `TableLayout` + /// that was used to allocate this table. Failure to comply with this condition + /// may result in [`undefined behavior`]. + /// + /// See also [`GlobalAlloc::dealloc`] or [`Allocator::deallocate`] for more information. + /// + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + /// [`GlobalAlloc::dealloc`]: https://doc.rust-lang.org/alloc/alloc/trait.GlobalAlloc.html#tymethod.dealloc + /// [`Allocator::deallocate`]: https://doc.rust-lang.org/alloc/alloc/trait.Allocator.html#tymethod.deallocate + #[cfg(feature = "raw")] + unsafe fn allocation_info_or_zero(&self, table_layout: TableLayout) -> (NonNull, Layout) { + if self.is_empty_singleton() { + (NonNull::dangling(), Layout::new::<()>()) + } else { + // SAFETY: + // 1. We have checked that our table is allocated. + // 2. The caller ensures that `table_layout` matches the [`TableLayout`] + // that was used to allocate this table. + unsafe { self.allocation_info(table_layout) } + } } /// Marks all table buckets as empty without dropping their contents. @@ -1576,27 +3346,95 @@ impl RawTableInner { self.growth_left = bucket_mask_to_capacity(self.bucket_mask); } + /// Erases the [`Bucket`]'s control byte at the given index so that it does not + /// triggered as full, decreases the `items` of the table and, if it can be done, + /// increases `self.growth_left`. + /// + /// This function does not actually erase / drop the [`Bucket`] itself, i.e. it + /// does not make any changes to the `data` parts of the table. The caller of this + /// function must take care to properly drop the `data`, otherwise calling this + /// function may result in a memory leak. + /// + /// # Safety + /// + /// You must observe the following safety rules when calling this function: + /// + /// * The [`RawTableInner`] has already been allocated; + /// + /// * It must be the full control byte at the given position; + /// + /// * The `index` must not be greater than the `RawTableInner.bucket_mask`, i.e. + /// `index <= RawTableInner.bucket_mask` or, in other words, `(index + 1)` must + /// be no greater than the number returned by the function [`RawTableInner::buckets`]. + /// + /// Calling this function on a table that has not been allocated results in [`undefined behavior`]. + /// + /// Calling this function on a table with no elements is unspecified, but calling subsequent + /// functions is likely to result in [`undefined behavior`] due to overflow subtraction + /// (`self.items -= 1 cause overflow when self.items == 0`). + /// + /// See also [`Bucket::as_ptr`] method, for more information about of properly removing + /// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`]. + /// + /// [`RawTableInner::buckets`]: RawTableInner::buckets + /// [`Bucket::as_ptr`]: Bucket::as_ptr + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[inline] unsafe fn erase(&mut self, index: usize) { - debug_assert!(is_full(*self.ctrl(index))); + debug_assert!(self.is_bucket_full(index)); + + // This is the same as `index.wrapping_sub(Group::WIDTH) % self.buckets()` because + // the number of buckets is a power of two, and `self.bucket_mask = self.buckets() - 1`. let index_before = index.wrapping_sub(Group::WIDTH) & self.bucket_mask; + // SAFETY: + // - The caller must uphold the safety contract for `erase` method; + // - `index_before` is guaranteed to be in range due to masking with `self.bucket_mask` let empty_before = Group::load(self.ctrl(index_before)).match_empty(); let empty_after = Group::load(self.ctrl(index)).match_empty(); - // If we are inside a continuous block of Group::WIDTH full or deleted - // cells then a probe window may have seen a full block when trying to - // insert. We therefore need to keep that block non-empty so that - // lookups will continue searching to the next probe window. + // Inserting and searching in the map is performed by two key functions: + // + // - The `find_insert_slot` function that looks up the index of any `EMPTY` or `DELETED` + // slot in a group to be able to insert. If it doesn't find an `EMPTY` or `DELETED` + // slot immediately in the first group, it jumps to the next `Group` looking for it, + // and so on until it has gone through all the groups in the control bytes. + // + // - The `find_inner` function that looks for the index of the desired element by looking + // at all the `FULL` bytes in the group. If it did not find the element right away, and + // there is no `EMPTY` byte in the group, then this means that the `find_insert_slot` + // function may have found a suitable slot in the next group. Therefore, `find_inner` + // jumps further, and if it does not find the desired element and again there is no `EMPTY` + // byte, then it jumps further, and so on. The search stops only if `find_inner` function + // finds the desired element or hits an `EMPTY` slot/byte. + // + // Accordingly, this leads to two consequences: // - // Note that in this context `leading_zeros` refers to the bytes at the - // end of a group, while `trailing_zeros` refers to the bytes at the - // beginning of a group. + // - The map must have `EMPTY` slots (bytes); + // + // - You can't just mark the byte to be erased as `EMPTY`, because otherwise the `find_inner` + // function may stumble upon an `EMPTY` byte before finding the desired element and stop + // searching. + // + // Thus it is necessary to check all bytes after and before the erased element. If we are in + // a contiguous `Group` of `FULL` or `DELETED` bytes (the number of `FULL` or `DELETED` bytes + // before and after is greater than or equal to `Group::WIDTH`), then we must mark our byte as + // `DELETED` in order for the `find_inner` function to go further. On the other hand, if there + // is at least one `EMPTY` slot in the `Group`, then the `find_inner` function will still stumble + // upon an `EMPTY` byte, so we can safely mark our erased byte as `EMPTY` as well. + // + // Finally, since `index_before == (index.wrapping_sub(Group::WIDTH) & self.bucket_mask) == index` + // and given all of the above, tables smaller than the group width (self.buckets() < Group::WIDTH) + // cannot have `DELETED` bytes. + // + // Note that in this context `leading_zeros` refers to the bytes at the end of a group, while + // `trailing_zeros` refers to the bytes at the beginning of a group. let ctrl = if empty_before.leading_zeros() + empty_after.trailing_zeros() >= Group::WIDTH { DELETED } else { self.growth_left += 1; EMPTY }; + // SAFETY: the caller must uphold the safety contract for `erase` method. self.set_ctrl(index, ctrl); self.items -= 1; } @@ -1605,63 +3443,99 @@ impl RawTableInner { impl Clone for RawTable { fn clone(&self) -> Self { if self.table.is_empty_singleton() { - Self::new_in(self.table.alloc.clone()) + Self::new_in(self.alloc.clone()) } else { unsafe { - let mut new_table = ManuallyDrop::new( - // Avoid `Result::ok_or_else` because it bloats LLVM IR. - match Self::new_uninitialized( - self.table.alloc.clone(), - self.table.buckets(), - Fallibility::Infallible, - ) { - Ok(table) => table, - Err(_) => hint::unreachable_unchecked(), - }, - ); - - new_table.clone_from_spec(self, |new_table| { - // We need to free the memory allocated for the new table. - new_table.free_buckets(); - }); - - // Return the newly created table. - ManuallyDrop::into_inner(new_table) + // Avoid `Result::ok_or_else` because it bloats LLVM IR. + // + // SAFETY: This is safe as we are taking the size of an already allocated table + // and therefore сapacity overflow cannot occur, `self.table.buckets()` is power + // of two and all allocator errors will be caught inside `RawTableInner::new_uninitialized`. + let mut new_table = match Self::new_uninitialized( + self.alloc.clone(), + self.table.buckets(), + Fallibility::Infallible, + ) { + Ok(table) => table, + Err(_) => hint::unreachable_unchecked(), + }; + + // Cloning elements may fail (the clone function may panic). But we don't + // need to worry about uninitialized control bits, since: + // 1. The number of items (elements) in the table is zero, which means that + // the control bits will not be readed by Drop function. + // 2. The `clone_from_spec` method will first copy all control bits from + // `self` (thus initializing them). But this will not affect the `Drop` + // function, since the `clone_from_spec` function sets `items` only after + // successfully clonning all elements. + new_table.clone_from_spec(self); + new_table } } } fn clone_from(&mut self, source: &Self) { if source.table.is_empty_singleton() { - *self = Self::new_in(self.table.alloc.clone()); + let mut old_inner = mem::replace(&mut self.table, RawTableInner::NEW); + unsafe { + // SAFETY: + // 1. We call the function only once; + // 2. We know for sure that `alloc` and `table_layout` matches the [`Allocator`] + // and [`TableLayout`] that were used to allocate this table. + // 3. If any elements' drop function panics, then there will only be a memory leak, + // because we have replaced the inner table with a new one. + old_inner.drop_inner_table::(&self.alloc, Self::TABLE_LAYOUT); + } } else { unsafe { - // First, drop all our elements without clearing the control bytes. - self.drop_elements(); + // Make sure that if any panics occurs, we clear the table and + // leave it in an empty state. + let mut self_ = guard(self, |self_| { + self_.clear_no_drop(); + }); + + // First, drop all our elements without clearing the control + // bytes. If this panics then the scope guard will clear the + // table, leaking any elements that were not dropped yet. + // + // This leak is unavoidable: we can't try dropping more elements + // since this could lead to another panic and abort the process. + // + // SAFETY: If something gets wrong we clear our table right after + // dropping the elements, so there is no double drop, since `items` + // will be equal to zero. + self_.table.drop_elements::(); // If necessary, resize our table to match the source. - if self.buckets() != source.buckets() { - // Skip our drop by using ptr::write. - if !self.table.is_empty_singleton() { - self.free_buckets(); + if self_.buckets() != source.buckets() { + let new_inner = match RawTableInner::new_uninitialized( + &self_.alloc, + Self::TABLE_LAYOUT, + source.buckets(), + Fallibility::Infallible, + ) { + Ok(table) => table, + Err(_) => hint::unreachable_unchecked(), + }; + // Replace the old inner with new uninitialized one. It's ok, since if something gets + // wrong `ScopeGuard` will initialize all control bytes and leave empty table. + let mut old_inner = mem::replace(&mut self_.table, new_inner); + if !old_inner.is_empty_singleton() { + // SAFETY: + // 1. We have checked that our table is allocated. + // 2. We know for sure that `alloc` and `table_layout` matches + // the [`Allocator`] and [`TableLayout`] that were used to allocate this table. + old_inner.free_buckets(&self_.alloc, Self::TABLE_LAYOUT); } - (self as *mut Self).write( - // Avoid `Result::unwrap_or_else` because it bloats LLVM IR. - match Self::new_uninitialized( - self.table.alloc.clone(), - source.buckets(), - Fallibility::Infallible, - ) { - Ok(table) => table, - Err(_) => hint::unreachable_unchecked(), - }, - ); } - self.clone_from_spec(source, |self_| { - // We need to leave the table in an empty state. - self_.clear_no_drop(); - }); + // Cloning elements may fail (the clone function may panic), but the `ScopeGuard` + // inside the `clone_from_impl` function will take care of that, dropping all + // cloned elements if necessary. Our `ScopeGuard` will clear the table. + self_.clone_from_spec(source); + + // Disarm the scope guard if cloning was successful. + ScopeGuard::into_inner(self_); } } } @@ -1669,27 +3543,28 @@ impl Clone for RawTable { /// Specialization of `clone_from` for `Copy` types trait RawTableClone { - unsafe fn clone_from_spec(&mut self, source: &Self, on_panic: impl FnMut(&mut Self)); + unsafe fn clone_from_spec(&mut self, source: &Self); } impl RawTableClone for RawTable { default_fn! { #[cfg_attr(feature = "inline-more", inline)] - unsafe fn clone_from_spec(&mut self, source: &Self, on_panic: impl FnMut(&mut Self)) { - self.clone_from_impl(source, on_panic); + unsafe fn clone_from_spec(&mut self, source: &Self) { + self.clone_from_impl(source); } } } #[cfg(feature = "nightly")] impl RawTableClone for RawTable { #[cfg_attr(feature = "inline-more", inline)] - unsafe fn clone_from_spec(&mut self, source: &Self, _on_panic: impl FnMut(&mut Self)) { + unsafe fn clone_from_spec(&mut self, source: &Self) { source .table .ctrl(0) .copy_to_nonoverlapping(self.table.ctrl(0), self.table.num_ctrl_bytes()); source .data_start() - .copy_to_nonoverlapping(self.data_start(), self.table.buckets()); + .as_ptr() + .copy_to_nonoverlapping(self.data_start().as_ptr(), self.table.buckets()); self.table.items = source.table.items; self.table.growth_left = source.table.growth_left; @@ -1697,9 +3572,12 @@ impl RawTableClone for RawTable { } impl RawTable { - /// Common code for clone and clone_from. Assumes `self.buckets() == source.buckets()`. + /// Common code for clone and clone_from. Assumes: + /// - `self.buckets() == source.buckets()`. + /// - Any existing elements have been dropped. + /// - The control bytes are not initialized yet. #[cfg_attr(feature = "inline-more", inline)] - unsafe fn clone_from_impl(&mut self, source: &Self, mut on_panic: impl FnMut(&mut Self)) { + unsafe fn clone_from_impl(&mut self, source: &Self) { // Copy the control bytes unchanged. We do this in a single pass source .table @@ -1710,18 +3588,13 @@ impl RawTable { // to make sure we drop only the elements that have been // cloned so far. let mut guard = guard((0, &mut *self), |(index, self_)| { - if mem::needs_drop::() && !self_.is_empty() { + if T::NEEDS_DROP { for i in 0..=*index { - if is_full(*self_.table.ctrl(i)) { + if self_.is_bucket_full(i) { self_.bucket(i).drop(); } } } - - // Depending on whether we were called from clone or clone_from, we - // either need to free the memory for the destination table or just - // clear the control bytes. - on_panic(self_); }); for from in source.iter() { @@ -1752,7 +3625,7 @@ impl RawTable { { self.clear(); - let guard_self = guard(&mut *self, |self_| { + let mut guard_self = guard(&mut *self, |self_| { // Clear the partially copied table if a panic occurs, otherwise // items and growth_left will be out of sync with the contents // of the table. @@ -1785,7 +3658,7 @@ impl RawTable { } } -impl Default for RawTable { +impl Default for RawTable { #[inline] fn default() -> Self { Self::new_in(Default::default()) @@ -1793,31 +3666,41 @@ impl Default for RawTable { } #[cfg(feature = "nightly")] -unsafe impl<#[may_dangle] T, A: Allocator + Clone> Drop for RawTable { +unsafe impl<#[may_dangle] T, A: Allocator> Drop for RawTable { #[cfg_attr(feature = "inline-more", inline)] fn drop(&mut self) { - if !self.table.is_empty_singleton() { - unsafe { - self.drop_elements(); - self.free_buckets(); - } + unsafe { + // SAFETY: + // 1. We call the function only once; + // 2. We know for sure that `alloc` and `table_layout` matches the [`Allocator`] + // and [`TableLayout`] that were used to allocate this table. + // 3. If the drop function of any elements fails, then only a memory leak will occur, + // and we don't care because we are inside the `Drop` function of the `RawTable`, + // so there won't be any table left in an inconsistent state. + self.table + .drop_inner_table::(&self.alloc, Self::TABLE_LAYOUT); } } } #[cfg(not(feature = "nightly"))] -impl Drop for RawTable { +impl Drop for RawTable { #[cfg_attr(feature = "inline-more", inline)] fn drop(&mut self) { - if !self.table.is_empty_singleton() { - unsafe { - self.drop_elements(); - self.free_buckets(); - } + unsafe { + // SAFETY: + // 1. We call the function only once; + // 2. We know for sure that `alloc` and `table_layout` matches the [`Allocator`] + // and [`TableLayout`] that were used to allocate this table. + // 3. If the drop function of any elements fails, then only a memory leak will occur, + // and we don't care because we are inside the `Drop` function of the `RawTable`, + // so there won't be any table left in an inconsistent state. + self.table + .drop_inner_table::(&self.alloc, Self::TABLE_LAYOUT); } } } -impl IntoIterator for RawTable { +impl IntoIterator for RawTable { type Item = T; type IntoIter = RawIntoIter; @@ -1835,7 +3718,7 @@ impl IntoIterator for RawTable { pub(crate) struct RawIterRange { // Mask of full buckets in the current group. Bits are cleared from this // mask as each element is processed. - current_group: BitMask, + current_group: BitMaskIter, // Pointer to the buckets for the current group. data: Bucket, @@ -1851,19 +3734,44 @@ pub(crate) struct RawIterRange { impl RawIterRange { /// Returns a `RawIterRange` covering a subset of a table. /// - /// The control byte address must be aligned to the group size. + /// # Safety + /// + /// If any of the following conditions are violated, the result is + /// [`undefined behavior`]: + /// + /// * `ctrl` must be [valid] for reads, i.e. table outlives the `RawIterRange`; + /// + /// * `ctrl` must be properly aligned to the group size (Group::WIDTH); + /// + /// * `ctrl` must point to the array of properly initialized control bytes; + /// + /// * `data` must be the [`Bucket`] at the `ctrl` index in the table; + /// + /// * the value of `len` must be less than or equal to the number of table buckets, + /// and the returned value of `ctrl.as_ptr().add(len).offset_from(ctrl.as_ptr())` + /// must be positive. + /// + /// * The `ctrl.add(len)` pointer must be either in bounds or one + /// byte past the end of the same [allocated table]. + /// + /// * The `len` must be a power of two. + /// + /// [valid]: https://doc.rust-lang.org/std/ptr/index.html#safety + /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[cfg_attr(feature = "inline-more", inline)] unsafe fn new(ctrl: *const u8, data: Bucket, len: usize) -> Self { debug_assert_ne!(len, 0); debug_assert_eq!(ctrl as usize % Group::WIDTH, 0); + // SAFETY: The caller must uphold the safety rules for the [`RawIterRange::new`] let end = ctrl.add(len); // Load the first group and advance ctrl to point to the next group + // SAFETY: The caller must uphold the safety rules for the [`RawIterRange::new`] let current_group = Group::load_aligned(ctrl).match_full(); let next_ctrl = ctrl.add(Group::WIDTH); Self { - current_group, + current_group: current_group.into_iter(), data, next_ctrl, end, @@ -1913,6 +3821,31 @@ impl RawIterRange { } } } + + /// # Safety + /// If DO_CHECK_PTR_RANGE is false, caller must ensure that we never try to iterate + /// after yielding all elements. + #[cfg_attr(feature = "inline-more", inline)] + unsafe fn next_impl(&mut self) -> Option> { + loop { + if let Some(index) = self.current_group.next() { + return Some(self.data.next_n(index)); + } + + if DO_CHECK_PTR_RANGE && self.next_ctrl >= self.end { + return None; + } + + // We might read past self.end up to the next group boundary, + // but this is fine because it only occurs on tables smaller + // than the group size where the trailing control bytes are all + // EMPTY. On larger tables self.end is guaranteed to be aligned + // to the group size (since tables are power-of-two sized). + self.current_group = Group::load_aligned(self.next_ctrl).match_full().into_iter(); + self.data = self.data.next_n(Group::WIDTH); + self.next_ctrl = self.next_ctrl.add(Group::WIDTH); + } + } } // We make raw iterators unconditionally Send and Sync, and let the PhantomData @@ -1938,35 +3871,22 @@ impl Iterator for RawIterRange { #[cfg_attr(feature = "inline-more", inline)] fn next(&mut self) -> Option> { unsafe { - loop { - if let Some(index) = self.current_group.lowest_set_bit() { - self.current_group = self.current_group.remove_lowest_bit(); - return Some(self.data.next_n(index)); - } - - if self.next_ctrl >= self.end { - return None; - } - - // We might read past self.end up to the next group boundary, - // but this is fine because it only occurs on tables smaller - // than the group size where the trailing control bytes are all - // EMPTY. On larger tables self.end is guaranteed to be aligned - // to the group size (since tables are power-of-two sized). - self.current_group = Group::load_aligned(self.next_ctrl).match_full(); - self.data = self.data.next_n(Group::WIDTH); - self.next_ctrl = self.next_ctrl.add(Group::WIDTH); - } + // SAFETY: We set checker flag to true. + self.next_impl::() } } #[inline] fn size_hint(&self) -> (usize, Option) { // We don't have an item count, so just guess based on the range size. - ( - 0, - Some(unsafe { offset_from(self.end, self.next_ctrl) + Group::WIDTH }), - ) + let remaining_buckets = if self.end > self.next_ctrl { + unsafe { offset_from(self.end, self.next_ctrl) } + } else { + 0 + }; + + // Add a group width to include the group we are currently processing. + (0, Some(Group::WIDTH + remaining_buckets)) } } @@ -1998,7 +3918,7 @@ impl RawIter { /// This method should be called _before_ the removal is made. It is not necessary to call this /// method if you are removing an item that this iterator yielded in the past. #[cfg(feature = "raw")] - pub fn reflect_remove(&mut self, b: &Bucket) { + pub unsafe fn reflect_remove(&mut self, b: &Bucket) { self.reflect_toggle_full(b, false); } @@ -2012,36 +3932,76 @@ impl RawIter { /// /// This method should be called _after_ the given insert is made. #[cfg(feature = "raw")] - pub fn reflect_insert(&mut self, b: &Bucket) { + pub unsafe fn reflect_insert(&mut self, b: &Bucket) { self.reflect_toggle_full(b, true); } /// Refresh the iterator so that it reflects a change to the state of the given bucket. #[cfg(feature = "raw")] - fn reflect_toggle_full(&mut self, b: &Bucket, is_insert: bool) { - unsafe { - if b.as_ptr() > self.iter.data.as_ptr() { - // The iterator has already passed the bucket's group. - // So the toggle isn't relevant to this iterator. - return; + unsafe fn reflect_toggle_full(&mut self, b: &Bucket, is_insert: bool) { + if b.as_ptr() > self.iter.data.as_ptr() { + // The iterator has already passed the bucket's group. + // So the toggle isn't relevant to this iterator. + return; + } + + if self.iter.next_ctrl < self.iter.end + && b.as_ptr() <= self.iter.data.next_n(Group::WIDTH).as_ptr() + { + // The iterator has not yet reached the bucket's group. + // We don't need to reload anything, but we do need to adjust the item count. + + if cfg!(debug_assertions) { + // Double-check that the user isn't lying to us by checking the bucket state. + // To do that, we need to find its control byte. We know that self.iter.data is + // at self.iter.next_ctrl - Group::WIDTH, so we work from there: + let offset = offset_from(self.iter.data.as_ptr(), b.as_ptr()); + let ctrl = self.iter.next_ctrl.sub(Group::WIDTH).add(offset); + // This method should be called _before_ a removal, or _after_ an insert, + // so in both cases the ctrl byte should indicate that the bucket is full. + assert!(is_full(*ctrl)); } - if self.iter.next_ctrl < self.iter.end - && b.as_ptr() <= self.iter.data.next_n(Group::WIDTH).as_ptr() - { - // The iterator has not yet reached the bucket's group. - // We don't need to reload anything, but we do need to adjust the item count. + if is_insert { + self.items += 1; + } else { + self.items -= 1; + } - if cfg!(debug_assertions) { - // Double-check that the user isn't lying to us by checking the bucket state. - // To do that, we need to find its control byte. We know that self.iter.data is - // at self.iter.next_ctrl - Group::WIDTH, so we work from there: - let offset = offset_from(self.iter.data.as_ptr(), b.as_ptr()); - let ctrl = self.iter.next_ctrl.sub(Group::WIDTH).add(offset); - // This method should be called _before_ a removal, or _after_ an insert, - // so in both cases the ctrl byte should indicate that the bucket is full. - assert!(is_full(*ctrl)); - } + return; + } + + // The iterator is at the bucket group that the toggled bucket is in. + // We need to do two things: + // + // - Determine if the iterator already yielded the toggled bucket. + // If it did, we're done. + // - Otherwise, update the iterator cached group so that it won't + // yield a to-be-removed bucket, or _will_ yield a to-be-added bucket. + // We'll also need to update the item count accordingly. + if let Some(index) = self.iter.current_group.0.lowest_set_bit() { + let next_bucket = self.iter.data.next_n(index); + if b.as_ptr() > next_bucket.as_ptr() { + // The toggled bucket is "before" the bucket the iterator would yield next. We + // therefore don't need to do anything --- the iterator has already passed the + // bucket in question. + // + // The item count must already be correct, since a removal or insert "prior" to + // the iterator's position wouldn't affect the item count. + } else { + // The removed bucket is an upcoming bucket. We need to make sure it does _not_ + // get yielded, and also that it's no longer included in the item count. + // + // NOTE: We can't just reload the group here, both since that might reflect + // inserts we've already passed, and because that might inadvertently unset the + // bits for _other_ removals. If we do that, we'd have to also decrement the + // item count for those other bits that we unset. But the presumably subsequent + // call to reflect for those buckets might _also_ decrement the item count. + // Instead, we _just_ flip the bit for the particular bucket the caller asked + // us to reflect. + let our_bit = offset_from(self.iter.data.as_ptr(), b.as_ptr()); + let was_full = self.iter.current_group.flip(our_bit); + debug_assert_ne!(was_full, is_insert); if is_insert { self.items += 1; @@ -2049,65 +4009,23 @@ impl RawIter { self.items -= 1; } - return; - } - - // The iterator is at the bucket group that the toggled bucket is in. - // We need to do two things: - // - // - Determine if the iterator already yielded the toggled bucket. - // If it did, we're done. - // - Otherwise, update the iterator cached group so that it won't - // yield a to-be-removed bucket, or _will_ yield a to-be-added bucket. - // We'll also need to update the item count accordingly. - if let Some(index) = self.iter.current_group.lowest_set_bit() { - let next_bucket = self.iter.data.next_n(index); - if b.as_ptr() > next_bucket.as_ptr() { - // The toggled bucket is "before" the bucket the iterator would yield next. We - // therefore don't need to do anything --- the iterator has already passed the - // bucket in question. - // - // The item count must already be correct, since a removal or insert "prior" to - // the iterator's position wouldn't affect the item count. - } else { - // The removed bucket is an upcoming bucket. We need to make sure it does _not_ - // get yielded, and also that it's no longer included in the item count. - // - // NOTE: We can't just reload the group here, both since that might reflect - // inserts we've already passed, and because that might inadvertently unset the - // bits for _other_ removals. If we do that, we'd have to also decrement the - // item count for those other bits that we unset. But the presumably subsequent - // call to reflect for those buckets might _also_ decrement the item count. - // Instead, we _just_ flip the bit for the particular bucket the caller asked - // us to reflect. - let our_bit = offset_from(self.iter.data.as_ptr(), b.as_ptr()); - let was_full = self.iter.current_group.flip(our_bit); - debug_assert_ne!(was_full, is_insert); - - if is_insert { - self.items += 1; + if cfg!(debug_assertions) { + if b.as_ptr() == next_bucket.as_ptr() { + // The removed bucket should no longer be next + debug_assert_ne!(self.iter.current_group.0.lowest_set_bit(), Some(index)); } else { - self.items -= 1; - } - - if cfg!(debug_assertions) { - if b.as_ptr() == next_bucket.as_ptr() { - // The removed bucket should no longer be next - debug_assert_ne!(self.iter.current_group.lowest_set_bit(), Some(index)); - } else { - // We should not have changed what bucket comes next. - debug_assert_eq!(self.iter.current_group.lowest_set_bit(), Some(index)); - } + // We should not have changed what bucket comes next. + debug_assert_eq!(self.iter.current_group.0.lowest_set_bit(), Some(index)); } } - } else { - // We must have already iterated past the removed item. } + } else { + // We must have already iterated past the removed item. } } unsafe fn drop_elements(&mut self) { - if mem::needs_drop::() && self.len() != 0 { + if T::NEEDS_DROP && self.items != 0 { for item in self { item.drop(); } @@ -2130,16 +4048,21 @@ impl Iterator for RawIter { #[cfg_attr(feature = "inline-more", inline)] fn next(&mut self) -> Option> { - if let Some(b) = self.iter.next() { - self.items -= 1; - Some(b) - } else { - // We don't check against items == 0 here to allow the - // compiler to optimize away the item count entirely if the - // iterator length is never queried. - debug_assert_eq!(self.items, 0); - None + // Inner iterator iterates over buckets + // so it can do unnecessary work if we already yielded all items. + if self.items == 0 { + return None; } + + let nxt = unsafe { + // SAFETY: We check number of items to yield using `items` field. + self.iter.next_impl::() + }; + + debug_assert!(nxt.is_some()); + self.items -= 1; + + nxt } #[inline] @@ -2151,28 +4074,146 @@ impl Iterator for RawIter { impl ExactSizeIterator for RawIter {} impl FusedIterator for RawIter {} +/// Iterator which returns an index of every full bucket in the table. +/// +/// For maximum flexibility this iterator is not bound by a lifetime, but you +/// must observe several rules when using it: +/// - You must not free the hash table while iterating (including via growing/shrinking). +/// - It is fine to erase a bucket that has been yielded by the iterator. +/// - Erasing a bucket that has not yet been yielded by the iterator may still +/// result in the iterator yielding index of that bucket. +/// - It is unspecified whether an element inserted after the iterator was +/// created will be yielded by that iterator. +/// - The order in which the iterator yields indices of the buckets is unspecified +/// and may change in the future. +pub(crate) struct FullBucketsIndices { + // Mask of full buckets in the current group. Bits are cleared from this + // mask as each element is processed. + current_group: BitMaskIter, + + // Initial value of the bytes' indices of the current group (relative + // to the start of the control bytes). + group_first_index: usize, + + // Pointer to the current group of control bytes, + // Must be aligned to the group size (Group::WIDTH). + ctrl: NonNull, + + // Number of elements in the table. + items: usize, +} + +impl FullBucketsIndices { + /// Advances the iterator and returns the next value. + /// + /// # Safety + /// + /// If any of the following conditions are violated, the result is + /// [`Undefined Behavior`]: + /// + /// * The [`RawTableInner`] / [`RawTable`] must be alive and not moved, + /// i.e. table outlives the `FullBucketsIndices`; + /// + /// * It never tries to iterate after getting all elements. + /// + /// [`Undefined Behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + #[inline(always)] + unsafe fn next_impl(&mut self) -> Option { + loop { + if let Some(index) = self.current_group.next() { + // The returned `self.group_first_index + index` will always + // be in the range `0..self.buckets()`. See explanation below. + return Some(self.group_first_index + index); + } + + // SAFETY: The caller of this function ensures that: + // + // 1. It never tries to iterate after getting all the elements; + // 2. The table is alive and did not moved; + // 3. The first `self.ctrl` pointed to the start of the array of control bytes. + // + // Taking the above into account, we always stay within the bounds, because: + // + // 1. For tables smaller than the group width (self.buckets() <= Group::WIDTH), + // we will never end up in the given branch, since we should have already + // yielded all the elements of the table. + // + // 2. For tables larger than the group width. The the number of buckets is a + // power of two (2 ^ n), Group::WIDTH is also power of two (2 ^ k). Sinse + // `(2 ^ n) > (2 ^ k)`, than `(2 ^ n) % (2 ^ k) = 0`. As we start from the + // the start of the array of control bytes, and never try to iterate after + // getting all the elements, the last `self.ctrl` will be equal to + // the `self.buckets() - Group::WIDTH`, so `self.current_group.next()` + // will always contains indices within the range `0..Group::WIDTH`, + // and subsequent `self.group_first_index + index` will always return a + // number less than `self.buckets()`. + self.ctrl = NonNull::new_unchecked(self.ctrl.as_ptr().add(Group::WIDTH)); + + // SAFETY: See explanation above. + self.current_group = Group::load_aligned(self.ctrl.as_ptr()) + .match_full() + .into_iter(); + self.group_first_index += Group::WIDTH; + } + } +} + +impl Iterator for FullBucketsIndices { + type Item = usize; + + /// Advances the iterator and returns the next value. It is up to + /// the caller to ensure that the `RawTable` outlives the `FullBucketsIndices`, + /// because we cannot make the `next` method unsafe. + #[inline(always)] + fn next(&mut self) -> Option { + // Return if we already yielded all items. + if self.items == 0 { + return None; + } + + let nxt = unsafe { + // SAFETY: + // 1. We check number of items to yield using `items` field. + // 2. The caller ensures that the table is alive and has not moved. + self.next_impl() + }; + + debug_assert!(nxt.is_some()); + self.items -= 1; + + nxt + } + + #[inline(always)] + fn size_hint(&self) -> (usize, Option) { + (self.items, Some(self.items)) + } +} + +impl ExactSizeIterator for FullBucketsIndices {} +impl FusedIterator for FullBucketsIndices {} + /// Iterator which consumes a table and returns elements. -pub struct RawIntoIter { +pub struct RawIntoIter { iter: RawIter, - allocation: Option<(NonNull, Layout)>, + allocation: Option<(NonNull, Layout, A)>, marker: PhantomData, - alloc: A, } -impl RawIntoIter { +impl RawIntoIter { #[cfg_attr(feature = "inline-more", inline)] pub fn iter(&self) -> RawIter { self.iter.clone() } } -unsafe impl Send for RawIntoIter +unsafe impl Send for RawIntoIter where T: Send, A: Send, { } -unsafe impl Sync for RawIntoIter +unsafe impl Sync for RawIntoIter where T: Sync, A: Sync, @@ -2180,7 +4221,7 @@ where } #[cfg(feature = "nightly")] -unsafe impl<#[may_dangle] T, A: Allocator + Clone> Drop for RawIntoIter { +unsafe impl<#[may_dangle] T, A: Allocator> Drop for RawIntoIter { #[cfg_attr(feature = "inline-more", inline)] fn drop(&mut self) { unsafe { @@ -2188,14 +4229,14 @@ unsafe impl<#[may_dangle] T, A: Allocator + Clone> Drop for RawIntoIter { self.iter.drop_elements(); // Free the table - if let Some((ptr, layout)) = self.allocation { - self.alloc.deallocate(ptr, layout); + if let Some((ptr, layout, ref alloc)) = self.allocation { + alloc.deallocate(ptr, layout); } } } } #[cfg(not(feature = "nightly"))] -impl Drop for RawIntoIter { +impl Drop for RawIntoIter { #[cfg_attr(feature = "inline-more", inline)] fn drop(&mut self) { unsafe { @@ -2203,14 +4244,14 @@ impl Drop for RawIntoIter { self.iter.drop_elements(); // Free the table - if let Some((ptr, layout)) = self.allocation { - self.alloc.deallocate(ptr, layout); + if let Some((ptr, layout, ref alloc)) = self.allocation { + alloc.deallocate(ptr, layout); } } } } -impl Iterator for RawIntoIter { +impl Iterator for RawIntoIter { type Item = T; #[cfg_attr(feature = "inline-more", inline)] @@ -2224,45 +4265,45 @@ impl Iterator for RawIntoIter { } } -impl ExactSizeIterator for RawIntoIter {} -impl FusedIterator for RawIntoIter {} +impl ExactSizeIterator for RawIntoIter {} +impl FusedIterator for RawIntoIter {} /// Iterator which consumes elements without freeing the table storage. -pub struct RawDrain<'a, T, A: Allocator + Clone = Global> { +pub struct RawDrain<'a, T, A: Allocator = Global> { iter: RawIter, // The table is moved into the iterator for the duration of the drain. This // ensures that an empty table is left if the drain iterator is leaked // without dropping. - table: ManuallyDrop>, - orig_table: NonNull>, + table: RawTableInner, + orig_table: NonNull, // We don't use a &'a mut RawTable because we want RawDrain to be // covariant over T. marker: PhantomData<&'a RawTable>, } -impl RawDrain<'_, T, A> { +impl RawDrain<'_, T, A> { #[cfg_attr(feature = "inline-more", inline)] pub fn iter(&self) -> RawIter { self.iter.clone() } } -unsafe impl Send for RawDrain<'_, T, A> +unsafe impl Send for RawDrain<'_, T, A> where T: Send, A: Send, { } -unsafe impl Sync for RawDrain<'_, T, A> +unsafe impl Sync for RawDrain<'_, T, A> where T: Sync, A: Sync, { } -impl Drop for RawDrain<'_, T, A> { +impl Drop for RawDrain<'_, T, A> { #[cfg_attr(feature = "inline-more", inline)] fn drop(&mut self) { unsafe { @@ -2276,12 +4317,12 @@ impl Drop for RawDrain<'_, T, A> { // Move the now empty table back to its original location. self.orig_table .as_ptr() - .copy_from_nonoverlapping(&*self.table, 1); + .copy_from_nonoverlapping(&self.table, 1); } } } -impl Iterator for RawDrain<'_, T, A> { +impl Iterator for RawDrain<'_, T, A> { type Item = T; #[cfg_attr(feature = "inline-more", inline)] @@ -2298,21 +4339,36 @@ impl Iterator for RawDrain<'_, T, A> { } } -impl ExactSizeIterator for RawDrain<'_, T, A> {} -impl FusedIterator for RawDrain<'_, T, A> {} +impl ExactSizeIterator for RawDrain<'_, T, A> {} +impl FusedIterator for RawDrain<'_, T, A> {} /// Iterator over occupied buckets that could match a given hash. /// /// `RawTable` only stores 7 bits of the hash value, so this iterator may return /// items that have a hash value different than the one provided. You should /// always validate the returned values before using them. -pub struct RawIterHash<'a, T, A: Allocator + Clone = Global> { - inner: RawIterHashInner<'a, A>, +/// +/// For maximum flexibility this iterator is not bound by a lifetime, but you +/// must observe several rules when using it: +/// - You must not free the hash table while iterating (including via growing/shrinking). +/// - It is fine to erase a bucket that has been yielded by the iterator. +/// - Erasing a bucket that has not yet been yielded by the iterator may still +/// result in the iterator yielding that bucket. +/// - It is unspecified whether an element inserted after the iterator was +/// created will be yielded by that iterator. +/// - The order in which the iterator yields buckets is unspecified and may +/// change in the future. +pub struct RawIterHash { + inner: RawIterHashInner, _marker: PhantomData, } -struct RawIterHashInner<'a, A: Allocator + Clone> { - table: &'a RawTableInner, +struct RawIterHashInner { + // See `RawTableInner`'s corresponding fields for details. + // We can't store a `*const RawTableInner` as it would get + // invalidated by the user calling `&mut` methods on `RawTable`. + bucket_mask: usize, + ctrl: NonNull, // The top 7 bits of the hash. h2_hash: u8, @@ -2326,71 +4382,105 @@ struct RawIterHashInner<'a, A: Allocator + Clone> { bitmask: BitMaskIter, } -impl<'a, T, A: Allocator + Clone> RawIterHash<'a, T, A> { +impl RawIterHash { #[cfg_attr(feature = "inline-more", inline)] #[cfg(feature = "raw")] - fn new(table: &'a RawTable, hash: u64) -> Self { + unsafe fn new(table: &RawTable, hash: u64) -> Self { RawIterHash { inner: RawIterHashInner::new(&table.table, hash), _marker: PhantomData, } } } -impl<'a, A: Allocator + Clone> RawIterHashInner<'a, A> { +impl RawIterHashInner { #[cfg_attr(feature = "inline-more", inline)] #[cfg(feature = "raw")] - fn new(table: &'a RawTableInner, hash: u64) -> Self { - unsafe { - let h2_hash = h2(hash); - let probe_seq = table.probe_seq(hash); - let group = Group::load(table.ctrl(probe_seq.pos)); - let bitmask = group.match_byte(h2_hash).into_iter(); - - RawIterHashInner { - table, - h2_hash, - probe_seq, - group, - bitmask, - } + unsafe fn new(table: &RawTableInner, hash: u64) -> Self { + let h2_hash = h2(hash); + let probe_seq = table.probe_seq(hash); + let group = Group::load(table.ctrl(probe_seq.pos)); + let bitmask = group.match_byte(h2_hash).into_iter(); + + RawIterHashInner { + bucket_mask: table.bucket_mask, + ctrl: table.ctrl, + h2_hash, + probe_seq, + group, + bitmask, } } } -impl<'a, T, A: Allocator + Clone> Iterator for RawIterHash<'a, T, A> { +impl Iterator for RawIterHash { type Item = Bucket; fn next(&mut self) -> Option> { unsafe { match self.inner.next() { - Some(index) => Some(self.inner.table.bucket(index)), + Some(index) => { + // Can't use `RawTable::bucket` here as we don't have + // an actual `RawTable` reference to use. + debug_assert!(index <= self.inner.bucket_mask); + let bucket = Bucket::from_base_index(self.inner.ctrl.cast(), index); + Some(bucket) + } None => None, } } } } -impl<'a, A: Allocator + Clone> Iterator for RawIterHashInner<'a, A> { +impl Iterator for RawIterHashInner { type Item = usize; fn next(&mut self) -> Option { unsafe { loop { if let Some(bit) = self.bitmask.next() { - let index = (self.probe_seq.pos + bit) & self.table.bucket_mask; + let index = (self.probe_seq.pos + bit) & self.bucket_mask; return Some(index); } if likely(self.group.match_empty().any_bit_set()) { return None; } - self.probe_seq.move_next(self.table.bucket_mask); - self.group = Group::load(self.table.ctrl(self.probe_seq.pos)); + self.probe_seq.move_next(self.bucket_mask); + + // Can't use `RawTableInner::ctrl` here as we don't have + // an actual `RawTableInner` reference to use. + let index = self.probe_seq.pos; + debug_assert!(index < self.bucket_mask + 1 + Group::WIDTH); + let group_ctrl = self.ctrl.as_ptr().add(index); + + self.group = Group::load(group_ctrl); self.bitmask = self.group.match_byte(self.h2_hash).into_iter(); } } } } +pub(crate) struct RawExtractIf<'a, T, A: Allocator> { + pub iter: RawIter, + pub table: &'a mut RawTable, +} + +impl RawExtractIf<'_, T, A> { + #[cfg_attr(feature = "inline-more", inline)] + pub(crate) fn next(&mut self, mut f: F) -> Option + where + F: FnMut(&mut T) -> bool, + { + unsafe { + for item in &mut self.iter { + if f(item.as_mut()) { + return Some(self.table.remove(item).0); + } + } + } + None + } +} + #[cfg(test)] mod test_map { use super::*; @@ -2433,4 +4523,214 @@ mod test_map { assert!(table.find(i + 100, |x| *x == i + 100).is_none()); } } + + /// CHECKING THAT WE ARE NOT TRYING TO READ THE MEMORY OF + /// AN UNINITIALIZED TABLE DURING THE DROP + #[test] + fn test_drop_uninitialized() { + use ::alloc::vec::Vec; + + let table = unsafe { + // SAFETY: The `buckets` is power of two and we're not + // trying to actually use the returned RawTable. + RawTable::<(u64, Vec)>::new_uninitialized(Global, 8, Fallibility::Infallible) + .unwrap() + }; + drop(table); + } + + /// CHECKING THAT WE DON'T TRY TO DROP DATA IF THE `ITEMS` + /// ARE ZERO, EVEN IF WE HAVE `FULL` CONTROL BYTES. + #[test] + fn test_drop_zero_items() { + use ::alloc::vec::Vec; + unsafe { + // SAFETY: The `buckets` is power of two and we're not + // trying to actually use the returned RawTable. + let table = + RawTable::<(u64, Vec)>::new_uninitialized(Global, 8, Fallibility::Infallible) + .unwrap(); + + // WE SIMULATE, AS IT WERE, A FULL TABLE. + + // SAFETY: We checked that the table is allocated and therefore the table already has + // `self.bucket_mask + 1 + Group::WIDTH` number of control bytes (see TableLayout::calculate_layout_for) + // so writing `table.table.num_ctrl_bytes() == bucket_mask + 1 + Group::WIDTH` bytes is safe. + table + .table + .ctrl(0) + .write_bytes(EMPTY, table.table.num_ctrl_bytes()); + + // SAFETY: table.capacity() is guaranteed to be smaller than table.buckets() + table.table.ctrl(0).write_bytes(0, table.capacity()); + + // Fix up the trailing control bytes. See the comments in set_ctrl + // for the handling of tables smaller than the group width. + if table.buckets() < Group::WIDTH { + // SAFETY: We have `self.bucket_mask + 1 + Group::WIDTH` number of control bytes, + // so copying `self.buckets() == self.bucket_mask + 1` bytes with offset equal to + // `Group::WIDTH` is safe + table + .table + .ctrl(0) + .copy_to(table.table.ctrl(Group::WIDTH), table.table.buckets()); + } else { + // SAFETY: We have `self.bucket_mask + 1 + Group::WIDTH` number of + // control bytes,so copying `Group::WIDTH` bytes with offset equal + // to `self.buckets() == self.bucket_mask + 1` is safe + table + .table + .ctrl(0) + .copy_to(table.table.ctrl(table.table.buckets()), Group::WIDTH); + } + drop(table); + } + } + + /// CHECKING THAT WE DON'T TRY TO DROP DATA IF THE `ITEMS` + /// ARE ZERO, EVEN IF WE HAVE `FULL` CONTROL BYTES. + #[test] + fn test_catch_panic_clone_from() { + use ::alloc::sync::Arc; + use ::alloc::vec::Vec; + use allocator_api2::alloc::{AllocError, Allocator, Global}; + use core::sync::atomic::{AtomicI8, Ordering}; + use std::thread; + + struct MyAllocInner { + drop_count: Arc, + } + + #[derive(Clone)] + struct MyAlloc { + _inner: Arc, + } + + impl Drop for MyAllocInner { + fn drop(&mut self) { + println!("MyAlloc freed."); + self.drop_count.fetch_sub(1, Ordering::SeqCst); + } + } + + unsafe impl Allocator for MyAlloc { + fn allocate(&self, layout: Layout) -> std::result::Result, AllocError> { + let g = Global; + g.allocate(layout) + } + + unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) { + let g = Global; + g.deallocate(ptr, layout) + } + } + + const DISARMED: bool = false; + const ARMED: bool = true; + + struct CheckedCloneDrop { + panic_in_clone: bool, + dropped: bool, + need_drop: Vec, + } + + impl Clone for CheckedCloneDrop { + fn clone(&self) -> Self { + if self.panic_in_clone { + panic!("panic in clone") + } + Self { + panic_in_clone: self.panic_in_clone, + dropped: self.dropped, + need_drop: self.need_drop.clone(), + } + } + } + + impl Drop for CheckedCloneDrop { + fn drop(&mut self) { + if self.dropped { + panic!("double drop"); + } + self.dropped = true; + } + } + + let dropped: Arc = Arc::new(AtomicI8::new(2)); + + let mut table = RawTable::new_in(MyAlloc { + _inner: Arc::new(MyAllocInner { + drop_count: dropped.clone(), + }), + }); + + for (idx, panic_in_clone) in core::iter::repeat(DISARMED).take(7).enumerate() { + let idx = idx as u64; + table.insert( + idx, + ( + idx, + CheckedCloneDrop { + panic_in_clone, + dropped: false, + need_drop: vec![idx], + }, + ), + |(k, _)| *k, + ); + } + + assert_eq!(table.len(), 7); + + thread::scope(|s| { + let result = s.spawn(|| { + let armed_flags = [ + DISARMED, DISARMED, ARMED, DISARMED, DISARMED, DISARMED, DISARMED, + ]; + let mut scope_table = RawTable::new_in(MyAlloc { + _inner: Arc::new(MyAllocInner { + drop_count: dropped.clone(), + }), + }); + for (idx, &panic_in_clone) in armed_flags.iter().enumerate() { + let idx = idx as u64; + scope_table.insert( + idx, + ( + idx, + CheckedCloneDrop { + panic_in_clone, + dropped: false, + need_drop: vec![idx + 100], + }, + ), + |(k, _)| *k, + ); + } + table.clone_from(&scope_table); + }); + assert!(result.join().is_err()); + }); + + // Let's check that all iterators work fine and do not return elements + // (especially `RawIterRange`, which does not depend on the number of + // elements in the table, but looks directly at the control bytes) + // + // SAFETY: We know for sure that `RawTable` will outlive + // the returned `RawIter / RawIterRange` iterator. + assert_eq!(table.len(), 0); + assert_eq!(unsafe { table.iter().count() }, 0); + assert_eq!(unsafe { table.iter().iter.count() }, 0); + + for idx in 0..table.buckets() { + let idx = idx as u64; + assert!( + table.find(idx, |(k, _)| *k == idx).is_none(), + "Index: {idx}" + ); + } + + // All allocator clones should already be dropped. + assert_eq!(dropped.load(Ordering::SeqCst), 1); + } } diff --git a/sgx_tstd/hashbrown/src/raw/neon.rs b/sgx_tstd/hashbrown/src/raw/neon.rs new file mode 100644 index 000000000..44e82d57d --- /dev/null +++ b/sgx_tstd/hashbrown/src/raw/neon.rs @@ -0,0 +1,124 @@ +use super::bitmask::BitMask; +use super::EMPTY; +use core::arch::aarch64 as neon; +use core::mem; +use core::num::NonZeroU64; + +pub(crate) type BitMaskWord = u64; +pub(crate) type NonZeroBitMaskWord = NonZeroU64; +pub(crate) const BITMASK_STRIDE: usize = 8; +pub(crate) const BITMASK_MASK: BitMaskWord = !0; +pub(crate) const BITMASK_ITER_MASK: BitMaskWord = 0x8080_8080_8080_8080; + +/// Abstraction over a group of control bytes which can be scanned in +/// parallel. +/// +/// This implementation uses a 64-bit NEON value. +#[derive(Copy, Clone)] +pub(crate) struct Group(neon::uint8x8_t); + +#[allow(clippy::use_self)] +impl Group { + /// Number of bytes in the group. + pub(crate) const WIDTH: usize = mem::size_of::(); + + /// Returns a full group of empty bytes, suitable for use as the initial + /// value for an empty hash table. + /// + /// This is guaranteed to be aligned to the group size. + #[inline] + pub(crate) const fn static_empty() -> &'static [u8; Group::WIDTH] { + #[repr(C)] + struct AlignedBytes { + _align: [Group; 0], + bytes: [u8; Group::WIDTH], + } + const ALIGNED_BYTES: AlignedBytes = AlignedBytes { + _align: [], + bytes: [EMPTY; Group::WIDTH], + }; + &ALIGNED_BYTES.bytes + } + + /// Loads a group of bytes starting at the given address. + #[inline] + #[allow(clippy::cast_ptr_alignment)] // unaligned load + pub(crate) unsafe fn load(ptr: *const u8) -> Self { + Group(neon::vld1_u8(ptr)) + } + + /// Loads a group of bytes starting at the given address, which must be + /// aligned to `mem::align_of::()`. + #[inline] + #[allow(clippy::cast_ptr_alignment)] + pub(crate) unsafe fn load_aligned(ptr: *const u8) -> Self { + // FIXME: use align_offset once it stabilizes + debug_assert_eq!(ptr as usize & (mem::align_of::() - 1), 0); + Group(neon::vld1_u8(ptr)) + } + + /// Stores the group of bytes to the given address, which must be + /// aligned to `mem::align_of::()`. + #[inline] + #[allow(clippy::cast_ptr_alignment)] + pub(crate) unsafe fn store_aligned(self, ptr: *mut u8) { + // FIXME: use align_offset once it stabilizes + debug_assert_eq!(ptr as usize & (mem::align_of::() - 1), 0); + neon::vst1_u8(ptr, self.0); + } + + /// Returns a `BitMask` indicating all bytes in the group which *may* + /// have the given value. + #[inline] + pub(crate) fn match_byte(self, byte: u8) -> BitMask { + unsafe { + let cmp = neon::vceq_u8(self.0, neon::vdup_n_u8(byte)); + BitMask(neon::vget_lane_u64(neon::vreinterpret_u64_u8(cmp), 0)) + } + } + + /// Returns a `BitMask` indicating all bytes in the group which are + /// `EMPTY`. + #[inline] + pub(crate) fn match_empty(self) -> BitMask { + self.match_byte(EMPTY) + } + + /// Returns a `BitMask` indicating all bytes in the group which are + /// `EMPTY` or `DELETED`. + #[inline] + pub(crate) fn match_empty_or_deleted(self) -> BitMask { + unsafe { + let cmp = neon::vcltz_s8(neon::vreinterpret_s8_u8(self.0)); + BitMask(neon::vget_lane_u64(neon::vreinterpret_u64_u8(cmp), 0)) + } + } + + /// Returns a `BitMask` indicating all bytes in the group which are full. + #[inline] + pub(crate) fn match_full(self) -> BitMask { + unsafe { + let cmp = neon::vcgez_s8(neon::vreinterpret_s8_u8(self.0)); + BitMask(neon::vget_lane_u64(neon::vreinterpret_u64_u8(cmp), 0)) + } + } + + /// Performs the following transformation on all bytes in the group: + /// - `EMPTY => EMPTY` + /// - `DELETED => EMPTY` + /// - `FULL => DELETED` + #[inline] + pub(crate) fn convert_special_to_empty_and_full_to_deleted(self) -> Self { + // Map high_bit = 1 (EMPTY or DELETED) to 1111_1111 + // and high_bit = 0 (FULL) to 1000_0000 + // + // Here's this logic expanded to concrete values: + // let special = 0 > byte = 1111_1111 (true) or 0000_0000 (false) + // 1111_1111 | 1000_0000 = 1111_1111 + // 0000_0000 | 1000_0000 = 1000_0000 + unsafe { + let special = neon::vcltz_s8(neon::vreinterpret_s8_u8(self.0)); + Group(neon::vorr_u8(special, neon::vdup_n_u8(0x80))) + } + } +} diff --git a/sgx_tstd/hashbrown/src/raw/sse2.rs b/sgx_tstd/hashbrown/src/raw/sse2.rs index a0bf6da80..956ba5d26 100644 --- a/sgx_tstd/hashbrown/src/raw/sse2.rs +++ b/sgx_tstd/hashbrown/src/raw/sse2.rs @@ -1,28 +1,31 @@ use super::bitmask::BitMask; use super::EMPTY; use core::mem; +use core::num::NonZeroU16; #[cfg(target_arch = "x86")] use core::arch::x86; #[cfg(target_arch = "x86_64")] use core::arch::x86_64 as x86; -pub type BitMaskWord = u16; -pub const BITMASK_STRIDE: usize = 1; -pub const BITMASK_MASK: BitMaskWord = 0xffff; +pub(crate) type BitMaskWord = u16; +pub(crate) type NonZeroBitMaskWord = NonZeroU16; +pub(crate) const BITMASK_STRIDE: usize = 1; +pub(crate) const BITMASK_MASK: BitMaskWord = 0xffff; +pub(crate) const BITMASK_ITER_MASK: BitMaskWord = !0; /// Abstraction over a group of control bytes which can be scanned in /// parallel. /// /// This implementation uses a 128-bit SSE value. #[derive(Copy, Clone)] -pub struct Group(x86::__m128i); +pub(crate) struct Group(x86::__m128i); // FIXME: https://github.com/rust-lang/rust-clippy/issues/3859 #[allow(clippy::use_self)] impl Group { /// Number of bytes in the group. - pub const WIDTH: usize = mem::size_of::(); + pub(crate) const WIDTH: usize = mem::size_of::(); /// Returns a full group of empty bytes, suitable for use as the initial /// value for an empty hash table. @@ -30,7 +33,7 @@ impl Group { /// This is guaranteed to be aligned to the group size. #[inline] #[allow(clippy::items_after_statements)] - pub const fn static_empty() -> &'static [u8; Group::WIDTH] { + pub(crate) const fn static_empty() -> &'static [u8; Group::WIDTH] { #[repr(C)] struct AlignedBytes { _align: [Group; 0], @@ -46,7 +49,7 @@ impl Group { /// Loads a group of bytes starting at the given address. #[inline] #[allow(clippy::cast_ptr_alignment)] // unaligned load - pub unsafe fn load(ptr: *const u8) -> Self { + pub(crate) unsafe fn load(ptr: *const u8) -> Self { Group(x86::_mm_loadu_si128(ptr.cast())) } @@ -54,7 +57,7 @@ impl Group { /// aligned to `mem::align_of::()`. #[inline] #[allow(clippy::cast_ptr_alignment)] - pub unsafe fn load_aligned(ptr: *const u8) -> Self { + pub(crate) unsafe fn load_aligned(ptr: *const u8) -> Self { // FIXME: use align_offset once it stabilizes debug_assert_eq!(ptr as usize & (mem::align_of::() - 1), 0); Group(x86::_mm_load_si128(ptr.cast())) @@ -64,7 +67,7 @@ impl Group { /// aligned to `mem::align_of::()`. #[inline] #[allow(clippy::cast_ptr_alignment)] - pub unsafe fn store_aligned(self, ptr: *mut u8) { + pub(crate) unsafe fn store_aligned(self, ptr: *mut u8) { // FIXME: use align_offset once it stabilizes debug_assert_eq!(ptr as usize & (mem::align_of::() - 1), 0); x86::_mm_store_si128(ptr.cast(), self.0); @@ -73,7 +76,7 @@ impl Group { /// Returns a `BitMask` indicating all bytes in the group which have /// the given value. #[inline] - pub fn match_byte(self, byte: u8) -> BitMask { + pub(crate) fn match_byte(self, byte: u8) -> BitMask { #[allow( clippy::cast_possible_wrap, // byte: u8 as i8 // byte: i32 as u16 @@ -91,14 +94,14 @@ impl Group { /// Returns a `BitMask` indicating all bytes in the group which are /// `EMPTY`. #[inline] - pub fn match_empty(self) -> BitMask { + pub(crate) fn match_empty(self) -> BitMask { self.match_byte(EMPTY) } /// Returns a `BitMask` indicating all bytes in the group which are /// `EMPTY` or `DELETED`. #[inline] - pub fn match_empty_or_deleted(self) -> BitMask { + pub(crate) fn match_empty_or_deleted(self) -> BitMask { #[allow( // byte: i32 as u16 // note: _mm_movemask_epi8 returns a 16-bit mask in a i32, the @@ -114,7 +117,7 @@ impl Group { /// Returns a `BitMask` indicating all bytes in the group which are full. #[inline] - pub fn match_full(&self) -> BitMask { + pub(crate) fn match_full(&self) -> BitMask { self.match_empty_or_deleted().invert() } @@ -123,7 +126,7 @@ impl Group { /// - `DELETED => EMPTY` /// - `FULL => DELETED` #[inline] - pub fn convert_special_to_empty_and_full_to_deleted(self) -> Self { + pub(crate) fn convert_special_to_empty_and_full_to_deleted(self) -> Self { // Map high_bit = 1 (EMPTY or DELETED) to 1111_1111 // and high_bit = 0 (FULL) to 1000_0000 // diff --git a/sgx_tstd/hashbrown/src/rustc_entry.rs b/sgx_tstd/hashbrown/src/rustc_entry.rs index 465db4781..defbd4bb8 100644 --- a/sgx_tstd/hashbrown/src/rustc_entry.rs +++ b/sgx_tstd/hashbrown/src/rustc_entry.rs @@ -1,5 +1,5 @@ use self::RustcEntry::*; -use crate::map::{make_insert_hash, Drain, HashMap, IntoIter, Iter, IterMut}; +use crate::map::{make_hash, Drain, HashMap, IntoIter, Iter, IterMut}; use crate::raw::{Allocator, Bucket, Global, RawTable}; use core::fmt::{self, Debug}; use core::hash::{BuildHasher, Hash}; @@ -9,7 +9,7 @@ impl HashMap where K: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { /// Gets the given key's corresponding entry in the map for in-place manipulation. /// @@ -32,7 +32,7 @@ where /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn rustc_entry(&mut self, key: K) -> RustcEntry<'_, K, V, A> { - let hash = make_insert_hash(&self.hash_builder, &key); + let hash = make_hash(&self.hash_builder, &key); if let Some(elem) = self.table.find(hash, |q| q.0.eq(&key)) { RustcEntry::Occupied(RustcOccupiedEntry { key: Some(key), @@ -56,13 +56,13 @@ where /// A view into a single entry in a map, which may either be vacant or occupied. /// -/// This `enum` is constructed from the [`entry`] method on [`HashMap`]. +/// This `enum` is constructed from the [`rustc_entry`] method on [`HashMap`]. /// /// [`HashMap`]: struct.HashMap.html -/// [`entry`]: struct.HashMap.html#method.rustc_entry +/// [`rustc_entry`]: struct.HashMap.html#method.rustc_entry pub enum RustcEntry<'a, K, V, A = Global> where - A: Allocator + Clone, + A: Allocator, { /// An occupied entry. Occupied(RustcOccupiedEntry<'a, K, V, A>), @@ -71,7 +71,7 @@ where Vacant(RustcVacantEntry<'a, K, V, A>), } -impl Debug for RustcEntry<'_, K, V, A> { +impl Debug for RustcEntry<'_, K, V, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Vacant(ref v) => f.debug_tuple("Entry").field(v).finish(), @@ -86,7 +86,7 @@ impl Debug for RustcEntry<'_, K, V, A> /// [`RustcEntry`]: enum.RustcEntry.html pub struct RustcOccupiedEntry<'a, K, V, A = Global> where - A: Allocator + Clone, + A: Allocator, { key: Option, elem: Bucket<(K, V)>, @@ -97,18 +97,18 @@ unsafe impl Send for RustcOccupiedEntry<'_, K, V, A> where K: Send, V: Send, - A: Allocator + Clone + Send, + A: Allocator + Send, { } unsafe impl Sync for RustcOccupiedEntry<'_, K, V, A> where K: Sync, V: Sync, - A: Allocator + Clone + Sync, + A: Allocator + Sync, { } -impl Debug for RustcOccupiedEntry<'_, K, V, A> { +impl Debug for RustcOccupiedEntry<'_, K, V, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("OccupiedEntry") .field("key", self.key()) @@ -123,20 +123,20 @@ impl Debug for RustcOccupiedEntry<'_, /// [`RustcEntry`]: enum.RustcEntry.html pub struct RustcVacantEntry<'a, K, V, A = Global> where - A: Allocator + Clone, + A: Allocator, { hash: u64, key: K, table: &'a mut RawTable<(K, V), A>, } -impl Debug for RustcVacantEntry<'_, K, V, A> { +impl Debug for RustcVacantEntry<'_, K, V, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("VacantEntry").field(self.key()).finish() } } -impl<'a, K, V, A: Allocator + Clone> RustcEntry<'a, K, V, A> { +impl<'a, K, V, A: Allocator> RustcEntry<'a, K, V, A> { /// Sets the value of the entry, and returns a RustcOccupiedEntry. /// /// # Examples @@ -145,7 +145,7 @@ impl<'a, K, V, A: Allocator + Clone> RustcEntry<'a, K, V, A> { /// use hashbrown::HashMap; /// /// let mut map: HashMap<&str, u32> = HashMap::new(); - /// let entry = map.entry("horseyland").insert(37); + /// let entry = map.rustc_entry("horseyland").insert(37); /// /// assert_eq!(entry.key(), &"horseyland"); /// ``` @@ -265,7 +265,7 @@ impl<'a, K, V, A: Allocator + Clone> RustcEntry<'a, K, V, A> { } } -impl<'a, K, V: Default, A: Allocator + Clone> RustcEntry<'a, K, V, A> { +impl<'a, K, V: Default, A: Allocator> RustcEntry<'a, K, V, A> { /// Ensures a value is in the entry by inserting the default value if empty, /// and returns a mutable reference to the value in the entry. /// @@ -293,7 +293,7 @@ impl<'a, K, V: Default, A: Allocator + Clone> RustcEntry<'a, K, V, A> { } } -impl<'a, K, V, A: Allocator + Clone> RustcOccupiedEntry<'a, K, V, A> { +impl<'a, K, V, A: Allocator> RustcOccupiedEntry<'a, K, V, A> { /// Gets a reference to the key in the entry. /// /// # Examples @@ -330,7 +330,7 @@ impl<'a, K, V, A: Allocator + Clone> RustcOccupiedEntry<'a, K, V, A> { /// ``` #[cfg_attr(feature = "inline-more", inline)] pub fn remove_entry(self) -> (K, V) { - unsafe { self.table.remove(self.elem) } + unsafe { self.table.remove(self.elem).0 } } /// Gets a reference to the value in the entry. @@ -431,10 +431,8 @@ impl<'a, K, V, A: Allocator + Clone> RustcOccupiedEntry<'a, K, V, A> { /// assert_eq!(map["poneyland"], 15); /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn insert(&mut self, mut value: V) -> V { - let old_value = self.get_mut(); - mem::swap(&mut value, old_value); - value + pub fn insert(&mut self, value: V) -> V { + mem::replace(self.get_mut(), value) } /// Takes the value out of the entry, and returns it. @@ -520,7 +518,7 @@ impl<'a, K, V, A: Allocator + Clone> RustcOccupiedEntry<'a, K, V, A> { } } -impl<'a, K, V, A: Allocator + Clone> RustcVacantEntry<'a, K, V, A> { +impl<'a, K, V, A: Allocator> RustcVacantEntry<'a, K, V, A> { /// Gets a reference to the key that would be used when inserting a value /// through the `RustcVacantEntry`. /// diff --git a/sgx_tstd/hashbrown/src/scopeguard.rs b/sgx_tstd/hashbrown/src/scopeguard.rs index ccdc0c511..382d06043 100644 --- a/sgx_tstd/hashbrown/src/scopeguard.rs +++ b/sgx_tstd/hashbrown/src/scopeguard.rs @@ -1,5 +1,9 @@ // Extracted from the scopeguard crate -use core::ops::{Deref, DerefMut}; +use core::{ + mem::ManuallyDrop, + ops::{Deref, DerefMut}, + ptr, +}; pub struct ScopeGuard where @@ -17,6 +21,25 @@ where ScopeGuard { dropfn, value } } +impl ScopeGuard +where + F: FnMut(&mut T), +{ + #[inline] + pub fn into_inner(guard: Self) -> T { + // Cannot move out of Drop-implementing types, so + // ptr::read the value out of a ManuallyDrop + // Don't use mem::forget as that might invalidate value + let guard = ManuallyDrop::new(guard); + unsafe { + let value = ptr::read(&guard.value); + // read the closure so that it is dropped + let _ = ptr::read(&guard.dropfn); + value + } + } +} + impl Deref for ScopeGuard where F: FnMut(&mut T), diff --git a/sgx_tstd/hashbrown/src/set.rs b/sgx_tstd/hashbrown/src/set.rs index bb8305483..09b45fd9f 100644 --- a/sgx_tstd/hashbrown/src/set.rs +++ b/sgx_tstd/hashbrown/src/set.rs @@ -1,14 +1,14 @@ -use crate::TryReserveError; +#[cfg(feature = "raw")] +use crate::raw::RawTable; +use crate::{Equivalent, TryReserveError}; use alloc::borrow::ToOwned; -use core::borrow::Borrow; use core::fmt; use core::hash::{BuildHasher, Hash}; use core::iter::{Chain, FromIterator, FusedIterator}; -use core::mem; use core::ops::{BitAnd, BitOr, BitXor, Sub}; -use super::map::{self, ConsumeAllOnDrop, DefaultHashBuilder, DrainFilterInner, HashMap, Keys}; -use crate::raw::{Allocator, Global}; +use super::map::{self, DefaultHashBuilder, HashMap, Keys}; +use crate::raw::{Allocator, Global, RawExtractIf}; // Future Optimization (FIXME!) // ============================= @@ -112,7 +112,7 @@ use crate::raw::{Allocator, Global}; /// [`HashMap`]: struct.HashMap.html /// [`PartialEq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html /// [`RefCell`]: https://doc.rust-lang.org/std/cell/struct.RefCell.html -pub struct HashSet { +pub struct HashSet { pub(crate) map: HashMap, } @@ -135,6 +135,18 @@ impl HashSet { /// The hash set is initially created with a capacity of 0, so it will not allocate until it /// is first inserted into. /// + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashSet` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashSet`], for example with + /// [`with_hasher`](HashSet::with_hasher) method. + /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// /// # Examples /// /// ``` @@ -153,6 +165,18 @@ impl HashSet { /// The hash set will be able to hold at least `capacity` elements without /// reallocating. If `capacity` is 0, the hash set will not allocate. /// + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashSet` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashSet`], for example with + /// [`with_capacity_and_hasher`](HashSet::with_capacity_and_hasher) method. + /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// /// # Examples /// /// ``` @@ -169,12 +193,24 @@ impl HashSet { } #[cfg(feature = "ahash")] -impl HashSet { +impl HashSet { /// Creates an empty `HashSet`. /// /// The hash set is initially created with a capacity of 0, so it will not allocate until it /// is first inserted into. /// + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashSet` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashSet`], for example with + /// [`with_hasher_in`](HashSet::with_hasher_in) method. + /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// /// # Examples /// /// ``` @@ -193,6 +229,18 @@ impl HashSet { /// The hash set will be able to hold at least `capacity` elements without /// reallocating. If `capacity` is 0, the hash set will not allocate. /// + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashSet` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashSet`], for example with + /// [`with_capacity_and_hasher_in`](HashSet::with_capacity_and_hasher_in) method. + /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// /// # Examples /// /// ``` @@ -208,7 +256,7 @@ impl HashSet { } } -impl HashSet { +impl HashSet { /// Returns the number of elements the set can hold without reallocating. /// /// # Examples @@ -331,8 +379,11 @@ impl HashSet { /// In other words, move all elements `e` such that `f(&e)` returns `true` out /// into another iterator. /// - /// When the returned DrainedFilter is dropped, any remaining elements that satisfy - /// the predicate are dropped from the set. + /// If the returned `ExtractIf` is not exhausted, e.g. because it is dropped without iterating + /// or the iteration short-circuits, then the remaining elements will be retained. + /// Use [`retain()`] with a negated predicate if you do not need the returned iterator. + /// + /// [`retain()`]: HashSet::retain /// /// # Examples /// @@ -340,7 +391,7 @@ impl HashSet { /// use hashbrown::HashSet; /// /// let mut set: HashSet = (0..8).collect(); - /// let drained: HashSet = set.drain_filter(|v| v % 2 == 0).collect(); + /// let drained: HashSet = set.extract_if(|v| v % 2 == 0).collect(); /// /// let mut evens = drained.into_iter().collect::>(); /// let mut odds = set.into_iter().collect::>(); @@ -351,13 +402,13 @@ impl HashSet { /// assert_eq!(odds, vec![1, 3, 5, 7]); /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn drain_filter(&mut self, f: F) -> DrainFilter<'_, T, F, A> + pub fn extract_if(&mut self, f: F) -> ExtractIf<'_, T, F, A> where F: FnMut(&T) -> bool, { - DrainFilter { + ExtractIf { f, - inner: DrainFilterInner { + inner: RawExtractIf { iter: unsafe { self.map.table.iter() }, table: &mut self.map.table, }, @@ -386,16 +437,23 @@ impl HashSet { /// Creates a new empty hash set which will use the given hasher to hash /// keys. /// - /// The hash set is also created with the default initial capacity. + /// The hash set is initially created with a capacity of 0, so it will not + /// allocate until it is first inserted into. /// - /// Warning: `hasher` is normally randomly generated, and - /// is designed to allow `HashSet`s to be resistant to attacks that - /// cause many collisions and very poor performance. Setting it - /// manually using this function can expose a DoS attack vector. + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashSet` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashSet`]. /// /// The `hash_builder` passed should implement the [`BuildHasher`] trait for - /// the HashMap to be useful, see its documentation for details. + /// the HashSet to be useful, see its documentation for details. /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// [`BuildHasher`]: https://doc.rust-lang.org/std/hash/trait.BuildHasher.html /// /// # Examples /// @@ -407,8 +465,6 @@ impl HashSet { /// let mut set = HashSet::with_hasher(s); /// set.insert(2); /// ``` - /// - /// [`BuildHasher`]: ../../std/hash/trait.BuildHasher.html #[cfg_attr(feature = "inline-more", inline)] pub const fn with_hasher(hasher: S) -> Self { Self { @@ -422,13 +478,20 @@ impl HashSet { /// The hash set will be able to hold at least `capacity` elements without /// reallocating. If `capacity` is 0, the hash set will not allocate. /// - /// Warning: `hasher` is normally randomly generated, and - /// is designed to allow `HashSet`s to be resistant to attacks that - /// cause many collisions and very poor performance. Setting it - /// manually using this function can expose a DoS attack vector. + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashSet` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashSet`]. /// /// The `hash_builder` passed should implement the [`BuildHasher`] trait for - /// the HashMap to be useful, see its documentation for details. + /// the HashSet to be useful, see its documentation for details. + /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// [`BuildHasher`]: https://doc.rust-lang.org/std/hash/trait.BuildHasher.html /// /// # Examples /// @@ -440,8 +503,6 @@ impl HashSet { /// let mut set = HashSet::with_capacity_and_hasher(10, s); /// set.insert(1); /// ``` - /// - /// [`BuildHasher`]: ../../std/hash/trait.BuildHasher.html #[cfg_attr(feature = "inline-more", inline)] pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Self { Self { @@ -452,7 +513,7 @@ impl HashSet { impl HashSet where - A: Allocator + Clone, + A: Allocator, { /// Returns a reference to the underlying allocator. #[inline] @@ -463,12 +524,23 @@ where /// Creates a new empty hash set which will use the given hasher to hash /// keys. /// - /// The hash set is also created with the default initial capacity. + /// The hash set is initially created with a capacity of 0, so it will not + /// allocate until it is first inserted into. /// - /// Warning: `hasher` is normally randomly generated, and - /// is designed to allow `HashSet`s to be resistant to attacks that - /// cause many collisions and very poor performance. Setting it - /// manually using this function can expose a DoS attack vector. + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashSet` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashSet`]. + /// + /// The `hash_builder` passed should implement the [`BuildHasher`] trait for + /// the HashSet to be useful, see its documentation for details. + /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// [`BuildHasher`]: https://doc.rust-lang.org/std/hash/trait.BuildHasher.html /// /// # Examples /// @@ -481,7 +553,7 @@ where /// set.insert(2); /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn with_hasher_in(hasher: S, alloc: A) -> Self { + pub const fn with_hasher_in(hasher: S, alloc: A) -> Self { Self { map: HashMap::with_hasher_in(hasher, alloc), } @@ -493,10 +565,20 @@ where /// The hash set will be able to hold at least `capacity` elements without /// reallocating. If `capacity` is 0, the hash set will not allocate. /// - /// Warning: `hasher` is normally randomly generated, and - /// is designed to allow `HashSet`s to be resistant to attacks that - /// cause many collisions and very poor performance. Setting it - /// manually using this function can expose a DoS attack vector. + /// # HashDoS resistance + /// + /// The `hash_builder` normally use a fixed key by default and that does + /// not allow the `HashSet` to be protected against attacks such as [`HashDoS`]. + /// Users who require HashDoS resistance should explicitly use + /// [`ahash::RandomState`] or [`std::collections::hash_map::RandomState`] + /// as the hasher when creating a [`HashSet`]. + /// + /// The `hash_builder` passed should implement the [`BuildHasher`] trait for + /// the HashSet to be useful, see its documentation for details. + /// + /// [`HashDoS`]: https://en.wikipedia.org/wiki/Collision_attack + /// [`std::collections::hash_map::RandomState`]: https://doc.rust-lang.org/std/collections/hash_map/struct.RandomState.html + /// [`BuildHasher`]: https://doc.rust-lang.org/std/hash/trait.BuildHasher.html /// /// # Examples /// @@ -539,7 +621,7 @@ impl HashSet where T: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { /// Reserves capacity for at least `additional` more elements to be inserted /// in the `HashSet`. The collection may reserve more space to avoid @@ -547,7 +629,12 @@ where /// /// # Panics /// - /// Panics if the new allocation size overflows `usize`. + /// Panics if the new capacity exceeds [`isize::MAX`] bytes and [`abort`] the program + /// in case of allocation error. Use [`try_reserve`](HashSet::try_reserve) instead + /// if you want to handle memory allocation failure. + /// + /// [`isize::MAX`]: https://doc.rust-lang.org/std/primitive.isize.html + /// [`abort`]: https://doc.rust-lang.org/alloc/alloc/fn.handle_alloc_error.html /// /// # Examples /// @@ -773,8 +860,7 @@ where #[cfg_attr(feature = "inline-more", inline)] pub fn contains(&self, value: &Q) -> bool where - T: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { self.map.contains_key(value) } @@ -800,8 +886,7 @@ where #[cfg_attr(feature = "inline-more", inline)] pub fn get(&self, value: &Q) -> Option<&T> where - T: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.map.get_key_value(value) { @@ -856,8 +941,7 @@ where #[inline] pub fn get_or_insert_owned(&mut self, value: &Q) -> &T where - T: Borrow, - Q: Hash + Eq + ToOwned, + Q: Hash + Equivalent + ToOwned, { // Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with // `get`. Key mutation is "raw" because you're not supposed to affect `Eq` or `Hash`. @@ -889,8 +973,7 @@ where #[cfg_attr(feature = "inline-more", inline)] pub fn get_or_insert_with(&mut self, value: &Q, f: F) -> &T where - T: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, F: FnOnce(&Q) -> T, { // Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with @@ -902,6 +985,47 @@ where .0 } + /// Gets the given value's corresponding entry in the set for in-place manipulation. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashSet; + /// use hashbrown::hash_set::Entry::*; + /// + /// let mut singles = HashSet::new(); + /// let mut dupes = HashSet::new(); + /// + /// for ch in "a short treatise on fungi".chars() { + /// if let Vacant(dupe_entry) = dupes.entry(ch) { + /// // We haven't already seen a duplicate, so + /// // check if we've at least seen it once. + /// match singles.entry(ch) { + /// Vacant(single_entry) => { + /// // We found a new character for the first time. + /// single_entry.insert() + /// } + /// Occupied(single_entry) => { + /// // We've already seen this once, "move" it to dupes. + /// single_entry.remove(); + /// dupe_entry.insert(); + /// } + /// } + /// } + /// } + /// + /// assert!(!singles.contains(&'t') && dupes.contains(&'t')); + /// assert!(singles.contains(&'u') && !dupes.contains(&'u')); + /// assert!(!singles.contains(&'v') && !dupes.contains(&'v')); + /// ``` + #[cfg_attr(feature = "inline-more", inline)] + pub fn entry(&mut self, value: T) -> Entry<'_, T, S, A> { + match self.map.entry(value) { + map::Entry::Occupied(entry) => Entry::Occupied(OccupiedEntry { inner: entry }), + map::Entry::Vacant(entry) => Entry::Vacant(VacantEntry { inner: entry }), + } + } + /// Returns `true` if `self` has no elements in common with `other`. /// This is equivalent to checking for an empty intersection. /// @@ -1065,8 +1189,7 @@ where #[cfg_attr(feature = "inline-more", inline)] pub fn remove(&mut self, value: &Q) -> bool where - T: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { self.map.remove(value).is_some() } @@ -1092,8 +1215,7 @@ where #[cfg_attr(feature = "inline-more", inline)] pub fn take(&mut self, value: &Q) -> Option where - T: Borrow, - Q: Hash + Eq, + Q: Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.map.remove_entry(value) { @@ -1103,11 +1225,53 @@ where } } +impl HashSet { + /// Returns a reference to the [`RawTable`] used underneath [`HashSet`]. + /// This function is only available if the `raw` feature of the crate is enabled. + /// + /// # Note + /// + /// Calling this function is safe, but using the raw hash table API may require + /// unsafe functions or blocks. + /// + /// `RawTable` API gives the lowest level of control under the set that can be useful + /// for extending the HashSet's API, but may lead to *[undefined behavior]*. + /// + /// [`HashSet`]: struct.HashSet.html + /// [`RawTable`]: crate::raw::RawTable + /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + #[cfg(feature = "raw")] + #[cfg_attr(feature = "inline-more", inline)] + pub fn raw_table(&self) -> &RawTable<(T, ()), A> { + self.map.raw_table() + } + + /// Returns a mutable reference to the [`RawTable`] used underneath [`HashSet`]. + /// This function is only available if the `raw` feature of the crate is enabled. + /// + /// # Note + /// + /// Calling this function is safe, but using the raw hash table API may require + /// unsafe functions or blocks. + /// + /// `RawTable` API gives the lowest level of control under the set that can be useful + /// for extending the HashSet's API, but may lead to *[undefined behavior]*. + /// + /// [`HashSet`]: struct.HashSet.html + /// [`RawTable`]: crate::raw::RawTable + /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + #[cfg(feature = "raw")] + #[cfg_attr(feature = "inline-more", inline)] + pub fn raw_table_mut(&mut self) -> &mut RawTable<(T, ()), A> { + self.map.raw_table_mut() + } +} + impl PartialEq for HashSet where T: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { fn eq(&self, other: &Self) -> bool { if self.len() != other.len() { @@ -1122,14 +1286,14 @@ impl Eq for HashSet where T: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { } impl fmt::Debug for HashSet where T: fmt::Debug, - A: Allocator + Clone, + A: Allocator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_set().entries(self.iter()).finish() @@ -1138,7 +1302,7 @@ where impl From> for HashSet where - A: Allocator + Clone, + A: Allocator, { fn from(map: HashMap) -> Self { Self { map } @@ -1149,7 +1313,7 @@ impl FromIterator for HashSet where T: Eq + Hash, S: BuildHasher + Default, - A: Default + Allocator + Clone, + A: Default + Allocator, { #[cfg_attr(feature = "inline-more", inline)] fn from_iter>(iter: I) -> Self { @@ -1164,7 +1328,7 @@ where impl From<[T; N]> for HashSet where T: Eq + Hash, - A: Default + Allocator + Clone, + A: Default + Allocator, { /// # Examples /// @@ -1184,7 +1348,7 @@ impl Extend for HashSet where T: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { #[cfg_attr(feature = "inline-more", inline)] fn extend>(&mut self, iter: I) { @@ -1208,7 +1372,7 @@ impl<'a, T, S, A> Extend<&'a T> for HashSet where T: 'a + Eq + Hash + Copy, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { #[cfg_attr(feature = "inline-more", inline)] fn extend>(&mut self, iter: I) { @@ -1231,7 +1395,7 @@ where impl Default for HashSet where S: Default, - A: Default + Allocator + Clone, + A: Default + Allocator, { /// Creates an empty `HashSet` with the `Default` value for the hasher. #[cfg_attr(feature = "inline-more", inline)] @@ -1246,7 +1410,7 @@ impl BitOr<&HashSet> for &HashSet where T: Eq + Hash + Clone, S: BuildHasher + Default, - A: Allocator + Clone, + A: Allocator, { type Output = HashSet; @@ -1279,7 +1443,7 @@ impl BitAnd<&HashSet> for &HashSet where T: Eq + Hash + Clone, S: BuildHasher + Default, - A: Allocator + Clone, + A: Allocator, { type Output = HashSet; @@ -1390,7 +1554,7 @@ pub struct Iter<'a, K> { /// /// [`HashSet`]: struct.HashSet.html /// [`into_iter`]: struct.HashSet.html#method.into_iter -pub struct IntoIter { +pub struct IntoIter { iter: map::IntoIter, } @@ -1401,23 +1565,24 @@ pub struct IntoIter { /// /// [`HashSet`]: struct.HashSet.html /// [`drain`]: struct.HashSet.html#method.drain -pub struct Drain<'a, K, A: Allocator + Clone = Global> { +pub struct Drain<'a, K, A: Allocator = Global> { iter: map::Drain<'a, K, (), A>, } /// A draining iterator over entries of a `HashSet` which don't satisfy the predicate `f`. /// -/// This `struct` is created by the [`drain_filter`] method on [`HashSet`]. See its +/// This `struct` is created by the [`extract_if`] method on [`HashSet`]. See its /// documentation for more. /// -/// [`drain_filter`]: struct.HashSet.html#method.drain_filter +/// [`extract_if`]: struct.HashSet.html#method.extract_if /// [`HashSet`]: struct.HashSet.html -pub struct DrainFilter<'a, K, F, A: Allocator + Clone = Global> +#[must_use = "Iterators are lazy unless consumed"] +pub struct ExtractIf<'a, K, F, A: Allocator = Global> where F: FnMut(&K) -> bool, { f: F, - inner: DrainFilterInner<'a, K, (), A>, + inner: RawExtractIf<'a, (K, ()), A>, } /// A lazy iterator producing elements in the intersection of `HashSet`s. @@ -1427,7 +1592,7 @@ where /// /// [`HashSet`]: struct.HashSet.html /// [`intersection`]: struct.HashSet.html#method.intersection -pub struct Intersection<'a, T, S, A: Allocator + Clone = Global> { +pub struct Intersection<'a, T, S, A: Allocator = Global> { // iterator of the first set iter: Iter<'a, T>, // the second set @@ -1441,7 +1606,7 @@ pub struct Intersection<'a, T, S, A: Allocator + Clone = Global> { /// /// [`HashSet`]: struct.HashSet.html /// [`difference`]: struct.HashSet.html#method.difference -pub struct Difference<'a, T, S, A: Allocator + Clone = Global> { +pub struct Difference<'a, T, S, A: Allocator = Global> { // iterator of the first set iter: Iter<'a, T>, // the second set @@ -1455,7 +1620,7 @@ pub struct Difference<'a, T, S, A: Allocator + Clone = Global> { /// /// [`HashSet`]: struct.HashSet.html /// [`symmetric_difference`]: struct.HashSet.html#method.symmetric_difference -pub struct SymmetricDifference<'a, T, S, A: Allocator + Clone = Global> { +pub struct SymmetricDifference<'a, T, S, A: Allocator = Global> { iter: Chain, Difference<'a, T, S, A>>, } @@ -1466,11 +1631,11 @@ pub struct SymmetricDifference<'a, T, S, A: Allocator + Clone = Global> { /// /// [`HashSet`]: struct.HashSet.html /// [`union`]: struct.HashSet.html#method.union -pub struct Union<'a, T, S, A: Allocator + Clone = Global> { +pub struct Union<'a, T, S, A: Allocator = Global> { iter: Chain, Difference<'a, T, S, A>>, } -impl<'a, T, S, A: Allocator + Clone> IntoIterator for &'a HashSet { +impl<'a, T, S, A: Allocator> IntoIterator for &'a HashSet { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -1480,7 +1645,7 @@ impl<'a, T, S, A: Allocator + Clone> IntoIterator for &'a HashSet { } } -impl IntoIterator for HashSet { +impl IntoIterator for HashSet { type Item = T; type IntoIter = IntoIter; @@ -1546,7 +1711,7 @@ impl fmt::Debug for Iter<'_, K> { } } -impl Iterator for IntoIter { +impl Iterator for IntoIter { type Item = K; #[cfg_attr(feature = "inline-more", inline)] @@ -1562,22 +1727,22 @@ impl Iterator for IntoIter { self.iter.size_hint() } } -impl ExactSizeIterator for IntoIter { +impl ExactSizeIterator for IntoIter { #[cfg_attr(feature = "inline-more", inline)] fn len(&self) -> usize { self.iter.len() } } -impl FusedIterator for IntoIter {} +impl FusedIterator for IntoIter {} -impl fmt::Debug for IntoIter { +impl fmt::Debug for IntoIter { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let entries_iter = self.iter.iter().map(|(k, _)| k); f.debug_list().entries(entries_iter).finish() } } -impl Iterator for Drain<'_, K, A> { +impl Iterator for Drain<'_, K, A> { type Item = K; #[cfg_attr(feature = "inline-more", inline)] @@ -1593,36 +1758,22 @@ impl Iterator for Drain<'_, K, A> { self.iter.size_hint() } } -impl ExactSizeIterator for Drain<'_, K, A> { +impl ExactSizeIterator for Drain<'_, K, A> { #[cfg_attr(feature = "inline-more", inline)] fn len(&self) -> usize { self.iter.len() } } -impl FusedIterator for Drain<'_, K, A> {} +impl FusedIterator for Drain<'_, K, A> {} -impl fmt::Debug for Drain<'_, K, A> { +impl fmt::Debug for Drain<'_, K, A> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let entries_iter = self.iter.iter().map(|(k, _)| k); f.debug_list().entries(entries_iter).finish() } } -impl<'a, K, F, A: Allocator + Clone> Drop for DrainFilter<'a, K, F, A> -where - F: FnMut(&K) -> bool, -{ - #[cfg_attr(feature = "inline-more", inline)] - fn drop(&mut self) { - while let Some(item) = self.next() { - let guard = ConsumeAllOnDrop(self); - drop(item); - mem::forget(guard); - } - } -} - -impl Iterator for DrainFilter<'_, K, F, A> +impl Iterator for ExtractIf<'_, K, F, A> where F: FnMut(&K) -> bool, { @@ -1630,9 +1781,9 @@ where #[cfg_attr(feature = "inline-more", inline)] fn next(&mut self) -> Option { - let f = &mut self.f; - let (k, _) = self.inner.next(&mut |k, _| f(k))?; - Some(k) + self.inner + .next(|&mut (ref k, ())| (self.f)(k)) + .map(|(k, ())| k) } #[inline] @@ -1641,12 +1792,9 @@ where } } -impl FusedIterator for DrainFilter<'_, K, F, A> where - F: FnMut(&K) -> bool -{ -} +impl FusedIterator for ExtractIf<'_, K, F, A> where F: FnMut(&K) -> bool {} -impl Clone for Intersection<'_, T, S, A> { +impl Clone for Intersection<'_, T, S, A> { #[cfg_attr(feature = "inline-more", inline)] fn clone(&self) -> Self { Intersection { @@ -1660,7 +1808,7 @@ impl<'a, T, S, A> Iterator for Intersection<'a, T, S, A> where T: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { type Item = &'a T; @@ -1685,7 +1833,7 @@ impl fmt::Debug for Intersection<'_, T, S, A> where T: fmt::Debug + Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.clone()).finish() @@ -1696,11 +1844,11 @@ impl FusedIterator for Intersection<'_, T, S, A> where T: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { } -impl Clone for Difference<'_, T, S, A> { +impl Clone for Difference<'_, T, S, A> { #[cfg_attr(feature = "inline-more", inline)] fn clone(&self) -> Self { Difference { @@ -1714,7 +1862,7 @@ impl<'a, T, S, A> Iterator for Difference<'a, T, S, A> where T: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { type Item = &'a T; @@ -1739,7 +1887,7 @@ impl FusedIterator for Difference<'_, T, S, A> where T: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { } @@ -1747,14 +1895,14 @@ impl fmt::Debug for Difference<'_, T, S, A> where T: fmt::Debug + Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.clone()).finish() } } -impl Clone for SymmetricDifference<'_, T, S, A> { +impl Clone for SymmetricDifference<'_, T, S, A> { #[cfg_attr(feature = "inline-more", inline)] fn clone(&self) -> Self { SymmetricDifference { @@ -1767,7 +1915,7 @@ impl<'a, T, S, A> Iterator for SymmetricDifference<'a, T, S, A> where T: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { type Item = &'a T; @@ -1785,7 +1933,7 @@ impl FusedIterator for SymmetricDifference<'_, T, S, A> where T: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { } @@ -1793,14 +1941,14 @@ impl fmt::Debug for SymmetricDifference<'_, T, S, A> where T: fmt::Debug + Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.clone()).finish() } } -impl Clone for Union<'_, T, S, A> { +impl Clone for Union<'_, T, S, A> { #[cfg_attr(feature = "inline-more", inline)] fn clone(&self) -> Self { Union { @@ -1813,7 +1961,7 @@ impl FusedIterator for Union<'_, T, S, A> where T: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { } @@ -1821,7 +1969,7 @@ impl fmt::Debug for Union<'_, T, S, A> where T: fmt::Debug + Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.clone()).finish() @@ -1832,7 +1980,7 @@ impl<'a, T, S, A> Iterator for Union<'a, T, S, A> where T: Eq + Hash, S: BuildHasher, - A: Allocator + Clone, + A: Allocator, { type Item = &'a T; @@ -1846,6 +1994,406 @@ where } } +/// A view into a single entry in a set, which may either be vacant or occupied. +/// +/// This `enum` is constructed from the [`entry`] method on [`HashSet`]. +/// +/// [`HashSet`]: struct.HashSet.html +/// [`entry`]: struct.HashSet.html#method.entry +/// +/// # Examples +/// +/// ``` +/// use hashbrown::hash_set::{Entry, HashSet, OccupiedEntry}; +/// +/// let mut set = HashSet::new(); +/// set.extend(["a", "b", "c"]); +/// assert_eq!(set.len(), 3); +/// +/// // Existing value (insert) +/// let entry: Entry<_, _> = set.entry("a"); +/// let _raw_o: OccupiedEntry<_, _> = entry.insert(); +/// assert_eq!(set.len(), 3); +/// // Nonexistent value (insert) +/// set.entry("d").insert(); +/// +/// // Existing value (or_insert) +/// set.entry("b").or_insert(); +/// // Nonexistent value (or_insert) +/// set.entry("e").or_insert(); +/// +/// println!("Our HashSet: {:?}", set); +/// +/// let mut vec: Vec<_> = set.iter().copied().collect(); +/// // The `Iter` iterator produces items in arbitrary order, so the +/// // items must be sorted to test them against a sorted array. +/// vec.sort_unstable(); +/// assert_eq!(vec, ["a", "b", "c", "d", "e"]); +/// ``` +pub enum Entry<'a, T, S, A = Global> +where + A: Allocator, +{ + /// An occupied entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_set::{Entry, HashSet}; + /// let mut set: HashSet<_> = ["a", "b"].into(); + /// + /// match set.entry("a") { + /// Entry::Vacant(_) => unreachable!(), + /// Entry::Occupied(_) => { } + /// } + /// ``` + Occupied(OccupiedEntry<'a, T, S, A>), + + /// A vacant entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_set::{Entry, HashSet}; + /// let mut set: HashSet<&str> = HashSet::new(); + /// + /// match set.entry("a") { + /// Entry::Occupied(_) => unreachable!(), + /// Entry::Vacant(_) => { } + /// } + /// ``` + Vacant(VacantEntry<'a, T, S, A>), +} + +impl fmt::Debug for Entry<'_, T, S, A> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self { + Entry::Vacant(ref v) => f.debug_tuple("Entry").field(v).finish(), + Entry::Occupied(ref o) => f.debug_tuple("Entry").field(o).finish(), + } + } +} + +/// A view into an occupied entry in a `HashSet`. +/// It is part of the [`Entry`] enum. +/// +/// [`Entry`]: enum.Entry.html +/// +/// # Examples +/// +/// ``` +/// use hashbrown::hash_set::{Entry, HashSet, OccupiedEntry}; +/// +/// let mut set = HashSet::new(); +/// set.extend(["a", "b", "c"]); +/// +/// let _entry_o: OccupiedEntry<_, _> = set.entry("a").insert(); +/// assert_eq!(set.len(), 3); +/// +/// // Existing key +/// match set.entry("a") { +/// Entry::Vacant(_) => unreachable!(), +/// Entry::Occupied(view) => { +/// assert_eq!(view.get(), &"a"); +/// } +/// } +/// +/// assert_eq!(set.len(), 3); +/// +/// // Existing key (take) +/// match set.entry("c") { +/// Entry::Vacant(_) => unreachable!(), +/// Entry::Occupied(view) => { +/// assert_eq!(view.remove(), "c"); +/// } +/// } +/// assert_eq!(set.get(&"c"), None); +/// assert_eq!(set.len(), 2); +/// ``` +pub struct OccupiedEntry<'a, T, S, A: Allocator = Global> { + inner: map::OccupiedEntry<'a, T, (), S, A>, +} + +impl fmt::Debug for OccupiedEntry<'_, T, S, A> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("OccupiedEntry") + .field("value", self.get()) + .finish() + } +} + +/// A view into a vacant entry in a `HashSet`. +/// It is part of the [`Entry`] enum. +/// +/// [`Entry`]: enum.Entry.html +/// +/// # Examples +/// +/// ``` +/// use hashbrown::hash_set::{Entry, HashSet, VacantEntry}; +/// +/// let mut set = HashSet::<&str>::new(); +/// +/// let entry_v: VacantEntry<_, _> = match set.entry("a") { +/// Entry::Vacant(view) => view, +/// Entry::Occupied(_) => unreachable!(), +/// }; +/// entry_v.insert(); +/// assert!(set.contains("a") && set.len() == 1); +/// +/// // Nonexistent key (insert) +/// match set.entry("b") { +/// Entry::Vacant(view) => view.insert(), +/// Entry::Occupied(_) => unreachable!(), +/// } +/// assert!(set.contains("b") && set.len() == 2); +/// ``` +pub struct VacantEntry<'a, T, S, A: Allocator = Global> { + inner: map::VacantEntry<'a, T, (), S, A>, +} + +impl fmt::Debug for VacantEntry<'_, T, S, A> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_tuple("VacantEntry").field(self.get()).finish() + } +} + +impl<'a, T, S, A: Allocator> Entry<'a, T, S, A> { + /// Sets the value of the entry, and returns an OccupiedEntry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashSet; + /// + /// let mut set: HashSet<&str> = HashSet::new(); + /// let entry = set.entry("horseyland").insert(); + /// + /// assert_eq!(entry.get(), &"horseyland"); + /// ``` + #[cfg_attr(feature = "inline-more", inline)] + pub fn insert(self) -> OccupiedEntry<'a, T, S, A> + where + T: Hash, + S: BuildHasher, + { + match self { + Entry::Occupied(entry) => entry, + Entry::Vacant(entry) => entry.insert_entry(), + } + } + + /// Ensures a value is in the entry by inserting if it was vacant. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashSet; + /// + /// let mut set: HashSet<&str> = HashSet::new(); + /// + /// // nonexistent key + /// set.entry("poneyland").or_insert(); + /// assert!(set.contains("poneyland")); + /// + /// // existing key + /// set.entry("poneyland").or_insert(); + /// assert!(set.contains("poneyland")); + /// assert_eq!(set.len(), 1); + /// ``` + #[cfg_attr(feature = "inline-more", inline)] + pub fn or_insert(self) + where + T: Hash, + S: BuildHasher, + { + if let Entry::Vacant(entry) = self { + entry.insert(); + } + } + + /// Returns a reference to this entry's value. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashSet; + /// + /// let mut set: HashSet<&str> = HashSet::new(); + /// set.entry("poneyland").or_insert(); + /// // existing key + /// assert_eq!(set.entry("poneyland").get(), &"poneyland"); + /// // nonexistent key + /// assert_eq!(set.entry("horseland").get(), &"horseland"); + /// ``` + #[cfg_attr(feature = "inline-more", inline)] + pub fn get(&self) -> &T { + match *self { + Entry::Occupied(ref entry) => entry.get(), + Entry::Vacant(ref entry) => entry.get(), + } + } +} + +impl OccupiedEntry<'_, T, S, A> { + /// Gets a reference to the value in the entry. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_set::{Entry, HashSet}; + /// + /// let mut set: HashSet<&str> = HashSet::new(); + /// set.entry("poneyland").or_insert(); + /// + /// match set.entry("poneyland") { + /// Entry::Vacant(_) => panic!(), + /// Entry::Occupied(entry) => assert_eq!(entry.get(), &"poneyland"), + /// } + /// ``` + #[cfg_attr(feature = "inline-more", inline)] + pub fn get(&self) -> &T { + self.inner.key() + } + + /// Takes the value out of the entry, and returns it. + /// Keeps the allocated memory for reuse. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashSet; + /// use hashbrown::hash_set::Entry; + /// + /// let mut set: HashSet<&str> = HashSet::new(); + /// // The set is empty + /// assert!(set.is_empty() && set.capacity() == 0); + /// + /// set.entry("poneyland").or_insert(); + /// let capacity_before_remove = set.capacity(); + /// + /// if let Entry::Occupied(o) = set.entry("poneyland") { + /// assert_eq!(o.remove(), "poneyland"); + /// } + /// + /// assert_eq!(set.contains("poneyland"), false); + /// // Now set hold none elements but capacity is equal to the old one + /// assert!(set.len() == 0 && set.capacity() == capacity_before_remove); + /// ``` + #[cfg_attr(feature = "inline-more", inline)] + pub fn remove(self) -> T { + self.inner.remove_entry().0 + } + + /// Replaces the entry, returning the old value. The new value in the hash map will be + /// the value used to create this entry. + /// + /// # Panics + /// + /// Will panic if this OccupiedEntry was created through [`Entry::insert`]. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_set::{Entry, HashSet}; + /// use std::rc::Rc; + /// + /// let mut set: HashSet> = HashSet::new(); + /// let key_one = Rc::new("Stringthing".to_string()); + /// let key_two = Rc::new("Stringthing".to_string()); + /// + /// set.insert(key_one.clone()); + /// assert!(Rc::strong_count(&key_one) == 2 && Rc::strong_count(&key_two) == 1); + /// + /// match set.entry(key_two.clone()) { + /// Entry::Occupied(entry) => { + /// let old_key: Rc = entry.replace(); + /// assert!(Rc::ptr_eq(&key_one, &old_key)); + /// } + /// Entry::Vacant(_) => panic!(), + /// } + /// + /// assert!(Rc::strong_count(&key_one) == 1 && Rc::strong_count(&key_two) == 2); + /// assert!(set.contains(&"Stringthing".to_owned())); + /// ``` + #[cfg_attr(feature = "inline-more", inline)] + pub fn replace(self) -> T { + self.inner.replace_key() + } +} + +impl<'a, T, S, A: Allocator> VacantEntry<'a, T, S, A> { + /// Gets a reference to the value that would be used when inserting + /// through the `VacantEntry`. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashSet; + /// + /// let mut set: HashSet<&str> = HashSet::new(); + /// assert_eq!(set.entry("poneyland").get(), &"poneyland"); + /// ``` + #[cfg_attr(feature = "inline-more", inline)] + pub fn get(&self) -> &T { + self.inner.key() + } + + /// Take ownership of the value. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::hash_set::{Entry, HashSet}; + /// + /// let mut set: HashSet<&str> = HashSet::new(); + /// + /// match set.entry("poneyland") { + /// Entry::Occupied(_) => panic!(), + /// Entry::Vacant(v) => assert_eq!(v.into_value(), "poneyland"), + /// } + /// ``` + #[cfg_attr(feature = "inline-more", inline)] + pub fn into_value(self) -> T { + self.inner.into_key() + } + + /// Sets the value of the entry with the VacantEntry's value. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashSet; + /// use hashbrown::hash_set::Entry; + /// + /// let mut set: HashSet<&str> = HashSet::new(); + /// + /// if let Entry::Vacant(o) = set.entry("poneyland") { + /// o.insert(); + /// } + /// assert!(set.contains("poneyland")); + /// ``` + #[cfg_attr(feature = "inline-more", inline)] + pub fn insert(self) + where + T: Hash, + S: BuildHasher, + { + self.inner.insert(()); + } + + #[cfg_attr(feature = "inline-more", inline)] + fn insert_entry(self) -> OccupiedEntry<'a, T, S, A> + where + T: Hash, + S: BuildHasher, + { + OccupiedEntry { + inner: self.inner.insert_entry(()), + } + } +} + #[allow(dead_code)] fn assert_covariance() { fn set<'new>(v: HashSet<&'static str>) -> HashSet<&'new str> { @@ -1854,34 +2402,30 @@ fn assert_covariance() { fn iter<'a, 'new>(v: Iter<'a, &'static str>) -> Iter<'a, &'new str> { v } - fn into_iter<'new, A: Allocator + Clone>( - v: IntoIter<&'static str, A>, - ) -> IntoIter<&'new str, A> { + fn into_iter<'new, A: Allocator>(v: IntoIter<&'static str, A>) -> IntoIter<&'new str, A> { v } - fn difference<'a, 'new, A: Allocator + Clone>( + fn difference<'a, 'new, A: Allocator>( v: Difference<'a, &'static str, DefaultHashBuilder, A>, ) -> Difference<'a, &'new str, DefaultHashBuilder, A> { v } - fn symmetric_difference<'a, 'new, A: Allocator + Clone>( + fn symmetric_difference<'a, 'new, A: Allocator>( v: SymmetricDifference<'a, &'static str, DefaultHashBuilder, A>, ) -> SymmetricDifference<'a, &'new str, DefaultHashBuilder, A> { v } - fn intersection<'a, 'new, A: Allocator + Clone>( + fn intersection<'a, 'new, A: Allocator>( v: Intersection<'a, &'static str, DefaultHashBuilder, A>, ) -> Intersection<'a, &'new str, DefaultHashBuilder, A> { v } - fn union<'a, 'new, A: Allocator + Clone>( + fn union<'a, 'new, A: Allocator>( v: Union<'a, &'static str, DefaultHashBuilder, A>, ) -> Union<'a, &'new str, DefaultHashBuilder, A> { v } - fn drain<'new, A: Allocator + Clone>( - d: Drain<'static, &'static str, A>, - ) -> Drain<'new, &'new str, A> { + fn drain<'new, A: Allocator>(d: Drain<'static, &'static str, A>) -> Drain<'new, &'new str, A> { d } } @@ -2172,10 +2716,10 @@ mod test_set { set.insert(1); set.insert(2); - let set_str = format!("{:?}", set); + let set_str = format!("{set:?}"); assert!(set_str == "{1, 2}" || set_str == "{2, 1}"); - assert_eq!(format!("{:?}", empty), "{}"); + assert_eq!(format!("{empty:?}"), "{}"); } #[test] @@ -2250,11 +2794,12 @@ mod test_set { } #[test] + #[allow(clippy::needless_borrow)] fn test_extend_ref() { let mut a = HashSet::new(); a.insert(1); - a.extend(&[2, 3, 4]); + a.extend([2, 3, 4]); assert_eq!(a.len(), 4); assert!(a.contains(&1)); @@ -2289,10 +2834,10 @@ mod test_set { } #[test] - fn test_drain_filter() { + fn test_extract_if() { { let mut set: HashSet = (0..8).collect(); - let drained = set.drain_filter(|&k| k % 2 == 0); + let drained = set.extract_if(|&k| k % 2 == 0); let mut out = drained.collect::>(); out.sort_unstable(); assert_eq!(vec![0, 2, 4, 6], out); @@ -2300,7 +2845,7 @@ mod test_set { } { let mut set: HashSet = (0..8).collect(); - drop(set.drain_filter(|&k| k % 2 == 0)); + set.extract_if(|&k| k % 2 == 0).for_each(drop); assert_eq!(set.len(), 4, "Removes non-matching items on drop"); } } @@ -2346,4 +2891,11 @@ mod test_set { set.insert(i); } } + + #[test] + fn collect() { + // At the time of writing, this hits the ZST case in from_base_index + // (and without the `map`, it does not). + let mut _set: HashSet<_> = (0..3).map(|_| ()).collect(); + } } diff --git a/sgx_tstd/hashbrown/src/table.rs b/sgx_tstd/hashbrown/src/table.rs new file mode 100644 index 000000000..bfb5dd989 --- /dev/null +++ b/sgx_tstd/hashbrown/src/table.rs @@ -0,0 +1,2030 @@ +use core::{fmt, iter::FusedIterator, marker::PhantomData}; + +use crate::{ + raw::{ + Allocator, Bucket, Global, InsertSlot, RawDrain, RawExtractIf, RawIntoIter, RawIter, + RawTable, + }, + TryReserveError, +}; + +/// Low-level hash table with explicit hashing. +/// +/// The primary use case for this type over [`HashMap`] or [`HashSet`] is to +/// support types that do not implement the [`Hash`] and [`Eq`] traits, but +/// instead require additional data not contained in the key itself to compute a +/// hash and compare two elements for equality. +/// +/// Examples of when this can be useful include: +/// - An `IndexMap` implementation where indices into a `Vec` are stored as +/// elements in a `HashTable`. Hashing and comparing the elements +/// requires indexing the associated `Vec` to get the actual value referred to +/// by the index. +/// - Avoiding re-computing a hash when it is already known. +/// - Mutating the key of an element in a way that doesn't affect its hash. +/// +/// To achieve this, `HashTable` methods that search for an element in the table +/// require a hash value and equality function to be explicitly passed in as +/// arguments. The method will then iterate over the elements with the given +/// hash and call the equality function on each of them, until a match is found. +/// +/// In most cases, a `HashTable` will not be exposed directly in an API. It will +/// instead be wrapped in a helper type which handles the work of calculating +/// hash values and comparing elements. +/// +/// Due to its low-level nature, this type provides fewer guarantees than +/// [`HashMap`] and [`HashSet`]. Specifically, the API allows you to shoot +/// yourself in the foot by having multiple elements with identical keys in the +/// table. The table itself will still function correctly and lookups will +/// arbitrarily return one of the matching elements. However you should avoid +/// doing this because it changes the runtime of hash table operations from +/// `O(1)` to `O(k)` where `k` is the number of duplicate entries. +/// +/// [`HashMap`]: super::HashMap +/// [`HashSet`]: super::HashSet +pub struct HashTable +where + A: Allocator, +{ + pub(crate) raw: RawTable, +} + +impl HashTable { + /// Creates an empty `HashTable`. + /// + /// The hash table is initially created with a capacity of 0, so it will not allocate until it + /// is first inserted into. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashTable; + /// let mut table: HashTable<&str> = HashTable::new(); + /// assert_eq!(table.len(), 0); + /// assert_eq!(table.capacity(), 0); + /// ``` + pub const fn new() -> Self { + Self { + raw: RawTable::new(), + } + } + + /// Creates an empty `HashTable` with the specified capacity. + /// + /// The hash table will be able to hold at least `capacity` elements without + /// reallocating. If `capacity` is 0, the hash table will not allocate. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashTable; + /// let mut table: HashTable<&str> = HashTable::with_capacity(10); + /// assert_eq!(table.len(), 0); + /// assert!(table.capacity() >= 10); + /// ``` + pub fn with_capacity(capacity: usize) -> Self { + Self { + raw: RawTable::with_capacity(capacity), + } + } +} + +impl HashTable +where + A: Allocator, +{ + /// Creates an empty `HashTable` using the given allocator. + /// + /// The hash table is initially created with a capacity of 0, so it will not allocate until it + /// is first inserted into. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use bumpalo::Bump; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let bump = Bump::new(); + /// let mut table = HashTable::new_in(&bump); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// + /// // The created HashTable holds none elements + /// assert_eq!(table.len(), 0); + /// + /// // The created HashTable also doesn't allocate memory + /// assert_eq!(table.capacity(), 0); + /// + /// // Now we insert element inside created HashTable + /// table.insert_unique(hasher(&"One"), "One", hasher); + /// // We can see that the HashTable holds 1 element + /// assert_eq!(table.len(), 1); + /// // And it also allocates some capacity + /// assert!(table.capacity() > 1); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub const fn new_in(alloc: A) -> Self { + Self { + raw: RawTable::new_in(alloc), + } + } + + /// Creates an empty `HashTable` with the specified capacity using the given allocator. + /// + /// The hash table will be able to hold at least `capacity` elements without + /// reallocating. If `capacity` is 0, the hash table will not allocate. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use bumpalo::Bump; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let bump = Bump::new(); + /// let mut table = HashTable::with_capacity_in(5, &bump); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// + /// // The created HashTable holds none elements + /// assert_eq!(table.len(), 0); + /// // But it can hold at least 5 elements without reallocating + /// let empty_map_capacity = table.capacity(); + /// assert!(empty_map_capacity >= 5); + /// + /// // Now we insert some 5 elements inside created HashTable + /// table.insert_unique(hasher(&"One"), "One", hasher); + /// table.insert_unique(hasher(&"Two"), "Two", hasher); + /// table.insert_unique(hasher(&"Three"), "Three", hasher); + /// table.insert_unique(hasher(&"Four"), "Four", hasher); + /// table.insert_unique(hasher(&"Five"), "Five", hasher); + /// + /// // We can see that the HashTable holds 5 elements + /// assert_eq!(table.len(), 5); + /// // But its capacity isn't changed + /// assert_eq!(table.capacity(), empty_map_capacity) + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn with_capacity_in(capacity: usize, alloc: A) -> Self { + Self { + raw: RawTable::with_capacity_in(capacity, alloc), + } + } + + /// Returns a reference to the underlying allocator. + pub fn allocator(&self) -> &A { + self.raw.allocator() + } + + /// Returns a reference to an entry in the table with the given hash and + /// which satisfies the equality function passed. + /// + /// This method will call `eq` for all entries with the given hash, but may + /// also call it for entries with a different hash. `eq` should only return + /// true for the desired entry, at which point the search is stopped. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// table.insert_unique(hasher(&1), 1, hasher); + /// table.insert_unique(hasher(&2), 2, hasher); + /// table.insert_unique(hasher(&3), 3, hasher); + /// assert_eq!(table.find(hasher(&2), |&val| val == 2), Some(&2)); + /// assert_eq!(table.find(hasher(&4), |&val| val == 4), None); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn find(&self, hash: u64, eq: impl FnMut(&T) -> bool) -> Option<&T> { + self.raw.get(hash, eq) + } + + /// Returns a mutable reference to an entry in the table with the given hash + /// and which satisfies the equality function passed. + /// + /// This method will call `eq` for all entries with the given hash, but may + /// also call it for entries with a different hash. `eq` should only return + /// true for the desired entry, at which point the search is stopped. + /// + /// When mutating an entry, you should ensure that it still retains the same + /// hash value as when it was inserted, otherwise lookups of that entry may + /// fail to find it. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// table.insert_unique(hasher(&1), (1, "a"), |val| hasher(&val.0)); + /// if let Some(val) = table.find_mut(hasher(&1), |val| val.0 == 1) { + /// val.1 = "b"; + /// } + /// assert_eq!(table.find(hasher(&1), |val| val.0 == 1), Some(&(1, "b"))); + /// assert_eq!(table.find(hasher(&2), |val| val.0 == 2), None); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn find_mut(&mut self, hash: u64, eq: impl FnMut(&T) -> bool) -> Option<&mut T> { + self.raw.get_mut(hash, eq) + } + + /// Returns an `OccupiedEntry` for an entry in the table with the given hash + /// and which satisfies the equality function passed. + /// + /// This can be used to remove the entry from the table. Call + /// [`HashTable::entry`] instead if you wish to insert an entry if the + /// lookup fails. + /// + /// This method will call `eq` for all entries with the given hash, but may + /// also call it for entries with a different hash. `eq` should only return + /// true for the desired entry, at which point the search is stopped. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// table.insert_unique(hasher(&1), (1, "a"), |val| hasher(&val.0)); + /// if let Ok(entry) = table.find_entry(hasher(&1), |val| val.0 == 1) { + /// entry.remove(); + /// } + /// assert_eq!(table.find(hasher(&1), |val| val.0 == 1), None); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn find_entry( + &mut self, + hash: u64, + eq: impl FnMut(&T) -> bool, + ) -> Result, AbsentEntry<'_, T, A>> { + match self.raw.find(hash, eq) { + Some(bucket) => Ok(OccupiedEntry { + hash, + bucket, + table: self, + }), + None => Err(AbsentEntry { table: self }), + } + } + + /// Returns an `Entry` for an entry in the table with the given hash + /// and which satisfies the equality function passed. + /// + /// This can be used to remove the entry from the table, or insert a new + /// entry with the given hash if one doesn't already exist. + /// + /// This method will call `eq` for all entries with the given hash, but may + /// also call it for entries with a different hash. `eq` should only return + /// true for the desired entry, at which point the search is stopped. + /// + /// This method may grow the table in preparation for an insertion. Call + /// [`HashTable::find_entry`] if this is undesirable. + /// + /// `hasher` is called if entries need to be moved or copied to a new table. + /// This must return the same hash value that each entry was inserted with. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::hash_table::Entry; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// table.insert_unique(hasher(&1), (1, "a"), |val| hasher(&val.0)); + /// if let Entry::Occupied(entry) = table.entry(hasher(&1), |val| val.0 == 1, |val| hasher(&val.0)) + /// { + /// entry.remove(); + /// } + /// if let Entry::Vacant(entry) = table.entry(hasher(&2), |val| val.0 == 2, |val| hasher(&val.0)) { + /// entry.insert((2, "b")); + /// } + /// assert_eq!(table.find(hasher(&1), |val| val.0 == 1), None); + /// assert_eq!(table.find(hasher(&2), |val| val.0 == 2), Some(&(2, "b"))); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn entry( + &mut self, + hash: u64, + eq: impl FnMut(&T) -> bool, + hasher: impl Fn(&T) -> u64, + ) -> Entry<'_, T, A> { + match self.raw.find_or_find_insert_slot(hash, eq, hasher) { + Ok(bucket) => Entry::Occupied(OccupiedEntry { + hash, + bucket, + table: self, + }), + Err(insert_slot) => Entry::Vacant(VacantEntry { + hash, + insert_slot, + table: self, + }), + } + } + + /// Inserts an element into the `HashTable` with the given hash value, but + /// without checking whether an equivalent element already exists within the + /// table. + /// + /// `hasher` is called if entries need to be moved or copied to a new table. + /// This must return the same hash value that each entry was inserted with. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut v = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// v.insert_unique(hasher(&1), 1, hasher); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn insert_unique( + &mut self, + hash: u64, + value: T, + hasher: impl Fn(&T) -> u64, + ) -> OccupiedEntry<'_, T, A> { + let bucket = self.raw.insert(hash, value, hasher); + OccupiedEntry { + hash, + bucket, + table: self, + } + } + + /// Clears the table, removing all values. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut v = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// v.insert_unique(hasher(&1), 1, hasher); + /// v.clear(); + /// assert!(v.is_empty()); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn clear(&mut self) { + self.raw.clear(); + } + + /// Shrinks the capacity of the table as much as possible. It will drop + /// down as much as possible while maintaining the internal rules + /// and possibly leaving some space in accordance with the resize policy. + /// + /// `hasher` is called if entries need to be moved or copied to a new table. + /// This must return the same hash value that each entry was inserted with. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table = HashTable::with_capacity(100); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// table.insert_unique(hasher(&1), 1, hasher); + /// table.insert_unique(hasher(&2), 2, hasher); + /// assert!(table.capacity() >= 100); + /// table.shrink_to_fit(hasher); + /// assert!(table.capacity() >= 2); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn shrink_to_fit(&mut self, hasher: impl Fn(&T) -> u64) { + self.raw.shrink_to(self.len(), hasher) + } + + /// Shrinks the capacity of the table with a lower limit. It will drop + /// down no lower than the supplied limit while maintaining the internal rules + /// and possibly leaving some space in accordance with the resize policy. + /// + /// `hasher` is called if entries need to be moved or copied to a new table. + /// This must return the same hash value that each entry was inserted with. + /// + /// Panics if the current capacity is smaller than the supplied + /// minimum capacity. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table = HashTable::with_capacity(100); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// table.insert_unique(hasher(&1), 1, hasher); + /// table.insert_unique(hasher(&2), 2, hasher); + /// assert!(table.capacity() >= 100); + /// table.shrink_to(10, hasher); + /// assert!(table.capacity() >= 10); + /// table.shrink_to(0, hasher); + /// assert!(table.capacity() >= 2); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn shrink_to(&mut self, min_capacity: usize, hasher: impl Fn(&T) -> u64) { + self.raw.shrink_to(min_capacity, hasher); + } + + /// Reserves capacity for at least `additional` more elements to be inserted + /// in the `HashTable`. The collection may reserve more space to avoid + /// frequent reallocations. + /// + /// `hasher` is called if entries need to be moved or copied to a new table. + /// This must return the same hash value that each entry was inserted with. + /// + /// # Panics + /// + /// Panics if the new capacity exceeds [`isize::MAX`] bytes and [`abort`] the program + /// in case of allocation error. Use [`try_reserve`](HashTable::try_reserve) instead + /// if you want to handle memory allocation failure. + /// + /// [`isize::MAX`]: https://doc.rust-lang.org/std/primitive.isize.html + /// [`abort`]: https://doc.rust-lang.org/alloc/alloc/fn.handle_alloc_error.html + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table: HashTable = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// table.reserve(10, hasher); + /// assert!(table.capacity() >= 10); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn reserve(&mut self, additional: usize, hasher: impl Fn(&T) -> u64) { + self.raw.reserve(additional, hasher) + } + + /// Tries to reserve capacity for at least `additional` more elements to be inserted + /// in the given `HashTable`. The collection may reserve more space to avoid + /// frequent reallocations. + /// + /// `hasher` is called if entries need to be moved or copied to a new table. + /// This must return the same hash value that each entry was inserted with. + /// + /// # Errors + /// + /// If the capacity overflows, or the allocator reports a failure, then an error + /// is returned. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table: HashTable = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// table + /// .try_reserve(10, hasher) + /// .expect("why is the test harness OOMing on 10 bytes?"); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn try_reserve( + &mut self, + additional: usize, + hasher: impl Fn(&T) -> u64, + ) -> Result<(), TryReserveError> { + self.raw.try_reserve(additional, hasher) + } + + /// Returns the number of elements the table can hold without reallocating. + /// + /// # Examples + /// + /// ``` + /// use hashbrown::HashTable; + /// let table: HashTable = HashTable::with_capacity(100); + /// assert!(table.capacity() >= 100); + /// ``` + pub fn capacity(&self) -> usize { + self.raw.capacity() + } + + /// Returns the number of elements in the table. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// let mut v = HashTable::new(); + /// assert_eq!(v.len(), 0); + /// v.insert_unique(hasher(&1), 1, hasher); + /// assert_eq!(v.len(), 1); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn len(&self) -> usize { + self.raw.len() + } + + /// Returns `true` if the set contains no elements. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// let mut v = HashTable::new(); + /// assert!(v.is_empty()); + /// v.insert_unique(hasher(&1), 1, hasher); + /// assert!(!v.is_empty()); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn is_empty(&self) -> bool { + self.raw.is_empty() + } + + /// An iterator visiting all elements in arbitrary order. + /// The iterator element type is `&'a T`. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// table.insert_unique(hasher(&"a"), "b", hasher); + /// table.insert_unique(hasher(&"b"), "b", hasher); + /// + /// // Will print in an arbitrary order. + /// for x in table.iter() { + /// println!("{}", x); + /// } + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn iter(&self) -> Iter<'_, T> { + Iter { + inner: unsafe { self.raw.iter() }, + marker: PhantomData, + } + } + + /// An iterator visiting all elements in arbitrary order, + /// with mutable references to the elements. + /// The iterator element type is `&'a mut T`. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// table.insert_unique(hasher(&1), 1, hasher); + /// table.insert_unique(hasher(&2), 2, hasher); + /// table.insert_unique(hasher(&3), 3, hasher); + /// + /// // Update all values + /// for val in table.iter_mut() { + /// *val *= 2; + /// } + /// + /// assert_eq!(table.len(), 3); + /// let mut vec: Vec = Vec::new(); + /// + /// for val in &table { + /// println!("val: {}", val); + /// vec.push(*val); + /// } + /// + /// // The `Iter` iterator produces items in arbitrary order, so the + /// // items must be sorted to test them against a sorted array. + /// vec.sort_unstable(); + /// assert_eq!(vec, [2, 4, 6]); + /// + /// assert_eq!(table.len(), 3); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn iter_mut(&mut self) -> IterMut<'_, T> { + IterMut { + inner: unsafe { self.raw.iter() }, + marker: PhantomData, + } + } + + /// Retains only the elements specified by the predicate. + /// + /// In other words, remove all elements `e` such that `f(&e)` returns `false`. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// for x in 1..=6 { + /// table.insert_unique(hasher(&x), x, hasher); + /// } + /// table.retain(|&mut x| x % 2 == 0); + /// assert_eq!(table.len(), 3); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn retain(&mut self, mut f: impl FnMut(&mut T) -> bool) { + // Here we only use `iter` as a temporary, preventing use-after-free + unsafe { + for item in self.raw.iter() { + if !f(item.as_mut()) { + self.raw.erase(item); + } + } + } + } + + /// Clears the set, returning all elements in an iterator. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// for x in 1..=3 { + /// table.insert_unique(hasher(&x), x, hasher); + /// } + /// assert!(!table.is_empty()); + /// + /// // print 1, 2, 3 in an arbitrary order + /// for i in table.drain() { + /// println!("{}", i); + /// } + /// + /// assert!(table.is_empty()); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn drain(&mut self) -> Drain<'_, T, A> { + Drain { + inner: self.raw.drain(), + } + } + + /// Drains elements which are true under the given predicate, + /// and returns an iterator over the removed items. + /// + /// In other words, move all elements `e` such that `f(&e)` returns `true` out + /// into another iterator. + /// + /// If the returned `ExtractIf` is not exhausted, e.g. because it is dropped without iterating + /// or the iteration short-circuits, then the remaining elements will be retained. + /// Use [`retain()`] with a negated predicate if you do not need the returned iterator. + /// + /// [`retain()`]: HashTable::retain + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// for x in 0..8 { + /// table.insert_unique(hasher(&x), x, hasher); + /// } + /// let drained: Vec = table.extract_if(|&mut v| v % 2 == 0).collect(); + /// + /// let mut evens = drained.into_iter().collect::>(); + /// let mut odds = table.into_iter().collect::>(); + /// evens.sort(); + /// odds.sort(); + /// + /// assert_eq!(evens, vec![0, 2, 4, 6]); + /// assert_eq!(odds, vec![1, 3, 5, 7]); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn extract_if(&mut self, f: F) -> ExtractIf<'_, T, F, A> + where + F: FnMut(&mut T) -> bool, + { + ExtractIf { + f, + inner: RawExtractIf { + iter: unsafe { self.raw.iter() }, + table: &mut self.raw, + }, + } + } + + /// Attempts to get mutable references to `N` values in the map at once. + /// + /// The `eq` argument should be a closure such that `eq(i, k)` returns true if `k` is equal to + /// the `i`th key to be looked up. + /// + /// Returns an array of length `N` with the results of each query. For soundness, at most one + /// mutable reference will be returned to any value. `None` will be returned if any of the + /// keys are duplicates or missing. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::hash_table::Entry; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut libraries: HashTable<(&str, u32)> = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// for (k, v) in [ + /// ("Bodleian Library", 1602), + /// ("Athenæum", 1807), + /// ("Herzogin-Anna-Amalia-Bibliothek", 1691), + /// ("Library of Congress", 1800), + /// ] { + /// libraries.insert_unique(hasher(&k), (k, v), |(k, _)| hasher(&k)); + /// } + /// + /// let keys = ["Athenæum", "Library of Congress"]; + /// let got = libraries.get_many_mut(keys.map(|k| hasher(&k)), |i, val| keys[i] == val.0); + /// assert_eq!( + /// got, + /// Some([&mut ("Athenæum", 1807), &mut ("Library of Congress", 1800),]), + /// ); + /// + /// // Missing keys result in None + /// let keys = ["Athenæum", "New York Public Library"]; + /// let got = libraries.get_many_mut(keys.map(|k| hasher(&k)), |i, val| keys[i] == val.0); + /// assert_eq!(got, None); + /// + /// // Duplicate keys result in None + /// let keys = ["Athenæum", "Athenæum"]; + /// let got = libraries.get_many_mut(keys.map(|k| hasher(&k)), |i, val| keys[i] == val.0); + /// assert_eq!(got, None); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn get_many_mut( + &mut self, + hashes: [u64; N], + eq: impl FnMut(usize, &T) -> bool, + ) -> Option<[&'_ mut T; N]> { + self.raw.get_many_mut(hashes, eq) + } + + /// Attempts to get mutable references to `N` values in the map at once, without validating that + /// the values are unique. + /// + /// The `eq` argument should be a closure such that `eq(i, k)` returns true if `k` is equal to + /// the `i`th key to be looked up. + /// + /// Returns an array of length `N` with the results of each query. `None` will be returned if + /// any of the keys are missing. + /// + /// For a safe alternative see [`get_many_mut`](`HashTable::get_many_mut`). + /// + /// # Safety + /// + /// Calling this method with overlapping keys is *[undefined behavior]* even if the resulting + /// references are not used. + /// + /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::hash_table::Entry; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut libraries: HashTable<(&str, u32)> = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// for (k, v) in [ + /// ("Bodleian Library", 1602), + /// ("Athenæum", 1807), + /// ("Herzogin-Anna-Amalia-Bibliothek", 1691), + /// ("Library of Congress", 1800), + /// ] { + /// libraries.insert_unique(hasher(&k), (k, v), |(k, _)| hasher(&k)); + /// } + /// + /// let keys = ["Athenæum", "Library of Congress"]; + /// let got = libraries.get_many_mut(keys.map(|k| hasher(&k)), |i, val| keys[i] == val.0); + /// assert_eq!( + /// got, + /// Some([&mut ("Athenæum", 1807), &mut ("Library of Congress", 1800),]), + /// ); + /// + /// // Missing keys result in None + /// let keys = ["Athenæum", "New York Public Library"]; + /// let got = libraries.get_many_mut(keys.map(|k| hasher(&k)), |i, val| keys[i] == val.0); + /// assert_eq!(got, None); + /// + /// // Duplicate keys result in None + /// let keys = ["Athenæum", "Athenæum"]; + /// let got = libraries.get_many_mut(keys.map(|k| hasher(&k)), |i, val| keys[i] == val.0); + /// assert_eq!(got, None); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub unsafe fn get_many_unchecked_mut( + &mut self, + hashes: [u64; N], + eq: impl FnMut(usize, &T) -> bool, + ) -> Option<[&'_ mut T; N]> { + self.raw.get_many_unchecked_mut(hashes, eq) + } +} + +impl IntoIterator for HashTable +where + A: Allocator, +{ + type Item = T; + type IntoIter = IntoIter; + + fn into_iter(self) -> IntoIter { + IntoIter { + inner: self.raw.into_iter(), + } + } +} + +impl<'a, T, A> IntoIterator for &'a HashTable +where + A: Allocator, +{ + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +impl<'a, T, A> IntoIterator for &'a mut HashTable +where + A: Allocator, +{ + type Item = &'a mut T; + type IntoIter = IterMut<'a, T>; + + fn into_iter(self) -> IterMut<'a, T> { + self.iter_mut() + } +} + +impl Default for HashTable +where + A: Allocator + Default, +{ + fn default() -> Self { + Self { + raw: Default::default(), + } + } +} + +impl Clone for HashTable +where + T: Clone, + A: Allocator + Clone, +{ + fn clone(&self) -> Self { + Self { + raw: self.raw.clone(), + } + } +} + +impl fmt::Debug for HashTable +where + T: fmt::Debug, + A: Allocator, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_set().entries(self.iter()).finish() + } +} + +/// A view into a single entry in a table, which may either be vacant or occupied. +/// +/// This `enum` is constructed from the [`entry`] method on [`HashTable`]. +/// +/// [`HashTable`]: struct.HashTable.html +/// [`entry`]: struct.HashTable.html#method.entry +/// +/// # Examples +/// +/// ``` +/// # #[cfg(feature = "nightly")] +/// # fn test() { +/// use ahash::AHasher; +/// use hashbrown::hash_table::{Entry, HashTable, OccupiedEntry}; +/// use std::hash::{BuildHasher, BuildHasherDefault}; +/// +/// let mut table = HashTable::new(); +/// let hasher = BuildHasherDefault::::default(); +/// let hasher = |val: &_| hasher.hash_one(val); +/// for x in ["a", "b", "c"] { +/// table.insert_unique(hasher(&x), x, hasher); +/// } +/// assert_eq!(table.len(), 3); +/// +/// // Existing value (insert) +/// let entry: Entry<_> = table.entry(hasher(&"a"), |&x| x == "a", hasher); +/// let _raw_o: OccupiedEntry<_, _> = entry.insert("a"); +/// assert_eq!(table.len(), 3); +/// // Nonexistent value (insert) +/// table.entry(hasher(&"d"), |&x| x == "d", hasher).insert("d"); +/// +/// // Existing value (or_insert) +/// table +/// .entry(hasher(&"b"), |&x| x == "b", hasher) +/// .or_insert("b"); +/// // Nonexistent value (or_insert) +/// table +/// .entry(hasher(&"e"), |&x| x == "e", hasher) +/// .or_insert("e"); +/// +/// println!("Our HashTable: {:?}", table); +/// +/// let mut vec: Vec<_> = table.iter().copied().collect(); +/// // The `Iter` iterator produces items in arbitrary order, so the +/// // items must be sorted to test them against a sorted array. +/// vec.sort_unstable(); +/// assert_eq!(vec, ["a", "b", "c", "d", "e"]); +/// # } +/// # fn main() { +/// # #[cfg(feature = "nightly")] +/// # test() +/// # } +/// ``` +pub enum Entry<'a, T, A = Global> +where + A: Allocator, +{ + /// An occupied entry. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::hash_table::{Entry, HashTable, OccupiedEntry}; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// for x in ["a", "b"] { + /// table.insert_unique(hasher(&x), x, hasher); + /// } + /// + /// match table.entry(hasher(&"a"), |&x| x == "a", hasher) { + /// Entry::Vacant(_) => unreachable!(), + /// Entry::Occupied(_) => {} + /// } + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + Occupied(OccupiedEntry<'a, T, A>), + + /// A vacant entry. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::hash_table::{Entry, HashTable, OccupiedEntry}; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table = HashTable::<&str>::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// + /// match table.entry(hasher(&"a"), |&x| x == "a", hasher) { + /// Entry::Vacant(_) => {} + /// Entry::Occupied(_) => unreachable!(), + /// } + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + Vacant(VacantEntry<'a, T, A>), +} + +impl fmt::Debug for Entry<'_, T, A> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self { + Entry::Vacant(ref v) => f.debug_tuple("Entry").field(v).finish(), + Entry::Occupied(ref o) => f.debug_tuple("Entry").field(o).finish(), + } + } +} + +impl<'a, T, A> Entry<'a, T, A> +where + A: Allocator, +{ + /// Sets the value of the entry, replacing any existing value if there is + /// one, and returns an [`OccupiedEntry`]. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table: HashTable<&str> = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// + /// let entry = table + /// .entry(hasher(&"horseyland"), |&x| x == "horseyland", hasher) + /// .insert("horseyland"); + /// + /// assert_eq!(entry.get(), &"horseyland"); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn insert(self, value: T) -> OccupiedEntry<'a, T, A> { + match self { + Entry::Occupied(mut entry) => { + *entry.get_mut() = value; + entry + } + Entry::Vacant(entry) => entry.insert(value), + } + } + + /// Ensures a value is in the entry by inserting if it was vacant. + /// + /// Returns an [`OccupiedEntry`] pointing to the now-occupied entry. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table: HashTable<&str> = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// + /// // nonexistent key + /// table + /// .entry(hasher(&"poneyland"), |&x| x == "poneyland", hasher) + /// .or_insert("poneyland"); + /// assert!(table + /// .find(hasher(&"poneyland"), |&x| x == "poneyland") + /// .is_some()); + /// + /// // existing key + /// table + /// .entry(hasher(&"poneyland"), |&x| x == "poneyland", hasher) + /// .or_insert("poneyland"); + /// assert!(table + /// .find(hasher(&"poneyland"), |&x| x == "poneyland") + /// .is_some()); + /// assert_eq!(table.len(), 1); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn or_insert(self, default: T) -> OccupiedEntry<'a, T, A> { + match self { + Entry::Occupied(entry) => entry, + Entry::Vacant(entry) => entry.insert(default), + } + } + + /// Ensures a value is in the entry by inserting the result of the default function if empty.. + /// + /// Returns an [`OccupiedEntry`] pointing to the now-occupied entry. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table: HashTable = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// + /// table + /// .entry(hasher("poneyland"), |x| x == "poneyland", |val| hasher(val)) + /// .or_insert_with(|| "poneyland".to_string()); + /// + /// assert!(table + /// .find(hasher(&"poneyland"), |x| x == "poneyland") + /// .is_some()); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn or_insert_with(self, default: impl FnOnce() -> T) -> OccupiedEntry<'a, T, A> { + match self { + Entry::Occupied(entry) => entry, + Entry::Vacant(entry) => entry.insert(default()), + } + } + + /// Provides in-place mutable access to an occupied entry before any + /// potential inserts into the table. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table: HashTable<(&str, u32)> = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// + /// table + /// .entry( + /// hasher(&"poneyland"), + /// |&(x, _)| x == "poneyland", + /// |(k, _)| hasher(&k), + /// ) + /// .and_modify(|(_, v)| *v += 1) + /// .or_insert(("poneyland", 42)); + /// assert_eq!( + /// table.find(hasher(&"poneyland"), |&(k, _)| k == "poneyland"), + /// Some(&("poneyland", 42)) + /// ); + /// + /// table + /// .entry( + /// hasher(&"poneyland"), + /// |&(x, _)| x == "poneyland", + /// |(k, _)| hasher(&k), + /// ) + /// .and_modify(|(_, v)| *v += 1) + /// .or_insert(("poneyland", 42)); + /// assert_eq!( + /// table.find(hasher(&"poneyland"), |&(k, _)| k == "poneyland"), + /// Some(&("poneyland", 43)) + /// ); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn and_modify(self, f: impl FnOnce(&mut T)) -> Self { + match self { + Entry::Occupied(mut entry) => { + f(entry.get_mut()); + Entry::Occupied(entry) + } + Entry::Vacant(entry) => Entry::Vacant(entry), + } + } +} + +/// A view into an occupied entry in a `HashTable`. +/// It is part of the [`Entry`] enum. +/// +/// [`Entry`]: enum.Entry.html +/// +/// # Examples +/// +/// ``` +/// # #[cfg(feature = "nightly")] +/// # fn test() { +/// use ahash::AHasher; +/// use hashbrown::hash_table::{Entry, HashTable, OccupiedEntry}; +/// use std::hash::{BuildHasher, BuildHasherDefault}; +/// +/// let mut table = HashTable::new(); +/// let hasher = BuildHasherDefault::::default(); +/// let hasher = |val: &_| hasher.hash_one(val); +/// for x in ["a", "b", "c"] { +/// table.insert_unique(hasher(&x), x, hasher); +/// } +/// assert_eq!(table.len(), 3); +/// +/// let _entry_o: OccupiedEntry<_, _> = table.find_entry(hasher(&"a"), |&x| x == "a").unwrap(); +/// assert_eq!(table.len(), 3); +/// +/// // Existing key +/// match table.entry(hasher(&"a"), |&x| x == "a", hasher) { +/// Entry::Vacant(_) => unreachable!(), +/// Entry::Occupied(view) => { +/// assert_eq!(view.get(), &"a"); +/// } +/// } +/// +/// assert_eq!(table.len(), 3); +/// +/// // Existing key (take) +/// match table.entry(hasher(&"c"), |&x| x == "c", hasher) { +/// Entry::Vacant(_) => unreachable!(), +/// Entry::Occupied(view) => { +/// assert_eq!(view.remove().0, "c"); +/// } +/// } +/// assert_eq!(table.find(hasher(&"c"), |&x| x == "c"), None); +/// assert_eq!(table.len(), 2); +/// # } +/// # fn main() { +/// # #[cfg(feature = "nightly")] +/// # test() +/// # } +/// ``` +pub struct OccupiedEntry<'a, T, A = Global> +where + A: Allocator, +{ + hash: u64, + bucket: Bucket, + table: &'a mut HashTable, +} + +unsafe impl Send for OccupiedEntry<'_, T, A> +where + T: Send, + A: Send + Allocator, +{ +} +unsafe impl Sync for OccupiedEntry<'_, T, A> +where + T: Sync, + A: Sync + Allocator, +{ +} + +impl fmt::Debug for OccupiedEntry<'_, T, A> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("OccupiedEntry") + .field("value", self.get()) + .finish() + } +} + +impl<'a, T, A> OccupiedEntry<'a, T, A> +where + A: Allocator, +{ + /// Takes the value out of the entry, and returns it along with a + /// `VacantEntry` that can be used to insert another value with the same + /// hash as the one that was just removed. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::hash_table::Entry; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table: HashTable<&str> = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// // The table is empty + /// assert!(table.is_empty() && table.capacity() == 0); + /// + /// table.insert_unique(hasher(&"poneyland"), "poneyland", hasher); + /// let capacity_before_remove = table.capacity(); + /// + /// if let Entry::Occupied(o) = table.entry(hasher(&"poneyland"), |&x| x == "poneyland", hasher) { + /// assert_eq!(o.remove().0, "poneyland"); + /// } + /// + /// assert!(table + /// .find(hasher(&"poneyland"), |&x| x == "poneyland") + /// .is_none()); + /// // Now table hold none elements but capacity is equal to the old one + /// assert!(table.len() == 0 && table.capacity() == capacity_before_remove); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn remove(self) -> (T, VacantEntry<'a, T, A>) { + let (val, slot) = unsafe { self.table.raw.remove(self.bucket) }; + ( + val, + VacantEntry { + hash: self.hash, + insert_slot: slot, + table: self.table, + }, + ) + } + + /// Gets a reference to the value in the entry. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::hash_table::Entry; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table: HashTable<&str> = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// table.insert_unique(hasher(&"poneyland"), "poneyland", hasher); + /// + /// match table.entry(hasher(&"poneyland"), |&x| x == "poneyland", hasher) { + /// Entry::Vacant(_) => panic!(), + /// Entry::Occupied(entry) => assert_eq!(entry.get(), &"poneyland"), + /// } + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn get(&self) -> &T { + unsafe { self.bucket.as_ref() } + } + + /// Gets a mutable reference to the value in the entry. + /// + /// If you need a reference to the `OccupiedEntry` which may outlive the + /// destruction of the `Entry` value, see [`into_mut`]. + /// + /// [`into_mut`]: #method.into_mut + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::hash_table::Entry; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table: HashTable<(&str, u32)> = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// table.insert_unique(hasher(&"poneyland"), ("poneyland", 12), |(k, _)| hasher(&k)); + /// + /// assert_eq!( + /// table.find(hasher(&"poneyland"), |&(x, _)| x == "poneyland",), + /// Some(&("poneyland", 12)) + /// ); + /// + /// if let Entry::Occupied(mut o) = table.entry( + /// hasher(&"poneyland"), + /// |&(x, _)| x == "poneyland", + /// |(k, _)| hasher(&k), + /// ) { + /// o.get_mut().1 += 10; + /// assert_eq!(o.get().1, 22); + /// + /// // We can use the same Entry multiple times. + /// o.get_mut().1 += 2; + /// } + /// + /// assert_eq!( + /// table.find(hasher(&"poneyland"), |&(x, _)| x == "poneyland",), + /// Some(&("poneyland", 24)) + /// ); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn get_mut(&mut self) -> &mut T { + unsafe { self.bucket.as_mut() } + } + + /// Converts the OccupiedEntry into a mutable reference to the value in the entry + /// with a lifetime bound to the table itself. + /// + /// If you need multiple references to the `OccupiedEntry`, see [`get_mut`]. + /// + /// [`get_mut`]: #method.get_mut + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::hash_table::Entry; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table: HashTable<(&str, u32)> = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// table.insert_unique(hasher(&"poneyland"), ("poneyland", 12), |(k, _)| hasher(&k)); + /// + /// assert_eq!( + /// table.find(hasher(&"poneyland"), |&(x, _)| x == "poneyland",), + /// Some(&("poneyland", 12)) + /// ); + /// + /// let value: &mut (&str, u32); + /// match table.entry( + /// hasher(&"poneyland"), + /// |&(x, _)| x == "poneyland", + /// |(k, _)| hasher(&k), + /// ) { + /// Entry::Occupied(entry) => value = entry.into_mut(), + /// Entry::Vacant(_) => panic!(), + /// } + /// value.1 += 10; + /// + /// assert_eq!( + /// table.find(hasher(&"poneyland"), |&(x, _)| x == "poneyland",), + /// Some(&("poneyland", 22)) + /// ); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn into_mut(self) -> &'a mut T { + unsafe { self.bucket.as_mut() } + } + + /// Converts the OccupiedEntry into a mutable reference to the underlying + /// table. + pub fn into_table(self) -> &'a mut HashTable { + self.table + } +} + +/// A view into a vacant entry in a `HashTable`. +/// It is part of the [`Entry`] enum. +/// +/// [`Entry`]: enum.Entry.html +/// +/// # Examples +/// +/// ``` +/// # #[cfg(feature = "nightly")] +/// # fn test() { +/// use ahash::AHasher; +/// use hashbrown::hash_table::{Entry, HashTable, VacantEntry}; +/// use std::hash::{BuildHasher, BuildHasherDefault}; +/// +/// let mut table: HashTable<&str> = HashTable::new(); +/// let hasher = BuildHasherDefault::::default(); +/// let hasher = |val: &_| hasher.hash_one(val); +/// +/// let entry_v: VacantEntry<_, _> = match table.entry(hasher(&"a"), |&x| x == "a", hasher) { +/// Entry::Vacant(view) => view, +/// Entry::Occupied(_) => unreachable!(), +/// }; +/// entry_v.insert("a"); +/// assert!(table.find(hasher(&"a"), |&x| x == "a").is_some() && table.len() == 1); +/// +/// // Nonexistent key (insert) +/// match table.entry(hasher(&"b"), |&x| x == "b", hasher) { +/// Entry::Vacant(view) => { +/// view.insert("b"); +/// } +/// Entry::Occupied(_) => unreachable!(), +/// } +/// assert!(table.find(hasher(&"b"), |&x| x == "b").is_some() && table.len() == 2); +/// # } +/// # fn main() { +/// # #[cfg(feature = "nightly")] +/// # test() +/// # } +/// ``` +pub struct VacantEntry<'a, T, A = Global> +where + A: Allocator, +{ + hash: u64, + insert_slot: InsertSlot, + table: &'a mut HashTable, +} + +impl fmt::Debug for VacantEntry<'_, T, A> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("VacantEntry") + } +} + +impl<'a, T, A> VacantEntry<'a, T, A> +where + A: Allocator, +{ + /// Inserts a new element into the table with the hash that was used to + /// obtain the `VacantEntry`. + /// + /// An `OccupiedEntry` is returned for the newly inserted element. + /// + /// # Examples + /// + /// ``` + /// # #[cfg(feature = "nightly")] + /// # fn test() { + /// use ahash::AHasher; + /// use hashbrown::hash_table::Entry; + /// use hashbrown::HashTable; + /// use std::hash::{BuildHasher, BuildHasherDefault}; + /// + /// let mut table: HashTable<&str> = HashTable::new(); + /// let hasher = BuildHasherDefault::::default(); + /// let hasher = |val: &_| hasher.hash_one(val); + /// + /// if let Entry::Vacant(o) = table.entry(hasher(&"poneyland"), |&x| x == "poneyland", hasher) { + /// o.insert("poneyland"); + /// } + /// assert_eq!( + /// table.find(hasher(&"poneyland"), |&x| x == "poneyland"), + /// Some(&"poneyland") + /// ); + /// # } + /// # fn main() { + /// # #[cfg(feature = "nightly")] + /// # test() + /// # } + /// ``` + pub fn insert(self, value: T) -> OccupiedEntry<'a, T, A> { + let bucket = unsafe { + self.table + .raw + .insert_in_slot(self.hash, self.insert_slot, value) + }; + OccupiedEntry { + hash: self.hash, + bucket, + table: self.table, + } + } + + /// Converts the VacantEntry into a mutable reference to the underlying + /// table. + pub fn into_table(self) -> &'a mut HashTable { + self.table + } +} + +/// Type representing the absence of an entry, as returned by [`HashTable::find_entry`]. +/// +/// This type only exists due to [limitations] in Rust's NLL borrow checker. In +/// the future, `find_entry` will return an `Option` and this +/// type will be removed. +/// +/// [limitations]: https://smallcultfollowing.com/babysteps/blog/2018/06/15/mir-based-borrow-check-nll-status-update/#polonius +/// +/// # Examples +/// +/// ``` +/// # #[cfg(feature = "nightly")] +/// # fn test() { +/// use ahash::AHasher; +/// use hashbrown::hash_table::{AbsentEntry, Entry, HashTable}; +/// use std::hash::{BuildHasher, BuildHasherDefault}; +/// +/// let mut table: HashTable<&str> = HashTable::new(); +/// let hasher = BuildHasherDefault::::default(); +/// let hasher = |val: &_| hasher.hash_one(val); +/// +/// let entry_v: AbsentEntry<_, _> = table.find_entry(hasher(&"a"), |&x| x == "a").unwrap_err(); +/// entry_v +/// .into_table() +/// .insert_unique(hasher(&"a"), "a", hasher); +/// assert!(table.find(hasher(&"a"), |&x| x == "a").is_some() && table.len() == 1); +/// +/// // Nonexistent key (insert) +/// match table.entry(hasher(&"b"), |&x| x == "b", hasher) { +/// Entry::Vacant(view) => { +/// view.insert("b"); +/// } +/// Entry::Occupied(_) => unreachable!(), +/// } +/// assert!(table.find(hasher(&"b"), |&x| x == "b").is_some() && table.len() == 2); +/// # } +/// # fn main() { +/// # #[cfg(feature = "nightly")] +/// # test() +/// # } +/// ``` +pub struct AbsentEntry<'a, T, A = Global> +where + A: Allocator, +{ + table: &'a mut HashTable, +} + +impl fmt::Debug for AbsentEntry<'_, T, A> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("AbsentEntry") + } +} + +impl<'a, T, A> AbsentEntry<'a, T, A> +where + A: Allocator, +{ + /// Converts the AbsentEntry into a mutable reference to the underlying + /// table. + pub fn into_table(self) -> &'a mut HashTable { + self.table + } +} + +/// An iterator over the entries of a `HashTable` in arbitrary order. +/// The iterator element type is `&'a T`. +/// +/// This `struct` is created by the [`iter`] method on [`HashTable`]. See its +/// documentation for more. +/// +/// [`iter`]: struct.HashTable.html#method.iter +/// [`HashTable`]: struct.HashTable.html +pub struct Iter<'a, T> { + inner: RawIter, + marker: PhantomData<&'a T>, +} + +impl<'a, T> Iterator for Iter<'a, T> { + type Item = &'a T; + + fn next(&mut self) -> Option { + self.inner.next().map(|bucket| unsafe { bucket.as_ref() }) + } + + fn size_hint(&self) -> (usize, Option) { + self.inner.size_hint() + } +} + +impl ExactSizeIterator for Iter<'_, T> { + fn len(&self) -> usize { + self.inner.len() + } +} + +impl FusedIterator for Iter<'_, T> {} + +/// A mutable iterator over the entries of a `HashTable` in arbitrary order. +/// The iterator element type is `&'a mut T`. +/// +/// This `struct` is created by the [`iter_mut`] method on [`HashTable`]. See its +/// documentation for more. +/// +/// [`iter_mut`]: struct.HashTable.html#method.iter_mut +/// [`HashTable`]: struct.HashTable.html +pub struct IterMut<'a, T> { + inner: RawIter, + marker: PhantomData<&'a mut T>, +} + +impl<'a, T> Iterator for IterMut<'a, T> { + type Item = &'a mut T; + + fn next(&mut self) -> Option { + self.inner.next().map(|bucket| unsafe { bucket.as_mut() }) + } + + fn size_hint(&self) -> (usize, Option) { + self.inner.size_hint() + } +} + +impl ExactSizeIterator for IterMut<'_, T> { + fn len(&self) -> usize { + self.inner.len() + } +} + +impl FusedIterator for IterMut<'_, T> {} + +/// An owning iterator over the entries of a `HashTable` in arbitrary order. +/// The iterator element type is `T`. +/// +/// This `struct` is created by the [`into_iter`] method on [`HashTable`] +/// (provided by the [`IntoIterator`] trait). See its documentation for more. +/// The table cannot be used after calling that method. +/// +/// [`into_iter`]: struct.HashTable.html#method.into_iter +/// [`HashTable`]: struct.HashTable.html +/// [`IntoIterator`]: https://doc.rust-lang.org/core/iter/trait.IntoIterator.html +pub struct IntoIter +where + A: Allocator, +{ + inner: RawIntoIter, +} + +impl Iterator for IntoIter +where + A: Allocator, +{ + type Item = T; + + fn next(&mut self) -> Option { + self.inner.next() + } + + fn size_hint(&self) -> (usize, Option) { + self.inner.size_hint() + } +} + +impl ExactSizeIterator for IntoIter +where + A: Allocator, +{ + fn len(&self) -> usize { + self.inner.len() + } +} + +impl FusedIterator for IntoIter where A: Allocator {} + +/// A draining iterator over the items of a `HashTable`. +/// +/// This `struct` is created by the [`drain`] method on [`HashTable`]. +/// See its documentation for more. +/// +/// [`HashTable`]: struct.HashTable.html +/// [`drain`]: struct.HashTable.html#method.drain +pub struct Drain<'a, T, A: Allocator = Global> { + inner: RawDrain<'a, T, A>, +} + +impl Drain<'_, T, A> { + /// Returns a iterator of references over the remaining items. + fn iter(&self) -> Iter<'_, T> { + Iter { + inner: self.inner.iter(), + marker: PhantomData, + } + } +} + +impl Iterator for Drain<'_, T, A> { + type Item = T; + + fn next(&mut self) -> Option { + self.inner.next() + } + fn size_hint(&self) -> (usize, Option) { + self.inner.size_hint() + } +} +impl ExactSizeIterator for Drain<'_, T, A> { + fn len(&self) -> usize { + self.inner.len() + } +} +impl FusedIterator for Drain<'_, T, A> {} + +impl fmt::Debug for Drain<'_, T, A> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_list().entries(self.iter()).finish() + } +} + +/// A draining iterator over entries of a `HashTable` which don't satisfy the predicate `f`. +/// +/// This `struct` is created by [`HashTable::extract_if`]. See its +/// documentation for more. +#[must_use = "Iterators are lazy unless consumed"] +pub struct ExtractIf<'a, T, F, A: Allocator = Global> +where + F: FnMut(&mut T) -> bool, +{ + f: F, + inner: RawExtractIf<'a, T, A>, +} + +impl Iterator for ExtractIf<'_, T, F, A> +where + F: FnMut(&mut T) -> bool, +{ + type Item = T; + + #[inline] + fn next(&mut self) -> Option { + self.inner.next(|val| (self.f)(val)) + } + + #[inline] + fn size_hint(&self) -> (usize, Option) { + (0, self.inner.iter.size_hint().1) + } +} + +impl FusedIterator for ExtractIf<'_, T, F, A> where F: FnMut(&mut T) -> bool {} diff --git a/sgx_tstd/hashbrown/tests/equivalent_trait.rs b/sgx_tstd/hashbrown/tests/equivalent_trait.rs new file mode 100644 index 000000000..713dddd53 --- /dev/null +++ b/sgx_tstd/hashbrown/tests/equivalent_trait.rs @@ -0,0 +1,53 @@ +use hashbrown::Equivalent; +use hashbrown::HashMap; + +use std::hash::Hash; + +#[derive(Debug, Hash)] +pub struct Pair(pub A, pub B); + +impl PartialEq<(A, B)> for Pair +where + C: PartialEq, + D: PartialEq, +{ + fn eq(&self, rhs: &(A, B)) -> bool { + self.0 == rhs.0 && self.1 == rhs.1 + } +} + +impl Equivalent for Pair +where + Pair: PartialEq, + A: Hash + Eq, + B: Hash + Eq, +{ + fn equivalent(&self, other: &X) -> bool { + *self == *other + } +} + +#[test] +fn test_lookup() { + let s = String::from; + let mut map = HashMap::new(); + map.insert((s("a"), s("b")), 1); + map.insert((s("a"), s("x")), 2); + + assert!(map.contains_key(&Pair("a", "b"))); + assert!(!map.contains_key(&Pair("b", "a"))); +} + +#[test] +fn test_string_str() { + let s = String::from; + let mut map = HashMap::new(); + map.insert(s("a"), 1); + map.insert(s("b"), 2); + map.insert(s("x"), 3); + map.insert(s("y"), 4); + + assert!(map.contains_key("a")); + assert!(!map.contains_key("z")); + assert_eq!(map.remove("b"), Some(2)); +} diff --git a/sgx_tstd/hashbrown/tests/raw.rs b/sgx_tstd/hashbrown/tests/raw.rs new file mode 100644 index 000000000..858836e63 --- /dev/null +++ b/sgx_tstd/hashbrown/tests/raw.rs @@ -0,0 +1,11 @@ +#![cfg(feature = "raw")] + +use hashbrown::raw::RawTable; +use std::mem; + +#[test] +fn test_allocation_info() { + assert_eq!(RawTable::<()>::new().allocation_info().1.size(), 0); + assert_eq!(RawTable::::new().allocation_info().1.size(), 0); + assert!(RawTable::::with_capacity(1).allocation_info().1.size() > mem::size_of::()); +} diff --git a/sgx_tstd/hashbrown/tests/rayon.rs b/sgx_tstd/hashbrown/tests/rayon.rs index 8c603c5c4..d55e5a980 100644 --- a/sgx_tstd/hashbrown/tests/rayon.rs +++ b/sgx_tstd/hashbrown/tests/rayon.rs @@ -356,7 +356,9 @@ fn set_seq_par_equivalence_into_iter_empty() { let vec_seq = SET_EMPTY.clone().into_iter().collect::>(); let vec_par = SET_EMPTY.clone().into_par_iter().collect::>(); - assert_eq3!(vec_seq, vec_par, []); + // Work around type inference failure introduced by rend dev-dependency. + let empty: [char; 0] = []; + assert_eq3!(vec_seq, vec_par, empty); } #[test] diff --git a/sgx_tstd/hashbrown/tests/set.rs b/sgx_tstd/hashbrown/tests/set.rs index 5ae1ec98e..86ec96476 100644 --- a/sgx_tstd/hashbrown/tests/set.rs +++ b/sgx_tstd/hashbrown/tests/set.rs @@ -27,7 +27,7 @@ fn test_hashset_insert_remove() { assert_eq!(m.insert(x.clone()), true); } for (i, x) in tx.iter().enumerate() { - println!("removing {} {:?}", i, x); + println!("removing {i} {x:?}"); assert_eq!(m.remove(x), true); } } diff --git a/sgx_tstd/src/alloc.rs b/sgx_tstd/src/alloc.rs index 6d6569d08..508e6bd98 100644 --- a/sgx_tstd/src/alloc.rs +++ b/sgx_tstd/src/alloc.rs @@ -82,15 +82,29 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut()); /// Registers a custom allocation error hook, replacing any that was previously registered. /// -/// The allocation error hook is invoked when an infallible memory allocation fails, before -/// the runtime aborts. The default hook prints a message to standard error, -/// but this behavior can be customized with the [`set_alloc_error_hook`] and -/// [`take_alloc_error_hook`] functions. +/// The allocation error hook is invoked when an infallible memory allocation fails — that is, +/// as a consequence of calling [`handle_alloc_error`] — before the runtime aborts. /// -/// The hook is provided with a `Layout` struct which contains information +/// The allocation error hook is a global resource. [`take_alloc_error_hook`] may be used to +/// retrieve a previously registered hook and wrap or discard it. +/// +/// # What the provided `hook` function should expect +/// +/// The hook function is provided with a [`Layout`] struct which contains information /// about the allocation that failed. /// -/// The allocation error hook is a global resource. +/// The hook function may choose to panic or abort; in the event that it returns normally, this +/// will cause an immediate abort. +/// +/// Since [`take_alloc_error_hook`] is a safe function that allows retrieving the hook, the hook +/// function must be _sound_ to call even if no memory allocations were attempted. +/// +/// # The default hook +/// +/// The default hook, used if [`set_alloc_error_hook`] is never called, prints a message to +/// standard error (and then returns, causing the runtime to abort the process). +/// Compiler options may cause it to panic instead, and the default behavior may be changed +/// to panicking in future versions of Rust. /// /// # Examples /// @@ -128,7 +142,7 @@ fn default_alloc_error_hook(layout: Layout) { #[allow(unused_unsafe)] if unsafe { __rust_alloc_error_handler_should_panic != 0 } { - panic!("memory allocation of {} bytes failed\n", layout.size()); + panic!("memory allocation of {} bytes failed", layout.size()); } else { rtprintpanic!("memory allocation of {} bytes failed\n", layout.size()); } diff --git a/sgx_tstd/src/backtrace.rs b/sgx_tstd/src/backtrace.rs index 5f6266d6b..dde5ca010 100644 --- a/sgx_tstd/src/backtrace.rs +++ b/sgx_tstd/src/backtrace.rs @@ -40,10 +40,10 @@ //! //! ## Platform support //! -//! Not all platforms that libstd compiles for support capturing backtraces. -//! Some platforms simply do nothing when capturing a backtrace. To check -//! whether the platform supports capturing backtraces you can consult the -//! `BacktraceStatus` enum as a result of `Backtrace::status`. +//! Not all platforms that std compiles for support capturing backtraces. Some +//! platforms simply do nothing when capturing a backtrace. To check whether the +//! platform supports capturing backtraces you can consult the `BacktraceStatus` +//! enum as a result of `Backtrace::status`. //! //! Like above with accuracy platform support is done on a best effort basis. //! Sometimes libraries might not be available at runtime or something may go @@ -81,13 +81,13 @@ mod tests; pub use crate::sys_common::backtrace::__rust_begin_short_backtrace; -use crate::cell::UnsafeCell; use crate::enclave::Enclave; use crate::ffi::c_void; use crate::fmt; use crate::io; +use crate::panic::UnwindSafe; use crate::panic::{BacktraceStyle, get_backtrace_style, set_backtrace_style}; -use crate::sync::Once; +use crate::sync::LazyLock; use crate::sys::backtrace::{self, BytesOrWideString}; use crate::sys_common::backtrace::{ lock, @@ -127,12 +127,11 @@ pub enum BacktraceStatus { enum Inner { Unsupported, Disabled, - Captured(LazilyResolvedCapture), + Captured(LazyLock), } struct Capture { actual_start: usize, - resolved: bool, frames: Vec, } @@ -171,7 +170,7 @@ impl fmt::Debug for Backtrace { let capture = match &self.inner { Inner::Unsupported => return fmt.write_str(""), Inner::Disabled => return fmt.write_str(""), - Inner::Captured(c) => c.force(), + Inner::Captured(c) => &**c, }; let frames = &capture.frames[capture.actual_start..]; @@ -296,7 +295,6 @@ impl Backtrace { // Capture a backtrace which start just before the function addressed by // `ip` fn create(ip: usize) -> Backtrace { - // SAFETY: We don't attempt to lock this reentrantly. let _lock = lock(); let mut frames = Vec::new(); let mut actual_start = None; @@ -306,7 +304,7 @@ impl Backtrace { frame: RawFrame::Actual(frame.clone()), symbols: Vec::new(), }); - if frame.symbol_address() as usize == ip && actual_start.is_none() { + if frame.symbol_address().addr() == ip && actual_start.is_none() { actual_start = Some(frames.len()); } true @@ -319,11 +317,10 @@ impl Backtrace { let inner = if frames.is_empty() { Inner::Unsupported } else { - Inner::Captured(LazilyResolvedCapture::new(Capture { + Inner::Captured(LazyLock::new(lazy_resolve(Capture { actual_start: actual_start.unwrap_or(0), frames, - resolved: false, - })) + }))) }; Backtrace { inner } @@ -346,7 +343,7 @@ impl<'a> Backtrace { /// Returns an iterator over the backtrace frames. #[must_use] pub fn frames(&'a self) -> &'a [BacktraceFrame] { - if let Inner::Captured(c) = &self.inner { &c.force().frames } else { &[] } + if let Inner::Captured(c) = &self.inner { &c.frames } else { &[] } } } @@ -355,7 +352,7 @@ impl fmt::Display for Backtrace { let capture = match &self.inner { Inner::Unsupported => return fmt.write_str("unsupported backtrace"), Inner::Disabled => return fmt.write_str("disabled backtrace"), - Inner::Captured(c) => c.force(), + Inner::Captured(c) => &**c, }; let full = fmt.alternate(); @@ -399,54 +396,22 @@ impl fmt::Display for Backtrace { } } -struct LazilyResolvedCapture { - sync: Once, - capture: UnsafeCell, -} - -impl LazilyResolvedCapture { - fn new(capture: Capture) -> Self { - LazilyResolvedCapture { sync: Once::new(), capture: UnsafeCell::new(capture) } - } - - fn force(&self) -> &Capture { - self.sync.call_once(|| { - // SAFETY: This exclusive reference can't overlap with any others - // `Once` guarantees callers will block until this closure returns - // `Once` also guarantees only a single caller will enter this closure - unsafe { &mut *self.capture.get() }.resolve(); - }); - - // SAFETY: This shared reference can't overlap with the exclusive reference above - unsafe { &*self.capture.get() } - } -} - -// SAFETY: Access to the inner value is synchronized using a thread-safe `Once` -// So long as `Capture` is `Sync`, `LazilyResolvedCapture` is too -unsafe impl Sync for LazilyResolvedCapture where Capture: Sync {} - -impl Capture { - #[allow(clippy::infallible_destructuring_match)] - fn resolve(&mut self) { - // If we're already resolved, nothing to do! - if self.resolved { - return; - } - self.resolved = true; +type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe; +#[allow(clippy::infallible_destructuring_match)] +fn lazy_resolve(mut capture: Capture) -> LazyResolve { + move || { // Use the global backtrace lock to synchronize this as it's a // requirement of the `backtrace` crate, and then actually resolve // everything. let _lock = lock(); - for frame in self.frames.iter_mut() { + for frame in capture.frames.iter_mut() { let symbols = &mut frame.symbols; let frame = match &frame.frame { RawFrame::Actual(frame) => frame, #[cfg(feature = "unit_test")] RawFrame::Fake => unimplemented!(), }; - // let RawFrame::Actual(frame) = &frame.frame; unsafe { resolve_frame_unsynchronized(frame, |symbol| { symbols.push(BacktraceSymbol { @@ -461,6 +426,8 @@ impl Capture { }); } } + + capture } } diff --git a/sgx_tstd/src/backtrace/tests.rs b/sgx_tstd/src/backtrace/tests.rs index cc8dc5f6e..3cff61d6d 100644 --- a/sgx_tstd/src/backtrace/tests.rs +++ b/sgx_tstd/src/backtrace/tests.rs @@ -16,6 +16,7 @@ // under the License.. use super::*; +use crate::panic::{RefUnwindSafe, UnwindSafe}; use sgx_test_utils::test_case; @@ -62,9 +63,8 @@ fn generate_fake_frames() -> Vec { #[test_case] fn test_debug() { let backtrace = Backtrace { - inner: Inner::Captured(LazilyResolvedCapture::new(Capture { + inner: Inner::Captured(LazyLock::preinit(Capture { actual_start: 1, - resolved: true, frames: generate_fake_frames(), })), }; @@ -83,11 +83,11 @@ fn test_debug() { } #[test_case] +#[allow(clippy::useless_vec)] fn test_frames() { let backtrace = Backtrace { - inner: Inner::Captured(LazilyResolvedCapture::new(Capture { + inner: Inner::Captured(LazyLock::preinit(Capture { actual_start: 1, - resolved: true, frames: generate_fake_frames(), })), }; @@ -112,3 +112,9 @@ fn test_frames() { assert!(iter.all(|(f, e)| format!("{f:#?}") == *e)); } + +#[test_case] +fn backtrace_unwind_safe() { + fn assert_unwind_safe() {} + assert_unwind_safe::(); +} diff --git a/sgx_tstd/src/collections/hash/map.rs b/sgx_tstd/src/collections/hash/map.rs index 3f7580f97..731c24693 100644 --- a/sgx_tstd/src/collections/hash/map.rs +++ b/sgx_tstd/src/collections/hash/map.rs @@ -23,16 +23,13 @@ use self::Entry::*; use hashbrown::hash_map as base; use crate::borrow::Borrow; -use crate::cell::Cell; use crate::collections::TryReserveError; use crate::collections::TryReserveErrorKind; use crate::error::Error; use crate::fmt::{self, Debug}; -#[allow(deprecated)] -use crate::hash::{BuildHasher, Hash, Hasher, SipHasher13}; +use crate::hash::{BuildHasher, Hash, RandomState}; use crate::iter::FusedIterator; use crate::ops::Index; -use crate::sys; /// A [hash map] implemented with quadratic probing and SIMD lookup. /// @@ -41,7 +38,7 @@ use crate::sys; /// reasonable best-effort is made to generate this seed from a high quality, /// secure source of randomness provided by the host without blocking the /// program. Because of this, the randomness of the seed depends on the output -/// quality of the system's random number generator when the seed is created. +/// quality of the system's random number coroutine when the seed is created. /// In particular, seeds generated when the system's entropy pool is abnormally /// low such as during system boot may be of a lower quality. /// @@ -66,12 +63,14 @@ use crate::sys; /// ``` /// /// In other words, if two keys are equal, their hashes must be equal. +/// Violating this property is a logic error. /// -/// It is a logic error for a key to be modified in such a way that the key's +/// It is also a logic error for a key to be modified in such a way that the key's /// hash, as determined by the [`Hash`] trait, or its equality, as determined by /// the [`Eq`] trait, changes while it is in the map. This is normally only /// possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. -/// The behavior resulting from such a logic error is not specified, but will +/// +/// The behavior resulting from either logic error is not specified, but will /// be encapsulated to the `HashMap` that observed the logic error and not /// result in undefined behavior. This could include panics, incorrect results, /// aborts, memory leaks, and non-termination. @@ -253,7 +252,7 @@ impl HashMap { /// /// The hash map will be able to hold at least `capacity` elements without /// reallocating. This method is allowed to allocate for more elements than - /// `capacity`. If `capacity` is 0, the hash set will not allocate. + /// `capacity`. If `capacity` is 0, the hash map will not allocate. /// /// # Examples /// @@ -286,7 +285,7 @@ impl HashMap { /// /// ``` /// use std::collections::HashMap; - /// use std::collections::hash_map::RandomState; + /// use std::hash::RandomState; /// /// let s = RandomState::new(); /// let mut map = HashMap::with_hasher(s); @@ -316,7 +315,7 @@ impl HashMap { /// /// ``` /// use std::collections::HashMap; - /// use std::collections::hash_map::RandomState; + /// use std::hash::RandomState; /// /// let s = RandomState::new(); /// let mut map = HashMap::with_capacity_and_hasher(10, s); @@ -623,28 +622,27 @@ impl HashMap { /// If the closure returns false, or panics, the element remains in the map and will not be /// yielded. /// - /// Note that `drain_filter` lets you mutate every value in the filter closure, regardless of + /// Note that `extract_if` lets you mutate every value in the filter closure, regardless of /// whether you choose to keep or remove it. /// - /// If the iterator is only partially consumed or not consumed at all, each of the remaining - /// elements will still be subjected to the closure and removed and dropped if it returns true. + /// If the returned `ExtractIf` is not exhausted, e.g. because it is dropped without iterating + /// or the iteration short-circuits, then the remaining elements will be retained. + /// Use [`retain`] with a negated predicate if you do not need the returned iterator. /// - /// It is unspecified how many more elements will be subjected to the closure - /// if a panic occurs in the closure, or a panic occurs while dropping an element, - /// or if the `DrainFilter` value is leaked. + /// [`retain`]: HashMap::retain /// /// # Examples /// /// Splitting a map into even and odd keys, reusing the original map: /// /// ``` - /// #![feature(hash_drain_filter)] + /// #![feature(hash_extract_if)] /// use std::collections::HashMap; /// /// let mut map: HashMap = (0..8).map(|x| (x, x)).collect(); - /// let drained: HashMap = map.drain_filter(|k, _v| k % 2 == 0).collect(); + /// let extracted: HashMap = map.extract_if(|k, _v| k % 2 == 0).collect(); /// - /// let mut evens = drained.keys().copied().collect::>(); + /// let mut evens = extracted.keys().copied().collect::>(); /// let mut odds = map.keys().copied().collect::>(); /// evens.sort(); /// odds.sort(); @@ -654,11 +652,11 @@ impl HashMap { /// ``` #[inline] #[rustc_lint_query_instability] - pub fn drain_filter(&mut self, pred: F) -> DrainFilter<'_, K, V, F> + pub fn extract_if(&mut self, pred: F) -> ExtractIf<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool, { - DrainFilter { base: self.base.drain_filter(pred) } + ExtractIf { base: self.base.extract_if(pred) } } /// Retains only the elements specified by the predicate. @@ -713,7 +711,7 @@ impl HashMap { /// /// ``` /// use std::collections::HashMap; - /// use std::collections::hash_map::RandomState; + /// use std::hash::RandomState; /// /// let hasher = RandomState::new(); /// let map: HashMap = HashMap::with_hasher(hasher); @@ -754,7 +752,7 @@ where /// Tries to reserve capacity for at least `additional` more elements to be inserted /// in the `HashMap`. The collection may reserve more space to speculatively - /// avoid frequent reallocations. After calling `reserve`, + /// avoid frequent reallocations. After calling `try_reserve`, /// capacity will be greater than or equal to `self.len() + additional` if /// it returns `Ok(())`. /// Does nothing if capacity is already sufficient. @@ -1414,7 +1412,6 @@ impl<'a, K, V> IterMut<'a, K, V> { /// (provided by the [`IntoIterator`] trait). See its documentation for more. /// /// [`into_iter`]: IntoIterator::into_iter -/// [`IntoIterator`]: crate::iter::IntoIterator /// /// # Example /// @@ -1539,27 +1536,28 @@ impl<'a, K, V> Drain<'a, K, V> { /// A draining, filtering iterator over the entries of a `HashMap`. /// -/// This `struct` is created by the [`drain_filter`] method on [`HashMap`]. +/// This `struct` is created by the [`extract_if`] method on [`HashMap`]. /// -/// [`drain_filter`]: HashMap::drain_filter +/// [`extract_if`]: HashMap::extract_if /// /// # Example /// /// ``` -/// #![feature(hash_drain_filter)] +/// #![feature(hash_extract_if)] /// /// use std::collections::HashMap; /// /// let mut map = HashMap::from([ /// ("a", 1), /// ]); -/// let iter = map.drain_filter(|_k, v| *v % 2 == 0); +/// let iter = map.extract_if(|_k, v| *v % 2 == 0); /// ``` -pub struct DrainFilter<'a, K, V, F> +#[must_use = "iterators are lazy and do nothing unless consumed"] +pub struct ExtractIf<'a, K, V, F> where F: FnMut(&K, &mut V) -> bool, { - base: base::DrainFilter<'a, K, V, F>, + base: base::ExtractIf<'a, K, V, F>, } /// A mutable iterator over the values of a `HashMap`. @@ -1820,7 +1818,6 @@ impl<'a, K, V, S> RawEntryMut<'a, K, V, S> { /// .or_insert("poneyland", 0); /// assert_eq!(map["poneyland"], 43); /// ``` - #[must_use] #[inline] pub fn and_modify(self, f: F) -> Self where @@ -2370,7 +2367,7 @@ where } } -impl Iterator for DrainFilter<'_, K, V, F> +impl Iterator for ExtractIf<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool, { @@ -2386,14 +2383,14 @@ where } } -impl FusedIterator for DrainFilter<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool {} +impl FusedIterator for ExtractIf<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool {} -impl<'a, K, V, F> fmt::Debug for DrainFilter<'a, K, V, F> +impl<'a, K, V, F> fmt::Debug for ExtractIf<'a, K, V, F> where F: FnMut(&K, &mut V) -> bool, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("DrainFilter").finish_non_exhaustive() + f.debug_struct("ExtractIf").finish_non_exhaustive() } } @@ -2430,12 +2427,12 @@ impl<'a, K, V> Entry<'a, K, V> { /// ``` /// use std::collections::HashMap; /// - /// let mut map: HashMap<&str, String> = HashMap::new(); - /// let s = "hoho".to_string(); + /// let mut map = HashMap::new(); + /// let value = "hoho"; /// - /// map.entry("poneyland").or_insert_with(|| s); + /// map.entry("poneyland").or_insert_with(|| value); /// - /// assert_eq!(map["poneyland"], "hoho".to_string()); + /// assert_eq!(map["poneyland"], "hoho"); /// ``` #[inline] pub fn or_insert_with V>(self, default: F) -> &'a mut V { @@ -2512,7 +2509,6 @@ impl<'a, K, V> Entry<'a, K, V> { /// .or_insert(42); /// assert_eq!(map["poneyland"], 43); /// ``` - #[must_use] #[inline] pub fn and_modify(self, f: F) -> Self where @@ -2936,142 +2932,6 @@ where } } -/// `RandomState` is the default state for [`HashMap`] types. -/// -/// A particular instance `RandomState` will create the same instances of -/// [`Hasher`], but the hashers created by two different `RandomState` -/// instances are unlikely to produce the same result for the same values. -/// -/// # Examples -/// -/// ``` -/// use std::collections::HashMap; -/// use std::collections::hash_map::RandomState; -/// -/// let s = RandomState::new(); -/// let mut map = HashMap::with_hasher(s); -/// map.insert(1, 2); -/// ``` -#[derive(Clone)] -pub struct RandomState { - k0: u64, - k1: u64, -} - -impl RandomState { - /// Constructs a new `RandomState` that is initialized with random keys. - /// - /// # Examples - /// - /// ``` - /// use std::collections::hash_map::RandomState; - /// - /// let s = RandomState::new(); - /// ``` - #[inline] - #[allow(deprecated)] - // rand - #[must_use] - pub fn new() -> RandomState { - // Historically this function did not cache keys from the OS and instead - // simply always called `rand::thread_rng().gen()` twice. In #31356 it - // was discovered, however, that because we re-seed the thread-local RNG - // from the OS periodically that this can cause excessive slowdown when - // many hash maps are created on a thread. To solve this performance - // trap we cache the first set of randomly generated keys per-thread. - // - // Later in #36481 it was discovered that exposing a deterministic - // iteration order allows a form of DOS attack. To counter that we - // increment one of the seeds on every RandomState creation, giving - // every corresponding HashMap a different iteration order. - thread_local!(static KEYS: Cell<(u64, u64)> = { - Cell::new(sys::hashmap_random_keys()) - }); - - KEYS.with(|keys| { - let (k0, k1) = keys.get(); - keys.set((k0.wrapping_add(1), k1)); - RandomState { k0, k1 } - }) - } -} - -impl BuildHasher for RandomState { - type Hasher = DefaultHasher; - #[inline] - #[allow(deprecated)] - fn build_hasher(&self) -> DefaultHasher { - DefaultHasher(SipHasher13::new_with_keys(self.k0, self.k1)) - } -} - -/// The default [`Hasher`] used by [`RandomState`]. -/// -/// The internal algorithm is not specified, and so it and its hashes should -/// not be relied upon over releases. -#[allow(deprecated)] -#[derive(Clone, Debug)] -pub struct DefaultHasher(SipHasher13); - -impl DefaultHasher { - /// Creates a new `DefaultHasher`. - /// - /// This hasher is not guaranteed to be the same as all other - /// `DefaultHasher` instances, but is the same as all other `DefaultHasher` - /// instances created through `new` or `default`. - #[inline] - #[allow(deprecated)] - #[must_use] - pub fn new() -> DefaultHasher { - DefaultHasher(SipHasher13::new_with_keys(0, 0)) - } -} - -impl Default for DefaultHasher { - /// Creates a new `DefaultHasher` using [`new`]. - /// See its documentation for more. - /// - /// [`new`]: DefaultHasher::new - #[inline] - fn default() -> DefaultHasher { - DefaultHasher::new() - } -} - -impl Hasher for DefaultHasher { - // The underlying `SipHasher13` doesn't override the other - // `write_*` methods, so it's ok not to forward them here. - - #[inline] - fn write(&mut self, msg: &[u8]) { - self.0.write(msg) - } - - #[inline] - fn write_str(&mut self, s: &str) { - self.0.write_str(s); - } - - #[inline] - fn finish(&self) -> u64 { - self.0.finish() - } -} - -impl Default for RandomState { - /// Constructs a new `RandomState`. - #[inline] - fn default() -> RandomState { - RandomState::new() - } -} - -impl fmt::Debug for RandomState { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("RandomState").finish_non_exhaustive() - } -} - #[inline] fn map_entry<'a, K: 'a, V: 'a>(raw: base::RustcEntry<'a, K, V>) -> Entry<'a, K, V> { match raw { diff --git a/sgx_tstd/src/collections/hash/map/tests.rs b/sgx_tstd/src/collections/hash/map/tests.rs index f2f0d5e8e..d2673485f 100644 --- a/sgx_tstd/src/collections/hash/map/tests.rs +++ b/sgx_tstd/src/collections/hash/map/tests.rs @@ -17,9 +17,9 @@ use super::Entry::{Occupied, Vacant}; use super::HashMap; -use super::RandomState; use crate::assert_matches::assert_matches; use crate::cell::RefCell; +use crate::hash::RandomState; use alloc_crate::collections::TryReserveErrorKind::*; use sgx_test_utils::test_case; @@ -835,6 +835,7 @@ fn test_try_reserve() { } #[test_case] +#[allow(clippy::manual_hash_one)] fn test_raw_entry() { use super::RawEntryMut::{Occupied, Vacant}; @@ -927,7 +928,7 @@ fn test_raw_entry() { } } -mod test_drain_filter { +mod test_extract_if { use super::*; use crate::panic::{catch_unwind, AssertUnwindSafe}; @@ -953,7 +954,7 @@ mod test_drain_filter { #[test_case] fn empty() { let mut map: HashMap = HashMap::new(); - map.drain_filter(|_, _| unreachable!("there's nothing to decide on")); + map.extract_if(|_, _| unreachable!("there's nothing to decide on")).for_each(drop); assert!(map.is_empty()); } @@ -961,7 +962,7 @@ mod test_drain_filter { fn consuming_nothing() { let pairs = (0..3).map(|i| (i, i)); let mut map: HashMap<_, _> = pairs.collect(); - assert!(map.drain_filter(|_, _| false).eq_sorted(crate::iter::empty())); + assert!(map.extract_if(|_, _| false).eq_sorted(crate::iter::empty())); assert_eq!(map.len(), 3); } @@ -969,7 +970,7 @@ mod test_drain_filter { fn consuming_all() { let pairs = (0..3).map(|i| (i, i)); let mut map: HashMap<_, _> = pairs.clone().collect(); - assert!(map.drain_filter(|_, _| true).eq_sorted(pairs)); + assert!(map.extract_if(|_, _| true).eq_sorted(pairs)); assert!(map.is_empty()); } @@ -978,7 +979,7 @@ mod test_drain_filter { let pairs = (0..3).map(|i| (i, i)); let mut map: HashMap<_, _> = pairs.collect(); assert!( - map.drain_filter(|_, v| { + map.extract_if(|_, v| { *v += 6; false }) @@ -993,7 +994,7 @@ mod test_drain_filter { let pairs = (0..3).map(|i| (i, i)); let mut map: HashMap<_, _> = pairs.collect(); assert!( - map.drain_filter(|_, v| { + map.extract_if(|_, v| { *v += 6; true }) @@ -1019,14 +1020,15 @@ mod test_drain_filter { let mut map = (0..3).map(|i| (i, D)).collect::>(); catch_unwind(move || { - drop(map.drain_filter(|_, _| { + map.extract_if(|_, _| { PREDS.fetch_add(1, Ordering::SeqCst); true - })) + }) + .for_each(drop) }) .unwrap_err(); - assert_eq!(PREDS.load(Ordering::SeqCst), 3); + assert_eq!(PREDS.load(Ordering::SeqCst), 2); assert_eq!(DROPS.load(Ordering::SeqCst), 3); } @@ -1045,10 +1047,11 @@ mod test_drain_filter { let mut map = (0..3).map(|i| (i, D)).collect::>(); catch_unwind(AssertUnwindSafe(|| { - drop(map.drain_filter(|_, _| match PREDS.fetch_add(1, Ordering::SeqCst) { + map.extract_if(|_, _| match PREDS.fetch_add(1, Ordering::SeqCst) { 0 => true, _ => panic!(), - })) + }) + .for_each(drop) })) .unwrap_err(); @@ -1073,7 +1076,7 @@ mod test_drain_filter { let mut map = (0..3).map(|i| (i, D)).collect::>(); { - let mut it = map.drain_filter(|_, _| match PREDS.fetch_add(1, Ordering::SeqCst) { + let mut it = map.extract_if(|_, _| match PREDS.fetch_add(1, Ordering::SeqCst) { 0 => true, _ => panic!(), }); diff --git a/sgx_tstd/src/collections/hash/set.rs b/sgx_tstd/src/collections/hash/set.rs index 05fac8a11..41835d2f0 100644 --- a/sgx_tstd/src/collections/hash/set.rs +++ b/sgx_tstd/src/collections/hash/set.rs @@ -23,18 +23,11 @@ use hashbrown::hash_set as base; use crate::borrow::Borrow; use crate::collections::TryReserveError; use crate::fmt; -use crate::hash::{BuildHasher, Hash}; +use crate::hash::{BuildHasher, Hash, RandomState}; use crate::iter::{Chain, FusedIterator}; use crate::ops::{BitAnd, BitOr, BitXor, Sub}; -use super::map::{map_try_reserve_error, RandomState}; - -// Future Optimization (FIXME!) -// ============================ -// -// Iteration over zero sized values is a noop. There is no need -// for `bucket.val` in the case of HashSet. I suppose we would need HKT -// to get rid of it properly. +use super::map::map_try_reserve_error; /// A [hash set] implemented as a `HashMap` where the value is `()`. /// @@ -48,13 +41,14 @@ use super::map::{map_try_reserve_error, RandomState}; /// ``` /// /// In other words, if two keys are equal, their hashes must be equal. +/// Violating this property is a logic error. /// -/// -/// It is a logic error for a key to be modified in such a way that the key's +/// It is also a logic error for a key to be modified in such a way that the key's /// hash, as determined by the [`Hash`] trait, or its equality, as determined by /// the [`Eq`] trait, changes while it is in the map. This is normally only /// possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. -/// The behavior resulting from such a logic error is not specified, but will +/// +/// The behavior resulting from either logic error is not specified, but will /// be encapsulated to the `HashSet` that observed the logic error and not /// result in undefined behavior. This could include panics, incorrect results, /// aborts, memory leaks, and non-termination. @@ -89,8 +83,8 @@ use super::map::{map_try_reserve_error, RandomState}; /// ``` /// /// The easiest way to use `HashSet` with a custom type is to derive -/// [`Eq`] and [`Hash`]. We must also derive [`PartialEq`], this will in the -/// future be implied by [`Eq`]. +/// [`Eq`] and [`Hash`]. We must also derive [`PartialEq`], +/// which is required if [`Eq`] is derived. /// /// ``` /// use std::collections::HashSet; @@ -164,7 +158,7 @@ impl HashSet { #[inline] #[must_use] pub fn with_capacity(capacity: usize) -> HashSet { - HashSet { base: base::HashSet::with_capacity_and_hasher(capacity, Default::default()) } + HashSet::with_capacity_and_hasher(capacity, Default::default()) } } @@ -278,25 +272,24 @@ impl HashSet { /// If the closure returns false, the value will remain in the list and will not be yielded /// by the iterator. /// - /// If the iterator is only partially consumed or not consumed at all, each of the remaining - /// values will still be subjected to the closure and removed and dropped if it returns true. + /// If the returned `ExtractIf` is not exhausted, e.g. because it is dropped without iterating + /// or the iteration short-circuits, then the remaining elements will be retained. + /// Use [`retain`] with a negated predicate if you do not need the returned iterator. /// - /// It is unspecified how many more values will be subjected to the closure - /// if a panic occurs in the closure, or if a panic occurs while dropping a value, or if the - /// `DrainFilter` itself is leaked. + /// [`retain`]: HashSet::retain /// /// # Examples /// /// Splitting a set into even and odd values, reusing the original set: /// /// ``` - /// #![feature(hash_drain_filter)] + /// #![feature(hash_extract_if)] /// use std::collections::HashSet; /// /// let mut set: HashSet = (0..8).collect(); - /// let drained: HashSet = set.drain_filter(|v| v % 2 == 0).collect(); + /// let extracted: HashSet = set.extract_if(|v| v % 2 == 0).collect(); /// - /// let mut evens = drained.into_iter().collect::>(); + /// let mut evens = extracted.into_iter().collect::>(); /// let mut odds = set.into_iter().collect::>(); /// evens.sort(); /// odds.sort(); @@ -306,11 +299,11 @@ impl HashSet { /// ``` #[inline] #[rustc_lint_query_instability] - pub fn drain_filter(&mut self, pred: F) -> DrainFilter<'_, T, F> + pub fn extract_if(&mut self, pred: F) -> ExtractIf<'_, T, F> where F: FnMut(&T) -> bool, { - DrainFilter { base: self.base.drain_filter(pred) } + ExtractIf { base: self.base.extract_if(pred) } } /// Retains only the elements specified by the predicate. @@ -325,7 +318,7 @@ impl HashSet { /// /// let mut set = HashSet::from([1, 2, 3, 4, 5, 6]); /// set.retain(|&k| k % 2 == 0); - /// assert_eq!(set.len(), 3); + /// assert_eq!(set, HashSet::from([2, 4, 6])); /// ``` /// /// # Performance @@ -374,7 +367,7 @@ impl HashSet { /// /// ``` /// use std::collections::HashSet; - /// use std::collections::hash_map::RandomState; + /// use std::hash::RandomState; /// /// let s = RandomState::new(); /// let mut set = HashSet::with_hasher(s); @@ -404,7 +397,7 @@ impl HashSet { /// /// ``` /// use std::collections::HashSet; - /// use std::collections::hash_map::RandomState; + /// use std::hash::RandomState; /// /// let s = RandomState::new(); /// let mut set = HashSet::with_capacity_and_hasher(10, s); @@ -421,7 +414,7 @@ impl HashSet { /// /// ``` /// use std::collections::HashSet; - /// use std::collections::hash_map::RandomState; + /// use std::hash::RandomState; /// /// let hasher = RandomState::new(); /// let set: HashSet = HashSet::with_hasher(hasher); @@ -463,7 +456,7 @@ where /// Tries to reserve capacity for at least `additional` more elements to be inserted /// in the `HashSet`. The collection may reserve more space to speculatively - /// avoid frequent reallocations. After calling `reserve`, + /// avoid frequent reallocations. After calling `try_reserve`, /// capacity will be greater than or equal to `self.len() + additional` if /// it returns `Ok(())`. /// Does nothing if capacity is already sufficient. @@ -861,7 +854,9 @@ where /// Returns whether the value was newly inserted. That is: /// /// - If the set did not previously contain this value, `true` is returned. - /// - If the set already contained this value, `false` is returned. + /// - If the set already contained this value, `false` is returned, + /// and the set is not modified: original value is not replaced, + /// and the value passed as argument is dropped. /// /// # Examples /// @@ -1247,7 +1242,6 @@ pub struct Iter<'a, K: 'a> { /// (provided by the [`IntoIterator`] trait). See its documentation for more. /// /// [`into_iter`]: IntoIterator::into_iter -/// [`IntoIterator`]: crate::iter::IntoIterator /// /// # Examples /// @@ -1284,26 +1278,26 @@ pub struct Drain<'a, K: 'a> { /// A draining, filtering iterator over the items of a `HashSet`. /// -/// This `struct` is created by the [`drain_filter`] method on [`HashSet`]. +/// This `struct` is created by the [`extract_if`] method on [`HashSet`]. /// -/// [`drain_filter`]: HashSet::drain_filter +/// [`extract_if`]: HashSet::extract_if /// /// # Examples /// /// ``` -/// #![feature(hash_drain_filter)] +/// #![feature(hash_extract_if)] /// /// use std::collections::HashSet; /// /// let mut a = HashSet::from([1, 2, 3]); /// -/// let mut drain_filtered = a.drain_filter(|v| v % 2 == 0); +/// let mut extract_ifed = a.extract_if(|v| v % 2 == 0); /// ``` -pub struct DrainFilter<'a, K, F> +pub struct ExtractIf<'a, K, F> where F: FnMut(&K) -> bool, { - base: base::DrainFilter<'a, K, F>, + base: base::ExtractIf<'a, K, F>, } /// A lazy iterator producing elements in the intersection of `HashSet`s. @@ -1537,7 +1531,7 @@ impl fmt::Debug for Drain<'_, K> { } } -impl Iterator for DrainFilter<'_, K, F> +impl Iterator for ExtractIf<'_, K, F> where F: FnMut(&K) -> bool, { @@ -1553,14 +1547,14 @@ where } } -impl FusedIterator for DrainFilter<'_, K, F> where F: FnMut(&K) -> bool {} +impl FusedIterator for ExtractIf<'_, K, F> where F: FnMut(&K) -> bool {} -impl<'a, K, F> fmt::Debug for DrainFilter<'a, K, F> +impl<'a, K, F> fmt::Debug for ExtractIf<'a, K, F> where F: FnMut(&K) -> bool, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("DrainFilter").finish_non_exhaustive() + f.debug_struct("ExtractIf").finish_non_exhaustive() } } diff --git a/sgx_tstd/src/collections/hash/set/tests.rs b/sgx_tstd/src/collections/hash/set/tests.rs index 352143fa9..0c01bd7fe 100644 --- a/sgx_tstd/src/collections/hash/set/tests.rs +++ b/sgx_tstd/src/collections/hash/set/tests.rs @@ -15,11 +15,12 @@ // specific language governing permissions and limitations // under the License.. -use super::super::map::RandomState; use super::HashSet; +use crate::hash::RandomState; use crate::panic::{catch_unwind, AssertUnwindSafe}; use crate::sync::atomic::{AtomicU32, Ordering}; +use crate::sync::Arc; use sgx_test_utils::test_case; @@ -339,6 +340,7 @@ fn test_trivial_drain() { } #[test_case] +#[allow(clippy::never_loop)] fn test_drain() { let mut s: HashSet<_> = (1..100).collect(); @@ -437,19 +439,19 @@ fn test_retain() { } #[test_case] -fn test_drain_filter() { +fn test_extract_if() { let mut x: HashSet<_> = [1].iter().copied().collect(); let mut y: HashSet<_> = [1].iter().copied().collect(); - x.drain_filter(|_| true); - y.drain_filter(|_| false); + x.extract_if(|_| true).for_each(drop); + y.extract_if(|_| false).for_each(drop); assert_eq!(x.len(), 0); assert_eq!(y.len(), 1); } #[allow(clippy::redundant_closure)] #[test_case] -fn test_drain_filter_drop_panic_leak() { +fn test_extract_if_drop_panic_leak() { static PREDS: AtomicU32 = AtomicU32::new(0); static DROPS: AtomicU32 = AtomicU32::new(0); @@ -466,19 +468,20 @@ fn test_drain_filter_drop_panic_leak() { let mut set = (0..3).map(|i| D(i)).collect::>(); catch_unwind(move || { - drop(set.drain_filter(|_| { + set.extract_if(|_| { PREDS.fetch_add(1, Ordering::SeqCst); true - })) + }) + .for_each(drop) }) .ok(); - assert_eq!(PREDS.load(Ordering::SeqCst), 3); + assert_eq!(PREDS.load(Ordering::SeqCst), 2); assert_eq!(DROPS.load(Ordering::SeqCst), 3); } #[test_case] -fn test_drain_filter_pred_panic_leak() { +fn test_extract_if_pred_panic_leak() { static PREDS: AtomicU32 = AtomicU32::new(0); static DROPS: AtomicU32 = AtomicU32::new(0); @@ -493,10 +496,11 @@ fn test_drain_filter_pred_panic_leak() { let mut set: HashSet<_> = (0..3).map(|_| D).collect(); catch_unwind(AssertUnwindSafe(|| { - drop(set.drain_filter(|_| match PREDS.fetch_add(1, Ordering::SeqCst) { + set.extract_if(|_| match PREDS.fetch_add(1, Ordering::SeqCst) { 0 => true, _ => panic!(), - })) + }) + .for_each(drop) })) .ok(); @@ -522,3 +526,22 @@ fn const_with_hasher() { const X: HashSet<(), ()> = HashSet::with_hasher(()); assert_eq!(X.len(), 0); } + +#[test_case] +fn test_insert_does_not_overwrite_the_value() { + let first_value = Arc::new(17); + let second_value = Arc::new(17); + + let mut set = HashSet::new(); + let inserted = set.insert(first_value.clone()); + assert!(inserted); + + let inserted = set.insert(second_value); + assert!(!inserted); + + assert!( + Arc::ptr_eq(set.iter().next().unwrap(), &first_value), + "Insert must not overwrite the value, so the contained value pointer \ + must be the same as first value pointer we inserted" + ); +} diff --git a/sgx_tstd/src/collections/mod.rs b/sgx_tstd/src/collections/mod.rs index 4b8c5a142..ed87791cf 100644 --- a/sgx_tstd/src/collections/mod.rs +++ b/sgx_tstd/src/collections/mod.rs @@ -189,7 +189,8 @@ //! //! ## Iterators //! -//! Iterators are a powerful and robust mechanism used throughout Rust's +//! [Iterators][crate::iter] +//! are a powerful and robust mechanism used throughout Rust's //! standard libraries. Iterators provide a sequence of values in a generic, //! safe, efficient and convenient way. The contents of an iterator are usually //! *lazily* evaluated, so that only the values that are actually needed are @@ -269,7 +270,9 @@ //! //! Several other collection methods also return iterators to yield a sequence //! of results but avoid allocating an entire collection to store the result in. -//! This provides maximum flexibility as `collect` or `extend` can be called to +//! This provides maximum flexibility as +//! [`collect`][crate::iter::Iterator::collect] or +//! [`extend`][crate::iter::Extend::extend] can be called to //! "pipe" the sequence into any collection if desired. Otherwise, the sequence //! can be looped over with a `for` loop. The iterator can also be discarded //! after partial use, preventing the computation of the unused items. @@ -412,8 +415,6 @@ //! // ...but the key hasn't changed. b is still "baz", not "xyz". //! assert_eq!(map.keys().next().unwrap().b, "baz"); //! ``` -//! -//! [IntoIterator]: crate::iter::IntoIterator "iter::IntoIterator" #[doc(hidden)] pub use crate::ops::Bound; @@ -433,6 +434,8 @@ mod hash; pub mod hash_map { //! A hash map implemented with quadratic probing and SIMD lookup. pub use super::hash::map::*; + pub use crate::hash::random::DefaultHasher; + pub use crate::hash::random::RandomState; } pub mod hash_set { diff --git a/sgx_tstd/src/env.rs b/sgx_tstd/src/env.rs index 46de970ca..ecc2fa79c 100644 --- a/sgx_tstd/src/env.rs +++ b/sgx_tstd/src/env.rs @@ -188,7 +188,8 @@ impl Iterator for Vars { impl fmt::Debug for Vars { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Vars").finish_non_exhaustive() + let Self { inner: VarsOs { inner } } = self; + f.debug_struct("Vars").field("inner", &inner.str_debug()).finish() } } @@ -204,7 +205,8 @@ impl Iterator for VarsOs { impl fmt::Debug for VarsOs { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("VarOs").finish_non_exhaustive() + let Self { inner } = self; + f.debug_struct("VarsOs").field("inner", inner).finish() } } @@ -243,21 +245,14 @@ fn _var(key: &OsStr) -> Result { } /// Fetches the environment variable `key` from the current process, returning -/// [`None`] if the variable isn't set or there's another error. +/// [`None`] if the variable isn't set or if there is another error. /// -/// Note that the method will not check if the environment variable -/// is valid Unicode. If you want to have an error on invalid UTF-8, -/// use the [`var`] function instead. -/// -/// # Errors -/// -/// This function returns an error if the environment variable isn't set. -/// -/// This function may return an error if the environment variable's name contains +/// It may return `None` if the environment variable's name contains /// the equal sign character (`=`) or the NUL character. /// -/// This function may return an error if the environment variable's value contains -/// the NUL character. +/// Note that this function will not check if the environment variable +/// is valid Unicode. If you want to have an error on invalid UTF-8, +/// use the [`var`] function instead. /// /// # Examples /// @@ -562,6 +557,13 @@ impl Error for JoinPathsError { /// /// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/userenv/nf-userenv-getuserprofiledirectorya /// +/// # Deprecation +/// +/// This function is deprecated because the behaviour on Windows is not correct. +/// The 'HOME' environment variable is not standard on Windows, and may not produce +/// desired results; for instance, under Cygwin or Mingw it will return `/home/you` +/// when it should return `C:\Users\you`. +/// /// # Examples /// /// ``` @@ -804,7 +806,8 @@ impl DoubleEndedIterator for Args { impl fmt::Debug for Args { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Args").field("inner", &self.inner.inner).finish() + let Self { inner: ArgsOs { inner } } = self; + f.debug_struct("Args").field("inner", inner).finish() } } @@ -839,7 +842,8 @@ impl DoubleEndedIterator for ArgsOs { impl fmt::Debug for ArgsOs { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("ArgsOs").field("inner", &self.inner).finish() + let Self { inner } = self; + f.debug_struct("ArgsOs").field("inner", inner).finish() } } @@ -856,7 +860,9 @@ pub mod consts { /// - x86_64 /// - arm /// - aarch64 + /// - loongarch64 /// - m68k + /// - csky /// - mips /// - mips64 /// - powerpc diff --git a/sgx_tstd/src/env/tests.rs b/sgx_tstd/src/env/tests.rs index 8d3ff809a..bc7e8c9ee 100644 --- a/sgx_tstd/src/env/tests.rs +++ b/sgx_tstd/src/env/tests.rs @@ -75,8 +75,28 @@ fn args_debug() { format!("Args {{ inner: {:?} }}", args().collect::>()), format!("{:?}", args()) ); +} + +#[test_case] +fn args_os_debug() { assert_eq!( format!("ArgsOs {{ inner: {:?} }}", args_os().collect::>()), format!("{:?}", args_os()) ); } + +#[test_case] +fn vars_debug() { + assert_eq!( + format!("Vars {{ inner: {:?} }}", vars().collect::>()), + format!("{:?}", vars()) + ); +} + +#[test_case] +fn vars_os_debug() { + assert_eq!( + format!("VarsOs {{ inner: {:?} }}", vars_os().collect::>()), + format!("{:?}", vars_os()) + ); +} diff --git a/sgx_tstd/src/error.rs b/sgx_tstd/src/error.rs index ec182b39b..736843f2a 100644 --- a/sgx_tstd/src/error.rs +++ b/sgx_tstd/src/error.rs @@ -25,6 +25,7 @@ use crate::backtrace::Backtrace; use crate::fmt::{self, Write}; pub use core::error::Error; +pub use core::error::{request_ref, request_value, Request}; mod private { // This is a hack to prevent `type_id` from being overridden by `Error` @@ -136,7 +137,8 @@ mod private { /// This example produces the following output: /// /// ```console -/// thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SuperError is here!: SuperErrorSideKick is here!', src/error.rs:34:40 +/// thread 'main' panicked at src/error.rs:34:40: +/// called `Result::unwrap()` on an `Err` value: SuperError is here!: SuperErrorSideKick is here! /// note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace /// ``` /// @@ -382,11 +384,10 @@ impl Report { /// /// ```rust /// #![feature(error_reporter)] - /// #![feature(provide_any)] /// #![feature(error_generic_member_access)] /// # use std::error::Error; /// # use std::fmt; - /// use std::any::Demand; + /// use std::error::Request; /// use std::error::Report; /// use std::backtrace::Backtrace; /// @@ -416,8 +417,8 @@ impl Report { /// } /// /// impl Error for SuperErrorSideKick { - /// fn provide<'a>(&'a self, demand: &mut Demand<'a>) { - /// demand.provide_ref::(&self.backtrace); + /// fn provide<'a>(&'a self, request: &mut Request<'a>) { + /// request.provide_ref::(&self.backtrace); /// } /// } /// @@ -471,13 +472,14 @@ where fn backtrace(&self) -> Option<&Backtrace> { // have to grab the backtrace on the first error directly since that error may not be // 'static - let backtrace = (&self.error as &dyn Error).request_ref(); - backtrace.or_else(|| { + let backtrace = request_ref(&self.error); + let backtrace = backtrace.or_else(|| { self.error .source() - .map(|source| source.sources().find_map(|source| source.request_ref())) + .map(|source| source.sources().find_map(|source| request_ref(source))) .flatten() - }) + }); + backtrace } /// Format the report as a single line. diff --git a/sgx_tstd/src/error/tests.rs b/sgx_tstd/src/error/tests.rs index b9f991380..5fba6ecf0 100644 --- a/sgx_tstd/src/error/tests.rs +++ b/sgx_tstd/src/error/tests.rs @@ -17,7 +17,7 @@ use super::Error; use crate::fmt; -use core::any::Demand; +use core::error::Request; use sgx_test_utils::test_case; @@ -218,7 +218,7 @@ where self.source.as_deref() } - fn provide<'a>(&'a self, req: &mut Demand<'a>) { + fn provide<'a>(&'a self, req: &mut Request<'a>) { self.backtrace.as_ref().map(|bt| req.provide_ref::(bt)); } } diff --git a/sgx_tstd/src/f32.rs b/sgx_tstd/src/f32.rs index 0f116a062..e762be630 100644 --- a/sgx_tstd/src/f32.rs +++ b/sgx_tstd/src/f32.rs @@ -79,17 +79,23 @@ impl f32 { unsafe { intrinsics::ceilf32(self) } } - /// Returns the nearest integer to `self`. Round half-way cases away from - /// `0.0`. + /// Returns the nearest integer to `self`. If a value is half-way between two + /// integers, round away from `0.0`. /// /// # Examples /// /// ``` /// let f = 3.3_f32; /// let g = -3.3_f32; + /// let h = -3.7_f32; + /// let i = 3.5_f32; + /// let j = 4.5_f32; /// /// assert_eq!(f.round(), 3.0); /// assert_eq!(g.round(), -3.0); + /// assert_eq!(h.round(), -4.0); + /// assert_eq!(i.round(), 4.0); + /// assert_eq!(j.round(), 5.0); /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] @@ -98,6 +104,31 @@ impl f32 { unsafe { intrinsics::roundf32(self) } } + /// Returns the nearest integer to a number. Rounds half-way cases to the number + /// with an even least significant digit. + /// + /// # Examples + /// + /// ``` + /// #![feature(round_ties_even)] + /// + /// let f = 3.3_f32; + /// let g = -3.3_f32; + /// let h = 3.5_f32; + /// let i = 4.5_f32; + /// + /// assert_eq!(f.round_ties_even(), 3.0); + /// assert_eq!(g.round_ties_even(), -3.0); + /// assert_eq!(h.round_ties_even(), 4.0); + /// assert_eq!(i.round_ties_even(), 4.0); + /// ``` + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn round_ties_even(self) -> f32 { + unsafe { intrinsics::rintf32(self) } + } + /// Returns the integer part of `self`. /// This means that non-integer numbers are always truncated towards zero. /// @@ -277,7 +308,7 @@ impl f32 { /// This result is not an element of the function's codomain, but it is the /// closest floating point number in the real numbers and thus fulfills the /// property `self == self.div_euclid(rhs) * rhs + self.rem_euclid(rhs)` - /// approximatively. + /// approximately. /// /// # Examples /// @@ -461,10 +492,7 @@ impl f32 { #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn log2(self) -> f32 { - #[cfg(target_os = "android")] - return crate::sys::android::log2f32(self); - #[cfg(not(target_os = "android"))] - return unsafe { intrinsics::log2f32(self) }; + unsafe { intrinsics::log2f32(self) } } /// Returns the base 10 logarithm of the number. @@ -488,7 +516,7 @@ impl f32 { /// The positive difference of two numbers. /// - /// * If `self <= other`: `0:0` + /// * If `self <= other`: `0.0` /// * Else: `self - other` /// /// # Examples @@ -506,6 +534,16 @@ impl f32 { #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] #[inline] + #[deprecated( + since = "1.10.0", + note = "you probably meant `(self - other).abs()`: \ + this operation is `(self - other).max(0.0)` \ + except that `abs_sub` also propagates NaNs (also \ + known as `fdimf` in C). If you truly need the positive \ + difference, consider using that expression or the C function \ + `fdimf`, depending on how you wish to handle NaN (please consider \ + filing an issue describing your use-case too)." + )] pub fn abs_sub(self, other: f32) -> f32 { unsafe { cmath::fdimf(self, other) } } @@ -529,8 +567,10 @@ impl f32 { unsafe { cmath::cbrtf(self) } } - /// Calculates the length of the hypotenuse of a right-angle triangle given - /// legs of length `x` and `y`. + /// Compute the distance between the origin and a point (`x`, `y`) on the + /// Euclidean plane. Equivalently, compute the length of the hypotenuse of a + /// right-angle triangle with other sides having length `x.abs()` and + /// `y.abs()`. /// /// # Examples /// @@ -843,7 +883,9 @@ impl f32 { #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn asinh(self) -> f32 { - (self.abs() + ((self * self) + 1.0).sqrt()).ln().copysign(self) + let ax = self.abs(); + let ix = 1.0 / ax; + (ax + (ax / (Self::hypot(1.0, ix) + ix))).ln_1p().copysign(self) } /// Inverse hyperbolic cosine function. @@ -862,7 +904,11 @@ impl f32 { #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn acosh(self) -> f32 { - if self < 1.0 { Self::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() } + if self < 1.0 { + Self::NAN + } else { + (self + ((self - 1.0).sqrt() * (self + 1.0).sqrt())).ln() + } } /// Inverse hyperbolic tangent function. @@ -883,4 +929,46 @@ impl f32 { pub fn atanh(self) -> f32 { 0.5 * ((2.0 * self) / (1.0 - self)).ln_1p() } + + /// Gamma function. + /// + /// # Examples + /// + /// ``` + /// #![feature(float_gamma)] + /// let x = 5.0f32; + /// + /// let abs_difference = (x.gamma() - 24.0).abs(); + /// + /// assert!(abs_difference <= f32::EPSILON); + /// ``` + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn gamma(self) -> f32 { + unsafe { cmath::tgammaf(self) } + } + + /// Natural logarithm of the absolute value of the gamma function + /// + /// The integer part of the tuple indicates the sign of the gamma function. + /// + /// # Examples + /// + /// ``` + /// #![feature(float_gamma)] + /// let x = 2.0f32; + /// + /// let abs_difference = (x.ln_gamma().0 - 0.0).abs(); + /// + /// assert!(abs_difference <= f32::EPSILON); + /// ``` + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn ln_gamma(self) -> (f32, i32) { + let mut signgamp: i32 = 0; + let x = unsafe { cmath::lgammaf_r(self, &mut signgamp) }; + (x, signgamp) + } } diff --git a/sgx_tstd/src/f32/tests.rs b/sgx_tstd/src/f32/tests.rs index 4f9c43358..a44f3883e 100644 --- a/sgx_tstd/src/f32/tests.rs +++ b/sgx_tstd/src/f32/tests.rs @@ -243,6 +243,21 @@ fn test_round() { assert_approx_eq!((-1.7f32).round(), -2.0f32); } +#[test_case] +fn test_round_ties_even() { + assert_approx_eq!(2.5f32.round_ties_even(), 2.0f32); + assert_approx_eq!(1.0f32.round_ties_even(), 1.0f32); + assert_approx_eq!(1.3f32.round_ties_even(), 1.0f32); + assert_approx_eq!(1.5f32.round_ties_even(), 2.0f32); + assert_approx_eq!(1.7f32.round_ties_even(), 2.0f32); + assert_approx_eq!(0.0f32.round_ties_even(), 0.0f32); + assert_approx_eq!((-0.0f32).round_ties_even(), -0.0f32); + assert_approx_eq!((-1.0f32).round_ties_even(), -1.0f32); + assert_approx_eq!((-1.3f32).round_ties_even(), -1.0f32); + assert_approx_eq!((-1.5f32).round_ties_even(), -2.0f32); + assert_approx_eq!((-1.7f32).round_ties_even(), -2.0f32); +} + #[test_case] fn test_trunc() { assert_approx_eq!(1.0f32.trunc(), 1.0f32); @@ -321,6 +336,17 @@ fn test_is_sign_negative() { assert!((-f32::NAN).is_sign_negative()); } +#[allow(unused_macros)] +macro_rules! assert_f32_biteq { + ($left : expr, $right : expr) => { + let l: &f32 = &$left; + let r: &f32 = &$right; + let lb = l.to_bits(); + let rb = r.to_bits(); + assert_eq!(lb, rb, "float {} ({:#x}) is not equal to {} ({:#x})", *l, lb, *r, rb); + }; +} + #[test_case] fn test_mul_add() { let nan: f32 = f32::NAN; @@ -531,6 +557,11 @@ fn test_asinh() { assert_approx_eq!((-2.0f32).asinh(), -1.443635475178810342493276740273105f32); // regression test for the catastrophic cancellation fixed in 72486 assert_approx_eq!((-3000.0f32).asinh(), -8.699514775987968673236893537700647f32); + + // test for low accuracy from issue 104548 + assert_approx_eq!(60.0f32, 60.0f32.sinh().asinh()); + // mul needed for approximate comparison to be meaningful + assert_approx_eq!(1.0f32, 1e-15f32.sinh().asinh() * 1e15f32); } #[test_case] @@ -546,6 +577,9 @@ fn test_acosh() { assert!(nan.acosh().is_nan()); assert_approx_eq!(2.0f32.acosh(), 1.31695789692481670862504634730796844f32); assert_approx_eq!(3.0f32.acosh(), 1.76274717403908605046521864995958461f32); + + // test for low accuracy from issue 104548 + assert_approx_eq!(60.0f32, 60.0f32.cosh().acosh()); } #[test_case] @@ -573,6 +607,38 @@ fn test_atanh() { } #[test_case] +fn test_gamma() { + // precision can differ between platforms + assert_approx_eq!(1.0f32.gamma(), 1.0f32); + assert_approx_eq!(2.0f32.gamma(), 1.0f32); + assert_approx_eq!(3.0f32.gamma(), 2.0f32); + assert_approx_eq!(4.0f32.gamma(), 6.0f32); + assert_approx_eq!(5.0f32.gamma(), 24.0f32); + assert_approx_eq!(0.5f32.gamma(), consts::PI.sqrt()); + assert_approx_eq!((-0.5f32).gamma(), -2.0 * consts::PI.sqrt()); + assert_eq!(0.0f32.gamma(), f32::INFINITY); + assert_eq!((-0.0f32).gamma(), f32::NEG_INFINITY); + assert!((-1.0f32).gamma().is_nan()); + assert!((-2.0f32).gamma().is_nan()); + assert!(f32::NAN.gamma().is_nan()); + assert!(f32::NEG_INFINITY.gamma().is_nan()); + assert_eq!(f32::INFINITY.gamma(), f32::INFINITY); + assert_eq!(171.71f32.gamma(), f32::INFINITY); +} + +#[test_case] +fn test_ln_gamma() { + assert_approx_eq!(1.0f32.ln_gamma().0, 0.0f32); + assert_eq!(1.0f32.ln_gamma().1, 1); + assert_approx_eq!(2.0f32.ln_gamma().0, 0.0f32); + assert_eq!(2.0f32.ln_gamma().1, 1); + assert_approx_eq!(3.0f32.ln_gamma().0, 2.0f32.ln()); + assert_eq!(3.0f32.ln_gamma().1, 1); + assert_approx_eq!((-0.5f32).ln_gamma().0, (2.0 * consts::PI.sqrt()).ln()); + assert_eq!((-0.5f32).ln_gamma().1, -1); +} + +#[test] fn test_real_consts() { use super::consts; diff --git a/sgx_tstd/src/f64.rs b/sgx_tstd/src/f64.rs index d80a295af..8c1979935 100644 --- a/sgx_tstd/src/f64.rs +++ b/sgx_tstd/src/f64.rs @@ -79,17 +79,23 @@ impl f64 { unsafe { intrinsics::ceilf64(self) } } - /// Returns the nearest integer to `self`. Round half-way cases away from - /// `0.0`. + /// Returns the nearest integer to `self`. If a value is half-way between two + /// integers, round away from `0.0`. /// /// # Examples /// /// ``` /// let f = 3.3_f64; /// let g = -3.3_f64; + /// let h = -3.7_f64; + /// let i = 3.5_f64; + /// let j = 4.5_f64; /// /// assert_eq!(f.round(), 3.0); /// assert_eq!(g.round(), -3.0); + /// assert_eq!(h.round(), -4.0); + /// assert_eq!(i.round(), 4.0); + /// assert_eq!(j.round(), 5.0); /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] @@ -98,6 +104,31 @@ impl f64 { unsafe { intrinsics::roundf64(self) } } + /// Returns the nearest integer to a number. Rounds half-way cases to the number + /// with an even least significant digit. + /// + /// # Examples + /// + /// ``` + /// #![feature(round_ties_even)] + /// + /// let f = 3.3_f64; + /// let g = -3.3_f64; + /// let h = 3.5_f64; + /// let i = 4.5_f64; + /// + /// assert_eq!(f.round_ties_even(), 3.0); + /// assert_eq!(g.round_ties_even(), -3.0); + /// assert_eq!(h.round_ties_even(), 4.0); + /// assert_eq!(i.round_ties_even(), 4.0); + /// ``` + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn round_ties_even(self) -> f64 { + unsafe { intrinsics::rintf64(self) } + } + /// Returns the integer part of `self`. /// This means that non-integer numbers are always truncated towards zero. /// @@ -277,7 +308,7 @@ impl f64 { /// This result is not an element of the function's codomain, but it is the /// closest floating point number in the real numbers and thus fulfills the /// property `self == self.div_euclid(rhs) * rhs + self.rem_euclid(rhs)` - /// approximatively. + /// approximately. /// /// # Examples /// @@ -461,12 +492,7 @@ impl f64 { #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn log2(self) -> f64 { - self.log_wrapper(|n| { - #[cfg(target_os = "android")] - return crate::sys::android::log2f64(n); - #[cfg(not(target_os = "android"))] - return unsafe { intrinsics::log2f64(n) }; - }) + self.log_wrapper(|n| unsafe { intrinsics::log2f64(n) }) } /// Returns the base 10 logarithm of the number. @@ -490,7 +516,7 @@ impl f64 { /// The positive difference of two numbers. /// - /// * If `self <= other`: `0:0` + /// * If `self <= other`: `0.0` /// * Else: `self - other` /// /// # Examples @@ -508,6 +534,16 @@ impl f64 { #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] #[inline] + #[deprecated( + since = "1.10.0", + note = "you probably meant `(self - other).abs()`: \ + this operation is `(self - other).max(0.0)` \ + except that `abs_sub` also propagates NaNs (also \ + known as `fdim` in C). If you truly need the positive \ + difference, consider using that expression or the C function \ + `fdim`, depending on how you wish to handle NaN (please consider \ + filing an issue describing your use-case too)." + )] pub fn abs_sub(self, other: f64) -> f64 { unsafe { cmath::fdim(self, other) } } @@ -531,8 +567,10 @@ impl f64 { unsafe { cmath::cbrt(self) } } - /// Calculates the length of the hypotenuse of a right-angle triangle given - /// legs of length `x` and `y`. + /// Compute the distance between the origin and a point (`x`, `y`) on the + /// Euclidean plane. Equivalently, compute the length of the hypotenuse of a + /// right-angle triangle with other sides having length `x.abs()` and + /// `y.abs()`. /// /// # Examples /// @@ -845,7 +883,9 @@ impl f64 { #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn asinh(self) -> f64 { - (self.abs() + ((self * self) + 1.0).sqrt()).ln().copysign(self) + let ax = self.abs(); + let ix = 1.0 / ax; + (ax + (ax / (Self::hypot(1.0, ix) + ix))).ln_1p().copysign(self) } /// Inverse hyperbolic cosine function. @@ -864,7 +904,11 @@ impl f64 { #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn acosh(self) -> f64 { - if self < 1.0 { Self::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() } + if self < 1.0 { + Self::NAN + } else { + (self + ((self - 1.0).sqrt() * (self + 1.0).sqrt())).ln() + } } /// Inverse hyperbolic tangent function. @@ -886,28 +930,51 @@ impl f64 { 0.5 * ((2.0 * self) / (1.0 - self)).ln_1p() } - // Solaris/Illumos requires a wrapper around log, log2, and log10 functions - // because of their non-standard behavior (e.g., log(-n) returns -Inf instead - // of expected NaN). - #[allow(clippy::if_same_then_else)] + /// Gamma function. + /// + /// # Examples + /// + /// ``` + /// #![feature(float_gamma)] + /// let x = 5.0f64; + /// + /// let abs_difference = (x.gamma() - 24.0).abs(); + /// + /// assert!(abs_difference <= f64::EPSILON); + /// ``` + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn gamma(self) -> f64 { + unsafe { cmath::tgamma(self) } + } + + /// Natural logarithm of the absolute value of the gamma function + /// + /// The integer part of the tuple indicates the sign of the gamma function. + /// + /// # Examples + /// + /// ``` + /// #![feature(float_gamma)] + /// let x = 2.0f64; + /// + /// let abs_difference = (x.ln_gamma().0 - 0.0).abs(); + /// + /// assert!(abs_difference <= f64::EPSILON); + /// ``` #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn ln_gamma(self) -> (f64, i32) { + let mut signgamp: i32 = 0; + let x = unsafe { cmath::lgamma_r(self, &mut signgamp) }; + (x, signgamp) + } + + #[rustc_allow_incoherent_impl] + #[inline] fn log_wrapper f64>(self, log_fn: F) -> f64 { - if !cfg!(any(target_os = "solaris", target_os = "illumos")) { - log_fn(self) - } else if self.is_finite() { - if self > 0.0 { - log_fn(self) - } else if self == 0.0 { - Self::NEG_INFINITY // log(0) = -Inf - } else { - Self::NAN // log(-n) = NaN - } - } else if self.is_nan() { - self // log(NaN) = NaN - } else if self > 0.0 { - self // log(Inf) = Inf - } else { - Self::NAN // log(-Inf) = NaN - } + log_fn(self) } } diff --git a/sgx_tstd/src/f64/tests.rs b/sgx_tstd/src/f64/tests.rs index 51535b366..6aed8c08d 100644 --- a/sgx_tstd/src/f64/tests.rs +++ b/sgx_tstd/src/f64/tests.rs @@ -218,6 +218,7 @@ fn test_ceil() { #[test_case] fn test_round() { + assert_approx_eq!(2.5f64.round(), 3.0f64); assert_approx_eq!(1.0f64.round(), 1.0f64); assert_approx_eq!(1.3f64.round(), 1.0f64); assert_approx_eq!(1.5f64.round(), 2.0f64); @@ -230,6 +231,21 @@ fn test_round() { assert_approx_eq!((-1.7f64).round(), -2.0f64); } +#[test_case] +fn test_round_ties_even() { + assert_approx_eq!(2.5f64.round_ties_even(), 2.0f64); + assert_approx_eq!(1.0f64.round_ties_even(), 1.0f64); + assert_approx_eq!(1.3f64.round_ties_even(), 1.0f64); + assert_approx_eq!(1.5f64.round_ties_even(), 2.0f64); + assert_approx_eq!(1.7f64.round_ties_even(), 2.0f64); + assert_approx_eq!(0.0f64.round_ties_even(), 0.0f64); + assert_approx_eq!((-0.0f64).round_ties_even(), -0.0f64); + assert_approx_eq!((-1.0f64).round_ties_even(), -1.0f64); + assert_approx_eq!((-1.3f64).round_ties_even(), -1.0f64); + assert_approx_eq!((-1.5f64).round_ties_even(), -2.0f64); + assert_approx_eq!((-1.7f64).round_ties_even(), -2.0f64); +} + #[test_case] fn test_trunc() { assert_approx_eq!(1.0f64.trunc(), 1.0f64); @@ -308,6 +324,17 @@ fn test_is_sign_negative() { assert!((-f64::NAN).is_sign_negative()); } +#[allow(unused_macros)] +macro_rules! assert_f64_biteq { + ($left : expr, $right : expr) => { + let l: &f64 = &$left; + let r: &f64 = &$right; + let lb = l.to_bits(); + let rb = r.to_bits(); + assert_eq!(lb, rb, "float {} ({:#x}) is not equal to {} ({:#x})", *l, lb, *r, rb); + }; +} + #[test_case] fn test_mul_add() { let nan: f64 = f64::NAN; @@ -518,6 +545,11 @@ fn test_asinh() { assert_approx_eq!((-2.0f64).asinh(), -1.443635475178810342493276740273105f64); // regression test for the catastrophic cancellation fixed in 72486 assert_approx_eq!((-67452098.07139316f64).asinh(), -18.72007542627454439398548429400083); + + // test for low accuracy from issue 104548 + assert_approx_eq!(60.0f64, 60.0f64.sinh().asinh()); + // mul needed for approximate comparison to be meaningful + assert_approx_eq!(1.0f64, 1e-15f64.sinh().asinh() * 1e15f64); } #[test_case] @@ -533,6 +565,9 @@ fn test_acosh() { assert!(nan.acosh().is_nan()); assert_approx_eq!(2.0f64.acosh(), 1.31695789692481670862504634730796844f64); assert_approx_eq!(3.0f64.acosh(), 1.76274717403908605046521864995958461f64); + + // test for low accuracy from issue 104548 + assert_approx_eq!(60.0f64, 60.0f64.cosh().acosh()); } #[test_case] @@ -554,6 +589,38 @@ fn test_atanh() { assert_approx_eq!((-0.5f64).atanh(), -0.54930614433405484569762261846126285f64); } +#[test_case] +fn test_gamma() { + // precision can differ between platforms + assert_approx_eq!(1.0f64.gamma(), 1.0f64); + assert_approx_eq!(2.0f64.gamma(), 1.0f64); + assert_approx_eq!(3.0f64.gamma(), 2.0f64); + assert_approx_eq!(4.0f64.gamma(), 6.0f64); + assert_approx_eq!(5.0f64.gamma(), 24.0f64); + assert_approx_eq!(0.5f64.gamma(), consts::PI.sqrt()); + assert_approx_eq!((-0.5f64).gamma(), -2.0 * consts::PI.sqrt()); + assert_eq!(0.0f64.gamma(), f64::INFINITY); + assert_eq!((-0.0f64).gamma(), f64::NEG_INFINITY); + assert!((-1.0f64).gamma().is_nan()); + assert!((-2.0f64).gamma().is_nan()); + assert!(f64::NAN.gamma().is_nan()); + assert!(f64::NEG_INFINITY.gamma().is_nan()); + assert_eq!(f64::INFINITY.gamma(), f64::INFINITY); + assert_eq!(171.71f64.gamma(), f64::INFINITY); +} + +#[test_case] +fn test_ln_gamma() { + assert_approx_eq!(1.0f64.ln_gamma().0, 0.0f64); + assert_eq!(1.0f64.ln_gamma().1, 1); + assert_approx_eq!(2.0f64.ln_gamma().0, 0.0f64); + assert_eq!(2.0f64.ln_gamma().1, 1); + assert_approx_eq!(3.0f64.ln_gamma().0, 2.0f64.ln()); + assert_eq!(3.0f64.ln_gamma().1, 1); + assert_approx_eq!((-0.5f64).ln_gamma().0, (2.0 * consts::PI.sqrt()).ln()); + assert_eq!((-0.5f64).ln_gamma().1, -1); +} + #[test_case] fn test_real_consts() { use super::consts; diff --git a/sgx_tstd/src/ffi/mod.rs b/sgx_tstd/src/ffi/mod.rs index 7e72f1219..16635a3f8 100644 --- a/sgx_tstd/src/ffi/mod.rs +++ b/sgx_tstd/src/ffi/mod.rs @@ -144,6 +144,14 @@ //! trait, which provides a [`from_wide`] method to convert a native Windows //! string (without the terminating nul character) to an [`OsString`]. //! +//! ## On all platforms +//! +//! On all platforms, [`OsStr`] consists of a sequence of bytes that is encoded as a superset of +//! UTF-8; see [`OsString`] for more details on its encoding on different platforms. +//! +//! For limited, inexpensive conversions from and to bytes, see [`OsStr::as_encoded_bytes`] and +//! [`OsStr::from_encoded_bytes_unchecked`]. +//! //! [Unicode scalar value]: https://www.unicode.org/glossary/#unicode_scalar_value //! [Unicode code point]: https://www.unicode.org/glossary/#code_point //! [`env::set_var()`]: crate::env::set_var "env::set_var" @@ -162,6 +170,7 @@ //! [`from_wide`]: crate::os::windows::ffi::OsStringExt::from_wide "os::windows::ffi::OsStringExt::from_wide" pub use alloc_crate::ffi::{CString, FromVecWithNulError, IntoStringError, NulError}; +pub use core::ffi::FromBytesUntilNulError; pub use core::ffi::{CStr, FromBytesWithNulError}; pub use self::os_str::{OsStr, OsString}; diff --git a/sgx_tstd/src/ffi/os_str.rs b/sgx_tstd/src/ffi/os_str.rs index 8a2d359f3..02d599148 100644 --- a/sgx_tstd/src/ffi/os_str.rs +++ b/sgx_tstd/src/ffi/os_str.rs @@ -25,7 +25,6 @@ use crate::cmp; use crate::collections::TryReserveError; use crate::fmt; use crate::hash::{Hash, Hasher}; -use crate::iter::Extend; use crate::ops; use crate::rc::Rc; use crate::str::FromStr; @@ -130,9 +129,10 @@ impl crate::sealed::Sealed for OsString {} // FIXME: // `OsStr::from_inner` current implementation relies // on `OsStr` being layout-compatible with `Slice`. -// When attribute privacy is implemented, `OsStr` should be annotated as `#[repr(transparent)]`. -// Anyway, `OsStr` representation and layout are considered implementation details, are -// not documented and must not be relied upon. +// However, `OsStr` layout is considered an implementation detail and must not be relied upon. We +// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under +// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy. +#[cfg_attr(not(doc), repr(transparent))] pub struct OsStr { inner: Slice, } @@ -156,6 +156,48 @@ impl OsString { OsString { inner: Buf::from_string(String::new()) } } + /// Converts bytes to an `OsString` without checking that the bytes contains + /// valid [`OsStr`]-encoded data. + /// + /// The byte encoding is an unspecified, platform-specific, self-synchronizing superset of UTF-8. + /// By being a self-synchronizing superset of UTF-8, this encoding is also a superset of 7-bit + /// ASCII. + /// + /// See the [module's toplevel documentation about conversions][conversions] for safe, + /// cross-platform [conversions] from/to native representations. + /// + /// # Safety + /// + /// As the encoding is unspecified, callers must pass in bytes that originated as a mixture of + /// validated UTF-8 and bytes from [`OsStr::as_encoded_bytes`] from within the same rust version + /// built for the same target platform. For example, reconstructing an `OsString` from bytes sent + /// over the network or stored in a file will likely violate these safety rules. + /// + /// Due to the encoding being self-synchronizing, the bytes from [`OsStr::as_encoded_bytes`] can be + /// split either immediately before or immediately after any valid non-empty UTF-8 substring. + /// + /// # Example + /// + /// ``` + /// use std::ffi::OsStr; + /// + /// let os_str = OsStr::new("Mary had a little lamb"); + /// let bytes = os_str.as_encoded_bytes(); + /// let words = bytes.split(|b| *b == b' '); + /// let words: Vec<&OsStr> = words.map(|word| { + /// // SAFETY: + /// // - Each `word` only contains content that originated from `OsStr::as_encoded_bytes` + /// // - Only split with ASCII whitespace which is a non-empty UTF-8 substring + /// unsafe { OsStr::from_encoded_bytes_unchecked(word) } + /// }).collect(); + /// ``` + /// + /// [conversions]: super#conversions + #[inline] + pub unsafe fn from_encoded_bytes_unchecked(bytes: Vec) -> Self { + OsString { inner: Buf::from_encoded_bytes_unchecked(bytes) } + } + /// Converts to an [`OsStr`] slice. /// /// # Examples @@ -173,6 +215,25 @@ impl OsString { self } + /// Converts the `OsString` into a byte slice. To convert the byte slice back into an + /// `OsString`, use the [`OsStr::from_encoded_bytes_unchecked`] function. + /// + /// The byte encoding is an unspecified, platform-specific, self-synchronizing superset of UTF-8. + /// By being a self-synchronizing superset of UTF-8, this encoding is also a superset of 7-bit + /// ASCII. + /// + /// Note: As the encoding is unspecified, any sub-slice of bytes that is not valid UTF-8 should + /// be treated as opaque and only comparable within the same rust version built for the same + /// target platform. For example, sending the bytes over the network or storing it in a file + /// will likely result in incompatible data. See [`OsString`] for more encoding details + /// and [`std::ffi`] for platform-specific, specified conversions. + /// + /// [`std::ffi`]: crate::ffi + #[inline] + pub fn into_encoded_bytes(self) -> Vec { + self.inner.into_encoded_bytes() + } + /// Converts the `OsString` into a [`String`] if it contains valid Unicode data. /// /// On failure, ownership of the original `OsString` is returned. @@ -648,6 +709,48 @@ impl OsStr { s.as_ref() } + /// Converts a slice of bytes to an OS string slice without checking that the string contains + /// valid `OsStr`-encoded data. + /// + /// The byte encoding is an unspecified, platform-specific, self-synchronizing superset of UTF-8. + /// By being a self-synchronizing superset of UTF-8, this encoding is also a superset of 7-bit + /// ASCII. + /// + /// See the [module's toplevel documentation about conversions][conversions] for safe, + /// cross-platform [conversions] from/to native representations. + /// + /// # Safety + /// + /// As the encoding is unspecified, callers must pass in bytes that originated as a mixture of + /// validated UTF-8 and bytes from [`OsStr::as_encoded_bytes`] from within the same rust version + /// built for the same target platform. For example, reconstructing an `OsStr` from bytes sent + /// over the network or stored in a file will likely violate these safety rules. + /// + /// Due to the encoding being self-synchronizing, the bytes from [`OsStr::as_encoded_bytes`] can be + /// split either immediately before or immediately after any valid non-empty UTF-8 substring. + /// + /// # Example + /// + /// ``` + /// use std::ffi::OsStr; + /// + /// let os_str = OsStr::new("Mary had a little lamb"); + /// let bytes = os_str.as_encoded_bytes(); + /// let words = bytes.split(|b| *b == b' '); + /// let words: Vec<&OsStr> = words.map(|word| { + /// // SAFETY: + /// // - Each `word` only contains content that originated from `OsStr::as_encoded_bytes` + /// // - Only split with ASCII whitespace which is a non-empty UTF-8 substring + /// unsafe { OsStr::from_encoded_bytes_unchecked(word) } + /// }).collect(); + /// ``` + /// + /// [conversions]: super#conversions + #[inline] + pub unsafe fn from_encoded_bytes_unchecked(bytes: &[u8]) -> &Self { + Self::from_inner(Slice::from_encoded_bytes_unchecked(bytes)) + } + #[inline] fn from_inner(inner: &Slice) -> &OsStr { // SAFETY: OsStr is just a wrapper of Slice, @@ -680,7 +783,7 @@ impl OsStr { without modifying the original"] #[inline] pub fn to_str(&self) -> Option<&str> { - self.inner.to_str() + self.inner.to_str().ok() } /// Converts an `OsStr` to a [Cow]<[str]>. @@ -812,13 +915,23 @@ impl OsStr { OsString { inner: Buf::from_box(boxed) } } - /// Gets the underlying byte representation. + /// Converts an OS string slice to a byte slice. To convert the byte slice back into an OS + /// string slice, use the [`OsStr::from_encoded_bytes_unchecked`] function. /// - /// Note: it is *crucial* that this API is not externally public, to avoid - /// revealing the internal, platform-specific encodings. + /// The byte encoding is an unspecified, platform-specific, self-synchronizing superset of UTF-8. + /// By being a self-synchronizing superset of UTF-8, this encoding is also a superset of 7-bit + /// ASCII. + /// + /// Note: As the encoding is unspecified, any sub-slice of bytes that is not valid UTF-8 should + /// be treated as opaque and only comparable within the same rust version built for the same + /// target platform. For example, sending the slice over the network or storing it in a file + /// will likely result in incompatible byte slices. See [`OsString`] for more encoding details + /// and [`std::ffi`] for platform-specific, specified conversions. + /// + /// [`std::ffi`]: crate::ffi #[inline] - pub(crate) fn bytes(&self) -> &[u8] { - unsafe { &*(&self.inner as *const _ as *const [u8]) } + pub fn as_encoded_bytes(&self) -> &[u8] { + self.inner.as_encoded_bytes() } /// Converts this string to its ASCII lower case equivalent in-place. @@ -1065,6 +1178,23 @@ impl<'a> From> for OsString { } } +impl<'a> TryFrom<&'a OsStr> for &'a str { + type Error = crate::str::Utf8Error; + + /// Tries to convert an `&OsStr` to a `&str`. + /// + /// ``` + /// use std::ffi::OsStr; + /// + /// let os_str = OsStr::new("foo"); + /// let as_str = <&str>::try_from(os_str).unwrap(); + /// assert_eq!(as_str, "foo"); + /// ``` + fn try_from(value: &'a OsStr) -> Result { + value.inner.to_str() + } +} + impl Default for Box { #[inline] fn default() -> Box { @@ -1084,7 +1214,7 @@ impl Default for &OsStr { impl PartialEq for OsStr { #[inline] fn eq(&self, other: &OsStr) -> bool { - self.bytes().eq(other.bytes()) + self.as_encoded_bytes().eq(other.as_encoded_bytes()) } } @@ -1107,23 +1237,23 @@ impl Eq for OsStr {} impl PartialOrd for OsStr { #[inline] fn partial_cmp(&self, other: &OsStr) -> Option { - self.bytes().partial_cmp(other.bytes()) + self.as_encoded_bytes().partial_cmp(other.as_encoded_bytes()) } #[inline] fn lt(&self, other: &OsStr) -> bool { - self.bytes().lt(other.bytes()) + self.as_encoded_bytes().lt(other.as_encoded_bytes()) } #[inline] fn le(&self, other: &OsStr) -> bool { - self.bytes().le(other.bytes()) + self.as_encoded_bytes().le(other.as_encoded_bytes()) } #[inline] fn gt(&self, other: &OsStr) -> bool { - self.bytes().gt(other.bytes()) + self.as_encoded_bytes().gt(other.as_encoded_bytes()) } #[inline] fn ge(&self, other: &OsStr) -> bool { - self.bytes().ge(other.bytes()) + self.as_encoded_bytes().ge(other.as_encoded_bytes()) } } @@ -1140,7 +1270,7 @@ impl PartialOrd for OsStr { impl Ord for OsStr { #[inline] fn cmp(&self, other: &OsStr) -> cmp::Ordering { - self.bytes().cmp(other.bytes()) + self.as_encoded_bytes().cmp(other.as_encoded_bytes()) } } @@ -1185,7 +1315,7 @@ impl_cmp!(Cow<'a, OsStr>, OsString); impl Hash for OsStr { #[inline] fn hash(&self, state: &mut H) { - self.bytes().hash(state) + self.as_encoded_bytes().hash(state) } } diff --git a/sgx_tstd/src/fs.rs b/sgx_tstd/src/fs.rs index 6a9afafde..c259af4b0 100644 --- a/sgx_tstd/src/fs.rs +++ b/sgx_tstd/src/fs.rs @@ -26,6 +26,8 @@ use crate::ffi::OsString; use crate::fmt; use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write}; use crate::path::{Path, PathBuf}; +use crate::sealed::Sealed; +use crate::sync::Arc; use crate::sys::fs as fs_imp; use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; use crate::time::SystemTime; @@ -235,8 +237,8 @@ pub struct DirBuilder { /// This function will return an error if `path` does not already exist. /// Other errors may also be returned according to [`OpenOptions::open`]. /// -/// It will also return an error if it encounters while reading an error -/// of a kind other than [`io::ErrorKind::Interrupted`]. +/// While reading from the file, this function handles [`io::ErrorKind::Interrupted`] +/// with automatic retries. See [io::Read] documentation for details. /// /// # Examples /// @@ -252,8 +254,9 @@ pub struct DirBuilder { pub fn read>(path: P) -> io::Result> { fn inner(path: &Path) -> io::Result> { let mut file = File::open(path)?; - let mut bytes = Vec::new(); - file.read_to_end(&mut bytes)?; + let size = file.metadata().map(|m| m.len() as usize).ok(); + let mut bytes = Vec::with_capacity(size.unwrap_or(0)); + io::default_read_to_end(&mut file, &mut bytes, size)?; Ok(bytes) } inner(path.as_ref()) @@ -271,9 +274,11 @@ pub fn read>(path: P) -> io::Result> { /// This function will return an error if `path` does not already exist. /// Other errors may also be returned according to [`OpenOptions::open`]. /// -/// It will also return an error if it encounters while reading an error -/// of a kind other than [`io::ErrorKind::Interrupted`], -/// or if the contents of the file are not valid UTF-8. +/// If the contents of the file are not valid UTF-8, then an error will also be +/// returned. +/// +/// While reading from the file, this function handles [`io::ErrorKind::Interrupted`] +/// with automatic retries. See [io::Read] documentation for details. /// /// # Examples /// @@ -290,8 +295,9 @@ pub fn read>(path: P) -> io::Result> { pub fn read_to_string>(path: P) -> io::Result { fn inner(path: &Path) -> io::Result { let mut file = File::open(path)?; - let mut string = String::new(); - file.read_to_string(&mut string)?; + let size = file.metadata().map(|m| m.len() as usize).ok(); + let mut string = String::with_capacity(size.unwrap_or(0)); + io::default_read_to_string(&mut file, &mut string, size)?; Ok(string) } inner(path.as_ref()) @@ -333,6 +339,10 @@ impl File { /// /// See the [`OpenOptions::open`] method for more details. /// + /// If you only need to read the entire file contents, + /// consider [`std::fs::read()`][self::read] or + /// [`std::fs::read_to_string()`][self::read_to_string] instead. + /// /// # Errors /// /// This function will return an error if `path` does not already exist. @@ -342,9 +352,12 @@ impl File { /// /// ```no_run /// use std::fs::File; + /// use std::io::Read; /// /// fn main() -> std::io::Result<()> { /// let mut f = File::open("foo.txt")?; + /// let mut data = vec![]; + /// f.read_to_end(&mut data)?; /// Ok(()) /// } /// ``` @@ -359,16 +372,20 @@ impl File { /// /// Depending on the platform, this function may fail if the /// full directory path does not exist. - /// /// See the [`OpenOptions::open`] function for more details. /// + /// See also [`std::fs::write()`][self::write] for a simple function to + /// create a file with a given data. + /// /// # Examples /// /// ```no_run /// use std::fs::File; + /// use std::io::Write; /// /// fn main() -> std::io::Result<()> { /// let mut f = File::create("foo.txt")?; + /// f.write_all(&1234_u32.to_be_bytes())?; /// Ok(()) /// } /// ``` @@ -394,9 +411,11 @@ impl File { /// #![feature(file_create_new)] /// /// use std::fs::File; + /// use std::io::Write; /// /// fn main() -> std::io::Result<()> { /// let mut f = File::create_new("foo.txt")?; + /// f.write_all("Hello, world!".as_bytes())?; /// Ok(()) /// } /// ``` @@ -422,9 +441,11 @@ impl File { /// /// ```no_run /// use std::fs::File; + /// use std::io::Write; /// /// fn main() -> std::io::Result<()> { /// let mut f = File::options().append(true).open("example.log")?; + /// writeln!(&mut f, "new line")?; /// Ok(()) /// } /// ``` @@ -505,8 +526,9 @@ impl File { /// # Errors /// /// This function will return an error if the file is not opened for writing. - /// Also, std::io::ErrorKind::InvalidInput will be returned if the desired - /// length would cause an overflow due to the implementation specifics. + /// Also, [`std::io::ErrorKind::InvalidInput`](crate::io::ErrorKind::InvalidInput) + /// will be returned if the desired length would cause an overflow due to + /// the implementation specifics. /// /// # Examples /// @@ -643,8 +665,6 @@ impl File { /// # Examples /// /// ```no_run - /// #![feature(file_set_times)] - /// /// fn main() -> std::io::Result<()> { /// use std::fs::{self, File, FileTimes}; /// @@ -677,6 +697,7 @@ impl File { // `AsRawHandle`/`IntoRawHandle`/`FromRawHandle` on Windows. impl AsInner for File { + #[inline] fn as_inner(&self) -> &fs_imp::File { &self.inner } @@ -699,23 +720,26 @@ impl fmt::Debug for File { } /// Indicates how much extra capacity is needed to read the rest of the file. -fn buffer_capacity_required(mut file: &File) -> usize { - let size = file.metadata().map(|m| m.len()).unwrap_or(0); - let pos = file.stream_position().unwrap_or(0); +fn buffer_capacity_required(mut file: &File) -> Option { + let size = file.metadata().map(|m| m.len()).ok()?; + let pos = file.stream_position().ok()?; // Don't worry about `usize` overflow because reading will fail regardless // in that case. - size.saturating_sub(pos) as usize + Some(size.saturating_sub(pos) as usize) } -impl Read for File { +impl Read for &File { + #[inline] fn read(&mut self, buf: &mut [u8]) -> io::Result { self.inner.read(buf) } + #[inline] fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.inner.read_vectored(bufs) } + #[inline] fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { self.inner.read_buf(cursor) } @@ -727,17 +751,19 @@ impl Read for File { // Reserves space in the buffer based on the file size when available. fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { - buf.reserve(buffer_capacity_required(self)); - io::default_read_to_end(self, buf) + let size = buffer_capacity_required(self); + buf.reserve(size.unwrap_or(0)); + io::default_read_to_end(self, buf, size) } // Reserves space in the buffer based on the file size when available. fn read_to_string(&mut self, buf: &mut String) -> io::Result { - buf.reserve(buffer_capacity_required(self)); - io::default_read_to_string(self, buf) + let size = buffer_capacity_required(self); + buf.reserve(size.unwrap_or(0)); + io::default_read_to_string(self, buf, size) } } -impl Write for File { +impl Write for &File { fn write(&mut self, buf: &[u8]) -> io::Result { self.inner.write(buf) } @@ -751,69 +777,106 @@ impl Write for File { self.inner.is_write_vectored() } + #[inline] fn flush(&mut self) -> io::Result<()> { self.inner.flush() } } -impl Seek for File { +impl Seek for &File { fn seek(&mut self, pos: SeekFrom) -> io::Result { self.inner.seek(pos) } } -impl Read for &File { +impl Read for File { fn read(&mut self, buf: &mut [u8]) -> io::Result { - self.inner.read(buf) + (&*self).read(buf) + } + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { + (&*self).read_vectored(bufs) } - fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { - self.inner.read_buf(cursor) + (&*self).read_buf(cursor) + } + #[inline] + fn is_read_vectored(&self) -> bool { + (&self).is_read_vectored() } + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (&*self).read_to_end(buf) + } + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (&*self).read_to_string(buf) + } +} - fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { - self.inner.read_vectored(bufs) +impl Write for File { + fn write(&mut self, buf: &[u8]) -> io::Result { + (&*self).write(buf) + } + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { + (&*self).write_vectored(bufs) + } + #[inline] + fn is_write_vectored(&self) -> bool { + (&self).is_write_vectored() } + #[inline] + fn flush(&mut self) -> io::Result<()> { + (&*self).flush() + } +} +impl Seek for File { + fn seek(&mut self, pos: SeekFrom) -> io::Result { + (&*self).seek(pos) + } +} + + +impl Read for Arc { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (&**self).read(buf) + } + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { + (&**self).read_vectored(bufs) + } + fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { + (&**self).read_buf(cursor) + } #[inline] fn is_read_vectored(&self) -> bool { - self.inner.is_read_vectored() + (&**self).is_read_vectored() } - - // Reserves space in the buffer based on the file size when available. fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { - buf.reserve(buffer_capacity_required(self)); - io::default_read_to_end(self, buf) + (&**self).read_to_end(buf) } - - // Reserves space in the buffer based on the file size when available. fn read_to_string(&mut self, buf: &mut String) -> io::Result { - buf.reserve(buffer_capacity_required(self)); - io::default_read_to_string(self, buf) + (&**self).read_to_string(buf) } } -impl Write for &File { + +impl Write for Arc { fn write(&mut self, buf: &[u8]) -> io::Result { - self.inner.write(buf) + (&**self).write(buf) } - fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { - self.inner.write_vectored(bufs) + (&**self).write_vectored(bufs) } - #[inline] fn is_write_vectored(&self) -> bool { - self.inner.is_write_vectored() + (&**self).is_write_vectored() } - + #[inline] fn flush(&mut self) -> io::Result<()> { - self.inner.flush() + (&**self).flush() } } -impl Seek for &File { +impl Seek for Arc { fn seek(&mut self, pos: SeekFrom) -> io::Result { - self.inner.seek(pos) + (&**self).seek(pos) } } @@ -940,6 +1003,9 @@ impl OpenOptions { /// In order for the file to be created, [`OpenOptions::write`] or /// [`OpenOptions::append`] access must be used. /// + /// See also [`std::fs::write()`][self::write] for a simple function to + /// create a file with a given data. + /// /// # Examples /// /// ```no_run @@ -1036,12 +1102,14 @@ impl OpenOptions { } impl AsInner for OpenOptions { + #[inline] fn as_inner(&self) -> &fs_imp::OpenOptions { &self.0 } } impl AsInnerMut for OpenOptions { + #[inline] fn as_inner_mut(&mut self) -> &mut fs_imp::OpenOptions { &mut self.0 } @@ -1291,6 +1359,7 @@ impl fmt::Debug for Metadata { } impl AsInner for Metadata { + #[inline] fn as_inner(&self) -> &fs_imp::FileAttr { &self.0 } @@ -1323,9 +1392,46 @@ impl FileTimes { } } +impl AsInnerMut for FileTimes { + fn as_inner_mut(&mut self) -> &mut fs_imp::FileTimes { + &mut self.0 + } +} + +// For implementing OS extension traits in `std::os` +impl Sealed for FileTimes {} + impl Permissions { /// Returns `true` if these permissions describe a readonly (unwritable) file. /// + /// # Note + /// + /// This function does not take Access Control Lists (ACLs) or Unix group + /// membership into account. + /// + /// # Windows + /// + /// On Windows this returns [`FILE_ATTRIBUTE_READONLY`](https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants). + /// If `FILE_ATTRIBUTE_READONLY` is set then writes to the file will fail + /// but the user may still have permission to change this flag. If + /// `FILE_ATTRIBUTE_READONLY` is *not* set then writes may still fail due + /// to lack of write permission. + /// The behavior of this attribute for directories depends on the Windows + /// version. + /// + /// # Unix (including macOS) + /// + /// On Unix-based platforms this checks if *any* of the owner, group or others + /// write permission bits are set. It does not check if the current + /// user is in the file's assigned group. It also does not check ACLs. + /// Therefore even if this returns true you may not be able to write to the + /// file, and vice versa. The [`PermissionsExt`] trait gives direct access + /// to the permission bits but also does not read ACLs. If you need to + /// accurately know whether or not a file is writable use the `access()` + /// function from libc. + /// + /// [`PermissionsExt`]: crate::os::unix::fs::PermissionsExt + /// /// # Examples /// /// ```no_run @@ -1350,8 +1456,40 @@ impl Permissions { /// using the resulting `Permission` will update file permissions to allow /// writing. /// - /// This operation does **not** modify the filesystem. To modify the - /// filesystem use the [`set_permissions`] function. + /// This operation does **not** modify the files attributes. This only + /// changes the in-memory value of these attributes for this `Permissions` + /// instance. To modify the files attributes use the [`set_permissions`] + /// function which commits these attribute changes to the file. + /// + /// # Note + /// + /// `set_readonly(false)` makes the file *world-writable* on Unix. + /// You can use the [`PermissionsExt`] trait on Unix to avoid this issue. + /// + /// It also does not take Access Control Lists (ACLs) or Unix group + /// membership into account. + /// + /// # Windows + /// + /// On Windows this sets or clears [`FILE_ATTRIBUTE_READONLY`](https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants). + /// If `FILE_ATTRIBUTE_READONLY` is set then writes to the file will fail + /// but the user may still have permission to change this flag. If + /// `FILE_ATTRIBUTE_READONLY` is *not* set then the write may still fail if + /// the user does not have permission to write to the file. + /// + /// In Windows 7 and earlier this attribute prevents deleting empty + /// directories. It does not prevent modifying the directory contents. + /// On later versions of Windows this attribute is ignored for directories. + /// + /// # Unix (including macOS) + /// + /// On Unix-based platforms this sets or clears the write access bit for + /// the owner, group *and* others, equivalent to `chmod a+w ` + /// or `chmod a-w ` respectively. The latter will grant write access + /// to all users! You can use the [`PermissionsExt`] trait on Unix + /// to avoid this issue. + /// + /// [`PermissionsExt`]: crate::os::unix::fs::PermissionsExt /// /// # Examples /// @@ -1365,7 +1503,8 @@ impl Permissions { /// /// permissions.set_readonly(true); /// - /// // filesystem doesn't change + /// // filesystem doesn't change, only the in memory state of the + /// // readonly permission /// assert_eq!(false, metadata.permissions().readonly()); /// /// // just this particular `permissions`. @@ -1406,7 +1545,7 @@ impl FileType { } /// Tests whether this file type represents a regular file. - /// The result is mutually exclusive to the results of + /// The result is mutually exclusive to the results of /// [`is_dir`] and [`is_symlink`]; only zero or one of these /// tests may pass. /// @@ -1474,6 +1613,7 @@ impl FileType { } impl AsInner for FileType { + #[inline] fn as_inner(&self) -> &fs_imp::FileType { &self.0 } @@ -1486,6 +1626,7 @@ impl FromInner for Permissions { } impl AsInner for Permissions { + #[inline] fn as_inner(&self) -> &fs_imp::FilePermissions { &self.0 } @@ -1604,8 +1745,14 @@ impl DirEntry { self.0.file_type().map(FileType) } - /// Returns the bare file name of this directory entry without any other - /// leading path component. + /// Returns the file name of this directory entry without any + /// leading path component(s). + /// + /// As an example, + /// the output of the function will result in "foo" for all the following paths: + /// - "./foo" + /// - "/the/foo" + /// - "../../foo" /// /// # Examples /// @@ -1634,6 +1781,7 @@ impl fmt::Debug for DirEntry { } impl AsInner for DirEntry { + #[inline] fn as_inner(&self) -> &fs_imp::DirEntry { &self.0 } @@ -1799,7 +1947,7 @@ pub fn rename, Q: AsRef>(from: P, to: Q) -> io::Result<()> /// On success, the total number of bytes copied is returned and it is equal to /// the length of the `to` file as reported by `metadata`. /// -/// If you’re wanting to copy the contents of one file to another and you’re +/// If you want to copy the contents of one file to another and you’re /// working with [`File`]s, see the [`io::copy()`] function. /// /// # Platform-specific behavior @@ -2129,6 +2277,11 @@ pub fn remove_dir>(path: P) -> io::Result<()> { /// /// See [`fs::remove_file`] and [`fs::remove_dir`]. /// +/// `remove_dir_all` will fail if `remove_dir` or `remove_file` fail on any constituent paths, including the root path. +/// As a result, the directory you are deleting must exist, meaning that this function is not idempotent. +/// +/// Consider ignoring the error if validating the removal is not required for your use case. +/// /// [`fs::remove_file`]: remove_file /// [`fs::remove_dir`]: remove_dir /// @@ -2344,6 +2497,7 @@ impl DirBuilder { } impl AsInnerMut for DirBuilder { + #[inline] fn as_inner_mut(&mut self) -> &mut fs_imp::DirBuilder { &mut self.inner } @@ -2354,9 +2508,10 @@ impl AsInnerMut for DirBuilder { /// This function will traverse symbolic links to query information about the /// destination file. In case of broken symbolic links this will return `Ok(false)`. /// -/// As opposed to the [`Path::exists`] method, this one doesn't silently ignore errors -/// unrelated to the path not existing. (E.g. it will return `Err(_)` in case of permission -/// denied on some of the parent directories.) +/// As opposed to the [`Path::exists`] method, this will only return `Ok(true)` or `Ok(false)` +/// if the path was _verified_ to exist or not exist. If its existence can neither be confirmed +/// nor denied, an `Err(_)` will be propagated instead. This can be the case if e.g. listing +/// permission is denied on one of the parent directories. /// /// Note that while this avoids some pitfalls of the `exists()` method, it still can not /// prevent time-of-check to time-of-use (TOCTOU) bugs. You should only use it in scenarios diff --git a/sgx_tstd/src/fs/tests.rs b/sgx_tstd/src/fs/tests.rs index da7de776d..3d2f3fd2a 100644 --- a/sgx_tstd/src/fs/tests.rs +++ b/sgx_tstd/src/fs/tests.rs @@ -20,12 +20,14 @@ use crate::io::prelude::*; -use crate::fs::{self, File, OpenOptions}; -use crate::io::{ErrorKind, SeekFrom}; +use crate::fs::{self, File, FileTimes, OpenOptions}; +use crate::io::{BorrowedBuf, ErrorKind, SeekFrom}; +use crate::mem::MaybeUninit; use crate::path::Path; use crate::str; use crate::sys_common::io::test::{tmpdir, TempDir}; use crate::thread; +use crate::time::{Duration, SystemTime}; use sgx_trts::rand::Rng; use crate::os::unix::fs::symlink as symlink_dir; @@ -311,6 +313,23 @@ fn set_get_unix_permissions() { assert_eq!(mask & metadata1.permissions().mode(), 0o1777); } +#[test_case] +fn file_test_read_buf() { + let tmpdir = tmpdir(); + let filename = &tmpdir.join("test"); + check!(fs::write(filename, [1, 2, 3, 4])); + + let mut buf: [MaybeUninit; 128] = MaybeUninit::uninit_array(); + let mut buf = BorrowedBuf::from(buf.as_mut_slice()); + let mut file = check!(File::open(filename)); + check!(file.read_buf(buf.unfilled())); + assert_eq!(buf.filled(), &[1, 2, 3, 4]); + // File::read_buf should omit buffer initialization. + assert_eq!(buf.init_len(), 4); + + check!(fs::remove_file(filename)); +} + #[test_case] fn file_test_stat_is_correct_on_is_file() { let tmpdir = tmpdir(); @@ -456,7 +475,7 @@ fn concurrent_recursive_mkdir() { for _ in 0..8 { let dir = dir.clone(); join.push(thread::spawn(move || { - check!(fs::create_dir_all(&dir)); + check!(fs::create_dir_all(dir)); })) } @@ -488,11 +507,11 @@ fn recursive_rmdir() { let dtt = dt.join("t"); let d2 = tmpdir.join("d2"); let canary = d2.join("do_not_delete"); - check!(fs::create_dir_all(&dtt)); + check!(fs::create_dir_all(dtt)); check!(fs::create_dir_all(&d2)); check!(check!(File::create(&canary)).write(b"foo")); - check!(symlink_junction(&d2, &dt.join("d2"))); - let _ = symlink_file(&canary, &d1.join("canary")); + check!(symlink_junction(&d2, dt.join("d2"))); + let _ = symlink_file(&canary, d1.join("canary")); check!(fs::remove_dir_all(&d1)); assert!(!d1.is_dir()); @@ -564,7 +583,7 @@ fn copy_file_does_not_exist() { let from = Path::new("test/nonexistent-bogus-path"); let to = Path::new("test/other-bogus-path"); - match fs::copy(&from, &to) { + match fs::copy(from, to) { Ok(..) => panic!(), Err(..) => { assert!(!from.exists()); @@ -579,7 +598,7 @@ fn copy_src_does_not_exist() { let from = Path::new("test/nonexistent-bogus-path"); let to = tmpdir.join("out.txt"); check!(check!(File::create(&to)).write(b"hello")); - assert!(fs::copy(&from, &to).is_err()); + assert!(fs::copy(from, &to).is_err()); assert!(!from.exists()); let mut v = Vec::new(); check!(check!(File::open(&to)).read_to_end(&mut v)); @@ -718,8 +737,8 @@ fn symlink_noexist() { // Use a relative path for testing. Symlinks get normalized by Windows, // so we might not get the same path back for absolute paths - check!(symlink_file(&"foo", &tmpdir.join("bar"))); - assert_eq!(check!(fs::read_link(&tmpdir.join("bar"))).to_str().unwrap(), "foo"); + check!(symlink_file("foo", tmpdir.join("bar"))); + assert_eq!(check!(fs::read_link(tmpdir.join("bar"))).to_str().unwrap(), "foo"); } #[test_case] @@ -729,7 +748,7 @@ fn read_link() { if !got_symlink_permission(&tmpdir) { return; }; - check!(symlink_file(&"foo", &link)); + check!(symlink_file("foo", &link)); assert_eq!(check!(fs::read_link(&link)).to_str().unwrap(), "foo"); } @@ -762,7 +781,7 @@ fn links_work() { Err(..) => {} } // can't link to something that doesn't exist - match fs::hard_link(&tmpdir.join("foo"), &tmpdir.join("bar")) { + match fs::hard_link(tmpdir.join("foo"), tmpdir.join("bar")) { Ok(..) => panic!("wanted a failure"), Err(..) => {} } @@ -782,7 +801,7 @@ fn chmod_works() { let attr = check!(fs::metadata(&file)); assert!(attr.permissions().readonly()); - match fs::set_permissions(&tmpdir.join("foo"), p.clone()) { + match fs::set_permissions(tmpdir.join("foo"), p.clone()) { Ok(..) => panic!("wanted an error"), Err(..) => {} } @@ -814,7 +833,7 @@ fn sync_doesnt_kill_anything() { let tmpdir = tmpdir(); let path = tmpdir.join("in.txt"); - let mut file = check!(File::create(&path)); + let mut file = check!(File::create(path)); check!(file.sync_all()); check!(file.sync_data()); check!(file.write(b"foo")); @@ -892,61 +911,61 @@ fn open_flavors() { // tested in reverse order, so 'create_new' creates the file, and 'open existing' opens it. // write-only - check!(c(&w).create_new(true).open(&tmpdir.join("a"))); - check!(c(&w).create(true).truncate(true).open(&tmpdir.join("a"))); - check!(c(&w).truncate(true).open(&tmpdir.join("a"))); - check!(c(&w).create(true).open(&tmpdir.join("a"))); - check!(c(&w).open(&tmpdir.join("a"))); + check!(c(&w).create_new(true).open(tmpdir.join("a"))); + check!(c(&w).create(true).truncate(true).open(tmpdir.join("a"))); + check!(c(&w).truncate(true).open(tmpdir.join("a"))); + check!(c(&w).create(true).open(tmpdir.join("a"))); + check!(c(&w).open(tmpdir.join("a"))); // read-only - error!(c(&r).create_new(true).open(&tmpdir.join("b")), invalid_options); - error!(c(&r).create(true).truncate(true).open(&tmpdir.join("b")), invalid_options); - error!(c(&r).truncate(true).open(&tmpdir.join("b")), invalid_options); - error!(c(&r).create(true).open(&tmpdir.join("b")), invalid_options); - check!(c(&r).open(&tmpdir.join("a"))); // try opening the file created with write_only + error!(c(&r).create_new(true).open(tmpdir.join("b")), invalid_options); + error!(c(&r).create(true).truncate(true).open(tmpdir.join("b")), invalid_options); + error!(c(&r).truncate(true).open(tmpdir.join("b")), invalid_options); + error!(c(&r).create(true).open(tmpdir.join("b")), invalid_options); + check!(c(&r).open(tmpdir.join("a"))); // try opening the file created with write_only // read-write - check!(c(&rw).create_new(true).open(&tmpdir.join("c"))); - check!(c(&rw).create(true).truncate(true).open(&tmpdir.join("c"))); - check!(c(&rw).truncate(true).open(&tmpdir.join("c"))); - check!(c(&rw).create(true).open(&tmpdir.join("c"))); - check!(c(&rw).open(&tmpdir.join("c"))); + check!(c(&rw).create_new(true).open(tmpdir.join("c"))); + check!(c(&rw).create(true).truncate(true).open(tmpdir.join("c"))); + check!(c(&rw).truncate(true).open(tmpdir.join("c"))); + check!(c(&rw).create(true).open(tmpdir.join("c"))); + check!(c(&rw).open(tmpdir.join("c"))); // append - check!(c(&a).create_new(true).open(&tmpdir.join("d"))); - error!(c(&a).create(true).truncate(true).open(&tmpdir.join("d")), invalid_options); - error!(c(&a).truncate(true).open(&tmpdir.join("d")), invalid_options); - check!(c(&a).create(true).open(&tmpdir.join("d"))); - check!(c(&a).open(&tmpdir.join("d"))); + check!(c(&a).create_new(true).open(tmpdir.join("d"))); + error!(c(&a).create(true).truncate(true).open(tmpdir.join("d")), invalid_options); + error!(c(&a).truncate(true).open(tmpdir.join("d")), invalid_options); + check!(c(&a).create(true).open(tmpdir.join("d"))); + check!(c(&a).open(tmpdir.join("d"))); // read-append - check!(c(&ra).create_new(true).open(&tmpdir.join("e"))); - error!(c(&ra).create(true).truncate(true).open(&tmpdir.join("e")), invalid_options); - error!(c(&ra).truncate(true).open(&tmpdir.join("e")), invalid_options); - check!(c(&ra).create(true).open(&tmpdir.join("e"))); - check!(c(&ra).open(&tmpdir.join("e"))); + check!(c(&ra).create_new(true).open(tmpdir.join("e"))); + error!(c(&ra).create(true).truncate(true).open(tmpdir.join("e")), invalid_options); + error!(c(&ra).truncate(true).open(tmpdir.join("e")), invalid_options); + check!(c(&ra).create(true).open(tmpdir.join("e"))); + check!(c(&ra).open(tmpdir.join("e"))); // Test opening a file without setting an access mode let mut blank = OO::new(); - error!(blank.create(true).open(&tmpdir.join("f")), invalid_options); + error!(blank.create(true).open(tmpdir.join("f")), invalid_options); // Test write works - check!(check!(File::create(&tmpdir.join("h"))).write("foobar".as_bytes())); + check!(check!(File::create(tmpdir.join("h"))).write("foobar".as_bytes())); // Test write fails for read-only - check!(r.open(&tmpdir.join("h"))); + check!(r.open(tmpdir.join("h"))); { - let mut f = check!(r.open(&tmpdir.join("h"))); + let mut f = check!(r.open(tmpdir.join("h"))); assert!(f.write("wut".as_bytes()).is_err()); } // Test write overwrites { - let mut f = check!(c(&w).open(&tmpdir.join("h"))); + let mut f = check!(c(&w).open(tmpdir.join("h"))); check!(f.write("baz".as_bytes())); } { - let mut f = check!(c(&r).open(&tmpdir.join("h"))); + let mut f = check!(c(&r).open(tmpdir.join("h"))); let mut b = vec![0; 6]; check!(f.read(&mut b)); assert_eq!(b, "bazbar".as_bytes()); @@ -954,25 +973,25 @@ fn open_flavors() { // Test truncate works { - let mut f = check!(c(&w).truncate(true).open(&tmpdir.join("h"))); + let mut f = check!(c(&w).truncate(true).open(tmpdir.join("h"))); check!(f.write("foo".as_bytes())); } - assert_eq!(check!(fs::metadata(&tmpdir.join("h"))).len(), 3); + assert_eq!(check!(fs::metadata(tmpdir.join("h"))).len(), 3); // Test append works - assert_eq!(check!(fs::metadata(&tmpdir.join("h"))).len(), 3); + assert_eq!(check!(fs::metadata(tmpdir.join("h"))).len(), 3); { - let mut f = check!(c(&a).open(&tmpdir.join("h"))); + let mut f = check!(c(&a).open(tmpdir.join("h"))); check!(f.write("bar".as_bytes())); } - assert_eq!(check!(fs::metadata(&tmpdir.join("h"))).len(), 6); + assert_eq!(check!(fs::metadata(tmpdir.join("h"))).len(), 6); // Test .append(true) equals .write(true).append(true) { - let mut f = check!(c(&w).append(true).open(&tmpdir.join("h"))); + let mut f = check!(c(&w).append(true).open(tmpdir.join("h"))); check!(f.write("baz".as_bytes())); } - assert_eq!(check!(fs::metadata(&tmpdir.join("h"))).len(), 9); + assert_eq!(check!(fs::metadata(tmpdir.join("h"))).len(), 9); } #[test_case] @@ -989,9 +1008,9 @@ fn binary_file() { let tmpdir = tmpdir(); - check!(check!(File::create(&tmpdir.join("test"))).write(&bytes)); + check!(check!(File::create(tmpdir.join("test"))).write(&bytes)); let mut v = Vec::new(); - check!(check!(File::open(&tmpdir.join("test"))).read_to_end(&mut v)); + check!(check!(File::open(tmpdir.join("test"))).read_to_end(&mut v)); assert!(v == &bytes[..]); } @@ -1003,19 +1022,19 @@ fn write_then_read() { let tmpdir = tmpdir(); - check!(fs::write(&tmpdir.join("test"), &bytes[..])); - let v = check!(fs::read(&tmpdir.join("test"))); + check!(fs::write(tmpdir.join("test"), &bytes[..])); + let v = check!(fs::read(tmpdir.join("test"))); assert!(v == &bytes[..]); - check!(fs::write(&tmpdir.join("not-utf8"), &[0xFF])); + check!(fs::write(tmpdir.join("not-utf8"), [0xFF])); error_contains!( - fs::read_to_string(&tmpdir.join("not-utf8")), + fs::read_to_string(tmpdir.join("not-utf8")), "stream did not contain valid UTF-8" ); let s = "𐁁𐀓𐀠𐀴𐀍"; - check!(fs::write(&tmpdir.join("utf8"), s.as_bytes())); - let string = check!(fs::read_to_string(&tmpdir.join("utf8"))); + check!(fs::write(tmpdir.join("utf8"), s.as_bytes())); + let string = check!(fs::read_to_string(tmpdir.join("utf8"))); assert_eq!(string, s); } @@ -1024,7 +1043,7 @@ fn file_try_clone() { let tmpdir = tmpdir(); let mut f1 = - check!(OpenOptions::new().read(true).write(true).create(true).open(&tmpdir.join("test"))); + check!(OpenOptions::new().read(true).write(true).create(true).open(tmpdir.join("test"))); let mut f2 = check!(f1.try_clone()); check!(f1.write_all(b"hello world")); @@ -1053,7 +1072,7 @@ fn unlink_readonly() { fn mkdir_trailing_slash() { let tmpdir = tmpdir(); let path = tmpdir.join("file"); - check!(fs::create_dir_all(&path.join("a/"))); + check!(fs::create_dir_all(path.join("a/"))); } #[test_case] @@ -1089,7 +1108,7 @@ fn realpath_works() { assert_eq!(fs::canonicalize(&file).unwrap(), file); assert_eq!(fs::canonicalize(&link).unwrap(), file); assert_eq!(fs::canonicalize(&linkdir).unwrap(), dir); - assert_eq!(fs::canonicalize(&linkdir.join("link")).unwrap(), file); + assert_eq!(fs::canonicalize(linkdir.join("link")).unwrap(), file); } #[test_case] @@ -1122,8 +1141,8 @@ fn realpath_works_tricky() { fn dir_entry_methods() { let tmpdir = tmpdir(); - fs::create_dir_all(&tmpdir.join("a")).unwrap(); - File::create(&tmpdir.join("b")).unwrap(); + fs::create_dir_all(tmpdir.join("a")).unwrap(); + File::create(tmpdir.join("b")).unwrap(); for file in tmpdir.path().read_dir().unwrap().map(|f| f.unwrap()) { let fname = file.file_name(); @@ -1144,7 +1163,7 @@ fn dir_entry_methods() { #[test_case] fn dir_entry_debug() { let tmpdir = tmpdir(); - File::create(&tmpdir.join("b")).unwrap(); + File::create(tmpdir.join("b")).unwrap(); let mut read_dir = tmpdir.path().read_dir().unwrap(); let dir_entry = read_dir.next().unwrap().unwrap(); let actual = format!("{dir_entry:?}"); @@ -1200,7 +1219,7 @@ fn metadata_access_times() { let b = tmpdir.join("b"); File::create(&b).unwrap(); - let a = check!(fs::metadata(&tmpdir.path())); + let a = check!(fs::metadata(tmpdir.path())); let b = check!(fs::metadata(&b)); assert_eq!(check!(a.accessed()), check!(a.accessed())); @@ -1293,3 +1312,80 @@ fn read_large_dir() { entry.unwrap(); } } + +/// Test that two different ways of obtaining the FileType give the same result. +/// Cf. https://github.com/rust-lang/rust/issues/104900 +#[test_case] +fn test_eq_direntry_metadata() { + let tmpdir = tmpdir(); + let file_path = tmpdir.join("file"); + File::create(file_path).unwrap(); + for e in fs::read_dir(tmpdir.path()).unwrap() { + let e = e.unwrap(); + let p = e.path(); + let ft1 = e.file_type().unwrap(); + let ft2 = p.metadata().unwrap().file_type(); + assert_eq!(ft1, ft2); + } +} + +/// Regression test for https://github.com/rust-lang/rust/issues/50619. +#[test_case] +fn test_read_dir_infinite_loop() { + use crate::io::ErrorKind; + use crate::process::Command; + + // Create a zombie child process + let Ok(mut child) = Command::new("echo").spawn() else { return }; + + // Make sure the process is (un)dead + match child.kill() { + // InvalidInput means the child already exited + Err(e) if e.kind() != ErrorKind::InvalidInput => return, + _ => {} + } + + // open() on this path will succeed, but readdir() will fail + let id = child.id(); + let path = format!("/proc/{id}/net"); + + // Skip the test if we can't open the directory in the first place + let Ok(dir) = fs::read_dir(path) else { return }; + + // Check for duplicate errors + assert!(dir.filter(|e| e.is_err()).take(2).count() < 2); +} + +#[test_case] +fn rename_directory() { + let tmpdir = tmpdir(); + let old_path = tmpdir.join("foo/bar/baz"); + fs::create_dir_all(&old_path).unwrap(); + let test_file = &old_path.join("temp.txt"); + + File::create(test_file).unwrap(); + + let new_path = tmpdir.join("quux/blat"); + fs::create_dir_all(&new_path).unwrap(); + fs::rename(&old_path, new_path.join("newdir")).unwrap(); + assert!(new_path.join("newdir").is_dir()); + assert!(new_path.join("newdir/temp.txt").exists()); +} + +#[test_case] +fn test_file_times() { + let tmp = tmpdir(); + let file = File::create(tmp.join("foo")).unwrap(); + let mut times = FileTimes::new(); + let accessed = SystemTime::UNIX_EPOCH + Duration::from_secs(12345); + let modified = SystemTime::UNIX_EPOCH + Duration::from_secs(54321); + times = times.set_accessed(accessed).set_modified(modified); + + match file.set_times(times) { + Err(e) => panic!("error setting file times: {e:?}"), + Ok(_) => {} + } + let metadata = file.metadata().unwrap(); + assert_eq!(metadata.accessed().unwrap(), accessed); + assert_eq!(metadata.modified().unwrap(), modified); +} diff --git a/sgx_tstd/src/hash/mod.rs b/sgx_tstd/src/hash/mod.rs new file mode 100644 index 000000000..8460b9512 --- /dev/null +++ b/sgx_tstd/src/hash/mod.rs @@ -0,0 +1,105 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +//! Generic hashing support. +//! +//! This module provides a generic way to compute the [hash] of a value. +//! Hashes are most commonly used with [`HashMap`] and [`HashSet`]. +//! +//! [hash]: https://en.wikipedia.org/wiki/Hash_function +//! [`HashMap`]: ../../std/collections/struct.HashMap.html +//! [`HashSet`]: ../../std/collections/struct.HashSet.html +//! +//! The simplest way to make a type hashable is to use `#[derive(Hash)]`: +//! +//! # Examples +//! +//! ```rust +//! use std::hash::{DefaultHasher, Hash, Hasher}; +//! +//! #[derive(Hash)] +//! struct Person { +//! id: u32, +//! name: String, +//! phone: u64, +//! } +//! +//! let person1 = Person { +//! id: 5, +//! name: "Janet".to_string(), +//! phone: 555_666_7777, +//! }; +//! let person2 = Person { +//! id: 5, +//! name: "Bob".to_string(), +//! phone: 555_666_7777, +//! }; +//! +//! assert!(calculate_hash(&person1) != calculate_hash(&person2)); +//! +//! fn calculate_hash(t: &T) -> u64 { +//! let mut s = DefaultHasher::new(); +//! t.hash(&mut s); +//! s.finish() +//! } +//! ``` +//! +//! If you need more control over how a value is hashed, you need to implement +//! the [`Hash`] trait: +//! +//! ```rust +//! use std::hash::{DefaultHasher, Hash, Hasher}; +//! +//! struct Person { +//! id: u32, +//! # #[allow(dead_code)] +//! name: String, +//! phone: u64, +//! } +//! +//! impl Hash for Person { +//! fn hash(&self, state: &mut H) { +//! self.id.hash(state); +//! self.phone.hash(state); +//! } +//! } +//! +//! let person1 = Person { +//! id: 5, +//! name: "Janet".to_string(), +//! phone: 555_666_7777, +//! }; +//! let person2 = Person { +//! id: 5, +//! name: "Bob".to_string(), +//! phone: 555_666_7777, +//! }; +//! +//! assert_eq!(calculate_hash(&person1), calculate_hash(&person2)); +//! +//! fn calculate_hash(t: &T) -> u64 { +//! let mut s = DefaultHasher::new(); +//! t.hash(&mut s); +//! s.finish() +//! } +//! ``` + +pub(crate) mod random; + +pub use core::hash::*; + +pub use self::random::{DefaultHasher, RandomState}; diff --git a/sgx_tstd/src/hash/random.rs b/sgx_tstd/src/hash/random.rs new file mode 100644 index 000000000..56a27be83 --- /dev/null +++ b/sgx_tstd/src/hash/random.rs @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + + +//! This module exists to isolate [`RandomState`] and [`DefaultHasher`] outside of the +//! [`collections`] module without actually publicly exporting them, so that parts of that +//! implementation can more easily be moved to the [`alloc`] crate. +//! +//! Although its items are public and contain stability attributes, they can't actually be accessed +//! outside this crate. +//! +//! [`collections`]: crate::collections +#[allow(deprecated)] +use super::{BuildHasher, Hasher, SipHasher13}; +use crate::cell::Cell; +use crate::fmt; +use crate::sys; + +/// `RandomState` is the default state for [`HashMap`] types. +/// +/// A particular instance `RandomState` will create the same instances of +/// [`Hasher`], but the hashers created by two different `RandomState` +/// instances are unlikely to produce the same result for the same values. +/// +/// [`HashMap`]: crate::collections::HashMap +/// +/// # Examples +/// +/// ``` +/// use std::collections::HashMap; +/// use std::hash::RandomState; +/// +/// let s = RandomState::new(); +/// let mut map = HashMap::with_hasher(s); +/// map.insert(1, 2); +/// ``` +#[derive(Clone)] +pub struct RandomState { + k0: u64, + k1: u64, +} + +impl RandomState { + /// Constructs a new `RandomState` that is initialized with random keys. + /// + /// # Examples + /// + /// ``` + /// use std::hash::RandomState; + /// + /// let s = RandomState::new(); + /// ``` + #[inline] + #[allow(deprecated)] + // rand + #[must_use] + pub fn new() -> RandomState { + // Historically this function did not cache keys from the OS and instead + // simply always called `rand::thread_rng().gen()` twice. In #31356 it + // was discovered, however, that because we re-seed the thread-local RNG + // from the OS periodically that this can cause excessive slowdown when + // many hash maps are created on a thread. To solve this performance + // trap we cache the first set of randomly generated keys per-thread. + // + // Later in #36481 it was discovered that exposing a deterministic + // iteration order allows a form of DOS attack. To counter that we + // increment one of the seeds on every RandomState creation, giving + // every corresponding HashMap a different iteration order. + thread_local!(static KEYS: Cell<(u64, u64)> = { + Cell::new(sys::hashmap_random_keys()) + }); + + KEYS.with(|keys| { + let (k0, k1) = keys.get(); + keys.set((k0.wrapping_add(1), k1)); + RandomState { k0, k1 } + }) + } +} + +impl BuildHasher for RandomState { + type Hasher = DefaultHasher; + #[inline] + #[allow(deprecated)] + fn build_hasher(&self) -> DefaultHasher { + DefaultHasher(SipHasher13::new_with_keys(self.k0, self.k1)) + } +} + +/// The default [`Hasher`] used by [`RandomState`]. +/// +/// The internal algorithm is not specified, and so it and its hashes should +/// not be relied upon over releases. +#[allow(deprecated)] +#[derive(Clone, Debug)] +pub struct DefaultHasher(SipHasher13); + +impl DefaultHasher { + /// Creates a new `DefaultHasher`. + /// + /// This hasher is not guaranteed to be the same as all other + /// `DefaultHasher` instances, but is the same as all other `DefaultHasher` + /// instances created through `new` or `default`. + #[inline] + #[allow(deprecated)] + #[must_use] + pub const fn new() -> DefaultHasher { + DefaultHasher(SipHasher13::new_with_keys(0, 0)) + } +} + +impl Default for DefaultHasher { + /// Creates a new `DefaultHasher` using [`new`]. + /// See its documentation for more. + /// + /// [`new`]: DefaultHasher::new + #[inline] + fn default() -> DefaultHasher { + DefaultHasher::new() + } +} + +impl Hasher for DefaultHasher { + // The underlying `SipHasher13` doesn't override the other + // `write_*` methods, so it's ok not to forward them here. + + #[inline] + fn write(&mut self, msg: &[u8]) { + self.0.write(msg) + } + + #[inline] + fn write_str(&mut self, s: &str) { + self.0.write_str(s); + } + + #[inline] + fn finish(&self) -> u64 { + self.0.finish() + } +} + +impl Default for RandomState { + /// Constructs a new `RandomState`. + #[inline] + fn default() -> RandomState { + RandomState::new() + } +} + +impl fmt::Debug for RandomState { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("RandomState").finish_non_exhaustive() + } +} diff --git a/sgx_tstd/src/io/buffered/bufreader.rs b/sgx_tstd/src/io/buffered/bufreader.rs index 5b8c50bb1..65f4f846c 100644 --- a/sgx_tstd/src/io/buffered/bufreader.rs +++ b/sgx_tstd/src/io/buffered/bufreader.rs @@ -19,7 +19,8 @@ mod buffer; use crate::fmt; use crate::io::{ - self, BorrowedCursor, BufRead, IoSliceMut, Read, Seek, SeekFrom, SizeHint, DEFAULT_BUF_SIZE, + self, uninlined_slow_read_byte, BorrowedCursor, BufRead, IoSliceMut, Read, Seek, SeekFrom, + SizeHint, SpecReadByte, DEFAULT_BUF_SIZE, }; use buffer::Buffer; @@ -63,13 +64,13 @@ use buffer::Buffer; /// Ok(()) /// } /// ``` -pub struct BufReader { - inner: R, +pub struct BufReader { buf: Buffer, + inner: R, } impl BufReader { - /// Creates a new `BufReader` with a default buffer capacity. The default is currently 8 KB, + /// Creates a new `BufReader` with a default buffer capacity. The default is currently 8 KiB, /// but may change in the future. /// /// # Examples @@ -109,7 +110,7 @@ impl BufReader { } } -impl BufReader { +impl BufReader { /// Gets a reference to the underlying reader. /// /// It is inadvisable to directly read from the underlying reader. @@ -222,26 +223,29 @@ impl BufReader { /// Ok(()) /// } /// ``` - pub fn into_inner(self) -> R { + pub fn into_inner(self) -> R + where + R: Sized, + { self.inner } /// Invalidates all data in the internal buffer. #[inline] - fn discard_buffer(&mut self) { + pub(in crate::io) fn discard_buffer(&mut self) { self.buf.discard_buffer() } } // This is only used by a test which asserts that the initialization-tracking is correct. #[cfg(feature = "unit_test")] -impl BufReader { +impl BufReader { pub fn initialized(&self) -> usize { self.buf.initialized() } } -impl BufReader { +impl BufReader { /// Seeks relative to the current position. If the new position lies within the buffer, /// the buffer will not be flushed, allowing for more efficient seeks. /// This method does not return the location of the underlying reader, so the caller @@ -265,7 +269,23 @@ impl BufReader { } } -impl Read for BufReader { +impl SpecReadByte for BufReader +where + Self: Read, +{ + #[inline] + fn spec_read_byte(&mut self) -> Option> { + let mut byte = 0; + if self.buf.consume_with(1, |claimed| byte = claimed[0]) { + return Some(Ok(byte)); + } + + // Fallback case, only reached once per buffer refill. + uninlined_slow_read_byte(self) + } +} + +impl Read for BufReader { fn read(&mut self, buf: &mut [u8]) -> io::Result { // If we don't have any buffered data and we're doing a massive read // (larger than our internal buffer), bypass our internal buffer @@ -274,10 +294,8 @@ impl Read for BufReader { self.discard_buffer(); return self.inner.read(buf); } - let nread = { - let mut rem = self.fill_buf()?; - rem.read(buf)? - }; + let mut rem = self.fill_buf()?; + let nread = rem.read(buf)?; self.consume(nread); Ok(nread) } @@ -378,7 +396,7 @@ impl Read for BufReader { } } -impl BufRead for BufReader { +impl BufRead for BufReader { fn fill_buf(&mut self) -> io::Result<&[u8]> { self.buf.fill_buf(&mut self.inner) } @@ -390,11 +408,11 @@ impl BufRead for BufReader { impl fmt::Debug for BufReader where - R: fmt::Debug, + R: ?Sized + fmt::Debug, { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("BufReader") - .field("reader", &self.inner) + .field("reader", &&self.inner) .field( "buffer", &format_args!("{}/{}", self.buf.filled() - self.buf.pos(), self.capacity()), @@ -403,7 +421,7 @@ where } } -impl Seek for BufReader { +impl Seek for BufReader { /// Seek to an offset, in bytes, in the underlying reader. /// /// The position used for seeking with [SeekFrom::Current]\(_) is the @@ -496,7 +514,7 @@ impl Seek for BufReader { } } -impl SizeHint for BufReader { +impl SizeHint for BufReader { #[inline] fn lower_bound(&self) -> usize { SizeHint::lower_bound(self.get_ref()) + self.buffer().len() diff --git a/sgx_tstd/src/io/buffered/bufreader/buffer.rs b/sgx_tstd/src/io/buffered/bufreader/buffer.rs index d3293bab7..fb248802c 100644 --- a/sgx_tstd/src/io/buffered/bufreader/buffer.rs +++ b/sgx_tstd/src/io/buffered/bufreader/buffer.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -///! An encapsulation of `BufReader`'s buffer management logic. +/// An encapsulation of `BufReader`'s buffer management logic. /// /// This module factors out the basic functionality of `BufReader` in order to protect two core /// invariants: diff --git a/sgx_tstd/src/io/buffered/bufwriter.rs b/sgx_tstd/src/io/buffered/bufwriter.rs index 1c74f29df..8dd44a539 100644 --- a/sgx_tstd/src/io/buffered/bufwriter.rs +++ b/sgx_tstd/src/io/buffered/bufwriter.rs @@ -83,8 +83,7 @@ use crate::ptr; /// [`TcpStream::write`]: super::super::super::net::TcpStream::write /// [`TcpStream`]: crate::net::TcpStream /// [`flush`]: BufWriter::flush -pub struct BufWriter { - inner: W, +pub struct BufWriter { // The buffer. Avoid using this like a normal `Vec` in common code paths. // That is, don't use `buf.push`, `buf.extend_from_slice`, or any other // methods that require bounds checking or the like. This makes an enormous @@ -94,10 +93,11 @@ pub struct BufWriter { // write the buffered data a second time in BufWriter's destructor. This // flag tells the Drop impl if it should skip the flush. panicked: bool, + inner: W, } impl BufWriter { - /// Creates a new `BufWriter` with a default buffer capacity. The default is currently 8 KB, + /// Creates a new `BufWriter` with a default buffer capacity. The default is currently 8 KiB, /// but may change in the future. /// /// # Examples @@ -129,6 +129,67 @@ impl BufWriter { BufWriter { inner, buf: Vec::with_capacity(capacity), panicked: false } } + /// Unwraps this `BufWriter`, returning the underlying writer. + /// + /// The buffer is written out before returning the writer. + /// + /// # Errors + /// + /// An [`Err`] will be returned if an error occurs while flushing the buffer. + /// + /// # Examples + /// + /// ```no_run + /// use std::io::BufWriter; + /// use std::net::TcpStream; + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError::new(self, e)), + Ok(()) => Ok(self.into_parts().0), + } + } + + /// Disassembles this `BufWriter`, returning the underlying writer, and any buffered but + /// unwritten data. + /// + /// If the underlying writer panicked, it is not known what portion of the data was written. + /// In this case, we return `WriterPanicked` for the buffered data (from which the buffer + /// contents can still be recovered). + /// + /// `into_parts` makes no attempt to flush data and cannot fail. + /// + /// # Examples + /// + /// ``` + /// use std::io::{BufWriter, Write}; + /// + /// let mut buffer = [0u8; 10]; + /// let mut stream = BufWriter::new(buffer.as_mut()); + /// write!(stream, "too much data").unwrap(); + /// stream.flush().expect_err("it doesn't fit"); + /// let (recovered_writer, buffered_data) = stream.into_parts(); + /// assert_eq!(recovered_writer.len(), 0); + /// assert_eq!(&buffered_data.unwrap(), b"ata"); + /// ``` + pub fn into_parts(mut self) -> (W, Result, WriterPanicked>) { + let buf = mem::take(&mut self.buf); + let buf = if !self.panicked { Ok(buf) } else { Err(WriterPanicked { buf }) }; + + // SAFETY: forget(self) prevents double dropping inner + let inner = unsafe { ptr::read(&self.inner) }; + mem::forget(self); + + (inner, buf) + } +} + +impl BufWriter { /// Send data in our local buffer into the inner writer, looping as /// necessary until either it's all been sent or an error occurs. /// @@ -188,7 +249,7 @@ impl BufWriter { )); } Ok(n) => guard.consume(n), - Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {} + Err(ref e) if e.is_interrupted() => {} Err(e) => return Err(e), } } @@ -294,65 +355,6 @@ impl BufWriter { self.buf.capacity() } - /// Unwraps this `BufWriter`, returning the underlying writer. - /// - /// The buffer is written out before returning the writer. - /// - /// # Errors - /// - /// An [`Err`] will be returned if an error occurs while flushing the buffer. - /// - /// # Examples - /// - /// ```no_run - /// use std::io::BufWriter; - /// use std::net::TcpStream; - /// - /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); - /// - /// // unwrap the TcpStream and flush the buffer - /// let stream = buffer.into_inner().unwrap(); - /// ``` - pub fn into_inner(mut self) -> Result>> { - match self.flush_buf() { - Err(e) => Err(IntoInnerError::new(self, e)), - Ok(()) => Ok(self.into_parts().0), - } - } - - /// Disassembles this `BufWriter`, returning the underlying writer, and any buffered but - /// unwritten data. - /// - /// If the underlying writer panicked, it is not known what portion of the data was written. - /// In this case, we return `WriterPanicked` for the buffered data (from which the buffer - /// contents can still be recovered). - /// - /// `into_parts` makes no attempt to flush data and cannot fail. - /// - /// # Examples - /// - /// ``` - /// use std::io::{BufWriter, Write}; - /// - /// let mut buffer = [0u8; 10]; - /// let mut stream = BufWriter::new(buffer.as_mut()); - /// write!(stream, "too much data").unwrap(); - /// stream.flush().expect_err("it doesn't fit"); - /// let (recovered_writer, buffered_data) = stream.into_parts(); - /// assert_eq!(recovered_writer.len(), 0); - /// assert_eq!(&buffered_data.unwrap(), b"ata"); - /// ``` - pub fn into_parts(mut self) -> (W, Result, WriterPanicked>) { - let buf = mem::take(&mut self.buf); - let buf = if !self.panicked { Ok(buf) } else { Err(WriterPanicked { buf }) }; - - // SAFETY: forget(self) prevents double dropping inner - let inner = unsafe { ptr::read(&self.inner) }; - mem::forget(self); - - (inner, buf) - } - // Ensure this function does not get inlined into `write`, so that it // remains inlineable and its common path remains as short as possible. // If this function ends up being called frequently relative to `write`, @@ -513,7 +515,7 @@ impl fmt::Debug for WriterPanicked { } } -impl Write for BufWriter { +impl Write for BufWriter { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { // Use < instead of <= to avoid a needless trip through the buffer in some cases. @@ -641,19 +643,19 @@ impl Write for BufWriter { } } -impl fmt::Debug for BufWriter +impl fmt::Debug for BufWriter where W: fmt::Debug, { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("BufWriter") - .field("writer", &self.inner) + .field("writer", &&self.inner) .field("buffer", &format_args!("{}/{}", self.buf.len(), self.buf.capacity())) .finish() } } -impl Seek for BufWriter { +impl Seek for BufWriter { /// Seek to the offset, in bytes, in the underlying writer. /// /// Seeking always writes out the internal buffer before seeking. @@ -663,7 +665,7 @@ impl Seek for BufWriter { } } -impl Drop for BufWriter { +impl Drop for BufWriter { fn drop(&mut self) { if !self.panicked { // dtors should not panic, so we ignore a failed flush diff --git a/sgx_tstd/src/io/buffered/linewriter.rs b/sgx_tstd/src/io/buffered/linewriter.rs index 2dcbd3e85..b0997db2e 100644 --- a/sgx_tstd/src/io/buffered/linewriter.rs +++ b/sgx_tstd/src/io/buffered/linewriter.rs @@ -80,7 +80,7 @@ use crate::io::{self, buffered::LineWriterShim, BufWriter, IntoInnerError, IoSli /// Ok(()) /// } /// ``` -pub struct LineWriter { +pub struct LineWriter { inner: BufWriter, } @@ -123,26 +123,6 @@ impl LineWriter { LineWriter { inner: BufWriter::with_capacity(capacity, inner) } } - /// Gets a reference to the underlying writer. - /// - /// # Examples - /// - /// ```no_run - /// use std::fs::File; - /// use std::io::LineWriter; - /// - /// fn main() -> std::io::Result<()> { - /// let file = File::create("poem.txt")?; - /// let file = LineWriter::new(file); - /// - /// let reference = file.get_ref(); - /// Ok(()) - /// } - /// ``` - pub fn get_ref(&self) -> &W { - self.inner.get_ref() - } - /// Gets a mutable reference to the underlying writer. /// /// Caution must be taken when calling methods on the mutable reference @@ -195,7 +175,29 @@ impl LineWriter { } } -impl Write for LineWriter { +impl LineWriter { + /// Gets a reference to the underlying writer. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs::File; + /// use std::io::LineWriter; + /// + /// fn main() -> std::io::Result<()> { + /// let file = File::create("poem.txt")?; + /// let file = LineWriter::new(file); + /// + /// let reference = file.get_ref(); + /// Ok(()) + /// } + /// ``` + pub fn get_ref(&self) -> &W { + self.inner.get_ref() + } +} + +impl Write for LineWriter { fn write(&mut self, buf: &[u8]) -> io::Result { LineWriterShim::new(&mut self.inner).write(buf) } @@ -225,7 +227,7 @@ impl Write for LineWriter { } } -impl fmt::Debug for LineWriter +impl fmt::Debug for LineWriter where W: fmt::Debug, { diff --git a/sgx_tstd/src/io/buffered/linewritershim.rs b/sgx_tstd/src/io/buffered/linewritershim.rs index 09bca4849..470db0a9c 100644 --- a/sgx_tstd/src/io/buffered/linewritershim.rs +++ b/sgx_tstd/src/io/buffered/linewritershim.rs @@ -28,11 +28,11 @@ use crate::sys_common::memchr; /// `BufWriters` to be temporarily given line-buffering logic; this is what /// enables Stdout to be alternately in line-buffered or block-buffered mode. #[derive(Debug)] -pub struct LineWriterShim<'a, W: Write> { +pub struct LineWriterShim<'a, W: ?Sized + Write> { buffer: &'a mut BufWriter, } -impl<'a, W: Write> LineWriterShim<'a, W> { +impl<'a, W: ?Sized + Write> LineWriterShim<'a, W> { pub fn new(buffer: &'a mut BufWriter) -> Self { Self { buffer } } @@ -66,7 +66,7 @@ impl<'a, W: Write> LineWriterShim<'a, W> { } } -impl<'a, W: Write> Write for LineWriterShim<'a, W> { +impl<'a, W: ?Sized + Write> Write for LineWriterShim<'a, W> { /// Write some data into this BufReader with line buffering. This means /// that, if any newlines are present in the data, the data up to the last /// newline is sent directly to the underlying writer, and data after it diff --git a/sgx_tstd/src/io/buffered/tests.rs b/sgx_tstd/src/io/buffered/tests.rs index e63da6775..14de647e7 100644 --- a/sgx_tstd/src/io/buffered/tests.rs +++ b/sgx_tstd/src/io/buffered/tests.rs @@ -308,8 +308,8 @@ fn test_buffered_reader_seek_underflow_discard_buffer_between_seeks() { let mut reader = BufReader::with_capacity(5, ErrAfterFirstSeekReader { first_seek: true }); assert_eq!(reader.fill_buf().ok(), Some(&[0, 0, 0, 0, 0][..])); - // The following seek will require two underlying seeks. The first will - // succeed but the second will fail. This should still invalidate the + // The following seek will require two underlying seeks. The first will + // succeed but the second will fail. This should still invalidate the // buffer. assert!(reader.seek(SeekFrom::Current(i64::MIN)).is_err()); assert_eq!(reader.buffer().len(), 0); @@ -850,9 +850,9 @@ fn partial_line_buffered_after_line_write() { assert_eq!(&writer.get_ref().buffer, b"Line 1\nLine 2\nLine 3"); } -/// Test that, given a partial line that exceeds the length of -/// LineBuffer's buffer (that is, without a trailing newline), that that -/// line is written to the inner writer +/// Test that for calls to LineBuffer::write where the passed bytes do not contain +/// a newline and on their own are greater in length than the internal buffer, the +/// passed bytes are immediately written to the inner writer. #[test_case] fn long_line_flushed() { let writer = ProgrammableSink::default(); @@ -863,9 +863,10 @@ fn long_line_flushed() { } /// Test that, given a very long partial line *after* successfully -/// flushing a complete line, that that line is buffered unconditionally, -/// and no additional writes take place. This assures the property that -/// `write` should make at-most-one attempt to write new data. +/// flushing a complete line, the very long partial line is buffered +/// unconditionally, and no additional writes take place. This assures +/// the property that `write` should make at-most-one attempt to write +/// new data. #[test_case] fn line_long_tail_not_flushed() { let writer = ProgrammableSink::default(); diff --git a/sgx_tstd/src/io/copy.rs b/sgx_tstd/src/io/copy.rs index 8730bbd4a..1bed96d56 100644 --- a/sgx_tstd/src/io/copy.rs +++ b/sgx_tstd/src/io/copy.rs @@ -15,9 +15,17 @@ // specific language governing permissions and limitations // under the License.. -use super::{BorrowedBuf, BufWriter, ErrorKind, Read, Result, Write, DEFAULT_BUF_SIZE}; +use super::{BorrowedBuf, BufReader, BufWriter, Read, Result, Write, DEFAULT_BUF_SIZE}; +use crate::alloc::Allocator; +use crate::cmp; +use crate::cmp::min; +use crate::collections::VecDeque; +use crate::io::IoSlice; use crate::mem::MaybeUninit; +#[cfg(feature = "unit_test")] +mod tests; + /// Copies the entire contents of a reader into a writer. /// /// This function will continuously read data from `reader` and then @@ -27,7 +35,7 @@ use crate::mem::MaybeUninit; /// On success, the total number of bytes that were copied from /// `reader` to `writer` is returned. /// -/// If you’re wanting to copy the contents of one file to another and you’re +/// If you want to copy the contents of one file to another and you’re /// working with filesystem paths, see the [`fs::copy`] function. /// /// [`fs::copy`]: crate::fs::copy @@ -40,6 +48,7 @@ use crate::mem::MaybeUninit; /// /// [`read`]: Read::read /// [`write`]: Write::write +/// [`ErrorKind::Interrupted`]: crate::io::ErrorKind::Interrupted /// /// # Examples /// @@ -81,32 +90,145 @@ where R: Read, W: Write, { - BufferedCopySpec::copy_to(reader, writer) + let read_buf = BufferedReaderSpec::buffer_size(reader); + let write_buf = BufferedWriterSpec::buffer_size(writer); + + if read_buf >= DEFAULT_BUF_SIZE && read_buf >= write_buf { + return BufferedReaderSpec::copy_to(reader, writer); + } + + BufferedWriterSpec::copy_from(writer, reader) +} + +/// Specialization of the read-write loop that reuses the internal +/// buffer of a BufReader. If there's no buffer then the writer side +/// should be used instead. +trait BufferedReaderSpec { + fn buffer_size(&self) -> usize; + + fn copy_to(&mut self, to: &mut (impl Write + ?Sized)) -> Result; +} + +impl BufferedReaderSpec for T +where + Self: Read, + T: ?Sized, +{ + #[inline] + default fn buffer_size(&self) -> usize { + 0 + } + + default fn copy_to(&mut self, _to: &mut (impl Write + ?Sized)) -> Result { + unreachable!("only called from specializations") + } +} + +impl BufferedReaderSpec for &[u8] { + fn buffer_size(&self) -> usize { + // prefer this specialization since the source "buffer" is all we'll ever need, + // even if it's small + usize::MAX + } + + fn copy_to(&mut self, to: &mut (impl Write + ?Sized)) -> Result { + let len = self.len(); + to.write_all(self)?; + *self = &self[len..]; + Ok(len as u64) + } +} + +impl BufferedReaderSpec for VecDeque { + fn buffer_size(&self) -> usize { + // prefer this specialization since the source "buffer" is all we'll ever need, + // even if it's small + usize::MAX + } + + fn copy_to(&mut self, to: &mut (impl Write + ?Sized)) -> Result { + let len = self.len(); + let (front, back) = self.as_slices(); + let bufs = &mut [IoSlice::new(front), IoSlice::new(back)]; + to.write_all_vectored(bufs)?; + self.clear(); + Ok(len as u64) + } +} + +impl BufferedReaderSpec for BufReader +where + Self: Read, + I: ?Sized, +{ + fn buffer_size(&self) -> usize { + self.capacity() + } + + fn copy_to(&mut self, to: &mut (impl Write + ?Sized)) -> Result { + let mut len = 0; + + loop { + // Hack: this relies on `impl Read for BufReader` always calling fill_buf + // if the buffer is empty, even for empty slices. + // It can't be called directly here since specialization prevents us + // from adding I: Read + match self.read(&mut []) { + Ok(_) => {} + Err(e) if e.is_interrupted() => continue, + Err(e) => return Err(e), + } + let buf = self.buffer(); + if self.buffer().is_empty() { + return Ok(len); + } + + // In case the writer side is a BufWriter then its write_all + // implements an optimization that passes through large + // buffers to the underlying writer. That code path is #[cold] + // but we're still avoiding redundant memcopies when doing + // a copy between buffered inputs and outputs. + to.write_all(buf)?; + len += buf.len() as u64; + self.discard_buffer(); + } + } } /// Specialization of the read-write loop that either uses a stack buffer /// or reuses the internal buffer of a BufWriter -trait BufferedCopySpec: Write { - fn copy_to(reader: &mut R, writer: &mut Self) -> Result; +trait BufferedWriterSpec: Write { + fn buffer_size(&self) -> usize; + + fn copy_from(&mut self, reader: &mut R) -> Result; } -impl BufferedCopySpec for W { - default fn copy_to(reader: &mut R, writer: &mut Self) -> Result { - stack_buffer_copy(reader, writer) +impl BufferedWriterSpec for W { + #[inline] + default fn buffer_size(&self) -> usize { + 0 + } + + default fn copy_from(&mut self, reader: &mut R) -> Result { + stack_buffer_copy(reader, self) } } -impl BufferedCopySpec for BufWriter { - fn copy_to(reader: &mut R, writer: &mut Self) -> Result { - if writer.capacity() < DEFAULT_BUF_SIZE { - return stack_buffer_copy(reader, writer); +impl BufferedWriterSpec for BufWriter { + fn buffer_size(&self) -> usize { + self.capacity() + } + + fn copy_from(&mut self, reader: &mut R) -> Result { + if self.capacity() < DEFAULT_BUF_SIZE { + return stack_buffer_copy(reader, self); } let mut len = 0; let mut init = 0; loop { - let buf = writer.buffer_mut(); + let buf = self.buffer_mut(); let mut read_buf: BorrowedBuf<'_> = buf.spare_capacity_mut().into(); unsafe { @@ -133,17 +255,89 @@ impl BufferedCopySpec for BufWriter { // Read again if the buffer still has enough capacity, as BufWriter itself would do // This will occur if the reader returns short reads } - Err(ref e) if e.kind() == ErrorKind::Interrupted => {} + Err(ref e) if e.is_interrupted() => {} Err(e) => return Err(e), } } else { - writer.flush_buf()?; + self.flush_buf()?; init = 0; } } } } +impl BufferedWriterSpec for Vec { + fn buffer_size(&self) -> usize { + cmp::max(DEFAULT_BUF_SIZE, self.capacity() - self.len()) + } + + fn copy_from(&mut self, reader: &mut R) -> Result { + let mut bytes = 0; + + // avoid inflating empty/small vecs before we have determined that there's anything to read + if self.capacity() < DEFAULT_BUF_SIZE { + let stack_read_limit = DEFAULT_BUF_SIZE as u64; + bytes = stack_buffer_copy(&mut reader.take(stack_read_limit), self)?; + // fewer bytes than requested -> EOF reached + if bytes < stack_read_limit { + return Ok(bytes); + } + } + + // don't immediately offer the vec's whole spare capacity, otherwise + // we might have to fully initialize it if the reader doesn't have a custom read_buf() impl + let mut max_read_size = DEFAULT_BUF_SIZE; + + loop { + self.reserve(DEFAULT_BUF_SIZE); + let mut initialized_spare_capacity = 0; + + loop { + let buf = self.spare_capacity_mut(); + let read_size = min(max_read_size, buf.len()); + let mut buf = BorrowedBuf::from(&mut buf[..read_size]); + // SAFETY: init is either 0 or the init_len from the previous iteration. + unsafe { + buf.set_init(initialized_spare_capacity); + } + match reader.read_buf(buf.unfilled()) { + Ok(()) => { + let bytes_read = buf.len(); + + // EOF + if bytes_read == 0 { + return Ok(bytes); + } + + // the reader is returning short reads but it doesn't call ensure_init() + if buf.init_len() < buf.capacity() { + max_read_size = usize::MAX; + } + // the reader hasn't returned short reads so far + if bytes_read == buf.capacity() { + max_read_size *= 2; + } + + initialized_spare_capacity = buf.init_len() - bytes_read; + bytes += bytes_read as u64; + // SAFETY: BorrowedBuf guarantees all of its filled bytes are init + // and the number of read bytes can't exceed the spare capacity since + // that's what the buffer is borrowing from. + unsafe { self.set_len(self.len() + bytes_read) }; + + // spare capacity full, reserve more + if self.len() == self.capacity() { + break; + } + } + Err(e) if e.is_interrupted() => continue, + Err(e) => return Err(e), + } + } + } + } +} + fn stack_buffer_copy( reader: &mut R, writer: &mut W, @@ -156,7 +350,7 @@ fn stack_buffer_copy( loop { match reader.read_buf(buf.unfilled()) { Ok(()) => {} - Err(e) if e.kind() == ErrorKind::Interrupted => continue, + Err(e) if e.is_interrupted() => continue, Err(e) => return Err(e), }; diff --git a/sgx_tstd/src/io/copy/tests.rs b/sgx_tstd/src/io/copy/tests.rs new file mode 100644 index 000000000..80d4903da --- /dev/null +++ b/sgx_tstd/src/io/copy/tests.rs @@ -0,0 +1,163 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT 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 crate::cmp::{max, min}; +use crate::collections::VecDeque; +use crate::io; +use crate::io::*; + +use sgx_test_utils::test_case; + +#[test_case] +fn copy_copies() { + let mut r = repeat(0).take(4); + let mut w = sink(); + assert_eq!(copy(&mut r, &mut w).unwrap(), 4); + + let mut r = repeat(0).take(1 << 17); + assert_eq!(copy(&mut r as &mut dyn Read, &mut w as &mut dyn Write).unwrap(), 1 << 17); +} + +struct ShortReader { + cap: usize, + read_size: usize, + observed_buffer: usize, +} + +impl Read for ShortReader { + fn read(&mut self, buf: &mut [u8]) -> Result { + let bytes = min(self.cap, self.read_size).min(buf.len()); + self.cap -= bytes; + self.observed_buffer = max(self.observed_buffer, buf.len()); + Ok(bytes) + } +} + +struct WriteObserver { + observed_buffer: usize, +} + +impl Write for WriteObserver { + fn write(&mut self, buf: &[u8]) -> Result { + self.observed_buffer = max(self.observed_buffer, buf.len()); + Ok(buf.len()) + } + + fn flush(&mut self) -> Result<()> { + Ok(()) + } +} + +#[test_case] +fn copy_specializes_bufwriter() { + let cap = 117 * 1024; + let buf_sz = 16 * 1024; + let mut r = ShortReader { cap, observed_buffer: 0, read_size: 1337 }; + let mut w = BufWriter::with_capacity(buf_sz, WriteObserver { observed_buffer: 0 }); + assert_eq!( + copy(&mut r, &mut w).unwrap(), + cap as u64, + "expected the whole capacity to be copied" + ); + assert_eq!(r.observed_buffer, buf_sz, "expected a large buffer to be provided to the reader"); + assert!(w.get_mut().observed_buffer > DEFAULT_BUF_SIZE, "expected coalesced writes"); +} + +#[test_case] +fn copy_specializes_bufreader() { + let mut source = vec![0; 768 * 1024]; + source[1] = 42; + let mut buffered = BufReader::with_capacity(256 * 1024, Cursor::new(&mut source)); + + let mut sink = Vec::new(); + assert_eq!(crate::io::copy(&mut buffered, &mut sink).unwrap(), source.len() as u64); + assert_eq!(source.as_slice(), sink.as_slice()); + + let buf_sz = 71 * 1024; + assert!(buf_sz > DEFAULT_BUF_SIZE, "test precondition"); + + let mut buffered = BufReader::with_capacity(buf_sz, Cursor::new(&mut source)); + let mut sink = WriteObserver { observed_buffer: 0 }; + assert_eq!(crate::io::copy(&mut buffered, &mut sink).unwrap(), source.len() as u64); + assert_eq!( + sink.observed_buffer, buf_sz, + "expected a large buffer to be provided to the writer" + ); +} + +#[test_case] +fn copy_specializes_to_vec() { + let cap = 123456; + let mut source = ShortReader { cap, observed_buffer: 0, read_size: 1337 }; + let mut sink = Vec::new(); + assert_eq!(cap as u64, io::copy(&mut source, &mut sink).unwrap()); + assert!( + source.observed_buffer > DEFAULT_BUF_SIZE, + "expected a large buffer to be provided to the reader" + ); +} + +#[test_case] +fn copy_specializes_from_vecdeque() { + let mut source = VecDeque::with_capacity(100 * 1024); + for _ in 0..20 * 1024 { + source.push_front(0); + } + for _ in 0..20 * 1024 { + source.push_back(0); + } + let mut sink = WriteObserver { observed_buffer: 0 }; + assert_eq!(40 * 1024u64, io::copy(&mut source, &mut sink).unwrap()); + assert_eq!(20 * 1024, sink.observed_buffer); +} + +#[test_case] +fn copy_specializes_from_slice() { + let mut source = [1; 60 * 1024].as_slice(); + let mut sink = WriteObserver { observed_buffer: 0 }; + assert_eq!(60 * 1024u64, io::copy(&mut source, &mut sink).unwrap()); + assert_eq!(60 * 1024, sink.observed_buffer); +} + +mod io_benches { + use crate::fs::File; + use crate::fs::OpenOptions; + use crate::io::prelude::*; + use crate::io::BufReader; + + use sgx_test_utils::bench_case; + use sgx_test_utils::Bencher; + + #[bench_case] + fn bench_copy_buf_reader(b: &mut Bencher) { + let mut file_in = File::open("/dev/zero").expect("opening /dev/zero failed"); + // use dyn to avoid specializations unrelated to readbuf + let dyn_in = &mut file_in as &mut dyn Read; + let mut reader = BufReader::with_capacity(256 * 1024, dyn_in.take(0)); + let mut writer = + OpenOptions::new().write(true).open("/dev/null").expect("opening /dev/null failed"); + + const BYTES: u64 = 1024 * 1024; + + b.bytes = BYTES; + + b.iter(|| { + reader.get_mut().set_limit(BYTES); + crate::io::copy(&mut reader, &mut writer).unwrap() + }); + } +} diff --git a/sgx_tstd/src/io/cursor.rs b/sgx_tstd/src/io/cursor.rs index b519b6834..e5fc84157 100644 --- a/sgx_tstd/src/io/cursor.rs +++ b/sgx_tstd/src/io/cursor.rs @@ -51,7 +51,7 @@ use crate::io::{self, BorrowedCursor, ErrorKind, IoSlice, IoSliceMut, SeekFrom}; /// use std::fs::File; /// /// // a library function we've written -/// fn write_ten_bytes_at_end(writer: &mut W) -> io::Result<()> { +/// fn write_ten_bytes_at_end(mut writer: W) -> io::Result<()> { /// writer.seek(SeekFrom::End(-10))?; /// /// for i in 0..10 { diff --git a/sgx_tstd/src/io/cursor/tests.rs b/sgx_tstd/src/io/cursor/tests.rs index b14dec08e..b61a46f33 100644 --- a/sgx_tstd/src/io/cursor/tests.rs +++ b/sgx_tstd/src/io/cursor/tests.rs @@ -313,7 +313,7 @@ fn read_to_end() { #[test_case] fn test_slice_reader() { - let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7]; + let in_buf = [0, 1, 2, 3, 4, 5, 6, 7]; let reader = &mut &in_buf[..]; let mut buf = []; assert_eq!(reader.read(&mut buf).unwrap(), 0); @@ -335,7 +335,7 @@ fn test_slice_reader() { #[test_case] fn test_slice_reader_vectored() { - let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7]; + let in_buf = [0, 1, 2, 3, 4, 5, 6, 7]; let reader = &mut &in_buf[..]; let mut buf = []; assert_eq!(reader.read_vectored(&mut [IoSliceMut::new(&mut buf)]).unwrap(), 0); @@ -364,7 +364,7 @@ fn test_slice_reader_vectored() { #[test_case] fn test_read_exact() { - let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7]; + let in_buf = [0, 1, 2, 3, 4, 5, 6, 7]; let reader = &mut &in_buf[..]; let mut buf = []; assert!(reader.read_exact(&mut buf).is_ok()); @@ -382,7 +382,7 @@ fn test_read_exact() { #[test_case] fn test_buf_reader() { - let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7]; + let in_buf = [0, 1, 2, 3, 4, 5, 6, 7]; let mut reader = Cursor::new(&in_buf[..]); let mut buf = []; assert_eq!(reader.read(&mut buf).unwrap(), 0); diff --git a/sgx_tstd/src/io/error.rs b/sgx_tstd/src/io/error.rs index 0a01fff00..6481cc07d 100644 --- a/sgx_tstd/src/io/error.rs +++ b/sgx_tstd/src/io/error.rs @@ -97,13 +97,23 @@ impl From for Error { // doesn't accidentally get printed. #[cfg_attr(feature = "unit_test", derive(Debug))] enum ErrorData { - Os(i32), + Os(RawOsError), Simple(ErrorKind), SimpleMessage(&'static SimpleMessage), Custom(C), SgxStatus(SgxStatus), } +/// The type of raw OS error codes returned by [`Error::raw_os_error`]. +/// +/// This is an [`i32`] on all currently supported platforms, but platforms +/// added in the future (such as UEFI) may use a different primitive type like +/// [`usize`]. Use `as`or [`into`] conversions where applicable to ensure maximum +/// portability. +/// +/// [`into`]: Into::into +pub type RawOsError = sys::RawOsError; + // `#[repr(align(4))]` is probably redundant, it should have that value or // higher already. We include it just because repr_bitpacked.rs's encoding // requires an alignment >= 4 (note that `#[repr(align)]` will not reduce the @@ -329,7 +339,7 @@ pub enum ErrorKind { // "Unusual" error kinds which do not correspond simply to (sets // of) OS error codes, should be added just above this comment. - // `Other` and `Uncategorised` should remain at the end: + // `Other` and `Uncategorized` should remain at the end: // /// A custom error that does not fall under any other I/O error kind. /// @@ -488,6 +498,7 @@ impl Error { /// // creating an error without payload (and without memory allocation) /// let eof_error = Error::from(ErrorKind::UnexpectedEof); /// ``` + #[inline(never)] pub fn new(kind: ErrorKind, error: E) -> Error where E: Into>, @@ -504,8 +515,6 @@ impl Error { /// # Examples /// /// ``` - /// #![feature(io_error_other)] - /// /// use std::io::Error; /// /// // errors can be created from strings @@ -593,7 +602,7 @@ impl Error { /// ``` #[must_use] #[inline] - pub fn from_raw_os_error(code: i32) -> Error { + pub fn from_raw_os_error(code: RawOsError) -> Error { Error { repr: Repr::new_os(code) } } @@ -628,7 +637,7 @@ impl Error { /// ``` #[must_use] #[inline] - pub fn raw_os_error(&self) -> Option { + pub fn raw_os_error(&self) -> Option { match self.repr.data() { ErrorData::Os(i) => Some(i), ErrorData::Custom(..) => None, @@ -873,6 +882,13 @@ impl Error { /// Returns the corresponding [`ErrorKind`] for this error. /// + /// This may be a value set by Rust code constructing custom `io::Error`s, + /// or if this `io::Error` was sourced from the operating system, + /// it will be a value inferred from the system's error encoding. + /// See [`last_os_error`] for more details. + /// + /// [`last_os_error`]: Error::last_os_error + /// /// # Examples /// /// ``` @@ -883,7 +899,8 @@ impl Error { /// } /// /// fn main() { - /// // Will print "Uncategorized". + /// // As no error has (visibly) occurred, this may print anything! + /// // It likely prints a placeholder for unidentified (non-)errors. /// print_error(Error::last_os_error()); /// // Will print "AddrInUse". /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); @@ -900,6 +917,17 @@ impl Error { ErrorData::SgxStatus(..) => ErrorKind::SgxError, } } + + #[inline] + pub(crate) fn is_interrupted(&self) -> bool { + match self.repr.data() { + ErrorData::Os(code) => sys::is_interrupted(code), + ErrorData::Custom(c) => c.kind == ErrorKind::Interrupted, + ErrorData::Simple(kind) => kind == ErrorKind::Interrupted, + ErrorData::SimpleMessage(m) => m.kind == ErrorKind::Interrupted, + ErrorData::SgxStatus(_) => false, + } + } } impl fmt::Debug for Repr { diff --git a/sgx_tstd/src/io/error/repr_bitpacked.rs b/sgx_tstd/src/io/error/repr_bitpacked.rs new file mode 100644 index 000000000..ac44b3ab0 --- /dev/null +++ b/sgx_tstd/src/io/error/repr_bitpacked.rs @@ -0,0 +1,451 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +//! This is a densely packed error representation which is used on targets with +//! 64-bit pointers. +//! +//! (Note that `bitpacked` vs `unpacked` here has no relationship to +//! `#[repr(packed)]`, it just refers to attempting to use any available bits in +//! a more clever manner than `rustc`'s default layout algorithm would). +//! +//! Conceptually, it stores the same data as the "unpacked" equivalent we use on +//! other targets. Specifically, you can imagine it as an optimized version of +//! the following enum (which is roughly equivalent to what's stored by +//! `repr_unpacked::Repr`, e.g. `super::ErrorData>`): +//! +//! ```ignore (exposition-only) +//! enum ErrorData { +//! Os(i32), +//! Simple(ErrorKind), +//! SimpleMessage(&'static SimpleMessage), +//! Custom(Box), +//! SgxStatus(SgxStatus), +//! } +//! ``` +//! +//! However, it packs this data into a 64bit non-zero value. +//! +//! This optimization not only allows `io::Error` to occupy a single pointer, +//! but improves `io::Result` as well, especially for situations like +//! `io::Result<()>` (which is now 64 bits) or `io::Result` (which is now +//! 128 bits), which are quite common. +//! +//! # Layout +//! Tagged values are 64 bits, with the 2 least significant bits used for the +//! tag. This means there are there are 4 "variants": +//! +//! - **Tag 0b00**: The first variant is equivalent to +//! `ErrorData::SimpleMessage`, and holds a `&'static SimpleMessage` directly. +//! +//! `SimpleMessage` has an alignment >= 4 (which is requested with +//! `#[repr(align)]` and checked statically at the bottom of this file), which +//! means every `&'static SimpleMessage` should have the both tag bits as 0, +//! meaning its tagged and untagged representation are equivalent. +//! +//! This means we can skip tagging it, which is necessary as this variant can +//! be constructed from a `const fn`, which probably cannot tag pointers (or +//! at least it would be difficult). +//! +//! - **Tag 0b01**: The other pointer variant holds the data for +//! `ErrorData::Custom` and the remaining 62 bits are used to store a +//! `Box`. `Custom` also has alignment >= 4, so the bottom two bits +//! are free to use for the tag. +//! +//! The only important thing to note is that `ptr::wrapping_add` and +//! `ptr::wrapping_sub` are used to tag the pointer, rather than bitwise +//! operations. This should preserve the pointer's provenance, which would +//! otherwise be lost. +//! +//! - **Tag 0b10**: Holds the data for `ErrorData::Os(i32)`. We store the `i32` +//! in the pointer's most significant 32 bits, and don't use the bits `2..32` +//! for anything. Using the top 32 bits is just to let us easily recover the +//! `i32` code with the correct sign. +//! +//! - **Tag 0b11**: Holds the data for `ErrorData::Simple(ErrorKind)`. This +//! stores the `ErrorKind` in the top 32 bits as well, although it doesn't +//! occupy nearly that many. Most of the bits are unused here, but it's not +//! like we need them for anything else yet. +//! +//! # Use of `NonNull<()>` +//! +//! Everything is stored in a `NonNull<()>`, which is odd, but actually serves a +//! purpose. +//! +//! Conceptually you might think of this more like: +//! +//! ```ignore (exposition-only) +//! union Repr { +//! // holds integer (Simple/Os) variants, and +//! // provides access to the tag bits. +//! bits: NonZeroU64, +//! // Tag is 0, so this is stored untagged. +//! msg: &'static SimpleMessage, +//! // Tagged (offset) `Box` pointer. +//! tagged_custom: NonNull<()>, +//! } +//! ``` +//! +//! But there are a few problems with this: +//! +//! 1. Union access is equivalent to a transmute, so this representation would +//! require we transmute between integers and pointers in at least one +//! direction, which may be UB (and even if not, it is likely harder for a +//! compiler to reason about than explicit ptr->int operations). +//! +//! 2. Even if all fields of a union have a niche, the union itself doesn't, +//! although this may change in the future. This would make things like +//! `io::Result<()>` and `io::Result` larger, which defeats part of +//! the motivation of this bitpacking. +//! +//! Storing everything in a `NonZeroUsize` (or some other integer) would be a +//! bit more traditional for pointer tagging, but it would lose provenance +//! information, couldn't be constructed from a `const fn`, and would probably +//! run into other issues as well. +//! +//! The `NonNull<()>` seems like the only alternative, even if it's fairly odd +//! to use a pointer type to store something that may hold an integer, some of +//! the time. + +use super::{Custom, ErrorData, ErrorKind, RawOsError, SimpleMessage}; +use alloc_crate::boxed::Box; +use core::marker::PhantomData; +use core::mem::{align_of, size_of}; +use core::ptr::{self, NonNull}; + +use sgx_types::error::SgxStatus; + +// The 2 least-significant bits are used as tag. +const TAG_MASK: usize = 0b111; +const TAG_SIMPLE_MESSAGE: usize = 0b00; +const TAG_CUSTOM: usize = 0b01; +const TAG_OS: usize = 0b10; +const TAG_SIMPLE: usize = 0b11; +const TAG_SGX: usize = 0b100; + +/// The internal representation. +/// +/// See the module docs for more, this is just a way to hack in a check that we +/// indeed are not unwind-safe. +/// +/// ```compile_fail,E0277 +/// fn is_unwind_safe() {} +/// is_unwind_safe::(); +/// ``` +#[repr(transparent)] +pub(super) struct Repr(NonNull<()>, PhantomData>>); + +// All the types `Repr` stores internally are Send + Sync, and so is it. +unsafe impl Send for Repr {} +unsafe impl Sync for Repr {} + +impl Repr { + pub(super) fn new(dat: ErrorData>) -> Self { + match dat { + ErrorData::Os(code) => Self::new_os(code), + ErrorData::Simple(kind) => Self::new_simple(kind), + ErrorData::SimpleMessage(simple_message) => Self::new_simple_message(simple_message), + ErrorData::Custom(b) => Self::new_custom(b), + ErrorData::SgxStatus(status) => Self::new_sgx(status), + } + } + + pub(super) fn new_custom(b: Box) -> Self { + let p = Box::into_raw(b).cast::(); + // Should only be possible if an allocator handed out a pointer with + // wrong alignment. + debug_assert_eq!(p.addr() & TAG_MASK, 0); + // Note: We know `TAG_CUSTOM <= size_of::()` (static_assert at + // end of file), and both the start and end of the expression must be + // valid without address space wraparound due to `Box`'s semantics. + // + // This means it would be correct to implement this using `ptr::add` + // (rather than `ptr::wrapping_add`), but it's unclear this would give + // any benefit, so we just use `wrapping_add` instead. + let tagged = p.wrapping_add(TAG_CUSTOM).cast::<()>(); + // Safety: `TAG_CUSTOM + p` is the same as `TAG_CUSTOM | p`, + // because `p`'s alignment means it isn't allowed to have any of the + // `TAG_BITS` set (you can verify that addition and bitwise-or are the + // same when the operands have no bits in common using a truth table). + // + // Then, `TAG_CUSTOM | p` is not zero, as that would require + // `TAG_CUSTOM` and `p` both be zero, and neither is (as `p` came from a + // box, and `TAG_CUSTOM` just... isn't zero -- it's `0b01`). Therefore, + // `TAG_CUSTOM + p` isn't zero and so `tagged` can't be, and the + // `new_unchecked` is safe. + let res = Self(unsafe { NonNull::new_unchecked(tagged) }, PhantomData); + // quickly smoke-check we encoded the right thing (This generally will + // only run in std's tests, unless the user uses -Zbuild-std) + debug_assert!(matches!(res.data(), ErrorData::Custom(_)), "repr(custom) encoding failed"); + res + } + + #[inline] + pub(super) fn new_os(code: RawOsError) -> Self { + let utagged = ((code as usize) << 32) | TAG_OS; + // Safety: `TAG_OS` is not zero, so the result of the `|` is not 0. + let res = Self(unsafe { NonNull::new_unchecked(ptr::invalid_mut(utagged)) }, PhantomData); + // quickly smoke-check we encoded the right thing (This generally will + // only run in std's tests, unless the user uses -Zbuild-std) + debug_assert!( + matches!(res.data(), ErrorData::Os(c) if c == code), + "repr(os) encoding failed for {code}" + ); + res + } + + #[inline] + pub(super) fn new_simple(kind: ErrorKind) -> Self { + let utagged = ((kind as usize) << 32) | TAG_SIMPLE; + // Safety: `TAG_SIMPLE` is not zero, so the result of the `|` is not 0. + let res = Self(unsafe { NonNull::new_unchecked(ptr::invalid_mut(utagged)) }, PhantomData); + // quickly smoke-check we encoded the right thing (This generally will + // only run in std's tests, unless the user uses -Zbuild-std) + debug_assert!( + matches!(res.data(), ErrorData::Simple(k) if k == kind), + "repr(simple) encoding failed {:?}", + kind, + ); + res + } + + #[inline] + pub(super) fn new_sgx(status: SgxStatus) -> Self { + let utagged = ((status as usize) << 32) | TAG_SGX; + // Safety: `TAG_OS` is not zero, so the result of the `|` is not 0. + let res = Self(unsafe { NonNull::new_unchecked(ptr::invalid_mut(utagged)) }, PhantomData); + // quickly smoke-check we encoded the right thing (This generally will + // only run in std's tests, unless the user uses -Zbuild-std) + debug_assert!( + matches!(res.data(), ErrorData::SgxStatus(s) if s == status), + "repr(sgx) encoding failed for {status}" + ); + res + } + + #[inline] + pub(super) const fn new_simple_message(m: &'static SimpleMessage) -> Self { + // Safety: References are never null. + Self(unsafe { NonNull::new_unchecked(m as *const _ as *mut ()) }, PhantomData) + } + + #[inline] + pub(super) fn data(&self) -> ErrorData<&Custom> { + // Safety: We're a Repr, decode_repr is fine. + unsafe { decode_repr(self.0, |c| &*c) } + } + + #[inline] + pub(super) fn data_mut(&mut self) -> ErrorData<&mut Custom> { + // Safety: We're a Repr, decode_repr is fine. + unsafe { decode_repr(self.0, |c| &mut *c) } + } + + #[inline] + pub(super) fn into_data(self) -> ErrorData> { + let this = core::mem::ManuallyDrop::new(self); + // Safety: We're a Repr, decode_repr is fine. The `Box::from_raw` is + // safe because we prevent double-drop using `ManuallyDrop`. + unsafe { decode_repr(this.0, |p| Box::from_raw(p)) } + } +} + +impl Drop for Repr { + #[inline] + fn drop(&mut self) { + // Safety: We're a Repr, decode_repr is fine. The `Box::from_raw` is + // safe because we're being dropped. + unsafe { + let _ = decode_repr(self.0, |p| Box::::from_raw(p)); + } + } +} + +// Shared helper to decode a `Repr`'s internal pointer into an ErrorData. +// +// Safety: `ptr`'s bits should be encoded as described in the document at the +// top (it should `some_repr.0`) +#[inline] +unsafe fn decode_repr(ptr: NonNull<()>, make_custom: F) -> ErrorData +where + F: FnOnce(*mut Custom) -> C, +{ + let bits = ptr.as_ptr().addr(); + match bits & TAG_MASK { + TAG_OS => { + let code = ((bits as i64) >> 32) as RawOsError; + ErrorData::Os(code) + } + TAG_SIMPLE => { + let kind_bits = (bits >> 32) as u32; + let kind = kind_from_prim(kind_bits).unwrap_or_else(|| { + debug_assert!(false, "Invalid io::error::Repr bits: `Repr({:#018x})`", bits); + // This means the `ptr` passed in was not valid, which violates + // the unsafe contract of `decode_repr`. + // + // Using this rather than unwrap meaningfully improves the code + // for callers which only care about one variant (usually + // `Custom`) + core::hint::unreachable_unchecked(); + }); + ErrorData::Simple(kind) + } + TAG_SIMPLE_MESSAGE => ErrorData::SimpleMessage(&*ptr.cast::().as_ptr()), + TAG_CUSTOM => { + // It would be correct for us to use `ptr::byte_sub` here (see the + // comment above the `wrapping_add` call in `new_custom` for why), + // but it isn't clear that it makes a difference, so we don't. + let custom = ptr.as_ptr().wrapping_byte_sub(TAG_CUSTOM).cast::(); + ErrorData::Custom(make_custom(custom)) + } + TAG_SGX => { + let status = ((bits as i64) >> 32) as u32 as SgxStatus; + ErrorData::SgxStatus(status) + } + _ => { + // Can't happen, and compiler can tell + unreachable!(); + } + } +} + +// This compiles to the same code as the check+transmute, but doesn't require +// unsafe, or to hard-code max ErrorKind or its size in a way the compiler +// couldn't verify. +#[inline] +fn kind_from_prim(ek: u32) -> Option { + macro_rules! from_prim { + ($prim:expr => $Enum:ident { $($Variant:ident),* $(,)? }) => {{ + // Force a compile error if the list gets out of date. + const _: fn(e: $Enum) = |e: $Enum| match e { + $($Enum::$Variant => ()),* + }; + match $prim { + $(v if v == ($Enum::$Variant as _) => Some($Enum::$Variant),)* + _ => None, + } + }} + } + from_prim!(ek => ErrorKind { + NotFound, + PermissionDenied, + ConnectionRefused, + ConnectionReset, + HostUnreachable, + NetworkUnreachable, + ConnectionAborted, + NotConnected, + AddrInUse, + AddrNotAvailable, + NetworkDown, + BrokenPipe, + AlreadyExists, + WouldBlock, + NotADirectory, + IsADirectory, + DirectoryNotEmpty, + ReadOnlyFilesystem, + FilesystemLoop, + StaleNetworkFileHandle, + InvalidInput, + InvalidData, + TimedOut, + WriteZero, + StorageFull, + NotSeekable, + FilesystemQuotaExceeded, + FileTooLarge, + ResourceBusy, + ExecutableFileBusy, + Deadlock, + CrossesDevices, + TooManyLinks, + InvalidFilename, + ArgumentListTooLong, + Interrupted, + Other, + UnexpectedEof, + Unsupported, + OutOfMemory, + Uncategorized, + }) +} + +// Some static checking to alert us if a change breaks any of the assumptions +// that our encoding relies on for correctness and soundness. (Some of these are +// a bit overly thorough/cautious, admittedly) +// +// If any of these are hit on a platform that std supports, we should likely +// just use `repr_unpacked.rs` there instead (unless the fix is easy). +macro_rules! static_assert { + ($condition:expr) => { + const _: () = assert!($condition); + }; + (@usize_eq: $lhs:expr, $rhs:expr) => { + const _: [(); $lhs] = [(); $rhs]; + }; +} + +// The bitpacking we use requires pointers be exactly 64 bits. +static_assert!(@usize_eq: size_of::>(), 8); + +// We also require pointers and usize be the same size. +static_assert!(@usize_eq: size_of::>(), size_of::()); + +// `Custom` and `SimpleMessage` need to be thin pointers. +static_assert!(@usize_eq: size_of::<&'static SimpleMessage>(), 8); +static_assert!(@usize_eq: size_of::>(), 8); + +static_assert!((TAG_MASK + 1).is_power_of_two()); +// And they must have sufficient alignment. +static_assert!(align_of::() >= 4); +static_assert!(align_of::() >= 4); + +static_assert!(@usize_eq: TAG_MASK & TAG_SIMPLE_MESSAGE, TAG_SIMPLE_MESSAGE); +static_assert!(@usize_eq: TAG_MASK & TAG_CUSTOM, TAG_CUSTOM); +static_assert!(@usize_eq: TAG_MASK & TAG_OS, TAG_OS); +static_assert!(@usize_eq: TAG_MASK & TAG_SIMPLE, TAG_SIMPLE); +static_assert!(@usize_eq: TAG_MASK & TAG_SGX, TAG_SGX); + +// This is obviously true (`TAG_CUSTOM` is `0b01`), but in `Repr::new_custom` we +// offset a pointer by this value, and expect it to both be within the same +// object, and to not wrap around the address space. See the comment in that +// function for further details. +// +// Actually, at the moment we use `ptr::wrapping_add`, not `ptr::add`, so this +// check isn't needed for that one, although the assertion that we don't +// actually wrap around in that wrapping_add does simplify the safety reasoning +// elsewhere considerably. +static_assert!(size_of::() >= TAG_CUSTOM); + +// These two store a payload which is allowed to be zero, so they must be +// non-zero to preserve the `NonNull`'s range invariant. +static_assert!(TAG_OS != 0); +static_assert!(TAG_SIMPLE != 0); +static_assert!(TAG_SGX != 0); +// We can't tag `SimpleMessage`s, the tag must be 0. +static_assert!(@usize_eq: TAG_SIMPLE_MESSAGE, 0); + +// Check that the point of all of this still holds. +// +// We'd check against `io::Error`, but *technically* it's allowed to vary, +// as it's not `#[repr(transparent)]`/`#[repr(C)]`. We could add that, but +// the `#[repr()]` would show up in rustdoc, which might be seen as a stable +// commitment. +static_assert!(@usize_eq: size_of::(), 8); +static_assert!(@usize_eq: size_of::>(), 8); +static_assert!(@usize_eq: size_of::>(), 8); +static_assert!(@usize_eq: size_of::>(), 16); diff --git a/sgx_tstd/src/io/error/repr_unpacked.rs b/sgx_tstd/src/io/error/repr_unpacked.rs index 1e12cac08..92aeb2e93 100644 --- a/sgx_tstd/src/io/error/repr_unpacked.rs +++ b/sgx_tstd/src/io/error/repr_unpacked.rs @@ -1,8 +1,25 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + //! This is a fairly simple unpacked error representation that's used on //! non-64bit targets, where the packed 64 bit representation wouldn't work, and //! would have no benefit. -use super::{Custom, ErrorData, ErrorKind, SimpleMessage}; +use super::{Custom, ErrorData, ErrorKind, RawOsError, SimpleMessage}; use alloc_crate::boxed::Box; use sgx_types::error::SgxStatus; @@ -20,7 +37,7 @@ impl Repr { Self(Inner::Custom(b)) } #[inline] - pub(super) fn new_os(code: i32) -> Self { + pub(super) fn new_os(code: RawOsError) -> Self { Self(Inner::Os(code)) } #[inline] @@ -45,7 +62,7 @@ impl Repr { Inner::Os(c) => ErrorData::Os(*c), Inner::Simple(k) => ErrorData::Simple(*k), Inner::SimpleMessage(m) => ErrorData::SimpleMessage(*m), - Inner::Custom(m) => ErrorData::Custom(&**m), + Inner::Custom(m) => ErrorData::Custom(m), Inner::SgxStatus(s) => ErrorData::SgxStatus(*s), } } diff --git a/sgx_tstd/src/io/error/tests.rs b/sgx_tstd/src/io/error/tests.rs index b83d4c7e8..58d6e1148 100644 --- a/sgx_tstd/src/io/error/tests.rs +++ b/sgx_tstd/src/io/error/tests.rs @@ -90,7 +90,7 @@ fn test_const() { #[test_case] fn test_os_packing() { - for code in -20i32..20i32 { + for code in -20..20 { let e = Error::from_raw_os_error(code); assert_eq!(e.raw_os_error(), Some(code)); assert_matches!( @@ -210,5 +210,5 @@ fn test_std_io_error_downcast() { let io_error = io_error.downcast::().unwrap_err(); assert_eq!(SIMPLE_MESSAGE.kind, io_error.kind()); - assert_eq!(SIMPLE_MESSAGE.message, &*format!("{io_error}")); + assert_eq!(SIMPLE_MESSAGE.message, format!("{io_error}")); } diff --git a/sgx_tstd/src/io/impls.rs b/sgx_tstd/src/io/impls.rs index 234ea20b2..0992d69df 100644 --- a/sgx_tstd/src/io/impls.rs +++ b/sgx_tstd/src/io/impls.rs @@ -26,6 +26,7 @@ use crate::io::{ self, BorrowedCursor, BufRead, ErrorKind, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write, }; use crate::mem; +use crate::str; // ============================================================================= // Forwarding implementations @@ -321,6 +322,17 @@ impl Read for &[u8] { *self = &self[len..]; Ok(len) } + + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + let content = str::from_utf8(self).map_err(|_| { + io::const_io_error!(ErrorKind::InvalidData, "stream did not contain valid UTF-8") + })?; + buf.push_str(content); + let len = self.len(); + *self = &self[len..]; + Ok(len) + } } impl BufRead for &[u8] { @@ -349,7 +361,7 @@ impl Write for &mut [u8] { #[inline] fn write(&mut self, data: &[u8]) -> io::Result { let amt = cmp::min(data.len(), self.len()); - let (a, b) = mem::replace(self, &mut []).split_at_mut(amt); + let (a, b) = mem::take(self).split_at_mut(amt); a.copy_from_slice(&data[..amt]); *self = b; Ok(amt) @@ -445,6 +457,50 @@ impl Read for VecDeque { self.drain(..n); Ok(()) } + + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + // The total len is known upfront so we can reserve it in a single call. + let len = self.len(); + buf.reserve(len); + + let (front, back) = self.as_slices(); + buf.extend_from_slice(front); + buf.extend_from_slice(back); + self.clear(); + Ok(len) + } + + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + // We have to use a single contiguous slice because the `VecDequeue` might be split in the + // middle of an UTF-8 character. + let len = self.len(); + let content = self.make_contiguous(); + let string = str::from_utf8(content).map_err(|_| { + io::const_io_error!(ErrorKind::InvalidData, "stream did not contain valid UTF-8") + })?; + buf.push_str(string); + self.clear(); + Ok(len) + } +} + +/// BufRead is implemented for `VecDeque` by reading bytes from the front of the `VecDeque`. +impl BufRead for VecDeque { + /// Returns the contents of the "front" slice as returned by + /// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are + /// discontiguous, multiple calls to `fill_buf` will be needed to read the entire content. + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { + let (front, _) = self.as_slices(); + Ok(front) + } + + #[inline] + fn consume(&mut self, amt: usize) { + self.drain(..amt); + } } /// Write is implemented for `VecDeque` by appending to the `VecDeque`, growing it as needed. @@ -455,6 +511,21 @@ impl Write for VecDeque { Ok(buf.len()) } + #[inline] + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); + self.reserve(len); + for buf in bufs { + self.extend(&**buf); + } + Ok(len) + } + + #[inline] + fn is_write_vectored(&self) -> bool { + true + } + #[inline] fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { self.extend(buf); @@ -466,3 +537,16 @@ impl Write for VecDeque { Ok(()) } } + +impl<'a> io::Write for core::io::BorrowedCursor<'a> { + fn write(&mut self, buf: &[u8]) -> io::Result { + let amt = cmp::min(buf.len(), self.capacity()); + self.append(&buf[..amt]); + Ok(amt) + } + + #[inline] + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} diff --git a/sgx_tstd/src/io/mod.rs b/sgx_tstd/src/io/mod.rs index 661b2333e..a69119386 100644 --- a/sgx_tstd/src/io/mod.rs +++ b/sgx_tstd/src/io/mod.rs @@ -22,7 +22,7 @@ //! the [`Read`] and [`Write`] traits, which provide the //! most general interface for reading and writing input and output. //! -//! # Read and Write +//! ## Read and Write //! //! Because they are traits, [`Read`] and [`Write`] are implemented by a number //! of other types, and you can implement them for your types too. As such, @@ -255,6 +255,47 @@ //! contract. The implementation of many of these functions are subject to change over //! time and may call fewer or more syscalls/library functions. //! +//! ## I/O Safety +//! +//! Rust follows an I/O safety discipline that is comparable to its memory safety discipline. This +//! means that file descriptors can be *exclusively owned*. (Here, "file descriptor" is meant to +//! subsume similar concepts that exist across a wide range of operating systems even if they might +//! use a different name, such as "handle".) An exclusively owned file descriptor is one that no +//! other code is allowed to access in any way, but the owner is allowed to access and even close +//! it any time. A type that owns its file descriptor should usually close it in its `drop` +//! function. Types like [`File`] own their file descriptor. Similarly, file descriptors +//! can be *borrowed*, granting the temporary right to perform operations on this file descriptor. +//! This indicates that the file descriptor will not be closed for the lifetime of the borrow, but +//! it does *not* imply any right to close this file descriptor, since it will likely be owned by +//! someone else. +//! +//! The platform-specific parts of the Rust standard library expose types that reflect these +//! concepts, see [`os::unix`] and [`os::windows`]. +//! +//! To uphold I/O safety, it is crucial that no code acts on file descriptors it does not own or +//! borrow, and no code closes file descriptors it does not own. In other words, a safe function +//! that takes a regular integer, treats it as a file descriptor, and acts on it, is *unsound*. +//! +//! Not upholding I/O safety and acting on a file descriptor without proof of ownership can lead to +//! misbehavior and even Undefined Behavior in code that relies on ownership of its file +//! descriptors: a closed file descriptor could be re-allocated, so the original owner of that file +//! descriptor is now working on the wrong file. Some code might even rely on fully encapsulating +//! its file descriptors with no operations being performed by any other part of the program. +//! +//! Note that exclusive ownership of a file descriptor does *not* imply exclusive ownership of the +//! underlying kernel object that the file descriptor references (also called "file description" on +//! some operating systems). File descriptors basically work like [`Arc`]: when you receive an owned +//! file descriptor, you cannot know whether there are any other file descriptors that reference the +//! same kernel object. However, when you create a new kernel object, you know that you are holding +//! the only reference to it. Just be careful not to lend it to anyone, since they can obtain a +//! clone and then you can no longer know what the reference count is! In that sense, [`OwnedFd`] is +//! like `Arc` and [`BorrowedFd<'a>`] is like `&'a Arc` (and similar for the Windows types). In +//! particular, given a `BorrowedFd<'a>`, you are not allowed to close the file descriptor -- just +//! like how, given a `&'a Arc`, you are not allowed to decrement the reference count and +//! potentially free the underlying object. There is no equivalent to `Box` for file descriptors in +//! the standard library (that would be a type that guarantees that the reference count is `1`), +//! however, it would be possible for a crate to define a type with those semantics. +//! //! [`File`]: crate::fs::File //! [`TcpStream`]: crate::net::TcpStream //! [`io::stdout`]: stdout @@ -268,7 +309,7 @@ mod tests; use crate::cmp; use crate::fmt; -use crate::mem::replace; +use crate::mem::take; use crate::ops::{Deref, DerefMut}; use crate::slice; use crate::str; @@ -276,9 +317,11 @@ use crate::sys; use crate::sys_common::memchr; pub use self::buffered::WriterPanicked; +pub use self::error::RawOsError; #[cfg(feature = "stdio")] #[allow(unused_imports)] pub(crate) use self::stdio::attempt_print_to_stderr; +pub use self::stdio::IsTerminal; #[cfg(feature = "stdio")] pub use self::stdio::set_output_capture; #[cfg(feature = "stdio")] @@ -293,7 +336,7 @@ pub use self::{ util::{empty, repeat, sink, Empty, Repeat, Sink}, }; -pub use self::readbuf::{BorrowedBuf, BorrowedCursor}; +pub use core::io::{BorrowedBuf, BorrowedCursor}; pub(crate) use error::const_io_error; mod buffered; @@ -302,20 +345,10 @@ mod cursor; mod error; mod impls; pub mod prelude; -mod readbuf; #[cfg(feature = "stdio")] mod stdio; mod util; -pub trait IsTerminal: crate::sealed::Sealed { - /// Returns `true` if the descriptor/handle refers to a terminal/tty. - /// - /// On platforms where Rust does not know how to detect a terminal yet, this will return - /// `false`. This will also return `false` if an unexpected error occurred, such as from - /// passing an invalid file descriptor. - fn is_terminal(&self) -> bool; -} - const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; #[cfg(feature = "stdio")] @@ -378,9 +411,17 @@ where // of data to return. Simply tacking on an extra DEFAULT_BUF_SIZE space every // time is 4,500 times (!) slower than a default reservation size of 32 if the // reader has a very small amount of data to return. -pub(crate) fn default_read_to_end(r: &mut R, buf: &mut Vec) -> Result { +pub(crate) fn default_read_to_end( + r: &mut R, + buf: &mut Vec, + size_hint: Option, +) -> Result { let start_len = buf.len(); let start_cap = buf.capacity(); + // Optionally limit the maximum bytes read on each iteration. + // This adds an arbitrary fiddle factor to allow for more data than we expect. + let max_read_size = + size_hint.and_then(|s| s.checked_add(1024)?.checked_next_multiple_of(DEFAULT_BUF_SIZE)); let mut initialized = 0; // Extra initialized bytes from previous loop iteration loop { @@ -388,7 +429,12 @@ pub(crate) fn default_read_to_end(r: &mut R, buf: &mut Vec buf.reserve(32); // buf is full, need more space } - let mut read_buf: BorrowedBuf<'_> = buf.spare_capacity_mut().into(); + let mut spare = buf.spare_capacity_mut(); + if let Some(size) = max_read_size { + let len = cmp::min(spare.len(), size); + spare = &mut spare[..len] + } + let mut read_buf: BorrowedBuf<'_> = spare.into(); // SAFETY: These bytes were initialized but not filled in the previous loop unsafe { @@ -398,7 +444,7 @@ pub(crate) fn default_read_to_end(r: &mut R, buf: &mut Vec let mut cursor = read_buf.unfilled(); match r.read_buf(cursor.reborrow()) { Ok(()) => {} - Err(e) if e.kind() == ErrorKind::Interrupted => continue, + Err(e) if e.is_interrupted() => continue, Err(e) => return Err(e), } @@ -429,7 +475,7 @@ pub(crate) fn default_read_to_end(r: &mut R, buf: &mut Vec buf.extend_from_slice(&probe[..n]); break; } - Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, + Err(ref e) if e.is_interrupted() => continue, Err(e) => return Err(e), } } @@ -440,6 +486,7 @@ pub(crate) fn default_read_to_end(r: &mut R, buf: &mut Vec pub(crate) fn default_read_to_string( r: &mut R, buf: &mut String, + size_hint: Option, ) -> Result { // Note that we do *not* call `r.read_to_end()` here. We are passing // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` @@ -450,7 +497,7 @@ pub(crate) fn default_read_to_string( // To prevent extraneously checking the UTF-8-ness of the entire buffer // we pass it to our hardcoded `default_read_to_end` implementation which // we know is guaranteed to only read data into the end of the buffer. - unsafe { append_to_string(buf, |b| default_read_to_end(r, b)) } + unsafe { append_to_string(buf, |b| default_read_to_end(r, b, size_hint)) } } pub(crate) fn default_read_vectored(read: F, bufs: &mut [IoSliceMut<'_>]) -> Result @@ -474,10 +521,9 @@ pub(crate) fn default_read_exact(this: &mut R, mut buf: &mut [ match this.read(buf) { Ok(0) => break, Ok(n) => { - let tmp = buf; - buf = &mut tmp[n..]; + buf = &mut buf[n..]; } - Err(ref e) if e.kind() == ErrorKind::Interrupted => {} + Err(ref e) if e.is_interrupted() => {} Err(e) => return Err(e), } } @@ -598,18 +644,19 @@ pub trait Read { /// This may happen for example because fewer bytes are actually available right now /// (e. g. being close to end-of-file) or because read() was interrupted by a signal. /// - /// As this trait is safe to implement, callers cannot rely on `n <= buf.len()` for safety. + /// As this trait is safe to implement, callers in unsafe code cannot rely on + /// `n <= buf.len()` for safety. /// Extra care needs to be taken when `unsafe` functions are used to access the read bytes. /// Callers have to ensure that no unchecked out-of-bounds accesses are possible even if /// `n > buf.len()`. /// /// No guarantees are provided about the contents of `buf` when this - /// function is called, implementations cannot rely on any property of the + /// function is called, so implementations cannot rely on any property of the /// contents of `buf` being true. It is recommended that *implementations* /// only write data to `buf` instead of reading its contents. /// - /// Correspondingly, however, *callers* of this method must not assume any guarantees - /// about how the implementation uses `buf`. The trait is safe to implement, + /// Correspondingly, however, *callers* of this method in unsafe code must not assume + /// any guarantees about how the implementation uses `buf`. The trait is safe to implement, /// so it is possible that the code that's supposed to write to the buffer might also read /// from it. It is your responsibility to make sure that `buf` is initialized /// before calling `read`. Calling `read` with an uninitialized `buf` (of the kind one @@ -724,7 +771,7 @@ pub trait Read { /// /// [`std::fs::read`]: crate::fs::read fn read_to_end(&mut self, buf: &mut Vec) -> Result { - default_read_to_end(self, buf) + default_read_to_end(self, buf, None) } /// Read all bytes until EOF in this source, appending them to `buf`. @@ -766,7 +813,7 @@ pub trait Read { /// /// [`std::fs::read_to_string`]: crate::fs::read_to_string fn read_to_string(&mut self, buf: &mut String) -> Result { - default_read_to_string(self, buf) + default_read_to_string(self, buf, None) } /// Read the exact number of bytes required to fill `buf`. @@ -775,7 +822,7 @@ pub trait Read { /// specified buffer `buf`. /// /// No guarantees are provided about the contents of `buf` when this - /// function is called, implementations cannot rely on any property of the + /// function is called, so implementations cannot rely on any property of the /// contents of `buf` being true. It is recommended that implementations /// only write data to `buf` instead of reading its contents. The /// documentation on [`read`] has a more detailed explanation on this @@ -835,14 +882,28 @@ pub trait Read { /// Read the exact number of bytes required to fill `cursor`. /// - /// This is equivalent to the [`read_exact`](Read::read_exact) method, except that it is passed a [`BorrowedCursor`] rather than `[u8]` to - /// allow use with uninitialized buffers. + /// This is similar to the [`read_exact`](Read::read_exact) method, except + /// that it is passed a [`BorrowedCursor`] rather than `[u8]` to allow use + /// with uninitialized buffers. + /// + /// # Errors + /// + /// If this function encounters an error of the kind [`ErrorKind::Interrupted`] + /// then the error is ignored and the operation will continue. + /// + /// If this function encounters an "end of file" before completely filling + /// the buffer, it returns an error of the kind [`ErrorKind::UnexpectedEof`]. + /// + /// If any other read error is encountered then this function immediately + /// returns. + /// + /// If this function returns an error, all bytes read will be appended to `cursor`. fn read_buf_exact(&mut self, mut cursor: BorrowedCursor<'_>) -> Result<()> { while cursor.capacity() > 0 { let prev_written = cursor.written(); match self.read_buf(cursor.reborrow()) { Ok(()) => {} - Err(e) if e.kind() == ErrorKind::Interrupted => continue, + Err(e) if e.is_interrupted() => continue, Err(e) => return Err(e), } @@ -1161,22 +1222,22 @@ impl<'a> IoSliceMut<'a> { pub fn advance_slices(bufs: &mut &mut [IoSliceMut<'a>], n: usize) { // Number of buffers to remove. let mut remove = 0; - // Total length of all the to be removed buffers. - let mut accumulated_len = 0; + // Remaining length before reaching n. + let mut left = n; for buf in bufs.iter() { - if accumulated_len + buf.len() > n { - break; - } else { - accumulated_len += buf.len(); + if let Some(remainder) = left.checked_sub(buf.len()) { + left = remainder; remove += 1; + } else { + break; } } - *bufs = &mut replace(bufs, &mut [])[remove..]; + *bufs = &mut take(bufs)[remove..]; if bufs.is_empty() { - assert!(n == accumulated_len, "advancing io slices beyond their length"); + assert!(left == 0, "advancing io slices beyond their length"); } else { - bufs[0].advance(n - accumulated_len) + bufs[0].advance(left); } } } @@ -1296,22 +1357,25 @@ impl<'a> IoSlice<'a> { pub fn advance_slices(bufs: &mut &mut [IoSlice<'a>], n: usize) { // Number of buffers to remove. let mut remove = 0; - // Total length of all the to be removed buffers. - let mut accumulated_len = 0; + // Remaining length before reaching n. This prevents overflow + // that could happen if the length of slices in `bufs` were instead + // accumulated. Those slice may be aliased and, if they are large + // enough, their added length may overflow a `usize`. + let mut left = n; for buf in bufs.iter() { - if accumulated_len + buf.len() > n { - break; - } else { - accumulated_len += buf.len(); + if let Some(remainder) = left.checked_sub(buf.len()) { + left = remainder; remove += 1; + } else { + break; } } - *bufs = &mut replace(bufs, &mut [])[remove..]; + *bufs = &mut take(bufs)[remove..]; if bufs.is_empty() { - assert!(n == accumulated_len, "advancing io slices beyond their length"); + assert!(left == 0, "advancing io slices beyond their length"); } else { - bufs[0].advance(n - accumulated_len) + bufs[0].advance(left); } } } @@ -1376,17 +1440,18 @@ pub trait Write { /// /// This function will attempt to write the entire contents of `buf`, but /// the entire write might not succeed, or the write may also generate an - /// error. A call to `write` represents *at most one* attempt to write to + /// error. Typically, a call to `write` represents one attempt to write to /// any wrapped object. /// /// Calls to `write` are not guaranteed to block waiting for data to be /// written, and a write which would otherwise block can be indicated through /// an [`Err`] variant. /// - /// If the return value is [`Ok(n)`] then it must be guaranteed that - /// `n <= buf.len()`. A return value of `0` typically means that the - /// underlying object is no longer able to accept bytes and will likely not - /// be able to in the future as well, or that the buffer provided is empty. + /// If this method consumed `n > 0` bytes of `buf` it must return [`Ok(n)`]. + /// If the return value is `Ok(n)` then `n` must satisfy `n <= buf.len()`. + /// A return value of `Ok(0)` typically means that the underlying object is + /// no longer able to accept bytes and will likely not be able to in the + /// future as well, or that the buffer provided is empty. /// /// # Errors /// @@ -1533,7 +1598,7 @@ pub trait Write { )); } Ok(n) => buf = &buf[n..], - Err(ref e) if e.kind() == ErrorKind::Interrupted => {} + Err(ref e) if e.is_interrupted() => {} Err(e) => return Err(e), } } @@ -1600,7 +1665,7 @@ pub trait Write { )); } Ok(n) => IoSlice::advance_slices(&mut bufs, n), - Err(ref e) if e.kind() == ErrorKind::Interrupted => {} + Err(ref e) if e.is_interrupted() => {} Err(e) => return Err(e), } } @@ -1885,7 +1950,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) -> R let (done, used) = { let available = match r.fill_buf() { Ok(n) => n, - Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, + Err(ref e) if e.is_interrupted() => continue, Err(e) => return Err(e), }; match memchr::memchr(delim, available) { @@ -2106,8 +2171,10 @@ pub trait BufRead: Read { } /// Read all bytes until a newline (the `0xA` byte) is reached, and append - /// them to the provided buffer. You do not need to clear the buffer before - /// appending. + /// them to the provided `String` buffer. + /// + /// Previous content of the buffer will be preserved. To avoid appending to + /// the buffer, you need to [`clear`] it first. /// /// This function will read bytes from the underlying stream until the /// newline delimiter (the `0xA` byte) or EOF is found. Once found, all bytes @@ -2120,9 +2187,11 @@ pub trait BufRead: Read { /// /// This function is blocking and should be used carefully: it is possible for /// an attacker to continuously send bytes without ever sending a newline - /// or EOF. + /// or EOF. You can use [`take`] to limit the maximum number of bytes read. /// /// [`Ok(0)`]: Ok + /// [`clear`]: String::clear + /// [`take`]: crate::io::Read::take /// /// # Errors /// @@ -2555,7 +2624,7 @@ impl Read for Take { // if we just use an as cast to convert, limit may wrap around on a 32 bit target let limit = cmp::min(self.limit, usize::MAX as u64) as usize; - let extra_init = cmp::min(limit, buf.init_ref().len()); + let extra_init = cmp::min(limit as usize, buf.init_ref().len()); // SAFETY: no uninit data is written to ibuf let ibuf = unsafe { &mut buf.as_mut()[..limit] }; @@ -2642,23 +2711,55 @@ pub struct Bytes { impl Iterator for Bytes { type Item = Result; + // Not `#[inline]`. This function gets inlined even without it, but having + // the inline annotation can result in worse code generation. See #116785. fn next(&mut self) -> Option> { - let mut byte = 0; - loop { - return match self.inner.read(slice::from_mut(&mut byte)) { - Ok(0) => None, - Ok(..) => Some(Ok(byte)), - Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, - Err(e) => Some(Err(e)), - }; - } + SpecReadByte::spec_read_byte(&mut self.inner) } + #[inline] fn size_hint(&self) -> (usize, Option) { SizeHint::size_hint(&self.inner) } } +/// For the specialization of `Bytes::next`. +trait SpecReadByte { + fn spec_read_byte(&mut self) -> Option>; +} + +impl SpecReadByte for R +where + Self: Read, +{ + #[inline] + default fn spec_read_byte(&mut self) -> Option> { + inlined_slow_read_byte(self) + } +} + +/// Read a single byte in a slow, generic way. This is used by the default +/// `spec_read_byte`. +#[inline] +fn inlined_slow_read_byte(reader: &mut R) -> Option> { + let mut byte = 0; + loop { + return match reader.read(slice::from_mut(&mut byte)) { + Ok(0) => None, + Ok(..) => Some(Ok(byte)), + Err(ref e) if e.is_interrupted() => continue, + Err(e) => Some(Err(e)), + }; + } +} + +// Used by `BufReader::spec_read_byte`, for which the `inline(ever)` is +// important. +#[inline(never)] +fn uninlined_slow_read_byte(reader: &mut R) -> Option> { + inlined_slow_read_byte(reader) +} + trait SizeHint { fn lower_bound(&self) -> usize; @@ -2669,7 +2770,7 @@ trait SizeHint { } } -impl SizeHint for T { +impl SizeHint for T { #[inline] default fn lower_bound(&self) -> usize { 0 diff --git a/sgx_tstd/src/io/readbuf.rs b/sgx_tstd/src/io/readbuf.rs deleted file mode 100644 index 722b97429..000000000 --- a/sgx_tstd/src/io/readbuf.rs +++ /dev/null @@ -1,324 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License.. - -#[cfg(feature = "unit_test")] -mod tests; - -use crate::fmt::{self, Debug, Formatter}; -use crate::io::{Result, Write}; -use crate::mem::{self, MaybeUninit}; -use crate::{cmp, ptr}; - -/// A borrowed byte buffer which is incrementally filled and initialized. -/// -/// This type is a sort of "double cursor". It tracks three regions in the buffer: a region at the beginning of the -/// buffer that has been logically filled with data, a region that has been initialized at some point but not yet -/// logically filled, and a region at the end that is fully uninitialized. The filled region is guaranteed to be a -/// subset of the initialized region. -/// -/// In summary, the contents of the buffer can be visualized as: -/// ```not_rust -/// [ capacity ] -/// [ filled | unfilled ] -/// [ initialized | uninitialized ] -/// ``` -/// -/// A `BorrowedBuf` is created around some existing data (or capacity for data) via a unique reference -/// (`&mut`). The `BorrowedBuf` can be configured (e.g., using `clear` or `set_init`), but cannot be -/// directly written. To write into the buffer, use `unfilled` to create a `BorrowedCursor`. The cursor -/// has write-only access to the unfilled portion of the buffer (you can think of it as a -/// write-only iterator). -/// -/// The lifetime `'data` is a bound on the lifetime of the underlying data. -pub struct BorrowedBuf<'data> { - /// The buffer's underlying data. - buf: &'data mut [MaybeUninit], - /// The length of `self.buf` which is known to be filled. - filled: usize, - /// The length of `self.buf` which is known to be initialized. - init: usize, -} - -impl Debug for BorrowedBuf<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - f.debug_struct("BorrowedBuf") - .field("init", &self.init) - .field("filled", &self.filled) - .field("capacity", &self.capacity()) - .finish() - } -} - -/// Create a new `BorrowedBuf` from a fully initialized slice. -impl<'data> From<&'data mut [u8]> for BorrowedBuf<'data> { - #[inline] - fn from(slice: &'data mut [u8]) -> BorrowedBuf<'data> { - let len = slice.len(); - - BorrowedBuf { - // SAFETY: initialized data never becoming uninitialized is an invariant of BorrowedBuf - buf: unsafe { (slice as *mut [u8]).as_uninit_slice_mut().unwrap() }, - filled: 0, - init: len, - } - } -} - -/// Create a new `BorrowedBuf` from an uninitialized buffer. -/// -/// Use `set_init` if part of the buffer is known to be already initialized. -impl<'data> From<&'data mut [MaybeUninit]> for BorrowedBuf<'data> { - #[inline] - fn from(buf: &'data mut [MaybeUninit]) -> BorrowedBuf<'data> { - BorrowedBuf { buf, filled: 0, init: 0 } - } -} - -impl<'data> BorrowedBuf<'data> { - /// Returns the total capacity of the buffer. - #[inline] - pub fn capacity(&self) -> usize { - self.buf.len() - } - - /// Returns the length of the filled part of the buffer. - #[inline] - pub fn len(&self) -> usize { - self.filled - } - - /// Returns the length of the initialized part of the buffer. - #[inline] - pub fn init_len(&self) -> usize { - self.init - } - - /// Returns a shared reference to the filled portion of the buffer. - #[inline] - pub fn filled(&self) -> &[u8] { - // SAFETY: We only slice the filled part of the buffer, which is always valid - unsafe { MaybeUninit::slice_assume_init_ref(&self.buf[0..self.filled]) } - } - - /// Returns a cursor over the unfilled part of the buffer. - #[inline] - pub fn unfilled<'this>(&'this mut self) -> BorrowedCursor<'this> { - BorrowedCursor { - start: self.filled, - // SAFETY: we never assign into `BorrowedCursor::buf`, so treating its - // lifetime covariantly is safe. - buf: unsafe { - mem::transmute::<&'this mut BorrowedBuf<'data>, &'this mut BorrowedBuf<'this>>(self) - }, - } - } - - /// Clears the buffer, resetting the filled region to empty. - /// - /// The number of initialized bytes is not changed, and the contents of the buffer are not modified. - #[inline] - pub fn clear(&mut self) -> &mut Self { - self.filled = 0; - self - } - - /// Asserts that the first `n` bytes of the buffer are initialized. - /// - /// `BorrowedBuf` assumes that bytes are never de-initialized, so this method does nothing when called with fewer - /// bytes than are already known to be initialized. - /// - /// # Safety - /// - /// The caller must ensure that the first `n` unfilled bytes of the buffer have already been initialized. - #[inline] - pub unsafe fn set_init(&mut self, n: usize) -> &mut Self { - self.init = cmp::max(self.init, n); - self - } -} - -/// A writeable view of the unfilled portion of a [`BorrowedBuf`](BorrowedBuf). -/// -/// Provides access to the initialized and uninitialized parts of the underlying `BorrowedBuf`. -/// Data can be written directly to the cursor by using [`append`](BorrowedCursor::append) or -/// indirectly by getting a slice of part or all of the cursor and writing into the slice. In the -/// indirect case, the caller must call [`advance`](BorrowedCursor::advance) after writing to inform -/// the cursor how many bytes have been written. -/// -/// Once data is written to the cursor, it becomes part of the filled portion of the underlying -/// `BorrowedBuf` and can no longer be accessed or re-written by the cursor. I.e., the cursor tracks -/// the unfilled part of the underlying `BorrowedBuf`. -/// -/// The lifetime `'a` is a bound on the lifetime of the underlying buffer (which means it is a bound -/// on the data in that buffer by transitivity). -#[derive(Debug)] -pub struct BorrowedCursor<'a> { - /// The underlying buffer. - // Safety invariant: we treat the type of buf as covariant in the lifetime of `BorrowedBuf` when - // we create a `BorrowedCursor`. This is only safe if we never replace `buf` by assigning into - // it, so don't do that! - buf: &'a mut BorrowedBuf<'a>, - /// The length of the filled portion of the underlying buffer at the time of the cursor's - /// creation. - start: usize, -} - -impl<'a> BorrowedCursor<'a> { - /// Reborrow this cursor by cloning it with a smaller lifetime. - /// - /// Since a cursor maintains unique access to its underlying buffer, the borrowed cursor is - /// not accessible while the new cursor exists. - #[inline] - pub fn reborrow<'this>(&'this mut self) -> BorrowedCursor<'this> { - BorrowedCursor { - // SAFETY: we never assign into `BorrowedCursor::buf`, so treating its - // lifetime covariantly is safe. - buf: unsafe { - mem::transmute::<&'this mut BorrowedBuf<'a>, &'this mut BorrowedBuf<'this>>( - self.buf, - ) - }, - start: self.start, - } - } - - /// Returns the available space in the cursor. - #[inline] - pub fn capacity(&self) -> usize { - self.buf.capacity() - self.buf.filled - } - - /// Returns the number of bytes written to this cursor since it was created from a `BorrowedBuf`. - /// - /// Note that if this cursor is a reborrowed clone of another, then the count returned is the - /// count written via either cursor, not the count since the cursor was reborrowed. - #[inline] - pub fn written(&self) -> usize { - self.buf.filled - self.start - } - - /// Returns a shared reference to the initialized portion of the cursor. - #[inline] - pub fn init_ref(&self) -> &[u8] { - // SAFETY: We only slice the initialized part of the buffer, which is always valid - unsafe { MaybeUninit::slice_assume_init_ref(&self.buf.buf[self.buf.filled..self.buf.init]) } - } - - /// Returns a mutable reference to the initialized portion of the cursor. - #[inline] - pub fn init_mut(&mut self) -> &mut [u8] { - // SAFETY: We only slice the initialized part of the buffer, which is always valid - unsafe { - MaybeUninit::slice_assume_init_mut(&mut self.buf.buf[self.buf.filled..self.buf.init]) - } - } - - /// Returns a mutable reference to the uninitialized part of the cursor. - /// - /// It is safe to uninitialize any of these bytes. - #[inline] - pub fn uninit_mut(&mut self) -> &mut [MaybeUninit] { - &mut self.buf.buf[self.buf.init..] - } - - /// Returns a mutable reference to the whole cursor. - /// - /// # Safety - /// - /// The caller must not uninitialize any bytes in the initialized portion of the cursor. - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut [MaybeUninit] { - &mut self.buf.buf[self.buf.filled..] - } - - /// Advance the cursor by asserting that `n` bytes have been filled. - /// - /// After advancing, the `n` bytes are no longer accessible via the cursor and can only be - /// accessed via the underlying buffer. I.e., the buffer's filled portion grows by `n` elements - /// and its unfilled portion (and the capacity of this cursor) shrinks by `n` elements. - /// - /// # Safety - /// - /// The caller must ensure that the first `n` bytes of the cursor have been properly - /// initialised. - #[inline] - pub unsafe fn advance(&mut self, n: usize) -> &mut Self { - self.buf.filled += n; - self.buf.init = cmp::max(self.buf.init, self.buf.filled); - self - } - - /// Initializes all bytes in the cursor. - #[inline] - pub fn ensure_init(&mut self) -> &mut Self { - let uninit = self.uninit_mut(); - // SAFETY: 0 is a valid value for MaybeUninit and the length matches the allocation - // since it is comes from a slice reference. - unsafe { - ptr::write_bytes(uninit.as_mut_ptr(), 0, uninit.len()); - } - self.buf.init = self.buf.capacity(); - - self - } - - /// Asserts that the first `n` unfilled bytes of the cursor are initialized. - /// - /// `BorrowedBuf` assumes that bytes are never de-initialized, so this method does nothing when - /// called with fewer bytes than are already known to be initialized. - /// - /// # Safety - /// - /// The caller must ensure that the first `n` bytes of the buffer have already been initialized. - #[inline] - pub unsafe fn set_init(&mut self, n: usize) -> &mut Self { - self.buf.init = cmp::max(self.buf.init, self.buf.filled + n); - self - } - - /// Appends data to the cursor, advancing position within its buffer. - /// - /// # Panics - /// - /// Panics if `self.capacity()` is less than `buf.len()`. - #[inline] - pub fn append(&mut self, buf: &[u8]) { - assert!(self.capacity() >= buf.len()); - - // SAFETY: we do not de-initialize any of the elements of the slice - unsafe { - MaybeUninit::write_slice(&mut self.as_mut()[..buf.len()], buf); - } - - // SAFETY: We just added the entire contents of buf to the filled section. - unsafe { - self.set_init(buf.len()); - } - self.buf.filled += buf.len(); - } -} - -impl<'a> Write for BorrowedCursor<'a> { - fn write(&mut self, buf: &[u8]) -> Result { - self.append(buf); - Ok(buf.len()) - } - - fn flush(&mut self) -> Result<()> { - Ok(()) - } -} diff --git a/sgx_tstd/src/io/readbuf/tests.rs b/sgx_tstd/src/io/readbuf/tests.rs deleted file mode 100644 index 875365d58..000000000 --- a/sgx_tstd/src/io/readbuf/tests.rs +++ /dev/null @@ -1,194 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 super::BorrowedBuf; -use crate::mem::MaybeUninit; - -use sgx_test_utils::test_case; - -/// Test that BorrowedBuf has the correct numbers when created with new -#[test_case] -fn new() { - let buf: &mut [_] = &mut [0; 16]; - let mut rbuf: BorrowedBuf<'_> = buf.into(); - - assert_eq!(rbuf.filled().len(), 0); - assert_eq!(rbuf.init_len(), 16); - assert_eq!(rbuf.capacity(), 16); - assert_eq!(rbuf.unfilled().capacity(), 16); -} - -/// Test that BorrowedBuf has the correct numbers when created with uninit -#[test_case] -fn uninit() { - let buf: &mut [_] = &mut [MaybeUninit::uninit(); 16]; - let mut rbuf: BorrowedBuf<'_> = buf.into(); - - assert_eq!(rbuf.filled().len(), 0); - assert_eq!(rbuf.init_len(), 0); - assert_eq!(rbuf.capacity(), 16); - assert_eq!(rbuf.unfilled().capacity(), 16); -} - -#[test_case] -fn initialize_unfilled() { - let buf: &mut [_] = &mut [MaybeUninit::uninit(); 16]; - let mut rbuf: BorrowedBuf<'_> = buf.into(); - - rbuf.unfilled().ensure_init(); - - assert_eq!(rbuf.init_len(), 16); -} - -#[test_case] -fn addvance_filled() { - let buf: &mut [_] = &mut [0; 16]; - let mut rbuf: BorrowedBuf<'_> = buf.into(); - - unsafe { - rbuf.unfilled().advance(1); - } - - assert_eq!(rbuf.filled().len(), 1); - assert_eq!(rbuf.unfilled().capacity(), 15); -} - -#[test_case] -fn clear() { - let buf: &mut [_] = &mut [255; 16]; - let mut rbuf: BorrowedBuf<'_> = buf.into(); - - unsafe { - rbuf.unfilled().advance(16); - } - - assert_eq!(rbuf.filled().len(), 16); - assert_eq!(rbuf.unfilled().capacity(), 0); - - rbuf.clear(); - - assert_eq!(rbuf.filled().len(), 0); - assert_eq!(rbuf.unfilled().capacity(), 16); - - assert_eq!(rbuf.unfilled().init_ref(), [255; 16]); -} - -#[test_case] -fn set_init() { - let buf: &mut [_] = &mut [MaybeUninit::uninit(); 16]; - let mut rbuf: BorrowedBuf<'_> = buf.into(); - - unsafe { - rbuf.set_init(8); - } - - assert_eq!(rbuf.init_len(), 8); - - unsafe { - rbuf.unfilled().advance(4); - } - - unsafe { - rbuf.set_init(2); - } - - assert_eq!(rbuf.init_len(), 8); - - unsafe { - rbuf.set_init(8); - } - - assert_eq!(rbuf.init_len(), 8); -} - -#[test_case] -fn append() { - let buf: &mut [_] = &mut [MaybeUninit::new(255); 16]; - let mut rbuf: BorrowedBuf<'_> = buf.into(); - - rbuf.unfilled().append(&[0; 8]); - - assert_eq!(rbuf.init_len(), 8); - assert_eq!(rbuf.filled().len(), 8); - assert_eq!(rbuf.filled(), [0; 8]); - - rbuf.clear(); - - rbuf.unfilled().append(&[1; 16]); - - assert_eq!(rbuf.init_len(), 16); - assert_eq!(rbuf.filled().len(), 16); - assert_eq!(rbuf.filled(), [1; 16]); -} - -#[test_case] -fn reborrow_written() { - let buf: &mut [_] = &mut [MaybeUninit::new(0); 32]; - let mut buf: BorrowedBuf<'_> = buf.into(); - - let mut cursor = buf.unfilled(); - cursor.append(&[1; 16]); - - let mut cursor2 = cursor.reborrow(); - cursor2.append(&[2; 16]); - - assert_eq!(cursor2.written(), 32); - assert_eq!(cursor.written(), 32); - - assert_eq!(buf.unfilled().written(), 0); - assert_eq!(buf.init_len(), 32); - assert_eq!(buf.filled().len(), 32); - let filled = buf.filled(); - assert_eq!(&filled[..16], [1; 16]); - assert_eq!(&filled[16..], [2; 16]); -} - -#[test_case] -fn cursor_set_init() { - let buf: &mut [_] = &mut [MaybeUninit::uninit(); 16]; - let mut rbuf: BorrowedBuf<'_> = buf.into(); - - unsafe { - rbuf.unfilled().set_init(8); - } - - assert_eq!(rbuf.init_len(), 8); - assert_eq!(rbuf.unfilled().init_ref().len(), 8); - assert_eq!(rbuf.unfilled().init_mut().len(), 8); - assert_eq!(rbuf.unfilled().uninit_mut().len(), 8); - assert_eq!(unsafe { rbuf.unfilled().as_mut() }.len(), 16); - - unsafe { - rbuf.unfilled().advance(4); - } - - unsafe { - rbuf.unfilled().set_init(2); - } - - assert_eq!(rbuf.init_len(), 8); - - unsafe { - rbuf.unfilled().set_init(8); - } - - assert_eq!(rbuf.init_len(), 12); - assert_eq!(rbuf.unfilled().init_ref().len(), 8); - assert_eq!(rbuf.unfilled().init_mut().len(), 8); - assert_eq!(rbuf.unfilled().uninit_mut().len(), 4); - assert_eq!(unsafe { rbuf.unfilled().as_mut() }.len(), 12); -} diff --git a/sgx_tstd/src/io/stdio.rs b/sgx_tstd/src/io/stdio.rs index 0d42d63fc..b629fba40 100644 --- a/sgx_tstd/src/io/stdio.rs +++ b/sgx_tstd/src/io/stdio.rs @@ -23,11 +23,10 @@ use crate::io::prelude::*; use crate::cell::{Cell, RefCell}; use crate::fmt; use crate::fs::File; -use crate::io::{self, BufReader, IoSlice, IoSliceMut, LineWriter, Lines}; +use crate::io::{self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines}; use crate::sync::atomic::{AtomicBool, Ordering}; -use crate::sync::{Arc, Mutex, MutexGuard, OnceLock}; +use crate::sync::{Arc, Mutex, MutexGuard, OnceLock, ReentrantMutex, ReentrantMutexGuard}; use crate::sys::stdio; -use crate::sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard}; type LocalStream = Arc>>; @@ -110,6 +109,10 @@ impl Read for StdinRaw { handle_ebadf(self.0.read(buf), 0) } + fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + handle_ebadf(self.0.read_buf(buf), ()) + } + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { handle_ebadf(self.0.read_vectored(bufs), 0) } @@ -423,6 +426,9 @@ impl Read for Stdin { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.lock().read(buf) } + fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + self.lock().read_buf(buf) + } fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.lock().read_vectored(bufs) } @@ -453,6 +459,10 @@ impl Read for StdinLock<'_> { self.inner.read(buf) } + fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + self.inner.read_buf(buf) + } + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.inner.read_vectored(bufs) } @@ -1018,11 +1028,30 @@ pub(crate) fn attempt_print_to_stderr(args: fmt::Arguments<'_>) { let _ = stderr().write_fmt(args); } +/// Trait to determine if a descriptor/handle refers to a terminal/tty. +pub trait IsTerminal: crate::sealed::Sealed { + /// Returns `true` if the descriptor/handle refers to a terminal/tty. + /// + /// On platforms where Rust does not know how to detect a terminal yet, this will return + /// `false`. This will also return `false` if an unexpected error occurred, such as from + /// passing an invalid file descriptor. + /// + /// # Platform-specific behavior + /// + /// On Windows, in addition to detecting consoles, this currently uses some heuristics to + /// detect older msys/cygwin/mingw pseudo-terminals based on device name: devices with names + /// starting with `msys-` or `cygwin-` and ending in `-pty` will be considered terminals. + /// Note that this [may change in the future][changes]. + /// + /// [changes]: io#platform-specific-behavior + fn is_terminal(&self) -> bool; +} + macro_rules! impl_is_terminal { ($($t:ty),*$(,)?) => {$( impl crate::sealed::Sealed for $t {} - impl crate::io::IsTerminal for $t { + impl IsTerminal for $t { #[inline] fn is_terminal(&self) -> bool { crate::sys::io::is_terminal(self) diff --git a/sgx_tstd/src/io/stdio/tests.rs b/sgx_tstd/src/io/stdio/tests.rs index 85c89a562..9b4a6201b 100644 --- a/sgx_tstd/src/io/stdio/tests.rs +++ b/sgx_tstd/src/io/stdio/tests.rs @@ -17,7 +17,6 @@ use super::*; use crate::panic::{RefUnwindSafe, UnwindSafe}; -use crate::sync::Arc; use crate::sync::mpsc::sync_channel; use crate::thread; diff --git a/sgx_tstd/src/io/tests.rs b/sgx_tstd/src/io/tests.rs index 53c534284..5b16a547d 100644 --- a/sgx_tstd/src/io/tests.rs +++ b/sgx_tstd/src/io/tests.rs @@ -331,7 +331,7 @@ fn bench_read_to_end(b: &mut Bencher) { b.iter(|| { let mut lr = repeat(1).take(1000000); let mut vec = Vec::with_capacity(1024); - super::default_read_to_end(&mut lr, &mut vec) + super::default_read_to_end(&mut lr, &mut vec, None) }); } @@ -604,7 +604,7 @@ fn test_take_wrong_length() { } } - let mut buffer = vec![0; 4]; + let mut buffer = [0; 4]; let mut reader = LieAboutSize(true).take(4); // Primed the `Limit` by lying about the read size. should_panic!(reader.read(&mut buffer[..])); diff --git a/sgx_tstd/src/io/util.rs b/sgx_tstd/src/io/util.rs index 88dc06ad9..4e1b335f5 100644 --- a/sgx_tstd/src/io/util.rs +++ b/sgx_tstd/src/io/util.rs @@ -25,23 +25,40 @@ use crate::io::{ self, BorrowedCursor, BufRead, IoSlice, IoSliceMut, Read, Seek, SeekFrom, SizeHint, Write, }; -/// A reader which is always at EOF. +/// `Empty` ignores any data written via [`Write`], and will always be empty +/// (returning zero bytes) when read via [`Read`]. /// -/// This struct is generally created by calling [`empty()`]. Please see -/// the documentation of [`empty()`] for more details. +/// This struct is generally created by calling [`empty()`]. Please +/// see the documentation of [`empty()`] for more details. #[non_exhaustive] -#[derive(Copy, Clone, Default)] +#[derive(Copy, Clone, Debug, Default)] pub struct Empty; -/// Constructs a new handle to an empty reader. +/// Creates a value that is always at EOF for reads, and ignores all data written. /// -/// All reads from the returned reader will return [Ok]\(0). +/// All calls to [`write`] on the returned instance will return [`Ok(buf.len())`] +/// and the contents of the buffer will not be inspected. +/// +/// All calls to [`read`] from the returned reader will return [`Ok(0)`]. +/// +/// [`Ok(buf.len())`]: Ok +/// [`Ok(0)`]: Ok +/// +/// [`write`]: Write::write +/// [`read`]: Read::read /// /// # Examples /// -/// A slightly sad example of not reading anything into a buffer: +/// ```rust +/// use std::io::{self, Write}; /// +/// let buffer = vec![1, 2, 3, 5, 8]; +/// let num_bytes = io::empty().write(&buffer).unwrap(); +/// assert_eq!(num_bytes, 5); /// ``` +/// +/// +/// ```rust /// use std::io::{self, Read}; /// /// let mut buffer = String::new(); @@ -88,12 +105,6 @@ impl Seek for Empty { } } -impl fmt::Debug for Empty { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Empty").finish_non_exhaustive() - } -} - impl SizeHint for Empty { #[inline] fn upper_bound(&self) -> Option { @@ -101,6 +112,52 @@ impl SizeHint for Empty { } } +impl Write for Empty { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + Ok(buf.len()) + } + + #[inline] + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); + Ok(total_len) + } + + #[inline] + fn is_write_vectored(&self) -> bool { + true + } + + #[inline] + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} + +impl Write for &Empty { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + Ok(buf.len()) + } + + #[inline] + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); + Ok(total_len) + } + + #[inline] + fn is_write_vectored(&self) -> bool { + true + } + + #[inline] + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} + /// A reader which yields one byte over and over and over and over and over and... /// /// This struct is generally created by calling [`repeat()`]. Please @@ -188,18 +245,19 @@ impl fmt::Debug for Repeat { /// A writer which will move data into the void. /// -/// This struct is generally created by calling [`sink`]. Please +/// This struct is generally created by calling [`sink()`]. Please /// see the documentation of [`sink()`] for more details. #[non_exhaustive] -#[derive(Copy, Clone, Default)] +#[derive(Copy, Clone, Debug, Default)] pub struct Sink; /// Creates an instance of a writer which will successfully consume all data. /// -/// All calls to [`write`] on the returned instance will return `Ok(buf.len())` +/// All calls to [`write`] on the returned instance will return [`Ok(buf.len())`] /// and the contents of the buffer will not be inspected. /// /// [`write`]: Write::write +/// [`Ok(buf.len())`]: Ok /// /// # Examples /// @@ -260,9 +318,3 @@ impl Write for &Sink { Ok(()) } } - -impl fmt::Debug for Sink { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Sink").finish_non_exhaustive() - } -} \ No newline at end of file diff --git a/sgx_tstd/src/io/util/tests.rs b/sgx_tstd/src/io/util/tests.rs index ad6006726..c0b42f9d7 100644 --- a/sgx_tstd/src/io/util/tests.rs +++ b/sgx_tstd/src/io/util/tests.rs @@ -15,72 +15,13 @@ // specific language governing permissions and limitations // under the License.. -use crate::cmp::{max, min}; use crate::io::prelude::*; -use crate::io::{ - copy, empty, repeat, sink, BorrowedBuf, BufWriter, Empty, Repeat, Result, SeekFrom, Sink, - DEFAULT_BUF_SIZE, -}; +use crate::io::{empty, repeat, sink, BorrowedBuf, Empty, Repeat, SeekFrom, Sink}; use crate::mem::MaybeUninit; use sgx_test_utils::test_case; -#[test_case] -fn copy_copies() { - let mut r = repeat(0).take(4); - let mut w = sink(); - assert_eq!(copy(&mut r, &mut w).unwrap(), 4); - - let mut r = repeat(0).take(1 << 17); - assert_eq!(copy(&mut r as &mut dyn Read, &mut w as &mut dyn Write).unwrap(), 1 << 17); -} - -struct ShortReader { - cap: usize, - read_size: usize, - observed_buffer: usize, -} - -impl Read for ShortReader { - fn read(&mut self, buf: &mut [u8]) -> Result { - let bytes = min(self.cap, self.read_size); - self.cap -= bytes; - self.observed_buffer = max(self.observed_buffer, buf.len()); - Ok(bytes) - } -} - -struct WriteObserver { - observed_buffer: usize, -} - -impl Write for WriteObserver { - fn write(&mut self, buf: &[u8]) -> Result { - self.observed_buffer = max(self.observed_buffer, buf.len()); - Ok(buf.len()) - } - - fn flush(&mut self) -> Result<()> { - Ok(()) - } -} - -#[test_case] -fn copy_specializes_bufwriter() { - let cap = 117 * 1024; - let buf_sz = 16 * 1024; - let mut r = ShortReader { cap, observed_buffer: 0, read_size: 1337 }; - let mut w = BufWriter::with_capacity(buf_sz, WriteObserver { observed_buffer: 0 }); - assert_eq!( - copy(&mut r, &mut w).unwrap(), - cap as u64, - "expected the whole capacity to be copied" - ); - assert_eq!(r.observed_buffer, buf_sz, "expected a large buffer to be provided to the reader"); - assert!(w.get_mut().observed_buffer > DEFAULT_BUF_SIZE, "expected coalesced writes"); -} - #[test_case] fn sink_sinks() { let mut s = sink(); @@ -96,7 +37,7 @@ fn empty_reads() { assert_eq!(e.read(&mut []).unwrap(), 0); assert_eq!(e.read(&mut [0]).unwrap(), 0); assert_eq!(e.read(&mut [0; 1024]).unwrap(), 0); - assert_eq!(e.by_ref().read(&mut [0; 1024]).unwrap(), 0); + assert_eq!(Read::by_ref(&mut e).read(&mut [0; 1024]).unwrap(), 0); let buf: &mut [MaybeUninit<_>] = &mut []; let mut buf: BorrowedBuf<'_> = buf.into(); @@ -118,7 +59,7 @@ fn empty_reads() { let buf: &mut [_] = &mut [MaybeUninit::uninit(); 1024]; let mut buf: BorrowedBuf<'_> = buf.into(); - e.by_ref().read_buf(buf.unfilled()).unwrap(); + Read::by_ref(&mut e).read_buf(buf.unfilled()).unwrap(); assert_eq!(buf.len(), 0); assert_eq!(buf.init_len(), 0); } @@ -143,6 +84,15 @@ fn empty_seeks() { assert!(matches!(e.seek(SeekFrom::Current(i64::MAX)), Ok(0))); } +#[test_case] +fn empty_sinks() { + let mut e = empty(); + assert_eq!(e.write(&[]).unwrap(), 0); + assert_eq!(e.write(&[0]).unwrap(), 1); + assert_eq!(e.write(&[0; 1024]).unwrap(), 1024); + assert_eq!(Write::by_ref(&mut e).write(&[0; 1024]).unwrap(), 1024); +} + #[test_case] fn repeat_repeats() { let mut r = repeat(4); diff --git a/sgx_tstd/src/lib.rs b/sgx_tstd/src/lib.rs index 938d446e2..520ff1657 100644 --- a/sgx_tstd/src/lib.rs +++ b/sgx_tstd/src/lib.rs @@ -39,8 +39,9 @@ #![allow(dead_code)] #![allow(deprecated)] #![allow(incomplete_features)] +#![allow(internal_features)] #![allow(unused_assignments)] - + #![allow(unused_features)] #![allow(clippy::assertions_on_constants)] #![allow(clippy::err_expect)] #![allow(clippy::explicit_auto_deref)] @@ -50,6 +51,7 @@ #![allow(clippy::missing_safety_doc)] #![allow(clippy::needless_borrow)] #![allow(clippy::new_without_default)] +#![allow(clippy::non_canonical_partial_ord_impl)] #![allow(clippy::transmute_ptr_to_ptr)] #![allow(clippy::wrong_self_convention)] #![allow(clippy::unused_io_amount)] @@ -60,7 +62,6 @@ #![feature(allocator_internals)] #![feature(allow_internal_unsafe)] #![feature(allow_internal_unstable)] -#![feature(box_syntax)] #![feature(c_unwind)] #![feature(concat_idents)] #![feature(const_mut_refs)] @@ -79,53 +80,60 @@ #![feature(rustc_attrs)] #![feature(thread_local)] #![feature(try_blocks)] +#![feature(type_alias_impl_trait)] #![feature(utf8_chunks)] // // Library features (core): -#![feature(array_error_internals)] -#![feature(char_error_internals)] +// tidy-alphabetical-start #![feature(char_internals)] #![feature(core_intrinsics)] -#![feature(duration_checked_float)] +#![feature(core_io_borrowed_buf)] #![feature(duration_constants)] #![feature(error_generic_member_access)] #![feature(error_in_core)] #![feature(error_iter)] #![feature(exact_size_is_empty)] +#![feature(exclusive_wrapper)] #![feature(extend_one)] #![feature(float_minimum_maximum)] #![feature(hasher_prefixfree_extras)] #![feature(hashmap_internals)] -#![feature(int_error_internals)] +#![feature(ip)] +#![feature(ip_in_core)] #![feature(maybe_uninit_slice)] +#![feature(maybe_uninit_uninit_array)] #![feature(maybe_uninit_write_slice)] #![feature(panic_can_unwind)] #![feature(panic_info_message)] #![feature(panic_internals)] #![feature(prelude_2024)] -#![feature(provide_any)] #![feature(ptr_as_uninit)] #![feature(raw_os_nonzero)] #![feature(slice_internals)] #![feature(std_internals)] #![feature(str_internals)] #![feature(strict_provenance)] -#![feature(maybe_uninit_uninit_array)] -#![feature(const_maybe_uninit_uninit_array)] +#![feature(type_ascription)] +// tidy-alphabetical-end // // Library features (alloc): +// tidy-alphabetical-start #![feature(allocator_api)] -#![feature(exclusive_wrapper)] #![feature(get_mut_unchecked)] #![feature(map_try_insert)] #![feature(new_uninit)] -#![feature(try_reserve_kind)] #![feature(slice_concat_trait)] +#![feature(try_reserve_kind)] +#![feature(vec_into_raw_parts)] +// tidy-alphabetical-end // // Library features (unwind): +// tidy-alphabetical-start #![feature(panic_unwind)] +// tidy-alphabetical-end // // Only for re-exporting: +// tidy-alphabetical-start #![feature(assert_matches)] #![feature(async_iterator)] #![feature(c_variadic)] @@ -137,15 +145,20 @@ #![feature(custom_test_frameworks)] #![feature(edition_panic)] #![feature(format_args_nl)] +#![feature(lazy_cell)] #![feature(log_syntax)] -#![feature(once_cell)] #![feature(test)] #![feature(trace_macros)] +// tidy-alphabetical-end // // Only used in tests/benchmarks: // // Only for const-ness: +// tidy-alphabetical-start +#![feature(const_hash)] +// tidy-alphabetical-end // + #![default_lib_allocator] // Explicitly import the prelude. The compiler uses this same unstable attribute @@ -211,7 +224,6 @@ pub use core::cmp; pub use core::convert; pub use core::default; pub use core::future; -pub use core::hash; pub use core::hint; pub use core::i128; pub use core::i16; @@ -249,6 +261,7 @@ pub mod error; pub mod ffi; #[cfg(feature = "untrusted_fs")] pub mod fs; +pub mod hash; pub mod io; pub mod net; pub mod num; @@ -294,19 +307,18 @@ pub mod alloc; // Private support modules mod panicking; -mod personality; #[cfg(not(feature = "untrusted_fs"))] mod fs; -// Re-export macros defined in libcore. +// Re-export macros defined in core. #[allow(deprecated, deprecated_in_future)] pub use core::{ assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, todo, r#try, unimplemented, unreachable, write, writeln, }; -// Re-export built-in macros defined through libcore. +// Re-export built-in macros defined through core. #[allow(deprecated)] pub use core::{ assert, assert_matches, cfg, column, compile_error, concat, concat_idents, const_format_args, diff --git a/sgx_tstd/src/macros.rs b/sgx_tstd/src/macros.rs index 90760abad..49a6b9561 100644 --- a/sgx_tstd/src/macros.rs +++ b/sgx_tstd/src/macros.rs @@ -55,6 +55,9 @@ macro_rules! panic { /// Use `print!` only for the primary output of your program. Use /// [`eprint!`] instead to print error and progress messages. /// +/// See [the formatting documentation in `std::fmt`](../std/fmt/index.html) +/// for details of the macro argument syntax. +/// /// [flush]: crate::io::Write::flush /// [`println!`]: crate::println /// [`eprint!`]: crate::eprint @@ -117,6 +120,9 @@ macro_rules! print { /// Use `println!` only for the primary output of your program. Use /// [`eprintln!`] instead to print error and progress messages. /// +/// See [the formatting documentation in `std::fmt`](../std/fmt/index.html) +/// for details of the macro argument syntax. +/// /// [`std::fmt`]: crate::fmt /// [`eprintln!`]: crate::eprintln /// [lock]: crate::io::Stdout @@ -174,11 +180,14 @@ macro_rules! println { ($($arg:tt)*) => ({}) } /// [`io::stderr`]: crate::io::stderr /// [`io::stdout`]: crate::io::stdout /// +/// See [the formatting documentation in `std::fmt`](../std/fmt/index.html) +/// for details of the macro argument syntax. +/// /// # Panics /// /// Panics if writing to `io::stderr` fails. /// -/// Writing to non-blocking stdout can cause an error, which will lead +/// Writing to non-blocking stderr can cause an error, which will lead /// this macro to panic. /// /// # Examples @@ -205,6 +214,9 @@ macro_rules! eprint { /// Use `eprintln!` only for error and progress messages. Use `println!` /// instead for the primary output of your program. /// +/// See [the formatting documentation in `std::fmt`](../std/fmt/index.html) +/// for details of the macro argument syntax. +/// /// [`io::stderr`]: crate::io::stderr /// [`io::stdout`]: crate::io::stdout /// [`println!`]: crate::println @@ -213,7 +225,7 @@ macro_rules! eprint { /// /// Panics if writing to `io::stderr` fails. /// -/// Writing to non-blocking stdout can cause an error, which will lead +/// Writing to non-blocking stderr can cause an error, which will lead /// this macro to panic. /// /// # Examples diff --git a/sgx_tstd/src/net/display_buffer.rs b/sgx_tstd/src/net/display_buffer.rs deleted file mode 100644 index 278d63138..000000000 --- a/sgx_tstd/src/net/display_buffer.rs +++ /dev/null @@ -1,57 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 crate::fmt; -use crate::mem::MaybeUninit; -use crate::str; - -/// Used for slow path in `Display` implementations when alignment is required. -pub struct DisplayBuffer { - buf: [MaybeUninit; SIZE], - len: usize, -} - -impl DisplayBuffer { - #[inline] - pub const fn new() -> Self { - Self { buf: MaybeUninit::uninit_array(), len: 0 } - } - - #[inline] - pub fn as_str(&self) -> &str { - // SAFETY: `buf` is only written to by the `fmt::Write::write_str` implementation - // which writes a valid UTF-8 string to `buf` and correctly sets `len`. - unsafe { - let s = MaybeUninit::slice_assume_init_ref(&self.buf[..self.len]); - str::from_utf8_unchecked(s) - } - } -} - -impl fmt::Write for DisplayBuffer { - fn write_str(&mut self, s: &str) -> fmt::Result { - let bytes = s.as_bytes(); - - if let Some(buf) = self.buf.get_mut(self.len..(self.len + bytes.len())) { - MaybeUninit::write_slice(buf, bytes); - self.len += bytes.len(); - Ok(()) - } else { - Err(fmt::Error) - } - } -} diff --git a/sgx_tstd/src/net/ip_addr.rs b/sgx_tstd/src/net/ip_addr.rs index 35d559263..ae8e8e11b 100644 --- a/sgx_tstd/src/net/ip_addr.rs +++ b/sgx_tstd/src/net/ip_addr.rs @@ -19,1976 +19,38 @@ #[cfg(feature = "unit_test")] mod tests; -use crate::cmp::Ordering; -use crate::fmt::{self, Write}; -use crate::mem::transmute; use crate::sys_common::{FromInner, IntoInner}; -use super::display_buffer::DisplayBuffer; - use sgx_oc as c; -/// An IP address, either IPv4 or IPv6. -/// -/// This enum can contain either an [`Ipv4Addr`] or an [`Ipv6Addr`], see their -/// respective documentation for more details. -/// -/// # Examples -/// -/// ``` -/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; -/// -/// let localhost_v4 = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); -/// let localhost_v6 = IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)); -/// -/// assert_eq!("127.0.0.1".parse(), Ok(localhost_v4)); -/// assert_eq!("::1".parse(), Ok(localhost_v6)); -/// -/// assert_eq!(localhost_v4.is_ipv6(), false); -/// assert_eq!(localhost_v4.is_ipv4(), true); -/// ``` -#[cfg_attr(not(test), rustc_diagnostic_item = "IpAddr")] -#[derive(Copy, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)] -pub enum IpAddr { - /// An IPv4 address. - V4(Ipv4Addr), - /// An IPv6 address. - V6(Ipv6Addr), -} - -/// An IPv4 address. -/// -/// IPv4 addresses are defined as 32-bit integers in [IETF RFC 791]. -/// They are usually represented as four octets. -/// -/// See [`IpAddr`] for a type encompassing both IPv4 and IPv6 addresses. -/// -/// [IETF RFC 791]: https://tools.ietf.org/html/rfc791 -/// -/// # Textual representation -/// -/// `Ipv4Addr` provides a [`FromStr`] implementation. The four octets are in decimal -/// notation, divided by `.` (this is called "dot-decimal notation"). -/// Notably, octal numbers (which are indicated with a leading `0`) and hexadecimal numbers (which -/// are indicated with a leading `0x`) are not allowed per [IETF RFC 6943]. -/// -/// [IETF RFC 6943]: https://tools.ietf.org/html/rfc6943#section-3.1.1 -/// [`FromStr`]: crate::str::FromStr -/// -/// # Examples -/// -/// ``` -/// use std::net::Ipv4Addr; -/// -/// let localhost = Ipv4Addr::new(127, 0, 0, 1); -/// assert_eq!("127.0.0.1".parse(), Ok(localhost)); -/// assert_eq!(localhost.is_loopback(), true); -/// assert!("012.004.002.000".parse::().is_err()); // all octets are in octal -/// assert!("0000000.0.0.0".parse::().is_err()); // first octet is a zero in octal -/// assert!("0xcb.0x0.0x71.0x00".parse::().is_err()); // all octets are in hex -/// ``` -#[derive(Copy, Clone, PartialEq, Eq, Hash)] -#[cfg_attr(not(test), rustc_diagnostic_item = "Ipv4Addr")] -pub struct Ipv4Addr { - octets: [u8; 4], -} - -/// An IPv6 address. -/// -/// IPv6 addresses are defined as 128-bit integers in [IETF RFC 4291]. -/// They are usually represented as eight 16-bit segments. -/// -/// [IETF RFC 4291]: https://tools.ietf.org/html/rfc4291 -/// -/// # Embedding IPv4 Addresses -/// -/// See [`IpAddr`] for a type encompassing both IPv4 and IPv6 addresses. -/// -/// To assist in the transition from IPv4 to IPv6 two types of IPv6 addresses that embed an IPv4 address were defined: -/// IPv4-compatible and IPv4-mapped addresses. Of these IPv4-compatible addresses have been officially deprecated. -/// -/// Both types of addresses are not assigned any special meaning by this implementation, -/// other than what the relevant standards prescribe. This means that an address like `::ffff:127.0.0.1`, -/// while representing an IPv4 loopback address, is not itself an IPv6 loopback address; only `::1` is. -/// To handle these so called "IPv4-in-IPv6" addresses, they have to first be converted to their canonical IPv4 address. -/// -/// ### IPv4-Compatible IPv6 Addresses -/// -/// IPv4-compatible IPv6 addresses are defined in [IETF RFC 4291 Section 2.5.5.1], and have been officially deprecated. -/// The RFC describes the format of an "IPv4-Compatible IPv6 address" as follows: -/// -/// ```text -/// | 80 bits | 16 | 32 bits | -/// +--------------------------------------+--------------------------+ -/// |0000..............................0000|0000| IPv4 address | -/// +--------------------------------------+----+---------------------+ -/// ``` -/// So `::a.b.c.d` would be an IPv4-compatible IPv6 address representing the IPv4 address `a.b.c.d`. -/// -/// To convert from an IPv4 address to an IPv4-compatible IPv6 address, use [`Ipv4Addr::to_ipv6_compatible`]. -/// Use [`Ipv6Addr::to_ipv4`] to convert an IPv4-compatible IPv6 address to the canonical IPv4 address. -/// -/// [IETF RFC 4291 Section 2.5.5.1]: https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.1 -/// -/// ### IPv4-Mapped IPv6 Addresses -/// -/// IPv4-mapped IPv6 addresses are defined in [IETF RFC 4291 Section 2.5.5.2]. -/// The RFC describes the format of an "IPv4-Mapped IPv6 address" as follows: -/// -/// ```text -/// | 80 bits | 16 | 32 bits | -/// +--------------------------------------+--------------------------+ -/// |0000..............................0000|FFFF| IPv4 address | -/// +--------------------------------------+----+---------------------+ -/// ``` -/// So `::ffff:a.b.c.d` would be an IPv4-mapped IPv6 address representing the IPv4 address `a.b.c.d`. -/// -/// To convert from an IPv4 address to an IPv4-mapped IPv6 address, use [`Ipv4Addr::to_ipv6_mapped`]. -/// Use [`Ipv6Addr::to_ipv4`] to convert an IPv4-mapped IPv6 address to the canonical IPv4 address. -/// Note that this will also convert the IPv6 loopback address `::1` to `0.0.0.1`. Use -/// [`Ipv6Addr::to_ipv4_mapped`] to avoid this. -/// -/// [IETF RFC 4291 Section 2.5.5.2]: https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.2 -/// -/// # Textual representation -/// -/// `Ipv6Addr` provides a [`FromStr`] implementation. There are many ways to represent -/// an IPv6 address in text, but in general, each segments is written in hexadecimal -/// notation, and segments are separated by `:`. For more information, see -/// [IETF RFC 5952]. -/// -/// [`FromStr`]: crate::str::FromStr -/// [IETF RFC 5952]: https://tools.ietf.org/html/rfc5952 -/// -/// # Examples -/// -/// ``` -/// use std::net::Ipv6Addr; -/// -/// let localhost = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1); -/// assert_eq!("::1".parse(), Ok(localhost)); -/// assert_eq!(localhost.is_loopback(), true); -/// ``` -#[derive(Copy, Clone, PartialEq, Eq, Hash)] -#[cfg_attr(not(test), rustc_diagnostic_item = "Ipv6Addr")] -pub struct Ipv6Addr { - octets: [u8; 16], -} - -/// Scope of an [IPv6 multicast address] as defined in [IETF RFC 7346 section 2]. -/// -/// # Stability Guarantees -/// -/// Not all possible values for a multicast scope have been assigned. -/// Future RFCs may introduce new scopes, which will be added as variants to this enum; -/// because of this the enum is marked as `#[non_exhaustive]`. -/// -/// # Examples -/// ``` -/// #![feature(ip)] -/// -/// use std::net::Ipv6Addr; -/// use std::net::Ipv6MulticastScope::*; -/// -/// // An IPv6 multicast address with global scope (`ff0e::`). -/// let address = Ipv6Addr::new(0xff0e, 0, 0, 0, 0, 0, 0, 0); -/// -/// // Will print "Global scope". -/// match address.multicast_scope() { -/// Some(InterfaceLocal) => println!("Interface-Local scope"), -/// Some(LinkLocal) => println!("Link-Local scope"), -/// Some(RealmLocal) => println!("Realm-Local scope"), -/// Some(AdminLocal) => println!("Admin-Local scope"), -/// Some(SiteLocal) => println!("Site-Local scope"), -/// Some(OrganizationLocal) => println!("Organization-Local scope"), -/// Some(Global) => println!("Global scope"), -/// Some(_) => println!("Unknown scope"), -/// None => println!("Not a multicast address!") -/// } -/// -/// ``` -/// -/// [IPv6 multicast address]: Ipv6Addr -/// [IETF RFC 7346 section 2]: https://tools.ietf.org/html/rfc7346#section-2 -#[derive(Copy, PartialEq, Eq, Clone, Hash, Debug)] -#[non_exhaustive] -pub enum Ipv6MulticastScope { - /// Interface-Local scope. - InterfaceLocal, - /// Link-Local scope. - LinkLocal, - /// Realm-Local scope. - RealmLocal, - /// Admin-Local scope. - AdminLocal, - /// Site-Local scope. - SiteLocal, - /// Organization-Local scope. - OrganizationLocal, - /// Global scope. - Global, -} - -impl IpAddr { - /// Returns [`true`] for the special 'unspecified' address. - /// - /// See the documentation for [`Ipv4Addr::is_unspecified()`] and - /// [`Ipv6Addr::is_unspecified()`] for more details. - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - /// - /// assert_eq!(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)).is_unspecified(), true); - /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)).is_unspecified(), true); - /// ``` - #[must_use] - #[inline] - pub const fn is_unspecified(&self) -> bool { - match self { - IpAddr::V4(ip) => ip.is_unspecified(), - IpAddr::V6(ip) => ip.is_unspecified(), - } - } - - /// Returns [`true`] if this is a loopback address. - /// - /// See the documentation for [`Ipv4Addr::is_loopback()`] and - /// [`Ipv6Addr::is_loopback()`] for more details. - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - /// - /// assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).is_loopback(), true); - /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1)).is_loopback(), true); - /// ``` - #[must_use] - #[inline] - pub const fn is_loopback(&self) -> bool { - match self { - IpAddr::V4(ip) => ip.is_loopback(), - IpAddr::V6(ip) => ip.is_loopback(), - } - } - - /// Returns [`true`] if the address appears to be globally routable. - /// - /// See the documentation for [`Ipv4Addr::is_global()`] and - /// [`Ipv6Addr::is_global()`] for more details. - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// - /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - /// - /// assert_eq!(IpAddr::V4(Ipv4Addr::new(80, 9, 12, 3)).is_global(), true); - /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0x1c9, 0, 0, 0xafc8, 0, 0x1)).is_global(), true); - /// ``` - #[must_use] - #[inline] - pub const fn is_global(&self) -> bool { - match self { - IpAddr::V4(ip) => ip.is_global(), - IpAddr::V6(ip) => ip.is_global(), - } - } - - /// Returns [`true`] if this is a multicast address. - /// - /// See the documentation for [`Ipv4Addr::is_multicast()`] and - /// [`Ipv6Addr::is_multicast()`] for more details. - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - /// - /// assert_eq!(IpAddr::V4(Ipv4Addr::new(224, 254, 0, 0)).is_multicast(), true); - /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0)).is_multicast(), true); - /// ``` - #[must_use] - #[inline] - pub const fn is_multicast(&self) -> bool { - match self { - IpAddr::V4(ip) => ip.is_multicast(), - IpAddr::V6(ip) => ip.is_multicast(), - } - } +pub use core::net::IpAddr; - /// Returns [`true`] if this address is in a range designated for documentation. - /// - /// See the documentation for [`Ipv4Addr::is_documentation()`] and - /// [`Ipv6Addr::is_documentation()`] for more details. - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// - /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - /// - /// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_documentation(), true); - /// assert_eq!( - /// IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_documentation(), - /// true - /// ); - /// ``` - #[must_use] - #[inline] - pub const fn is_documentation(&self) -> bool { - match self { - IpAddr::V4(ip) => ip.is_documentation(), - IpAddr::V6(ip) => ip.is_documentation(), - } - } +pub use core::net::{Ipv4Addr, Ipv6Addr}; - /// Returns [`true`] if this address is in a range designated for benchmarking. - /// - /// See the documentation for [`Ipv4Addr::is_benchmarking()`] and - /// [`Ipv6Addr::is_benchmarking()`] for more details. - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// - /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - /// - /// assert_eq!(IpAddr::V4(Ipv4Addr::new(198, 19, 255, 255)).is_benchmarking(), true); - /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0)).is_benchmarking(), true); - /// ``` - #[must_use] - #[inline] - pub const fn is_benchmarking(&self) -> bool { - match self { - IpAddr::V4(ip) => ip.is_benchmarking(), - IpAddr::V6(ip) => ip.is_benchmarking(), - } - } - - /// Returns [`true`] if this address is an [`IPv4` address], and [`false`] - /// otherwise. - /// - /// [`IPv4` address]: IpAddr::V4 - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - /// - /// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv4(), true); - /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv4(), false); - /// ``` - #[must_use] - #[inline] - pub const fn is_ipv4(&self) -> bool { - matches!(self, IpAddr::V4(_)) - } - - /// Returns [`true`] if this address is an [`IPv6` address], and [`false`] - /// otherwise. - /// - /// [`IPv6` address]: IpAddr::V6 - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - /// - /// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv6(), false); - /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv6(), true); - /// ``` - #[must_use] - #[inline] - pub const fn is_ipv6(&self) -> bool { - matches!(self, IpAddr::V6(_)) - } - - /// Converts this address to an `IpAddr::V4` if it is an IPv4-mapped IPv6 addresses, otherwise it - /// return `self` as-is. - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - /// - /// assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).to_canonical().is_loopback(), true); - /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).is_loopback(), false); - /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).to_canonical().is_loopback(), true); - /// ``` - #[inline] - #[must_use = "this returns the result of the operation, \ - without modifying the original"] - pub const fn to_canonical(&self) -> IpAddr { - match self { - &v4 @ IpAddr::V4(_) => v4, - IpAddr::V6(v6) => v6.to_canonical(), - } - } -} - -impl Ipv4Addr { - /// Creates a new IPv4 address from four eight-bit octets. - /// - /// The result will represent the IP address `a`.`b`.`c`.`d`. - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// let addr = Ipv4Addr::new(127, 0, 0, 1); - /// ``` - #[must_use] - #[inline] - pub const fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr { - Ipv4Addr { octets: [a, b, c, d] } - } - - /// An IPv4 address with the address pointing to localhost: `127.0.0.1` - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// let addr = Ipv4Addr::LOCALHOST; - /// assert_eq!(addr, Ipv4Addr::new(127, 0, 0, 1)); - /// ``` - pub const LOCALHOST: Self = Ipv4Addr::new(127, 0, 0, 1); - - /// An IPv4 address representing an unspecified address: `0.0.0.0` - /// - /// This corresponds to the constant `INADDR_ANY` in other languages. - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// let addr = Ipv4Addr::UNSPECIFIED; - /// assert_eq!(addr, Ipv4Addr::new(0, 0, 0, 0)); - /// ``` - #[doc(alias = "INADDR_ANY")] - pub const UNSPECIFIED: Self = Ipv4Addr::new(0, 0, 0, 0); - - /// An IPv4 address representing the broadcast address: `255.255.255.255` - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// let addr = Ipv4Addr::BROADCAST; - /// assert_eq!(addr, Ipv4Addr::new(255, 255, 255, 255)); - /// ``` - pub const BROADCAST: Self = Ipv4Addr::new(255, 255, 255, 255); - - /// Returns the four eight-bit integers that make up this address. - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// let addr = Ipv4Addr::new(127, 0, 0, 1); - /// assert_eq!(addr.octets(), [127, 0, 0, 1]); - /// ``` - #[must_use] - #[inline] - pub const fn octets(&self) -> [u8; 4] { - self.octets - } - - /// Returns [`true`] for the special 'unspecified' address (`0.0.0.0`). - /// - /// This property is defined in _UNIX Network Programming, Second Edition_, - /// W. Richard Stevens, p. 891; see also [ip7]. - /// - /// [ip7]: https://man7.org/linux/man-pages/man7/ip.7.html - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// assert_eq!(Ipv4Addr::new(0, 0, 0, 0).is_unspecified(), true); - /// assert_eq!(Ipv4Addr::new(45, 22, 13, 197).is_unspecified(), false); - /// ``` - #[must_use] - #[inline] - pub const fn is_unspecified(&self) -> bool { - u32::from_be_bytes(self.octets) == 0 - } - - /// Returns [`true`] if this is a loopback address (`127.0.0.0/8`). - /// - /// This property is defined by [IETF RFC 1122]. - /// - /// [IETF RFC 1122]: https://tools.ietf.org/html/rfc1122 - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// assert_eq!(Ipv4Addr::new(127, 0, 0, 1).is_loopback(), true); - /// assert_eq!(Ipv4Addr::new(45, 22, 13, 197).is_loopback(), false); - /// ``` - #[must_use] - #[inline] - pub const fn is_loopback(&self) -> bool { - self.octets()[0] == 127 - } - - /// Returns [`true`] if this is a private address. - /// - /// The private address ranges are defined in [IETF RFC 1918] and include: - /// - /// - `10.0.0.0/8` - /// - `172.16.0.0/12` - /// - `192.168.0.0/16` - /// - /// [IETF RFC 1918]: https://tools.ietf.org/html/rfc1918 - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// assert_eq!(Ipv4Addr::new(10, 0, 0, 1).is_private(), true); - /// assert_eq!(Ipv4Addr::new(10, 10, 10, 10).is_private(), true); - /// assert_eq!(Ipv4Addr::new(172, 16, 10, 10).is_private(), true); - /// assert_eq!(Ipv4Addr::new(172, 29, 45, 14).is_private(), true); - /// assert_eq!(Ipv4Addr::new(172, 32, 0, 2).is_private(), false); - /// assert_eq!(Ipv4Addr::new(192, 168, 0, 2).is_private(), true); - /// assert_eq!(Ipv4Addr::new(192, 169, 0, 2).is_private(), false); - /// ``` - #[must_use] - #[inline] - pub const fn is_private(&self) -> bool { - match self.octets() { - [10, ..] => true, - [172, b, ..] if b >= 16 && b <= 31 => true, - [192, 168, ..] => true, - _ => false, - } - } - - /// Returns [`true`] if the address is link-local (`169.254.0.0/16`). - /// - /// This property is defined by [IETF RFC 3927]. - /// - /// [IETF RFC 3927]: https://tools.ietf.org/html/rfc3927 - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// assert_eq!(Ipv4Addr::new(169, 254, 0, 0).is_link_local(), true); - /// assert_eq!(Ipv4Addr::new(169, 254, 10, 65).is_link_local(), true); - /// assert_eq!(Ipv4Addr::new(16, 89, 10, 65).is_link_local(), false); - /// ``` - #[must_use] - #[inline] - pub const fn is_link_local(&self) -> bool { - matches!(self.octets(), [169, 254, ..]) - } - - /// Returns [`true`] if the address appears to be globally reachable - /// as specified by the [IANA IPv4 Special-Purpose Address Registry]. - /// Whether or not an address is practically reachable will depend on your network configuration. - /// - /// Most IPv4 addresses are globally reachable; - /// unless they are specifically defined as *not* globally reachable. - /// - /// Non-exhaustive list of notable addresses that are not globally reachable: - /// - /// - The [unspecified address] ([`is_unspecified`](Ipv4Addr::is_unspecified)) - /// - Addresses reserved for private use ([`is_private`](Ipv4Addr::is_private)) - /// - Addresses in the shared address space ([`is_shared`](Ipv4Addr::is_shared)) - /// - Loopback addresses ([`is_loopback`](Ipv4Addr::is_loopback)) - /// - Link-local addresses ([`is_link_local`](Ipv4Addr::is_link_local)) - /// - Addresses reserved for documentation ([`is_documentation`](Ipv4Addr::is_documentation)) - /// - Addresses reserved for benchmarking ([`is_benchmarking`](Ipv4Addr::is_benchmarking)) - /// - Reserved addresses ([`is_reserved`](Ipv4Addr::is_reserved)) - /// - The [broadcast address] ([`is_broadcast`](Ipv4Addr::is_broadcast)) - /// - /// For the complete overview of which addresses are globally reachable, see the table at the [IANA IPv4 Special-Purpose Address Registry]. - /// - /// [IANA IPv4 Special-Purpose Address Registry]: https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml - /// [unspecified address]: Ipv4Addr::UNSPECIFIED - /// [broadcast address]: Ipv4Addr::BROADCAST - - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// - /// use std::net::Ipv4Addr; - /// - /// // Most IPv4 addresses are globally reachable: - /// assert_eq!(Ipv4Addr::new(80, 9, 12, 3).is_global(), true); - /// - /// // However some addresses have been assigned a special meaning - /// // that makes them not globally reachable. Some examples are: - /// - /// // The unspecified address (`0.0.0.0`) - /// assert_eq!(Ipv4Addr::UNSPECIFIED.is_global(), false); - /// - /// // Addresses reserved for private use (`10.0.0.0/8`, `172.16.0.0/12`, 192.168.0.0/16) - /// assert_eq!(Ipv4Addr::new(10, 254, 0, 0).is_global(), false); - /// assert_eq!(Ipv4Addr::new(192, 168, 10, 65).is_global(), false); - /// assert_eq!(Ipv4Addr::new(172, 16, 10, 65).is_global(), false); - /// - /// // Addresses in the shared address space (`100.64.0.0/10`) - /// assert_eq!(Ipv4Addr::new(100, 100, 0, 0).is_global(), false); - /// - /// // The loopback addresses (`127.0.0.0/8`) - /// assert_eq!(Ipv4Addr::LOCALHOST.is_global(), false); - /// - /// // Link-local addresses (`169.254.0.0/16`) - /// assert_eq!(Ipv4Addr::new(169, 254, 45, 1).is_global(), false); - /// - /// // Addresses reserved for documentation (`192.0.2.0/24`, `198.51.100.0/24`, `203.0.113.0/24`) - /// assert_eq!(Ipv4Addr::new(192, 0, 2, 255).is_global(), false); - /// assert_eq!(Ipv4Addr::new(198, 51, 100, 65).is_global(), false); - /// assert_eq!(Ipv4Addr::new(203, 0, 113, 6).is_global(), false); - /// - /// // Addresses reserved for benchmarking (`198.18.0.0/15`) - /// assert_eq!(Ipv4Addr::new(198, 18, 0, 0).is_global(), false); - /// - /// // Reserved addresses (`240.0.0.0/4`) - /// assert_eq!(Ipv4Addr::new(250, 10, 20, 30).is_global(), false); - /// - /// // The broadcast address (`255.255.255.255`) - /// assert_eq!(Ipv4Addr::BROADCAST.is_global(), false); - /// - /// // For a complete overview see the IANA IPv4 Special-Purpose Address Registry. - /// ``` - #[must_use] - #[inline] - pub const fn is_global(&self) -> bool { - !(self.octets()[0] == 0 // "This network" - || self.is_private() - || self.is_shared() - || self.is_loopback() - || self.is_link_local() - // addresses reserved for future protocols (`192.0.0.0/24`) - ||(self.octets()[0] == 192 && self.octets()[1] == 0 && self.octets()[2] == 0) - || self.is_documentation() - || self.is_benchmarking() - || self.is_reserved() - || self.is_broadcast()) - } - - /// Returns [`true`] if this address is part of the Shared Address Space defined in - /// [IETF RFC 6598] (`100.64.0.0/10`). - /// - /// [IETF RFC 6598]: https://tools.ietf.org/html/rfc6598 - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// use std::net::Ipv4Addr; - /// - /// assert_eq!(Ipv4Addr::new(100, 64, 0, 0).is_shared(), true); - /// assert_eq!(Ipv4Addr::new(100, 127, 255, 255).is_shared(), true); - /// assert_eq!(Ipv4Addr::new(100, 128, 0, 0).is_shared(), false); - /// ``` - #[must_use] - #[inline] - pub const fn is_shared(&self) -> bool { - self.octets()[0] == 100 && (self.octets()[1] & 0b1100_0000 == 0b0100_0000) - } - - /// Returns [`true`] if this address part of the `198.18.0.0/15` range, which is reserved for - /// network devices benchmarking. This range is defined in [IETF RFC 2544] as `192.18.0.0` - /// through `198.19.255.255` but [errata 423] corrects it to `198.18.0.0/15`. - /// - /// [IETF RFC 2544]: https://tools.ietf.org/html/rfc2544 - /// [errata 423]: https://www.rfc-editor.org/errata/eid423 - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// use std::net::Ipv4Addr; - /// - /// assert_eq!(Ipv4Addr::new(198, 17, 255, 255).is_benchmarking(), false); - /// assert_eq!(Ipv4Addr::new(198, 18, 0, 0).is_benchmarking(), true); - /// assert_eq!(Ipv4Addr::new(198, 19, 255, 255).is_benchmarking(), true); - /// assert_eq!(Ipv4Addr::new(198, 20, 0, 0).is_benchmarking(), false); - /// ``` - #[must_use] - #[inline] - pub const fn is_benchmarking(&self) -> bool { - self.octets()[0] == 198 && (self.octets()[1] & 0xfe) == 18 - } - - /// Returns [`true`] if this address is reserved by IANA for future use. [IETF RFC 1112] - /// defines the block of reserved addresses as `240.0.0.0/4`. This range normally includes the - /// broadcast address `255.255.255.255`, but this implementation explicitly excludes it, since - /// it is obviously not reserved for future use. - /// - /// [IETF RFC 1112]: https://tools.ietf.org/html/rfc1112 - /// - /// # Warning - /// - /// As IANA assigns new addresses, this method will be - /// updated. This may result in non-reserved addresses being - /// treated as reserved in code that relies on an outdated version - /// of this method. - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// use std::net::Ipv4Addr; - /// - /// assert_eq!(Ipv4Addr::new(240, 0, 0, 0).is_reserved(), true); - /// assert_eq!(Ipv4Addr::new(255, 255, 255, 254).is_reserved(), true); - /// - /// assert_eq!(Ipv4Addr::new(239, 255, 255, 255).is_reserved(), false); - /// // The broadcast address is not considered as reserved for future use by this implementation - /// assert_eq!(Ipv4Addr::new(255, 255, 255, 255).is_reserved(), false); - /// ``` - #[must_use] - #[inline] - pub const fn is_reserved(&self) -> bool { - self.octets()[0] & 240 == 240 && !self.is_broadcast() - } - - /// Returns [`true`] if this is a multicast address (`224.0.0.0/4`). - /// - /// Multicast addresses have a most significant octet between `224` and `239`, - /// and is defined by [IETF RFC 5771]. - /// - /// [IETF RFC 5771]: https://tools.ietf.org/html/rfc5771 - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// assert_eq!(Ipv4Addr::new(224, 254, 0, 0).is_multicast(), true); - /// assert_eq!(Ipv4Addr::new(236, 168, 10, 65).is_multicast(), true); - /// assert_eq!(Ipv4Addr::new(172, 16, 10, 65).is_multicast(), false); - /// ``` - #[must_use] - #[inline] - pub const fn is_multicast(&self) -> bool { - self.octets()[0] >= 224 && self.octets()[0] <= 239 - } - - /// Returns [`true`] if this is a broadcast address (`255.255.255.255`). - /// - /// A broadcast address has all octets set to `255` as defined in [IETF RFC 919]. - /// - /// [IETF RFC 919]: https://tools.ietf.org/html/rfc919 - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// assert_eq!(Ipv4Addr::new(255, 255, 255, 255).is_broadcast(), true); - /// assert_eq!(Ipv4Addr::new(236, 168, 10, 65).is_broadcast(), false); - /// ``` - #[must_use] - #[inline] - pub const fn is_broadcast(&self) -> bool { - u32::from_be_bytes(self.octets()) == u32::from_be_bytes(Self::BROADCAST.octets()) - } - - /// Returns [`true`] if this address is in a range designated for documentation. - /// - /// This is defined in [IETF RFC 5737]: - /// - /// - `192.0.2.0/24` (TEST-NET-1) - /// - `198.51.100.0/24` (TEST-NET-2) - /// - `203.0.113.0/24` (TEST-NET-3) - /// - /// [IETF RFC 5737]: https://tools.ietf.org/html/rfc5737 - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// assert_eq!(Ipv4Addr::new(192, 0, 2, 255).is_documentation(), true); - /// assert_eq!(Ipv4Addr::new(198, 51, 100, 65).is_documentation(), true); - /// assert_eq!(Ipv4Addr::new(203, 0, 113, 6).is_documentation(), true); - /// assert_eq!(Ipv4Addr::new(193, 34, 17, 19).is_documentation(), false); - /// ``` - #[must_use] - #[inline] - pub const fn is_documentation(&self) -> bool { - matches!(self.octets(), [192, 0, 2, _] | [198, 51, 100, _] | [203, 0, 113, _]) - } - - /// Converts this address to an [IPv4-compatible] [`IPv6` address]. - /// - /// `a.b.c.d` becomes `::a.b.c.d` - /// - /// Note that IPv4-compatible addresses have been officially deprecated. - /// If you don't explicitly need an IPv4-compatible address for legacy reasons, consider using `to_ipv6_mapped` instead. - /// - /// [IPv4-compatible]: Ipv6Addr#ipv4-compatible-ipv6-addresses - /// [`IPv6` address]: Ipv6Addr - /// - /// # Examples - /// - /// ``` - /// use std::net::{Ipv4Addr, Ipv6Addr}; - /// - /// assert_eq!( - /// Ipv4Addr::new(192, 0, 2, 255).to_ipv6_compatible(), - /// Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0xc000, 0x2ff) - /// ); - /// ``` - #[must_use = "this returns the result of the operation, \ - without modifying the original"] - #[inline] - pub const fn to_ipv6_compatible(&self) -> Ipv6Addr { - let [a, b, c, d] = self.octets(); - Ipv6Addr { octets: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, a, b, c, d] } - } - - /// Converts this address to an [IPv4-mapped] [`IPv6` address]. - /// - /// `a.b.c.d` becomes `::ffff:a.b.c.d` - /// - /// [IPv4-mapped]: Ipv6Addr#ipv4-mapped-ipv6-addresses - /// [`IPv6` address]: Ipv6Addr - /// - /// # Examples - /// - /// ``` - /// use std::net::{Ipv4Addr, Ipv6Addr}; - /// - /// assert_eq!(Ipv4Addr::new(192, 0, 2, 255).to_ipv6_mapped(), - /// Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x2ff)); - /// ``` - #[must_use = "this returns the result of the operation, \ - without modifying the original"] - #[inline] - pub const fn to_ipv6_mapped(&self) -> Ipv6Addr { - let [a, b, c, d] = self.octets(); - Ipv6Addr { octets: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, a, b, c, d] } - } -} - -impl fmt::Display for IpAddr { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - IpAddr::V4(ip) => ip.fmt(fmt), - IpAddr::V6(ip) => ip.fmt(fmt), - } - } -} - -impl fmt::Debug for IpAddr { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(self, fmt) - } -} - -impl From for IpAddr { - /// Copies this address to a new `IpAddr::V4`. - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr}; - /// - /// let addr = Ipv4Addr::new(127, 0, 0, 1); - /// - /// assert_eq!( - /// IpAddr::V4(addr), - /// IpAddr::from(addr) - /// ) - /// ``` - #[inline] - fn from(ipv4: Ipv4Addr) -> IpAddr { - IpAddr::V4(ipv4) - } -} - -impl From for IpAddr { - /// Copies this address to a new `IpAddr::V6`. - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv6Addr}; - /// - /// let addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff); - /// - /// assert_eq!( - /// IpAddr::V6(addr), - /// IpAddr::from(addr) - /// ); - /// ``` - #[inline] - fn from(ipv6: Ipv6Addr) -> IpAddr { - IpAddr::V6(ipv6) - } -} - -impl fmt::Display for Ipv4Addr { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - let octets = self.octets(); - - // If there are no alignment requirements, write the IP address directly to `f`. - // Otherwise, write it to a local buffer and then use `f.pad`. - if fmt.precision().is_none() && fmt.width().is_none() { - write!(fmt, "{}.{}.{}.{}", octets[0], octets[1], octets[2], octets[3]) - } else { - const LONGEST_IPV4_ADDR: &str = "255.255.255.255"; - - let mut buf = DisplayBuffer::<{ LONGEST_IPV4_ADDR.len() }>::new(); - // Buffer is long enough for the longest possible IPv4 address, so this should never fail. - write!(buf, "{}.{}.{}.{}", octets[0], octets[1], octets[2], octets[3]).unwrap(); - - fmt.pad(buf.as_str()) - } - } -} - -impl fmt::Debug for Ipv4Addr { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(self, fmt) - } -} - -impl PartialEq for IpAddr { - #[inline] - fn eq(&self, other: &Ipv4Addr) -> bool { - match self { - IpAddr::V4(v4) => v4 == other, - IpAddr::V6(_) => false, - } - } -} - -impl PartialEq for Ipv4Addr { - #[inline] - fn eq(&self, other: &IpAddr) -> bool { - match other { - IpAddr::V4(v4) => self == v4, - IpAddr::V6(_) => false, - } - } -} - -impl PartialOrd for Ipv4Addr { - #[inline] - fn partial_cmp(&self, other: &Ipv4Addr) -> Option { - Some(self.cmp(other)) - } -} - -impl PartialOrd for IpAddr { - #[inline] - fn partial_cmp(&self, other: &Ipv4Addr) -> Option { - match self { - IpAddr::V4(v4) => v4.partial_cmp(other), - IpAddr::V6(_) => Some(Ordering::Greater), - } - } -} - -impl PartialOrd for Ipv4Addr { - #[inline] - fn partial_cmp(&self, other: &IpAddr) -> Option { - match other { - IpAddr::V4(v4) => self.partial_cmp(v4), - IpAddr::V6(_) => Some(Ordering::Less), - } - } -} - -impl Ord for Ipv4Addr { - #[inline] - fn cmp(&self, other: &Ipv4Addr) -> Ordering { - self.octets.cmp(&other.octets) - } -} +pub use core::net::Ipv6MulticastScope; impl IntoInner for Ipv4Addr { #[inline] fn into_inner(self) -> c::in_addr { // `s_addr` is stored as BE on all machines and the array is in BE order. // So the native endian conversion method is used so that it's never swapped. - c::in_addr { s_addr: u32::from_ne_bytes(self.octets) } + c::in_addr { s_addr: u32::from_ne_bytes(self.octets()) } } } impl FromInner for Ipv4Addr { fn from_inner(addr: c::in_addr) -> Ipv4Addr { - Ipv4Addr { octets: addr.s_addr.to_ne_bytes() } - } -} - -impl From for u32 { - /// Converts an `Ipv4Addr` into a host byte order `u32`. - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// let addr = Ipv4Addr::new(0x12, 0x34, 0x56, 0x78); - /// assert_eq!(0x12345678, u32::from(addr)); - /// ``` - #[inline] - fn from(ip: Ipv4Addr) -> u32 { - u32::from_be_bytes(ip.octets) - } -} - -impl From for Ipv4Addr { - /// Converts a host byte order `u32` into an `Ipv4Addr`. - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// let addr = Ipv4Addr::from(0x12345678); - /// assert_eq!(Ipv4Addr::new(0x12, 0x34, 0x56, 0x78), addr); - /// ``` - #[inline] - fn from(ip: u32) -> Ipv4Addr { - Ipv4Addr { octets: ip.to_be_bytes() } - } -} - -impl From<[u8; 4]> for Ipv4Addr { - /// Creates an `Ipv4Addr` from a four element byte array. - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv4Addr; - /// - /// let addr = Ipv4Addr::from([13u8, 12u8, 11u8, 10u8]); - /// assert_eq!(Ipv4Addr::new(13, 12, 11, 10), addr); - /// ``` - #[inline] - fn from(octets: [u8; 4]) -> Ipv4Addr { - Ipv4Addr { octets } - } -} - -impl From<[u8; 4]> for IpAddr { - /// Creates an `IpAddr::V4` from a four element byte array. - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr}; - /// - /// let addr = IpAddr::from([13u8, 12u8, 11u8, 10u8]); - /// assert_eq!(IpAddr::V4(Ipv4Addr::new(13, 12, 11, 10)), addr); - /// ``` - #[inline] - fn from(octets: [u8; 4]) -> IpAddr { - IpAddr::V4(Ipv4Addr::from(octets)) - } -} - -impl Ipv6Addr { - /// Creates a new IPv6 address from eight 16-bit segments. - /// - /// The result will represent the IP address `a:b:c:d:e:f:g:h`. - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv6Addr; - /// - /// let addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff); - /// ``` - #[allow(clippy::too_many_arguments)] - #[must_use] - #[inline] - pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr { - let addr16 = [ - a.to_be(), - b.to_be(), - c.to_be(), - d.to_be(), - e.to_be(), - f.to_be(), - g.to_be(), - h.to_be(), - ]; - Ipv6Addr { - // All elements in `addr16` are big endian. - // SAFETY: `[u16; 8]` is always safe to transmute to `[u8; 16]`. - octets: unsafe { transmute::<_, [u8; 16]>(addr16) }, - } - } - - /// An IPv6 address representing localhost: `::1`. - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv6Addr; - /// - /// let addr = Ipv6Addr::LOCALHOST; - /// assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)); - /// ``` - pub const LOCALHOST: Self = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1); - - /// An IPv6 address representing the unspecified address: `::` - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv6Addr; - /// - /// let addr = Ipv6Addr::UNSPECIFIED; - /// assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)); - /// ``` - pub const UNSPECIFIED: Self = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0); - - /// Returns the eight 16-bit segments that make up this address. - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv6Addr; - /// - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).segments(), - /// [0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff]); - /// ``` - #[must_use] - #[inline] - pub const fn segments(&self) -> [u16; 8] { - // All elements in `self.octets` must be big endian. - // SAFETY: `[u8; 16]` is always safe to transmute to `[u16; 8]`. - let [a, b, c, d, e, f, g, h] = unsafe { transmute::<_, [u16; 8]>(self.octets) }; - // We want native endian u16 - [ - u16::from_be(a), - u16::from_be(b), - u16::from_be(c), - u16::from_be(d), - u16::from_be(e), - u16::from_be(f), - u16::from_be(g), - u16::from_be(h), - ] - } - - /// Returns [`true`] for the special 'unspecified' address (`::`). - /// - /// This property is defined in [IETF RFC 4291]. - /// - /// [IETF RFC 4291]: https://tools.ietf.org/html/rfc4291 - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv6Addr; - /// - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unspecified(), false); - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0).is_unspecified(), true); - /// ``` - #[must_use] - #[inline] - pub const fn is_unspecified(&self) -> bool { - u128::from_be_bytes(self.octets()) == u128::from_be_bytes(Ipv6Addr::UNSPECIFIED.octets()) - } - - /// Returns [`true`] if this is the [loopback address] (`::1`), - /// as defined in [IETF RFC 4291 section 2.5.3]. - /// - /// Contrary to IPv4, in IPv6 there is only one loopback address. - /// - /// [loopback address]: Ipv6Addr::LOCALHOST - /// [IETF RFC 4291 section 2.5.3]: https://tools.ietf.org/html/rfc4291#section-2.5.3 - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv6Addr; - /// - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_loopback(), false); - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1).is_loopback(), true); - /// ``` - #[must_use] - #[inline] - pub const fn is_loopback(&self) -> bool { - u128::from_be_bytes(self.octets()) == u128::from_be_bytes(Ipv6Addr::LOCALHOST.octets()) - } - - /// Returns [`true`] if the address appears to be globally reachable - /// as specified by the [IANA IPv6 Special-Purpose Address Registry]. - /// Whether or not an address is practically reachable will depend on your network configuration. - /// - /// Most IPv6 addresses are globally reachable; - /// unless they are specifically defined as *not* globally reachable. - /// - /// Non-exhaustive list of notable addresses that are not globally reachable: - /// - The [unspecified address] ([`is_unspecified`](Ipv6Addr::is_unspecified)) - /// - The [loopback address] ([`is_loopback`](Ipv6Addr::is_loopback)) - /// - IPv4-mapped addresses - /// - Addresses reserved for benchmarking - /// - Addresses reserved for documentation ([`is_documentation`](Ipv6Addr::is_documentation)) - /// - Unique local addresses ([`is_unique_local`](Ipv6Addr::is_unique_local)) - /// - Unicast addresses with link-local scope ([`is_unicast_link_local`](Ipv6Addr::is_unicast_link_local)) - /// - /// For the complete overview of which addresses are globally reachable, see the table at the [IANA IPv6 Special-Purpose Address Registry]. - /// - /// Note that an address having global scope is not the same as being globally reachable, - /// and there is no direct relation between the two concepts: There exist addresses with global scope - /// that are not globally reachable (for example unique local addresses), - /// and addresses that are globally reachable without having global scope - /// (multicast addresses with non-global scope). - /// - /// [IANA IPv6 Special-Purpose Address Registry]: https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml - /// [unspecified address]: Ipv6Addr::UNSPECIFIED - /// [loopback address]: Ipv6Addr::LOCALHOST - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// - /// use std::net::Ipv6Addr; - /// - /// // Most IPv6 addresses are globally reachable: - /// assert_eq!(Ipv6Addr::new(0x26, 0, 0x1c9, 0, 0, 0xafc8, 0x10, 0x1).is_global(), true); - /// - /// // However some addresses have been assigned a special meaning - /// // that makes them not globally reachable. Some examples are: - /// - /// // The unspecified address (`::`) - /// assert_eq!(Ipv6Addr::UNSPECIFIED.is_global(), false); - /// - /// // The loopback address (`::1`) - /// assert_eq!(Ipv6Addr::LOCALHOST.is_global(), false); - /// - /// // IPv4-mapped addresses (`::ffff:0:0/96`) - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_global(), false); - /// - /// // Addresses reserved for benchmarking (`2001:2::/48`) - /// assert_eq!(Ipv6Addr::new(0x2001, 2, 0, 0, 0, 0, 0, 1,).is_global(), false); - /// - /// // Addresses reserved for documentation (`2001:db8::/32`) - /// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1).is_global(), false); - /// - /// // Unique local addresses (`fc00::/7`) - /// assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 1).is_global(), false); - /// - /// // Unicast addresses with link-local scope (`fe80::/10`) - /// assert_eq!(Ipv6Addr::new(0xfe81, 0, 0, 0, 0, 0, 0, 1).is_global(), false); - /// - /// // For a complete overview see the IANA IPv6 Special-Purpose Address Registry. - /// ``` - #[must_use] - #[inline] - pub const fn is_global(&self) -> bool { - !(self.is_unspecified() - || self.is_loopback() - // IPv4-mapped Address (`::ffff:0:0/96`) - || matches!(self.segments(), [0, 0, 0, 0, 0, 0xffff, _, _]) - // IPv4-IPv6 Translat. (`64:ff9b:1::/48`) - || matches!(self.segments(), [0x64, 0xff9b, 1, _, _, _, _, _]) - // Discard-Only Address Block (`100::/64`) - || matches!(self.segments(), [0x100, 0, 0, 0, _, _, _, _]) - // IETF Protocol Assignments (`2001::/23`) - || (matches!(self.segments(), [0x2001, b, _, _, _, _, _, _] if b < 0x200) - && !( - // Port Control Protocol Anycast (`2001:1::1`) - u128::from_be_bytes(self.octets()) == 0x2001_0001_0000_0000_0000_0000_0000_0001 - // Traversal Using Relays around NAT Anycast (`2001:1::2`) - || u128::from_be_bytes(self.octets()) == 0x2001_0001_0000_0000_0000_0000_0000_0002 - // AMT (`2001:3::/32`) - || matches!(self.segments(), [0x2001, 3, _, _, _, _, _, _]) - // AS112-v6 (`2001:4:112::/48`) - || matches!(self.segments(), [0x2001, 4, 0x112, _, _, _, _, _]) - // ORCHIDv2 (`2001:20::/28`) - || matches!(self.segments(), [0x2001, b, _, _, _, _, _, _] if b >= 0x20 && b <= 0x2F) - )) - || self.is_documentation() - || self.is_unique_local() - || self.is_unicast_link_local()) - } - - /// Returns [`true`] if this is a unique local address (`fc00::/7`). - /// - /// This property is defined in [IETF RFC 4193]. - /// - /// [IETF RFC 4193]: https://tools.ietf.org/html/rfc4193 - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// - /// use std::net::Ipv6Addr; - /// - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unique_local(), false); - /// assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 0).is_unique_local(), true); - /// ``` - #[must_use] - #[inline] - pub const fn is_unique_local(&self) -> bool { - (self.segments()[0] & 0xfe00) == 0xfc00 - } - - /// Returns [`true`] if this is a unicast address, as defined by [IETF RFC 4291]. - /// Any address that is not a [multicast address] (`ff00::/8`) is unicast. - /// - /// [IETF RFC 4291]: https://tools.ietf.org/html/rfc4291 - /// [multicast address]: Ipv6Addr::is_multicast - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// - /// use std::net::Ipv6Addr; - /// - /// // The unspecified and loopback addresses are unicast. - /// assert_eq!(Ipv6Addr::UNSPECIFIED.is_unicast(), true); - /// assert_eq!(Ipv6Addr::LOCALHOST.is_unicast(), true); - /// - /// // Any address that is not a multicast address (`ff00::/8`) is unicast. - /// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_unicast(), true); - /// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).is_unicast(), false); - /// ``` - #[must_use] - #[inline] - pub const fn is_unicast(&self) -> bool { - !self.is_multicast() - } - - /// Returns `true` if the address is a unicast address with link-local scope, - /// as defined in [RFC 4291]. - /// - /// A unicast address has link-local scope if it has the prefix `fe80::/10`, as per [RFC 4291 section 2.4]. - /// Note that this encompasses more addresses than those defined in [RFC 4291 section 2.5.6], - /// which describes "Link-Local IPv6 Unicast Addresses" as having the following stricter format: - /// - /// ```text - /// | 10 bits | 54 bits | 64 bits | - /// +----------+-------------------------+----------------------------+ - /// |1111111010| 0 | interface ID | - /// +----------+-------------------------+----------------------------+ - /// ``` - /// So while currently the only addresses with link-local scope an application will encounter are all in `fe80::/64`, - /// this might change in the future with the publication of new standards. More addresses in `fe80::/10` could be allocated, - /// and those addresses will have link-local scope. - /// - /// Also note that while [RFC 4291 section 2.5.3] mentions about the [loopback address] (`::1`) that "it is treated as having Link-Local scope", - /// this does not mean that the loopback address actually has link-local scope and this method will return `false` on it. - /// - /// [RFC 4291]: https://tools.ietf.org/html/rfc4291 - /// [RFC 4291 section 2.4]: https://tools.ietf.org/html/rfc4291#section-2.4 - /// [RFC 4291 section 2.5.3]: https://tools.ietf.org/html/rfc4291#section-2.5.3 - /// [RFC 4291 section 2.5.6]: https://tools.ietf.org/html/rfc4291#section-2.5.6 - /// [loopback address]: Ipv6Addr::LOCALHOST - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// - /// use std::net::Ipv6Addr; - /// - /// // The loopback address (`::1`) does not actually have link-local scope. - /// assert_eq!(Ipv6Addr::LOCALHOST.is_unicast_link_local(), false); - /// - /// // Only addresses in `fe80::/10` have link-local scope. - /// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_unicast_link_local(), false); - /// assert_eq!(Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 0).is_unicast_link_local(), true); - /// - /// // Addresses outside the stricter `fe80::/64` also have link-local scope. - /// assert_eq!(Ipv6Addr::new(0xfe80, 0, 0, 1, 0, 0, 0, 0).is_unicast_link_local(), true); - /// assert_eq!(Ipv6Addr::new(0xfe81, 0, 0, 0, 0, 0, 0, 0).is_unicast_link_local(), true); - /// ``` - #[must_use] - #[inline] - pub const fn is_unicast_link_local(&self) -> bool { - (self.segments()[0] & 0xffc0) == 0xfe80 - } - - /// Returns [`true`] if this is an address reserved for documentation - /// (`2001:db8::/32`). - /// - /// This property is defined in [IETF RFC 3849]. - /// - /// [IETF RFC 3849]: https://tools.ietf.org/html/rfc3849 - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// - /// use std::net::Ipv6Addr; - /// - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_documentation(), false); - /// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_documentation(), true); - /// ``` - #[must_use] - #[inline] - pub const fn is_documentation(&self) -> bool { - (self.segments()[0] == 0x2001) && (self.segments()[1] == 0xdb8) - } - - /// Returns [`true`] if this is an address reserved for benchmarking (`2001:2::/48`). - /// - /// This property is defined in [IETF RFC 5180], where it is mistakenly specified as covering the range `2001:0200::/48`. - /// This is corrected in [IETF RFC Errata 1752] to `2001:0002::/48`. - /// - /// [IETF RFC 5180]: https://tools.ietf.org/html/rfc5180 - /// [IETF RFC Errata 1752]: https://www.rfc-editor.org/errata_search.php?eid=1752 - /// - /// ``` - /// #![feature(ip)] - /// - /// use std::net::Ipv6Addr; - /// - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc613, 0x0).is_benchmarking(), false); - /// assert_eq!(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0).is_benchmarking(), true); - /// ``` - #[must_use] - #[inline] - pub const fn is_benchmarking(&self) -> bool { - (self.segments()[0] == 0x2001) && (self.segments()[1] == 0x2) && (self.segments()[2] == 0) - } - - /// Returns [`true`] if the address is a globally routable unicast address. - /// - /// The following return false: - /// - /// - the loopback address - /// - the link-local addresses - /// - unique local addresses - /// - the unspecified address - /// - the address range reserved for documentation - /// - /// This method returns [`true`] for site-local addresses as per [RFC 4291 section 2.5.7] - /// - /// ```no_rust - /// The special behavior of [the site-local unicast] prefix defined in [RFC3513] must no longer - /// be supported in new implementations (i.e., new implementations must treat this prefix as - /// Global Unicast). - /// ``` - /// - /// [RFC 4291 section 2.5.7]: https://tools.ietf.org/html/rfc4291#section-2.5.7 - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// - /// use std::net::Ipv6Addr; - /// - /// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_unicast_global(), false); - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_global(), true); - /// ``` - #[must_use] - #[inline] - pub const fn is_unicast_global(&self) -> bool { - self.is_unicast() - && !self.is_loopback() - && !self.is_unicast_link_local() - && !self.is_unique_local() - && !self.is_unspecified() - && !self.is_documentation() - && !self.is_benchmarking() - } - - /// Returns the address's multicast scope if the address is multicast. - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// - /// use std::net::{Ipv6Addr, Ipv6MulticastScope}; - /// - /// assert_eq!( - /// Ipv6Addr::new(0xff0e, 0, 0, 0, 0, 0, 0, 0).multicast_scope(), - /// Some(Ipv6MulticastScope::Global) - /// ); - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).multicast_scope(), None); - /// ``` - #[must_use] - #[inline] - pub const fn multicast_scope(&self) -> Option { - if self.is_multicast() { - match self.segments()[0] & 0x000f { - 1 => Some(Ipv6MulticastScope::InterfaceLocal), - 2 => Some(Ipv6MulticastScope::LinkLocal), - 3 => Some(Ipv6MulticastScope::RealmLocal), - 4 => Some(Ipv6MulticastScope::AdminLocal), - 5 => Some(Ipv6MulticastScope::SiteLocal), - 8 => Some(Ipv6MulticastScope::OrganizationLocal), - 14 => Some(Ipv6MulticastScope::Global), - _ => None, - } - } else { - None - } - } - - /// Returns [`true`] if this is a multicast address (`ff00::/8`). - /// - /// This property is defined by [IETF RFC 4291]. - /// - /// [IETF RFC 4291]: https://tools.ietf.org/html/rfc4291 - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv6Addr; - /// - /// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).is_multicast(), true); - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_multicast(), false); - /// ``` - #[must_use] - #[inline] - pub const fn is_multicast(&self) -> bool { - (self.segments()[0] & 0xff00) == 0xff00 - } - - /// Converts this address to an [`IPv4` address] if it's an [IPv4-mapped] address, - /// as defined in [IETF RFC 4291 section 2.5.5.2], otherwise returns [`None`]. - /// - /// `::ffff:a.b.c.d` becomes `a.b.c.d`. - /// All addresses *not* starting with `::ffff` will return `None`. - /// - /// [`IPv4` address]: Ipv4Addr - /// [IPv4-mapped]: Ipv6Addr - /// [IETF RFC 4291 section 2.5.5.2]: https://tools.ietf.org/html/rfc4291#section-2.5.5.2 - /// - /// # Examples - /// - /// ``` - /// use std::net::{Ipv4Addr, Ipv6Addr}; - /// - /// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).to_ipv4_mapped(), None); - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).to_ipv4_mapped(), - /// Some(Ipv4Addr::new(192, 10, 2, 255))); - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4_mapped(), None); - /// ``` - #[must_use = "this returns the result of the operation, \ - without modifying the original"] - #[inline] - pub const fn to_ipv4_mapped(&self) -> Option { - match self.octets() { - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, a, b, c, d] => { - Some(Ipv4Addr::new(a, b, c, d)) - } - _ => None, - } - } - - /// Converts this address to an [`IPv4` address] if it is either - /// an [IPv4-compatible] address as defined in [IETF RFC 4291 section 2.5.5.1], - /// or an [IPv4-mapped] address as defined in [IETF RFC 4291 section 2.5.5.2], - /// otherwise returns [`None`]. - /// - /// Note that this will return an [`IPv4` address] for the IPv6 loopback address `::1`. Use - /// [`Ipv6Addr::to_ipv4_mapped`] to avoid this. - /// - /// `::a.b.c.d` and `::ffff:a.b.c.d` become `a.b.c.d`. `::1` becomes `0.0.0.1`. - /// All addresses *not* starting with either all zeroes or `::ffff` will return `None`. - /// - /// [`IPv4` address]: Ipv4Addr - /// [IPv4-compatible]: Ipv6Addr#ipv4-compatible-ipv6-addresses - /// [IPv4-mapped]: Ipv6Addr#ipv4-mapped-ipv6-addresses - /// [IETF RFC 4291 section 2.5.5.1]: https://tools.ietf.org/html/rfc4291#section-2.5.5.1 - /// [IETF RFC 4291 section 2.5.5.2]: https://tools.ietf.org/html/rfc4291#section-2.5.5.2 - /// - /// # Examples - /// - /// ``` - /// use std::net::{Ipv4Addr, Ipv6Addr}; - /// - /// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).to_ipv4(), None); - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).to_ipv4(), - /// Some(Ipv4Addr::new(192, 10, 2, 255))); - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4(), - /// Some(Ipv4Addr::new(0, 0, 0, 1))); - /// ``` - #[must_use = "this returns the result of the operation, \ - without modifying the original"] - #[inline] - pub const fn to_ipv4(&self) -> Option { - if let [0, 0, 0, 0, 0, 0 | 0xffff, ab, cd] = self.segments() { - let [a, b] = ab.to_be_bytes(); - let [c, d] = cd.to_be_bytes(); - Some(Ipv4Addr::new(a, b, c, d)) - } else { - None - } - } - - /// Converts this address to an `IpAddr::V4` if it is an IPv4-mapped addresses, otherwise it - /// returns self wrapped in an `IpAddr::V6`. - /// - /// # Examples - /// - /// ``` - /// #![feature(ip)] - /// use std::net::Ipv6Addr; - /// - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1).is_loopback(), false); - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1).to_canonical().is_loopback(), true); - /// ``` - #[must_use = "this returns the result of the operation, \ - without modifying the original"] - #[inline] - pub const fn to_canonical(&self) -> IpAddr { - if let Some(mapped) = self.to_ipv4_mapped() { - return IpAddr::V4(mapped); - } - IpAddr::V6(*self) - } - - /// Returns the sixteen eight-bit integers the IPv6 address consists of. - /// - /// ``` - /// use std::net::Ipv6Addr; - /// - /// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).octets(), - /// [255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); - /// ``` - #[must_use] - #[inline] - pub const fn octets(&self) -> [u8; 16] { - self.octets - } -} - -/// Write an Ipv6Addr, conforming to the canonical style described by -/// [RFC 5952](https://tools.ietf.org/html/rfc5952). -impl fmt::Display for Ipv6Addr { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - // If there are no alignment requirements, write the IP address directly to `f`. - // Otherwise, write it to a local buffer and then use `f.pad`. - if f.precision().is_none() && f.width().is_none() { - let segments = self.segments(); - - // Special case for :: and ::1; otherwise they get written with the - // IPv4 formatter - if self.is_unspecified() { - f.write_str("::") - } else if self.is_loopback() { - f.write_str("::1") - } else if let Some(ipv4) = self.to_ipv4() { - match segments[5] { - // IPv4 Compatible address - 0 => write!(f, "::{}", ipv4), - // IPv4 Mapped address - 0xffff => write!(f, "::ffff:{}", ipv4), - _ => unreachable!(), - } - } else { - #[derive(Copy, Clone, Default)] - struct Span { - start: usize, - len: usize, - } - - // Find the inner 0 span - let zeroes = { - let mut longest = Span::default(); - let mut current = Span::default(); - - for (i, &segment) in segments.iter().enumerate() { - if segment == 0 { - if current.len == 0 { - current.start = i; - } - - current.len += 1; - - if current.len > longest.len { - longest = current; - } - } else { - current = Span::default(); - } - } - - longest - }; - - /// Write a colon-separated part of the address - #[inline] - fn fmt_subslice(f: &mut fmt::Formatter<'_>, chunk: &[u16]) -> fmt::Result { - if let Some((first, tail)) = chunk.split_first() { - write!(f, "{:x}", first)?; - for segment in tail { - f.write_char(':')?; - write!(f, "{:x}", segment)?; - } - } - Ok(()) - } - - if zeroes.len > 1 { - fmt_subslice(f, &segments[..zeroes.start])?; - f.write_str("::")?; - fmt_subslice(f, &segments[zeroes.start + zeroes.len..]) - } else { - fmt_subslice(f, &segments) - } - } - } else { - const LONGEST_IPV6_ADDR: &str = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"; - - let mut buf = DisplayBuffer::<{ LONGEST_IPV6_ADDR.len() }>::new(); - // Buffer is long enough for the longest possible IPv6 address, so this should never fail. - write!(buf, "{}", self).unwrap(); - - f.pad(buf.as_str()) - } - } -} - -impl fmt::Debug for Ipv6Addr { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(self, fmt) - } -} - -impl PartialEq for Ipv6Addr { - #[inline] - fn eq(&self, other: &IpAddr) -> bool { - match other { - IpAddr::V4(_) => false, - IpAddr::V6(v6) => self == v6, - } - } -} - -impl PartialEq for IpAddr { - #[inline] - fn eq(&self, other: &Ipv6Addr) -> bool { - match self { - IpAddr::V4(_) => false, - IpAddr::V6(v6) => v6 == other, - } - } -} - -impl PartialOrd for Ipv6Addr { - #[inline] - fn partial_cmp(&self, other: &Ipv6Addr) -> Option { - Some(self.cmp(other)) - } -} - -impl PartialOrd for IpAddr { - #[inline] - fn partial_cmp(&self, other: &Ipv6Addr) -> Option { - match self { - IpAddr::V4(_) => Some(Ordering::Less), - IpAddr::V6(v6) => v6.partial_cmp(other), - } - } -} - -impl PartialOrd for Ipv6Addr { - #[inline] - fn partial_cmp(&self, other: &IpAddr) -> Option { - match other { - IpAddr::V4(_) => Some(Ordering::Greater), - IpAddr::V6(v6) => self.partial_cmp(v6), - } - } -} - -impl Ord for Ipv6Addr { - #[inline] - fn cmp(&self, other: &Ipv6Addr) -> Ordering { - self.segments().cmp(&other.segments()) + Ipv4Addr::from(addr.s_addr.to_ne_bytes()) } } impl IntoInner for Ipv6Addr { fn into_inner(self) -> c::in6_addr { - c::in6_addr { s6_addr: self.octets } + c::in6_addr { s6_addr: self.octets() } } } impl FromInner for Ipv6Addr { #[inline] fn from_inner(addr: c::in6_addr) -> Ipv6Addr { - Ipv6Addr { octets: addr.s6_addr } - } -} - -impl From for u128 { - /// Convert an `Ipv6Addr` into a host byte order `u128`. - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv6Addr; - /// - /// let addr = Ipv6Addr::new( - /// 0x1020, 0x3040, 0x5060, 0x7080, - /// 0x90A0, 0xB0C0, 0xD0E0, 0xF00D, - /// ); - /// assert_eq!(0x102030405060708090A0B0C0D0E0F00D_u128, u128::from(addr)); - /// ``` - #[inline] - fn from(ip: Ipv6Addr) -> u128 { - u128::from_be_bytes(ip.octets) - } -} - -impl From for Ipv6Addr { - /// Convert a host byte order `u128` into an `Ipv6Addr`. - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv6Addr; - /// - /// let addr = Ipv6Addr::from(0x102030405060708090A0B0C0D0E0F00D_u128); - /// assert_eq!( - /// Ipv6Addr::new( - /// 0x1020, 0x3040, 0x5060, 0x7080, - /// 0x90A0, 0xB0C0, 0xD0E0, 0xF00D, - /// ), - /// addr); - /// ``` - #[inline] - fn from(ip: u128) -> Ipv6Addr { - Ipv6Addr::from(ip.to_be_bytes()) - } -} - -impl From<[u8; 16]> for Ipv6Addr { - /// Creates an `Ipv6Addr` from a sixteen element byte array. - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv6Addr; - /// - /// let addr = Ipv6Addr::from([ - /// 25u8, 24u8, 23u8, 22u8, 21u8, 20u8, 19u8, 18u8, - /// 17u8, 16u8, 15u8, 14u8, 13u8, 12u8, 11u8, 10u8, - /// ]); - /// assert_eq!( - /// Ipv6Addr::new( - /// 0x1918, 0x1716, - /// 0x1514, 0x1312, - /// 0x1110, 0x0f0e, - /// 0x0d0c, 0x0b0a - /// ), - /// addr - /// ); - /// ``` - #[inline] - fn from(octets: [u8; 16]) -> Ipv6Addr { - Ipv6Addr { octets } - } -} - -impl From<[u16; 8]> for Ipv6Addr { - /// Creates an `Ipv6Addr` from an eight element 16-bit array. - /// - /// # Examples - /// - /// ``` - /// use std::net::Ipv6Addr; - /// - /// let addr = Ipv6Addr::from([ - /// 525u16, 524u16, 523u16, 522u16, - /// 521u16, 520u16, 519u16, 518u16, - /// ]); - /// assert_eq!( - /// Ipv6Addr::new( - /// 0x20d, 0x20c, - /// 0x20b, 0x20a, - /// 0x209, 0x208, - /// 0x207, 0x206 - /// ), - /// addr - /// ); - /// ``` - #[inline] - fn from(segments: [u16; 8]) -> Ipv6Addr { - let [a, b, c, d, e, f, g, h] = segments; - Ipv6Addr::new(a, b, c, d, e, f, g, h) - } -} - -impl From<[u8; 16]> for IpAddr { - /// Creates an `IpAddr::V6` from a sixteen element byte array. - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv6Addr}; - /// - /// let addr = IpAddr::from([ - /// 25u8, 24u8, 23u8, 22u8, 21u8, 20u8, 19u8, 18u8, - /// 17u8, 16u8, 15u8, 14u8, 13u8, 12u8, 11u8, 10u8, - /// ]); - /// assert_eq!( - /// IpAddr::V6(Ipv6Addr::new( - /// 0x1918, 0x1716, - /// 0x1514, 0x1312, - /// 0x1110, 0x0f0e, - /// 0x0d0c, 0x0b0a - /// )), - /// addr - /// ); - /// ``` - #[inline] - fn from(octets: [u8; 16]) -> IpAddr { - IpAddr::V6(Ipv6Addr::from(octets)) - } -} - -impl From<[u16; 8]> for IpAddr { - /// Creates an `IpAddr::V6` from an eight element 16-bit array. - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv6Addr}; - /// - /// let addr = IpAddr::from([ - /// 525u16, 524u16, 523u16, 522u16, - /// 521u16, 520u16, 519u16, 518u16, - /// ]); - /// assert_eq!( - /// IpAddr::V6(Ipv6Addr::new( - /// 0x20d, 0x20c, - /// 0x20b, 0x20a, - /// 0x209, 0x208, - /// 0x207, 0x206 - /// )), - /// addr - /// ); - /// ``` - #[inline] - fn from(segments: [u16; 8]) -> IpAddr { - IpAddr::V6(Ipv6Addr::from(segments)) + Ipv6Addr::from(addr.s6_addr) } } diff --git a/sgx_tstd/src/net/ip_addr/tests.rs b/sgx_tstd/src/net/ip_addr/tests.rs index 4d754bac2..78b3377d9 100644 --- a/sgx_tstd/src/net/ip_addr/tests.rs +++ b/sgx_tstd/src/net/ip_addr/tests.rs @@ -15,1044 +15,13 @@ // specific language governing permissions and limitations // under the License.. -use crate::net::test::{sa4, sa6, tsa}; -use crate::net::*; -use crate::str::FromStr; +use crate::net::test::{sa4, tsa}; +use crate::net::Ipv4Addr; use sgx_test_utils::test_case; -#[test_case] -fn test_from_str_ipv4() { - assert_eq!(Ok(Ipv4Addr::new(127, 0, 0, 1)), "127.0.0.1".parse()); - assert_eq!(Ok(Ipv4Addr::new(255, 255, 255, 255)), "255.255.255.255".parse()); - assert_eq!(Ok(Ipv4Addr::new(0, 0, 0, 0)), "0.0.0.0".parse()); - - // out of range - let none: Option = "256.0.0.1".parse().ok(); - assert_eq!(None, none); - // too short - let none: Option = "255.0.0".parse().ok(); - assert_eq!(None, none); - // too long - let none: Option = "255.0.0.1.2".parse().ok(); - assert_eq!(None, none); - // no number between dots - let none: Option = "255.0..1".parse().ok(); - assert_eq!(None, none); - // octal - let none: Option = "255.0.0.01".parse().ok(); - assert_eq!(None, none); - // octal zero - let none: Option = "255.0.0.00".parse().ok(); - assert_eq!(None, none); - let none: Option = "255.0.00.0".parse().ok(); - assert_eq!(None, none); -} - -#[test_case] -fn test_from_str_ipv6() { - assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)), "0:0:0:0:0:0:0:0".parse()); - assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), "0:0:0:0:0:0:0:1".parse()); - - assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), "::1".parse()); - assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)), "::".parse()); - - assert_eq!(Ok(Ipv6Addr::new(0x2a02, 0x6b8, 0, 0, 0, 0, 0x11, 0x11)), "2a02:6b8::11:11".parse()); - - // too long group - let none: Option = "::00000".parse().ok(); - assert_eq!(None, none); - // too short - let none: Option = "1:2:3:4:5:6:7".parse().ok(); - assert_eq!(None, none); - // too long - let none: Option = "1:2:3:4:5:6:7:8:9".parse().ok(); - assert_eq!(None, none); - // triple colon - let none: Option = "1:2:::6:7:8".parse().ok(); - assert_eq!(None, none); - // two double colons - let none: Option = "1:2::6::8".parse().ok(); - assert_eq!(None, none); - // `::` indicating zero groups of zeros - let none: Option = "1:2:3:4::5:6:7:8".parse().ok(); - assert_eq!(None, none); -} - -#[test_case] -fn test_from_str_ipv4_in_ipv6() { - assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 49152, 545)), "::192.0.2.33".parse()); - assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0xFFFF, 49152, 545)), "::FFFF:192.0.2.33".parse()); - assert_eq!( - Ok(Ipv6Addr::new(0x64, 0xff9b, 0, 0, 0, 0, 49152, 545)), - "64:ff9b::192.0.2.33".parse() - ); - assert_eq!( - Ok(Ipv6Addr::new(0x2001, 0xdb8, 0x122, 0xc000, 0x2, 0x2100, 49152, 545)), - "2001:db8:122:c000:2:2100:192.0.2.33".parse() - ); - - // colon after v4 - let none: Option = "::127.0.0.1:".parse().ok(); - assert_eq!(None, none); - // not enough groups - let none: Option = "1:2:3:4:5:127.0.0.1".parse().ok(); - assert_eq!(None, none); - // too many groups - let none: Option = "1:2:3:4:5:6:7:127.0.0.1".parse().ok(); - assert_eq!(None, none); -} - -#[test_case] -fn test_from_str_socket_addr() { - assert_eq!(Ok(sa4(Ipv4Addr::new(77, 88, 21, 11), 80)), "77.88.21.11:80".parse()); - assert_eq!(Ok(SocketAddrV4::new(Ipv4Addr::new(77, 88, 21, 11), 80)), "77.88.21.11:80".parse()); - assert_eq!( - Ok(sa6(Ipv6Addr::new(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), 53)), - "[2a02:6b8:0:1::1]:53".parse() - ); - assert_eq!( - Ok(SocketAddrV6::new(Ipv6Addr::new(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), 53, 0, 0)), - "[2a02:6b8:0:1::1]:53".parse() - ); - assert_eq!(Ok(sa6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0x7F00, 1), 22)), "[::127.0.0.1]:22".parse()); - assert_eq!( - Ok(SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0x7F00, 1), 22, 0, 0)), - "[::127.0.0.1]:22".parse() - ); - - // without port - let none: Option = "127.0.0.1".parse().ok(); - assert_eq!(None, none); - // without port - let none: Option = "127.0.0.1:".parse().ok(); - assert_eq!(None, none); - // wrong brackets around v4 - let none: Option = "[127.0.0.1]:22".parse().ok(); - assert_eq!(None, none); - // port out of range - let none: Option = "127.0.0.1:123456".parse().ok(); - assert_eq!(None, none); -} - -#[test_case] -fn ipv4_addr_to_string() { - assert_eq!(Ipv4Addr::new(127, 0, 0, 1).to_string(), "127.0.0.1"); - // Short address - assert_eq!(Ipv4Addr::new(1, 1, 1, 1).to_string(), "1.1.1.1"); - // Long address - assert_eq!(Ipv4Addr::new(127, 127, 127, 127).to_string(), "127.127.127.127"); - - // Test padding - assert_eq!(&format!("{:16}", Ipv4Addr::new(1, 1, 1, 1)), "1.1.1.1 "); - assert_eq!(&format!("{:>16}", Ipv4Addr::new(1, 1, 1, 1)), " 1.1.1.1"); -} - -#[test_case] -fn ipv6_addr_to_string() { - // ipv4-mapped address - let a1 = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x280); - assert_eq!(a1.to_string(), "::ffff:192.0.2.128"); - - // ipv4-compatible address - let a1 = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0xc000, 0x280); - assert_eq!(a1.to_string(), "::192.0.2.128"); - - // v6 address with no zero segments - assert_eq!(Ipv6Addr::new(8, 9, 10, 11, 12, 13, 14, 15).to_string(), "8:9:a:b:c:d:e:f"); - - // longest possible IPv6 length - assert_eq!( - Ipv6Addr::new(0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666, 0x7777, 0x8888).to_string(), - "1111:2222:3333:4444:5555:6666:7777:8888" - ); - // padding - assert_eq!(&format!("{:20}", Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8)), "1:2:3:4:5:6:7:8 "); - assert_eq!(&format!("{:>20}", Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8)), " 1:2:3:4:5:6:7:8"); - - // reduce a single run of zeros - assert_eq!( - "ae::ffff:102:304", - Ipv6Addr::new(0xae, 0, 0, 0, 0, 0xffff, 0x0102, 0x0304).to_string() - ); - - // don't reduce just a single zero segment - assert_eq!("1:2:3:4:5:6:0:8", Ipv6Addr::new(1, 2, 3, 4, 5, 6, 0, 8).to_string()); - - // 'any' address - assert_eq!("::", Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0).to_string()); - - // loopback address - assert_eq!("::1", Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_string()); - - // ends in zeros - assert_eq!("1::", Ipv6Addr::new(1, 0, 0, 0, 0, 0, 0, 0).to_string()); - - // two runs of zeros, second one is longer - assert_eq!("1:0:0:4::8", Ipv6Addr::new(1, 0, 0, 4, 0, 0, 0, 8).to_string()); - - // two runs of zeros, equal length - assert_eq!("1::4:5:0:0:8", Ipv6Addr::new(1, 0, 0, 4, 5, 0, 0, 8).to_string()); - - // don't prefix `0x` to each segment in `dbg!`. - assert_eq!("1::4:5:0:0:8", &format!("{:#?}", Ipv6Addr::new(1, 0, 0, 4, 5, 0, 0, 8))); -} - -#[test_case] -fn ipv4_to_ipv6() { - assert_eq!( - Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x1234, 0x5678), - Ipv4Addr::new(0x12, 0x34, 0x56, 0x78).to_ipv6_mapped() - ); - assert_eq!( - Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0x1234, 0x5678), - Ipv4Addr::new(0x12, 0x34, 0x56, 0x78).to_ipv6_compatible() - ); -} - -#[test_case] -fn ipv6_to_ipv4_mapped() { - assert_eq!( - Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x1234, 0x5678).to_ipv4_mapped(), - Some(Ipv4Addr::new(0x12, 0x34, 0x56, 0x78)) - ); - assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0x1234, 0x5678).to_ipv4_mapped(), None); -} - -#[test_case] -fn ipv6_to_ipv4() { - assert_eq!( - Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x1234, 0x5678).to_ipv4(), - Some(Ipv4Addr::new(0x12, 0x34, 0x56, 0x78)) - ); - assert_eq!( - Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0x1234, 0x5678).to_ipv4(), - Some(Ipv4Addr::new(0x12, 0x34, 0x56, 0x78)) - ); - assert_eq!(Ipv6Addr::new(0, 0, 1, 0, 0, 0, 0x1234, 0x5678).to_ipv4(), None); -} - -#[test_case] -fn ip_properties() { - macro_rules! ip { - ($s:expr) => { - IpAddr::from_str($s).unwrap() - }; - } - - macro_rules! check { - ($s:expr) => { - check!($s, 0); - }; - - ($s:expr, $mask:expr) => {{ - let unspec: u8 = 1 << 0; - let loopback: u8 = 1 << 1; - let global: u8 = 1 << 2; - let multicast: u8 = 1 << 3; - let doc: u8 = 1 << 4; - let benchmarking: u8 = 1 << 5; - - if ($mask & unspec) == unspec { - assert!(ip!($s).is_unspecified()); - } else { - assert!(!ip!($s).is_unspecified()); - } - - if ($mask & loopback) == loopback { - assert!(ip!($s).is_loopback()); - } else { - assert!(!ip!($s).is_loopback()); - } - - if ($mask & global) == global { - assert!(ip!($s).is_global()); - } else { - assert!(!ip!($s).is_global()); - } - - if ($mask & multicast) == multicast { - assert!(ip!($s).is_multicast()); - } else { - assert!(!ip!($s).is_multicast()); - } - - if ($mask & doc) == doc { - assert!(ip!($s).is_documentation()); - } else { - assert!(!ip!($s).is_documentation()); - } - - if ($mask & benchmarking) == benchmarking { - assert!(ip!($s).is_benchmarking()); - } else { - assert!(!ip!($s).is_benchmarking()); - } - }}; - } - - let unspec: u8 = 1 << 0; - let loopback: u8 = 1 << 1; - let global: u8 = 1 << 2; - let multicast: u8 = 1 << 3; - let doc: u8 = 1 << 4; - let benchmarking: u8 = 1 << 5; - - check!("0.0.0.0", unspec); - check!("0.0.0.1"); - check!("0.1.0.0"); - check!("10.9.8.7"); - check!("127.1.2.3", loopback); - check!("172.31.254.253"); - check!("169.254.253.242"); - check!("192.0.2.183", doc); - check!("192.1.2.183", global); - check!("192.168.254.253"); - check!("198.51.100.0", doc); - check!("203.0.113.0", doc); - check!("203.2.113.0", global); - check!("224.0.0.0", global | multicast); - check!("239.255.255.255", global | multicast); - check!("255.255.255.255"); - // make sure benchmarking addresses are not global - check!("198.18.0.0", benchmarking); - check!("198.18.54.2", benchmarking); - check!("198.19.255.255", benchmarking); - // make sure addresses reserved for protocol assignment are not global - check!("192.0.0.0"); - check!("192.0.0.255"); - check!("192.0.0.100"); - // make sure reserved addresses are not global - check!("240.0.0.0"); - check!("251.54.1.76"); - check!("254.255.255.255"); - // make sure shared addresses are not global - check!("100.64.0.0"); - check!("100.127.255.255"); - check!("100.100.100.0"); - - check!("::", unspec); - check!("::1", loopback); - check!("::0.0.0.2", global); - check!("1::", global); - check!("fc00::"); - check!("fdff:ffff::"); - check!("fe80:ffff::"); - check!("febf:ffff::"); - check!("fec0::", global); - check!("ff01::", global | multicast); - check!("ff02::", global | multicast); - check!("ff03::", global | multicast); - check!("ff04::", global | multicast); - check!("ff05::", global | multicast); - check!("ff08::", global | multicast); - check!("ff0e::", global | multicast); - check!("2001:db8:85a3::8a2e:370:7334", doc); - check!("2001:2::ac32:23ff:21", benchmarking); - check!("102:304:506:708:90a:b0c:d0e:f10", global); -} - -#[test_case] -fn ipv4_properties() { - macro_rules! ip { - ($s:expr) => { - Ipv4Addr::from_str($s).unwrap() - }; - } - - macro_rules! check { - ($s:expr) => { - check!($s, 0); - }; - - ($s:expr, $mask:expr) => {{ - let unspec: u16 = 1 << 0; - let loopback: u16 = 1 << 1; - let private: u16 = 1 << 2; - let link_local: u16 = 1 << 3; - let global: u16 = 1 << 4; - let multicast: u16 = 1 << 5; - let broadcast: u16 = 1 << 6; - let documentation: u16 = 1 << 7; - let benchmarking: u16 = 1 << 8; - let reserved: u16 = 1 << 10; - let shared: u16 = 1 << 11; - - if ($mask & unspec) == unspec { - assert!(ip!($s).is_unspecified()); - } else { - assert!(!ip!($s).is_unspecified()); - } - - if ($mask & loopback) == loopback { - assert!(ip!($s).is_loopback()); - } else { - assert!(!ip!($s).is_loopback()); - } - - if ($mask & private) == private { - assert!(ip!($s).is_private()); - } else { - assert!(!ip!($s).is_private()); - } - - if ($mask & link_local) == link_local { - assert!(ip!($s).is_link_local()); - } else { - assert!(!ip!($s).is_link_local()); - } - - if ($mask & global) == global { - assert!(ip!($s).is_global()); - } else { - assert!(!ip!($s).is_global()); - } - - if ($mask & multicast) == multicast { - assert!(ip!($s).is_multicast()); - } else { - assert!(!ip!($s).is_multicast()); - } - - if ($mask & broadcast) == broadcast { - assert!(ip!($s).is_broadcast()); - } else { - assert!(!ip!($s).is_broadcast()); - } - - if ($mask & documentation) == documentation { - assert!(ip!($s).is_documentation()); - } else { - assert!(!ip!($s).is_documentation()); - } - - if ($mask & benchmarking) == benchmarking { - assert!(ip!($s).is_benchmarking()); - } else { - assert!(!ip!($s).is_benchmarking()); - } - - if ($mask & reserved) == reserved { - assert!(ip!($s).is_reserved()); - } else { - assert!(!ip!($s).is_reserved()); - } - - if ($mask & shared) == shared { - assert!(ip!($s).is_shared()); - } else { - assert!(!ip!($s).is_shared()); - } - }}; - } - - let unspec: u16 = 1 << 0; - let loopback: u16 = 1 << 1; - let private: u16 = 1 << 2; - let link_local: u16 = 1 << 3; - let global: u16 = 1 << 4; - let multicast: u16 = 1 << 5; - let broadcast: u16 = 1 << 6; - let documentation: u16 = 1 << 7; - let benchmarking: u16 = 1 << 8; - let reserved: u16 = 1 << 10; - let shared: u16 = 1 << 11; - - check!("0.0.0.0", unspec); - check!("0.0.0.1"); - check!("0.1.0.0"); - check!("10.9.8.7", private); - check!("127.1.2.3", loopback); - check!("172.31.254.253", private); - check!("169.254.253.242", link_local); - check!("192.0.2.183", documentation); - check!("192.1.2.183", global); - check!("192.168.254.253", private); - check!("198.51.100.0", documentation); - check!("203.0.113.0", documentation); - check!("203.2.113.0", global); - check!("224.0.0.0", global | multicast); - check!("239.255.255.255", global | multicast); - check!("255.255.255.255", broadcast); - check!("198.18.0.0", benchmarking); - check!("198.18.54.2", benchmarking); - check!("198.19.255.255", benchmarking); - check!("192.0.0.0"); - check!("192.0.0.255"); - check!("192.0.0.100"); - check!("240.0.0.0", reserved); - check!("251.54.1.76", reserved); - check!("254.255.255.255", reserved); - check!("100.64.0.0", shared); - check!("100.127.255.255", shared); - check!("100.100.100.0", shared); -} - -#[test_case] -fn ipv6_properties() { - macro_rules! ip { - ($s:expr) => { - Ipv6Addr::from_str($s).unwrap() - }; - } - - macro_rules! check { - ($s:expr, &[$($octet:expr),*], $mask:expr) => { - assert_eq!($s, ip!($s).to_string()); - let octets = &[$($octet),*]; - assert_eq!(&ip!($s).octets(), octets); - assert_eq!(Ipv6Addr::from(*octets), ip!($s)); - - let unspecified: u32 = 1 << 0; - let loopback: u32 = 1 << 1; - let unique_local: u32 = 1 << 2; - let global: u32 = 1 << 3; - let unicast_link_local: u32 = 1 << 4; - let unicast_global: u32 = 1 << 7; - let documentation: u32 = 1 << 8; - let benchmarking: u32 = 1 << 16; - let multicast_interface_local: u32 = 1 << 9; - let multicast_link_local: u32 = 1 << 10; - let multicast_realm_local: u32 = 1 << 11; - let multicast_admin_local: u32 = 1 << 12; - let multicast_site_local: u32 = 1 << 13; - let multicast_organization_local: u32 = 1 << 14; - let multicast_global: u32 = 1 << 15; - let multicast: u32 = multicast_interface_local - | multicast_admin_local - | multicast_global - | multicast_link_local - | multicast_realm_local - | multicast_site_local - | multicast_organization_local; - - if ($mask & unspecified) == unspecified { - assert!(ip!($s).is_unspecified()); - } else { - assert!(!ip!($s).is_unspecified()); - } - if ($mask & loopback) == loopback { - assert!(ip!($s).is_loopback()); - } else { - assert!(!ip!($s).is_loopback()); - } - if ($mask & unique_local) == unique_local { - assert!(ip!($s).is_unique_local()); - } else { - assert!(!ip!($s).is_unique_local()); - } - if ($mask & global) == global { - assert!(ip!($s).is_global()); - } else { - assert!(!ip!($s).is_global()); - } - if ($mask & unicast_link_local) == unicast_link_local { - assert!(ip!($s).is_unicast_link_local()); - } else { - assert!(!ip!($s).is_unicast_link_local()); - } - if ($mask & unicast_global) == unicast_global { - assert!(ip!($s).is_unicast_global()); - } else { - assert!(!ip!($s).is_unicast_global()); - } - if ($mask & documentation) == documentation { - assert!(ip!($s).is_documentation()); - } else { - assert!(!ip!($s).is_documentation()); - } - if ($mask & benchmarking) == benchmarking { - assert!(ip!($s).is_benchmarking()); - } else { - assert!(!ip!($s).is_benchmarking()); - } - if ($mask & multicast) != 0 { - assert!(ip!($s).multicast_scope().is_some()); - assert!(ip!($s).is_multicast()); - } else { - assert!(ip!($s).multicast_scope().is_none()); - assert!(!ip!($s).is_multicast()); - } - if ($mask & multicast_interface_local) == multicast_interface_local { - assert_eq!(ip!($s).multicast_scope().unwrap(), - Ipv6MulticastScope::InterfaceLocal); - } - if ($mask & multicast_link_local) == multicast_link_local { - assert_eq!(ip!($s).multicast_scope().unwrap(), - Ipv6MulticastScope::LinkLocal); - } - if ($mask & multicast_realm_local) == multicast_realm_local { - assert_eq!(ip!($s).multicast_scope().unwrap(), - Ipv6MulticastScope::RealmLocal); - } - if ($mask & multicast_admin_local) == multicast_admin_local { - assert_eq!(ip!($s).multicast_scope().unwrap(), - Ipv6MulticastScope::AdminLocal); - } - if ($mask & multicast_site_local) == multicast_site_local { - assert_eq!(ip!($s).multicast_scope().unwrap(), - Ipv6MulticastScope::SiteLocal); - } - if ($mask & multicast_organization_local) == multicast_organization_local { - assert_eq!(ip!($s).multicast_scope().unwrap(), - Ipv6MulticastScope::OrganizationLocal); - } - if ($mask & multicast_global) == multicast_global { - assert_eq!(ip!($s).multicast_scope().unwrap(), - Ipv6MulticastScope::Global); - } - } - } - - let unspecified: u32 = 1 << 0; - let loopback: u32 = 1 << 1; - let unique_local: u32 = 1 << 2; - let global: u32 = 1 << 3; - let unicast_link_local: u32 = 1 << 4; - let unicast_global: u32 = 1 << 7; - let documentation: u32 = 1 << 8; - let benchmarking: u32 = 1 << 16; - let multicast_interface_local: u32 = 1 << 9; - let multicast_link_local: u32 = 1 << 10; - let multicast_realm_local: u32 = 1 << 11; - let multicast_admin_local: u32 = 1 << 12; - let multicast_site_local: u32 = 1 << 13; - let multicast_organization_local: u32 = 1 << 14; - let multicast_global: u32 = 1 << 15; - - check!("::", &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unspecified); - - check!("::1", &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], loopback); - - check!("::0.0.0.2", &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], global | unicast_global); - - check!("1::", &[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], global | unicast_global); - - check!( - "::ffff:127.0.0.1", - &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0x7f, 0, 0, 1], - unicast_global - ); - - check!( - "64:ff9b:1::", - &[0, 0x64, 0xff, 0x9b, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - unicast_global - ); - - check!("100::", &[0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unicast_global); - - check!("2001::", &[0x20, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unicast_global); - - check!( - "2001:1::1", - &[0x20, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], - global | unicast_global - ); - - check!( - "2001:1::2", - &[0x20, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], - global | unicast_global - ); - - check!( - "2001:3::", - &[0x20, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - global | unicast_global - ); - - check!( - "2001:4:112::", - &[0x20, 1, 0, 4, 1, 0x12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - global | unicast_global - ); - - check!( - "2001:20::", - &[0x20, 1, 0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - global | unicast_global - ); - - check!("2001:30::", &[0x20, 1, 0, 0x30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unicast_global); - - check!( - "2001:200::", - &[0x20, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - global | unicast_global - ); - - check!("fc00::", &[0xfc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unique_local); - - check!( - "fdff:ffff::", - &[0xfd, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - unique_local - ); - - check!( - "fe80:ffff::", - &[0xfe, 0x80, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - unicast_link_local - ); - - check!("fe80::", &[0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unicast_link_local); - - check!( - "febf:ffff::", - &[0xfe, 0xbf, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - unicast_link_local - ); - - check!("febf::", &[0xfe, 0xbf, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unicast_link_local); - - check!( - "febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff", - &[ - 0xfe, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff - ], - unicast_link_local - ); - - check!( - "fe80::ffff:ffff:ffff:ffff", - &[ - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff - ], - unicast_link_local - ); - - check!( - "fe80:0:0:1::", - &[0xfe, 0x80, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], - unicast_link_local - ); - - check!( - "fec0::", - &[0xfe, 0xc0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - unicast_global | global - ); - - check!( - "ff01::", - &[0xff, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - multicast_interface_local | global - ); - - check!( - "ff02::", - &[0xff, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - multicast_link_local | global - ); - - check!( - "ff03::", - &[0xff, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - multicast_realm_local | global - ); - - check!( - "ff04::", - &[0xff, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - multicast_admin_local | global - ); - - check!( - "ff05::", - &[0xff, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - multicast_site_local | global - ); - - check!( - "ff08::", - &[0xff, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - multicast_organization_local | global - ); - - check!( - "ff0e::", - &[0xff, 0xe, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - multicast_global | global - ); - - check!( - "2001:db8:85a3::8a2e:370:7334", - &[0x20, 1, 0xd, 0xb8, 0x85, 0xa3, 0, 0, 0, 0, 0x8a, 0x2e, 3, 0x70, 0x73, 0x34], - documentation - ); - - check!( - "2001:2::ac32:23ff:21", - &[0x20, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0xac, 0x32, 0x23, 0xff, 0, 0x21], - benchmarking - ); - - check!( - "102:304:506:708:90a:b0c:d0e:f10", - &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], - global | unicast_global - ); -} - #[test_case] fn to_socket_addr_socketaddr() { let a = sa4(Ipv4Addr::new(77, 88, 21, 11), 12345); assert_eq!(Ok(vec![a]), tsa(a)); } - -#[test_case] -fn test_ipv4_to_int() { - let a = Ipv4Addr::new(0x11, 0x22, 0x33, 0x44); - assert_eq!(u32::from(a), 0x11223344); -} - -#[test_case] -fn test_int_to_ipv4() { - let a = Ipv4Addr::new(0x11, 0x22, 0x33, 0x44); - assert_eq!(Ipv4Addr::from(0x11223344), a); -} - -#[test_case] -fn test_ipv6_to_int() { - let a = Ipv6Addr::new(0x1122, 0x3344, 0x5566, 0x7788, 0x99aa, 0xbbcc, 0xddee, 0xff11); - assert_eq!(u128::from(a), 0x112233445566778899aabbccddeeff11u128); -} - -#[test_case] -fn test_int_to_ipv6() { - let a = Ipv6Addr::new(0x1122, 0x3344, 0x5566, 0x7788, 0x99aa, 0xbbcc, 0xddee, 0xff11); - assert_eq!(Ipv6Addr::from(0x112233445566778899aabbccddeeff11u128), a); -} - -#[test_case] -fn ipv4_from_constructors() { - assert_eq!(Ipv4Addr::LOCALHOST, Ipv4Addr::new(127, 0, 0, 1)); - assert!(Ipv4Addr::LOCALHOST.is_loopback()); - assert_eq!(Ipv4Addr::UNSPECIFIED, Ipv4Addr::new(0, 0, 0, 0)); - assert!(Ipv4Addr::UNSPECIFIED.is_unspecified()); - assert_eq!(Ipv4Addr::BROADCAST, Ipv4Addr::new(255, 255, 255, 255)); - assert!(Ipv4Addr::BROADCAST.is_broadcast()); -} - -#[test_case] -fn ipv6_from_constructors() { - assert_eq!(Ipv6Addr::LOCALHOST, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)); - assert!(Ipv6Addr::LOCALHOST.is_loopback()); - assert_eq!(Ipv6Addr::UNSPECIFIED, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)); - assert!(Ipv6Addr::UNSPECIFIED.is_unspecified()); -} - -#[test_case] -fn ipv4_from_octets() { - assert_eq!(Ipv4Addr::from([127, 0, 0, 1]), Ipv4Addr::new(127, 0, 0, 1)) -} - -#[test_case] -fn ipv6_from_segments() { - let from_u16s = - Ipv6Addr::from([0x0011, 0x2233, 0x4455, 0x6677, 0x8899, 0xaabb, 0xccdd, 0xeeff]); - let new = Ipv6Addr::new(0x0011, 0x2233, 0x4455, 0x6677, 0x8899, 0xaabb, 0xccdd, 0xeeff); - assert_eq!(new, from_u16s); -} - -#[test_case] -fn ipv6_from_octets() { - let from_u16s = - Ipv6Addr::from([0x0011, 0x2233, 0x4455, 0x6677, 0x8899, 0xaabb, 0xccdd, 0xeeff]); - let from_u8s = Ipv6Addr::from([ - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, - 0xff, - ]); - assert_eq!(from_u16s, from_u8s); -} - -#[test_case] -fn cmp() { - let v41 = Ipv4Addr::new(100, 64, 3, 3); - let v42 = Ipv4Addr::new(192, 0, 2, 2); - let v61 = "2001:db8:f00::1002".parse::().unwrap(); - let v62 = "2001:db8:f00::2001".parse::().unwrap(); - assert!(v41 < v42); - assert!(v61 < v62); - - assert_eq!(v41, IpAddr::V4(v41)); - assert_eq!(v61, IpAddr::V6(v61)); - assert!(v41 != IpAddr::V4(v42)); - assert!(v61 != IpAddr::V6(v62)); - - assert!(v41 < IpAddr::V4(v42)); - assert!(v61 < IpAddr::V6(v62)); - assert!(IpAddr::V4(v41) < v42); - assert!(IpAddr::V6(v61) < v62); - - assert!(v41 < IpAddr::V6(v61)); - assert!(IpAddr::V4(v41) < v61); -} - -#[test_case] -fn is_v4() { - let ip = IpAddr::V4(Ipv4Addr::new(100, 64, 3, 3)); - assert!(ip.is_ipv4()); - assert!(!ip.is_ipv6()); -} - -#[test_case] -fn is_v6() { - let ip = IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x1234, 0x5678)); - assert!(!ip.is_ipv4()); - assert!(ip.is_ipv6()); -} - -#[test_case] -fn ipv4_const() { - // test that the methods of `Ipv4Addr` are usable in a const context - - const IP_ADDRESS: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1); - assert_eq!(IP_ADDRESS, Ipv4Addr::LOCALHOST); - - const OCTETS: [u8; 4] = IP_ADDRESS.octets(); - assert_eq!(OCTETS, [127, 0, 0, 1]); - - const IS_UNSPECIFIED: bool = IP_ADDRESS.is_unspecified(); - assert!(!IS_UNSPECIFIED); - - const IS_LOOPBACK: bool = IP_ADDRESS.is_loopback(); - assert!(IS_LOOPBACK); - - const IS_PRIVATE: bool = IP_ADDRESS.is_private(); - assert!(!IS_PRIVATE); - - const IS_LINK_LOCAL: bool = IP_ADDRESS.is_link_local(); - assert!(!IS_LINK_LOCAL); - - const IS_GLOBAL: bool = IP_ADDRESS.is_global(); - assert!(!IS_GLOBAL); - - const IS_SHARED: bool = IP_ADDRESS.is_shared(); - assert!(!IS_SHARED); - - const IS_BENCHMARKING: bool = IP_ADDRESS.is_benchmarking(); - assert!(!IS_BENCHMARKING); - - const IS_RESERVED: bool = IP_ADDRESS.is_reserved(); - assert!(!IS_RESERVED); - - const IS_MULTICAST: bool = IP_ADDRESS.is_multicast(); - assert!(!IS_MULTICAST); - - const IS_BROADCAST: bool = IP_ADDRESS.is_broadcast(); - assert!(!IS_BROADCAST); - - const IS_DOCUMENTATION: bool = IP_ADDRESS.is_documentation(); - assert!(!IS_DOCUMENTATION); - - const IP_V6_COMPATIBLE: Ipv6Addr = IP_ADDRESS.to_ipv6_compatible(); - assert_eq!( - IP_V6_COMPATIBLE, - Ipv6Addr::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1]) - ); - - const IP_V6_MAPPED: Ipv6Addr = IP_ADDRESS.to_ipv6_mapped(); - assert_eq!( - IP_V6_MAPPED, - Ipv6Addr::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127, 0, 0, 1]) - ); -} - -#[test_case] -fn ipv6_const() { - // test that the methods of `Ipv6Addr` are usable in a const context - - const IP_ADDRESS: Ipv6Addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1); - assert_eq!(IP_ADDRESS, Ipv6Addr::LOCALHOST); - - const SEGMENTS: [u16; 8] = IP_ADDRESS.segments(); - assert_eq!(SEGMENTS, [0, 0, 0, 0, 0, 0, 0, 1]); - - const OCTETS: [u8; 16] = IP_ADDRESS.octets(); - assert_eq!(OCTETS, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]); - - const IS_UNSPECIFIED: bool = IP_ADDRESS.is_unspecified(); - assert!(!IS_UNSPECIFIED); - - const IS_LOOPBACK: bool = IP_ADDRESS.is_loopback(); - assert!(IS_LOOPBACK); - - const IS_GLOBAL: bool = IP_ADDRESS.is_global(); - assert!(!IS_GLOBAL); - - const IS_UNIQUE_LOCAL: bool = IP_ADDRESS.is_unique_local(); - assert!(!IS_UNIQUE_LOCAL); - - const IS_UNICAST_LINK_LOCAL: bool = IP_ADDRESS.is_unicast_link_local(); - assert!(!IS_UNICAST_LINK_LOCAL); - - const IS_DOCUMENTATION: bool = IP_ADDRESS.is_documentation(); - assert!(!IS_DOCUMENTATION); - - const IS_BENCHMARKING: bool = IP_ADDRESS.is_benchmarking(); - assert!(!IS_BENCHMARKING); - - const IS_UNICAST_GLOBAL: bool = IP_ADDRESS.is_unicast_global(); - assert!(!IS_UNICAST_GLOBAL); - - const MULTICAST_SCOPE: Option = IP_ADDRESS.multicast_scope(); - assert_eq!(MULTICAST_SCOPE, None); - - const IS_MULTICAST: bool = IP_ADDRESS.is_multicast(); - assert!(!IS_MULTICAST); - - const IP_V4: Option = IP_ADDRESS.to_ipv4(); - assert_eq!(IP_V4.unwrap(), Ipv4Addr::new(0, 0, 0, 1)); -} - -#[test_case] -fn ip_const() { - // test that the methods of `IpAddr` are usable in a const context - - const IP_ADDRESS: IpAddr = IpAddr::V4(Ipv4Addr::LOCALHOST); - - const IS_UNSPECIFIED: bool = IP_ADDRESS.is_unspecified(); - assert!(!IS_UNSPECIFIED); - - const IS_LOOPBACK: bool = IP_ADDRESS.is_loopback(); - assert!(IS_LOOPBACK); - - const IS_GLOBAL: bool = IP_ADDRESS.is_global(); - assert!(!IS_GLOBAL); - - const IS_MULTICAST: bool = IP_ADDRESS.is_multicast(); - assert!(!IS_MULTICAST); - - const IS_IP_V4: bool = IP_ADDRESS.is_ipv4(); - assert!(IS_IP_V4); - - const IS_IP_V6: bool = IP_ADDRESS.is_ipv6(); - assert!(!IS_IP_V6); -} - -#[test_case] -fn structural_match() { - // test that all IP types can be structurally matched upon - - const IPV4: Ipv4Addr = Ipv4Addr::LOCALHOST; - match IPV4 { - Ipv4Addr::LOCALHOST => {} - _ => unreachable!(), - } - - const IPV6: Ipv6Addr = Ipv6Addr::LOCALHOST; - match IPV6 { - Ipv6Addr::LOCALHOST => {} - _ => unreachable!(), - } - - const IP: IpAddr = IpAddr::V4(Ipv4Addr::LOCALHOST); - match IP { - IpAddr::V4(Ipv4Addr::LOCALHOST) => {} - _ => unreachable!(), - } -} diff --git a/sgx_tstd/src/net/mod.rs b/sgx_tstd/src/net/mod.rs index c6e75a8e9..74dd1244b 100644 --- a/sgx_tstd/src/net/mod.rs +++ b/sgx_tstd/src/net/mod.rs @@ -39,7 +39,6 @@ use crate::io::{self, ErrorKind}; pub use self::ip_addr::{IpAddr, Ipv4Addr, Ipv6Addr, Ipv6MulticastScope}; -pub use self::parser::AddrParseError; pub use self::socket_addr::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs}; #[cfg(feature = "net")] pub use self::tcp::IntoIncoming; @@ -47,10 +46,9 @@ pub use self::tcp::IntoIncoming; pub use self::tcp::{Incoming, TcpListener, TcpStream}; #[cfg(feature = "net")] pub use self::udp::UdpSocket; +pub use core::net::AddrParseError; -mod display_buffer; mod ip_addr; -mod parser; mod socket_addr; #[cfg(feature = "net")] mod tcp; diff --git a/sgx_tstd/src/net/parser.rs b/sgx_tstd/src/net/parser.rs deleted file mode 100644 index 2fd84fd40..000000000 --- a/sgx_tstd/src/net/parser.rs +++ /dev/null @@ -1,503 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 private parser implementation of IPv4, IPv6, and socket addresses. -//! -//! This module is "publicly exported" through the `FromStr` implementations -//! below. - -#[cfg(feature = "unit_test")] -mod tests; - -use crate::error::Error; -use crate::fmt; -use crate::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; -use crate::str::FromStr; - -trait ReadNumberHelper: crate::marker::Sized { - const ZERO: Self; - fn checked_mul(&self, other: u32) -> Option; - fn checked_add(&self, other: u32) -> Option; -} - -macro_rules! impl_helper { - ($($t:ty)*) => ($(impl ReadNumberHelper for $t { - const ZERO: Self = 0; - #[inline] - fn checked_mul(&self, other: u32) -> Option { - Self::checked_mul(*self, other.try_into().ok()?) - } - #[inline] - fn checked_add(&self, other: u32) -> Option { - Self::checked_add(*self, other.try_into().ok()?) - } - })*) -} - -impl_helper! { u8 u16 u32 } - -struct Parser<'a> { - // Parsing as ASCII, so can use byte array. - state: &'a [u8], -} - -impl<'a> Parser<'a> { - fn new(input: &'a [u8]) -> Parser<'a> { - Parser { state: input } - } - - /// Run a parser, and restore the pre-parse state if it fails. - fn read_atomically(&mut self, inner: F) -> Option - where - F: FnOnce(&mut Parser<'_>) -> Option, - { - let state = self.state; - let result = inner(self); - if result.is_none() { - self.state = state; - } - result - } - - /// Run a parser, but fail if the entire input wasn't consumed. - /// Doesn't run atomically. - fn parse_with(&mut self, inner: F, kind: AddrKind) -> Result - where - F: FnOnce(&mut Parser<'_>) -> Option, - { - let result = inner(self); - if self.state.is_empty() { result } else { None }.ok_or(AddrParseError(kind)) - } - - /// Peek the next character from the input - fn peek_char(&self) -> Option { - self.state.first().map(|&b| char::from(b)) - } - - /// Read the next character from the input - fn read_char(&mut self) -> Option { - self.state.split_first().map(|(&b, tail)| { - self.state = tail; - char::from(b) - }) - } - - #[must_use] - /// Read the next character from the input if it matches the target. - fn read_given_char(&mut self, target: char) -> Option<()> { - self.read_atomically(|p| { - p.read_char().and_then(|c| if c == target { Some(()) } else { None }) - }) - } - - /// Helper for reading separators in an indexed loop. Reads the separator - /// character iff index > 0, then runs the parser. When used in a loop, - /// the separator character will only be read on index > 0 (see - /// read_ipv4_addr for an example) - fn read_separator(&mut self, sep: char, index: usize, inner: F) -> Option - where - F: FnOnce(&mut Parser<'_>) -> Option, - { - self.read_atomically(move |p| { - if index > 0 { - p.read_given_char(sep)?; - } - inner(p) - }) - } - - // Read a number off the front of the input in the given radix, stopping - // at the first non-digit character or eof. Fails if the number has more - // digits than max_digits or if there is no number. - #[allow(clippy::if_same_then_else)] - fn read_number( - &mut self, - radix: u32, - max_digits: Option, - allow_zero_prefix: bool, - ) -> Option { - self.read_atomically(move |p| { - let mut result = T::ZERO; - let mut digit_count = 0; - let has_leading_zero = p.peek_char() == Some('0'); - - while let Some(digit) = p.read_atomically(|p| p.read_char()?.to_digit(radix)) { - result = result.checked_mul(radix)?; - result = result.checked_add(digit)?; - digit_count += 1; - if let Some(max_digits) = max_digits { - if digit_count > max_digits { - return None; - } - } - } - - if digit_count == 0 { - None - } else if !allow_zero_prefix && has_leading_zero && digit_count > 1 { - None - } else { - Some(result) - } - }) - } - - /// Read an IPv4 address. - fn read_ipv4_addr(&mut self) -> Option { - self.read_atomically(|p| { - let mut groups = [0; 4]; - - for (i, slot) in groups.iter_mut().enumerate() { - *slot = p.read_separator('.', i, |p| { - // Disallow octal number in IP string. - // https://tools.ietf.org/html/rfc6943#section-3.1.1 - p.read_number(10, Some(3), false) - })?; - } - - Some(groups.into()) - }) - } - - /// Read an IPv6 Address. - fn read_ipv6_addr(&mut self) -> Option { - /// Read a chunk of an IPv6 address into `groups`. Returns the number - /// of groups read, along with a bool indicating if an embedded - /// trailing IPv4 address was read. Specifically, read a series of - /// colon-separated IPv6 groups (0x0000 - 0xFFFF), with an optional - /// trailing embedded IPv4 address. - fn read_groups(p: &mut Parser<'_>, groups: &mut [u16]) -> (usize, bool) { - let limit = groups.len(); - - for (i, slot) in groups.iter_mut().enumerate() { - // Try to read a trailing embedded IPv4 address. There must be - // at least two groups left. - if i < limit - 1 { - let ipv4 = p.read_separator(':', i, |p| p.read_ipv4_addr()); - - if let Some(v4_addr) = ipv4 { - let [one, two, three, four] = v4_addr.octets(); - groups[i] = u16::from_be_bytes([one, two]); - groups[i + 1] = u16::from_be_bytes([three, four]); - return (i + 2, true); - } - } - - let group = p.read_separator(':', i, |p| p.read_number(16, Some(4), true)); - - match group { - Some(g) => *slot = g, - None => return (i, false), - } - } - (groups.len(), false) - } - - self.read_atomically(|p| { - // Read the front part of the address; either the whole thing, or up - // to the first :: - let mut head = [0; 8]; - let (head_size, head_ipv4) = read_groups(p, &mut head); - - if head_size == 8 { - return Some(head.into()); - } - - // IPv4 part is not allowed before `::` - if head_ipv4 { - return None; - } - - // Read `::` if previous code parsed less than 8 groups. - // `::` indicates one or more groups of 16 bits of zeros. - p.read_given_char(':')?; - p.read_given_char(':')?; - - // Read the back part of the address. The :: must contain at least one - // set of zeroes, so our max length is 7. - let mut tail = [0; 7]; - let limit = 8 - (head_size + 1); - let (tail_size, _) = read_groups(p, &mut tail[..limit]); - - // Concat the head and tail of the IP address - head[(8 - tail_size)..8].copy_from_slice(&tail[..tail_size]); - - Some(head.into()) - }) - } - - /// Read an IP Address, either IPv4 or IPv6. - fn read_ip_addr(&mut self) -> Option { - self.read_ipv4_addr().map(IpAddr::V4).or_else(move || self.read_ipv6_addr().map(IpAddr::V6)) - } - - /// Read a `:` followed by a port in base 10. - fn read_port(&mut self) -> Option { - self.read_atomically(|p| { - p.read_given_char(':')?; - p.read_number(10, None, true) - }) - } - - /// Read a `%` followed by a scope ID in base 10. - fn read_scope_id(&mut self) -> Option { - self.read_atomically(|p| { - p.read_given_char('%')?; - p.read_number(10, None, true) - }) - } - - /// Read an IPv4 address with a port. - fn read_socket_addr_v4(&mut self) -> Option { - self.read_atomically(|p| { - let ip = p.read_ipv4_addr()?; - let port = p.read_port()?; - Some(SocketAddrV4::new(ip, port)) - }) - } - - /// Read an IPv6 address with a port. - fn read_socket_addr_v6(&mut self) -> Option { - self.read_atomically(|p| { - p.read_given_char('[')?; - let ip = p.read_ipv6_addr()?; - let scope_id = p.read_scope_id().unwrap_or(0); - p.read_given_char(']')?; - - let port = p.read_port()?; - Some(SocketAddrV6::new(ip, port, 0, scope_id)) - }) - } - - /// Read an IP address with a port - fn read_socket_addr(&mut self) -> Option { - self.read_socket_addr_v4() - .map(SocketAddr::V4) - .or_else(|| self.read_socket_addr_v6().map(SocketAddr::V6)) - } -} - -impl IpAddr { - /// Parse an IP address from a slice of bytes. - /// - /// ``` - /// #![feature(addr_parse_ascii)] - /// - /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - /// - /// let localhost_v4 = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); - /// let localhost_v6 = IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)); - /// - /// assert_eq!(IpAddr::parse_ascii(b"127.0.0.1"), Ok(localhost_v4)); - /// assert_eq!(IpAddr::parse_ascii(b"::1"), Ok(localhost_v6)); - /// ``` - pub fn parse_ascii(b: &[u8]) -> Result { - Parser::new(b).parse_with(|p| p.read_ip_addr(), AddrKind::Ip) - } -} - -impl FromStr for IpAddr { - type Err = AddrParseError; - fn from_str(s: &str) -> Result { - Self::parse_ascii(s.as_bytes()) - } -} - -impl Ipv4Addr { - /// Parse an IPv4 address from a slice of bytes. - /// - /// ``` - /// #![feature(addr_parse_ascii)] - /// - /// use std::net::Ipv4Addr; - /// - /// let localhost = Ipv4Addr::new(127, 0, 0, 1); - /// - /// assert_eq!(Ipv4Addr::parse_ascii(b"127.0.0.1"), Ok(localhost)); - /// ``` - pub fn parse_ascii(b: &[u8]) -> Result { - // don't try to parse if too long - if b.len() > 15 { - Err(AddrParseError(AddrKind::Ipv4)) - } else { - Parser::new(b).parse_with(|p| p.read_ipv4_addr(), AddrKind::Ipv4) - } - } -} - -impl FromStr for Ipv4Addr { - type Err = AddrParseError; - fn from_str(s: &str) -> Result { - Self::parse_ascii(s.as_bytes()) - } -} - -impl Ipv6Addr { - /// Parse an IPv6 address from a slice of bytes. - /// - /// ``` - /// #![feature(addr_parse_ascii)] - /// - /// use std::net::Ipv6Addr; - /// - /// let localhost = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1); - /// - /// assert_eq!(Ipv6Addr::parse_ascii(b"::1"), Ok(localhost)); - /// ``` - pub fn parse_ascii(b: &[u8]) -> Result { - Parser::new(b).parse_with(|p| p.read_ipv6_addr(), AddrKind::Ipv6) - } -} - -impl FromStr for Ipv6Addr { - type Err = AddrParseError; - fn from_str(s: &str) -> Result { - Self::parse_ascii(s.as_bytes()) - } -} - -impl SocketAddrV4 { - /// Parse an IPv4 socket address from a slice of bytes. - /// - /// ``` - /// #![feature(addr_parse_ascii)] - /// - /// use std::net::{Ipv4Addr, SocketAddrV4}; - /// - /// let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080); - /// - /// assert_eq!(SocketAddrV4::parse_ascii(b"127.0.0.1:8080"), Ok(socket)); - /// ``` - pub fn parse_ascii(b: &[u8]) -> Result { - Parser::new(b).parse_with(|p| p.read_socket_addr_v4(), AddrKind::SocketV4) - } -} - -impl FromStr for SocketAddrV4 { - type Err = AddrParseError; - fn from_str(s: &str) -> Result { - Self::parse_ascii(s.as_bytes()) - } -} - -impl SocketAddrV6 { - /// Parse an IPv6 socket address from a slice of bytes. - /// - /// ``` - /// #![feature(addr_parse_ascii)] - /// - /// use std::net::{Ipv6Addr, SocketAddrV6}; - /// - /// let socket = SocketAddrV6::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1), 8080, 0, 0); - /// - /// assert_eq!(SocketAddrV6::parse_ascii(b"[2001:db8::1]:8080"), Ok(socket)); - /// ``` - pub fn parse_ascii(b: &[u8]) -> Result { - Parser::new(b).parse_with(|p| p.read_socket_addr_v6(), AddrKind::SocketV6) - } -} - -impl FromStr for SocketAddrV6 { - type Err = AddrParseError; - fn from_str(s: &str) -> Result { - Self::parse_ascii(s.as_bytes()) - } -} - -impl SocketAddr { - /// Parse a socket address from a slice of bytes. - /// - /// ``` - /// #![feature(addr_parse_ascii)] - /// - /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; - /// - /// let socket_v4 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); - /// let socket_v6 = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 8080); - /// - /// assert_eq!(SocketAddr::parse_ascii(b"127.0.0.1:8080"), Ok(socket_v4)); - /// assert_eq!(SocketAddr::parse_ascii(b"[::1]:8080"), Ok(socket_v6)); - /// ``` - pub fn parse_ascii(b: &[u8]) -> Result { - Parser::new(b).parse_with(|p| p.read_socket_addr(), AddrKind::Socket) - } -} - -impl FromStr for SocketAddr { - type Err = AddrParseError; - fn from_str(s: &str) -> Result { - Self::parse_ascii(s.as_bytes()) - } -} - -#[derive(Debug, Clone, PartialEq, Eq)] -enum AddrKind { - Ip, - Ipv4, - Ipv6, - Socket, - SocketV4, - SocketV6, -} - -/// An error which can be returned when parsing an IP address or a socket address. -/// -/// This error is used as the error type for the [`FromStr`] implementation for -/// [`IpAddr`], [`Ipv4Addr`], [`Ipv6Addr`], [`SocketAddr`], [`SocketAddrV4`], and -/// [`SocketAddrV6`]. -/// -/// # Potential causes -/// -/// `AddrParseError` may be thrown because the provided string does not parse as the given type, -/// often because it includes information only handled by a different address type. -/// -/// ```should_panic -/// use std::net::IpAddr; -/// let _foo: IpAddr = "127.0.0.1:8080".parse().expect("Cannot handle the socket port"); -/// ``` -/// -/// [`IpAddr`] doesn't handle the port. Use [`SocketAddr`] instead. -/// -/// ``` -/// use std::net::SocketAddr; -/// -/// // No problem, the `panic!` message has disappeared. -/// let _foo: SocketAddr = "127.0.0.1:8080".parse().expect("unreachable panic"); -/// ``` -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct AddrParseError(AddrKind); - -impl fmt::Display for AddrParseError { - #[allow(deprecated, deprecated_in_future)] - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt.write_str(self.description()) - } -} - -impl Error for AddrParseError { - #[allow(deprecated)] - fn description(&self) -> &str { - match self.0 { - AddrKind::Ip => "invalid IP address syntax", - AddrKind::Ipv4 => "invalid IPv4 address syntax", - AddrKind::Ipv6 => "invalid IPv6 address syntax", - AddrKind::Socket => "invalid socket address syntax", - AddrKind::SocketV4 => "invalid IPv4 socket address syntax", - AddrKind::SocketV6 => "invalid IPv6 socket address syntax", - } - } -} \ No newline at end of file diff --git a/sgx_tstd/src/net/parser/tests.rs b/sgx_tstd/src/net/parser/tests.rs deleted file mode 100644 index 15960d5f0..000000000 --- a/sgx_tstd/src/net/parser/tests.rs +++ /dev/null @@ -1,168 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License.. - -// FIXME: These tests are all excellent candidates for AFL fuzz testing -use crate::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; -use crate::str::FromStr; - -use sgx_test_utils::test_case; - -const PORT: u16 = 8080; -const SCOPE_ID: u32 = 1337; - -const IPV4: Ipv4Addr = Ipv4Addr::new(192, 168, 0, 1); -const IPV4_STR: &str = "192.168.0.1"; -const IPV4_STR_PORT: &str = "192.168.0.1:8080"; -const IPV4_STR_WITH_OCTAL: &str = "0127.0.0.1"; -const IPV4_STR_WITH_HEX: &str = "0x10.0.0.1"; - -const IPV6: Ipv6Addr = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0xc0a8, 0x1); -const IPV6_STR_FULL: &str = "2001:db8:0:0:0:0:c0a8:1"; -const IPV6_STR_COMPRESS: &str = "2001:db8::c0a8:1"; -const IPV6_STR_V4: &str = "2001:db8::192.168.0.1"; -const IPV6_STR_V4_WITH_OCTAL: &str = "2001:db8::0127.0.0.1"; -const IPV6_STR_V4_WITH_HEX: &str = "2001:db8::0x10.0.0.1"; -const IPV6_STR_PORT: &str = "[2001:db8::c0a8:1]:8080"; -const IPV6_STR_PORT_SCOPE_ID: &str = "[2001:db8::c0a8:1%1337]:8080"; - -#[test_case] -fn parse_ipv4() { - let result: Ipv4Addr = IPV4_STR.parse().unwrap(); - assert_eq!(result, IPV4); - - assert!(Ipv4Addr::from_str(IPV4_STR_PORT).is_err()); - assert!(Ipv4Addr::from_str(IPV4_STR_WITH_OCTAL).is_err()); - assert!(Ipv4Addr::from_str(IPV4_STR_WITH_HEX).is_err()); - assert!(Ipv4Addr::from_str(IPV6_STR_FULL).is_err()); - assert!(Ipv4Addr::from_str(IPV6_STR_COMPRESS).is_err()); - assert!(Ipv4Addr::from_str(IPV6_STR_V4).is_err()); - assert!(Ipv4Addr::from_str(IPV6_STR_PORT).is_err()); -} - -#[test_case] -fn parse_ipv6() { - let result: Ipv6Addr = IPV6_STR_FULL.parse().unwrap(); - assert_eq!(result, IPV6); - - let result: Ipv6Addr = IPV6_STR_COMPRESS.parse().unwrap(); - assert_eq!(result, IPV6); - - let result: Ipv6Addr = IPV6_STR_V4.parse().unwrap(); - assert_eq!(result, IPV6); - - assert!(Ipv6Addr::from_str(IPV6_STR_V4_WITH_OCTAL).is_err()); - assert!(Ipv6Addr::from_str(IPV6_STR_V4_WITH_HEX).is_err()); - assert!(Ipv6Addr::from_str(IPV4_STR).is_err()); - assert!(Ipv6Addr::from_str(IPV4_STR_PORT).is_err()); - assert!(Ipv6Addr::from_str(IPV6_STR_PORT).is_err()); -} - -#[test_case] -fn parse_ip() { - let result: IpAddr = IPV4_STR.parse().unwrap(); - assert_eq!(result, IpAddr::from(IPV4)); - - let result: IpAddr = IPV6_STR_FULL.parse().unwrap(); - assert_eq!(result, IpAddr::from(IPV6)); - - let result: IpAddr = IPV6_STR_COMPRESS.parse().unwrap(); - assert_eq!(result, IpAddr::from(IPV6)); - - let result: IpAddr = IPV6_STR_V4.parse().unwrap(); - assert_eq!(result, IpAddr::from(IPV6)); - - assert!(IpAddr::from_str(IPV4_STR_PORT).is_err()); - assert!(IpAddr::from_str(IPV6_STR_PORT).is_err()); -} - -#[test_case] -fn parse_socket_v4() { - let result: SocketAddrV4 = IPV4_STR_PORT.parse().unwrap(); - assert_eq!(result, SocketAddrV4::new(IPV4, PORT)); - - assert!(SocketAddrV4::from_str(IPV4_STR).is_err()); - assert!(SocketAddrV4::from_str(IPV6_STR_FULL).is_err()); - assert!(SocketAddrV4::from_str(IPV6_STR_COMPRESS).is_err()); - assert!(SocketAddrV4::from_str(IPV6_STR_V4).is_err()); - assert!(SocketAddrV4::from_str(IPV6_STR_PORT).is_err()); -} - -#[test_case] -fn parse_socket_v6() { - assert_eq!(IPV6_STR_PORT.parse(), Ok(SocketAddrV6::new(IPV6, PORT, 0, 0))); - assert_eq!(IPV6_STR_PORT_SCOPE_ID.parse(), Ok(SocketAddrV6::new(IPV6, PORT, 0, SCOPE_ID))); - - assert!(SocketAddrV6::from_str(IPV4_STR).is_err()); - assert!(SocketAddrV6::from_str(IPV4_STR_PORT).is_err()); - assert!(SocketAddrV6::from_str(IPV6_STR_FULL).is_err()); - assert!(SocketAddrV6::from_str(IPV6_STR_COMPRESS).is_err()); - assert!(SocketAddrV6::from_str(IPV6_STR_V4).is_err()); -} - -#[test_case] -fn parse_socket() { - let result: SocketAddr = IPV4_STR_PORT.parse().unwrap(); - assert_eq!(result, SocketAddr::from((IPV4, PORT))); - - let result: SocketAddr = IPV6_STR_PORT.parse().unwrap(); - assert_eq!(result, SocketAddr::from((IPV6, PORT))); - - assert!(SocketAddr::from_str(IPV4_STR).is_err()); - assert!(SocketAddr::from_str(IPV6_STR_FULL).is_err()); - assert!(SocketAddr::from_str(IPV6_STR_COMPRESS).is_err()); - assert!(SocketAddr::from_str(IPV6_STR_V4).is_err()); -} - -#[test_case] -fn ipv6_corner_cases() { - let result: Ipv6Addr = "1::".parse().unwrap(); - assert_eq!(result, Ipv6Addr::new(1, 0, 0, 0, 0, 0, 0, 0)); - - let result: Ipv6Addr = "1:1::".parse().unwrap(); - assert_eq!(result, Ipv6Addr::new(1, 1, 0, 0, 0, 0, 0, 0)); - - let result: Ipv6Addr = "::1".parse().unwrap(); - assert_eq!(result, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)); - - let result: Ipv6Addr = "::1:1".parse().unwrap(); - assert_eq!(result, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 1, 1)); - - let result: Ipv6Addr = "::".parse().unwrap(); - assert_eq!(result, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)); - - let result: Ipv6Addr = "::192.168.0.1".parse().unwrap(); - assert_eq!(result, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0xc0a8, 0x1)); - - let result: Ipv6Addr = "::1:192.168.0.1".parse().unwrap(); - assert_eq!(result, Ipv6Addr::new(0, 0, 0, 0, 0, 1, 0xc0a8, 0x1)); - - let result: Ipv6Addr = "1:1:1:1:1:1:192.168.0.1".parse().unwrap(); - assert_eq!(result, Ipv6Addr::new(1, 1, 1, 1, 1, 1, 0xc0a8, 0x1)); -} - -// Things that might not seem like failures but are -#[test_case] -fn ipv6_corner_failures() { - // No IP address before the :: - assert!(Ipv6Addr::from_str("1:192.168.0.1::").is_err()); - - // :: must have at least 1 set of zeroes - assert!(Ipv6Addr::from_str("1:1:1:1::1:1:1:1").is_err()); - - // Need brackets for a port - assert!(SocketAddrV6::from_str("1:1:1:1:1:1:1:1:8080").is_err()); -} diff --git a/sgx_tstd/src/net/socket_addr.rs b/sgx_tstd/src/net/socket_addr.rs index d551e84e8..94d038283 100644 --- a/sgx_tstd/src/net/socket_addr.rs +++ b/sgx_tstd/src/net/socket_addr.rs @@ -15,16 +15,12 @@ // specific language governing permissions and limitations // under the License.. -#![allow(clippy::derive_hash_xor_eq)] +#![allow(clippy::derived_hash_with_manual_eq)] +// Tests for this module #[cfg(feature = "unit_test")] mod tests; -use crate::cmp::Ordering; -#[cfg(feature = "net")] -use crate::convert::TryInto; -use crate::fmt::{self, Write}; -use crate::hash; use crate::io; use crate::iter; use crate::mem; @@ -33,509 +29,38 @@ use crate::option; use crate::slice; #[cfg(feature = "net")] use crate::sys_common::net::LookupHost; -use crate::sys_common::{FromInner, IntoInner}; +use crate::sys_common::{FromInner, IntoInner, TryIntoInner}; use crate::vec; -use super::display_buffer::DisplayBuffer; - use sgx_oc::ocall::SockAddr; use sgx_oc as c; -/// An internet socket address, either IPv4 or IPv6. -/// -/// Internet socket addresses consist of an [IP address], a 16-bit port number, as well -/// as possibly some version-dependent additional information. See [`SocketAddrV4`]'s and -/// [`SocketAddrV6`]'s respective documentation for more details. -/// -/// The size of a `SocketAddr` instance may vary depending on the target operating -/// system. -/// -/// [IP address]: IpAddr -/// -/// # Examples -/// -/// ``` -/// use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -/// -/// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); -/// -/// assert_eq!("127.0.0.1:8080".parse(), Ok(socket)); -/// assert_eq!(socket.port(), 8080); -/// assert_eq!(socket.is_ipv4(), true); -/// ``` -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub enum SocketAddr { - /// An IPv4 socket address. - V4(SocketAddrV4), - /// An IPv6 socket address. - V6(SocketAddrV6), -} - -/// An IPv4 socket address. -/// -/// IPv4 socket addresses consist of an [`IPv4` address] and a 16-bit port number, as -/// stated in [IETF RFC 793]. -/// -/// See [`SocketAddr`] for a type encompassing both IPv4 and IPv6 socket addresses. -/// -/// The size of a `SocketAddrV4` struct may vary depending on the target operating -/// system. Do not assume that this type has the same memory layout as the underlying -/// system representation. -/// -/// [IETF RFC 793]: https://tools.ietf.org/html/rfc793 -/// [`IPv4` address]: Ipv4Addr -/// -/// # Examples -/// -/// ``` -/// use std::net::{Ipv4Addr, SocketAddrV4}; -/// -/// let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080); -/// -/// assert_eq!("127.0.0.1:8080".parse(), Ok(socket)); -/// assert_eq!(socket.ip(), &Ipv4Addr::new(127, 0, 0, 1)); -/// assert_eq!(socket.port(), 8080); -/// ``` -#[derive(Copy, Clone, Eq, PartialEq)] -pub struct SocketAddrV4 { - ip: Ipv4Addr, - port: u16, -} - -/// An IPv6 socket address. -/// -/// IPv6 socket addresses consist of an [`IPv6` address], a 16-bit port number, as well -/// as fields containing the traffic class, the flow label, and a scope identifier -/// (see [IETF RFC 2553, Section 3.3] for more details). -/// -/// See [`SocketAddr`] for a type encompassing both IPv4 and IPv6 socket addresses. -/// -/// The size of a `SocketAddrV6` struct may vary depending on the target operating -/// system. Do not assume that this type has the same memory layout as the underlying -/// system representation. -/// -/// [IETF RFC 2553, Section 3.3]: https://tools.ietf.org/html/rfc2553#section-3.3 -/// [`IPv6` address]: Ipv6Addr -/// -/// # Examples -/// -/// ``` -/// use std::net::{Ipv6Addr, SocketAddrV6}; -/// -/// let socket = SocketAddrV6::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1), 8080, 0, 0); -/// -/// assert_eq!("[2001:db8::1]:8080".parse(), Ok(socket)); -/// assert_eq!(socket.ip(), &Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1)); -/// assert_eq!(socket.port(), 8080); -/// ``` -#[derive(Copy, Clone, Eq, PartialEq)] -pub struct SocketAddrV6 { - ip: Ipv6Addr, - port: u16, - flowinfo: u32, - scope_id: u32, -} - -impl SocketAddr { - /// Creates a new socket address from an [IP address] and a port number. - /// - /// [IP address]: IpAddr - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr, SocketAddr}; - /// - /// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); - /// assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))); - /// assert_eq!(socket.port(), 8080); - /// ``` - #[must_use] - pub const fn new(ip: IpAddr, port: u16) -> SocketAddr { - match ip { - IpAddr::V4(a) => SocketAddr::V4(SocketAddrV4::new(a, port)), - IpAddr::V6(a) => SocketAddr::V6(SocketAddrV6::new(a, port, 0, 0)), - } - } - - /// Returns the IP address associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr, SocketAddr}; - /// - /// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); - /// assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))); - /// ``` - #[must_use] - pub const fn ip(&self) -> IpAddr { - match *self { - SocketAddr::V4(ref a) => IpAddr::V4(*a.ip()), - SocketAddr::V6(ref a) => IpAddr::V6(*a.ip()), - } - } - - /// Changes the IP address associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr, SocketAddr}; - /// - /// let mut socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); - /// socket.set_ip(IpAddr::V4(Ipv4Addr::new(10, 10, 0, 1))); - /// assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(10, 10, 0, 1))); - /// ``` - pub fn set_ip(&mut self, new_ip: IpAddr) { - // `match (*self, new_ip)` would have us mutate a copy of self only to throw it away. - match (self, new_ip) { - (&mut SocketAddr::V4(ref mut a), IpAddr::V4(new_ip)) => a.set_ip(new_ip), - (&mut SocketAddr::V6(ref mut a), IpAddr::V6(new_ip)) => a.set_ip(new_ip), - (self_, new_ip) => *self_ = Self::new(new_ip, self_.port()), - } - } - - /// Returns the port number associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr, SocketAddr}; - /// - /// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); - /// assert_eq!(socket.port(), 8080); - /// ``` - #[must_use] - pub const fn port(&self) -> u16 { - match *self { - SocketAddr::V4(ref a) => a.port(), - SocketAddr::V6(ref a) => a.port(), - } - } - - /// Changes the port number associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr, SocketAddr}; - /// - /// let mut socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); - /// socket.set_port(1025); - /// assert_eq!(socket.port(), 1025); - /// ``` - pub fn set_port(&mut self, new_port: u16) { - match *self { - SocketAddr::V4(ref mut a) => a.set_port(new_port), - SocketAddr::V6(ref mut a) => a.set_port(new_port), - } - } - - /// Returns [`true`] if the [IP address] in this `SocketAddr` is an - /// [`IPv4` address], and [`false`] otherwise. - /// - /// [IP address]: IpAddr - /// [`IPv4` address]: IpAddr::V4 - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr, SocketAddr}; - /// - /// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); - /// assert_eq!(socket.is_ipv4(), true); - /// assert_eq!(socket.is_ipv6(), false); - /// ``` - #[must_use] - pub const fn is_ipv4(&self) -> bool { - matches!(*self, SocketAddr::V4(_)) - } - - /// Returns [`true`] if the [IP address] in this `SocketAddr` is an - /// [`IPv6` address], and [`false`] otherwise. - /// - /// [IP address]: IpAddr - /// [`IPv6` address]: IpAddr::V6 - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv6Addr, SocketAddr}; - /// - /// let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 65535, 0, 1)), 8080); - /// assert_eq!(socket.is_ipv4(), false); - /// assert_eq!(socket.is_ipv6(), true); - /// ``` - #[must_use] - pub const fn is_ipv6(&self) -> bool { - matches!(*self, SocketAddr::V6(_)) - } -} - -impl SocketAddrV4 { - /// Creates a new socket address from an [`IPv4` address] and a port number. - /// - /// [`IPv4` address]: Ipv4Addr - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV4, Ipv4Addr}; - /// - /// let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080); - /// ``` - #[must_use] - pub const fn new(ip: Ipv4Addr, port: u16) -> SocketAddrV4 { - SocketAddrV4 { ip, port } - } - - /// Returns the IP address associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV4, Ipv4Addr}; - /// - /// let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080); - /// assert_eq!(socket.ip(), &Ipv4Addr::new(127, 0, 0, 1)); - /// ``` - #[must_use] - pub const fn ip(&self) -> &Ipv4Addr { - &self.ip - } - - /// Changes the IP address associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV4, Ipv4Addr}; - /// - /// let mut socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080); - /// socket.set_ip(Ipv4Addr::new(192, 168, 0, 1)); - /// assert_eq!(socket.ip(), &Ipv4Addr::new(192, 168, 0, 1)); - /// ``` - pub fn set_ip(&mut self, new_ip: Ipv4Addr) { - self.ip = new_ip; - } - - /// Returns the port number associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV4, Ipv4Addr}; - /// - /// let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080); - /// assert_eq!(socket.port(), 8080); - /// ``` - #[must_use] - pub const fn port(&self) -> u16 { - self.port - } - - /// Changes the port number associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV4, Ipv4Addr}; - /// - /// let mut socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080); - /// socket.set_port(4242); - /// assert_eq!(socket.port(), 4242); - /// ``` - pub fn set_port(&mut self, new_port: u16) { - self.port = new_port; - } -} - -impl SocketAddrV6 { - /// Creates a new socket address from an [`IPv6` address], a 16-bit port number, - /// and the `flowinfo` and `scope_id` fields. - /// - /// For more information on the meaning and layout of the `flowinfo` and `scope_id` - /// parameters, see [IETF RFC 2553, Section 3.3]. - /// - /// [IETF RFC 2553, Section 3.3]: https://tools.ietf.org/html/rfc2553#section-3.3 - /// [`IPv6` address]: Ipv6Addr - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV6, Ipv6Addr}; - /// - /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0); - /// ``` - #[must_use] - pub const fn new(ip: Ipv6Addr, port: u16, flowinfo: u32, scope_id: u32) -> SocketAddrV6 { - SocketAddrV6 { ip, port, flowinfo, scope_id } - } - - /// Returns the IP address associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV6, Ipv6Addr}; - /// - /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0); - /// assert_eq!(socket.ip(), &Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)); - /// ``` - #[must_use] - pub const fn ip(&self) -> &Ipv6Addr { - &self.ip - } - - /// Changes the IP address associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV6, Ipv6Addr}; - /// - /// let mut socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0); - /// socket.set_ip(Ipv6Addr::new(76, 45, 0, 0, 0, 0, 0, 0)); - /// assert_eq!(socket.ip(), &Ipv6Addr::new(76, 45, 0, 0, 0, 0, 0, 0)); - /// ``` - pub fn set_ip(&mut self, new_ip: Ipv6Addr) { - self.ip = new_ip; - } - - /// Returns the port number associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV6, Ipv6Addr}; - /// - /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0); - /// assert_eq!(socket.port(), 8080); - /// ``` - #[must_use] - pub const fn port(&self) -> u16 { - self.port - } - - /// Changes the port number associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV6, Ipv6Addr}; - /// - /// let mut socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0); - /// socket.set_port(4242); - /// assert_eq!(socket.port(), 4242); - /// ``` - pub fn set_port(&mut self, new_port: u16) { - self.port = new_port; - } - - /// Returns the flow information associated with this address. - /// - /// This information corresponds to the `sin6_flowinfo` field in C's `netinet/in.h`, - /// as specified in [IETF RFC 2553, Section 3.3]. - /// It combines information about the flow label and the traffic class as specified - /// in [IETF RFC 2460], respectively [Section 6] and [Section 7]. - /// - /// [IETF RFC 2553, Section 3.3]: https://tools.ietf.org/html/rfc2553#section-3.3 - /// [IETF RFC 2460]: https://tools.ietf.org/html/rfc2460 - /// [Section 6]: https://tools.ietf.org/html/rfc2460#section-6 - /// [Section 7]: https://tools.ietf.org/html/rfc2460#section-7 - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV6, Ipv6Addr}; - /// - /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 10, 0); - /// assert_eq!(socket.flowinfo(), 10); - /// ``` - #[must_use] - pub const fn flowinfo(&self) -> u32 { - self.flowinfo - } - - /// Changes the flow information associated with this socket address. - /// - /// See [`SocketAddrV6::flowinfo`]'s documentation for more details. - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV6, Ipv6Addr}; - /// - /// let mut socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 10, 0); - /// socket.set_flowinfo(56); - /// assert_eq!(socket.flowinfo(), 56); - /// ``` - pub fn set_flowinfo(&mut self, new_flowinfo: u32) { - self.flowinfo = new_flowinfo; - } - - /// Returns the scope ID associated with this address. - /// - /// This information corresponds to the `sin6_scope_id` field in C's `netinet/in.h`, - /// as specified in [IETF RFC 2553, Section 3.3]. - /// - /// [IETF RFC 2553, Section 3.3]: https://tools.ietf.org/html/rfc2553#section-3.3 - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV6, Ipv6Addr}; - /// - /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 78); - /// assert_eq!(socket.scope_id(), 78); - /// ``` - #[must_use] - pub const fn scope_id(&self) -> u32 { - self.scope_id - } - - /// Changes the scope ID associated with this socket address. - /// - /// See [`SocketAddrV6::scope_id`]'s documentation for more details. - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV6, Ipv6Addr}; - /// - /// let mut socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 78); - /// socket.set_scope_id(42); - /// assert_eq!(socket.scope_id(), 42); - /// ``` - pub fn set_scope_id(&mut self, new_scope_id: u32) { - self.scope_id = new_scope_id; - } -} +pub use core::net::{SocketAddr, SocketAddrV4, SocketAddrV6}; impl FromInner for SocketAddrV4 { fn from_inner(addr: c::sockaddr_in) -> SocketAddrV4 { - SocketAddrV4 { ip: Ipv4Addr::from_inner(addr.sin_addr), port: u16::from_be(addr.sin_port) } + SocketAddrV4::new(Ipv4Addr::from_inner(addr.sin_addr), u16::from_be(addr.sin_port)) } } impl FromInner for SocketAddrV6 { fn from_inner(addr: c::sockaddr_in6) -> SocketAddrV6 { - SocketAddrV6 { - ip: Ipv6Addr::from_inner(addr.sin6_addr), - port: u16::from_be(addr.sin6_port), - flowinfo: addr.sin6_flowinfo, - scope_id: addr.sin6_scope_id, - } + SocketAddrV6::new( + Ipv6Addr::from_inner(addr.sin6_addr), + u16::from_be(addr.sin6_port), + addr.sin6_flowinfo, + addr.sin6_scope_id, + ) } } impl IntoInner for SocketAddrV4 { + #[allow(clippy::needless_update)] fn into_inner(self) -> c::sockaddr_in { c::sockaddr_in { sin_family: c::AF_INET as c::sa_family_t, - sin_port: self.port.to_be(), - sin_addr: self.ip.into_inner(), + sin_port: self.port().to_be(), + sin_addr: self.ip().into_inner(), ..unsafe { mem::zeroed() } } } @@ -546,38 +71,29 @@ impl IntoInner for SocketAddrV6 { fn into_inner(self) -> c::sockaddr_in6 { c::sockaddr_in6 { sin6_family: c::AF_INET6 as c::sa_family_t, - sin6_port: self.port.to_be(), - sin6_addr: self.ip.into_inner(), - sin6_flowinfo: self.flowinfo, - sin6_scope_id: self.scope_id, + sin6_port: self.port().to_be(), + sin6_addr: self.ip().into_inner(), + sin6_flowinfo: self.flowinfo(), + sin6_scope_id: self.scope_id(), ..unsafe { mem::zeroed() } } } } -impl From for SockAddr { - fn from(addr: SocketAddr) -> SockAddr { - match addr { - SocketAddr::V4(sa) => SockAddr::IN4(sa.into_inner()), - SocketAddr::V6(sa) => SockAddr::IN6(sa.into_inner()), - } - } -} - -impl From<&SocketAddr> for SockAddr { - fn from(addr: &SocketAddr) -> SockAddr { - match *addr { +impl<'a> IntoInner for &'a SocketAddr { + fn into_inner(self) -> SockAddr { + match *self { SocketAddr::V4(sa) => SockAddr::IN4(sa.into_inner()), SocketAddr::V6(sa) => SockAddr::IN6(sa.into_inner()), } } } -impl TryFrom for SocketAddr { +impl TryIntoInner for SockAddr { type Error = io::Error; - fn try_from(addr: SockAddr) -> io::Result { - match addr { + fn try_into_inner(self) -> io::Result { + match self { SockAddr::IN4(sa) => Ok(SocketAddr::V4(SocketAddrV4::from_inner(sa))), SockAddr::IN6(sa) => Ok(SocketAddr::V6(SocketAddrV6::from_inner(sa))), _ => Err(io::const_io_error!(io::ErrorKind::InvalidData, "Unsupported SocketAddr")), @@ -585,139 +101,6 @@ impl TryFrom for SocketAddr { } } -impl From for SocketAddr { - /// Converts a [`SocketAddrV4`] into a [`SocketAddr::V4`]. - fn from(sock4: SocketAddrV4) -> SocketAddr { - SocketAddr::V4(sock4) - } -} - -impl From for SocketAddr { - /// Converts a [`SocketAddrV6`] into a [`SocketAddr::V6`]. - fn from(sock6: SocketAddrV6) -> SocketAddr { - SocketAddr::V6(sock6) - } -} - -impl> From<(I, u16)> for SocketAddr { - /// Converts a tuple struct (Into<[`IpAddr`]>, `u16`) into a [`SocketAddr`]. - /// - /// This conversion creates a [`SocketAddr::V4`] for an [`IpAddr::V4`] - /// and creates a [`SocketAddr::V6`] for an [`IpAddr::V6`]. - /// - /// `u16` is treated as port of the newly created [`SocketAddr`]. - fn from(pieces: (I, u16)) -> SocketAddr { - SocketAddr::new(pieces.0.into(), pieces.1) - } -} - -impl fmt::Display for SocketAddr { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self { - SocketAddr::V4(ref a) => a.fmt(f), - SocketAddr::V6(ref a) => a.fmt(f), - } - } -} - -impl fmt::Debug for SocketAddr { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(self, fmt) - } -} - -impl fmt::Display for SocketAddrV4 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - // If there are no alignment requirements, write the socket address directly to `f`. - // Otherwise, write it to a local buffer and then use `f.pad`. - if f.precision().is_none() && f.width().is_none() { - write!(f, "{}:{}", self.ip(), self.port()) - } else { - const LONGEST_IPV4_SOCKET_ADDR: &str = "255.255.255.255:65536"; - - let mut buf = DisplayBuffer::<{ LONGEST_IPV4_SOCKET_ADDR.len() }>::new(); - // Buffer is long enough for the longest possible IPv4 socket address, so this should never fail. - write!(buf, "{}:{}", self.ip(), self.port()).unwrap(); - - f.pad(buf.as_str()) - } - } -} - -impl fmt::Debug for SocketAddrV4 { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(self, fmt) - } -} - -impl fmt::Display for SocketAddrV6 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - // If there are no alignment requirements, write the socket address directly to `f`. - // Otherwise, write it to a local buffer and then use `f.pad`. - if f.precision().is_none() && f.width().is_none() { - match self.scope_id() { - 0 => write!(f, "[{}]:{}", self.ip(), self.port()), - scope_id => write!(f, "[{}%{}]:{}", self.ip(), scope_id, self.port()), - } - } else { - const LONGEST_IPV6_SOCKET_ADDR: &str = - "[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff%4294967296]:65536"; - - let mut buf = DisplayBuffer::<{ LONGEST_IPV6_SOCKET_ADDR.len() }>::new(); - match self.scope_id() { - 0 => write!(buf, "[{}]:{}", self.ip(), self.port()), - scope_id => write!(buf, "[{}%{}]:{}", self.ip(), scope_id, self.port()), - } - // Buffer is long enough for the longest possible IPv6 socket address, so this should never fail. - .unwrap(); - - f.pad(buf.as_str()) - } - } -} - -impl fmt::Debug for SocketAddrV6 { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(self, fmt) - } -} - -impl PartialOrd for SocketAddrV4 { - fn partial_cmp(&self, other: &SocketAddrV4) -> Option { - Some(self.cmp(other)) - } -} - -impl PartialOrd for SocketAddrV6 { - fn partial_cmp(&self, other: &SocketAddrV6) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for SocketAddrV4 { - fn cmp(&self, other: &SocketAddrV4) -> Ordering { - self.ip().cmp(other.ip()).then(self.port().cmp(&other.port())) - } -} - -impl Ord for SocketAddrV6 { - fn cmp(&self, other: &SocketAddrV6) -> Ordering { - self.ip().cmp(other.ip()).then(self.port().cmp(&other.port())) - } -} - -impl hash::Hash for SocketAddrV4 { - fn hash(&self, s: &mut H) { - (self.port, self.ip).hash(s) - } -} - -impl hash::Hash for SocketAddrV6 { - fn hash(&self, s: &mut H) { - (self.port, &self.ip, self.flowinfo, self.scope_id).hash(s) - } -} - /// A trait for objects which can be converted or resolved to one or more /// [`SocketAddr`] values. /// diff --git a/sgx_tstd/src/net/socket_addr/tests.rs b/sgx_tstd/src/net/socket_addr/tests.rs index ab7af29f5..b8e5afe05 100644 --- a/sgx_tstd/src/net/socket_addr/tests.rs +++ b/sgx_tstd/src/net/socket_addr/tests.rs @@ -56,7 +56,7 @@ fn to_socket_addr_str() { fn to_socket_addr_string() { let a = sa4(Ipv4Addr::new(77, 88, 21, 11), 24352); assert_eq!(Ok(vec![a]), tsa(&*format!("{}:{}", "77.88.21.11", "24352"))); - assert_eq!(Ok(vec![a]), tsa(&format!("{}:{}", "77.88.21.11", "24352"))); + assert_eq!(Ok(vec![a]), tsa(format!("{}:{}", "77.88.21.11", "24352"))); assert_eq!(Ok(vec![a]), tsa(format!("{}:{}", "77.88.21.11", "24352"))); let s = format!("{}:{}", "77.88.21.11", "24352"); @@ -77,11 +77,11 @@ fn ipv4_socket_addr_to_string() { // Test padding. assert_eq!( - &format!("{:16}", SocketAddrV4::new(Ipv4Addr::new(1, 1, 1, 1), 53)), + format!("{:16}", SocketAddrV4::new(Ipv4Addr::new(1, 1, 1, 1), 53)), "1.1.1.1:53 " ); assert_eq!( - &format!("{:>16}", SocketAddrV4::new(Ipv4Addr::new(1, 1, 1, 1), 53)), + format!("{:>16}", SocketAddrV4::new(Ipv4Addr::new(1, 1, 1, 1), 53)), " 1.1.1.1:53" ); } @@ -98,7 +98,7 @@ fn ipv6_socket_addr_to_string() { // IPv4-compatible address. assert_eq!( SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0xc000, 0x280), 8080, 0, 0).to_string(), - "[::192.0.2.128]:8080" + "[::c000:280]:8080" ); // IPv6 address with no zero segments. @@ -124,11 +124,11 @@ fn ipv6_socket_addr_to_string() { // Test padding. assert_eq!( - &format!("{:22}", SocketAddrV6::new(Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8), 9, 0, 0)), + format!("{:22}", SocketAddrV6::new(Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8), 9, 0, 0)), "[1:2:3:4:5:6:7:8]:9 " ); assert_eq!( - &format!("{:>22}", SocketAddrV6::new(Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8), 9, 0, 0)), + format!("{:>22}", SocketAddrV6::new(Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8), 9, 0, 0)), " [1:2:3:4:5:6:7:8]:9" ); } diff --git a/sgx_tstd/src/net/tcp.rs b/sgx_tstd/src/net/tcp.rs index b3528bbc7..d615a2d67 100644 --- a/sgx_tstd/src/net/tcp.rs +++ b/sgx_tstd/src/net/tcp.rs @@ -21,7 +21,7 @@ mod tests; use crate::io::prelude::*; use crate::fmt; -use crate::io::{self, IoSlice, IoSliceMut}; +use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; use crate::iter::FusedIterator; use crate::net::{Shutdown, SocketAddr, ToSocketAddrs}; use crate::sys_common::net as net_imp; @@ -610,6 +610,10 @@ impl Read for TcpStream { self.0.read(buf) } + fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + self.0.read_buf(buf) + } + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.0.read_vectored(bufs) } @@ -644,6 +648,10 @@ impl Read for &TcpStream { self.0.read(buf) } + fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + self.0.read_buf(buf) + } + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.0.read_vectored(bufs) } @@ -668,12 +676,14 @@ impl Write for &TcpStream { self.0.is_write_vectored() } + #[inline] fn flush(&mut self) -> io::Result<()> { Ok(()) } } impl AsInner for TcpStream { + #[inline] fn as_inner(&self) -> &net_imp::TcpStream { &self.0 } @@ -737,6 +747,15 @@ impl TcpListener { /// ]; /// let listener = TcpListener::bind(&addrs[..]).unwrap(); /// ``` + /// + /// Creates a TCP listener bound to a port assigned by the operating system + /// at `127.0.0.1`. + /// + /// ```no_run + /// use std::net::TcpListener; + /// + /// let socket = TcpListener::bind("127.0.0.1:0").unwrap(); + /// ``` pub fn bind(addr: A) -> io::Result { super::each_addr(addr, net_imp::TcpListener::bind).map(TcpListener) } @@ -812,7 +831,7 @@ impl TcpListener { /// } /// /// fn main() -> std::io::Result<()> { - /// let listener = TcpListener::bind("127.0.0.1:80").unwrap(); + /// let listener = TcpListener::bind("127.0.0.1:80")?; /// /// for stream in listener.incoming() { /// match stream { @@ -843,7 +862,7 @@ impl TcpListener { /// use std::net::{TcpListener, TcpStream}; /// /// fn listen_on(port: u16) -> impl Iterator { - /// let listener = TcpListener::bind("127.0.0.1:80").unwrap(); + /// let listener = TcpListener::bind(("127.0.0.1", port)).unwrap(); /// listener.into_incoming() /// .filter_map(Result::ok) /* Ignore failed connections */ /// } @@ -994,6 +1013,7 @@ impl Iterator for IntoIncoming { impl FusedIterator for IntoIncoming {} impl AsInner for TcpListener { + #[inline] fn as_inner(&self) -> &net_imp::TcpListener { &self.0 } diff --git a/sgx_tstd/src/net/tcp/tests.rs b/sgx_tstd/src/net/tcp/tests.rs index 80f2d05da..9e72449ca 100644 --- a/sgx_tstd/src/net/tcp/tests.rs +++ b/sgx_tstd/src/net/tcp/tests.rs @@ -21,7 +21,8 @@ use crate::fmt; use crate::io::prelude::*; -use crate::io::{ErrorKind, IoSlice, IoSliceMut}; +use crate::io::{BorrowedBuf, ErrorKind, IoSlice, IoSliceMut}; +use crate::mem::MaybeUninit; use crate::net::test::{next_test_ip4, next_test_ip6}; use crate::net::*; use crate::sync::mpsc::channel; @@ -68,13 +69,23 @@ fn connect_error() { } } +#[test_case] +fn connect_timeout_error() { + let socket_addr = next_test_ip4(); + let result = TcpStream::connect_timeout(&socket_addr, Duration::MAX); + assert!(!matches!(result, Err(e) if e.kind() == ErrorKind::TimedOut)); + + let _listener = TcpListener::bind(socket_addr).unwrap(); + assert!(TcpStream::connect_timeout(&socket_addr, Duration::MAX).is_ok()); +} + #[test_case] fn listen_localhost() { let socket_addr = next_test_ip4(); - let listener = t!(TcpListener::bind(&socket_addr)); + let listener = t!(TcpListener::bind(socket_addr)); let _t = thread::spawn(move || { - let mut stream = t!(TcpStream::connect(&("localhost", socket_addr.port()))); + let mut stream = t!(TcpStream::connect(("localhost", socket_addr.port()))); t!(stream.write(&[144])); }); @@ -87,14 +98,14 @@ fn listen_localhost() { #[test_case] fn connect_loopback() { each_ip(&mut |addr| { - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind(addr)); let _t = thread::spawn(move || { let host = match addr { SocketAddr::V4(..) => "127.0.0.1", SocketAddr::V6(..) => "::1", }; - let mut stream = t!(TcpStream::connect(&(host, addr.port()))); + let mut stream = t!(TcpStream::connect((host, addr.port()))); t!(stream.write(&[66])); }); @@ -108,11 +119,11 @@ fn connect_loopback() { #[test_case] fn smoke_test() { each_ip(&mut |addr| { - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind(addr)); let (tx, rx) = channel(); let _t = thread::spawn(move || { - let mut stream = t!(TcpStream::connect(&addr)); + let mut stream = t!(TcpStream::connect(addr)); t!(stream.write(&[99])); tx.send(t!(stream.local_addr())).unwrap(); }); @@ -128,10 +139,10 @@ fn smoke_test() { #[test_case] fn read_eof() { each_ip(&mut |addr| { - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind(addr)); let _t = thread::spawn(move || { - let _stream = t!(TcpStream::connect(&addr)); + let _stream = t!(TcpStream::connect(addr)); // Close }); @@ -147,11 +158,11 @@ fn read_eof() { #[test_case] fn write_close() { each_ip(&mut |addr| { - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind(addr)); let (tx, rx) = channel(); let _t = thread::spawn(move || { - drop(t!(TcpStream::connect(&addr))); + drop(t!(TcpStream::connect(addr))); tx.send(()).unwrap(); }); @@ -176,11 +187,11 @@ fn write_close() { fn multiple_connect_serial() { each_ip(&mut |addr| { let max = 10; - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind(addr)); let _t = thread::spawn(move || { for _ in 0..max { - let mut stream = t!(TcpStream::connect(&addr)); + let mut stream = t!(TcpStream::connect(addr)); t!(stream.write(&[99])); } }); @@ -198,7 +209,7 @@ fn multiple_connect_serial() { fn multiple_connect_interleaved_greedy_schedule() { const MAX: usize = 10; each_ip(&mut |addr| { - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind(addr)); let _t = thread::spawn(move || { let acceptor = acceptor; @@ -222,7 +233,7 @@ fn multiple_connect_interleaved_greedy_schedule() { } let t = thread::spawn(move || { - let mut stream = t!(TcpStream::connect(&addr)); + let mut stream = t!(TcpStream::connect(addr)); // Connect again before writing connect(i + 1, addr); t!(stream.write(&[i as u8])); @@ -235,7 +246,7 @@ fn multiple_connect_interleaved_greedy_schedule() { fn multiple_connect_interleaved_lazy_schedule() { const MAX: usize = 10; each_ip(&mut |addr| { - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind(addr)); let _t = thread::spawn(move || { for stream in acceptor.incoming().take(MAX) { @@ -258,7 +269,7 @@ fn multiple_connect_interleaved_lazy_schedule() { } let t = thread::spawn(move || { - let mut stream = t!(TcpStream::connect(&addr)); + let mut stream = t!(TcpStream::connect(addr)); connect(i + 1, addr); t!(stream.write(&[99])); }); @@ -269,14 +280,14 @@ fn multiple_connect_interleaved_lazy_schedule() { #[test_case] fn socket_and_peer_name() { each_ip(&mut |addr| { - let listener = t!(TcpListener::bind(&addr)); + let listener = t!(TcpListener::bind(addr)); let so_name = t!(listener.local_addr()); assert_eq!(addr, so_name); let _t = thread::spawn(move || { t!(listener.accept()); }); - let stream = t!(TcpStream::connect(&addr)); + let stream = t!(TcpStream::connect(addr)); assert_eq!(addr, t!(stream.peer_addr())); }) } @@ -285,7 +296,7 @@ fn socket_and_peer_name() { fn partial_read() { each_ip(&mut |addr| { let (tx, rx) = channel(); - let srv = t!(TcpListener::bind(&addr)); + let srv = t!(TcpListener::bind(addr)); let _t = thread::spawn(move || { let mut cl = t!(srv.accept()).0; cl.write(&[10]).unwrap(); @@ -294,7 +305,7 @@ fn partial_read() { tx.send(()).unwrap(); }); - let mut c = t!(TcpStream::connect(&addr)); + let mut c = t!(TcpStream::connect(addr)); let mut b = [0; 10]; assert_eq!(c.read(&mut b).unwrap(), 1); t!(c.write(&[1])); @@ -302,11 +313,33 @@ fn partial_read() { }) } +#[test_case] +fn read_buf() { + each_ip(&mut |addr| { + let srv = t!(TcpListener::bind(addr)); + let t = thread::spawn(move || { + let mut s = t!(TcpStream::connect(addr)); + s.write_all(&[1, 2, 3, 4]).unwrap(); + }); + + let mut s = t!(srv.accept()).0; + let mut buf: [MaybeUninit; 128] = MaybeUninit::uninit_array(); + let mut buf = BorrowedBuf::from(buf.as_mut_slice()); + t!(s.read_buf(buf.unfilled())); + assert_eq!(buf.filled(), &[1, 2, 3, 4]); + + // TcpStream::read_buf should omit buffer initialization. + assert_eq!(buf.init_len(), 4); + + t.join().ok().expect("thread panicked"); + }) +} + #[test_case] fn read_vectored() { each_ip(&mut |addr| { - let srv = t!(TcpListener::bind(&addr)); - let mut s1 = t!(TcpStream::connect(&addr)); + let srv = t!(TcpListener::bind(addr)); + let mut s1 = t!(TcpStream::connect(addr)); let mut s2 = t!(srv.accept()).0; let len = s1.write(&[10, 11, 12]).unwrap(); @@ -330,8 +363,8 @@ fn read_vectored() { #[test_case] fn write_vectored() { each_ip(&mut |addr| { - let srv = t!(TcpListener::bind(&addr)); - let mut s1 = t!(TcpStream::connect(&addr)); + let srv = t!(TcpListener::bind(addr)); + let mut s1 = t!(TcpStream::connect(addr)); let mut s2 = t!(srv.accept()).0; let a = []; @@ -354,8 +387,8 @@ fn write_vectored() { #[test_case] fn double_bind() { each_ip(&mut |addr| { - let listener1 = t!(TcpListener::bind(&addr)); - match TcpListener::bind(&addr) { + let listener1 = t!(TcpListener::bind(addr)); + match TcpListener::bind(addr) { Ok(listener2) => panic!( "This system (perhaps due to options set by TcpListener::bind) \ permits double binding: {:?} and {:?}", @@ -378,10 +411,10 @@ fn double_bind() { #[test_case] fn tcp_clone_smoke() { each_ip(&mut |addr| { - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind(addr)); let _t = thread::spawn(move || { - let mut s = t!(TcpStream::connect(&addr)); + let mut s = t!(TcpStream::connect(addr)); let mut buf = [0, 0]; assert_eq!(s.read(&mut buf).unwrap(), 1); assert_eq!(buf[0], 1); @@ -409,12 +442,12 @@ fn tcp_clone_smoke() { #[test_case] fn tcp_clone_two_read() { each_ip(&mut |addr| { - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind(addr)); let (tx1, rx) = channel(); let tx2 = tx1.clone(); let _t = thread::spawn(move || { - let mut s = t!(TcpStream::connect(&addr)); + let mut s = t!(TcpStream::connect(addr)); t!(s.write(&[1])); rx.recv().unwrap(); t!(s.write(&[2])); @@ -443,10 +476,10 @@ fn tcp_clone_two_read() { #[test_case] fn tcp_clone_two_write() { each_ip(&mut |addr| { - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind(addr)); let _t = thread::spawn(move || { - let mut s = t!(TcpStream::connect(&addr)); + let mut s = t!(TcpStream::connect(addr)); let mut buf = [0, 1]; t!(s.read(&mut buf)); t!(s.read(&mut buf)); @@ -470,7 +503,7 @@ fn tcp_clone_two_write() { #[test_case] fn shutdown_smoke() { each_ip(&mut |addr| { - let a = t!(TcpListener::bind(&addr)); + let a = t!(TcpListener::bind(addr)); let _t = thread::spawn(move || { let mut c = t!(a.accept()).0; let mut b = [0]; @@ -478,7 +511,7 @@ fn shutdown_smoke() { t!(c.write(&[1])); }); - let mut s = t!(TcpStream::connect(&addr)); + let mut s = t!(TcpStream::connect(addr)); t!(s.shutdown(Shutdown::Write)); assert!(s.write(&[1]).is_err()); let mut b = [0, 0]; @@ -490,7 +523,7 @@ fn shutdown_smoke() { #[test_case] fn close_readwrite_smoke() { each_ip(&mut |addr| { - let a = t!(TcpListener::bind(&addr)); + let a = t!(TcpListener::bind(addr)); let (tx, rx) = channel::<()>(); let _t = thread::spawn(move || { let _s = t!(a.accept()); @@ -498,7 +531,7 @@ fn close_readwrite_smoke() { }); let mut b = [0]; - let mut s = t!(TcpStream::connect(&addr)); + let mut s = t!(TcpStream::connect(addr)); let mut s2 = t!(s.try_clone()); // closing should prevent reads/writes @@ -528,14 +561,14 @@ fn close_readwrite_smoke() { #[test_case] fn close_read_wakes_up() { each_ip(&mut |addr| { - let a = t!(TcpListener::bind(&addr)); + let a = t!(TcpListener::bind(addr)); let (tx1, rx) = channel::<()>(); let _t = thread::spawn(move || { let _s = t!(a.accept()); let _ = rx.recv(); }); - let s = t!(TcpStream::connect(&addr)); + let s = t!(TcpStream::connect(addr)); let s2 = t!(s.try_clone()); let (tx, rx) = channel(); let _t = thread::spawn(move || { @@ -556,14 +589,14 @@ fn close_read_wakes_up() { #[test_case] fn clone_while_reading() { each_ip(&mut |addr| { - let accept = t!(TcpListener::bind(&addr)); + let accept = t!(TcpListener::bind(addr)); // Enqueue a thread to write to a socket let (tx, rx) = channel(); let (txdone, rxdone) = channel(); let txdone2 = txdone.clone(); let _t = thread::spawn(move || { - let mut tcp = t!(TcpStream::connect(&addr)); + let mut tcp = t!(TcpStream::connect(addr)); rx.recv().unwrap(); t!(tcp.write(&[0])); txdone2.send(()).unwrap(); @@ -596,14 +629,14 @@ fn clone_while_reading() { #[test_case] fn clone_accept_smoke() { each_ip(&mut |addr| { - let a = t!(TcpListener::bind(&addr)); + let a = t!(TcpListener::bind(addr)); let a2 = t!(a.try_clone()); let _t = thread::spawn(move || { - let _ = TcpStream::connect(&addr); + let _ = TcpStream::connect(addr); }); let _t = thread::spawn(move || { - let _ = TcpStream::connect(&addr); + let _ = TcpStream::connect(addr); }); t!(a.accept()); @@ -614,7 +647,7 @@ fn clone_accept_smoke() { #[test_case] fn clone_accept_concurrent() { each_ip(&mut |addr| { - let a = t!(TcpListener::bind(&addr)); + let a = t!(TcpListener::bind(addr)); let a2 = t!(a.try_clone()); let (tx, rx) = channel(); @@ -628,10 +661,10 @@ fn clone_accept_concurrent() { }); let _t = thread::spawn(move || { - let _ = TcpStream::connect(&addr); + let _ = TcpStream::connect(addr); }); let _t = thread::spawn(move || { - let _ = TcpStream::connect(&addr); + let _ = TcpStream::connect(addr); }); rx.recv().unwrap(); @@ -653,7 +686,7 @@ fn debug() { let inner_name = if cfg!(windows) { "socket" } else { "fd" }; let socket_addr = next_test_ip4(); - let listener = t!(TcpListener::bind(&socket_addr)); + let listener = t!(TcpListener::bind(socket_addr)); let compare = format!( "TcpListener {{ addr: {:?}, {}: {:?} }}", render_socket_addr(&socket_addr), @@ -662,7 +695,7 @@ fn debug() { ); assert_eq!(format!("{listener:?}"), compare); - let stream = t!(TcpStream::connect(&("localhost", socket_addr.port()))); + let stream = t!(TcpStream::connect(("localhost", socket_addr.port()))); let compare = format!( "TcpStream {{ addr: {:?}, peer: {:?}, {}: {:?} }}", render_socket_addr(&stream.local_addr().unwrap()), @@ -676,9 +709,9 @@ fn debug() { #[test_case] fn timeouts() { let addr = next_test_ip4(); - let listener = t!(TcpListener::bind(&addr)); + let listener = t!(TcpListener::bind(addr)); - let stream = t!(TcpStream::connect(&("localhost", addr.port()))); + let stream = t!(TcpStream::connect(("localhost", addr.port()))); let dur = Duration::new(15410, 0); assert_eq!(None, t!(stream.read_timeout())); @@ -702,9 +735,9 @@ fn timeouts() { #[test_case] fn test_read_timeout() { let addr = next_test_ip4(); - let listener = t!(TcpListener::bind(&addr)); + let listener = t!(TcpListener::bind(addr)); - let mut stream = t!(TcpStream::connect(&("localhost", addr.port()))); + let mut stream = t!(TcpStream::connect(("localhost", addr.port()))); t!(stream.set_read_timeout(Some(Duration::from_millis(1000)))); let mut buf = [0; 10]; @@ -722,9 +755,9 @@ fn test_read_timeout() { #[test_case] fn test_read_with_timeout() { let addr = next_test_ip4(); - let listener = t!(TcpListener::bind(&addr)); + let listener = t!(TcpListener::bind(addr)); - let mut stream = t!(TcpStream::connect(&("localhost", addr.port()))); + let mut stream = t!(TcpStream::connect(("localhost", addr.port()))); t!(stream.set_read_timeout(Some(Duration::from_millis(1000)))); let mut other_end = t!(listener.accept()).0; @@ -751,8 +784,8 @@ fn test_read_with_timeout() { fn test_timeout_zero_duration() { let addr = next_test_ip4(); - let listener = t!(TcpListener::bind(&addr)); - let stream = t!(TcpStream::connect(&addr)); + let listener = t!(TcpListener::bind(addr)); + let stream = t!(TcpStream::connect(addr)); let result = stream.set_write_timeout(Some(Duration::new(0, 0))); let err = result.unwrap_err(); @@ -768,9 +801,9 @@ fn test_timeout_zero_duration() { #[test_case] fn linger() { let addr = next_test_ip4(); - let _listener = t!(TcpListener::bind(&addr)); + let _listener = t!(TcpListener::bind(addr)); - let stream = t!(TcpStream::connect(&("localhost", addr.port()))); + let stream = t!(TcpStream::connect(("localhost", addr.port()))); assert_eq!(None, t!(stream.linger())); t!(stream.set_linger(Some(Duration::from_secs(1)))); @@ -782,9 +815,9 @@ fn linger() { #[test_case] fn nodelay() { let addr = next_test_ip4(); - let _listener = t!(TcpListener::bind(&addr)); + let _listener = t!(TcpListener::bind(addr)); - let stream = t!(TcpStream::connect(&("localhost", addr.port()))); + let stream = t!(TcpStream::connect(("localhost", addr.port()))); assert_eq!(false, t!(stream.nodelay())); t!(stream.set_nodelay(true)); @@ -798,12 +831,12 @@ fn ttl() { let ttl = 100; let addr = next_test_ip4(); - let listener = t!(TcpListener::bind(&addr)); + let listener = t!(TcpListener::bind(addr)); t!(listener.set_ttl(ttl)); assert_eq!(ttl, t!(listener.ttl())); - let stream = t!(TcpStream::connect(&("localhost", addr.port()))); + let stream = t!(TcpStream::connect(("localhost", addr.port()))); t!(stream.set_ttl(ttl)); assert_eq!(ttl, t!(stream.ttl())); @@ -812,12 +845,12 @@ fn ttl() { #[test_case] fn set_nonblocking() { let addr = next_test_ip4(); - let listener = t!(TcpListener::bind(&addr)); + let listener = t!(TcpListener::bind(addr)); t!(listener.set_nonblocking(true)); t!(listener.set_nonblocking(false)); - let mut stream = t!(TcpStream::connect(&("localhost", addr.port()))); + let mut stream = t!(TcpStream::connect(("localhost", addr.port()))); t!(stream.set_nonblocking(false)); t!(stream.set_nonblocking(true)); @@ -835,14 +868,14 @@ fn peek() { each_ip(&mut |addr| { let (txdone, rxdone) = channel(); - let srv = t!(TcpListener::bind(&addr)); + let srv = t!(TcpListener::bind(addr)); let _t = thread::spawn(move || { let mut cl = t!(srv.accept()).0; cl.write(&[1, 3, 3, 7]).unwrap(); t!(rxdone.recv()); }); - let mut c = t!(TcpStream::connect(&addr)); + let mut c = t!(TcpStream::connect(addr)); let mut b = [0; 10]; for _ in 1..3 { let len = c.peek(&mut b).unwrap(); diff --git a/sgx_tstd/src/net/test.rs b/sgx_tstd/src/net/test.rs index 0ce2045a5..f34c10de8 100644 --- a/sgx_tstd/src/net/test.rs +++ b/sgx_tstd/src/net/test.rs @@ -52,11 +52,7 @@ pub fn tsa(a: A) -> Result, String> { // all want to use ports. This function figures out which workspace // it is running in and assigns a port range based on it. fn base_port() -> u16 { - let cwd = if cfg!(target_env = "sgx") { - String::from("sgx") - } else { - env::current_dir().unwrap().into_os_string().into_string().unwrap() - }; + let cwd = String::from("sgx"); let dirs = [ "32-opt", "32-nopt", diff --git a/sgx_tstd/src/net/udp.rs b/sgx_tstd/src/net/udp.rs index 4c82e97fd..54a85b259 100644 --- a/sgx_tstd/src/net/udp.rs +++ b/sgx_tstd/src/net/udp.rs @@ -106,6 +106,25 @@ impl UdpSocket { /// ]; /// let socket = UdpSocket::bind(&addrs[..]).expect("couldn't bind to address"); /// ``` + /// + /// Creates a UDP socket bound to a port assigned by the operating system + /// at `127.0.0.1`. + /// + /// ```no_run + /// use std::net::UdpSocket; + /// + /// let socket = UdpSocket::bind("127.0.0.1:0").unwrap(); + /// ``` + /// + /// Note that `bind` declares the scope of your network connection. + /// You can only receive datagrams from and send datagrams to + /// participants in that view of the network. + /// For instance, binding to a loopback address as in the example + /// above will prevent you from sending datagrams to another device + /// in your local network. + /// + /// In order to limit your view of the network the least, `bind` to + /// [`Ipv4Addr::UNSPECIFIED`] or [`Ipv6Addr::UNSPECIFIED`]. pub fn bind(addr: A) -> io::Result { super::each_addr(addr, net_imp::UdpSocket::bind).map(UdpSocket) } @@ -161,7 +180,9 @@ impl UdpSocket { } /// Sends data on the socket to the given address. On success, returns the - /// number of bytes written. + /// number of bytes written. Note that the operating system may refuse + /// buffers larger than 65507. However, partial writes are not possible + /// until buffer sizes above `i32::MAX`. /// /// Address type can be any implementor of [`ToSocketAddrs`] trait. See its /// documentation for concrete examples. @@ -633,11 +654,18 @@ impl UdpSocket { /// function of a UDP socket is not a useful thing to do: The OS will be /// unable to determine whether something is listening on the remote /// address without the application sending data. + /// + /// If your first `connect` is to a loopback address, subsequent + /// `connect`s to non-loopback addresses might fail, depending + /// on the platform. pub fn connect(&self, addr: A) -> io::Result<()> { super::each_addr(addr, |addr| self.0.connect(addr)) } /// Sends data on the socket to the remote address to which it is connected. + /// On success, returns the number of bytes written. Note that the operating + /// system may refuse buffers larger than 65507. However, partial writes are + /// not possible until buffer sizes above `i32::MAX`. /// /// [`UdpSocket::connect`] will connect this socket to a remote address. This /// method will fail if the socket is not connected. @@ -773,6 +801,7 @@ impl UdpSocket { // `AsRawSocket`/`IntoRawSocket`/`FromRawSocket` on Windows. impl AsInner for UdpSocket { + #[inline] fn as_inner(&self) -> &net_imp::UdpSocket { &self.0 } diff --git a/sgx_tstd/src/net/udp/tests.rs b/sgx_tstd/src/net/udp/tests.rs index 5c20e28a5..540d25e5d 100644 --- a/sgx_tstd/src/net/udp/tests.rs +++ b/sgx_tstd/src/net/udp/tests.rs @@ -53,13 +53,13 @@ fn socket_smoke_test_ip4() { let (tx2, rx2) = channel(); let _t = thread::spawn(move || { - let client = t!(UdpSocket::bind(&client_ip)); + let client = t!(UdpSocket::bind(client_ip)); rx1.recv().unwrap(); - t!(client.send_to(&[99], &server_ip)); + t!(client.send_to(&[99], server_ip)); tx2.send(()).unwrap(); }); - let server = t!(UdpSocket::bind(&server_ip)); + let server = t!(UdpSocket::bind(server_ip)); tx1.send(()).unwrap(); let mut buf = [0]; let (nread, src) = t!(server.recv_from(&mut buf)); @@ -73,7 +73,7 @@ fn socket_smoke_test_ip4() { #[test_case] fn socket_name() { each_ip(&mut |addr, _| { - let server = t!(UdpSocket::bind(&addr)); + let server = t!(UdpSocket::bind(addr)); assert_eq!(addr, t!(server.local_addr())); }) } @@ -81,9 +81,9 @@ fn socket_name() { #[test_case] fn socket_peer() { each_ip(&mut |addr1, addr2| { - let server = t!(UdpSocket::bind(&addr1)); + let server = t!(UdpSocket::bind(addr1)); assert_eq!(server.peer_addr().unwrap_err().kind(), ErrorKind::NotConnected); - t!(server.connect(&addr2)); + t!(server.connect(addr2)); assert_eq!(addr2, t!(server.peer_addr())); }) } @@ -91,14 +91,14 @@ fn socket_peer() { #[test_case] fn udp_clone_smoke() { each_ip(&mut |addr1, addr2| { - let sock1 = t!(UdpSocket::bind(&addr1)); - let sock2 = t!(UdpSocket::bind(&addr2)); + let sock1 = t!(UdpSocket::bind(addr1)); + let sock2 = t!(UdpSocket::bind(addr2)); let _t = thread::spawn(move || { let mut buf = [0, 0]; assert_eq!(sock2.recv_from(&mut buf).unwrap(), (1, addr1)); assert_eq!(buf[0], 1); - t!(sock2.send_to(&[2], &addr1)); + t!(sock2.send_to(&[2], addr1)); }); let sock3 = t!(sock1.try_clone()); @@ -107,7 +107,7 @@ fn udp_clone_smoke() { let (tx2, rx2) = channel(); let _t = thread::spawn(move || { rx1.recv().unwrap(); - t!(sock3.send_to(&[1], &addr2)); + t!(sock3.send_to(&[1], addr2)); tx2.send(()).unwrap(); }); tx1.send(()).unwrap(); @@ -120,15 +120,15 @@ fn udp_clone_smoke() { #[test_case] fn udp_clone_two_read() { each_ip(&mut |addr1, addr2| { - let sock1 = t!(UdpSocket::bind(&addr1)); - let sock2 = t!(UdpSocket::bind(&addr2)); + let sock1 = t!(UdpSocket::bind(addr1)); + let sock2 = t!(UdpSocket::bind(addr2)); let (tx1, rx) = channel(); let tx2 = tx1.clone(); let _t = thread::spawn(move || { - t!(sock2.send_to(&[1], &addr1)); + t!(sock2.send_to(&[1], addr1)); rx.recv().unwrap(); - t!(sock2.send_to(&[2], &addr1)); + t!(sock2.send_to(&[2], addr1)); rx.recv().unwrap(); }); @@ -152,8 +152,8 @@ fn udp_clone_two_read() { #[test_case] fn udp_clone_two_write() { each_ip(&mut |addr1, addr2| { - let sock1 = t!(UdpSocket::bind(&addr1)); - let sock2 = t!(UdpSocket::bind(&addr2)); + let sock1 = t!(UdpSocket::bind(addr1)); + let sock2 = t!(UdpSocket::bind(addr2)); let (tx, rx) = channel(); let (serv_tx, serv_rx) = channel(); @@ -170,12 +170,12 @@ fn udp_clone_two_write() { let (done, rx) = channel(); let tx2 = tx.clone(); let _t = thread::spawn(move || { - if sock3.send_to(&[1], &addr2).is_ok() { + if sock3.send_to(&[1], addr2).is_ok() { let _ = tx2.send(()); } done.send(()).unwrap(); }); - if sock1.send_to(&[2], &addr2).is_ok() { + if sock1.send_to(&[2], addr2).is_ok() { let _ = tx.send(()); } drop(tx); @@ -190,7 +190,7 @@ fn debug() { let name = if cfg!(windows) { "socket" } else { "fd" }; let socket_addr = next_test_ip4(); - let udpsock = t!(UdpSocket::bind(&socket_addr)); + let udpsock = t!(UdpSocket::bind(socket_addr)); let udpsock_inner = udpsock.0.socket().as_raw(); let compare = format!("UdpSocket {{ addr: {socket_addr:?}, {name}: {udpsock_inner:?} }}"); assert_eq!(format!("{udpsock:?}"), compare); @@ -200,7 +200,7 @@ fn debug() { fn timeouts() { let addr = next_test_ip4(); - let stream = t!(UdpSocket::bind(&addr)); + let stream = t!(UdpSocket::bind(addr)); let dur = Duration::new(15410, 0); assert_eq!(None, t!(stream.read_timeout())); @@ -224,7 +224,7 @@ fn timeouts() { fn test_read_timeout() { let addr = next_test_ip4(); - let stream = t!(UdpSocket::bind(&addr)); + let stream = t!(UdpSocket::bind(addr)); t!(stream.set_read_timeout(Some(Duration::from_millis(1000)))); let mut buf = [0; 10]; @@ -248,10 +248,10 @@ fn test_read_timeout() { fn test_read_with_timeout() { let addr = next_test_ip4(); - let stream = t!(UdpSocket::bind(&addr)); + let stream = t!(UdpSocket::bind(addr)); t!(stream.set_read_timeout(Some(Duration::from_millis(1000)))); - t!(stream.send_to(b"hello world", &addr)); + t!(stream.send_to(b"hello world", addr)); let mut buf = [0; 11]; t!(stream.recv_from(&mut buf)); @@ -278,7 +278,7 @@ fn test_read_with_timeout() { fn test_timeout_zero_duration() { let addr = next_test_ip4(); - let socket = t!(UdpSocket::bind(&addr)); + let socket = t!(UdpSocket::bind(addr)); let result = socket.set_write_timeout(Some(Duration::new(0, 0))); let err = result.unwrap_err(); @@ -293,7 +293,7 @@ fn test_timeout_zero_duration() { fn connect_send_recv() { let addr = next_test_ip4(); - let socket = t!(UdpSocket::bind(&addr)); + let socket = t!(UdpSocket::bind(addr)); t!(socket.connect(addr)); t!(socket.send(b"hello world")); @@ -306,7 +306,7 @@ fn connect_send_recv() { #[test_case] fn connect_send_peek_recv() { each_ip(&mut |addr, _| { - let socket = t!(UdpSocket::bind(&addr)); + let socket = t!(UdpSocket::bind(addr)); t!(socket.connect(addr)); t!(socket.send(b"hello world")); @@ -328,8 +328,8 @@ fn connect_send_peek_recv() { #[test_case] fn peek_from() { each_ip(&mut |addr, _| { - let socket = t!(UdpSocket::bind(&addr)); - t!(socket.send_to(b"hello world", &addr)); + let socket = t!(UdpSocket::bind(addr)); + t!(socket.send_to(b"hello world", addr)); for _ in 1..3 { let mut buf = [0; 11]; @@ -351,7 +351,7 @@ fn ttl() { let addr = next_test_ip4(); - let stream = t!(UdpSocket::bind(&addr)); + let stream = t!(UdpSocket::bind(addr)); t!(stream.set_ttl(ttl)); assert_eq!(ttl, t!(stream.ttl())); @@ -360,7 +360,7 @@ fn ttl() { #[test_case] fn set_nonblocking() { each_ip(&mut |addr, _| { - let socket = t!(UdpSocket::bind(&addr)); + let socket = t!(UdpSocket::bind(addr)); t!(socket.set_nonblocking(true)); t!(socket.set_nonblocking(false)); diff --git a/sgx_tstd/src/os/fd/owned.rs b/sgx_tstd/src/os/fd/owned.rs index 57486321c..9809485f2 100644 --- a/sgx_tstd/src/os/fd/owned.rs +++ b/sgx_tstd/src/os/fd/owned.rs @@ -29,8 +29,9 @@ use crate::sys_common::{AsInner, FromInner, IntoInner}; /// A borrowed file descriptor. /// -/// This has a lifetime parameter to tie it to the lifetime of something that -/// owns the file descriptor. +/// This has a lifetime parameter to tie it to the lifetime of something that owns the file +/// descriptor. For the duration of that lifetime, it is guaranteed that nobody will close the file +/// descriptor. /// /// This uses `repr(transparent)` and has the representation of a host file /// descriptor, so it can be used in FFI in places where a file descriptor is @@ -54,7 +55,8 @@ pub struct BorrowedFd<'fd> { /// An owned file descriptor. /// -/// This closes the file descriptor on drop. +/// This closes the file descriptor on drop. It is guaranteed that nobody else will close the file +/// descriptor. /// /// This uses `repr(transparent)` and has the representation of a host file /// descriptor, so it can be used in FFI in places where a file descriptor is @@ -137,7 +139,9 @@ impl FromRawFd for OwnedFd { /// # Safety /// /// The resource pointed to by `fd` must be open and suitable for assuming - /// ownership. The resource must not require any cleanup other than `close`. + /// [ownership][io-safety]. The resource must not require any cleanup other than `close`. + /// + /// [io-safety]: io#io-safety #[inline] unsafe fn from_raw_fd(fd: RawFd) -> Self { assert_ne!(fd, u32::MAX as RawFd); @@ -236,7 +240,7 @@ impl AsFd for OwnedFd { #[inline] fn as_fd(&self) -> BorrowedFd<'_> { // Safety: `OwnedFd` and `BorrowedFd` have the same validity - // invariants, and the `BorrowdFd` is bounded by the lifetime + // invariants, and the `BorrowedFd` is bounded by the lifetime // of `&self`. unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } } @@ -366,6 +370,13 @@ impl AsFd for crate::sync::Arc { } } +impl AsFd for crate::rc::Rc { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + (**self).as_fd() + } +} + impl AsFd for Box { #[inline] fn as_fd(&self) -> BorrowedFd<'_> { diff --git a/sgx_tstd/src/os/fd/raw.rs b/sgx_tstd/src/os/fd/raw.rs index 8acf6ed22..baa8696c1 100644 --- a/sgx_tstd/src/os/fd/raw.rs +++ b/sgx_tstd/src/os/fd/raw.rs @@ -81,7 +81,10 @@ pub trait FromRawFd { /// /// # Safety /// - /// The `fd` passed in must be a valid and open file descriptor. + /// The `fd` passed in must be an [owned file descriptor][io-safety]; + /// in particular, it must be open. + /// + /// [io-safety]: io#io-safety /// /// # Example /// @@ -244,6 +247,13 @@ impl AsRawFd for crate::sync::Arc { } } +impl AsRawFd for crate::rc::Rc { + #[inline] + fn as_raw_fd(&self) -> RawFd { + (**self).as_raw_fd() + } +} + impl AsRawFd for Box { #[inline] fn as_raw_fd(&self) -> RawFd { diff --git a/sgx_tstd/src/os/fd/tests.rs b/sgx_tstd/src/os/fd/tests.rs index dbc06e338..7b4d1d536 100644 --- a/sgx_tstd/src/os/fd/tests.rs +++ b/sgx_tstd/src/os/fd/tests.rs @@ -54,7 +54,7 @@ fn test_niche_optimizations() { unsafe { assert_eq!(OwnedFd::from_raw_fd(RawFd::MIN).into_raw_fd(), RawFd::MIN); assert_eq!(OwnedFd::from_raw_fd(RawFd::MAX).into_raw_fd(), RawFd::MAX); - assert_eq!(Some(OwnedFd::from_raw_fd(RawFd::MIN)).unwrap().into_raw_fd(), RawFd::MIN); - assert_eq!(Some(OwnedFd::from_raw_fd(RawFd::MAX)).unwrap().into_raw_fd(), RawFd::MAX); + assert_eq!(OwnedFd::from_raw_fd(RawFd::MIN).into_raw_fd(), RawFd::MIN); + assert_eq!(OwnedFd::from_raw_fd(RawFd::MAX).into_raw_fd(), RawFd::MAX); } } diff --git a/sgx_tstd/src/os/linux/fs.rs b/sgx_tstd/src/os/linux/fs.rs index 325d324dd..7f2874eb2 100644 --- a/sgx_tstd/src/os/linux/fs.rs +++ b/sgx_tstd/src/os/linux/fs.rs @@ -326,7 +326,9 @@ pub trait MetadataExt { impl MetadataExt for Metadata { #[allow(deprecated)] fn as_raw_stat(&self) -> &raw::stat { - unsafe { &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat) } + unsafe { + &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat) + } } fn st_dev(&self) -> u64 { self.as_inner().as_inner().st_dev @@ -353,19 +355,22 @@ impl MetadataExt for Metadata { self.as_inner().as_inner().st_size as u64 } fn st_atime(&self) -> i64 { - self.as_inner().as_inner().st_atime + let file_attr = self.as_inner(); + file_attr.as_inner().st_atime } fn st_atime_nsec(&self) -> i64 { self.as_inner().as_inner().st_atime_nsec } fn st_mtime(&self) -> i64 { - self.as_inner().as_inner().st_mtime + let file_attr = self.as_inner(); + file_attr.as_inner().st_mtime } fn st_mtime_nsec(&self) -> i64 { self.as_inner().as_inner().st_mtime_nsec } fn st_ctime(&self) -> i64 { - self.as_inner().as_inner().st_ctime + let file_attr = self.as_inner(); + file_attr.as_inner().st_ctime } fn st_ctime_nsec(&self) -> i64 { self.as_inner().as_inner().st_ctime_nsec diff --git a/sgx_tstd/src/os/linux/net.rs b/sgx_tstd/src/os/linux/net.rs index 69a0437a2..710cdac56 100644 --- a/sgx_tstd/src/os/linux/net.rs +++ b/sgx_tstd/src/os/linux/net.rs @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License.. -//! Linux and Android-specific definitions for socket options. +//! Linux-specific networking functionality. -pub use crate::os::net::tcp::TcpStreamExt; +pub use crate::os::net::linux_ext::addr::SocketAddrExt; +pub use crate::os::net::linux_ext::tcp::TcpStreamExt; diff --git a/sgx_tstd/src/os/linux/process.rs b/sgx_tstd/src/os/linux/process.rs index 5756578d6..305aeb8b4 100644 --- a/sgx_tstd/src/os/linux/process.rs +++ b/sgx_tstd/src/os/linux/process.rs @@ -64,6 +64,7 @@ pub struct PidFd { } impl AsInner for PidFd { + #[inline] fn as_inner(&self) -> &FileDesc { &self.inner } @@ -82,6 +83,7 @@ impl IntoInner for PidFd { } impl AsRawFd for PidFd { + #[inline] fn as_raw_fd(&self) -> RawFd { self.as_inner().as_raw_fd() } diff --git a/sgx_tstd/src/os/net/linux_ext/addr.rs b/sgx_tstd/src/os/net/linux_ext/addr.rs new file mode 100644 index 000000000..a2515a50c --- /dev/null +++ b/sgx_tstd/src/os/net/linux_ext/addr.rs @@ -0,0 +1,78 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +//! Linux and Android-specific extensions to socket addresses. + +use crate::os::unix::net::SocketAddr; +use crate::sealed::Sealed; + +/// Platform-specific extensions to [`SocketAddr`]. +pub trait SocketAddrExt: Sealed { + /// Creates a Unix socket address in the abstract namespace. + /// + /// The abstract namespace is a Linux-specific extension that allows Unix + /// sockets to be bound without creating an entry in the filesystem. + /// Abstract sockets are unaffected by filesystem layout or permissions, + /// and no cleanup is necessary when the socket is closed. + /// + /// An abstract socket address name may contain any bytes, including zero. + /// + /// # Errors + /// + /// Returns an error if the name is longer than `SUN_LEN - 1`. + /// + /// # Examples + /// + /// ```no_run + /// use std::os::unix::net::{UnixListener, SocketAddr}; + /// use std::os::linux::net::SocketAddrExt; + /// + /// fn main() -> std::io::Result<()> { + /// let addr = SocketAddr::from_abstract_name(b"hidden")?; + /// let listener = match UnixListener::bind_addr(&addr) { + /// Ok(sock) => sock, + /// Err(err) => { + /// println!("Couldn't bind: {err:?}"); + /// return Err(err); + /// } + /// }; + /// Ok(()) + /// } + /// ``` + fn from_abstract_name(name: N) -> crate::io::Result + where + N: AsRef<[u8]>; + + /// Returns the contents of this address if it is in the abstract namespace. + /// + /// # Examples + /// + /// ```no_run + /// use std::os::unix::net::{UnixListener, SocketAddr}; + /// use std::os::linux::net::SocketAddrExt; + /// + /// fn main() -> std::io::Result<()> { + /// let name = b"hidden"; + /// let name_addr = SocketAddr::from_abstract_name(name)?; + /// let socket = UnixListener::bind_addr(&name_addr)?; + /// let local_addr = socket.local_addr().expect("Couldn't get local address"); + /// assert_eq!(local_addr.as_abstract_name(), Some(&name[..])); + /// Ok(()) + /// } + /// ``` + fn as_abstract_name(&self) -> Option<&[u8]>; +} diff --git a/sgx_tstd/src/sync/mpsc/cache_aligned.rs b/sgx_tstd/src/os/net/linux_ext/mod.rs similarity index 61% rename from sgx_tstd/src/sync/mpsc/cache_aligned.rs rename to sgx_tstd/src/os/net/linux_ext/mod.rs index ca1583e0a..43176af03 100644 --- a/sgx_tstd/src/sync/mpsc/cache_aligned.rs +++ b/sgx_tstd/src/os/net/linux_ext/mod.rs @@ -15,27 +15,9 @@ // specific language governing permissions and limitations // under the License.. -use crate::ops::{Deref, DerefMut}; +//! Linux and Android-specific networking functionality. -#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[repr(align(64))] -pub(super) struct CacheAligned(pub T); - -impl Deref for CacheAligned { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl DerefMut for CacheAligned { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -impl CacheAligned { - pub(super) fn new(t: T) -> Self { - CacheAligned(t) - } -} +pub(crate) mod addr; +pub(crate) mod tcp; +#[cfg(feature = "unit_test")] +mod tests; diff --git a/sgx_tstd/src/os/net/tcp.rs b/sgx_tstd/src/os/net/linux_ext/tcp.rs similarity index 100% rename from sgx_tstd/src/os/net/tcp.rs rename to sgx_tstd/src/os/net/linux_ext/tcp.rs diff --git a/sgx_tstd/src/os/net/tests.rs b/sgx_tstd/src/os/net/linux_ext/tests.rs similarity index 89% rename from sgx_tstd/src/os/net/tests.rs rename to sgx_tstd/src/os/net/linux_ext/tests.rs index 9dc437020..6340e10c9 100644 --- a/sgx_tstd/src/os/net/tests.rs +++ b/sgx_tstd/src/os/net/linux_ext/tests.rs @@ -21,7 +21,7 @@ use sgx_test_utils::test_case; fn quickack() { use crate::{ net::{test::next_test_ip4, TcpListener, TcpStream}, - os::net::tcp::TcpStreamExt, + os::net::linux_ext::tcp::TcpStreamExt, }; macro_rules! t { @@ -34,9 +34,9 @@ fn quickack() { } let addr = next_test_ip4(); - let _listener = t!(TcpListener::bind(&addr)); + let _listener = t!(TcpListener::bind(addr)); - let stream = t!(TcpStream::connect(&("localhost", addr.port()))); + let stream = t!(TcpStream::connect(("localhost", addr.port()))); t!(stream.set_quickack(false)); assert!(!t!(stream.quickack())); diff --git a/sgx_tstd/src/os/net/mod.rs b/sgx_tstd/src/os/net/mod.rs index 20c9677c4..bf6c909dd 100644 --- a/sgx_tstd/src/os/net/mod.rs +++ b/sgx_tstd/src/os/net/mod.rs @@ -15,9 +15,4 @@ // specific language governing permissions and limitations // under the License.. - -//! Linux and Android-specific definitions for socket options. - -pub mod tcp; -#[cfg(feature = "unit_test")] -mod tests; +pub(super) mod linux_ext; diff --git a/sgx_tstd/src/os/raw/mod.rs b/sgx_tstd/src/os/raw/mod.rs index 700dfd944..ac98a34a5 100644 --- a/sgx_tstd/src/os/raw/mod.rs +++ b/sgx_tstd/src/os/raw/mod.rs @@ -22,10 +22,6 @@ mod tests; macro_rules! alias_core_ffi { ($($t:ident)*) => {$( - // Make this type alias appear cfg-dependent so that Clippy does not suggest - // replacing expressions like `0 as c_char` with `0_i8`/`0_u8`. This #[cfg(all())] can be - // removed after the false positive in https://github.com/rust-lang/rust-clippy/issues/8093 - // is fixed. #[cfg(all())] pub type $t = core::ffi::$t; )*} diff --git a/sgx_tstd/src/os/unix/fs.rs b/sgx_tstd/src/os/unix/fs.rs index e3f7896b7..a6c856711 100644 --- a/sgx_tstd/src/os/unix/fs.rs +++ b/sgx_tstd/src/os/unix/fs.rs @@ -71,6 +71,15 @@ pub trait FileExt { /// ``` fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result; + /// Like `read_at`, except that it reads into a slice of buffers. + /// + /// Data is copied to fill each buffer in order, with the final buffer + /// written to possibly being only partially filled. This method must behave + /// equivalently to a single call to read with concatenated buffers. + fn read_vectored_at(&self, bufs: &mut [io::IoSliceMut<'_>], offset: u64) -> io::Result { + io::default_read_vectored(|b| self.read_at(b, offset), bufs) + } + /// Reads the exact number of byte required to fill `buf` from the given offset. /// /// The offset is relative to the start of the file and thus independent @@ -125,7 +134,7 @@ pub trait FileExt { buf = &mut tmp[n..]; offset += n as u64; } - Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {} + Err(ref e) if e.is_interrupted() => {} Err(e) => return Err(e), } } @@ -151,7 +160,36 @@ pub trait FileExt { /// Note that similar to [`File::write`], it is not an error to return a /// short write. /// + /// # Bug + /// On some systems, `write_at` utilises [`pwrite64`] to write to files. + /// However, this syscall has a [bug] where files opened with the `O_APPEND` + /// flag fail to respect the offset parameter, always appending to the end + /// of the file instead. + /// + /// It is possible to inadvertently set this flag, like in the example below. + /// Therefore, it is important to be vigilant while changing options to mitigate + /// unexpected behaviour. + /// + /// ```no_run + /// use std::fs::File; + /// use std::io; + /// use std::os::unix::prelude::FileExt; + /// + /// fn main() -> io::Result<()> { + /// // Open a file with the append option (sets the `O_APPEND` flag) + /// let file = File::options().append(true).open("foo.txt")?; + /// + /// // We attempt to write at offset 10; instead appended to EOF + /// file.write_at(b"sushi", 10)?; + /// + /// // foo.txt is 5 bytes long instead of 15 + /// Ok(()) + /// } + /// ``` + /// /// [`File::write`]: fs::File::write + /// [`pwrite64`]: https://man7.org/linux/man-pages/man2/pwrite.2.html + /// [bug]: https://man7.org/linux/man-pages/man2/pwrite.2.html#BUGS /// /// # Examples /// @@ -161,7 +199,7 @@ pub trait FileExt { /// use std::os::unix::prelude::FileExt; /// /// fn main() -> io::Result<()> { - /// let file = File::open("foo.txt")?; + /// let file = File::create("foo.txt")?; /// /// // We now write at the offset 10. /// file.write_at(b"sushi", 10)?; @@ -170,6 +208,15 @@ pub trait FileExt { /// ``` fn write_at(&self, buf: &[u8], offset: u64) -> io::Result; + /// Like `write_at`, except that it writes from a slice of buffers. + /// + /// Data is copied from each buffer in order, with the final buffer read + /// from possibly being only partially consumed. This method must behave as + /// a call to `write_at` with the buffers concatenated would. + fn write_vectored_at(&self, bufs: &[io::IoSlice<'_>], offset: u64) -> io::Result { + io::default_write_vectored(|b| self.write_at(b, offset), bufs) + } + /// Attempts to write an entire buffer starting from a given offset. /// /// The offset is relative to the start of the file and thus independent @@ -219,7 +266,7 @@ pub trait FileExt { buf = &buf[n..]; offset += n as u64 } - Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {} + Err(ref e) if e.is_interrupted() => {} Err(e) => return Err(e), } } @@ -231,9 +278,15 @@ impl FileExt for fs::File { fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { self.as_inner().read_at(buf, offset) } + fn read_vectored_at(&self, bufs: &mut [io::IoSliceMut<'_>], offset: u64) -> io::Result { + self.as_inner().read_vectored_at(bufs, offset) + } fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { self.as_inner().write_at(buf, offset) } + fn write_vectored_at(&self, bufs: &[io::IoSlice<'_>], offset: u64) -> io::Result { + self.as_inner().write_vectored_at(bufs, offset) + } } /// Unix-specific extensions to [`fs::Permissions`]. @@ -344,7 +397,7 @@ pub trait OpenOptionsExt { /// /// ```no_run /// # #![feature(rustc_private)] - /// extern crate libc; + /// use libc; /// use std::fs::OpenOptions; /// use std::os::unix::fs::OpenOptionsExt; /// @@ -904,7 +957,6 @@ impl DirBuilderExt for fs::DirBuilder { /// # Examples /// /// ```no_run -/// #![feature(unix_chown)] /// use std::os::unix::fs; /// /// fn main() -> std::io::Result<()> { @@ -923,7 +975,6 @@ pub fn chown>(dir: P, uid: Option, gid: Option) -> io:: /// # Examples /// /// ```no_run -/// #![feature(unix_chown)] /// use std::os::unix::fs; /// /// fn main() -> std::io::Result<()> { @@ -944,7 +995,6 @@ pub fn fchown(fd: F, uid: Option, gid: Option) -> io::Result< /// # Examples /// /// ```no_run -/// #![feature(unix_chown)] /// use std::os::unix::fs; /// /// fn main() -> std::io::Result<()> { diff --git a/sgx_tstd/src/os/unix/fs/tests.rs b/sgx_tstd/src/os/unix/fs/tests.rs new file mode 100644 index 000000000..1607362f8 --- /dev/null +++ b/sgx_tstd/src/os/unix/fs/tests.rs @@ -0,0 +1,76 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT 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 super::*; + +use sgx_test_utils::test_case; + +#[test_case] +fn read_vectored_at() { + let msg = b"preadv is working!"; + let dir = crate::sys_common::io::test::tmpdir(); + + let filename = dir.join("preadv.txt"); + { + let mut file = fs::File::create(&filename).unwrap(); + file.write_all(msg).unwrap(); + } + { + let file = fs::File::open(&filename).unwrap(); + let mut buf0 = [0; 4]; + let mut buf1 = [0; 3]; + + let mut iovec = [io::IoSliceMut::new(&mut buf0), io::IoSliceMut::new(&mut buf1)]; + + let n = file.read_vectored_at(&mut iovec, 4).unwrap(); + + assert!(n == 4 || n == 7); + assert_eq!(&buf0, b"dv i"); + + if n == 7 { + assert_eq!(&buf1, b"s w"); + } + } +} + +#[test_case] +fn write_vectored_at() { + let msg = b"pwritev is not working!"; + let dir = crate::sys_common::io::test::tmpdir(); + + let filename = dir.join("preadv.txt"); + { + let mut file = fs::File::create(&filename).unwrap(); + file.write_all(msg).unwrap(); + } + let expected = { + let file = fs::File::options().write(true).open(&filename).unwrap(); + let buf0 = b" "; + let buf1 = b"great "; + + let iovec = [io::IoSlice::new(buf0), io::IoSlice::new(buf1)]; + + let n = file.write_vectored_at(&iovec, 11).unwrap(); + + assert!(n == 4 || n == 11); + + if n == 4 { b"pwritev is working!" } else { b"pwritev is great !" } + }; + + let content = fs::read(&filename).unwrap(); + assert_eq!(&content, expected); +} diff --git a/sgx_tstd/src/os/unix/io/mod.rs b/sgx_tstd/src/os/unix/io/mod.rs index 38939182f..b1484338b 100644 --- a/sgx_tstd/src/os/unix/io/mod.rs +++ b/sgx_tstd/src/os/unix/io/mod.rs @@ -23,7 +23,8 @@ //! //! This module provides three types for representing file descriptors, //! with different ownership properties: raw, borrowed, and owned, which are -//! analogous to types used for representing pointers: +//! analogous to types used for representing pointers. These types reflect concepts of [I/O +//! safety][io-safety] on Unix. //! //! | Type | Analogous to | //! | ------------------ | ------------ | @@ -34,8 +35,8 @@ //! Like raw pointers, `RawFd` values are primitive values. And in new code, //! they should be considered unsafe to do I/O on (analogous to dereferencing //! them). Rust did not always provide this guidance, so existing code in the -//! Rust ecosystem often doesn't mark `RawFd` usage as unsafe. Once the -//! `io_safety` feature is stable, libraries will be encouraged to migrate, +//! Rust ecosystem often doesn't mark `RawFd` usage as unsafe. +//! Libraries are encouraged to migrate, //! either by adding `unsafe` to APIs that dereference `RawFd` values, or by //! using to `BorrowedFd` or `OwnedFd` instead. //! @@ -71,6 +72,8 @@ //! Like boxes, `OwnedFd` values conceptually own the resource they point to, //! and free (close) it when they are dropped. //! +//! See the [`io` module docs][io-safety] for a general explanation of I/O safety. +//! //! ## `/proc/self/mem` and similar OS features //! //! Some platforms have special files, such as `/proc/self/mem`, which @@ -82,15 +85,16 @@ //! to be opened and read from or written must be `unsafe`. Rust's safety guarantees //! only cover what the program itself can do, and not what entities outside //! the program can do to it. `/proc/self/mem` is considered to be such an -//! external entity, along with debugging interfaces, and people with physical access to -//! the hardware. This is true even in cases where the program is controlling -//! the external entity. +//! external entity, along with `/proc/self/fd/*`, debugging interfaces, and people with physical +//! access to the hardware. This is true even in cases where the program is controlling the external +//! entity. //! //! If you desire to comprehensively prevent programs from reaching out and //! causing external entities to reach back in and violate memory safety, it's //! necessary to use *sandboxing*, which is outside the scope of `std`. //! //! [`BorrowedFd<'a>`]: crate::os::unix::io::BorrowedFd +//! [io-safety]: crate::io#io-safety pub use crate::os::fd::*; diff --git a/sgx_tstd/src/os/unix/net/addr.rs b/sgx_tstd/src/os/unix/net/addr.rs index 3be2f3694..55f0404fb 100644 --- a/sgx_tstd/src/os/unix/net/addr.rs +++ b/sgx_tstd/src/os/unix/net/addr.rs @@ -17,8 +17,10 @@ use crate::convert::{TryFrom, TryInto}; use crate::ffi::OsStr; +use crate::os::net::linux_ext; use crate::os::unix::ffi::OsStrExt; use crate::path::Path; +use crate::sealed::Sealed; use crate::sys::cvt_ocall; use crate::{fmt, io, mem, ptr}; @@ -227,28 +229,6 @@ impl SocketAddr { if let AddressKind::Pathname(path) = self.address() { Some(path) } else { None } } - /// Returns the contents of this address if it is an abstract namespace - /// without the leading null byte. - /// - /// # Examples - /// - /// ```no_run - /// #![feature(unix_socket_abstract)] - /// use std::os::unix::net::{UnixListener, SocketAddr}; - /// - /// fn main() -> std::io::Result<()> { - /// let namespace = b"hidden"; - /// let namespace_addr = SocketAddr::from_abstract_namespace(&namespace[..])?; - /// let socket = UnixListener::bind_addr(&namespace_addr)?; - /// let local_addr = socket.local_addr().expect("Couldn't get local address"); - /// assert_eq!(local_addr.as_abstract_namespace(), Some(&namespace[..])); - /// Ok(()) - /// } - /// ``` - pub fn as_abstract_namespace(&self) -> Option<&[u8]> { - if let AddressKind::Abstract(name) = self.address() { Some(name) } else { None } - } - fn address(&self) -> AddressKind<'_> { let len = self.len as usize - sun_path_offset(&self.addr); let path = unsafe { mem::transmute::<&[libc::c_char], &[u8]>(&self.addr.sun_path) }; @@ -261,59 +241,37 @@ impl SocketAddr { AddressKind::Pathname(OsStr::from_bytes(&path[..len - 1]).as_ref()) } } +} - /// Creates an abstract domain socket address from a namespace - /// - /// An abstract address does not create a file unlike traditional path-based - /// Unix sockets. The advantage of this is that the address will disappear when - /// the socket bound to it is closed, so no filesystem clean up is required. - /// - /// The leading null byte for the abstract namespace is automatically added. - /// - /// This is a Linux-specific extension. See more at [`unix(7)`]. - /// - /// [`unix(7)`]: https://man7.org/linux/man-pages/man7/unix.7.html - /// - /// # Errors - /// - /// This will return an error if the given namespace is too long - /// - /// # Examples - /// - /// ```no_run - /// #![feature(unix_socket_abstract)] - /// use std::os::unix::net::{UnixListener, SocketAddr}; - /// - /// fn main() -> std::io::Result<()> { - /// let addr = SocketAddr::from_abstract_namespace(b"hidden")?; - /// let listener = match UnixListener::bind_addr(&addr) { - /// Ok(sock) => sock, - /// Err(err) => { - /// println!("Couldn't bind: {err:?}"); - /// return Err(err); - /// } - /// }; - /// Ok(()) - /// } - /// ``` - pub fn from_abstract_namespace(namespace: &[u8]) -> io::Result { +impl Sealed for SocketAddr {} + +impl linux_ext::addr::SocketAddrExt for SocketAddr { + fn as_abstract_name(&self) -> Option<&[u8]> { + if let AddressKind::Abstract(name) = self.address() { Some(name) } else { None } + } + + fn from_abstract_name(name: N) -> crate::io::Result + where + N: AsRef<[u8]>, + { + let name = name.as_ref(); unsafe { let mut addr: libc::sockaddr_un = mem::zeroed(); addr.sun_family = libc::AF_UNIX as libc::sa_family_t; - if namespace.len() + 1 > addr.sun_path.len() { + if name.len() + 1 > addr.sun_path.len() { return Err(io::const_io_error!( io::ErrorKind::InvalidInput, - "namespace must be shorter than SUN_LEN", + "abstract socket name must be shorter than SUN_LEN", )); } crate::ptr::copy_nonoverlapping( - namespace.as_ptr(), + name.as_ptr(), addr.sun_path.as_mut_ptr().add(1) as *mut u8, - namespace.len(), + name.len(), ); - let len = (sun_path_offset(&addr) + 1 + namespace.len()) as libc::socklen_t; + let len = (sun_path_offset(&addr) + 1 + name.len()) as libc::socklen_t; SocketAddr::from_parts(addr, len) } } diff --git a/sgx_tstd/src/os/unix/net/ancillary.rs b/sgx_tstd/src/os/unix/net/ancillary.rs index 97ed37087..6a6627576 100644 --- a/sgx_tstd/src/os/unix/net/ancillary.rs +++ b/sgx_tstd/src/os/unix/net/ancillary.rs @@ -53,7 +53,7 @@ pub(super) fn recv_vectored_with_ancillary_from( msg.msg_controllen = msghdr.control_len; msg.msg_flags = msghdr.flags.bits(); - ancillary.length = msg.msg_controllen; + ancillary.length = msg.msg_controllen as usize; ancillary.truncated = msg.msg_flags & libc::MSG_CTRUNC == libc::MSG_CTRUNC; let truncated = msg.msg_flags & libc::MSG_TRUNC == libc::MSG_TRUNC; @@ -98,7 +98,8 @@ fn add_to_ancillary_data( cmsg_level: libc::c_int, cmsg_type: libc::c_int, ) -> bool { - let source_len = if let Some(source_len) = source.len().checked_mul(size_of::()) { + let cmsg_size = source.len().checked_mul(size_of::()); + let source_len = if let Some(source_len) = cmsg_size { if let Ok(source_len) = u32::try_from(source_len) { source_len } else { @@ -508,10 +509,10 @@ impl<'a> SocketAncillary<'a> { /// Add credentials to the ancillary data. /// - /// The function returns `true` if there was enough space in the buffer. - /// If there was not enough space then no credentials was appended. + /// The function returns `true` if there is enough space in the buffer. + /// If there is not enough space then no credentials will be appended. /// Technically, that means this operation adds a control message with the level `SOL_SOCKET` - /// and type `SCM_CREDENTIALS` or `SCM_CREDS`. + /// and type `SCM_CREDENTIALS`, `SCM_CREDS`, or `SCM_CREDS2`. /// pub fn add_creds(&mut self, creds: &[SocketCred]) -> bool { self.truncated = false; diff --git a/sgx_tstd/src/os/unix/net/datagram.rs b/sgx_tstd/src/os/unix/net/datagram.rs index e61e78cb9..8e9430f85 100644 --- a/sgx_tstd/src/os/unix/net/datagram.rs +++ b/sgx_tstd/src/os/unix/net/datagram.rs @@ -94,7 +94,6 @@ impl UnixDatagram { /// # Examples /// /// ```no_run - /// #![feature(unix_socket_abstract)] /// use std::os::unix::net::{UnixDatagram}; /// /// fn main() -> std::io::Result<()> { @@ -203,7 +202,6 @@ impl UnixDatagram { /// # Examples /// /// ```no_run - /// #![feature(unix_socket_abstract)] /// use std::os::unix::net::{UnixDatagram}; /// /// fn main() -> std::io::Result<()> { @@ -478,7 +476,6 @@ impl UnixDatagram { /// # Examples /// /// ```no_run - /// #![feature(unix_socket_abstract)] /// use std::os::unix::net::{UnixDatagram}; /// /// fn main() -> std::io::Result<()> { diff --git a/sgx_tstd/src/os/unix/net/listener.rs b/sgx_tstd/src/os/unix/net/listener.rs index 5b31d0a2f..4c249a635 100644 --- a/sgx_tstd/src/os/unix/net/listener.rs +++ b/sgx_tstd/src/os/unix/net/listener.rs @@ -91,9 +91,10 @@ impl UnixListener { let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; let (addr, len) = sockaddr_un(path.as_ref())?; let sock_addr = SockAddr::UN((addr, len)); + const BACKLOG: libc::c_int = 128; cvt_ocall(libc::bind(inner.as_inner().as_raw_fd(), &sock_addr))?; - cvt_ocall(libc::listen(inner.as_inner().as_raw_fd(), 128))?; + cvt_ocall(libc::listen(inner.as_inner().as_raw_fd(), BACKLOG))?; Ok(UnixListener(inner)) } @@ -106,7 +107,6 @@ impl UnixListener { /// # Examples /// /// ```no_run - /// #![feature(unix_socket_abstract)] /// use std::os::unix::net::{UnixListener}; /// /// fn main() -> std::io::Result<()> { @@ -127,8 +127,10 @@ impl UnixListener { unsafe { let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; let sock_addr = socket_addr.into(); + const BACKLOG: libc::c_int = 128; + cvt_ocall(libc::bind(inner.as_raw_fd(), &sock_addr))?; - cvt_ocall(libc::listen(inner.as_raw_fd(), 128))?; + cvt_ocall(libc::listen(inner.as_raw_fd(), BACKLOG))?; Ok(UnixListener(inner)) } } diff --git a/sgx_tstd/src/os/unix/net/tests.rs b/sgx_tstd/src/os/unix/net/tests.rs index 953eee0c4..5b2e95773 100644 --- a/sgx_tstd/src/os/unix/net/tests.rs +++ b/sgx_tstd/src/os/unix/net/tests.rs @@ -26,6 +26,8 @@ use crate::sys_common::io::test::tmpdir; use crate::thread; use crate::time::Duration; +use crate::os::linux::net::SocketAddrExt; + use sgx_test_utils::test_case; macro_rules! or_panic { @@ -279,7 +281,7 @@ fn test_unix_datagram() { let path1 = dir.path().join("sock1"); let path2 = dir.path().join("sock2"); - let sock1 = or_panic!(UnixDatagram::bind(&path1)); + let sock1 = or_panic!(UnixDatagram::bind(path1)); let sock2 = or_panic!(UnixDatagram::bind(&path2)); let msg = b"hello world"; @@ -312,8 +314,8 @@ fn test_unix_datagram_connect_to_recv_addr() { let path1 = dir.path().join("sock1"); let path2 = dir.path().join("sock2"); - let sock1 = or_panic!(UnixDatagram::bind(&path1)); - let sock2 = or_panic!(UnixDatagram::bind(&path2)); + let sock1 = or_panic!(UnixDatagram::bind(path1)); + let sock2 = or_panic!(UnixDatagram::bind(path2)); let msg = b"hello world"; let sock1_addr = or_panic!(sock1.local_addr()); @@ -403,7 +405,7 @@ fn test_unix_datagram_timeout_zero_duration() { let dir = tmpdir(); let path = dir.path().join("sock"); - let datagram = or_panic!(UnixDatagram::bind(&path)); + let datagram = or_panic!(UnixDatagram::bind(path)); let result = datagram.set_write_timeout(Some(Duration::new(0, 0))); let err = result.unwrap_err(); @@ -424,7 +426,7 @@ fn test_abstract_stream_connect() { let msg1 = b"hello"; let msg2 = b"world"; - let socket_addr = or_panic!(SocketAddr::from_abstract_namespace(b"namespace")); + let socket_addr = or_panic!(SocketAddr::from_abstract_name(b"name")); let listener = or_panic!(UnixListener::bind_addr(&socket_addr)); let thread = thread::spawn(move || { @@ -438,7 +440,7 @@ fn test_abstract_stream_connect() { let mut stream = or_panic!(UnixStream::connect_addr(&socket_addr)); let peer = or_panic!(stream.peer_addr()); - assert_eq!(peer.as_abstract_namespace().unwrap(), b"namespace"); + assert_eq!(peer.as_abstract_name().unwrap(), b"name"); or_panic!(stream.write_all(msg1)); let mut buf = vec![]; @@ -451,7 +453,7 @@ fn test_abstract_stream_connect() { #[test_case] fn test_abstract_stream_iter() { - let addr = or_panic!(SocketAddr::from_abstract_namespace(b"hidden")); + let addr = or_panic!(SocketAddr::from_abstract_name(b"hidden")); let listener = or_panic!(UnixListener::bind_addr(&addr)); let thread = thread::spawn(move || { @@ -472,13 +474,13 @@ fn test_abstract_stream_iter() { #[test_case] fn test_abstract_datagram_bind_send_to_addr() { - let addr1 = or_panic!(SocketAddr::from_abstract_namespace(b"ns1")); + let addr1 = or_panic!(SocketAddr::from_abstract_name(b"ns1")); let sock1 = or_panic!(UnixDatagram::bind_addr(&addr1)); let local = or_panic!(sock1.local_addr()); - assert_eq!(local.as_abstract_namespace().unwrap(), b"ns1"); + assert_eq!(local.as_abstract_name().unwrap(), b"ns1"); - let addr2 = or_panic!(SocketAddr::from_abstract_namespace(b"ns2")); + let addr2 = or_panic!(SocketAddr::from_abstract_name(b"ns2")); let sock2 = or_panic!(UnixDatagram::bind_addr(&addr2)); let msg = b"hello world"; @@ -487,12 +489,12 @@ fn test_abstract_datagram_bind_send_to_addr() { let (len, addr) = or_panic!(sock2.recv_from(&mut buf)); assert_eq!(msg, &buf[..]); assert_eq!(len, 11); - assert_eq!(addr.as_abstract_namespace().unwrap(), b"ns1"); + assert_eq!(addr.as_abstract_name().unwrap(), b"ns1"); } #[test_case] fn test_abstract_datagram_connect_addr() { - let addr1 = or_panic!(SocketAddr::from_abstract_namespace(b"ns3")); + let addr1 = or_panic!(SocketAddr::from_abstract_name(b"ns3")); let bsock1 = or_panic!(UnixDatagram::bind_addr(&addr1)); let sock = or_panic!(UnixDatagram::unbound()); @@ -506,7 +508,7 @@ fn test_abstract_datagram_connect_addr() { assert_eq!(addr.is_unnamed(), true); assert_eq!(msg, &buf[..]); - let addr2 = or_panic!(SocketAddr::from_abstract_namespace(b"ns4")); + let addr2 = or_panic!(SocketAddr::from_abstract_name(b"ns4")); let bsock2 = or_panic!(UnixDatagram::bind_addr(&addr2)); or_panic!(sock.connect_addr(&addr2)); @@ -515,8 +517,8 @@ fn test_abstract_datagram_connect_addr() { } #[test_case] -fn test_abstract_namespace_too_long() { - match SocketAddr::from_abstract_namespace( +fn test_abstract_name_too_long() { + match SocketAddr::from_abstract_name( b"abcdefghijklmnopqrstuvwxyzabcdefghijklmn\ opqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi\ jklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", @@ -528,11 +530,11 @@ fn test_abstract_namespace_too_long() { } #[test_case] -fn test_abstract_namespace_no_pathname_and_not_unnamed() { - let namespace = b"local"; - let addr = or_panic!(SocketAddr::from_abstract_namespace(&namespace[..])); +fn test_abstract_no_pathname_and_not_unnamed() { + let name = b"local"; + let addr = or_panic!(SocketAddr::from_abstract_name(name)); assert_eq!(addr.as_pathname(), None); - assert_eq!(addr.as_abstract_namespace(), Some(&namespace[..])); + assert_eq!(addr.as_abstract_name(), Some(&name[..])); assert_eq!(addr.is_unnamed(), false); } @@ -671,7 +673,7 @@ fn test_send_vectored_with_ancillary_to_unix_datagram() { let path1 = dir.path().join("sock1"); let path2 = dir.path().join("sock2"); - let bsock1 = or_panic!(UnixDatagram::bind(&path1)); + let bsock1 = or_panic!(UnixDatagram::bind(path1)); let bsock2 = or_panic!(UnixDatagram::bind(&path2)); or_panic!(bsock2.set_passcred(true)); @@ -725,7 +727,7 @@ fn test_send_vectored_with_ancillary_unix_datagram() { let path1 = dir.path().join("sock1"); let path2 = dir.path().join("sock2"); - let bsock1 = or_panic!(UnixDatagram::bind(&path1)); + let bsock1 = or_panic!(UnixDatagram::bind(path1)); let bsock2 = or_panic!(UnixDatagram::bind(&path2)); let buf1 = [1; 8]; diff --git a/sgx_tstd/src/os/unix/process.rs b/sgx_tstd/src/os/unix/process.rs index 28703bb3f..ddafe3b02 100644 --- a/sgx_tstd/src/os/unix/process.rs +++ b/sgx_tstd/src/os/unix/process.rs @@ -406,6 +406,19 @@ impl From for OwnedFd { } } +/// Create a `ChildStdin` from the provided `OwnedFd`. +/// +/// The provided file descriptor must point to a pipe +/// with the `CLOEXEC` flag set. +impl From for process::ChildStdin { + #[inline] + fn from(fd: OwnedFd) -> process::ChildStdin { + let fd = sys::fd::FileDesc::from_inner(fd); + let pipe = sys::unsupported::pipe::AnonPipe::from_inner(fd); + process::ChildStdin::from_inner(pipe) + } +} + impl AsFd for crate::process::ChildStdout { #[inline] fn as_fd(&self) -> BorrowedFd<'_> { @@ -420,6 +433,19 @@ impl From for OwnedFd { } } +/// Create a `ChildStdout` from the provided `OwnedFd`. +/// +/// The provided file descriptor must point to a pipe +/// with the `CLOEXEC` flag set. +impl From for process::ChildStdout { + #[inline] + fn from(fd: OwnedFd) -> process::ChildStdout { + let fd = sys::fd::FileDesc::from_inner(fd); + let pipe = sys::unsupported::pipe::AnonPipe::from_inner(fd); + process::ChildStdout::from_inner(pipe) + } +} + impl AsFd for crate::process::ChildStderr { #[inline] fn as_fd(&self) -> BorrowedFd<'_> { @@ -434,6 +460,19 @@ impl From for OwnedFd { } } +/// Create a `ChildStderr` from the provided `OwnedFd`. +/// +/// The provided file descriptor must point to a pipe +/// with the `CLOEXEC` flag set. +impl From for process::ChildStderr { + #[inline] + fn from(fd: OwnedFd) -> process::ChildStderr { + let fd = sys::fd::FileDesc::from_inner(fd); + let pipe = sys::unsupported::pipe::AnonPipe::from_inner(fd); + process::ChildStderr::from_inner(pipe) + } +} + /// Returns the OS-assigned process identifier associated with this process's parent. #[deprecated(note = "Process operations are not supported in the enclave.")] #[must_use] diff --git a/sgx_tstd/src/os/unix/ucred/tests.rs b/sgx_tstd/src/os/unix/ucred/tests.rs index 7ec2db7f9..eb8fb78c8 100644 --- a/sgx_tstd/src/os/unix/ucred/tests.rs +++ b/sgx_tstd/src/os/unix/ucred/tests.rs @@ -48,5 +48,4 @@ fn test_socket_pair_pids() { mod libc { pub use sgx_oc::ocall::{getgid, getpid, getuid}; - pub use sgx_oc::*; } diff --git a/sgx_tstd/src/panic.rs b/sgx_tstd/src/panic.rs index 13e441365..1af078cf0 100644 --- a/sgx_tstd/src/panic.rs +++ b/sgx_tstd/src/panic.rs @@ -26,7 +26,7 @@ use crate::sync::{Mutex, RwLock}; use crate::thread::Result; #[doc(hidden)] -#[allow_internal_unstable(libstd_sys_internals, const_format_args, core_panic)] +#[allow_internal_unstable(libstd_sys_internals, const_format_args, core_panic, rt)] #[cfg_attr(not(test), rustc_diagnostic_item = "std_panic_2015_macro")] #[rustc_macro_transparency = "semitransparent"] pub macro panic_2015 { @@ -34,14 +34,16 @@ pub macro panic_2015 { $crate::rt::begin_panic("explicit panic") }), ($msg:expr $(,)?) => ({ - $crate::rt::begin_panic($msg) + $crate::rt::begin_panic($msg); }), // Special-case the single-argument case for const_panic. ("{}", $arg:expr $(,)?) => ({ - $crate::rt::panic_display(&$arg) + $crate::rt::panic_display(&$arg); }), ($fmt:expr, $($arg:tt)+) => ({ - $crate::rt::panic_fmt($crate::const_format_args!($fmt, $($arg)+)) + // Semicolon to prevent temporaries inside the formatting machinery from + // being considered alive in the caller after the panic_fmt call. + $crate::rt::panic_fmt($crate::const_format_args!($fmt, $($arg)+)); }), } @@ -118,6 +120,9 @@ where /// aborting the process as well. This function *only* catches unwinding panics, /// not those that abort the process. /// +/// Note that if a custom panic hook has been set, it will be invoked before +/// the panic is caught, before unwinding. +/// /// Also note that unwinding into Rust code with a foreign exception (e.g. /// an exception thrown from C++ code) is undefined behavior. /// diff --git a/sgx_tstd/src/panicking.rs b/sgx_tstd/src/panicking.rs index 6bd89d6fb..06eb3a8c3 100644 --- a/sgx_tstd/src/panicking.rs +++ b/sgx_tstd/src/panicking.rs @@ -26,13 +26,11 @@ #[cfg(feature = "backtrace")] use crate::panic::BacktraceStyle; -use core::panic::{BoxMeUp, Location, PanicInfo}; +use core::panic::{Location, PanicInfo, PanicPayload}; use crate::any::Any; use crate::fmt; use crate::intrinsics; -#[cfg(feature = "stdio")] -use crate::io::set_output_capture; use crate::mem::{self, ManuallyDrop}; #[cfg(feature = "backtrace")] use crate::sync::atomic::{AtomicBool, Ordering}; @@ -45,7 +43,8 @@ use crate::sys_common::backtrace; use crate::sys_common::thread_info; use crate::thread; -use sgx_trts::error::abort; +#[cfg(feature = "stdio")] +use crate::io::set_output_capture; // Binary interface to the panic runtime that the standard library depends on. // @@ -62,12 +61,10 @@ extern "C" { fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static); } -#[allow(improper_ctypes)] extern "Rust" { - /// `payload` is passed through another layer of raw pointers as `&mut dyn Trait` is not - /// FFI-safe. `BoxMeUp` lazily performs allocation only when needed (this avoids allocations - /// when using the "abort" panic runtime). - fn __rust_start_panic(payload: *mut &mut dyn BoxMeUp) -> u32; + /// `PanicPayload` lazily performs allocation only when needed (this avoids + /// allocations when using the "abort" panic runtime). + fn __rust_start_panic(payload: &mut dyn PanicPayload) -> u32; } /// This function is called by the panic runtime if FFI code catches a Rust @@ -109,13 +106,16 @@ impl Default for Hook { static HOOK: RwLock = RwLock::new(Hook::Default); -/// Registers a custom panic hook, replacing any that was previously registered. +/// Registers a custom panic hook, replacing the previously registered hook. /// /// The panic hook is invoked when a thread panics, but before the panic runtime /// is invoked. As such, the hook will run with both the aborting and unwinding -/// runtimes. The default hook prints a message to standard error and generates -/// a backtrace if requested, but this behavior can be customized with the -/// `set_hook` and [`take_hook`] functions. +/// runtimes. +/// +/// The default hook, which is registered at startup, prints a message to standard error and +/// generates a backtrace if requested. This behavior can be customized using the `set_hook` function. +/// The current hook can be retrieved while reinstating the default hook with the [`take_hook`] +/// function. /// /// [`take_hook`]: ./fn.take_hook.html /// @@ -156,13 +156,14 @@ pub fn set_hook(hook: Box) + 'static + Sync + Send>) { drop(old); } -/// Unregisters the current panic hook, returning it. +/// Unregisters the current panic hook and returns it, registering the default hook +/// in its place. /// /// *See also the function [`set_hook`].* /// /// [`set_hook`]: ./fn.set_hook.html /// -/// If no custom hook is registered, the default hook will be returned. +/// If the default hook is registered it will be returned, but remain registered. /// /// # Panics /// @@ -246,12 +247,15 @@ where #[cfg(not(feature = "stdio"))] fn default_hook(_info: &PanicInfo<'_>) {} +/// The default panic handler. #[cfg(feature = "stdio")] fn default_hook(info: &PanicInfo<'_>) { // If this is a double panic, make sure that we print a backtrace // for this panic. Otherwise only print it if logging is enabled. #[cfg(feature = "backtrace")] - let backtrace = if panic_count::get_count() >= 2 { + let backtrace = if info.force_no_backtrace() { + None + } else if panic_count::get_count() >= 2 { BacktraceStyle::full() } else { crate::panic::get_backtrace_style() @@ -271,7 +275,7 @@ fn default_hook(info: &PanicInfo<'_>) { let name = thread.as_ref().and_then(|t| t.name()).unwrap_or(""); let write = |err: &mut dyn crate::io::Write| { - let _ = writeln!(err, "thread '{name}' panicked at '{msg}', {location}"); + let _ = writeln!(err, "thread '{name}' panicked at {location}:\n{msg}"); #[cfg(feature = "backtrace")] { @@ -292,7 +296,7 @@ fn default_hook(info: &PanicInfo<'_>) { ); } } - // If backtraces aren't supported, do nothing. + // If backtraces aren't supported or are forced-off, do nothing. None => {} } } @@ -311,10 +315,20 @@ pub mod panic_count { use crate::cell::Cell; use crate::sync::atomic::{AtomicUsize, Ordering}; - pub const ALWAYS_ABORT_FLAG: usize = 1 << (usize::BITS - 1); + const ALWAYS_ABORT_FLAG: usize = 1 << (usize::BITS - 1); - // Panic count for the current thread. - thread_local! { static LOCAL_PANIC_COUNT: Cell = const { Cell::new(0) } } + /// A reason for forcing an immediate abort on panic. + #[derive(Debug)] + pub enum MustAbort { + AlwaysAbort, + PanicInHook, + } + + // Panic count for the current thread and whether a panic hook is currently + // being executed.. + thread_local! { + static LOCAL_PANIC_COUNT: Cell<(usize, bool)> = const { Cell::new((0, false)) } + } // Sum of panic counts from all threads. The purpose of this is to have // a fast path in `count_is_zero` (which is used by `panicking`). In any particular @@ -323,11 +337,11 @@ pub mod panic_count { // and after increase and decrease, but not necessarily during their execution. // // Additionally, the top bit of GLOBAL_PANIC_COUNT (GLOBAL_ALWAYS_ABORT_FLAG) - // records whether panic::always_abort() has been called. This can only be + // records whether panic::always_abort() has been called. This can only be // set, never cleared. // panic::always_abort() is usually called to prevent memory allocations done by // the panic handling in the child created by `libc::fork`. - // Memory allocations performed in a child created with `libc::fork` are undefined + // Memory allocations performed in a child created with `libc::fork` are undefined // behavior in most operating systems. // Accessing LOCAL_PANIC_COUNT in a child created by `libc::fork` would lead to a memory // allocation. Only GLOBAL_PANIC_COUNT can be accessed in this situation. This is @@ -343,34 +357,39 @@ pub mod panic_count { // panicking thread consumes at least 2 bytes of address space. static GLOBAL_PANIC_COUNT: AtomicUsize = AtomicUsize::new(0); - // Return the state of the ALWAYS_ABORT_FLAG and number of panics. + // Increases the global and local panic count, and returns whether an + // immediate abort is required. // - // If ALWAYS_ABORT_FLAG is not set, the number is determined on a per-thread - // base (stored in LOCAL_PANIC_COUNT), i.e. it is the amount of recursive calls - // of the calling thread. - // If ALWAYS_ABORT_FLAG is set, the number equals the *global* number of panic - // calls. See above why LOCAL_PANIC_COUNT is not used. - pub fn increase() -> (bool, usize) { + // This also updates thread-local state to keep track of whether a panic + // hook is currently executing. + pub fn increase(run_panic_hook: bool) -> Option { let global_count = GLOBAL_PANIC_COUNT.fetch_add(1, Ordering::Relaxed); - let must_abort = global_count & ALWAYS_ABORT_FLAG != 0; - let panics = if must_abort { - global_count & !ALWAYS_ABORT_FLAG - } else { - LOCAL_PANIC_COUNT.with(|c| { - let next = c.get() + 1; - c.set(next); - next - }) - }; - (must_abort, panics) + if global_count & ALWAYS_ABORT_FLAG != 0 { + return Some(MustAbort::AlwaysAbort); + } + + LOCAL_PANIC_COUNT.with(|c| { + let (count, in_panic_hook) = c.get(); + if in_panic_hook { + return Some(MustAbort::PanicInHook); + } + c.set((count + 1, run_panic_hook)); + None + }) + } + + pub fn finished_panic_hook() { + LOCAL_PANIC_COUNT.with(|c| { + let (count, _) = c.get(); + c.set((count, false)); + }); } pub fn decrease() { GLOBAL_PANIC_COUNT.fetch_sub(1, Ordering::Relaxed); LOCAL_PANIC_COUNT.with(|c| { - let next = c.get() - 1; - c.set(next); - next + let (count, _) = c.get(); + c.set((count - 1, false)); }); } @@ -381,7 +400,7 @@ pub mod panic_count { // Disregards ALWAYS_ABORT_FLAG #[must_use] pub fn get_count() -> usize { - LOCAL_PANIC_COUNT.with(|c| c.get()) + LOCAL_PANIC_COUNT.with(|c| c.get().0) } // Disregards ALWAYS_ABORT_FLAG @@ -409,10 +428,11 @@ pub mod panic_count { #[inline(never)] #[cold] fn is_zero_slow_path() -> bool { - LOCAL_PANIC_COUNT.with(|c| c.get() == 0) + LOCAL_PANIC_COUNT.with(|c| c.get().0 == 0) } } +/// Invoke a closure, capturing the cause of an unwinding panic if one occurs. /// Invoke a closure, capturing the cause of an unwinding panic if one occurs. pub unsafe fn r#try R>(f: F) -> Result> { union Data { @@ -510,6 +530,7 @@ pub unsafe fn r#try R>(f: F) -> Result> // This function cannot be marked as `unsafe` because `intrinsics::r#try` // expects normal function pointers. #[inline] + #[rustc_nounwind] // `intrinsic::r#try` requires catch fn to be nounwind fn do_catch R, R>(data: *mut u8, payload: *mut u8) { // SAFETY: this is the responsibility of the caller, see above. // @@ -531,20 +552,19 @@ pub fn panicking() -> bool { !panic_count::count_is_zero() } -/// Entry point of panics from the libcore crate (`panic_impl` lang item). +/// Entry point of panics from the core crate (`panic_impl` lang item). #[panic_handler] pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { - struct PanicPayload<'a> { + struct FormatStringPayload<'a> { inner: &'a fmt::Arguments<'a>, string: Option, } - impl<'a> PanicPayload<'a> { - fn new(inner: &'a fmt::Arguments<'a>) -> PanicPayload<'a> { - PanicPayload { inner, string: None } + impl<'a> FormatStringPayload<'a> { + fn new(inner: &'a fmt::Arguments<'a>) -> Self { + Self { inner, string: None } } - #[allow(clippy::drop_copy)] fn fill(&mut self) -> &mut String { use crate::fmt::Write; @@ -552,13 +572,13 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { // Lazily, the first time this gets called, run the actual string formatting. self.string.get_or_insert_with(|| { let mut s = String::new(); - drop(s.write_fmt(*inner)); + let _err = s.write_fmt(*inner); s }) } } - unsafe impl<'a> BoxMeUp for PanicPayload<'a> { + unsafe impl<'a> PanicPayload for FormatStringPayload<'a> { fn take_box(&mut self) -> *mut (dyn Any + Send) { // We do two allocations here, unfortunately. But (a) they're required with the current // scheme, and (b) we don't handle panic + OOM properly anyway (see comment in @@ -572,9 +592,9 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { } } - struct StrPanicPayload(&'static str); + struct StaticStrPayload(&'static str); - unsafe impl BoxMeUp for StrPanicPayload { + unsafe impl PanicPayload for StaticStrPayload { fn take_box(&mut self) -> *mut (dyn Any + Send) { Box::into_raw(Box::new(self.0)) } @@ -589,14 +609,23 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { #[cfg(feature = "backtrace")] { crate::sys_common::backtrace::__rust_end_short_backtrace(move || { + // FIXME: can we just pass `info` along rather than taking it apart here, only to have + // `rust_panic_with_hook` construct a new `PanicInfo`? if let Some(msg) = msg.as_str() { - rust_panic_with_hook(&mut StrPanicPayload(msg), info.message(), loc, info.can_unwind()); + rust_panic_with_hook( + &mut StaticStrPayload(msg), + info.message(), + loc, + info.can_unwind(), + info.force_no_backtrace(), + ); } else { rust_panic_with_hook( - &mut PanicPayload::new(msg), + &mut FormatStringPayload::new(msg), info.message(), loc, info.can_unwind(), + info.force_no_backtrace(), ); } }) @@ -604,13 +633,20 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { #[cfg(not(feature = "backtrace"))] { if let Some(msg) = msg.as_str() { - rust_panic_with_hook(&mut StrPanicPayload(msg), info.message(), loc, info.can_unwind()); + rust_panic_with_hook( + &mut StaticStrPayload(msg), + info.message(), + loc, + info.can_unwind(), + /* force_no_backtrace */ true, + ); } else { rust_panic_with_hook( - &mut PanicPayload::new(msg), + &mut FormatStringPayload::new(msg), info.message(), loc, info.can_unwind(), + /* force_no_backtrace */ true, ); } } @@ -628,17 +664,17 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { #[track_caller] #[rustc_do_not_const_check] // hooked by const-eval pub const fn begin_panic(msg: M) -> ! { - struct PanicPayload { + struct Payload { inner: Option, } - impl PanicPayload { - fn new(inner: A) -> PanicPayload { - PanicPayload { inner: Some(inner) } + impl Payload { + fn new(inner: A) -> Payload { + Payload { inner: Some(inner) } } } - unsafe impl BoxMeUp for PanicPayload { + unsafe impl PanicPayload for Payload { fn take_box(&mut self) -> *mut (dyn Any + Send) { // Note that this should be the only allocation performed in this code path. Currently // this means that panic!() on OOM will invoke this code path, but then again we're not @@ -663,11 +699,23 @@ pub const fn begin_panic(msg: M) -> ! { let loc = Location::caller(); #[cfg(feature = "backtrace")] { crate::sys_common::backtrace::__rust_end_short_backtrace(move || { - rust_panic_with_hook(&mut PanicPayload::new(msg), None, loc, true) + rust_panic_with_hook( + &mut Payload::new(msg), + None, + loc, + /* can_unwind */ true, + /* force_no_backtrace */ false, + ) }) } #[cfg(not(feature = "backtrace"))] { - rust_panic_with_hook(&mut PanicPayload::new(msg), None, loc, true) + rust_panic_with_hook( + &mut Payload::new(msg), + None, + loc, + /* can_unwind */ true, + /* force_no_backtrace */ true, + ) } } @@ -677,33 +725,39 @@ pub const fn begin_panic(msg: M) -> ! { /// panics, panic hooks, and finally dispatching to the panic runtime to either /// abort or unwind. fn rust_panic_with_hook( - payload: &mut dyn BoxMeUp, + payload: &mut dyn PanicPayload, message: Option<&fmt::Arguments<'_>>, location: &Location<'_>, can_unwind: bool, + force_no_backtrace: bool, ) -> ! { - let (must_abort, panics) = panic_count::increase(); - - // If this is the third nested call (e.g., panics == 2, this is 0-indexed), - // the panic hook probably triggered the last panic, otherwise the - // double-panic check would have aborted the process. In this case abort the - // process real quickly as we don't want to try calling it again as it'll - // probably just panic again. - if must_abort || panics > 2 { - if panics > 2 { - // Don't try to print the message in this case - // - perhaps that is causing the recursive panics. - rtprintpanic!("thread panicked while processing panic. aborting.\n"); - } else { - // Unfortunately, this does not print a backtrace, because creating - // a `Backtrace` will allocate, which we must to avoid here. - let panicinfo = PanicInfo::internal_constructor(message, location, can_unwind); - rtprintpanic!("{panicinfo}\npanicked after panic::always_abort(), aborting.\n"); + let must_abort = panic_count::increase(true); + + // Check if we need to abort immediately. + if let Some(must_abort) = must_abort { + match must_abort { + panic_count::MustAbort::PanicInHook => { + // Don't try to print the message in this case + // - perhaps that is causing the recursive panics. + rtprintpanic!("thread panicked while processing panic. aborting.\n"); + } + panic_count::MustAbort::AlwaysAbort => { + // Unfortunately, this does not print a backtrace, because creating + // a `Backtrace` will allocate, which we must to avoid here. + let panicinfo = PanicInfo::internal_constructor( + message, + location, + can_unwind, + force_no_backtrace, + ); + rtprintpanic!("{panicinfo}\npanicked after panic::always_abort(), aborting.\n"); + } } - abort() + crate::sys::abort_internal(); } - let mut info = PanicInfo::internal_constructor(message, location, can_unwind); + let mut info = + PanicInfo::internal_constructor(message, location, can_unwind, force_no_backtrace); let hook = HOOK.read().unwrap_or_else(PoisonError::into_inner); match *hook { // Some platforms (like wasm) know that printing to stderr won't ever actually @@ -725,13 +779,17 @@ fn rust_panic_with_hook( }; drop(hook); - if panics > 1 || !can_unwind { - // If a thread panics while it's already unwinding then we - // have limited options. Currently our preference is to - // just abort. In the future we may consider resuming - // unwinding or otherwise exiting the thread cleanly. - rtprintpanic!("thread panicked while panicking. aborting.\n"); - abort() + // Indicate that we have finished executing the panic hook. After this point + // it is fine if there is a panic while executing destructors, as long as it + // it contained within a `catch_unwind`. + panic_count::finished_panic_hook(); + + if !can_unwind { + // If a thread panics while running destructors or tries to unwind + // through a nounwind function (e.g. extern "C") then we cannot continue + // unwinding and have to abort immediately. + rtprintpanic!("thread caused non-unwinding panic. aborting.\n"); + crate::sys::abort_internal(); } rust_panic(payload) @@ -740,11 +798,11 @@ fn rust_panic_with_hook( /// This is the entry point for `resume_unwind`. /// It just forwards the payload to the panic runtime. pub fn rust_panic_without_hook(payload: Box) -> ! { - panic_count::increase(); + panic_count::increase(false); struct RewrapBox(Box); - unsafe impl BoxMeUp for RewrapBox { + unsafe impl PanicPayload for RewrapBox { fn take_box(&mut self) -> *mut (dyn Any + Send) { Box::into_raw(mem::replace(&mut self.0, Box::new(()))) } @@ -760,11 +818,8 @@ pub fn rust_panic_without_hook(payload: Box) -> ! { /// An unmangled function (through `rustc_std_internal_symbol`) on which to slap /// yer breakpoints. #[inline(never)] -#[cfg_attr(not(test), rustc_std_internal_symbol)] -fn rust_panic(mut msg: &mut dyn BoxMeUp) -> ! { - let code = unsafe { - let obj = &mut msg as *mut &mut dyn BoxMeUp; - __rust_start_panic(obj) - }; +#[rustc_std_internal_symbol] +fn rust_panic(msg: &mut dyn PanicPayload) -> ! { + let code = unsafe { __rust_start_panic(msg) }; rtabort!("failed to initiate panic, error {code}") } diff --git a/sgx_tstd/src/path.rs b/sgx_tstd/src/path.rs index 7f23d8645..d7e92c2f6 100644 --- a/sgx_tstd/src/path.rs +++ b/sgx_tstd/src/path.rs @@ -96,7 +96,7 @@ use crate::fmt; use crate::fs; use crate::hash::{Hash, Hasher}; use crate::io; -use crate::iter::{self, FusedIterator}; +use crate::iter::FusedIterator; use crate::ops::{self, Deref}; use crate::rc::Rc; use crate::str::FromStr; @@ -135,7 +135,7 @@ use crate::sys::path::{is_sep_byte, is_verbatim_sep, parse_prefix, MAIN_SEP_STR} /// use std::path::Prefix::*; /// use std::ffi::OsStr; /// -/// fn get_path_prefix(s: &str) -> Prefix { +/// fn get_path_prefix(s: &str) -> Prefix<'_> { /// let path = Path::new(s); /// match path.components().next().unwrap() { /// Component::Prefix(prefix_component) => prefix_component.kind(), @@ -199,7 +199,7 @@ impl<'a> Prefix<'a> { fn len(&self) -> usize { use self::Prefix::*; fn os_str_len(s: &OsStr) -> usize { - s.bytes().len() + s.as_encoded_bytes().len() } match *self { Verbatim(x) => 4 + os_str_len(x), @@ -301,21 +301,6 @@ where } } -unsafe fn u8_slice_as_os_str(s: &[u8]) -> &OsStr { - // SAFETY: See note at the top of this module to understand why this and - // `OsStr::bytes` are used: - // - // This casts are safe as OsStr is internally a wrapper around [u8] on all - // platforms. - // - // Note that currently this relies on the special knowledge that libstd has; - // these types are single-element structs but are not marked - // repr(transparent) or repr(C) which would make these casts not allowable - // outside std. - unsafe { &*(s as *const [u8] as *const OsStr) } -} - - //////////////////////////////////////////////////////////////////////////////// // Cross-platform, iterator-independent parsing //////////////////////////////////////////////////////////////////////////////// @@ -328,7 +313,7 @@ fn has_physical_root(s: &[u8], prefix: Option>) -> bool { // basic workhorse for splitting stem and extension fn rsplit_file_at_dot(file: &OsStr) -> (Option<&OsStr>, Option<&OsStr>) { - if file.bytes() == b".." { + if file.as_encoded_bytes() == b".." { return (Some(file), None); } @@ -336,18 +321,23 @@ fn rsplit_file_at_dot(file: &OsStr) -> (Option<&OsStr>, Option<&OsStr>) { // and back. This is safe to do because (1) we only look at ASCII // contents of the encoding and (2) new &OsStr values are produced // only from ASCII-bounded slices of existing &OsStr values. - let mut iter = file.bytes().rsplitn(2, |b| *b == b'.'); + let mut iter = file.as_encoded_bytes().rsplitn(2, |b| *b == b'.'); let after = iter.next(); let before = iter.next(); if before == Some(b"") { (Some(file), None) } else { - unsafe { (before.map(|s| u8_slice_as_os_str(s)), after.map(|s| u8_slice_as_os_str(s))) } + unsafe { + ( + before.map(|s| OsStr::from_encoded_bytes_unchecked(s)), + after.map(|s| OsStr::from_encoded_bytes_unchecked(s)), + ) + } } } fn split_file_at_dot(file: &OsStr) -> (&OsStr, Option<&OsStr>) { - let slice = file.bytes(); + let slice = file.as_encoded_bytes(); if slice == b".." { return (file, None); } @@ -362,7 +352,12 @@ fn split_file_at_dot(file: &OsStr) -> (&OsStr, Option<&OsStr>) { }; let before = &slice[..i]; let after = &slice[i + 1..]; - unsafe { (u8_slice_as_os_str(before), Some(u8_slice_as_os_str(after))) } + unsafe { + ( + OsStr::from_encoded_bytes_unchecked(before), + Some(OsStr::from_encoded_bytes_unchecked(after)), + ) + } } //////////////////////////////////////////////////////////////////////////////// @@ -444,24 +439,24 @@ impl<'a> PrefixComponent<'a> { } } -impl<'a> cmp::PartialEq for PrefixComponent<'a> { +impl<'a> PartialEq for PrefixComponent<'a> { #[inline] fn eq(&self, other: &PrefixComponent<'a>) -> bool { - cmp::PartialEq::eq(&self.parsed, &other.parsed) + self.parsed == other.parsed } } -impl<'a> cmp::PartialOrd for PrefixComponent<'a> { +impl<'a> PartialOrd for PrefixComponent<'a> { #[inline] fn partial_cmp(&self, other: &PrefixComponent<'a>) -> Option { - cmp::PartialOrd::partial_cmp(&self.parsed, &other.parsed) + PartialOrd::partial_cmp(&self.parsed, &other.parsed) } } -impl cmp::Ord for PrefixComponent<'_> { +impl Ord for PrefixComponent<'_> { #[inline] fn cmp(&self, other: &Self) -> cmp::Ordering { - cmp::Ord::cmp(&self.parsed, &other.parsed) + Ord::cmp(&self.parsed, &other.parsed) } } @@ -589,7 +584,7 @@ pub struct Components<'a> { // true if path *physically* has a root separator; for most Windows // prefixes, it may have a "logical" root separator for the purposes of - // normalization, e.g., \\server\share == \\server\share\. + // normalization, e.g., \\server\share == \\server\share\. has_physical_root: bool, // The iterator is double-ended, and these two states keep track of what has @@ -712,8 +707,9 @@ impl<'a> Components<'a> { } } - // parse a given byte sequence into the corresponding path component - fn parse_single_component<'b>(&self, comp: &'b [u8]) -> Option> { + // parse a given byte sequence following the OsStr encoding into the + // corresponding path component + unsafe fn parse_single_component<'b>(&self, comp: &'b [u8]) -> Option> { match comp { b"." if self.prefix_verbatim() => Some(Component::CurDir), b"." => None, // . components are normalized away, except at @@ -721,7 +717,7 @@ impl<'a> Components<'a> { // separately via `include_cur_dir` b".." => Some(Component::ParentDir), b"" => None, - _ => Some(Component::Normal(unsafe { u8_slice_as_os_str(comp) })), + _ => Some(Component::Normal(unsafe { OsStr::from_encoded_bytes_unchecked(comp) })), } } @@ -733,7 +729,8 @@ impl<'a> Components<'a> { None => (0, self.path), Some(i) => (1, &self.path[..i]), }; - (comp.len() + extra, self.parse_single_component(comp)) + // SAFETY: `comp` is a valid substring, since it is split on a separator. + (comp.len() + extra, unsafe { self.parse_single_component(comp) }) } // parse a component from the right, saying how many bytes to consume to @@ -745,7 +742,8 @@ impl<'a> Components<'a> { None => (0, &self.path[start..]), Some(i) => (1, &self.path[start + i + 1..]), }; - (comp.len() + extra, self.parse_single_component(comp)) + // SAFETY: `comp` is a valid substring, since it is split on a separator. + (comp.len() + extra, unsafe { self.parse_single_component(comp) }) } // trim away repeated separators (i.e., empty components) on the left @@ -866,7 +864,7 @@ impl<'a> Iterator for Components<'a> { let raw = &self.path[..self.prefix_len()]; self.path = &self.path[self.prefix_len()..]; return Some(Component::Prefix(PrefixComponent { - raw: unsafe { u8_slice_as_os_str(raw) }, + raw: unsafe { OsStr::from_encoded_bytes_unchecked(raw) }, parsed: self.prefix.unwrap(), })); } @@ -937,7 +935,7 @@ impl<'a> DoubleEndedIterator for Components<'a> { State::Prefix if self.prefix_len() > 0 => { self.back = State::Done; return Some(Component::Prefix(PrefixComponent { - raw: unsafe { u8_slice_as_os_str(self.path) }, + raw: unsafe { OsStr::from_encoded_bytes_unchecked(self.path) }, parsed: self.prefix.unwrap(), })); } @@ -954,7 +952,7 @@ impl<'a> DoubleEndedIterator for Components<'a> { impl FusedIterator for Components<'_> {} -impl<'a> cmp::PartialEq for Components<'a> { +impl<'a> PartialEq for Components<'a> { #[inline] fn eq(&self, other: &Components<'a>) -> bool { let Components { path: _, front: _, back: _, has_physical_root: _, prefix: _ } = self; @@ -980,16 +978,16 @@ impl<'a> cmp::PartialEq for Components<'a> { } } -impl cmp::Eq for Components<'_> {} +impl Eq for Components<'_> {} -impl<'a> cmp::PartialOrd for Components<'a> { +impl<'a> PartialOrd for Components<'a> { #[inline] fn partial_cmp(&self, other: &Components<'a>) -> Option { Some(compare_components(self.clone(), other.clone())) } } -impl cmp::Ord for Components<'_> { +impl Ord for Components<'_> { #[inline] fn cmp(&self, other: &Self) -> cmp::Ordering { compare_components(self.clone(), other.clone()) @@ -1121,9 +1119,10 @@ impl FusedIterator for Ancestors<'_> {} // FIXME: // `PathBuf::as_mut_vec` current implementation relies // on `PathBuf` being layout-compatible with `Vec`. -// When attribute privacy is implemented, `PathBuf` should be annotated as `#[repr(transparent)]`. -// Anyway, `PathBuf` representation and layout are considered implementation detail, are -// not documented and must not be relied upon. +// However, `PathBuf` layout is considered an implementation detail and must not be relied upon. We +// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under +// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy. +#[cfg_attr(not(doc), repr(transparent))] pub struct PathBuf { inner: OsString, } @@ -1185,7 +1184,6 @@ impl PathBuf { /// ``` #[must_use] #[inline] - #[allow(clippy::ptr_arg)] pub fn as_path(&self) -> &Path { self } @@ -1203,6 +1201,9 @@ impl PathBuf { /// and `path` is not empty, the new path is normalized: all references /// to `.` and `..` are removed. /// + /// Consider using [`Path::join`] if you need a new `PathBuf` instead of + /// using this function on a cloned `PathBuf`. + /// /// # Examples /// /// Pushing a relative path extends the existing path: @@ -1347,11 +1348,16 @@ impl PathBuf { /// /// let mut buf = PathBuf::from("/"); /// assert!(buf.file_name() == None); - /// buf.set_file_name("bar"); - /// assert!(buf == PathBuf::from("/bar")); + /// + /// buf.set_file_name("foo.txt"); + /// assert!(buf == PathBuf::from("/foo.txt")); /// assert!(buf.file_name().is_some()); - /// buf.set_file_name("baz.txt"); - /// assert!(buf == PathBuf::from("/baz.txt")); + /// + /// buf.set_file_name("bar.txt"); + /// assert!(buf == PathBuf::from("/bar.txt")); + /// + /// buf.set_file_name("baz"); + /// assert!(buf == PathBuf::from("/baz")); /// ``` pub fn set_file_name>(&mut self, file_name: S) { self._set_file_name(file_name.as_ref()) @@ -1365,7 +1371,8 @@ impl PathBuf { self.push(file_name); } - /// Updates [`self.extension`] to `extension`. + /// Updates [`self.extension`] to `Some(extension)` or to `None` if + /// `extension` is empty. /// /// Returns `false` and does nothing if [`self.file_name`] is [`None`], /// returns `true` and updates the extension otherwise. @@ -1373,6 +1380,20 @@ impl PathBuf { /// If [`self.extension`] is [`None`], the extension is added; otherwise /// it is replaced. /// + /// If `extension` is the empty string, [`self.extension`] will be [`None`] + /// afterwards, not `Some("")`. + /// + /// # Caveats + /// + /// The new `extension` may contain dots and will be used in its entirety, + /// but only the part after the final dot will be reflected in + /// [`self.extension`]. + /// + /// If the file stem contains internal dots and `extension` is empty, part + /// of the old file stem will be considered the new [`self.extension`]. + /// + /// See the examples below. + /// /// [`self.file_name`]: Path::file_name /// [`self.extension`]: Path::extension /// @@ -1386,8 +1407,20 @@ impl PathBuf { /// p.set_extension("force"); /// assert_eq!(Path::new("/feel/the.force"), p.as_path()); /// - /// p.set_extension("dark_side"); - /// assert_eq!(Path::new("/feel/the.dark_side"), p.as_path()); + /// p.set_extension("dark.side"); + /// assert_eq!(Path::new("/feel/the.dark.side"), p.as_path()); + /// + /// p.set_extension("cookie"); + /// assert_eq!(Path::new("/feel/the.dark.cookie"), p.as_path()); + /// + /// p.set_extension(""); + /// assert_eq!(Path::new("/feel/the.dark"), p.as_path()); + /// + /// p.set_extension(""); + /// assert_eq!(Path::new("/feel/the"), p.as_path()); + /// + /// p.set_extension(""); + /// assert_eq!(Path::new("/feel/the"), p.as_path()); /// ``` pub fn set_extension>(&mut self, extension: S) -> bool { self._set_extension(extension.as_ref()) @@ -1396,17 +1429,17 @@ impl PathBuf { fn _set_extension(&mut self, extension: &OsStr) -> bool { let file_stem = match self.file_stem() { None => return false, - Some(f) => f.bytes(), + Some(f) => f.as_encoded_bytes(), }; // truncate until right after the file stem let end_file_stem = file_stem[file_stem.len()..].as_ptr().addr(); - let start = self.inner.bytes().as_ptr().addr(); + let start = self.inner.as_encoded_bytes().as_ptr().addr(); let v = self.as_mut_vec(); v.truncate(end_file_stem.wrapping_sub(start)); // add the new extension, if any - let new = extension.bytes(); + let new = extension.as_encoded_bytes(); if !new.is_empty() { v.reserve_exact(new.len() + 1); v.push(b'.'); @@ -1416,6 +1449,28 @@ impl PathBuf { true } + /// Yields a mutable reference to the underlying [`OsString`] instance. + /// + /// # Examples + /// + /// ``` + /// use std::path::{Path, PathBuf}; + /// + /// let mut path = PathBuf::from("/foo"); + /// + /// path.push("bar"); + /// assert_eq!(path, Path::new("/foo/bar")); + /// + /// // OsString's `push` does not add a separator. + /// path.as_mut_os_string().push("baz"); + /// assert_eq!(path, Path::new("/foo/barbaz")); + /// ``` + #[must_use] + #[inline] + pub fn as_mut_os_string(&mut self) -> &mut OsString { + &mut self.inner + } + /// Consumes the `PathBuf`, yielding its internal [`OsString`] storage. /// /// # Examples @@ -1445,7 +1500,6 @@ impl PathBuf { /// [`capacity`]: OsString::capacity #[must_use] #[inline] - #[allow(clippy::ptr_arg)] pub fn capacity(&self) -> usize { self.inner.capacity() } @@ -1620,7 +1674,7 @@ impl FromStr for PathBuf { } } -impl> iter::FromIterator

for PathBuf { +impl> FromIterator

for PathBuf { fn from_iter>(iter: I) -> PathBuf { let mut buf = PathBuf::new(); buf.extend(iter); @@ -1628,7 +1682,7 @@ impl> iter::FromIterator

for PathBuf { } } -impl> iter::Extend

for PathBuf { +impl> Extend

for PathBuf { fn extend>(&mut self, iter: I) { iter.into_iter().for_each(move |p| self.push(p.as_ref())); } @@ -1653,6 +1707,13 @@ impl ops::Deref for PathBuf { } } +impl ops::DerefMut for PathBuf { + #[inline] + fn deref_mut(&mut self) -> &mut Path { + Path::from_inner_mut(&mut self.inner) + } +} + impl Borrow for PathBuf { #[inline] fn borrow(&self) -> &Path { @@ -1760,7 +1821,7 @@ impl ToOwned for Path { } } -impl cmp::PartialEq for PathBuf { +impl PartialEq for PathBuf { #[inline] fn eq(&self, other: &PathBuf) -> bool { self.components() == other.components() @@ -1773,16 +1834,16 @@ impl Hash for PathBuf { } } -impl cmp::Eq for PathBuf {} +impl Eq for PathBuf {} -impl cmp::PartialOrd for PathBuf { +impl PartialOrd for PathBuf { #[inline] fn partial_cmp(&self, other: &PathBuf) -> Option { Some(compare_components(self.components(), other.components())) } } -impl cmp::Ord for PathBuf { +impl Ord for PathBuf { #[inline] fn cmp(&self, other: &PathBuf) -> cmp::Ordering { compare_components(self.components(), other.components()) @@ -1832,9 +1893,10 @@ impl AsRef for PathBuf { // FIXME: // `Path::new` current implementation relies // on `Path` being layout-compatible with `OsStr`. -// When attribute privacy is implemented, `Path` should be annotated as `#[repr(transparent)]`. -// Anyway, `Path` representation and layout are considered implementation detail, are -// not documented and must not be relied upon. +// However, `Path` layout is considered an implementation detail and must not be relied upon. We +// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under +// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy. +#[cfg_attr(not(doc), repr(transparent))] pub struct Path { inner: OsStr, } @@ -1852,11 +1914,11 @@ impl Path { // The following (private!) function allows construction of a path from a u8 // slice, which is only safe when it is known to follow the OsStr encoding. unsafe fn from_u8_slice(s: &[u8]) -> &Path { - Path::new(u8_slice_as_os_str(s)) + unsafe { Path::new(OsStr::from_encoded_bytes_unchecked(s)) } } // The following (private!) function reveals the byte encoding used for OsStr. fn as_u8_slice(&self) -> &[u8] { - self.inner.bytes() + self.inner.as_encoded_bytes() } /// Directly wraps a string slice as a `Path` slice. @@ -1885,6 +1947,12 @@ impl Path { unsafe { &*(s.as_ref() as *const OsStr as *const Path) } } + fn from_inner_mut(inner: &mut OsStr) -> &mut Path { + // SAFETY: Path is just a wrapper around OsStr, + // therefore converting &mut OsStr to &mut Path is safe. + unsafe { &mut *(inner as *mut OsStr as *mut Path) } + } + /// Yields the underlying [`OsStr`] slice. /// /// # Examples @@ -1901,6 +1969,26 @@ impl Path { &self.inner } + /// Yields a mutable reference to the underlying [`OsStr`] slice. + /// + /// # Examples + /// + /// ``` + /// use std::path::{Path, PathBuf}; + /// + /// let mut path = PathBuf::from("Foo.TXT"); + /// + /// assert_ne!(path, Path::new("foo.txt")); + /// + /// path.as_mut_os_str().make_ascii_lowercase(); + /// assert_eq!(path, Path::new("foo.txt")); + /// ``` + #[must_use] + #[inline] + pub fn as_mut_os_str(&mut self) -> &mut OsStr { + &mut self.inner + } + /// Yields a [`&str`] slice if the `Path` is valid unicode. /// /// This conversion may entail doing a check for UTF-8 validity. @@ -2039,7 +2127,10 @@ impl Path { /// Returns the `Path` without its final component, if there is one. /// - /// Returns [`None`] if the path terminates in a root or prefix. + /// This means it returns `Some("")` for relative paths with one component. + /// + /// Returns [`None`] if the path terminates in a root or prefix, or if it's + /// the empty string. /// /// # Examples /// @@ -2053,6 +2144,14 @@ impl Path { /// let grand_parent = parent.parent().unwrap(); /// assert_eq!(grand_parent, Path::new("/")); /// assert_eq!(grand_parent.parent(), None); + /// + /// let relative_path = Path::new("foo/bar"); + /// let parent = relative_path.parent(); + /// assert_eq!(parent, Some(Path::new("foo"))); + /// let grand_parent = parent.and_then(Path::parent); + /// assert_eq!(grand_parent, Some(Path::new(""))); + /// let great_grand_parent = grand_parent.and_then(Path::parent); + /// assert_eq!(great_grand_parent, None); /// ``` #[must_use] pub fn parent(&self) -> Option<&Path> { @@ -2096,7 +2195,7 @@ impl Path { /// [`parent`]: Path::parent #[inline] pub fn ancestors(&self) -> Ancestors<'_> { - Ancestors { next: Some(self) } + Ancestors { next: Some(&self) } } /// Returns the final component of the `Path`, if there is one. @@ -2317,6 +2416,8 @@ impl Path { /// Creates an owned [`PathBuf`] with `path` adjoined to `self`. /// + /// If `path` is absolute, it replaces the current path. + /// /// See [`PathBuf::push`] for more details on what it means to adjoin a path. /// /// # Examples @@ -2325,6 +2426,7 @@ impl Path { /// use std::path::{Path, PathBuf}; /// /// assert_eq!(Path::new("/etc").join("passwd"), PathBuf::from("/etc/passwd")); + /// assert_eq!(Path::new("/etc").join("/bin/sh"), PathBuf::from("/bin/sh")); /// ``` #[must_use] pub fn join>(&self, path: P) -> PathBuf { @@ -2346,7 +2448,8 @@ impl Path { /// ``` /// use std::path::{Path, PathBuf}; /// - /// let path = Path::new("/tmp/foo.txt"); + /// let path = Path::new("/tmp/foo.png"); + /// assert_eq!(path.with_file_name("bar"), PathBuf::from("/tmp/bar")); /// assert_eq!(path.with_file_name("bar.txt"), PathBuf::from("/tmp/bar.txt")); /// /// let path = Path::new("/tmp"); @@ -2385,9 +2488,27 @@ impl Path { } fn _with_extension(&self, extension: &OsStr) -> PathBuf { - let mut buf = self.to_path_buf(); - buf.set_extension(extension); - buf + let self_len = self.as_os_str().len(); + let self_bytes = self.as_os_str().as_encoded_bytes(); + + let (new_capacity, slice_to_copy) = match self.extension() { + None => { + // Enough capacity for the extension and the dot + let capacity = self_len + extension.len() + 1; + let whole_path = self_bytes.iter(); + (capacity, whole_path) + } + Some(previous_extension) => { + let capacity = self_len + extension.len() - previous_extension.len(); + let path_till_dot = self_bytes[..self_len - previous_extension.len()].iter(); + (capacity, path_till_dot) + } + }; + + let mut new_path = PathBuf::with_capacity(new_capacity); + new_path.as_mut_vec().extend(slice_to_copy); + new_path.set_extension(extension); + new_path } /// Produces an iterator over the [`Component`]s of the path. @@ -2465,6 +2586,7 @@ impl Path { /// escapes the path please use [`Debug`] instead. /// /// [`Display`]: fmt::Display + /// [`Debug`]: fmt::Debug /// /// # Examples /// @@ -2621,9 +2743,11 @@ impl Path { /// This function will traverse symbolic links to query information about the /// destination file. In case of broken symbolic links this will return `Ok(false)`. /// - /// As opposed to the [`exists()`] method, this one doesn't silently ignore errors - /// unrelated to the path not existing. (E.g. it will return `Err(_)` in case of permission - /// denied on some of the parent directories.) + /// [`Path::exists()`] only checks whether or not a path was both found and readable. By + /// contrast, `try_exists` will return `Ok(true)` or `Ok(false)`, respectively, if the path + /// was _verified_ to exist or not exist. If its existence can neither be confirmed nor + /// denied, it will propagate an `Err(_)` instead. This can be the case if e.g. listing + /// permission is denied on one of the parent directories. /// /// Note that while this avoids some pitfalls of the `exists()` method, it still can not /// prevent time-of-check to time-of-use (TOCTOU) bugs. You should only use it in scenarios @@ -2795,7 +2919,7 @@ impl fmt::Display for Display<'_> { } } -impl cmp::PartialEq for Path { +impl PartialEq for Path { #[inline] fn eq(&self, other: &Path) -> bool { self.components() == other.components() @@ -2853,16 +2977,16 @@ impl Hash for Path { } } -impl cmp::Eq for Path {} +impl Eq for Path {} -impl cmp::PartialOrd for Path { +impl PartialOrd for Path { #[inline] fn partial_cmp(&self, other: &Path) -> Option { Some(compare_components(self.components(), other.components())) } } -impl cmp::Ord for Path { +impl Ord for Path { #[inline] fn cmp(&self, other: &Path) -> cmp::Ordering { compare_components(self.components(), other.components()) @@ -2937,29 +3061,29 @@ impl<'a> IntoIterator for &'a Path { } macro_rules! impl_cmp { - ($lhs:ty, $rhs: ty) => { - impl<'a, 'b> PartialEq<$rhs> for $lhs { + (<$($life:lifetime),*> $lhs:ty, $rhs: ty) => { + impl<$($life),*> PartialEq<$rhs> for $lhs { #[inline] fn eq(&self, other: &$rhs) -> bool { ::eq(self, other) } } - impl<'a, 'b> PartialEq<$lhs> for $rhs { + impl<$($life),*> PartialEq<$lhs> for $rhs { #[inline] fn eq(&self, other: &$lhs) -> bool { ::eq(self, other) } } - impl<'a, 'b> PartialOrd<$rhs> for $lhs { + impl<$($life),*> PartialOrd<$rhs> for $lhs { #[inline] fn partial_cmp(&self, other: &$rhs) -> Option { ::partial_cmp(self, other) } } - impl<'a, 'b> PartialOrd<$lhs> for $rhs { + impl<$($life),*> PartialOrd<$lhs> for $rhs { #[inline] fn partial_cmp(&self, other: &$lhs) -> Option { ::partial_cmp(self, other) @@ -2968,36 +3092,36 @@ macro_rules! impl_cmp { }; } -impl_cmp!(PathBuf, Path); -impl_cmp!(PathBuf, &'a Path); -impl_cmp!(Cow<'a, Path>, Path); -impl_cmp!(Cow<'a, Path>, &'b Path); -impl_cmp!(Cow<'a, Path>, PathBuf); +impl_cmp!(<> PathBuf, Path); +impl_cmp!(<'a> PathBuf, &'a Path); +impl_cmp!(<'a> Cow<'a, Path>, Path); +impl_cmp!(<'a, 'b> Cow<'a, Path>, &'b Path); +impl_cmp!(<'a> Cow<'a, Path>, PathBuf); macro_rules! impl_cmp_os_str { - ($lhs:ty, $rhs: ty) => { - impl<'a, 'b> PartialEq<$rhs> for $lhs { + (<$($life:lifetime),*> $lhs:ty, $rhs: ty) => { + impl<$($life),*> PartialEq<$rhs> for $lhs { #[inline] fn eq(&self, other: &$rhs) -> bool { ::eq(self, other.as_ref()) } } - impl<'a, 'b> PartialEq<$lhs> for $rhs { + impl<$($life),*> PartialEq<$lhs> for $rhs { #[inline] fn eq(&self, other: &$lhs) -> bool { ::eq(self.as_ref(), other) } } - impl<'a, 'b> PartialOrd<$rhs> for $lhs { + impl<$($life),*> PartialOrd<$rhs> for $lhs { #[inline] fn partial_cmp(&self, other: &$rhs) -> Option { ::partial_cmp(self, other.as_ref()) } } - impl<'a, 'b> PartialOrd<$lhs> for $rhs { + impl<$($life),*> PartialOrd<$lhs> for $rhs { #[inline] fn partial_cmp(&self, other: &$lhs) -> Option { ::partial_cmp(self.as_ref(), other) @@ -3006,20 +3130,20 @@ macro_rules! impl_cmp_os_str { }; } -impl_cmp_os_str!(PathBuf, OsStr); -impl_cmp_os_str!(PathBuf, &'a OsStr); -impl_cmp_os_str!(PathBuf, Cow<'a, OsStr>); -impl_cmp_os_str!(PathBuf, OsString); -impl_cmp_os_str!(Path, OsStr); -impl_cmp_os_str!(Path, &'a OsStr); -impl_cmp_os_str!(Path, Cow<'a, OsStr>); -impl_cmp_os_str!(Path, OsString); -impl_cmp_os_str!(&'a Path, OsStr); -impl_cmp_os_str!(&'a Path, Cow<'b, OsStr>); -impl_cmp_os_str!(&'a Path, OsString); -impl_cmp_os_str!(Cow<'a, Path>, OsStr); -impl_cmp_os_str!(Cow<'a, Path>, &'b OsStr); -impl_cmp_os_str!(Cow<'a, Path>, OsString); +impl_cmp_os_str!(<> PathBuf, OsStr); +impl_cmp_os_str!(<'a> PathBuf, &'a OsStr); +impl_cmp_os_str!(<'a> PathBuf, Cow<'a, OsStr>); +impl_cmp_os_str!(<> PathBuf, OsString); +impl_cmp_os_str!(<> Path, OsStr); +impl_cmp_os_str!(<'a> Path, &'a OsStr); +impl_cmp_os_str!(<'a> Path, Cow<'a, OsStr>); +impl_cmp_os_str!(<> Path, OsString); +impl_cmp_os_str!(<'a> &'a Path, OsStr); +impl_cmp_os_str!(<'a, 'b> &'a Path, Cow<'b, OsStr>); +impl_cmp_os_str!(<'a> &'a Path, OsString); +impl_cmp_os_str!(<'a> Cow<'a, Path>, OsStr); +impl_cmp_os_str!(<'a, 'b> Cow<'a, Path>, &'b OsStr); +impl_cmp_os_str!(<'a> Cow<'a, Path>, OsString); impl fmt::Display for StripPrefixError { #[allow(deprecated, deprecated_in_future)] diff --git a/sgx_tstd/src/path/tests.rs b/sgx_tstd/src/path/tests.rs index 68a003e74..82821b9b8 100644 --- a/sgx_tstd/src/path/tests.rs +++ b/sgx_tstd/src/path/tests.rs @@ -17,9 +17,8 @@ use super::*; -use crate::collections::hash_map::DefaultHasher; use crate::collections::{BTreeSet, HashSet}; -use crate::hash::Hasher; +use crate::hash::{DefaultHasher, Hasher}; use crate::rc::Rc; use crate::sync::Arc; @@ -569,7 +568,7 @@ pub fn test_prefix_ext() { #[test_case] pub fn test_push() { macro_rules! tp ( - ($path:expr, $push:expr, $expected:expr) => ( { + ($path:expr, $push:expr, $expected:expr) => ({ let mut actual = PathBuf::from($path); actual.push($push); assert!(actual.to_str() == Some($expected), @@ -596,7 +595,7 @@ pub fn test_push() { #[test_case] pub fn test_pop() { macro_rules! tp ( - ($path:expr, $expected:expr, $output:expr) => ( { + ($path:expr, $expected:expr, $output:expr) => ({ let mut actual = PathBuf::from($path); let output = actual.pop(); assert!(actual.to_str() == Some($expected) && output == $output, @@ -620,7 +619,7 @@ pub fn test_pop() { #[test_case] pub fn test_set_file_name() { macro_rules! tfn ( - ($path:expr, $file:expr, $expected:expr) => ( { + ($path:expr, $file:expr, $expected:expr) => ({ let mut p = PathBuf::from($path); p.set_file_name($file); assert!(p.to_str() == Some($expected), @@ -645,7 +644,7 @@ pub fn test_set_file_name() { #[test_case] pub fn test_set_extension() { macro_rules! tfe ( - ($path:expr, $ext:expr, $expected:expr, $output:expr) => ( { + ($path:expr, $ext:expr, $expected:expr, $output:expr) => ({ let mut p = PathBuf::from($path); let output = p.set_extension($ext); assert!(p.to_str() == Some($expected) && output == $output, @@ -670,6 +669,46 @@ pub fn test_set_extension() { tfe!("/", "foo", "/", false); } +#[test_case] +pub fn test_with_extension() { + macro_rules! twe ( + ($input:expr, $extension:expr, $expected:expr) => ({ + let input = Path::new($input); + let output = input.with_extension($extension); + + assert!( + output.to_str() == Some($expected), + "calling Path::new({:?}).with_extension({:?}): Expected {:?}, got {:?}", + $input, $extension, $expected, output, + ); + }); + ); + + twe!("foo", "txt", "foo.txt"); + twe!("foo.bar", "txt", "foo.txt"); + twe!("foo.bar.baz", "txt", "foo.bar.txt"); + twe!(".test", "txt", ".test.txt"); + twe!("foo.txt", "", "foo"); + twe!("foo", "", "foo"); + twe!("", "foo", ""); + twe!(".", "foo", "."); + twe!("foo/", "bar", "foo.bar"); + twe!("foo/.", "bar", "foo.bar"); + twe!("..", "foo", ".."); + twe!("foo/..", "bar", "foo/.."); + twe!("/", "foo", "/"); + + // New extension is smaller than file name + twe!("aaa_aaa_aaa", "bbb_bbb", "aaa_aaa_aaa.bbb_bbb"); + // New extension is greater than file name + twe!("bbb_bbb", "aaa_aaa_aaa", "bbb_bbb.aaa_aaa_aaa"); + + // New extension is smaller than previous extension + twe!("ccc.aaa_aaa_aaa", "bbb_bbb", "ccc.bbb_bbb"); + // New extension is greater than previous extension + twe!("ccc.bbb_bbb", "aaa_aaa_aaa", "ccc.aaa_aaa_aaa"); +} + #[test_case] fn test_eq_receivers() { use crate::borrow::Cow; @@ -697,8 +736,7 @@ fn test_eq_receivers() { #[test_case] pub fn test_compare() { - use crate::collections::hash_map::DefaultHasher; - use crate::hash::{Hash, Hasher}; + use crate::hash::{DefaultHasher, Hash, Hasher}; fn hash(t: T) -> u64 { let mut s = DefaultHasher::new(); @@ -906,7 +944,7 @@ fn into_rc() { #[test_case] fn test_ord() { macro_rules! ord( - ($ord:ident, $left:expr, $right:expr) => ( { + ($ord:ident, $left:expr, $right:expr) => ({ use core::cmp::Ordering; let left = Path::new($left); diff --git a/sgx_tstd/src/prelude/mod.rs b/sgx_tstd/src/prelude/mod.rs index 84c56248a..e3109bf4e 100644 --- a/sgx_tstd/src/prelude/mod.rs +++ b/sgx_tstd/src/prelude/mod.rs @@ -51,7 +51,7 @@ //! marker traits that indicate fundamental properties of types. //! * [std::ops]::{[Drop], [Fn], [FnMut], [FnOnce]}, various //! operations for both destructors and overloading `()`. -//! * [std::mem]::[drop][mem::drop], a convenience function for explicitly +//! * [std::mem]::[drop], a convenience function for explicitly //! dropping a value. //! * [std::boxed]::[Box], a way to allocate values on the heap. //! * [std::borrow]::[ToOwned], the conversion trait that defines @@ -83,7 +83,6 @@ //! * [std::convert]::{[TryFrom], [TryInto]}, //! * [std::iter]::[FromIterator]. //! -//! [mem::drop]: crate::mem::drop //! [std::borrow]: crate::borrow //! [std::boxed]: crate::boxed //! [std::clone]: crate::clone @@ -103,9 +102,6 @@ //! [std::slice]: crate::slice //! [std::string]: crate::string //! [std::vec]: mod@crate::vec -//! [TryFrom]: crate::convert::TryFrom -//! [TryInto]: crate::convert::TryInto -//! [FromIterator]: crate::iter::FromIterator //! [`to_owned`]: crate::borrow::ToOwned::to_owned //! [book-closures]: ../../book/ch13-01-closures.html //! [book-dtor]: ../../book/ch15-03-drop.html diff --git a/sgx_tstd/src/prelude/v1.rs b/sgx_tstd/src/prelude/v1.rs index 756a2c2e8..8ea33cdf2 100644 --- a/sgx_tstd/src/prelude/v1.rs +++ b/sgx_tstd/src/prelude/v1.rs @@ -58,17 +58,21 @@ pub use core::prelude::v1::{RustcDecodable, RustcEncodable}; // Do not `doc(no_inline)` so that they become doc items on their own // (no public module for them to be re-exported from). -pub use core::prelude::v1::{derive, global_allocator, test, test_case}; +pub use core::prelude::v1::{ + alloc_error_handler, derive, global_allocator, test, test_case, +}; // Do not `doc(no_inline)` either. pub use core::prelude::v1::cfg_accessible; pub use core::prelude::v1::cfg_eval; -// The file so far is equivalent to src/libcore/prelude/v1.rs, -// and below to src/liballoc/prelude.rs. -// Those files are duplicated rather than using glob imports -// because we want docs to show these re-exports as pointing to within `std`. +pub use core::prelude::v1::type_ascribe; + +// The file so far is equivalent to core/src/prelude/v1.rs. It is duplicated +// rather than glob imported because we want docs to show these re-exports as +// pointing to within `std`. +// Below are the items from the alloc crate. #[doc(no_inline)] pub use crate::borrow::ToOwned; diff --git a/sgx_tstd/src/process.rs b/sgx_tstd/src/process.rs index 3fc769a77..a36a2b76a 100644 --- a/sgx_tstd/src/process.rs +++ b/sgx_tstd/src/process.rs @@ -29,9 +29,9 @@ //! use std::process::Command; //! //! let output = Command::new("echo") -//! .arg("Hello world") -//! .output() -//! .expect("Failed to execute command"); +//! .arg("Hello world") +//! .output() +//! .expect("Failed to execute command"); //! //! assert_eq!(b"Hello world\n", output.stdout.as_slice()); //! ``` @@ -123,7 +123,7 @@ use crate::convert::Infallible; use crate::ffi::OsStr; use crate::fmt; use crate::fs; -use crate::io::{self, IoSlice, IoSliceMut}; +use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; use crate::num::NonZeroI32; use crate::path::Path; use crate::str; @@ -166,12 +166,11 @@ use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; /// use std::process::Command; /// /// let mut child = Command::new("/bin/cat") -/// .arg("file.txt") -/// .spawn() -/// .expect("failed to execute child"); +/// .arg("file.txt") +/// .spawn() +/// .expect("failed to execute child"); /// -/// let ecode = child.wait() -/// .expect("failed to wait on child"); +/// let ecode = child.wait().expect("failed to wait on child"); /// /// assert!(ecode.success()); /// ``` @@ -219,6 +218,7 @@ pub struct Child { impl crate::sealed::Sealed for Child {} impl AsInner for Child { + #[inline] fn as_inner(&self) -> &imp::Process { &self.handle } @@ -285,6 +285,7 @@ impl Write for ChildStdin { io::Write::is_write_vectored(&self) } + #[inline] fn flush(&mut self) -> io::Result<()> { (&*self).flush() } @@ -303,12 +304,14 @@ impl Write for &ChildStdin { self.inner.is_write_vectored() } + #[inline] fn flush(&mut self) -> io::Result<()> { Ok(()) } } impl AsInner for ChildStdin { + #[inline] fn as_inner(&self) -> &AnonPipe { &self.inner } @@ -357,6 +360,10 @@ impl Read for ChildStdout { self.inner.read(buf) } + fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + self.inner.read_buf(buf) + } + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.inner.read_vectored(bufs) } @@ -365,9 +372,14 @@ impl Read for ChildStdout { fn is_read_vectored(&self) -> bool { self.inner.is_read_vectored() } + + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + self.inner.read_to_end(buf) + } } impl AsInner for ChildStdout { + #[inline] fn as_inner(&self) -> &AnonPipe { &self.inner } @@ -416,6 +428,10 @@ impl Read for ChildStderr { self.inner.read(buf) } + fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + self.inner.read_buf(buf) + } + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.inner.read_vectored(bufs) } @@ -427,6 +443,7 @@ impl Read for ChildStderr { } impl AsInner for ChildStderr { + #[inline] fn as_inner(&self) -> &AnonPipe { &self.inner } @@ -463,15 +480,15 @@ impl fmt::Debug for ChildStderr { /// /// let output = if cfg!(target_os = "windows") { /// Command::new("cmd") -/// .args(["/C", "echo hello"]) -/// .output() -/// .expect("failed to execute process") +/// .args(["/C", "echo hello"]) +/// .output() +/// .expect("failed to execute process") /// } else { /// Command::new("sh") -/// .arg("-c") -/// .arg("echo hello") -/// .output() -/// .expect("failed to execute process") +/// .arg("-c") +/// .arg("echo hello") +/// .output() +/// .expect("failed to execute process") /// }; /// /// let hello = output.stdout; @@ -484,8 +501,7 @@ impl fmt::Debug for ChildStderr { /// use std::process::Command; /// /// let mut echo_hello = Command::new("sh"); -/// echo_hello.arg("-c") -/// .arg("echo hello"); +/// echo_hello.arg("-c").arg("echo hello"); /// let hello_1 = echo_hello.output().expect("failed to execute process"); /// let hello_2 = echo_hello.output().expect("failed to execute process"); /// ``` @@ -514,6 +530,7 @@ pub struct Command { inner: imp::Command, } +/// Allows extension traits within `std`. impl crate::sealed::Sealed for Command {} #[deprecated(note = "Process operations are not supported in the enclave.")] @@ -541,6 +558,14 @@ impl Command { /// but this has some implementation limitations on Windows /// (see issue #37519). /// + /// # Platform-specific behavior + /// + /// Note on Windows: For executable files with the .exe extension, + /// it can be omitted when specifying the program for this Command. + /// However, if the file has a different extension, + /// a filename including the extension needs to be provided, + /// otherwise the file won't be found. + /// /// # Examples /// /// Basic usage: @@ -549,8 +574,8 @@ impl Command { /// use std::process::Command; /// /// Command::new("sh") - /// .spawn() - /// .expect("sh command failed to start"); + /// .spawn() + /// .expect("sh command failed to start"); /// ``` pub fn new>(program: S) -> Command { Command { inner: imp::Command::new(program.as_ref()) } @@ -581,7 +606,7 @@ impl Command { /// /// Note that the argument is not passed through a shell, but given /// literally to the program. This means that shell syntax like quotes, - /// escaped characters, word splitting, glob patterns, substitution, etc. + /// escaped characters, word splitting, glob patterns, variable substitution, etc. /// have no effect. /// /// # Examples @@ -592,10 +617,10 @@ impl Command { /// use std::process::Command; /// /// Command::new("ls") - /// .arg("-l") - /// .arg("-a") - /// .spawn() - /// .expect("ls command failed to start"); + /// .arg("-l") + /// .arg("-a") + /// .spawn() + /// .expect("ls command failed to start"); /// ``` pub fn arg>(&mut self, arg: S) -> &mut Command { self.inner.arg(arg.as_ref()); @@ -610,7 +635,7 @@ impl Command { /// /// Note that the arguments are not passed through a shell, but given /// literally to the program. This means that shell syntax like quotes, - /// escaped characters, word splitting, glob patterns, substitution, etc. + /// escaped characters, word splitting, glob patterns, variable substitution, etc. /// have no effect. /// /// # Examples @@ -621,9 +646,9 @@ impl Command { /// use std::process::Command; /// /// Command::new("ls") - /// .args(["-l", "-a"]) - /// .spawn() - /// .expect("ls command failed to start"); + /// .args(["-l", "-a"]) + /// .spawn() + /// .expect("ls command failed to start"); /// ``` pub fn args(&mut self, args: I) -> &mut Command where @@ -636,10 +661,19 @@ impl Command { self } - /// Inserts or updates an environment variable mapping. + /// Inserts or updates an explicit environment variable mapping. /// - /// Note that environment variable names are case-insensitive (but case-preserving) on Windows, - /// and case-sensitive on all other platforms. + /// This method allows you to add an environment variable mapping to the spawned process or + /// overwrite a previously set value. You can use [`Command::envs`] to set multiple environment + /// variables simultaneously. + /// + /// Child processes will inherit environment variables from their parent process by default. + /// Environment variables explicitly set using [`Command::env`] take precedence over inherited + /// variables. You can disable environment variable inheritance entirely using + /// [`Command::env_clear`] or for a single key using [`Command::env_remove`]. + /// + /// Note that environment variable names are case-insensitive (but + /// case-preserving) on Windows and case-sensitive on all other platforms. /// /// # Examples /// @@ -649,9 +683,9 @@ impl Command { /// use std::process::Command; /// /// Command::new("ls") - /// .env("PATH", "/bin") - /// .spawn() - /// .expect("ls command failed to start"); + /// .env("PATH", "/bin") + /// .spawn() + /// .expect("ls command failed to start"); /// ``` pub fn env(&mut self, key: K, val: V) -> &mut Command where @@ -662,7 +696,19 @@ impl Command { self } - /// Adds or updates multiple environment variable mappings. + /// Inserts or updates multiple explicit environment variable mappings. + /// + /// This method allows you to add multiple environment variable mappings to the spawned process + /// or overwrite previously set values. You can use [`Command::env`] to set a single environment + /// variable. + /// + /// Child processes will inherit environment variables from their parent process by default. + /// Environment variables explicitly set using [`Command::envs`] take precedence over inherited + /// variables. You can disable environment variable inheritance entirely using + /// [`Command::env_clear`] or for a single key using [`Command::env_remove`]. + /// + /// Note that environment variable names are case-insensitive (but case-preserving) on Windows + /// and case-sensitive on all other platforms. /// /// # Examples /// @@ -679,12 +725,12 @@ impl Command { /// ).collect(); /// /// Command::new("printenv") - /// .stdin(Stdio::null()) - /// .stdout(Stdio::inherit()) - /// .env_clear() - /// .envs(&filtered_env) - /// .spawn() - /// .expect("printenv failed to start"); + /// .stdin(Stdio::null()) + /// .stdout(Stdio::inherit()) + /// .env_clear() + /// .envs(&filtered_env) + /// .spawn() + /// .expect("printenv failed to start"); /// ``` pub fn envs(&mut self, vars: I) -> &mut Command where @@ -698,7 +744,18 @@ impl Command { self } - /// Removes an environment variable mapping. + /// Removes an explicitly set environment variable and prevents inheriting it from a parent + /// process. + /// + /// This method will remove the explicit value of an environment variable set via + /// [`Command::env`] or [`Command::envs`]. In addition, it will prevent the spawned child + /// process from inheriting that environment variable from its parent process. + /// + /// After calling [`Command::env_remove`], the value associated with its key from + /// [`Command::get_envs`] will be [`None`]. + /// + /// To clear all explicitly set environment variables and disable all environment variable + /// inheritance, you can use [`Command::env_clear`]. /// /// # Examples /// @@ -708,16 +765,26 @@ impl Command { /// use std::process::Command; /// /// Command::new("ls") - /// .env_remove("PATH") - /// .spawn() - /// .expect("ls command failed to start"); + /// .env_remove("PATH") + /// .spawn() + /// .expect("ls command failed to start"); /// ``` pub fn env_remove>(&mut self, key: K) -> &mut Command { self.inner.env_mut().remove(key.as_ref()); self } - /// Clears the entire environment map for the child process. + /// Clears all explicitly set environment variables and prevents inheriting any parent process + /// environment variables. + /// + /// This method will remove all explicitly added environment variables set via [`Command::env`] + /// or [`Command::envs`]. In addition, it will prevent the spawned child process from inheriting + /// any environment variable from its parent process. + /// + /// After calling [`Command::env_clear`], the iterator from [`Command::get_envs`] will be + /// empty. + /// + /// You can use [`Command::env_remove`] to clear a single mapping. /// /// # Examples /// @@ -727,9 +794,9 @@ impl Command { /// use std::process::Command; /// /// Command::new("ls") - /// .env_clear() - /// .spawn() - /// .expect("ls command failed to start"); + /// .env_clear() + /// .spawn() + /// .expect("ls command failed to start"); /// ``` pub fn env_clear(&mut self) -> &mut Command { self.inner.env_mut().clear(); @@ -754,9 +821,9 @@ impl Command { /// use std::process::Command; /// /// Command::new("ls") - /// .current_dir("/bin") - /// .spawn() - /// .expect("ls command failed to start"); + /// .current_dir("/bin") + /// .spawn() + /// .expect("ls command failed to start"); /// ``` /// /// [`canonicalize`]: crate::fs::canonicalize @@ -784,9 +851,9 @@ impl Command { /// use std::process::{Command, Stdio}; /// /// Command::new("ls") - /// .stdin(Stdio::null()) - /// .spawn() - /// .expect("ls command failed to start"); + /// .stdin(Stdio::null()) + /// .spawn() + /// .expect("ls command failed to start"); /// ``` pub fn stdin>(&mut self, cfg: T) -> &mut Command { self.inner.stdin(cfg.into().0); @@ -812,9 +879,9 @@ impl Command { /// use std::process::{Command, Stdio}; /// /// Command::new("ls") - /// .stdout(Stdio::null()) - /// .spawn() - /// .expect("ls command failed to start"); + /// .stdout(Stdio::null()) + /// .spawn() + /// .expect("ls command failed to start"); /// ``` pub fn stdout>(&mut self, cfg: T) -> &mut Command { self.inner.stdout(cfg.into().0); @@ -840,9 +907,9 @@ impl Command { /// use std::process::{Command, Stdio}; /// /// Command::new("ls") - /// .stderr(Stdio::null()) - /// .spawn() - /// .expect("ls command failed to start"); + /// .stderr(Stdio::null()) + /// .spawn() + /// .expect("ls command failed to start"); /// ``` pub fn stderr>(&mut self, cfg: T) -> &mut Command { self.inner.stderr(cfg.into().0); @@ -861,8 +928,8 @@ impl Command { /// use std::process::Command; /// /// Command::new("ls") - /// .spawn() - /// .expect("ls command failed to start"); + /// .spawn() + /// .expect("ls command failed to start"); /// ``` pub fn spawn(&mut self) -> io::Result { self.inner.spawn(imp::Stdio::Inherit, true).map(Child::from_inner) @@ -882,9 +949,9 @@ impl Command { /// use std::process::Command; /// use std::io::{self, Write}; /// let output = Command::new("/bin/cat") - /// .arg("file.txt") - /// .output() - /// .expect("failed to execute process"); + /// .arg("file.txt") + /// .output() + /// .expect("failed to execute process"); /// /// println!("status: {}", output.status); /// io::stdout().write_all(&output.stdout).unwrap(); @@ -893,10 +960,8 @@ impl Command { /// assert!(output.status.success()); /// ``` pub fn output(&mut self) -> io::Result { - self.inner - .spawn(imp::Stdio::MakePipe, false) - .map(Child::from_inner) - .and_then(|p| p.wait_with_output()) + let (status, stdout, stderr) = self.inner.output()?; + Ok(Output { status: ExitStatus(status), stdout, stderr }) } /// Executes a command as a child process, waiting for it to finish and @@ -910,9 +975,9 @@ impl Command { /// use std::process::Command; /// /// let status = Command::new("/bin/cat") - /// .arg("file.txt") - /// .status() - /// .expect("failed to execute process"); + /// .arg("file.txt") + /// .status() + /// .expect("failed to execute process"); /// /// println!("process finished with: {status}"); /// @@ -961,17 +1026,21 @@ impl Command { CommandArgs { inner: self.inner.get_args() } } - /// Returns an iterator of the environment variables that will be set when - /// the process is spawned. + /// Returns an iterator of the environment variables explicitly set for the child process. + /// + /// Environment variables explicitly set using [`Command::env`], [`Command::envs`], and + /// [`Command::env_remove`] can be retrieved with this method. /// - /// Each element is a tuple `(&OsStr, Option<&OsStr>)`, where the first - /// value is the key, and the second is the value, which is [`None`] if - /// the environment variable is to be explicitly removed. + /// Note that this output does not include environment variables inherited from the parent + /// process. /// - /// This only includes environment variables explicitly set with - /// [`Command::env`], [`Command::envs`], and [`Command::env_remove`]. It - /// does not include environment variables that will be inherited by the - /// child process. + /// Each element is a tuple key/value pair `(&OsStr, Option<&OsStr>)`. A [`None`] value + /// indicates its key was explicitly removed via [`Command::env_remove`]. The associated key for + /// the [`None`] value will no longer inherit from its parent process. + /// + /// An empty iterator can indicate that no explicit mappings were added or that + /// [`Command::env_clear`] was called. After calling [`Command::env_clear`], the child process + /// will not inherit any environment variables from its parent process. /// /// # Examples /// @@ -1016,18 +1085,29 @@ impl fmt::Debug for Command { /// Format the program and arguments of a Command for display. Any /// non-utf8 data is lossily converted using the utf8 replacement /// character. + /// + /// The default format approximates a shell invocation of the program along with its + /// arguments. It does not include most of the other command properties. The output is not guaranteed to work + /// (e.g. due to lack of shell-escaping or differences in path resolution) + /// On some platforms you can use [the alternate syntax] to show more fields. + /// + /// Note that the debug implementation is platform-specific. + /// + /// [the alternate syntax]: fmt#sign0 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.inner.fmt(f) } } impl AsInner for Command { + #[inline] fn as_inner(&self) -> &imp::Command { &self.inner } } impl AsInnerMut for Command { + #[inline] fn as_inner_mut(&mut self) -> &mut imp::Command { &mut self.inner } @@ -1371,7 +1451,7 @@ impl From for Stdio { /// use std::fs::File; /// use std::process::Command; /// - /// // With the `foo.txt` file containing `Hello, world!" + /// // With the `foo.txt` file containing "Hello, world!" /// let file = File::open("foo.txt").unwrap(); /// /// let reverse = Command::new("rev") @@ -1386,6 +1466,66 @@ impl From for Stdio { } } +#[cfg(feature = "stdio")] +impl From for Stdio { + /// Redirect command stdout/stderr to our stdout + /// + /// # Examples + /// + /// ```rust + /// #![feature(exit_status_error)] + /// use std::io; + /// use std::process::Command; + /// + /// # fn test() -> Result<(), Box> { + /// let output = Command::new("whoami") + // "whoami" is a command which exists on both Unix and Windows, + // and which succeeds, producing some stdout output but no stderr. + /// .stdout(io::stdout()) + /// .output()?; + /// output.status.exit_ok()?; + /// assert!(output.stdout.is_empty()); + /// # Ok(()) + /// # } + /// # + /// # if cfg!(unix) { + /// # test().unwrap(); + /// # } + /// ``` + fn from(inherit: io::Stdout) -> Stdio { + Stdio::from_inner(inherit.into()) + } +} + +#[cfg(feature = "stdio")] +impl From for Stdio { + /// Redirect command stdout/stderr to our stderr + /// + /// # Examples + /// + /// ```rust + /// #![feature(exit_status_error)] + /// use std::io; + /// use std::process::Command; + /// + /// # fn test() -> Result<(), Box> { + /// let output = Command::new("whoami") + /// .stdout(io::stderr()) + /// .output()?; + /// output.status.exit_ok()?; + /// assert!(output.stdout.is_empty()); + /// # Ok(()) + /// # } + /// # + /// # if cfg!(unix) { + /// # test().unwrap(); + /// # } + /// ``` + fn from(inherit: io::Stderr) -> Stdio { + Stdio::from_inner(inherit.into()) + } +} + /// Describes the result of a process after it has terminated. /// /// This `struct` is used to represent the exit status or other termination of a child process. @@ -1419,6 +1559,14 @@ impl From for Stdio { #[derive(PartialEq, Eq, Clone, Copy, Debug)] pub struct ExitStatus(imp::ExitStatus); +/// The default value is one which indicates successful completion. +impl Default for ExitStatus { + fn default() -> Self { + // Ideally this would be done by ExitCode::default().into() but that is complicated. + ExitStatus::from_inner(imp::ExitStatus::default()) + } +} + /// Allows extension traits within `std`. impl crate::sealed::Sealed for ExitStatus {} @@ -1434,9 +1582,9 @@ impl ExitStatus { /// use std::process::Command; /// /// let status = Command::new("ls") - /// .arg("/dev/nonexistent") - /// .status() - /// .expect("ls could not be executed"); + /// .arg("/dev/nonexistent") + /// .status() + /// .expect("ls could not be executed"); /// /// println!("ls: {status}"); /// status.exit_ok().expect_err("/dev/nonexistent could be listed!"); @@ -1455,9 +1603,9 @@ impl ExitStatus { /// use std::process::Command; /// /// let status = Command::new("mkdir") - /// .arg("projects") - /// .status() - /// .expect("failed to execute mkdir"); + /// .arg("projects") + /// .status() + /// .expect("failed to execute mkdir"); /// /// if status.success() { /// println!("'projects/' directory created"); @@ -1487,13 +1635,13 @@ impl ExitStatus { /// use std::process::Command; /// /// let status = Command::new("mkdir") - /// .arg("projects") - /// .status() - /// .expect("failed to execute mkdir"); + /// .arg("projects") + /// .status() + /// .expect("failed to execute mkdir"); /// /// match status.code() { /// Some(code) => println!("Exited with status code: {code}"), - /// None => println!("Process terminated by signal") + /// None => println!("Process terminated by signal") /// } /// ``` #[must_use] @@ -1503,6 +1651,7 @@ impl ExitStatus { } impl AsInner for ExitStatus { + #[inline] fn as_inner(&self) -> &imp::ExitStatus { &self.0 } @@ -1618,10 +1767,9 @@ impl ExitStatusError { } } -#[allow(clippy::from_over_into)] -impl Into for ExitStatusError { - fn into(self) -> ExitStatus { - ExitStatus(self.0.into()) +impl From for ExitStatus { + fn from(error: ExitStatusError) -> Self { + Self(error.0.into()) } } @@ -1682,6 +1830,9 @@ impl crate::error::Error for ExitStatusError {} #[derive(Clone, Copy, Debug)] pub struct ExitCode(imp::ExitCode); +/// Allows extension traits within `std`. +impl crate::sealed::Sealed for ExitCode {} + impl ExitCode { /// The canonical `ExitCode` for successful termination on this platform. /// @@ -1721,7 +1872,7 @@ impl ExitCode { /// # use std::fmt; /// # enum UhOhError { GenericProblem, Specific, WithCode { exit_code: ExitCode, _x: () } } /// # impl fmt::Display for UhOhError { - /// # fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { unimplemented!() } + /// # fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { unimplemented!() } /// # } /// // there's no way to gracefully recover from an UhOhError, so we just /// // print a message and exit @@ -1755,6 +1906,13 @@ impl ExitCode { } } +/// The default value is [`ExitCode::SUCCESS`] +impl Default for ExitCode { + fn default() -> Self { + ExitCode::SUCCESS + } +} + impl From for ExitCode { /// Construct an `ExitCode` from an arbitrary u8 value. fn from(code: u8) -> Self { @@ -1763,6 +1921,7 @@ impl From for ExitCode { } impl AsInner for ExitCode { + #[inline] fn as_inner(&self) -> &imp::ExitCode { &self.0 } @@ -1776,8 +1935,8 @@ impl FromInner for ExitCode { #[deprecated(note = "Process operations are not supported in the enclave.")] impl Child { - /// Forces the child process to exit. If the child has already exited, an [`InvalidInput`] - /// error is returned. + /// Forces the child process to exit. If the child has already exited, `Ok(())` + /// is returned. /// /// The mapping to [`ErrorKind`]s is not part of the compatibility contract of the function. /// @@ -1792,7 +1951,7 @@ impl Child { /// /// let mut command = Command::new("yes"); /// if let Ok(mut child) = command.spawn() { - /// child.kill().expect("command wasn't running"); + /// child.kill().expect("command couldn't be killed"); /// } else { /// println!("yes command didn't start"); /// } @@ -2090,18 +2249,11 @@ pub fn id() -> u32 { /// standard library's runtime for convenience. Other runtimes are not required /// to provide similar functionality. #[cfg_attr(not(test), lang = "termination")] -#[rustc_on_unimplemented( - on( - all(not(bootstrap), cause = "MainFunctionType"), - message = "`main` has invalid return type `{Self}`", - label = "`main` can only return types that implement `{Termination}`" - ), - on( - bootstrap, - message = "`main` has invalid return type `{Self}`", - label = "`main` can only return types that implement `{Termination}`" - ) -)] +#[rustc_on_unimplemented(on( + cause = "MainFunctionType", + message = "`main` has invalid return type `{Self}`", + label = "`main` can only return types that implement `{Termination}`" +))] pub trait Termination { /// Is called to get the representation of the value as status code. /// This status code is returned to the operating system. diff --git a/sgx_tstd/src/sync/barrier.rs b/sgx_tstd/src/sync/barrier.rs index a9e0e8168..103ea0be8 100644 --- a/sgx_tstd/src/sync/barrier.rs +++ b/sgx_tstd/src/sync/barrier.rs @@ -30,9 +30,10 @@ use crate::sync::{Condvar, Mutex}; /// use std::sync::{Arc, Barrier}; /// use std::thread; /// -/// let mut handles = Vec::with_capacity(10); -/// let barrier = Arc::new(Barrier::new(10)); -/// for _ in 0..10 { +/// let n = 10; +/// let mut handles = Vec::with_capacity(n); +/// let barrier = Arc::new(Barrier::new(n)); +/// for _ in 0..n { /// let c = Arc::clone(&barrier); /// // The same messages will be printed together. /// // You will NOT see any interleaving. @@ -118,9 +119,10 @@ impl Barrier { /// use std::sync::{Arc, Barrier}; /// use std::thread; /// - /// let mut handles = Vec::with_capacity(10); - /// let barrier = Arc::new(Barrier::new(10)); - /// for _ in 0..10 { + /// let n = 10; + /// let mut handles = Vec::with_capacity(n); + /// let barrier = Arc::new(Barrier::new(n)); + /// for _ in 0..n { /// let c = Arc::clone(&barrier); /// // The same messages will be printed together. /// // You will NOT see any interleaving. @@ -140,11 +142,8 @@ impl Barrier { let local_gen = lock.generation_id; lock.count += 1; if lock.count < self.num_threads { - // We need a while loop to guard against spurious wakeups. - // https://en.wikipedia.org/wiki/Spurious_wakeup - while local_gen == lock.generation_id { - lock = self.cvar.wait(lock).unwrap(); - } + let _guard = + self.cvar.wait_while(lock, |state| local_gen == state.generation_id).unwrap(); BarrierWaitResult(false) } else { lock.count = 0; diff --git a/sgx_tstd/src/sync/condvar.rs b/sgx_tstd/src/sync/condvar.rs index 6d91c52d6..f763801fa 100644 --- a/sgx_tstd/src/sync/condvar.rs +++ b/sgx_tstd/src/sync/condvar.rs @@ -39,11 +39,11 @@ impl WaitTimeoutResult { /// /// # Examples /// - /// This example spawns a thread which will update the boolean value and - /// then wait 100 milliseconds before notifying the condvar. + /// This example spawns a thread which will sleep 20 milliseconds before + /// updating a boolean value and then notifying the condvar. /// - /// The main thread will wait with a timeout on the condvar and then leave - /// once the boolean has been updated and notified. + /// The main thread will wait with a 10 millisecond timeout on the condvar + /// and will leave the loop upon timeout. /// /// ``` /// use std::sync::{Arc, Condvar, Mutex}; @@ -67,14 +67,12 @@ impl WaitTimeoutResult { /// /// // Wait for the thread to start up. /// let (lock, cvar) = &*pair; - /// let mut started = lock.lock().unwrap(); /// loop { /// // Let's put a timeout on the condvar's wait. - /// let result = cvar.wait_timeout(started, Duration::from_millis(10)).unwrap(); - /// // 10 milliseconds have passed, or maybe the value changed! - /// started = result.0; - /// if *started == true { - /// // We received the notification and the value has been updated, we can leave. + /// let result = cvar.wait_timeout(lock.lock().unwrap(), Duration::from_millis(10)).unwrap(); + /// // 10 milliseconds have passed. + /// if result.1.timed_out() { + /// // timed out now and we can leave. /// break /// } /// } diff --git a/sgx_tstd/src/sync/condvar/tests.rs b/sgx_tstd/src/sync/condvar/tests.rs index b320d6a07..d4f565e15 100644 --- a/sgx_tstd/src/sync/condvar/tests.rs +++ b/sgx_tstd/src/sync/condvar/tests.rs @@ -58,7 +58,7 @@ fn notify_all() { let data = data.clone(); let tx = tx.clone(); thread::spawn(move || { - let &(ref lock, ref cond) = &*data; + let (lock, cond) = &*data; let mut cnt = lock.lock().unwrap(); *cnt += 1; if *cnt == N { @@ -72,7 +72,7 @@ fn notify_all() { } drop(tx); - let &(ref lock, ref cond) = &*data; + let (lock, cond) = &*data; rx.recv().unwrap(); let mut cnt = lock.lock().unwrap(); *cnt = 0; @@ -91,7 +91,7 @@ fn wait_while() { // Inside of our lock, spawn a new thread, and then wait for it to start. thread::spawn(move || { - let &(ref lock, ref cvar) = &*pair2; + let (lock, cvar) = &*pair2; let mut started = lock.lock().unwrap(); *started = true; // We notify the condvar that the value has changed. @@ -99,7 +99,7 @@ fn wait_while() { }); // Wait for the thread to start up. - let &(ref lock, ref cvar) = &*pair; + let (lock, cvar) = &*pair; let guard = cvar.wait_while(lock.lock().unwrap(), |started| !*started); assert!(*guard.unwrap()); } @@ -149,10 +149,10 @@ fn wait_timeout_while_wake() { let pair = Arc::new((Mutex::new(false), Condvar::new())); let pair_copy = pair.clone(); - let &(ref m, ref c) = &*pair; + let (m, c) = &*pair; let g = m.lock().unwrap(); let _t = thread::spawn(move || { - let &(ref lock, ref cvar) = &*pair_copy; + let (lock, cvar) = &*pair_copy; let mut started = lock.lock().unwrap(); thread::sleep(Duration::from_millis(1)); *started = true; diff --git a/sgx_tstd/src/sync/lazy_lock.rs b/sgx_tstd/src/sync/lazy_lock.rs index d513a088b..d57534d2d 100644 --- a/sgx_tstd/src/sync/lazy_lock.rs +++ b/sgx_tstd/src/sync/lazy_lock.rs @@ -15,20 +15,37 @@ // specific language governing permissions and limitations // under the License.. -use crate::cell::Cell; -use crate::fmt; +use crate::cell::UnsafeCell; +use crate::mem::ManuallyDrop; use crate::ops::Deref; use crate::panic::{RefUnwindSafe, UnwindSafe}; -use crate::sync::OnceLock; +use crate::sync::Once; +use crate::{fmt, ptr}; + +use super::once::ExclusiveState; + +// We use the state of a Once as discriminant value. Upon creation, the state is +// "incomplete" and `f` contains the initialization closure. In the first call to +// `call_once`, `f` is taken and run. If it succeeds, `value` is set and the state +// is changed to "complete". If it panics, the Once is poisoned, so none of the +// two fields is initialized. +union Data { + value: ManuallyDrop, + f: ManuallyDrop, +} /// A value which is initialized on the first access. /// -/// This type is a thread-safe `Lazy`, and can be used in statics. +/// This type is a thread-safe [`LazyCell`], and can be used in statics. +/// +/// [`LazyCell`]: crate::cell::LazyCell /// /// # Examples /// +/// Initialize static variables with `LazyLock`. +/// /// ``` -/// #![feature(once_cell)] +/// #![feature(lazy_cell)] /// /// use std::collections::HashMap; /// @@ -42,7 +59,7 @@ use crate::sync::OnceLock; /// m /// }); /// -/// fn main() { +/// fn needless_main() { /// println!("ready"); /// std::thread::spawn(|| { /// println!("{:?}", HASHMAP.get(&13)); @@ -56,20 +73,81 @@ use crate::sync::OnceLock; /// // Some("Hoyten") /// } /// ``` +/// Initialize fields with `LazyLock`. +/// ``` +/// #![feature(lazy_cell)] +/// +/// use std::sync::LazyLock; +/// +/// #[derive(Debug)] +/// struct UseCellLock { +/// number: LazyLock, +/// } +/// fn needless_main() { +/// let lock: LazyLock = LazyLock::new(|| 0u32); +/// +/// let data = UseCellLock { number: lock }; +/// println!("{}", *data.number); +/// } +/// ``` + pub struct LazyLock T> { - cell: OnceLock, - init: Cell>, + once: Once, + data: UnsafeCell>, } -impl LazyLock { +impl T> LazyLock { /// Creates a new lazy value with the given initializing /// function. + #[inline] pub const fn new(f: F) -> LazyLock { - LazyLock { cell: OnceLock::new(), init: Cell::new(Some(f)) } + LazyLock { once: Once::new(), data: UnsafeCell::new(Data { f: ManuallyDrop::new(f) }) } + } + + /// Creates a new lazy value that is already initialized. + #[inline] + #[cfg(feature = "unit_test")] + pub(crate) fn preinit(value: T) -> LazyLock { + let once = Once::new(); + once.call_once(|| {}); + LazyLock { once, data: UnsafeCell::new(Data { value: ManuallyDrop::new(value) }) } + } + + /// Consumes this `LazyLock` returning the stored value. + /// + /// Returns `Ok(value)` if `Lazy` is initialized and `Err(f)` otherwise. + /// + /// # Examples + /// + /// ``` + /// #![feature(lazy_cell)] + /// #![feature(lazy_cell_consume)] + /// + /// use std::sync::LazyLock; + /// + /// let hello = "Hello, World!".to_string(); + /// + /// let lazy = LazyLock::new(|| hello.to_uppercase()); + /// + /// assert_eq!(&*lazy, "HELLO, WORLD!"); + /// assert_eq!(LazyLock::into_inner(lazy).ok(), Some("HELLO, WORLD!".to_string())); + /// ``` + pub fn into_inner(mut this: Self) -> Result { + let state = this.once.state(); + match state { + ExclusiveState::Poisoned => panic!("LazyLock instance has previously been poisoned"), + state => { + let this = ManuallyDrop::new(this); + let data = unsafe { ptr::read(&this.data) }.into_inner(); + match state { + ExclusiveState::Incomplete => Err(ManuallyDrop::into_inner(unsafe { data.f })), + ExclusiveState::Complete => Ok(ManuallyDrop::into_inner(unsafe { data.value })), + ExclusiveState::Poisoned => unreachable!(), + } + } + } } -} -impl T> LazyLock { /// Forces the evaluation of this lazy value and /// returns a reference to result. This is equivalent /// to the `Deref` impl, but is explicit. @@ -77,7 +155,7 @@ impl T> LazyLock { /// # Examples /// /// ``` - /// #![feature(once_cell)] + /// #![feature(lazy_cell)] /// /// use std::sync::LazyLock; /// @@ -86,16 +164,58 @@ impl T> LazyLock { /// assert_eq!(LazyLock::force(&lazy), &92); /// assert_eq!(&*lazy, &92); /// ``` + #[inline] pub fn force(this: &LazyLock) -> &T { - this.cell.get_or_init(|| match this.init.take() { - Some(f) => f(), - None => panic!("Lazy instance has previously been poisoned"), - }) + this.once.call_once(|| { + // SAFETY: `call_once` only runs this closure once, ever. + let data = unsafe { &mut *this.data.get() }; + let f = unsafe { ManuallyDrop::take(&mut data.f) }; + let value = f(); + data.value = ManuallyDrop::new(value); + }); + + // SAFETY: + // There are four possible scenarios: + // * the closure was called and initialized `value`. + // * the closure was called and panicked, so this point is never reached. + // * the closure was not called, but a previous call initialized `value`. + // * the closure was not called because the Once is poisoned, so this point + // is never reached. + // So `value` has definitely been initialized and will not be modified again. + unsafe { &*(*this.data.get()).value } + } +} + +impl LazyLock { + /// Get the inner value if it has already been initialized. + fn get(&self) -> Option<&T> { + if self.once.is_completed() { + // SAFETY: + // The closure has been run successfully, so `value` has been initialized + // and will not be modified again. + Some(unsafe { &*(*self.data.get()).value }) + } else { + None + } + } +} + +impl Drop for LazyLock { + fn drop(&mut self) { + match self.once.state() { + ExclusiveState::Incomplete => unsafe { ManuallyDrop::drop(&mut self.data.get_mut().f) }, + ExclusiveState::Complete => unsafe { + ManuallyDrop::drop(&mut self.data.get_mut().value) + }, + ExclusiveState::Poisoned => {} + } } } impl T> Deref for LazyLock { type Target = T; + + #[inline] fn deref(&self) -> &T { LazyLock::force(self) } @@ -103,6 +223,7 @@ impl T> Deref for LazyLock { impl Default for LazyLock { /// Creates a new lazy value using `Default` as the initializing function. + #[inline] fn default() -> LazyLock { LazyLock::new(T::default) } @@ -110,20 +231,22 @@ impl Default for LazyLock { impl fmt::Debug for LazyLock { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Lazy").field("cell", &self.cell).finish_non_exhaustive() + let mut d = f.debug_tuple("LazyLock"); + match self.get() { + Some(v) => d.field(v), + None => d.field(&format_args!("")), + }; + d.finish() } } // We never create a `&F` from a `&LazyLock` so it is fine // to not impl `Sync` for `F` -// we do create a `&mut Option` in `force`, but this is -// properly synchronized, so it only happens once -// so it also does not contribute to this impl. -unsafe impl Sync for LazyLock where OnceLock: Sync {} +unsafe impl Sync for LazyLock {} // auto-derived `Send` impl is OK. -impl RefUnwindSafe for LazyLock where OnceLock: RefUnwindSafe {} -impl UnwindSafe for LazyLock where OnceLock: UnwindSafe {} +impl RefUnwindSafe for LazyLock {} +impl UnwindSafe for LazyLock {} #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/sync/lazy_lock/tests.rs b/sgx_tstd/src/sync/lazy_lock/tests.rs index 3d8752d14..2fc0bfac6 100644 --- a/sgx_tstd/src/sync/lazy_lock/tests.rs +++ b/sgx_tstd/src/sync/lazy_lock/tests.rs @@ -155,6 +155,12 @@ fn sync_lazy_poisoning() { } } +// Check that we can infer `T` from closure's type. +#[test_case] +fn lazy_type_inference() { + let _ = LazyCell::new(|| ()); +} + #[test_case] fn is_sync_send() { fn assert_traits() {} diff --git a/sgx_tstd/src/sync/mod.rs b/sgx_tstd/src/sync/mod.rs index a4ff39ddc..712c6988c 100644 --- a/sgx_tstd/src/sync/mod.rs +++ b/sgx_tstd/src/sync/mod.rs @@ -150,7 +150,9 @@ //! - [`Mutex`]: Mutual Exclusion mechanism, which ensures that at //! most one thread at a time is able to access some data. //! -//! - [`Once`]: Used for thread-safe, one-time initialization of a +//! - [`Once`]: Used for a thread-safe, one-time global initialization routine +//! +//! - [`OnceLock`]: Used for thread-safe, one-time initialization of a //! global variable. //! //! - [`RwLock`]: Provides a mutual exclusion mechanism which allows @@ -164,6 +166,7 @@ //! [`mpsc`]: crate::sync::mpsc //! [`Mutex`]: crate::sync::Mutex //! [`Once`]: crate::sync::Once +//! [`OnceLock`]: crate::sync::OnceLock //! [`RwLock`]: crate::sync::RwLock pub use alloc_crate::sync::{Arc, Weak}; @@ -181,14 +184,19 @@ pub use self::rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard}; pub use self::lazy_lock::LazyLock; pub use self::once_lock::OnceLock; +pub(crate) use self::remutex::{ReentrantMutex, ReentrantMutexGuard}; + #[cfg(feature = "thread")] pub mod mpsc; mod barrier; mod condvar; mod lazy_lock; +#[cfg(feature = "thread")] +mod mpmc; mod mutex; -mod once; +pub(crate) mod once; mod once_lock; mod poison; +mod remutex; mod rwlock; diff --git a/sgx_tstd/src/sync/mpmc/array.rs b/sgx_tstd/src/sync/mpmc/array.rs new file mode 100644 index 000000000..230db92c1 --- /dev/null +++ b/sgx_tstd/src/sync/mpmc/array.rs @@ -0,0 +1,583 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +//! Bounded channel based on a preallocated array. +//! +//! This flavor has a fixed, positive capacity. +//! +//! The implementation is based on Dmitry Vyukov's bounded MPMC queue. +//! +//! Source: +//! - +//! - + +use super::context::Context; +use super::error::*; +use super::select::{Operation, Selected, Token}; +use super::utils::{Backoff, CachePadded}; +use super::waker::SyncWaker; + +use crate::cell::UnsafeCell; +use crate::mem::MaybeUninit; +use crate::ptr; +use crate::sync::atomic::{self, AtomicUsize, Ordering}; +use crate::time::Instant; +#[cfg(not(feature = "untrusted_time"))] +use crate::untrusted::time::InstantEx; + +/// A slot in a channel. +struct Slot { + /// The current stamp. + stamp: AtomicUsize, + + /// The message in this slot. Either read out in `read` or dropped through + /// `discard_all_messages`. + msg: UnsafeCell>, +} + +/// The token type for the array flavor. +#[derive(Debug)] +pub(crate) struct ArrayToken { + /// Slot to read from or write to. + slot: *const u8, + + /// Stamp to store into the slot after reading or writing. + stamp: usize, +} + +impl Default for ArrayToken { + #[inline] + fn default() -> Self { + ArrayToken { slot: ptr::null(), stamp: 0 } + } +} + +/// Bounded channel based on a preallocated array. +pub(crate) struct Channel { + /// The head of the channel. + /// + /// This value is a "stamp" consisting of an index into the buffer, a mark bit, and a lap, but + /// packed into a single `usize`. The lower bits represent the index, while the upper bits + /// represent the lap. The mark bit in the head is always zero. + /// + /// Messages are popped from the head of the channel. + head: CachePadded, + + /// The tail of the channel. + /// + /// This value is a "stamp" consisting of an index into the buffer, a mark bit, and a lap, but + /// packed into a single `usize`. The lower bits represent the index, while the upper bits + /// represent the lap. The mark bit indicates that the channel is disconnected. + /// + /// Messages are pushed into the tail of the channel. + tail: CachePadded, + + /// The buffer holding slots. + buffer: Box<[Slot]>, + + /// The channel capacity. + cap: usize, + + /// A stamp with the value of `{ lap: 1, mark: 0, index: 0 }`. + one_lap: usize, + + /// If this bit is set in the tail, that means the channel is disconnected. + mark_bit: usize, + + /// Senders waiting while the channel is full. + senders: SyncWaker, + + /// Receivers waiting while the channel is empty and not disconnected. + receivers: SyncWaker, +} + +impl Channel { + /// Creates a bounded channel of capacity `cap`. + pub(crate) fn with_capacity(cap: usize) -> Self { + assert!(cap > 0, "capacity must be positive"); + + // Compute constants `mark_bit` and `one_lap`. + let mark_bit = (cap + 1).next_power_of_two(); + let one_lap = mark_bit * 2; + + // Head is initialized to `{ lap: 0, mark: 0, index: 0 }`. + let head = 0; + // Tail is initialized to `{ lap: 0, mark: 0, index: 0 }`. + let tail = 0; + + // Allocate a buffer of `cap` slots initialized + // with stamps. + let buffer: Box<[Slot]> = (0..cap) + .map(|i| { + // Set the stamp to `{ lap: 0, mark: 0, index: i }`. + Slot { stamp: AtomicUsize::new(i), msg: UnsafeCell::new(MaybeUninit::uninit()) } + }) + .collect(); + + Channel { + buffer, + cap, + one_lap, + mark_bit, + head: CachePadded::new(AtomicUsize::new(head)), + tail: CachePadded::new(AtomicUsize::new(tail)), + senders: SyncWaker::new(), + receivers: SyncWaker::new(), + } + } + + /// Attempts to reserve a slot for sending a message. + fn start_send(&self, token: &mut Token) -> bool { + let backoff = Backoff::new(); + let mut tail = self.tail.load(Ordering::Relaxed); + + loop { + // Check if the channel is disconnected. + if tail & self.mark_bit != 0 { + token.array.slot = ptr::null(); + token.array.stamp = 0; + return true; + } + + // Deconstruct the tail. + let index = tail & (self.mark_bit - 1); + let lap = tail & !(self.one_lap - 1); + + // Inspect the corresponding slot. + debug_assert!(index < self.buffer.len()); + let slot = unsafe { self.buffer.get_unchecked(index) }; + let stamp = slot.stamp.load(Ordering::Acquire); + + // If the tail and the stamp match, we may attempt to push. + if tail == stamp { + let new_tail = if index + 1 < self.cap { + // Same lap, incremented index. + // Set to `{ lap: lap, mark: 0, index: index + 1 }`. + tail + 1 + } else { + // One lap forward, index wraps around to zero. + // Set to `{ lap: lap.wrapping_add(1), mark: 0, index: 0 }`. + lap.wrapping_add(self.one_lap) + }; + + // Try moving the tail. + match self.tail.compare_exchange_weak( + tail, + new_tail, + Ordering::SeqCst, + Ordering::Relaxed, + ) { + Ok(_) => { + // Prepare the token for the follow-up call to `write`. + token.array.slot = slot as *const Slot as *const u8; + token.array.stamp = tail + 1; + return true; + } + Err(_) => { + backoff.spin_light(); + tail = self.tail.load(Ordering::Relaxed); + } + } + } else if stamp.wrapping_add(self.one_lap) == tail + 1 { + atomic::fence(Ordering::SeqCst); + let head = self.head.load(Ordering::Relaxed); + + // If the head lags one lap behind the tail as well... + if head.wrapping_add(self.one_lap) == tail { + // ...then the channel is full. + return false; + } + + backoff.spin_light(); + tail = self.tail.load(Ordering::Relaxed); + } else { + // Snooze because we need to wait for the stamp to get updated. + backoff.spin_heavy(); + tail = self.tail.load(Ordering::Relaxed); + } + } + } + + /// Writes a message into the channel. + pub(crate) unsafe fn write(&self, token: &mut Token, msg: T) -> Result<(), T> { + // If there is no slot, the channel is disconnected. + if token.array.slot.is_null() { + return Err(msg); + } + + let slot: &Slot = &*(token.array.slot as *const Slot); + + // Write the message into the slot and update the stamp. + slot.msg.get().write(MaybeUninit::new(msg)); + slot.stamp.store(token.array.stamp, Ordering::Release); + + // Wake a sleeping receiver. + self.receivers.notify(); + Ok(()) + } + + /// Attempts to reserve a slot for receiving a message. + fn start_recv(&self, token: &mut Token) -> bool { + let backoff = Backoff::new(); + let mut head = self.head.load(Ordering::Relaxed); + + loop { + // Deconstruct the head. + let index = head & (self.mark_bit - 1); + let lap = head & !(self.one_lap - 1); + + // Inspect the corresponding slot. + debug_assert!(index < self.buffer.len()); + let slot = unsafe { self.buffer.get_unchecked(index) }; + let stamp = slot.stamp.load(Ordering::Acquire); + + // If the stamp is ahead of the head by 1, we may attempt to pop. + if head + 1 == stamp { + let new = if index + 1 < self.cap { + // Same lap, incremented index. + // Set to `{ lap: lap, mark: 0, index: index + 1 }`. + head + 1 + } else { + // One lap forward, index wraps around to zero. + // Set to `{ lap: lap.wrapping_add(1), mark: 0, index: 0 }`. + lap.wrapping_add(self.one_lap) + }; + + // Try moving the head. + match self.head.compare_exchange_weak( + head, + new, + Ordering::SeqCst, + Ordering::Relaxed, + ) { + Ok(_) => { + // Prepare the token for the follow-up call to `read`. + token.array.slot = slot as *const Slot as *const u8; + token.array.stamp = head.wrapping_add(self.one_lap); + return true; + } + Err(_) => { + backoff.spin_light(); + head = self.head.load(Ordering::Relaxed); + } + } + } else if stamp == head { + atomic::fence(Ordering::SeqCst); + let tail = self.tail.load(Ordering::Relaxed); + + // If the tail equals the head, that means the channel is empty. + if (tail & !self.mark_bit) == head { + // If the channel is disconnected... + if tail & self.mark_bit != 0 { + // ...then receive an error. + token.array.slot = ptr::null(); + token.array.stamp = 0; + return true; + } else { + // Otherwise, the receive operation is not ready. + return false; + } + } + + backoff.spin_light(); + head = self.head.load(Ordering::Relaxed); + } else { + // Snooze because we need to wait for the stamp to get updated. + backoff.spin_heavy(); + head = self.head.load(Ordering::Relaxed); + } + } + } + + /// Reads a message from the channel. + pub(crate) unsafe fn read(&self, token: &mut Token) -> Result { + if token.array.slot.is_null() { + // The channel is disconnected. + return Err(()); + } + + let slot: &Slot = &*(token.array.slot as *const Slot); + + // Read the message from the slot and update the stamp. + let msg = slot.msg.get().read().assume_init(); + slot.stamp.store(token.array.stamp, Ordering::Release); + + // Wake a sleeping sender. + self.senders.notify(); + Ok(msg) + } + + /// Attempts to send a message into the channel. + pub(crate) fn try_send(&self, msg: T) -> Result<(), TrySendError> { + let token = &mut Token::default(); + if self.start_send(token) { + unsafe { self.write(token, msg).map_err(TrySendError::Disconnected) } + } else { + Err(TrySendError::Full(msg)) + } + } + + /// Sends a message into the channel. + pub(crate) fn send( + &self, + msg: T, + deadline: Option, + ) -> Result<(), SendTimeoutError> { + let token = &mut Token::default(); + loop { + // Try sending a message. + if self.start_send(token) { + let res = unsafe { self.write(token, msg) }; + return res.map_err(SendTimeoutError::Disconnected); + } + + if let Some(d) = deadline { + if Instant::now() >= d { + return Err(SendTimeoutError::Timeout(msg)); + } + } + + Context::with(|cx| { + // Prepare for blocking until a receiver wakes us up. + let oper = Operation::hook(token); + self.senders.register(oper, cx); + + // Has the channel become ready just now? + if !self.is_full() || self.is_disconnected() { + let _ = cx.try_select(Selected::Aborted); + } + + // Block the current thread. + let sel = cx.wait_until(deadline); + + match sel { + Selected::Waiting => unreachable!(), + Selected::Aborted | Selected::Disconnected => { + self.senders.unregister(oper).unwrap(); + } + Selected::Operation(_) => {} + } + }); + } + } + + /// Attempts to receive a message without blocking. + pub(crate) fn try_recv(&self) -> Result { + let token = &mut Token::default(); + + if self.start_recv(token) { + unsafe { self.read(token).map_err(|_| TryRecvError::Disconnected) } + } else { + Err(TryRecvError::Empty) + } + } + + /// Receives a message from the channel. + pub(crate) fn recv(&self, deadline: Option) -> Result { + let token = &mut Token::default(); + loop { + // Try receiving a message. + if self.start_recv(token) { + let res = unsafe { self.read(token) }; + return res.map_err(|_| RecvTimeoutError::Disconnected); + } + + if let Some(d) = deadline { + if Instant::now() >= d { + return Err(RecvTimeoutError::Timeout); + } + } + + Context::with(|cx| { + // Prepare for blocking until a sender wakes us up. + let oper = Operation::hook(token); + self.receivers.register(oper, cx); + + // Has the channel become ready just now? + if !self.is_empty() || self.is_disconnected() { + let _ = cx.try_select(Selected::Aborted); + } + + // Block the current thread. + let sel = cx.wait_until(deadline); + + match sel { + Selected::Waiting => unreachable!(), + Selected::Aborted | Selected::Disconnected => { + self.receivers.unregister(oper).unwrap(); + // If the channel was disconnected, we still have to check for remaining + // messages. + } + Selected::Operation(_) => {} + } + }); + } + } + + /// Returns the current number of messages inside the channel. + pub(crate) fn len(&self) -> usize { + loop { + // Load the tail, then load the head. + let tail = self.tail.load(Ordering::SeqCst); + let head = self.head.load(Ordering::SeqCst); + + // If the tail didn't change, we've got consistent values to work with. + if self.tail.load(Ordering::SeqCst) == tail { + let hix = head & (self.mark_bit - 1); + let tix = tail & (self.mark_bit - 1); + + return if hix < tix { + tix - hix + } else if hix > tix { + self.cap - hix + tix + } else if (tail & !self.mark_bit) == head { + 0 + } else { + self.cap + }; + } + } + } + + /// Returns the capacity of the channel. + #[allow(clippy::unnecessary_wraps)] // This is intentional. + pub(crate) fn capacity(&self) -> Option { + Some(self.cap) + } + + /// Disconnects senders and wakes up all blocked receivers. + /// + /// Returns `true` if this call disconnected the channel. + pub(crate) fn disconnect_senders(&self) -> bool { + let tail = self.tail.fetch_or(self.mark_bit, Ordering::SeqCst); + + if tail & self.mark_bit == 0 { + self.receivers.disconnect(); + true + } else { + false + } + } + + /// Disconnects receivers and wakes up all blocked senders. + /// + /// Returns `true` if this call disconnected the channel. + /// + /// # Safety + /// May only be called once upon dropping the last receiver. The + /// destruction of all other receivers must have been observed with acquire + /// ordering or stronger. + pub(crate) unsafe fn disconnect_receivers(&self) -> bool { + let tail = self.tail.fetch_or(self.mark_bit, Ordering::SeqCst); + let disconnected = if tail & self.mark_bit == 0 { + self.senders.disconnect(); + true + } else { + false + }; + + self.discard_all_messages(tail); + disconnected + } + + /// Discards all messages. + /// + /// `tail` should be the current (and therefore last) value of `tail`. + /// + /// # Panicking + /// If a destructor panics, the remaining messages are leaked, matching the + /// behaviour of the unbounded channel. + /// + /// # Safety + /// This method must only be called when dropping the last receiver. The + /// destruction of all other receivers must have been observed with acquire + /// ordering or stronger. + unsafe fn discard_all_messages(&self, tail: usize) { + debug_assert!(self.is_disconnected()); + + // Only receivers modify `head`, so since we are the last one, + // this value will not change and will not be observed (since + // no new messages can be sent after disconnection). + let mut head = self.head.load(Ordering::Relaxed); + let tail = tail & !self.mark_bit; + + let backoff = Backoff::new(); + loop { + // Deconstruct the head. + let index = head & (self.mark_bit - 1); + let lap = head & !(self.one_lap - 1); + + // Inspect the corresponding slot. + debug_assert!(index < self.buffer.len()); + let slot = unsafe { self.buffer.get_unchecked(index) }; + let stamp = slot.stamp.load(Ordering::Acquire); + + // If the stamp is ahead of the head by 1, we may drop the message. + if head + 1 == stamp { + head = if index + 1 < self.cap { + // Same lap, incremented index. + // Set to `{ lap: lap, mark: 0, index: index + 1 }`. + head + 1 + } else { + // One lap forward, index wraps around to zero. + // Set to `{ lap: lap.wrapping_add(1), mark: 0, index: 0 }`. + lap.wrapping_add(self.one_lap) + }; + + unsafe { + (*slot.msg.get()).assume_init_drop(); + } + // If the tail equals the head, that means the channel is empty. + } else if tail == head { + return; + // Otherwise, a sender is about to write into the slot, so we need + // to wait for it to update the stamp. + } else { + backoff.spin_heavy(); + } + } + } + + /// Returns `true` if the channel is disconnected. + pub(crate) fn is_disconnected(&self) -> bool { + self.tail.load(Ordering::SeqCst) & self.mark_bit != 0 + } + + /// Returns `true` if the channel is empty. + pub(crate) fn is_empty(&self) -> bool { + let head = self.head.load(Ordering::SeqCst); + let tail = self.tail.load(Ordering::SeqCst); + + // Is the tail equal to the head? + // + // Note: If the head changes just before we load the tail, that means there was a moment + // when the channel was not empty, so it is safe to just return `false`. + (tail & !self.mark_bit) == head + } + + /// Returns `true` if the channel is full. + pub(crate) fn is_full(&self) -> bool { + let tail = self.tail.load(Ordering::SeqCst); + let head = self.head.load(Ordering::SeqCst); + + // Is the head lagging one lap behind tail? + // + // Note: If the tail changes just before we load the head, that means there was a moment + // when the channel was not full, so it is safe to just return `false`. + head.wrapping_add(self.one_lap) == tail & !self.mark_bit + } +} diff --git a/sgx_tstd/src/sync/mpmc/context.rs b/sgx_tstd/src/sync/mpmc/context.rs new file mode 100644 index 000000000..14cac3546 --- /dev/null +++ b/sgx_tstd/src/sync/mpmc/context.rs @@ -0,0 +1,174 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +//! Thread-local channel context. + +use super::select::Selected; +use super::waker::current_thread_id; + +use crate::cell::Cell; +use crate::ptr; +use crate::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; +use crate::sync::Arc; +use crate::thread::{self, Thread}; +use crate::time::Instant; +#[cfg(not(feature = "untrusted_time"))] +use crate::untrusted::time::InstantEx; + +/// Thread-local context. +#[derive(Debug, Clone)] +pub struct Context { + inner: Arc, +} + +/// Inner representation of `Context`. +#[derive(Debug)] +struct Inner { + /// Selected operation. + select: AtomicUsize, + + /// A slot into which another thread may store a pointer to its `Packet`. + packet: AtomicPtr<()>, + + /// Thread handle. + thread: Thread, + + /// Thread id. + thread_id: usize, +} + +impl Context { + /// Creates a new context for the duration of the closure. + #[inline] + pub fn with(f: F) -> R + where + F: FnOnce(&Context) -> R, + { + thread_local! { + /// Cached thread-local context. + static CONTEXT: Cell> = Cell::new(Some(Context::new())); + } + + let mut f = Some(f); + let mut f = |cx: &Context| -> R { + let f = f.take().unwrap(); + f(cx) + }; + + CONTEXT + .try_with(|cell| match cell.take() { + None => f(&Context::new()), + Some(cx) => { + cx.reset(); + let res = f(&cx); + cell.set(Some(cx)); + res + } + }) + .unwrap_or_else(|_| f(&Context::new())) + } + + /// Creates a new `Context`. + #[cold] + fn new() -> Context { + Context { + inner: Arc::new(Inner { + select: AtomicUsize::new(Selected::Waiting.into()), + packet: AtomicPtr::new(ptr::null_mut()), + thread: thread::current(), + thread_id: current_thread_id(), + }), + } + } + + /// Resets `select` and `packet`. + #[inline] + fn reset(&self) { + self.inner.select.store(Selected::Waiting.into(), Ordering::Release); + self.inner.packet.store(ptr::null_mut(), Ordering::Release); + } + + /// Attempts to select an operation. + /// + /// On failure, the previously selected operation is returned. + #[inline] + pub fn try_select(&self, select: Selected) -> Result<(), Selected> { + self.inner + .select + .compare_exchange( + Selected::Waiting.into(), + select.into(), + Ordering::AcqRel, + Ordering::Acquire, + ) + .map(|_| ()) + .map_err(|e| e.into()) + } + + /// Stores a packet. + /// + /// This method must be called after `try_select` succeeds and there is a packet to provide. + #[inline] + pub fn store_packet(&self, packet: *mut ()) { + if !packet.is_null() { + self.inner.packet.store(packet, Ordering::Release); + } + } + + /// Waits until an operation is selected and returns it. + /// + /// If the deadline is reached, `Selected::Aborted` will be selected. + #[inline] + pub fn wait_until(&self, deadline: Option) -> Selected { + loop { + // Check whether an operation has been selected. + let sel = Selected::from(self.inner.select.load(Ordering::Acquire)); + if sel != Selected::Waiting { + return sel; + } + + // If there's a deadline, park the current thread until the deadline is reached. + if let Some(end) = deadline { + let now = Instant::now(); + + if now < end { + thread::park_timeout(end - now); + } else { + // The deadline has been reached. Try aborting select. + return match self.try_select(Selected::Aborted) { + Ok(()) => Selected::Aborted, + Err(s) => s, + }; + } + } else { + thread::park(); + } + } + } + + /// Unparks the thread this context belongs to. + #[inline] + pub fn unpark(&self) { + self.inner.thread.unpark(); + } + + /// Returns the id of the thread this context belongs to. + #[inline] + pub fn thread_id(&self) -> usize { + self.inner.thread_id + } +} diff --git a/sgx_tstd/src/sync/mpmc/counter.rs b/sgx_tstd/src/sync/mpmc/counter.rs new file mode 100644 index 000000000..c34cb55bf --- /dev/null +++ b/sgx_tstd/src/sync/mpmc/counter.rs @@ -0,0 +1,154 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT 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 crate::ops; +use crate::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; +use crate::sys; + +/// Reference counter internals. +struct Counter { + /// The number of senders associated with the channel. + senders: AtomicUsize, + + /// The number of receivers associated with the channel. + receivers: AtomicUsize, + + /// Set to `true` if the last sender or the last receiver reference deallocates the channel. + destroy: AtomicBool, + + /// The internal channel. + chan: C, +} + +/// Wraps a channel into the reference counter. +pub(crate) fn new(chan: C) -> (Sender, Receiver) { + let counter = Box::into_raw(Box::new(Counter { + senders: AtomicUsize::new(1), + receivers: AtomicUsize::new(1), + destroy: AtomicBool::new(false), + chan, + })); + let s = Sender { counter }; + let r = Receiver { counter }; + (s, r) +} + +/// The sending side. +pub(crate) struct Sender { + counter: *mut Counter, +} + +impl Sender { + /// Returns the internal `Counter`. + fn counter(&self) -> &Counter { + unsafe { &*self.counter } + } + + /// Acquires another sender reference. + pub(crate) fn acquire(&self) -> Sender { + let count = self.counter().senders.fetch_add(1, Ordering::Relaxed); + + // Cloning senders and calling `mem::forget` on the clones could potentially overflow the + // counter. It's very difficult to recover sensibly from such degenerate scenarios so we + // just abort when the count becomes very large. + if count > isize::MAX as usize { + sys::abort_internal(); + } + + Sender { counter: self.counter } + } + + /// Releases the sender reference. + /// + /// Function `disconnect` will be called if this is the last sender reference. + pub(crate) unsafe fn release bool>(&self, disconnect: F) { + if self.counter().senders.fetch_sub(1, Ordering::AcqRel) == 1 { + disconnect(&self.counter().chan); + + if self.counter().destroy.swap(true, Ordering::AcqRel) { + drop(Box::from_raw(self.counter)); + } + } + } +} + +impl ops::Deref for Sender { + type Target = C; + + fn deref(&self) -> &C { + &self.counter().chan + } +} + +impl PartialEq for Sender { + fn eq(&self, other: &Sender) -> bool { + self.counter == other.counter + } +} + +/// The receiving side. +pub(crate) struct Receiver { + counter: *mut Counter, +} + +impl Receiver { + /// Returns the internal `Counter`. + fn counter(&self) -> &Counter { + unsafe { &*self.counter } + } + + /// Acquires another receiver reference. + pub(crate) fn acquire(&self) -> Receiver { + let count = self.counter().receivers.fetch_add(1, Ordering::Relaxed); + + // Cloning receivers and calling `mem::forget` on the clones could potentially overflow the + // counter. It's very difficult to recover sensibly from such degenerate scenarios so we + // just abort when the count becomes very large. + if count > isize::MAX as usize { + sys::abort_internal(); + } + + Receiver { counter: self.counter } + } + + /// Releases the receiver reference. + /// + /// Function `disconnect` will be called if this is the last receiver reference. + pub(crate) unsafe fn release bool>(&self, disconnect: F) { + if self.counter().receivers.fetch_sub(1, Ordering::AcqRel) == 1 { + disconnect(&self.counter().chan); + + if self.counter().destroy.swap(true, Ordering::AcqRel) { + drop(Box::from_raw(self.counter)); + } + } + } +} + +impl ops::Deref for Receiver { + type Target = C; + + fn deref(&self) -> &C { + &self.counter().chan + } +} + +impl PartialEq for Receiver { + fn eq(&self, other: &Receiver) -> bool { + self.counter == other.counter + } +} diff --git a/sgx_tstd/src/sync/mpmc/error.rs b/sgx_tstd/src/sync/mpmc/error.rs new file mode 100644 index 000000000..28e1fe42f --- /dev/null +++ b/sgx_tstd/src/sync/mpmc/error.rs @@ -0,0 +1,63 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT 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 crate::error; +use crate::fmt; + +pub use crate::sync::mpsc::{RecvError, RecvTimeoutError, SendError, TryRecvError, TrySendError}; + +/// An error returned from the [`send_timeout`] method. +/// +/// The error contains the message being sent so it can be recovered. +/// +/// [`send_timeout`]: super::Sender::send_timeout +#[derive(PartialEq, Eq, Clone, Copy)] +pub enum SendTimeoutError { + /// The message could not be sent because the channel is full and the operation timed out. + /// + /// If this is a zero-capacity channel, then the error indicates that there was no receiver + /// available to receive the message and the operation timed out. + Timeout(T), + + /// The message could not be sent because the channel is disconnected. + Disconnected(T), +} + +impl fmt::Debug for SendTimeoutError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + "SendTimeoutError(..)".fmt(f) + } +} + +impl fmt::Display for SendTimeoutError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self { + SendTimeoutError::Timeout(..) => "timed out waiting on send operation".fmt(f), + SendTimeoutError::Disconnected(..) => "sending on a disconnected channel".fmt(f), + } + } +} + +impl error::Error for SendTimeoutError {} + +impl From> for SendTimeoutError { + fn from(err: SendError) -> SendTimeoutError { + match err { + SendError(e) => SendTimeoutError::Disconnected(e), + } + } +} diff --git a/sgx_tstd/src/sync/mpmc/list.rs b/sgx_tstd/src/sync/mpmc/list.rs new file mode 100644 index 000000000..07285b673 --- /dev/null +++ b/sgx_tstd/src/sync/mpmc/list.rs @@ -0,0 +1,669 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +//! Unbounded channel implemented as a linked list. + +use super::context::Context; +use super::error::*; +use super::select::{Operation, Selected, Token}; +use super::utils::{Backoff, CachePadded}; +use super::waker::SyncWaker; + +use crate::cell::UnsafeCell; +use crate::marker::PhantomData; +use crate::mem::MaybeUninit; +use crate::ptr; +use crate::sync::atomic::{self, AtomicPtr, AtomicUsize, Ordering}; +use crate::time::Instant; +#[cfg(not(feature = "untrusted_time"))] +use crate::untrusted::time::InstantEx; + +// Bits indicating the state of a slot: +// * If a message has been written into the slot, `WRITE` is set. +// * If a message has been read from the slot, `READ` is set. +// * If the block is being destroyed, `DESTROY` is set. +const WRITE: usize = 1; +const READ: usize = 2; +const DESTROY: usize = 4; + +// Each block covers one "lap" of indices. +const LAP: usize = 32; +// The maximum number of messages a block can hold. +const BLOCK_CAP: usize = LAP - 1; +// How many lower bits are reserved for metadata. +const SHIFT: usize = 1; +// Has two different purposes: +// * If set in head, indicates that the block is not the last one. +// * If set in tail, indicates that the channel is disconnected. +const MARK_BIT: usize = 1; + +/// A slot in a block. +struct Slot { + /// The message. + msg: UnsafeCell>, + + /// The state of the slot. + state: AtomicUsize, +} + +impl Slot { + /// Waits until a message is written into the slot. + fn wait_write(&self) { + let backoff = Backoff::new(); + while self.state.load(Ordering::Acquire) & WRITE == 0 { + backoff.spin_heavy(); + } + } +} + +/// A block in a linked list. +/// +/// Each block in the list can hold up to `BLOCK_CAP` messages. +struct Block { + /// The next block in the linked list. + next: AtomicPtr>, + + /// Slots for messages. + slots: [Slot; BLOCK_CAP], +} + +impl Block { + /// Creates an empty block. + fn new() -> Block { + // SAFETY: This is safe because: + // [1] `Block::next` (AtomicPtr) may be safely zero initialized. + // [2] `Block::slots` (Array) may be safely zero initialized because of [3, 4]. + // [3] `Slot::msg` (UnsafeCell) may be safely zero initialized because it + // holds a MaybeUninit. + // [4] `Slot::state` (AtomicUsize) may be safely zero initialized. + unsafe { MaybeUninit::zeroed().assume_init() } + } + + /// Waits until the next pointer is set. + fn wait_next(&self) -> *mut Block { + let backoff = Backoff::new(); + loop { + let next = self.next.load(Ordering::Acquire); + if !next.is_null() { + return next; + } + backoff.spin_heavy(); + } + } + + /// Sets the `DESTROY` bit in slots starting from `start` and destroys the block. + unsafe fn destroy(this: *mut Block, start: usize) { + // It is not necessary to set the `DESTROY` bit in the last slot because that slot has + // begun destruction of the block. + for i in start..BLOCK_CAP - 1 { + let slot = (*this).slots.get_unchecked(i); + + // Mark the `DESTROY` bit if a thread is still using the slot. + if slot.state.load(Ordering::Acquire) & READ == 0 + && slot.state.fetch_or(DESTROY, Ordering::AcqRel) & READ == 0 + { + // If a thread is still using the slot, it will continue destruction of the block. + return; + } + } + + // No thread is using the block, now it is safe to destroy it. + drop(Box::from_raw(this)); + } +} + +/// A position in a channel. +#[derive(Debug)] +struct Position { + /// The index in the channel. + index: AtomicUsize, + + /// The block in the linked list. + block: AtomicPtr>, +} + +/// The token type for the list flavor. +#[derive(Debug)] +pub(crate) struct ListToken { + /// The block of slots. + block: *const u8, + + /// The offset into the block. + offset: usize, +} + +impl Default for ListToken { + #[inline] + fn default() -> Self { + ListToken { block: ptr::null(), offset: 0 } + } +} + +/// Unbounded channel implemented as a linked list. +/// +/// Each message sent into the channel is assigned a sequence number, i.e. an index. Indices are +/// represented as numbers of type `usize` and wrap on overflow. +/// +/// Consecutive messages are grouped into blocks in order to put less pressure on the allocator and +/// improve cache efficiency. +pub(crate) struct Channel { + /// The head of the channel. + head: CachePadded>, + + /// The tail of the channel. + tail: CachePadded>, + + /// Receivers waiting while the channel is empty and not disconnected. + receivers: SyncWaker, + + /// Indicates that dropping a `Channel` may drop messages of type `T`. + _marker: PhantomData, +} + +impl Channel { + /// Creates a new unbounded channel. + pub(crate) fn new() -> Self { + Channel { + head: CachePadded::new(Position { + block: AtomicPtr::new(ptr::null_mut()), + index: AtomicUsize::new(0), + }), + tail: CachePadded::new(Position { + block: AtomicPtr::new(ptr::null_mut()), + index: AtomicUsize::new(0), + }), + receivers: SyncWaker::new(), + _marker: PhantomData, + } + } + + /// Attempts to reserve a slot for sending a message. + fn start_send(&self, token: &mut Token) -> bool { + let backoff = Backoff::new(); + let mut tail = self.tail.index.load(Ordering::Acquire); + let mut block = self.tail.block.load(Ordering::Acquire); + let mut next_block = None; + + loop { + // Check if the channel is disconnected. + if tail & MARK_BIT != 0 { + token.list.block = ptr::null(); + return true; + } + + // Calculate the offset of the index into the block. + let offset = (tail >> SHIFT) % LAP; + + // If we reached the end of the block, wait until the next one is installed. + if offset == BLOCK_CAP { + backoff.spin_heavy(); + tail = self.tail.index.load(Ordering::Acquire); + block = self.tail.block.load(Ordering::Acquire); + continue; + } + + // If we're going to have to install the next block, allocate it in advance in order to + // make the wait for other threads as short as possible. + if offset + 1 == BLOCK_CAP && next_block.is_none() { + next_block = Some(Box::new(Block::::new())); + } + + // If this is the first message to be sent into the channel, we need to allocate the + // first block and install it. + if block.is_null() { + let new = Box::into_raw(Box::new(Block::::new())); + + if self + .tail + .block + .compare_exchange(block, new, Ordering::Release, Ordering::Relaxed) + .is_ok() + { + self.head.block.store(new, Ordering::Release); + block = new; + } else { + next_block = unsafe { Some(Box::from_raw(new)) }; + tail = self.tail.index.load(Ordering::Acquire); + block = self.tail.block.load(Ordering::Acquire); + continue; + } + } + + let new_tail = tail + (1 << SHIFT); + + // Try advancing the tail forward. + match self.tail.index.compare_exchange_weak( + tail, + new_tail, + Ordering::SeqCst, + Ordering::Acquire, + ) { + Ok(_) => unsafe { + // If we've reached the end of the block, install the next one. + if offset + 1 == BLOCK_CAP { + let next_block = Box::into_raw(next_block.unwrap()); + self.tail.block.store(next_block, Ordering::Release); + self.tail.index.fetch_add(1 << SHIFT, Ordering::Release); + (*block).next.store(next_block, Ordering::Release); + } + + token.list.block = block as *const u8; + token.list.offset = offset; + return true; + }, + Err(_) => { + backoff.spin_light(); + tail = self.tail.index.load(Ordering::Acquire); + block = self.tail.block.load(Ordering::Acquire); + } + } + } + } + + /// Writes a message into the channel. + pub(crate) unsafe fn write(&self, token: &mut Token, msg: T) -> Result<(), T> { + // If there is no slot, the channel is disconnected. + if token.list.block.is_null() { + return Err(msg); + } + + // Write the message into the slot. + let block = token.list.block as *mut Block; + let offset = token.list.offset; + let slot = (*block).slots.get_unchecked(offset); + slot.msg.get().write(MaybeUninit::new(msg)); + slot.state.fetch_or(WRITE, Ordering::Release); + + // Wake a sleeping receiver. + self.receivers.notify(); + Ok(()) + } + + /// Attempts to reserve a slot for receiving a message. + fn start_recv(&self, token: &mut Token) -> bool { + let backoff = Backoff::new(); + let mut head = self.head.index.load(Ordering::Acquire); + let mut block = self.head.block.load(Ordering::Acquire); + + loop { + // Calculate the offset of the index into the block. + let offset = (head >> SHIFT) % LAP; + + // If we reached the end of the block, wait until the next one is installed. + if offset == BLOCK_CAP { + backoff.spin_heavy(); + head = self.head.index.load(Ordering::Acquire); + block = self.head.block.load(Ordering::Acquire); + continue; + } + + let mut new_head = head + (1 << SHIFT); + + if new_head & MARK_BIT == 0 { + atomic::fence(Ordering::SeqCst); + let tail = self.tail.index.load(Ordering::Relaxed); + + // If the tail equals the head, that means the channel is empty. + if head >> SHIFT == tail >> SHIFT { + // If the channel is disconnected... + if tail & MARK_BIT != 0 { + // ...then receive an error. + token.list.block = ptr::null(); + return true; + } else { + // Otherwise, the receive operation is not ready. + return false; + } + } + + // If head and tail are not in the same block, set `MARK_BIT` in head. + if (head >> SHIFT) / LAP != (tail >> SHIFT) / LAP { + new_head |= MARK_BIT; + } + } + + // The block can be null here only if the first message is being sent into the channel. + // In that case, just wait until it gets initialized. + if block.is_null() { + backoff.spin_heavy(); + head = self.head.index.load(Ordering::Acquire); + block = self.head.block.load(Ordering::Acquire); + continue; + } + + // Try moving the head index forward. + match self.head.index.compare_exchange_weak( + head, + new_head, + Ordering::SeqCst, + Ordering::Acquire, + ) { + Ok(_) => unsafe { + // If we've reached the end of the block, move to the next one. + if offset + 1 == BLOCK_CAP { + let next = (*block).wait_next(); + let mut next_index = (new_head & !MARK_BIT).wrapping_add(1 << SHIFT); + if !(*next).next.load(Ordering::Relaxed).is_null() { + next_index |= MARK_BIT; + } + + self.head.block.store(next, Ordering::Release); + self.head.index.store(next_index, Ordering::Release); + } + + token.list.block = block as *const u8; + token.list.offset = offset; + return true; + }, + Err(_) => { + backoff.spin_light(); + head = self.head.index.load(Ordering::Acquire); + block = self.head.block.load(Ordering::Acquire); + } + } + } + } + + /// Reads a message from the channel. + pub(crate) unsafe fn read(&self, token: &mut Token) -> Result { + if token.list.block.is_null() { + // The channel is disconnected. + return Err(()); + } + + // Read the message. + let block = token.list.block as *mut Block; + let offset = token.list.offset; + let slot = (*block).slots.get_unchecked(offset); + slot.wait_write(); + let msg = slot.msg.get().read().assume_init(); + + // Destroy the block if we've reached the end, or if another thread wanted to destroy but + // couldn't because we were busy reading from the slot. + if offset + 1 == BLOCK_CAP { + Block::destroy(block, 0); + } else if slot.state.fetch_or(READ, Ordering::AcqRel) & DESTROY != 0 { + Block::destroy(block, offset + 1); + } + + Ok(msg) + } + + /// Attempts to send a message into the channel. + pub(crate) fn try_send(&self, msg: T) -> Result<(), TrySendError> { + self.send(msg, None).map_err(|err| match err { + SendTimeoutError::Disconnected(msg) => TrySendError::Disconnected(msg), + SendTimeoutError::Timeout(_) => unreachable!(), + }) + } + + /// Sends a message into the channel. + pub(crate) fn send( + &self, + msg: T, + _deadline: Option, + ) -> Result<(), SendTimeoutError> { + let token = &mut Token::default(); + assert!(self.start_send(token)); + unsafe { self.write(token, msg).map_err(SendTimeoutError::Disconnected) } + } + + /// Attempts to receive a message without blocking. + pub(crate) fn try_recv(&self) -> Result { + let token = &mut Token::default(); + + if self.start_recv(token) { + unsafe { self.read(token).map_err(|_| TryRecvError::Disconnected) } + } else { + Err(TryRecvError::Empty) + } + } + + /// Receives a message from the channel. + pub(crate) fn recv(&self, deadline: Option) -> Result { + let token = &mut Token::default(); + loop { + if self.start_recv(token) { + unsafe { + return self.read(token).map_err(|_| RecvTimeoutError::Disconnected); + } + } + + if let Some(d) = deadline { + if Instant::now() >= d { + return Err(RecvTimeoutError::Timeout); + } + } + + // Prepare for blocking until a sender wakes us up. + Context::with(|cx| { + let oper = Operation::hook(token); + self.receivers.register(oper, cx); + + // Has the channel become ready just now? + if !self.is_empty() || self.is_disconnected() { + let _ = cx.try_select(Selected::Aborted); + } + + // Block the current thread. + let sel = cx.wait_until(deadline); + + match sel { + Selected::Waiting => unreachable!(), + Selected::Aborted | Selected::Disconnected => { + self.receivers.unregister(oper).unwrap(); + // If the channel was disconnected, we still have to check for remaining + // messages. + } + Selected::Operation(_) => {} + } + }); + } + } + + /// Returns the current number of messages inside the channel. + pub(crate) fn len(&self) -> usize { + loop { + // Load the tail index, then load the head index. + let mut tail = self.tail.index.load(Ordering::SeqCst); + let mut head = self.head.index.load(Ordering::SeqCst); + + // If the tail index didn't change, we've got consistent indices to work with. + if self.tail.index.load(Ordering::SeqCst) == tail { + // Erase the lower bits. + tail &= !((1 << SHIFT) - 1); + head &= !((1 << SHIFT) - 1); + + // Fix up indices if they fall onto block ends. + if (tail >> SHIFT) & (LAP - 1) == LAP - 1 { + tail = tail.wrapping_add(1 << SHIFT); + } + if (head >> SHIFT) & (LAP - 1) == LAP - 1 { + head = head.wrapping_add(1 << SHIFT); + } + + // Rotate indices so that head falls into the first block. + let lap = (head >> SHIFT) / LAP; + tail = tail.wrapping_sub((lap * LAP) << SHIFT); + head = head.wrapping_sub((lap * LAP) << SHIFT); + + // Remove the lower bits. + tail >>= SHIFT; + head >>= SHIFT; + + // Return the difference minus the number of blocks between tail and head. + return tail - head - tail / LAP; + } + } + } + + /// Returns the capacity of the channel. + pub(crate) fn capacity(&self) -> Option { + None + } + + /// Disconnects senders and wakes up all blocked receivers. + /// + /// Returns `true` if this call disconnected the channel. + pub(crate) fn disconnect_senders(&self) -> bool { + let tail = self.tail.index.fetch_or(MARK_BIT, Ordering::SeqCst); + + if tail & MARK_BIT == 0 { + self.receivers.disconnect(); + true + } else { + false + } + } + + /// Disconnects receivers. + /// + /// Returns `true` if this call disconnected the channel. + pub(crate) fn disconnect_receivers(&self) -> bool { + let tail = self.tail.index.fetch_or(MARK_BIT, Ordering::SeqCst); + + if tail & MARK_BIT == 0 { + // If receivers are dropped first, discard all messages to free + // memory eagerly. + self.discard_all_messages(); + true + } else { + false + } + } + + /// Discards all messages. + /// + /// This method should only be called when all receivers are dropped. + fn discard_all_messages(&self) { + let backoff = Backoff::new(); + let mut tail = self.tail.index.load(Ordering::Acquire); + loop { + let offset = (tail >> SHIFT) % LAP; + if offset != BLOCK_CAP { + break; + } + + // New updates to tail will be rejected by MARK_BIT and aborted unless it's + // at boundary. We need to wait for the updates take affect otherwise there + // can be memory leaks. + backoff.spin_heavy(); + tail = self.tail.index.load(Ordering::Acquire); + } + + let mut head = self.head.index.load(Ordering::Acquire); + let mut block = self.head.block.load(Ordering::Acquire); + + // If we're going to be dropping messages we need to synchronize with initialization + if head >> SHIFT != tail >> SHIFT { + // The block can be null here only if a sender is in the process of initializing the + // channel while another sender managed to send a message by inserting it into the + // semi-initialized channel and advanced the tail. + // In that case, just wait until it gets initialized. + while block.is_null() { + backoff.spin_heavy(); + block = self.head.block.load(Ordering::Acquire); + } + } + + unsafe { + // Drop all messages between head and tail and deallocate the heap-allocated blocks. + while head >> SHIFT != tail >> SHIFT { + let offset = (head >> SHIFT) % LAP; + + if offset < BLOCK_CAP { + // Drop the message in the slot. + let slot = (*block).slots.get_unchecked(offset); + slot.wait_write(); + let p = &mut *slot.msg.get(); + p.as_mut_ptr().drop_in_place(); + } else { + (*block).wait_next(); + // Deallocate the block and move to the next one. + let next = (*block).next.load(Ordering::Acquire); + drop(Box::from_raw(block)); + block = next; + } + + head = head.wrapping_add(1 << SHIFT); + } + + // Deallocate the last remaining block. + if !block.is_null() { + drop(Box::from_raw(block)); + } + } + head &= !MARK_BIT; + self.head.block.store(ptr::null_mut(), Ordering::Release); + self.head.index.store(head, Ordering::Release); + } + + /// Returns `true` if the channel is disconnected. + pub(crate) fn is_disconnected(&self) -> bool { + self.tail.index.load(Ordering::SeqCst) & MARK_BIT != 0 + } + + /// Returns `true` if the channel is empty. + pub(crate) fn is_empty(&self) -> bool { + let head = self.head.index.load(Ordering::SeqCst); + let tail = self.tail.index.load(Ordering::SeqCst); + head >> SHIFT == tail >> SHIFT + } + + /// Returns `true` if the channel is full. + pub(crate) fn is_full(&self) -> bool { + false + } +} + +impl Drop for Channel { + fn drop(&mut self) { + let mut head = self.head.index.load(Ordering::Relaxed); + let mut tail = self.tail.index.load(Ordering::Relaxed); + let mut block = self.head.block.load(Ordering::Relaxed); + + // Erase the lower bits. + head &= !((1 << SHIFT) - 1); + tail &= !((1 << SHIFT) - 1); + + unsafe { + // Drop all messages between head and tail and deallocate the heap-allocated blocks. + while head != tail { + let offset = (head >> SHIFT) % LAP; + + if offset < BLOCK_CAP { + // Drop the message in the slot. + let slot = (*block).slots.get_unchecked(offset); + let p = &mut *slot.msg.get(); + p.as_mut_ptr().drop_in_place(); + } else { + // Deallocate the block and move to the next one. + let next = (*block).next.load(Ordering::Relaxed); + drop(Box::from_raw(block)); + block = next; + } + + head = head.wrapping_add(1 << SHIFT); + } + + // Deallocate the last remaining block. + if !block.is_null() { + drop(Box::from_raw(block)); + } + } + } +} diff --git a/sgx_tstd/src/sync/mpmc/mod.rs b/sgx_tstd/src/sync/mpmc/mod.rs new file mode 100644 index 000000000..f1cead50f --- /dev/null +++ b/sgx_tstd/src/sync/mpmc/mod.rs @@ -0,0 +1,449 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +//! Multi-producer multi-consumer channels. + +// This module is not currently exposed publicly, but is used +// as the implementation for the channels in `sync::mpsc`. The +// implementation comes from the crossbeam-channel crate: +// +// Copyright (c) 2019 The Crossbeam Project Developers +// +// Permission is hereby granted, free of charge, to any +// person obtaining a copy of this software and associated +// documentation files (the "Software"), to deal in the +// Software without restriction, including without +// limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of +// the Software, and to permit persons to whom the Software +// is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice +// shall be included in all copies or substantial portions +// of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +mod array; +mod context; +mod counter; +mod error; +mod list; +mod select; +mod utils; +mod waker; +mod zero; + +use crate::fmt; +use crate::panic::{RefUnwindSafe, UnwindSafe}; +use crate::time::{Duration, Instant}; +#[cfg(not(feature = "untrusted_time"))] +use crate::untrusted::time::InstantEx; +pub use error::*; + +/// Creates a channel of unbounded capacity. +/// +/// This channel has a growable buffer that can hold any number of messages at a time. +pub fn channel() -> (Sender, Receiver) { + let (s, r) = counter::new(list::Channel::new()); + let s = Sender { flavor: SenderFlavor::List(s) }; + let r = Receiver { flavor: ReceiverFlavor::List(r) }; + (s, r) +} + +/// Creates a channel of bounded capacity. +/// +/// This channel has a buffer that can hold at most `cap` messages at a time. +/// +/// A special case is zero-capacity channel, which cannot hold any messages. Instead, send and +/// receive operations must appear at the same time in order to pair up and pass the message over. +pub fn sync_channel(cap: usize) -> (Sender, Receiver) { + if cap == 0 { + let (s, r) = counter::new(zero::Channel::new()); + let s = Sender { flavor: SenderFlavor::Zero(s) }; + let r = Receiver { flavor: ReceiverFlavor::Zero(r) }; + (s, r) + } else { + let (s, r) = counter::new(array::Channel::with_capacity(cap)); + let s = Sender { flavor: SenderFlavor::Array(s) }; + let r = Receiver { flavor: ReceiverFlavor::Array(r) }; + (s, r) + } +} + +/// The sending side of a channel. +pub struct Sender { + flavor: SenderFlavor, +} + +/// Sender flavors. +enum SenderFlavor { + /// Bounded channel based on a preallocated array. + Array(counter::Sender>), + + /// Unbounded channel implemented as a linked list. + List(counter::Sender>), + + /// Zero-capacity channel. + Zero(counter::Sender>), +} + +unsafe impl Send for Sender {} +unsafe impl Sync for Sender {} + +impl UnwindSafe for Sender {} +impl RefUnwindSafe for Sender {} + +impl Sender { + /// Attempts to send a message into the channel without blocking. + /// + /// This method will either send a message into the channel immediately or return an error if + /// the channel is full or disconnected. The returned error contains the original message. + /// + /// If called on a zero-capacity channel, this method will send the message only if there + /// happens to be a receive operation on the other side of the channel at the same time. + pub fn try_send(&self, msg: T) -> Result<(), TrySendError> { + match &self.flavor { + SenderFlavor::Array(chan) => chan.try_send(msg), + SenderFlavor::List(chan) => chan.try_send(msg), + SenderFlavor::Zero(chan) => chan.try_send(msg), + } + } + + /// Blocks the current thread until a message is sent or the channel is disconnected. + /// + /// If the channel is full and not disconnected, this call will block until the send operation + /// can proceed. If the channel becomes disconnected, this call will wake up and return an + /// error. The returned error contains the original message. + /// + /// If called on a zero-capacity channel, this method will wait for a receive operation to + /// appear on the other side of the channel. + pub fn send(&self, msg: T) -> Result<(), SendError> { + match &self.flavor { + SenderFlavor::Array(chan) => chan.send(msg, None), + SenderFlavor::List(chan) => chan.send(msg, None), + SenderFlavor::Zero(chan) => chan.send(msg, None), + } + .map_err(|err| match err { + SendTimeoutError::Disconnected(msg) => SendError(msg), + SendTimeoutError::Timeout(_) => unreachable!(), + }) + } +} + +// The methods below are not used by `sync::mpsc`, but +// are useful and we'll likely want to expose them +// eventually +#[allow(unused)] +impl Sender { + /// Waits for a message to be sent into the channel, but only for a limited time. + /// + /// If the channel is full and not disconnected, this call will block until the send operation + /// can proceed or the operation times out. If the channel becomes disconnected, this call will + /// wake up and return an error. The returned error contains the original message. + /// + /// If called on a zero-capacity channel, this method will wait for a receive operation to + /// appear on the other side of the channel. + pub fn send_timeout(&self, msg: T, timeout: Duration) -> Result<(), SendTimeoutError> { + match Instant::now().checked_add(timeout) { + Some(deadline) => self.send_deadline(msg, deadline), + // So far in the future that it's practically the same as waiting indefinitely. + None => self.send(msg).map_err(SendTimeoutError::from), + } + } + + /// Waits for a message to be sent into the channel, but only until a given deadline. + /// + /// If the channel is full and not disconnected, this call will block until the send operation + /// can proceed or the operation times out. If the channel becomes disconnected, this call will + /// wake up and return an error. The returned error contains the original message. + /// + /// If called on a zero-capacity channel, this method will wait for a receive operation to + /// appear on the other side of the channel. + pub fn send_deadline(&self, msg: T, deadline: Instant) -> Result<(), SendTimeoutError> { + match &self.flavor { + SenderFlavor::Array(chan) => chan.send(msg, Some(deadline)), + SenderFlavor::List(chan) => chan.send(msg, Some(deadline)), + SenderFlavor::Zero(chan) => chan.send(msg, Some(deadline)), + } + } + + /// Returns `true` if the channel is empty. + /// + /// Note: Zero-capacity channels are always empty. + pub fn is_empty(&self) -> bool { + match &self.flavor { + SenderFlavor::Array(chan) => chan.is_empty(), + SenderFlavor::List(chan) => chan.is_empty(), + SenderFlavor::Zero(chan) => chan.is_empty(), + } + } + + /// Returns `true` if the channel is full. + /// + /// Note: Zero-capacity channels are always full. + pub fn is_full(&self) -> bool { + match &self.flavor { + SenderFlavor::Array(chan) => chan.is_full(), + SenderFlavor::List(chan) => chan.is_full(), + SenderFlavor::Zero(chan) => chan.is_full(), + } + } + + /// Returns the number of messages in the channel. + pub fn len(&self) -> usize { + match &self.flavor { + SenderFlavor::Array(chan) => chan.len(), + SenderFlavor::List(chan) => chan.len(), + SenderFlavor::Zero(chan) => chan.len(), + } + } + + /// If the channel is bounded, returns its capacity. + pub fn capacity(&self) -> Option { + match &self.flavor { + SenderFlavor::Array(chan) => chan.capacity(), + SenderFlavor::List(chan) => chan.capacity(), + SenderFlavor::Zero(chan) => chan.capacity(), + } + } + + /// Returns `true` if senders belong to the same channel. + pub fn same_channel(&self, other: &Sender) -> bool { + match (&self.flavor, &other.flavor) { + (SenderFlavor::Array(ref a), SenderFlavor::Array(ref b)) => a == b, + (SenderFlavor::List(ref a), SenderFlavor::List(ref b)) => a == b, + (SenderFlavor::Zero(ref a), SenderFlavor::Zero(ref b)) => a == b, + _ => false, + } + } +} + +impl Drop for Sender { + fn drop(&mut self) { + unsafe { + match &self.flavor { + SenderFlavor::Array(chan) => chan.release(|c| c.disconnect_senders()), + SenderFlavor::List(chan) => chan.release(|c| c.disconnect_senders()), + SenderFlavor::Zero(chan) => chan.release(|c| c.disconnect()), + } + } + } +} + +impl Clone for Sender { + fn clone(&self) -> Self { + let flavor = match &self.flavor { + SenderFlavor::Array(chan) => SenderFlavor::Array(chan.acquire()), + SenderFlavor::List(chan) => SenderFlavor::List(chan.acquire()), + SenderFlavor::Zero(chan) => SenderFlavor::Zero(chan.acquire()), + }; + + Sender { flavor } + } +} + +impl fmt::Debug for Sender { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("Sender { .. }") + } +} + +/// The receiving side of a channel. +pub struct Receiver { + flavor: ReceiverFlavor, +} + +/// Receiver flavors. +enum ReceiverFlavor { + /// Bounded channel based on a preallocated array. + Array(counter::Receiver>), + + /// Unbounded channel implemented as a linked list. + List(counter::Receiver>), + + /// Zero-capacity channel. + Zero(counter::Receiver>), +} + +unsafe impl Send for Receiver {} +unsafe impl Sync for Receiver {} + +impl UnwindSafe for Receiver {} +impl RefUnwindSafe for Receiver {} + +impl Receiver { + /// Attempts to receive a message from the channel without blocking. + /// + /// This method will either receive a message from the channel immediately or return an error + /// if the channel is empty. + /// + /// If called on a zero-capacity channel, this method will receive a message only if there + /// happens to be a send operation on the other side of the channel at the same time. + pub fn try_recv(&self) -> Result { + match &self.flavor { + ReceiverFlavor::Array(chan) => chan.try_recv(), + ReceiverFlavor::List(chan) => chan.try_recv(), + ReceiverFlavor::Zero(chan) => chan.try_recv(), + } + } + + /// Blocks the current thread until a message is received or the channel is empty and + /// disconnected. + /// + /// If the channel is empty and not disconnected, this call will block until the receive + /// operation can proceed. If the channel is empty and becomes disconnected, this call will + /// wake up and return an error. + /// + /// If called on a zero-capacity channel, this method will wait for a send operation to appear + /// on the other side of the channel. + pub fn recv(&self) -> Result { + match &self.flavor { + ReceiverFlavor::Array(chan) => chan.recv(None), + ReceiverFlavor::List(chan) => chan.recv(None), + ReceiverFlavor::Zero(chan) => chan.recv(None), + } + .map_err(|_| RecvError) + } + + /// Waits for a message to be received from the channel, but only for a limited time. + /// + /// If the channel is empty and not disconnected, this call will block until the receive + /// operation can proceed or the operation times out. If the channel is empty and becomes + /// disconnected, this call will wake up and return an error. + /// + /// If called on a zero-capacity channel, this method will wait for a send operation to appear + /// on the other side of the channel. + pub fn recv_timeout(&self, timeout: Duration) -> Result { + match Instant::now().checked_add(timeout) { + Some(deadline) => self.recv_deadline(deadline), + // So far in the future that it's practically the same as waiting indefinitely. + None => self.recv().map_err(RecvTimeoutError::from), + } + } + + /// Waits for a message to be received from the channel, but only for a limited time. + /// + /// If the channel is empty and not disconnected, this call will block until the receive + /// operation can proceed or the operation times out. If the channel is empty and becomes + /// disconnected, this call will wake up and return an error. + /// + /// If called on a zero-capacity channel, this method will wait for a send operation to appear + /// on the other side of the channel. + pub fn recv_deadline(&self, deadline: Instant) -> Result { + match &self.flavor { + ReceiverFlavor::Array(chan) => chan.recv(Some(deadline)), + ReceiverFlavor::List(chan) => chan.recv(Some(deadline)), + ReceiverFlavor::Zero(chan) => chan.recv(Some(deadline)), + } + } +} + +// The methods below are not used by `sync::mpsc`, but +// are useful and we'll likely want to expose them +// eventually +#[allow(unused)] +impl Receiver { + /// Returns `true` if the channel is empty. + /// + /// Note: Zero-capacity channels are always empty. + pub fn is_empty(&self) -> bool { + match &self.flavor { + ReceiverFlavor::Array(chan) => chan.is_empty(), + ReceiverFlavor::List(chan) => chan.is_empty(), + ReceiverFlavor::Zero(chan) => chan.is_empty(), + } + } + + /// Returns `true` if the channel is full. + /// + /// Note: Zero-capacity channels are always full. + pub fn is_full(&self) -> bool { + match &self.flavor { + ReceiverFlavor::Array(chan) => chan.is_full(), + ReceiverFlavor::List(chan) => chan.is_full(), + ReceiverFlavor::Zero(chan) => chan.is_full(), + } + } + + /// Returns the number of messages in the channel. + pub fn len(&self) -> usize { + match &self.flavor { + ReceiverFlavor::Array(chan) => chan.len(), + ReceiverFlavor::List(chan) => chan.len(), + ReceiverFlavor::Zero(chan) => chan.len(), + } + } + + /// If the channel is bounded, returns its capacity. + pub fn capacity(&self) -> Option { + match &self.flavor { + ReceiverFlavor::Array(chan) => chan.capacity(), + ReceiverFlavor::List(chan) => chan.capacity(), + ReceiverFlavor::Zero(chan) => chan.capacity(), + } + } + + /// Returns `true` if receivers belong to the same channel. + pub fn same_channel(&self, other: &Receiver) -> bool { + match (&self.flavor, &other.flavor) { + (ReceiverFlavor::Array(a), ReceiverFlavor::Array(b)) => a == b, + (ReceiverFlavor::List(a), ReceiverFlavor::List(b)) => a == b, + (ReceiverFlavor::Zero(a), ReceiverFlavor::Zero(b)) => a == b, + _ => false, + } + } +} + +impl Drop for Receiver { + fn drop(&mut self) { + unsafe { + match &self.flavor { + ReceiverFlavor::Array(chan) => chan.release(|c| c.disconnect_receivers()), + ReceiverFlavor::List(chan) => chan.release(|c| c.disconnect_receivers()), + ReceiverFlavor::Zero(chan) => chan.release(|c| c.disconnect()), + } + } + } +} + +impl Clone for Receiver { + fn clone(&self) -> Self { + let flavor = match &self.flavor { + ReceiverFlavor::Array(chan) => ReceiverFlavor::Array(chan.acquire()), + ReceiverFlavor::List(chan) => ReceiverFlavor::List(chan.acquire()), + ReceiverFlavor::Zero(chan) => ReceiverFlavor::Zero(chan.acquire()), + }; + + Receiver { flavor } + } +} + +impl fmt::Debug for Receiver { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("Receiver { .. }") + } +} diff --git a/sgx_tstd/src/sync/mpmc/select.rs b/sgx_tstd/src/sync/mpmc/select.rs new file mode 100644 index 000000000..94e20eb53 --- /dev/null +++ b/sgx_tstd/src/sync/mpmc/select.rs @@ -0,0 +1,89 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +/// Temporary data that gets initialized during a blocking operation, and is consumed by +/// `read` or `write`. +/// +/// Each field contains data associated with a specific channel flavor. +#[derive(Debug, Default)] +pub struct Token { + pub(crate) array: super::array::ArrayToken, + pub(crate) list: super::list::ListToken, + #[allow(dead_code)] + pub(crate) zero: super::zero::ZeroToken, +} + +/// Identifier associated with an operation by a specific thread on a specific channel. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Operation(usize); + +impl Operation { + /// Creates an operation identifier from a mutable reference. + /// + /// This function essentially just turns the address of the reference into a number. The + /// reference should point to a variable that is specific to the thread and the operation, + /// and is alive for the entire duration of a blocking operation. + #[inline] + pub fn hook(r: &mut T) -> Operation { + let val = r as *mut T as usize; + // Make sure that the pointer address doesn't equal the numerical representation of + // `Selected::{Waiting, Aborted, Disconnected}`. + assert!(val > 2); + Operation(val) + } +} + +/// Current state of a blocking operation. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Selected { + /// Still waiting for an operation. + Waiting, + + /// The attempt to block the current thread has been aborted. + Aborted, + + /// An operation became ready because a channel is disconnected. + Disconnected, + + /// An operation became ready because a message can be sent or received. + Operation(Operation), +} + +impl From for Selected { + #[inline] + fn from(val: usize) -> Selected { + match val { + 0 => Selected::Waiting, + 1 => Selected::Aborted, + 2 => Selected::Disconnected, + oper => Selected::Operation(Operation(oper)), + } + } +} + +#[allow(clippy::from_over_into)] +impl Into for Selected { + #[inline] + fn into(self) -> usize { + match self { + Selected::Waiting => 0, + Selected::Aborted => 1, + Selected::Disconnected => 2, + Selected::Operation(Operation(val)) => val, + } + } +} diff --git a/sgx_tstd/src/sync/mpmc/utils.rs b/sgx_tstd/src/sync/mpmc/utils.rs new file mode 100644 index 000000000..998b1bd65 --- /dev/null +++ b/sgx_tstd/src/sync/mpmc/utils.rs @@ -0,0 +1,107 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT 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 crate::cell::Cell; +use crate::ops::{Deref, DerefMut}; + +/// Pads and aligns a value to the length of a cache line. +#[derive(Clone, Copy, Default, Hash, PartialEq, Eq)] +// Starting from Intel's Sandy Bridge, spatial prefetcher is now pulling pairs of 64-byte cache +// lines at a time, so we have to align to 128 bytes rather than 64. +// +// Sources: +// - https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-optimization-manual.pdf +// - https://github.com/facebook/folly/blob/1b5288e6eea6df074758f877c849b6e73bbb9fbb/folly/lang/Align.h#L107 +// +// ARM's big.LITTLE architecture has asymmetric cores and "big" cores have 128-byte cache line size. +// +// Sources: +// - https://www.mono-project.com/news/2016/09/12/arm64-icache/ +// +// powerpc64 has 128-byte cache line size. +// +// Sources: +// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_ppc64x.go#L9 +#[repr(align(128))] +pub struct CachePadded { + value: T, +} + +impl CachePadded { + /// Pads and aligns a value to the length of a cache line. + pub fn new(value: T) -> CachePadded { + CachePadded:: { value } + } +} + +impl Deref for CachePadded { + type Target = T; + + fn deref(&self) -> &T { + &self.value + } +} + +impl DerefMut for CachePadded { + fn deref_mut(&mut self) -> &mut T { + &mut self.value + } +} + +const SPIN_LIMIT: u32 = 6; + +/// Performs quadratic backoff in spin loops. +pub struct Backoff { + step: Cell, +} + +impl Backoff { + /// Creates a new `Backoff`. + pub fn new() -> Self { + Backoff { step: Cell::new(0) } + } + + /// Backs off using lightweight spinning. + /// + /// This method should be used for retrying an operation because another thread made + /// progress. i.e. on CAS failure. + #[inline] + pub fn spin_light(&self) { + let step = self.step.get().min(SPIN_LIMIT); + for _ in 0..step.pow(2) { + crate::hint::spin_loop(); + } + + self.step.set(self.step.get() + 1); + } + + /// Backs off using heavyweight spinning. + /// + /// This method should be used in blocking loops where parking the thread is not an option. + #[inline] + pub fn spin_heavy(&self) { + if self.step.get() <= SPIN_LIMIT { + for _ in 0..self.step.get().pow(2) { + crate::hint::spin_loop() + } + } else { + crate::thread::yield_now(); + } + + self.step.set(self.step.get() + 1); + } +} diff --git a/sgx_tstd/src/sync/mpmc/waker.rs b/sgx_tstd/src/sync/mpmc/waker.rs new file mode 100644 index 000000000..a3e4a6c2d --- /dev/null +++ b/sgx_tstd/src/sync/mpmc/waker.rs @@ -0,0 +1,227 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +//! Waking mechanism for threads blocked on channel operations. + +use super::context::Context; +use super::select::{Operation, Selected}; + +use crate::ptr; +use crate::sync::atomic::{AtomicBool, Ordering}; +use crate::sync::Mutex; + +/// Represents a thread blocked on a specific channel operation. +pub(crate) struct Entry { + /// The operation. + pub(crate) oper: Operation, + + /// Optional packet. + pub(crate) packet: *mut (), + + /// Context associated with the thread owning this operation. + pub(crate) cx: Context, +} + +/// A queue of threads blocked on channel operations. +/// +/// This data structure is used by threads to register blocking operations and get woken up once +/// an operation becomes ready. +pub(crate) struct Waker { + /// A list of select operations. + selectors: Vec, + + /// A list of operations waiting to be ready. + observers: Vec, +} + +impl Waker { + /// Creates a new `Waker`. + #[inline] + pub(crate) fn new() -> Self { + Waker { selectors: Vec::new(), observers: Vec::new() } + } + + /// Registers a select operation. + #[inline] + pub(crate) fn register(&mut self, oper: Operation, cx: &Context) { + self.register_with_packet(oper, ptr::null_mut(), cx); + } + + /// Registers a select operation and a packet. + #[inline] + pub(crate) fn register_with_packet(&mut self, oper: Operation, packet: *mut (), cx: &Context) { + self.selectors.push(Entry { oper, packet, cx: cx.clone() }); + } + + /// Unregisters a select operation. + #[inline] + pub(crate) fn unregister(&mut self, oper: Operation) -> Option { + if let Some((i, _)) = + self.selectors.iter().enumerate().find(|&(_, entry)| entry.oper == oper) + { + let entry = self.selectors.remove(i); + Some(entry) + } else { + None + } + } + + /// Attempts to find another thread's entry, select the operation, and wake it up. + #[inline] + pub(crate) fn try_select(&mut self) -> Option { + if self.selectors.is_empty() { + None + } else { + let thread_id = current_thread_id(); + + self.selectors + .iter() + .position(|selector| { + // Does the entry belong to a different thread? + selector.cx.thread_id() != thread_id + && selector // Try selecting this operation. + .cx + .try_select(Selected::Operation(selector.oper)) + .is_ok() + && { + // Provide the packet. + selector.cx.store_packet(selector.packet); + // Wake the thread up. + selector.cx.unpark(); + true + } + }) + // Remove the entry from the queue to keep it clean and improve + // performance. + .map(|pos| self.selectors.remove(pos)) + } + } + + /// Notifies all operations waiting to be ready. + #[inline] + pub(crate) fn notify(&mut self) { + for entry in self.observers.drain(..) { + if entry.cx.try_select(Selected::Operation(entry.oper)).is_ok() { + entry.cx.unpark(); + } + } + } + + /// Notifies all registered operations that the channel is disconnected. + #[inline] + pub(crate) fn disconnect(&mut self) { + for entry in self.selectors.iter() { + if entry.cx.try_select(Selected::Disconnected).is_ok() { + // Wake the thread up. + // + // Here we don't remove the entry from the queue. Registered threads must + // unregister from the waker by themselves. They might also want to recover the + // packet value and destroy it, if necessary. + entry.cx.unpark(); + } + } + + self.notify(); + } +} + +impl Drop for Waker { + #[inline] + fn drop(&mut self) { + debug_assert_eq!(self.selectors.len(), 0); + debug_assert_eq!(self.observers.len(), 0); + } +} + +/// A waker that can be shared among threads without locking. +/// +/// This is a simple wrapper around `Waker` that internally uses a mutex for synchronization. +pub(crate) struct SyncWaker { + /// The inner `Waker`. + inner: Mutex, + + /// `true` if the waker is empty. + is_empty: AtomicBool, +} + +impl SyncWaker { + /// Creates a new `SyncWaker`. + #[inline] + pub(crate) fn new() -> Self { + SyncWaker { inner: Mutex::new(Waker::new()), is_empty: AtomicBool::new(true) } + } + + /// Registers the current thread with an operation. + #[inline] + pub(crate) fn register(&self, oper: Operation, cx: &Context) { + let mut inner = self.inner.lock().unwrap(); + inner.register(oper, cx); + self.is_empty + .store(inner.selectors.is_empty() && inner.observers.is_empty(), Ordering::SeqCst); + } + + /// Unregisters an operation previously registered by the current thread. + #[inline] + pub(crate) fn unregister(&self, oper: Operation) -> Option { + let mut inner = self.inner.lock().unwrap(); + let entry = inner.unregister(oper); + self.is_empty + .store(inner.selectors.is_empty() && inner.observers.is_empty(), Ordering::SeqCst); + entry + } + + /// Attempts to find one thread (not the current one), select its operation, and wake it up. + #[inline] + pub(crate) fn notify(&self) { + if !self.is_empty.load(Ordering::SeqCst) { + let mut inner = self.inner.lock().unwrap(); + if !self.is_empty.load(Ordering::SeqCst) { + inner.try_select(); + inner.notify(); + self.is_empty.store( + inner.selectors.is_empty() && inner.observers.is_empty(), + Ordering::SeqCst, + ); + } + } + } + + /// Notifies all threads that the channel is disconnected. + #[inline] + pub(crate) fn disconnect(&self) { + let mut inner = self.inner.lock().unwrap(); + inner.disconnect(); + self.is_empty + .store(inner.selectors.is_empty() && inner.observers.is_empty(), Ordering::SeqCst); + } +} + +impl Drop for SyncWaker { + #[inline] + fn drop(&mut self) { + debug_assert!(self.is_empty.load(Ordering::SeqCst)); + } +} + +/// Returns a unique id for the current thread. +#[inline] +pub fn current_thread_id() -> usize { + // `u8` is not drop so this variable will be available during thread destruction, + // whereas `thread::current()` would not be + thread_local! { static DUMMY: u8 = 0 } + DUMMY.with(|x| (x as *const u8).addr()) +} diff --git a/sgx_tstd/src/sync/mpmc/zero.rs b/sgx_tstd/src/sync/mpmc/zero.rs new file mode 100644 index 000000000..a35eb6e64 --- /dev/null +++ b/sgx_tstd/src/sync/mpmc/zero.rs @@ -0,0 +1,335 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +//! Zero-capacity channel. +//! +//! This kind of channel is also known as *rendezvous* channel. + +use super::context::Context; +use super::error::*; +use super::select::{Operation, Selected, Token}; +use super::utils::Backoff; +use super::waker::Waker; + +use crate::cell::UnsafeCell; +use crate::marker::PhantomData; +use crate::sync::atomic::{AtomicBool, Ordering}; +use crate::sync::Mutex; +use crate::time::Instant; +use crate::{fmt, ptr}; + +/// A pointer to a packet. +pub(crate) struct ZeroToken(*mut ()); + +impl Default for ZeroToken { + fn default() -> Self { + Self(ptr::null_mut()) + } +} + +impl fmt::Debug for ZeroToken { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&(self.0 as usize), f) + } +} + +/// A slot for passing one message from a sender to a receiver. +struct Packet { + /// Equals `true` if the packet is allocated on the stack. + on_stack: bool, + + /// Equals `true` once the packet is ready for reading or writing. + ready: AtomicBool, + + /// The message. + msg: UnsafeCell>, +} + +impl Packet { + /// Creates an empty packet on the stack. + fn empty_on_stack() -> Packet { + Packet { on_stack: true, ready: AtomicBool::new(false), msg: UnsafeCell::new(None) } + } + + /// Creates a packet on the stack, containing a message. + fn message_on_stack(msg: T) -> Packet { + Packet { on_stack: true, ready: AtomicBool::new(false), msg: UnsafeCell::new(Some(msg)) } + } + + /// Waits until the packet becomes ready for reading or writing. + fn wait_ready(&self) { + let backoff = Backoff::new(); + while !self.ready.load(Ordering::Acquire) { + backoff.spin_heavy(); + } + } +} + +/// Inner representation of a zero-capacity channel. +struct Inner { + /// Senders waiting to pair up with a receive operation. + senders: Waker, + + /// Receivers waiting to pair up with a send operation. + receivers: Waker, + + /// Equals `true` when the channel is disconnected. + is_disconnected: bool, +} + +/// Zero-capacity channel. +pub(crate) struct Channel { + /// Inner representation of the channel. + inner: Mutex, + + /// Indicates that dropping a `Channel` may drop values of type `T`. + _marker: PhantomData, +} + +impl Channel { + /// Constructs a new zero-capacity channel. + pub(crate) fn new() -> Self { + Channel { + inner: Mutex::new(Inner { + senders: Waker::new(), + receivers: Waker::new(), + is_disconnected: false, + }), + _marker: PhantomData, + } + } + + /// Writes a message into the packet. + pub(crate) unsafe fn write(&self, token: &mut Token, msg: T) -> Result<(), T> { + // If there is no packet, the channel is disconnected. + if token.zero.0.is_null() { + return Err(msg); + } + + let packet = &*(token.zero.0 as *const Packet); + packet.msg.get().write(Some(msg)); + packet.ready.store(true, Ordering::Release); + Ok(()) + } + + /// Reads a message from the packet. + pub(crate) unsafe fn read(&self, token: &mut Token) -> Result { + // If there is no packet, the channel is disconnected. + if token.zero.0.is_null() { + return Err(()); + } + + let packet = &*(token.zero.0 as *const Packet); + + if packet.on_stack { + // The message has been in the packet from the beginning, so there is no need to wait + // for it. However, after reading the message, we need to set `ready` to `true` in + // order to signal that the packet can be destroyed. + let msg = packet.msg.get().replace(None).unwrap(); + packet.ready.store(true, Ordering::Release); + Ok(msg) + } else { + // Wait until the message becomes available, then read it and destroy the + // heap-allocated packet. + packet.wait_ready(); + let msg = packet.msg.get().replace(None).unwrap(); + drop(Box::from_raw(token.zero.0 as *mut Packet)); + Ok(msg) + } + } + + /// Attempts to send a message into the channel. + pub(crate) fn try_send(&self, msg: T) -> Result<(), TrySendError> { + let token = &mut Token::default(); + let mut inner = self.inner.lock().unwrap(); + + // If there's a waiting receiver, pair up with it. + if let Some(operation) = inner.receivers.try_select() { + token.zero.0 = operation.packet; + drop(inner); + unsafe { + self.write(token, msg).ok().unwrap(); + } + Ok(()) + } else if inner.is_disconnected { + Err(TrySendError::Disconnected(msg)) + } else { + Err(TrySendError::Full(msg)) + } + } + + /// Sends a message into the channel. + pub(crate) fn send( + &self, + msg: T, + deadline: Option, + ) -> Result<(), SendTimeoutError> { + let token = &mut Token::default(); + let mut inner = self.inner.lock().unwrap(); + + // If there's a waiting receiver, pair up with it. + if let Some(operation) = inner.receivers.try_select() { + token.zero.0 = operation.packet; + drop(inner); + unsafe { + self.write(token, msg).ok().unwrap(); + } + return Ok(()); + } + + if inner.is_disconnected { + return Err(SendTimeoutError::Disconnected(msg)); + } + + Context::with(|cx| { + // Prepare for blocking until a receiver wakes us up. + let oper = Operation::hook(token); + let mut packet = Packet::::message_on_stack(msg); + inner.senders.register_with_packet(oper, &mut packet as *mut Packet as *mut (), cx); + inner.receivers.notify(); + drop(inner); + + // Block the current thread. + let sel = cx.wait_until(deadline); + + match sel { + Selected::Waiting => unreachable!(), + Selected::Aborted => { + self.inner.lock().unwrap().senders.unregister(oper).unwrap(); + let msg = unsafe { packet.msg.get().replace(None).unwrap() }; + Err(SendTimeoutError::Timeout(msg)) + } + Selected::Disconnected => { + self.inner.lock().unwrap().senders.unregister(oper).unwrap(); + let msg = unsafe { packet.msg.get().replace(None).unwrap() }; + Err(SendTimeoutError::Disconnected(msg)) + } + Selected::Operation(_) => { + // Wait until the message is read, then drop the packet. + packet.wait_ready(); + Ok(()) + } + } + }) + } + + /// Attempts to receive a message without blocking. + pub(crate) fn try_recv(&self) -> Result { + let token = &mut Token::default(); + let mut inner = self.inner.lock().unwrap(); + + // If there's a waiting sender, pair up with it. + if let Some(operation) = inner.senders.try_select() { + token.zero.0 = operation.packet; + drop(inner); + unsafe { self.read(token).map_err(|_| TryRecvError::Disconnected) } + } else if inner.is_disconnected { + Err(TryRecvError::Disconnected) + } else { + Err(TryRecvError::Empty) + } + } + + /// Receives a message from the channel. + pub(crate) fn recv(&self, deadline: Option) -> Result { + let token = &mut Token::default(); + let mut inner = self.inner.lock().unwrap(); + + // If there's a waiting sender, pair up with it. + if let Some(operation) = inner.senders.try_select() { + token.zero.0 = operation.packet; + drop(inner); + unsafe { + return self.read(token).map_err(|_| RecvTimeoutError::Disconnected); + } + } + + if inner.is_disconnected { + return Err(RecvTimeoutError::Disconnected); + } + + Context::with(|cx| { + // Prepare for blocking until a sender wakes us up. + let oper = Operation::hook(token); + let mut packet = Packet::::empty_on_stack(); + inner.receivers.register_with_packet( + oper, + &mut packet as *mut Packet as *mut (), + cx, + ); + inner.senders.notify(); + drop(inner); + + // Block the current thread. + let sel = cx.wait_until(deadline); + + match sel { + Selected::Waiting => unreachable!(), + Selected::Aborted => { + self.inner.lock().unwrap().receivers.unregister(oper).unwrap(); + Err(RecvTimeoutError::Timeout) + } + Selected::Disconnected => { + self.inner.lock().unwrap().receivers.unregister(oper).unwrap(); + Err(RecvTimeoutError::Disconnected) + } + Selected::Operation(_) => { + // Wait until the message is provided, then read it. + packet.wait_ready(); + unsafe { Ok(packet.msg.get().replace(None).unwrap()) } + } + } + }) + } + + /// Disconnects the channel and wakes up all blocked senders and receivers. + /// + /// Returns `true` if this call disconnected the channel. + pub(crate) fn disconnect(&self) -> bool { + let mut inner = self.inner.lock().unwrap(); + + if !inner.is_disconnected { + inner.is_disconnected = true; + inner.senders.disconnect(); + inner.receivers.disconnect(); + true + } else { + false + } + } + + /// Returns the current number of messages inside the channel. + pub(crate) fn len(&self) -> usize { + 0 + } + + /// Returns the capacity of the channel. + #[allow(clippy::unnecessary_wraps)] // This is intentional. + pub(crate) fn capacity(&self) -> Option { + Some(0) + } + + /// Returns `true` if the channel is empty. + pub(crate) fn is_empty(&self) -> bool { + true + } + + /// Returns `true` if the channel is full. + pub(crate) fn is_full(&self) -> bool { + true + } +} diff --git a/sgx_tstd/src/sync/mpsc/blocking.rs b/sgx_tstd/src/sync/mpsc/blocking.rs deleted file mode 100644 index cb378bd12..000000000 --- a/sgx_tstd/src/sync/mpsc/blocking.rs +++ /dev/null @@ -1,101 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License.. - -//! Generic support for building blocking abstractions. - -use crate::sync::atomic::{AtomicBool, Ordering}; -use crate::sync::Arc; -use crate::thread::{self, Thread}; -use crate::time::Instant; -#[cfg(not(feature = "untrusted_time"))] -use crate::untrusted::time::InstantEx; - -struct Inner { - thread: Thread, - woken: AtomicBool, -} - -unsafe impl Send for Inner {} -unsafe impl Sync for Inner {} - -#[derive(Clone)] -pub struct SignalToken { - inner: Arc, -} - -pub struct WaitToken { - inner: Arc, -} - -impl !Send for WaitToken {} - -impl !Sync for WaitToken {} - -pub fn tokens() -> (WaitToken, SignalToken) { - let inner = Arc::new(Inner { thread: thread::current(), woken: AtomicBool::new(false) }); - let wait_token = WaitToken { inner: inner.clone() }; - let signal_token = SignalToken { inner }; - (wait_token, signal_token) -} - -impl SignalToken { - pub fn signal(&self) -> bool { - let wake = self - .inner - .woken - .compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) - .is_ok(); - if wake { - self.inner.thread.unpark(); - } - wake - } - - /// Converts to an unsafe raw pointer. Useful for storing in a pipe's state - /// flag. - #[inline] - pub unsafe fn to_raw(self) -> *mut u8 { - Arc::into_raw(self.inner) as *mut u8 - } - - /// Converts from an unsafe raw pointer. Useful for retrieving a pipe's state - /// flag. - #[inline] - pub unsafe fn from_raw(signal_ptr: *mut u8) -> SignalToken { - SignalToken { inner: Arc::from_raw(signal_ptr as *mut Inner) } - } -} - -impl WaitToken { - pub fn wait(self) { - while !self.inner.woken.load(Ordering::SeqCst) { - thread::park() - } - } - - /// Returns `true` if we wake up normally. - pub fn wait_max_until(self, end: Instant) -> bool { - while !self.inner.woken.load(Ordering::SeqCst) { - let now = Instant::now(); - if now >= end { - return false; - } - thread::park_timeout(end - now) - } - true - } -} diff --git a/sgx_tstd/src/sync/mpsc/mod.rs b/sgx_tstd/src/sync/mpsc/mod.rs index 94acc72cc..312d1257c 100644 --- a/sgx_tstd/src/sync/mpsc/mod.rs +++ b/sgx_tstd/src/sync/mpsc/mod.rs @@ -158,176 +158,15 @@ mod tests; #[cfg(feature = "unit_test")] mod sync_tests; -// A description of how Rust's channel implementation works -// -// Channels are supposed to be the basic building block for all other -// concurrent primitives that are used in Rust. As a result, the channel type -// needs to be highly optimized, flexible, and broad enough for use everywhere. -// -// The choice of implementation of all channels is to be built on lock-free data -// structures. The channels themselves are then consequently also lock-free data -// structures. As always with lock-free code, this is a very "here be dragons" -// territory, especially because I'm unaware of any academic papers that have -// gone into great length about channels of these flavors. -// -// ## Flavors of channels -// -// From the perspective of a consumer of this library, there is only one flavor -// of channel. This channel can be used as a stream and cloned to allow multiple -// senders. Under the hood, however, there are actually three flavors of -// channels in play. -// -// * Flavor::Oneshots - these channels are highly optimized for the one-send use -// case. They contain as few atomics as possible and -// involve one and exactly one allocation. -// * Streams - these channels are optimized for the non-shared use case. They -// use a different concurrent queue that is more tailored for this -// use case. The initial allocation of this flavor of channel is not -// optimized. -// * Shared - this is the most general form of channel that this module offers, -// a channel with multiple senders. This type is as optimized as it -// can be, but the previous two types mentioned are much faster for -// their use-cases. -// -// ## Concurrent queues -// -// The basic idea of Rust's Sender/Receiver types is that send() never blocks, -// but recv() obviously blocks. This means that under the hood there must be -// some shared and concurrent queue holding all of the actual data. -// -// With two flavors of channels, two flavors of queues are also used. We have -// chosen to use queues from a well-known author that are abbreviated as SPSC -// and MPSC (single producer, single consumer and multiple producer, single -// consumer). SPSC queues are used for streams while MPSC queues are used for -// shared channels. -// -// ### SPSC optimizations -// -// The SPSC queue found online is essentially a linked list of nodes where one -// half of the nodes are the "queue of data" and the other half of nodes are a -// cache of unused nodes. The unused nodes are used such that an allocation is -// not required on every push() and a free doesn't need to happen on every -// pop(). -// -// As found online, however, the cache of nodes is of an infinite size. This -// means that if a channel at one point in its life had 50k items in the queue, -// then the queue will always have the capacity for 50k items. I believed that -// this was an unnecessary limitation of the implementation, so I have altered -// the queue to optionally have a bound on the cache size. -// -// By default, streams will have an unbounded SPSC queue with a small-ish cache -// size. The hope is that the cache is still large enough to have very fast -// send() operations while not too large such that millions of channels can -// coexist at once. -// -// ### MPSC optimizations -// -// Right now the MPSC queue has not been optimized. Like the SPSC queue, it uses -// a linked list under the hood to earn its unboundedness, but I have not put -// forth much effort into having a cache of nodes similar to the SPSC queue. -// -// For now, I believe that this is "ok" because shared channels are not the most -// common type, but soon we may wish to revisit this queue choice and determine -// another candidate for backend storage of shared channels. -// -// ## Overview of the Implementation -// -// Now that there's a little background on the concurrent queues used, it's -// worth going into much more detail about the channels themselves. The basic -// pseudocode for a send/recv are: -// -// -// send(t) recv() -// queue.push(t) return if queue.pop() -// if increment() == -1 deschedule { -// wakeup() if decrement() > 0 -// cancel_deschedule() -// } -// queue.pop() -// -// As mentioned before, there are no locks in this implementation, only atomic -// instructions are used. -// -// ### The internal atomic counter -// -// Every channel has a shared counter with each half to keep track of the size -// of the queue. This counter is used to abort descheduling by the receiver and -// to know when to wake up on the sending side. -// -// As seen in the pseudocode, senders will increment this count and receivers -// will decrement the count. The theory behind this is that if a sender sees a -// -1 count, it will wake up the receiver, and if the receiver sees a 1+ count, -// then it doesn't need to block. -// -// The recv() method has a beginning call to pop(), and if successful, it needs -// to decrement the count. It is a crucial implementation detail that this -// decrement does *not* happen to the shared counter. If this were the case, -// then it would be possible for the counter to be very negative when there were -// no receivers waiting, in which case the senders would have to determine when -// it was actually appropriate to wake up a receiver. -// -// Instead, the "steal count" is kept track of separately (not atomically -// because it's only used by receivers), and then the decrement() call when -// descheduling will lump in all of the recent steals into one large decrement. -// -// The implication of this is that if a sender sees a -1 count, then there's -// guaranteed to be a waiter waiting! -// -// ## Native Implementation -// -// A major goal of these channels is to work seamlessly on and off the runtime. -// All of the previous race conditions have been worded in terms of -// scheduler-isms (which is obviously not available without the runtime). -// -// For now, native usage of channels (off the runtime) will fall back onto -// mutexes/cond vars for descheduling/atomic decisions. The no-contention path -// is still entirely lock-free, the "deschedule" blocks above are surrounded by -// a mutex and the "wakeup" blocks involve grabbing a mutex and signaling on a -// condition variable. -// -// ## Select -// -// Being able to support selection over channels has greatly influenced this -// design, and not only does selection need to work inside the runtime, but also -// outside the runtime. -// -// The implementation is fairly straightforward. The goal of select() is not to -// return some data, but only to return which channel can receive data without -// blocking. The implementation is essentially the entire blocking procedure -// followed by an increment as soon as its woken up. The cancellation procedure -// involves an increment and swapping out of to_wake to acquire ownership of the -// thread to unblock. -// -// Sadly this current implementation requires multiple allocations, so I have -// seen the throughput of select() be much worse than it should be. I do not -// believe that there is anything fundamental that needs to change about these -// channels, however, in order to support a more efficient select(). -// -// FIXME: Select is now removed, so these factors are ready to be cleaned up! -// -// # Conclusion -// -// And now that you've seen all the races that I found and attempted to fix, -// here's the code for you to find some more! +// MPSC channels are built as a wrapper around MPMC channels, which +// were ported from the `crossbeam-channel` crate. MPMC channels are +// not exposed publicly, but if you are curious about the implementation, +// that's where everything is. -use crate::cell::UnsafeCell; use crate::error; use crate::fmt; -use crate::mem; -use crate::sync::Arc; +use crate::sync::mpmc; use crate::time::{Duration, Instant}; -#[cfg(not(feature = "untrusted_time"))] -use crate::untrusted::time::InstantEx; - -mod blocking; -mod mpsc_queue; -mod oneshot; -mod shared; -mod spsc_queue; -mod stream; -mod sync; - -mod cache_aligned; /// The receiving half of Rust's [`channel`] (or [`sync_channel`]) type. /// This half can only be owned by one thread. @@ -356,7 +195,7 @@ mod cache_aligned; /// println!("{}", recv.recv().unwrap()); // Received after 2 seconds /// ``` pub struct Receiver { - inner: UnsafeCell>, + inner: mpmc::Receiver, } // The receiver port can be sent from place to place, so long as it @@ -472,12 +311,11 @@ pub struct IntoIter { rx: Receiver, } -/// The sending-half of Rust's asynchronous [`channel`] type. This half can only be -/// owned by one thread, but it can be cloned to send to other threads. +/// The sending-half of Rust's asynchronous [`channel`] type. /// /// Messages can be sent through this channel with [`send`]. /// -/// Note: all senders (the original and the clones) need to be dropped for the receiver +/// Note: all senders (the original and its clones) need to be dropped for the receiver /// to stop blocking to receive messages with [`Receiver::recv`]. /// /// [`send`]: Sender::send @@ -507,14 +345,14 @@ pub struct IntoIter { /// assert_eq!(3, msg + msg2); /// ``` pub struct Sender { - inner: UnsafeCell>, + inner: mpmc::Sender, } // The send port can be sent from place to place, so long as it // is not used to send non-sendable things. unsafe impl Send for Sender {} -impl !Sync for Sender {} +unsafe impl Sync for Sender {} /// The sending-half of Rust's synchronous [`sync_channel`] type. /// @@ -563,7 +401,7 @@ impl !Sync for Sender {} /// println!("message {msg} received"); /// ``` pub struct SyncSender { - inner: Arc>, + inner: mpmc::Sender, } unsafe impl Send for SyncSender {} @@ -637,35 +475,6 @@ pub enum TrySendError { Disconnected(T), } -enum Flavor { - Oneshot(Arc>), - Stream(Arc>), - Shared(Arc>), - Sync(Arc>), -} - -#[doc(hidden)] -#[allow(clippy::mut_from_ref)] -trait UnsafeFlavor { - fn inner_unsafe(&self) -> &UnsafeCell>; - unsafe fn inner_mut(&self) -> &mut Flavor { - &mut *self.inner_unsafe().get() - } - unsafe fn inner(&self) -> &Flavor { - &*self.inner_unsafe().get() - } -} -impl UnsafeFlavor for Sender { - fn inner_unsafe(&self) -> &UnsafeCell> { - &self.inner - } -} -impl UnsafeFlavor for Receiver { - fn inner_unsafe(&self) -> &UnsafeCell> { - &self.inner - } -} - /// Creates a new asynchronous channel, returning the sender/receiver halves. /// All data sent on the [`Sender`] will become available on the [`Receiver`] in /// the same order as it was sent, and no [`send`] will block the calling thread @@ -705,8 +514,8 @@ impl UnsafeFlavor for Receiver { /// ``` #[must_use] pub fn channel() -> (Sender, Receiver) { - let a = Arc::new(oneshot::Packet::new()); - (Sender::new(Flavor::Oneshot(a.clone())), Receiver::new(Flavor::Oneshot(a))) + let (tx, rx) = mpmc::channel(); + (Sender { inner: tx }, Receiver { inner: rx }) } /// Creates a new synchronous, bounded channel. @@ -753,8 +562,8 @@ pub fn channel() -> (Sender, Receiver) { /// ``` #[must_use] pub fn sync_channel(bound: usize) -> (SyncSender, Receiver) { - let a = Arc::new(sync::Packet::new(bound)); - (SyncSender::new(a.clone()), Receiver::new(Flavor::Sync(a))) + let (tx, rx) = mpmc::sync_channel(bound); + (SyncSender { inner: tx }, Receiver { inner: rx }) } //////////////////////////////////////////////////////////////////////////////// @@ -762,10 +571,6 @@ pub fn sync_channel(bound: usize) -> (SyncSender, Receiver) { //////////////////////////////////////////////////////////////////////////////// impl Sender { - fn new(inner: Flavor) -> Sender { - Sender { inner: UnsafeCell::new(inner) } - } - /// Attempts to send a value on this channel, returning it back if it could /// not be sent. /// @@ -794,40 +599,7 @@ impl Sender { /// assert_eq!(tx.send(1).unwrap_err().0, 1); /// ``` pub fn send(&self, t: T) -> Result<(), SendError> { - let (new_inner, ret) = match *unsafe { self.inner() } { - Flavor::Oneshot(ref p) => { - if !p.sent() { - return p.send(t).map_err(SendError); - } else { - let a = Arc::new(stream::Packet::new()); - let rx = Receiver::new(Flavor::Stream(a.clone())); - match p.upgrade(rx) { - oneshot::UpSuccess => { - let ret = a.send(t); - (a, ret) - } - oneshot::UpDisconnected => (a, Err(t)), - oneshot::UpWoke(token) => { - // This send cannot panic because the thread is - // asleep (we're looking at it), so the receiver - // can't go away. - a.send(t).ok().unwrap(); - token.signal(); - (a, Ok(())) - } - } - } - } - Flavor::Stream(ref p) => return p.send(t).map_err(SendError), - Flavor::Shared(ref p) => return p.send(t).map_err(SendError), - Flavor::Sync(..) => unreachable!(), - }; - - unsafe { - let tmp = Sender::new(Flavor::Stream(new_inner)); - mem::swap(self.inner_mut(), tmp.inner_mut()); - } - ret.map_err(SendError) + self.inner.send(t) } } @@ -838,56 +610,7 @@ impl Clone for Sender { /// (including the original) need to be dropped in order for /// [`Receiver::recv`] to stop blocking. fn clone(&self) -> Sender { - let packet = match *unsafe { self.inner() } { - Flavor::Oneshot(ref p) => { - let a = Arc::new(shared::Packet::new()); - { - let guard = a.postinit_lock(); - let rx = Receiver::new(Flavor::Shared(a.clone())); - let sleeper = match p.upgrade(rx) { - oneshot::UpSuccess | oneshot::UpDisconnected => None, - oneshot::UpWoke(task) => Some(task), - }; - a.inherit_blocker(sleeper, guard); - } - a - } - Flavor::Stream(ref p) => { - let a = Arc::new(shared::Packet::new()); - { - let guard = a.postinit_lock(); - let rx = Receiver::new(Flavor::Shared(a.clone())); - let sleeper = match p.upgrade(rx) { - stream::UpSuccess | stream::UpDisconnected => None, - stream::UpWoke(task) => Some(task), - }; - a.inherit_blocker(sleeper, guard); - } - a - } - Flavor::Shared(ref p) => { - p.clone_chan(); - return Sender::new(Flavor::Shared(p.clone())); - } - Flavor::Sync(..) => unreachable!(), - }; - - unsafe { - let tmp = Sender::new(Flavor::Shared(packet.clone())); - mem::swap(self.inner_mut(), tmp.inner_mut()); - } - Sender::new(Flavor::Shared(packet)) - } -} - -impl Drop for Sender { - fn drop(&mut self) { - match *unsafe { self.inner() } { - Flavor::Oneshot(ref p) => p.drop_chan(), - Flavor::Stream(ref p) => p.drop_chan(), - Flavor::Shared(ref p) => p.drop_chan(), - Flavor::Sync(..) => unreachable!(), - } + Sender { inner: self.inner.clone() } } } @@ -902,10 +625,6 @@ impl fmt::Debug for Sender { //////////////////////////////////////////////////////////////////////////////// impl SyncSender { - fn new(inner: Arc>) -> SyncSender { - SyncSender { inner } - } - /// Sends a value on this synchronous channel. /// /// This function will *block* until space in the internal buffer becomes @@ -943,7 +662,7 @@ impl SyncSender { /// assert_eq!(1, msg); /// ``` pub fn send(&self, t: T) -> Result<(), SendError> { - self.inner.send(t).map_err(SendError) + self.inner.send(t) } /// Attempts to send a value on this channel without blocking. @@ -998,18 +717,20 @@ impl SyncSender { pub fn try_send(&self, t: T) -> Result<(), TrySendError> { self.inner.try_send(t) } -} -impl Clone for SyncSender { - fn clone(&self) -> SyncSender { - self.inner.clone_chan(); - SyncSender::new(self.inner.clone()) + // Attempts to send for a value on this receiver, returning an error if the + // corresponding channel has hung up, or if it waits more than `timeout`. + // + // This method is currently private and only used for tests. + #[allow(unused)] + fn send_timeout(&self, t: T, timeout: Duration) -> Result<(), mpmc::SendTimeoutError> { + self.inner.send_timeout(t, timeout) } } -impl Drop for SyncSender { - fn drop(&mut self) { - self.inner.drop_chan(); +impl Clone for SyncSender { + fn clone(&self) -> SyncSender { + SyncSender { inner: self.inner.clone() } } } @@ -1024,10 +745,6 @@ impl fmt::Debug for SyncSender { //////////////////////////////////////////////////////////////////////////////// impl Receiver { - fn new(inner: Flavor) -> Receiver { - Receiver { inner: UnsafeCell::new(inner) } - } - /// Attempts to return a pending value on this receiver without blocking. /// /// This method will never block the caller in order to wait for data to @@ -1052,35 +769,7 @@ impl Receiver { /// assert!(receiver.try_recv().is_err()); /// ``` pub fn try_recv(&self) -> Result { - loop { - let new_port = match *unsafe { self.inner() } { - Flavor::Oneshot(ref p) => match p.try_recv() { - Ok(t) => return Ok(t), - Err(oneshot::Empty) => return Err(TryRecvError::Empty), - Err(oneshot::Disconnected) => return Err(TryRecvError::Disconnected), - Err(oneshot::Upgraded(rx)) => rx, - }, - Flavor::Stream(ref p) => match p.try_recv() { - Ok(t) => return Ok(t), - Err(stream::Empty) => return Err(TryRecvError::Empty), - Err(stream::Disconnected) => return Err(TryRecvError::Disconnected), - Err(stream::Upgraded(rx)) => rx, - }, - Flavor::Shared(ref p) => match p.try_recv() { - Ok(t) => return Ok(t), - Err(shared::Empty) => return Err(TryRecvError::Empty), - Err(shared::Disconnected) => return Err(TryRecvError::Disconnected), - }, - Flavor::Sync(ref p) => match p.try_recv() { - Ok(t) => return Ok(t), - Err(sync::Empty) => return Err(TryRecvError::Empty), - Err(sync::Disconnected) => return Err(TryRecvError::Disconnected), - }, - }; - unsafe { - mem::swap(self.inner_mut(), new_port.inner_mut()); - } - } + self.inner.try_recv() } /// Attempts to wait for a value on this receiver, returning an error if the @@ -1138,31 +827,7 @@ impl Receiver { /// assert_eq!(Err(RecvError), recv.recv()); /// ``` pub fn recv(&self) -> Result { - loop { - let new_port = match *unsafe { self.inner() } { - Flavor::Oneshot(ref p) => match p.recv(None) { - Ok(t) => return Ok(t), - Err(oneshot::Disconnected) => return Err(RecvError), - Err(oneshot::Upgraded(rx)) => rx, - Err(oneshot::Empty) => unreachable!(), - }, - Flavor::Stream(ref p) => match p.recv(None) { - Ok(t) => return Ok(t), - Err(stream::Disconnected) => return Err(RecvError), - Err(stream::Upgraded(rx)) => rx, - Err(stream::Empty) => unreachable!(), - }, - Flavor::Shared(ref p) => match p.recv(None) { - Ok(t) => return Ok(t), - Err(shared::Disconnected) => return Err(RecvError), - Err(shared::Empty) => unreachable!(), - }, - Flavor::Sync(ref p) => return p.recv(None).map_err(|_| RecvError), - }; - unsafe { - mem::swap(self.inner_mut(), new_port.inner_mut()); - } - } + self.inner.recv() } /// Attempts to wait for a value on this receiver, returning an error if the @@ -1180,34 +845,6 @@ impl Receiver { /// However, since channels are buffered, messages sent before the disconnect /// will still be properly received. /// - /// # Known Issues - /// - /// There is currently a known issue (see [`#39364`]) that causes `recv_timeout` - /// to panic unexpectedly with the following example: - /// - /// ```no_run - /// use std::sync::mpsc::channel; - /// use std::thread; - /// use std::time::Duration; - /// - /// let (tx, rx) = channel::(); - /// - /// thread::spawn(move || { - /// let d = Duration::from_millis(10); - /// loop { - /// println!("recv"); - /// let _r = rx.recv_timeout(d); - /// } - /// }); - /// - /// thread::sleep(Duration::from_millis(100)); - /// let _c1 = tx.clone(); - /// - /// thread::sleep(Duration::from_secs(1)); - /// ``` - /// - /// [`#39364`]: https://github.com/rust-lang/rust/issues/39364 - /// /// # Examples /// /// Successfully receiving value before encountering timeout: @@ -1249,17 +886,7 @@ impl Receiver { /// ); /// ``` pub fn recv_timeout(&self, timeout: Duration) -> Result { - // Do an optimistic try_recv to avoid the performance impact of - // Instant::now() in the full-channel case. - match self.try_recv() { - Ok(result) => Ok(result), - Err(TryRecvError::Disconnected) => Err(RecvTimeoutError::Disconnected), - Err(TryRecvError::Empty) => match Instant::now().checked_add(timeout) { - Some(deadline) => self.recv_deadline(deadline), - // So far in the future that it's practically the same as waiting indefinitely. - None => self.recv().map_err(RecvTimeoutError::from), - }, - } + self.inner.recv_timeout(timeout) } /// Attempts to wait for a value on this receiver, returning an error if the @@ -1319,46 +946,7 @@ impl Receiver { /// ); /// ``` pub fn recv_deadline(&self, deadline: Instant) -> Result { - use self::RecvTimeoutError::*; - - loop { - let port_or_empty = match *unsafe { self.inner() } { - Flavor::Oneshot(ref p) => match p.recv(Some(deadline)) { - Ok(t) => return Ok(t), - Err(oneshot::Disconnected) => return Err(Disconnected), - Err(oneshot::Upgraded(rx)) => Some(rx), - Err(oneshot::Empty) => None, - }, - Flavor::Stream(ref p) => match p.recv(Some(deadline)) { - Ok(t) => return Ok(t), - Err(stream::Disconnected) => return Err(Disconnected), - Err(stream::Upgraded(rx)) => Some(rx), - Err(stream::Empty) => None, - }, - Flavor::Shared(ref p) => match p.recv(Some(deadline)) { - Ok(t) => return Ok(t), - Err(shared::Disconnected) => return Err(Disconnected), - Err(shared::Empty) => None, - }, - Flavor::Sync(ref p) => match p.recv(Some(deadline)) { - Ok(t) => return Ok(t), - Err(sync::Disconnected) => return Err(Disconnected), - Err(sync::Empty) => None, - }, - }; - - if let Some(new_port) = port_or_empty { - unsafe { - mem::swap(self.inner_mut(), new_port.inner_mut()); - } - } - - // If we're already passed the deadline, and we're here without - // data, return a timeout, else try again. - if Instant::now() >= deadline { - return Err(Timeout); - } - } + self.inner.recv_deadline(deadline) } /// Returns an iterator that will block waiting for messages, but never @@ -1470,17 +1058,6 @@ impl IntoIterator for Receiver { } } -impl Drop for Receiver { - fn drop(&mut self) { - match *unsafe { self.inner() } { - Flavor::Oneshot(ref p) => p.drop_port(), - Flavor::Stream(ref p) => p.drop_port(), - Flavor::Shared(ref p) => p.drop_port(), - Flavor::Sync(ref p) => p.drop_port(), - } - } -} - impl fmt::Debug for Receiver { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Receiver").finish_non_exhaustive() @@ -1499,7 +1076,7 @@ impl fmt::Display for SendError { } } -impl error::Error for SendError { +impl error::Error for SendError { #[allow(deprecated)] fn description(&self) -> &str { "sending on a closed channel" @@ -1524,7 +1101,7 @@ impl fmt::Display for TrySendError { } } -impl error::Error for TrySendError { +impl error::Error for TrySendError { #[allow(deprecated)] fn description(&self) -> &str { match *self { diff --git a/sgx_tstd/src/sync/mpsc/mpsc_queue.rs b/sgx_tstd/src/sync/mpsc/mpsc_queue.rs deleted file mode 100644 index d37a4471c..000000000 --- a/sgx_tstd/src/sync/mpsc/mpsc_queue.rs +++ /dev/null @@ -1,135 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 mostly lock-free multi-producer, single consumer queue. -//! -//! This module contains an implementation of a concurrent MPSC queue. This -//! queue can be used to share data between threads, and is also used as the -//! building block of channels in rust. -//! -//! Note that the current implementation of this queue has a caveat of the `pop` -//! method, and see the method for more information about it. Due to this -//! caveat, this queue might not be appropriate for all use-cases. - -// https://www.1024cores.net/home/lock-free-algorithms -// /queues/non-intrusive-mpsc-node-based-queue - - -#[cfg(feature = "unit_test")] -mod tests; - -pub use self::PopResult::*; - -use core::cell::UnsafeCell; -use core::ptr; - -use crate::boxed::Box; -use crate::sync::atomic::{AtomicPtr, Ordering}; - -/// A result of the `pop` function. -pub enum PopResult { - /// Some data has been popped - Data(T), - /// The queue is empty - Empty, - /// The queue is in an inconsistent state. Popping data should succeed, but - /// some pushers have yet to make enough progress in order allow a pop to - /// succeed. It is recommended that a pop() occur "in the near future" in - /// order to see if the sender has made progress or not - Inconsistent, -} - -struct Node { - next: AtomicPtr>, - value: Option, -} - -/// The multi-producer single-consumer structure. This is not cloneable, but it -/// may be safely shared so long as it is guaranteed that there is only one -/// popper at a time (many pushers are allowed). -pub struct Queue { - head: AtomicPtr>, - tail: UnsafeCell<*mut Node>, -} - -unsafe impl Send for Queue {} -unsafe impl Sync for Queue {} - -impl Node { - unsafe fn new(v: Option) -> *mut Node { - Box::into_raw(box Node { next: AtomicPtr::new(ptr::null_mut()), value: v }) - } -} - -impl Queue { - /// Creates a new queue that is safe to share among multiple producers and - /// one consumer. - pub fn new() -> Queue { - let stub = unsafe { Node::new(None) }; - Queue { head: AtomicPtr::new(stub), tail: UnsafeCell::new(stub) } - } - - /// Pushes a new value onto this queue. - pub fn push(&self, t: T) { - unsafe { - let n = Node::new(Some(t)); - let prev = self.head.swap(n, Ordering::AcqRel); - (*prev).next.store(n, Ordering::Release); - } - } - - /// Pops some data from this queue. - /// - /// Note that the current implementation means that this function cannot - /// return `Option`. It is possible for this queue to be in an - /// inconsistent state where many pushes have succeeded and completely - /// finished, but pops cannot return `Some(t)`. This inconsistent state - /// happens when a pusher is pre-empted at an inopportune moment. - /// - /// This inconsistent state means that this queue does indeed have data, but - /// it does not currently have access to it at this time. - pub fn pop(&self) -> PopResult { - unsafe { - let tail = *self.tail.get(); - let next = (*tail).next.load(Ordering::Acquire); - - if !next.is_null() { - *self.tail.get() = next; - assert!((*tail).value.is_none()); - assert!((*next).value.is_some()); - let ret = (*next).value.take().unwrap(); - let _: Box> = Box::from_raw(tail); - return Data(ret); - } - - if self.head.load(Ordering::Acquire) == tail { Empty } else { Inconsistent } - } - } -} - -impl Drop for Queue { - fn drop(&mut self) { - unsafe { - let mut cur = *self.tail.get(); - while !cur.is_null() { - let next = (*cur).next.load(Ordering::Relaxed); - let _: Box> = Box::from_raw(cur); - cur = next; - } - } - } -} diff --git a/sgx_tstd/src/sync/mpsc/mpsc_queue/tests.rs b/sgx_tstd/src/sync/mpsc/mpsc_queue/tests.rs deleted file mode 100644 index 099518773..000000000 --- a/sgx_tstd/src/sync/mpsc/mpsc_queue/tests.rs +++ /dev/null @@ -1,66 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 super::{Data, Empty, Inconsistent, Queue}; -use crate::sync::mpsc::channel; -use crate::sync::Arc; -use crate::thread; - -use sgx_test_utils::test_case; - -#[test_case] -fn test_full() { - let q: Queue> = Queue::new(); - q.push(Box::new(1)); - q.push(Box::new(2)); -} - -#[test_case] -fn test() { - let nthreads = 8; - let nmsgs = 1000; - let q = Queue::new(); - match q.pop() { - Empty => {} - Inconsistent | Data(..) => panic!(), - } - let (tx, rx) = channel(); - let q = Arc::new(q); - - for _ in 0..nthreads { - let tx = tx.clone(); - let q = q.clone(); - thread::spawn(move || { - for i in 0..nmsgs { - q.push(i); - } - tx.send(()).unwrap(); - }); - } - - let mut i = 0; - while i < nthreads * nmsgs { - match q.pop() { - Empty | Inconsistent => {} - Data(_) => i += 1, - } - } - drop(tx); - for _ in 0..nthreads { - rx.recv().unwrap(); - } -} diff --git a/sgx_tstd/src/sync/mpsc/oneshot.rs b/sgx_tstd/src/sync/mpsc/oneshot.rs deleted file mode 100644 index 9050ddf36..000000000 --- a/sgx_tstd/src/sync/mpsc/oneshot.rs +++ /dev/null @@ -1,333 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License.. - -/// Oneshot channels/ports -/// -/// This is the initial flavor of channels/ports used for comm module. This is -/// an optimization for the one-use case of a channel. The major optimization of -/// this type is to have one and exactly one allocation when the chan/port pair -/// is created. -/// -/// Another possible optimization would be to not use an Arc box because -/// in theory we know when the shared packet can be deallocated (no real need -/// for the atomic reference counting), but I was having trouble how to destroy -/// the data early in a drop of a Port. -/// -/// # Implementation -/// -/// Oneshots are implemented around one atomic usize variable. This variable -/// indicates both the state of the port/chan but also contains any threads -/// blocked on the port. All atomic operations happen on this one word. -/// -/// In order to upgrade a oneshot channel, an upgrade is considered a disconnect -/// on behalf of the channel side of things (it can be mentally thought of as -/// consuming the port). This upgrade is then also stored in the shared packet. -/// The one caveat to consider is that when a port sees a disconnected channel -/// it must check for data because there is no "data plus upgrade" state. -pub use self::Failure::*; -use self::MyUpgrade::*; -pub use self::UpgradeResult::*; - -use crate::cell::UnsafeCell; -use crate::ptr; -use crate::sync::atomic::{AtomicPtr, Ordering}; -use crate::sync::mpsc::blocking::{self, SignalToken}; -use crate::sync::mpsc::Receiver; -use crate::time::Instant; - -// Various states you can find a port in. -const EMPTY: *mut u8 = ptr::invalid_mut::(0); // initial state: no data, no blocked receiver -const DATA: *mut u8 = ptr::invalid_mut::(1); // data ready for receiver to take -const DISCONNECTED: *mut u8 = ptr::invalid_mut::(2); // channel is disconnected OR upgraded -// Any other value represents a pointer to a SignalToken value. The -// protocol ensures that when the state moves *to* a pointer, -// ownership of the token is given to the packet, and when the state -// moves *from* a pointer, ownership of the token is transferred to -// whoever changed the state. - -pub struct Packet { - // Internal state of the chan/port pair (stores the blocked thread as well) - state: AtomicPtr, - // One-shot data slot location - data: UnsafeCell>, - // when used for the second time, a oneshot channel must be upgraded, and - // this contains the slot for the upgrade - upgrade: UnsafeCell>, -} - -pub enum Failure { - Empty, - Disconnected, - Upgraded(Receiver), -} - -#[allow(clippy::enum_variant_names)] -pub enum UpgradeResult { - UpSuccess, - UpDisconnected, - UpWoke(SignalToken), -} - -enum MyUpgrade { - NothingSent, - SendUsed, - GoUp(Receiver), -} - -impl Packet { - pub fn new() -> Packet { - Packet { - data: UnsafeCell::new(None), - upgrade: UnsafeCell::new(NothingSent), - state: AtomicPtr::new(EMPTY), - } - } - - pub fn send(&self, t: T) -> Result<(), T> { - unsafe { - // Sanity check - match *self.upgrade.get() { - NothingSent => {} - _ => panic!("sending on a oneshot that's already sent on "), - } - assert!((*self.data.get()).is_none()); - ptr::write(self.data.get(), Some(t)); - ptr::write(self.upgrade.get(), SendUsed); - - match self.state.swap(DATA, Ordering::SeqCst) { - // Sent the data, no one was waiting - EMPTY => Ok(()), - - // Couldn't send the data, the port hung up first. Return the data - // back up the stack. - DISCONNECTED => { - self.state.swap(DISCONNECTED, Ordering::SeqCst); - ptr::write(self.upgrade.get(), NothingSent); - Err((&mut *self.data.get()).take().unwrap()) - } - - // Not possible, these are one-use channels - DATA => unreachable!(), - - // There is a thread waiting on the other end. We leave the 'DATA' - // state inside so it'll pick it up on the other end. - ptr => { - SignalToken::from_raw(ptr).signal(); - Ok(()) - } - } - } - } - - // Just tests whether this channel has been sent on or not, this is only - // safe to use from the sender. - pub fn sent(&self) -> bool { - unsafe { !matches!(*self.upgrade.get(), NothingSent) } - } - - pub fn recv(&self, deadline: Option) -> Result> { - // Attempt to not block the thread (it's a little expensive). If it looks - // like we're not empty, then immediately go through to `try_recv`. - if self.state.load(Ordering::SeqCst) == EMPTY { - let (wait_token, signal_token) = blocking::tokens(); - let ptr = unsafe { signal_token.to_raw() }; - - // race with senders to enter the blocking state - if self.state.compare_exchange(EMPTY, ptr, Ordering::SeqCst, Ordering::SeqCst).is_ok() { - if let Some(deadline) = deadline { - let timed_out = !wait_token.wait_max_until(deadline); - // Try to reset the state - if timed_out { - self.abort_selection().map_err(Upgraded)?; - } - } else { - wait_token.wait(); - debug_assert!(self.state.load(Ordering::SeqCst) != EMPTY); - } - } else { - // drop the signal token, since we never blocked - drop(unsafe { SignalToken::from_raw(ptr) }); - } - } - - self.try_recv() - } - - pub fn try_recv(&self) -> Result> { - unsafe { - match self.state.load(Ordering::SeqCst) { - EMPTY => Err(Empty), - - // We saw some data on the channel, but the channel can be used - // again to send us an upgrade. As a result, we need to re-insert - // into the channel that there's no data available (otherwise we'll - // just see DATA next time). This is done as a cmpxchg because if - // the state changes under our feet we'd rather just see that state - // change. - DATA => { - let _ = self.state.compare_exchange( - DATA, - EMPTY, - Ordering::SeqCst, - Ordering::SeqCst, - ); - match (&mut *self.data.get()).take() { - Some(data) => Ok(data), - None => unreachable!(), - } - } - - // There's no guarantee that we receive before an upgrade happens, - // and an upgrade flags the channel as disconnected, so when we see - // this we first need to check if there's data available and *then* - // we go through and process the upgrade. - DISCONNECTED => match (&mut *self.data.get()).take() { - Some(data) => Ok(data), - None => match ptr::replace(self.upgrade.get(), SendUsed) { - SendUsed | NothingSent => Err(Disconnected), - GoUp(upgrade) => Err(Upgraded(upgrade)), - }, - }, - - // We are the sole receiver; there cannot be a blocking - // receiver already. - _ => unreachable!(), - } - } - } - - // Returns whether the upgrade was completed. If the upgrade wasn't - // completed, then the port couldn't get sent to the other half (it will - // never receive it). - pub fn upgrade(&self, up: Receiver) -> UpgradeResult { - unsafe { - let prev = match *self.upgrade.get() { - NothingSent => NothingSent, - SendUsed => SendUsed, - _ => panic!("upgrading again"), - }; - ptr::write(self.upgrade.get(), GoUp(up)); - - match self.state.swap(DISCONNECTED, Ordering::SeqCst) { - // If the channel is empty or has data on it, then we're good to go. - // Senders will check the data before the upgrade (in case we - // plastered over the DATA state). - DATA | EMPTY => UpSuccess, - - // If the other end is already disconnected, then we failed the - // upgrade. Be sure to trash the port we were given. - DISCONNECTED => { - ptr::replace(self.upgrade.get(), prev); - UpDisconnected - } - - // If someone's waiting, we gotta wake them up - ptr => UpWoke(SignalToken::from_raw(ptr)), - } - } - } - - pub fn drop_chan(&self) { - match self.state.swap(DISCONNECTED, Ordering::SeqCst) { - DATA | DISCONNECTED | EMPTY => {} - - // If someone's waiting, we gotta wake them up - ptr => unsafe { - SignalToken::from_raw(ptr).signal(); - }, - } - } - - pub fn drop_port(&self) { - match self.state.swap(DISCONNECTED, Ordering::SeqCst) { - // An empty channel has nothing to do, and a remotely disconnected - // channel also has nothing to do b/c we're about to run the drop - // glue - DISCONNECTED | EMPTY => {} - - // There's data on the channel, so make sure we destroy it promptly. - // This is why not using an arc is a little difficult (need the box - // to stay valid while we take the data). - DATA => unsafe { - (&mut *self.data.get()).take().unwrap(); - }, - - // We're the only ones that can block on this port - _ => unreachable!(), - } - } - - //////////////////////////////////////////////////////////////////////////// - // select implementation - //////////////////////////////////////////////////////////////////////////// - - // Remove a previous selecting thread from this port. This ensures that the - // blocked thread will no longer be visible to any other threads. - // - // The return value indicates whether there's data on this port. - pub fn abort_selection(&self) -> Result> { - let state = match self.state.load(Ordering::SeqCst) { - // Each of these states means that no further activity will happen - // with regard to abortion selection - s @ (EMPTY | DATA | DISCONNECTED) => s, - - // If we've got a blocked thread, then use an atomic to gain ownership - // of it (may fail) - ptr => self - .state - .compare_exchange(ptr, EMPTY, Ordering::SeqCst, Ordering::SeqCst) - .unwrap_or_else(|x| x), - }; - - // Now that we've got ownership of our state, figure out what to do - // about it. - match state { - EMPTY => unreachable!(), - // our thread used for select was stolen - DATA => Ok(true), - - // If the other end has hung up, then we have complete ownership - // of the port. First, check if there was data waiting for us. This - // is possible if the other end sent something and then hung up. - // - // We then need to check to see if there was an upgrade requested, - // and if so, the upgraded port needs to have its selection aborted. - DISCONNECTED => unsafe { - if (*self.data.get()).is_some() { - Ok(true) - } else { - match ptr::replace(self.upgrade.get(), SendUsed) { - GoUp(port) => Err(port), - _ => Ok(true), - } - } - }, - - // We woke ourselves up from select. - ptr => unsafe { - drop(SignalToken::from_raw(ptr)); - Ok(false) - }, - } - } -} - -impl Drop for Packet { - fn drop(&mut self) { - assert_eq!(self.state.load(Ordering::SeqCst), DISCONNECTED); - } -} diff --git a/sgx_tstd/src/sync/mpsc/shared.rs b/sgx_tstd/src/sync/mpsc/shared.rs deleted file mode 100644 index 90bdf5d01..000000000 --- a/sgx_tstd/src/sync/mpsc/shared.rs +++ /dev/null @@ -1,515 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License.. - -/// Shared channels. -/// -/// This is the flavor of channels which are not necessarily optimized for any -/// particular use case, but are the most general in how they are used. Shared -/// channels are cloneable allowing for multiple senders. -/// -/// High level implementation details can be found in the comment of the parent -/// module. You'll also note that the implementation of the shared and stream -/// channels are quite similar, and this is no coincidence! -pub use self::Failure::*; -use self::StartResult::*; - -use core::cmp; - -use crate::cell::UnsafeCell; -use crate::ptr; -use crate::sync::atomic::{AtomicBool, AtomicIsize, AtomicPtr, AtomicUsize, Ordering}; -use crate::sync::mpsc::blocking::{self, SignalToken}; -use crate::sync::mpsc::mpsc_queue as mpsc; -use crate::sync::{Mutex, MutexGuard}; -use crate::thread; -use crate::time::Instant; - -use sgx_trts::error::abort; - -const DISCONNECTED: isize = isize::MIN; -const FUDGE: isize = 1024; -const MAX_REFCOUNT: usize = (isize::MAX) as usize; -const MAX_STEALS: isize = 1 << 20; -const EMPTY: *mut u8 = ptr::null_mut(); // initial state: no data, no blocked receiver - -pub struct Packet { - queue: mpsc::Queue, - cnt: AtomicIsize, // How many items are on this channel - steals: UnsafeCell, // How many times has a port received without blocking? - to_wake: AtomicPtr, // SignalToken for wake up - - // The number of channels which are currently using this packet. - channels: AtomicUsize, - - // See the discussion in Port::drop and the channel send methods for what - // these are used for - port_dropped: AtomicBool, - sender_drain: AtomicIsize, - - // this lock protects various portions of this implementation during - // select() - select_lock: Mutex<()>, -} - -pub enum Failure { - Empty, - Disconnected, -} - -#[derive(PartialEq, Eq)] -enum StartResult { - Installed, - Abort, -} - -impl Packet { - // Creation of a packet *must* be followed by a call to postinit_lock - // and later by inherit_blocker - pub fn new() -> Packet { - Packet { - queue: mpsc::Queue::new(), - cnt: AtomicIsize::new(0), - steals: UnsafeCell::new(0), - to_wake: AtomicPtr::new(EMPTY), - channels: AtomicUsize::new(2), - port_dropped: AtomicBool::new(false), - sender_drain: AtomicIsize::new(0), - select_lock: Mutex::new(()), - } - } - - // This function should be used after newly created Packet - // was wrapped with an Arc - // In other case mutex data will be duplicated while cloning - // and that could cause problems on platforms where it is - // represented by opaque data structure - pub fn postinit_lock(&self) -> MutexGuard<'_, ()> { - self.select_lock.lock().unwrap() - } - - // This function is used at the creation of a shared packet to inherit a - // previously blocked thread. This is done to prevent spurious wakeups of - // threads in select(). - // - // This can only be called at channel-creation time - pub fn inherit_blocker(&self, token: Option, guard: MutexGuard<'_, ()>) { - if let Some(token) = token { - assert_eq!(self.cnt.load(Ordering::SeqCst), 0); - assert_eq!(self.to_wake.load(Ordering::SeqCst), EMPTY); - self.to_wake.store(unsafe { token.to_raw() }, Ordering::SeqCst); - self.cnt.store(-1, Ordering::SeqCst); - - // This store is a little sketchy. What's happening here is that - // we're transferring a blocker from a oneshot or stream channel to - // this shared channel. In doing so, we never spuriously wake them - // up and rather only wake them up at the appropriate time. This - // implementation of shared channels assumes that any blocking - // recv() will undo the increment of steals performed in try_recv() - // once the recv is complete. This thread that we're inheriting, - // however, is not in the middle of recv. Hence, the first time we - // wake them up, they're going to wake up from their old port, move - // on to the upgraded port, and then call the block recv() function. - // - // When calling this function, they'll find there's data immediately - // available, counting it as a steal. This in fact wasn't a steal - // because we appropriately blocked them waiting for data. - // - // To offset this bad increment, we initially set the steal count to - // -1. You'll find some special code in abort_selection() as well to - // ensure that this -1 steal count doesn't escape too far. - unsafe { - *self.steals.get() = -1; - } - } - - // When the shared packet is constructed, we grabbed this lock. The - // purpose of this lock is to ensure that abort_selection() doesn't - // interfere with this method. After we unlock this lock, we're - // signifying that we're done modifying self.cnt and self.to_wake and - // the port is ready for the world to continue using it. - drop(guard); - } - - pub fn send(&self, t: T) -> Result<(), T> { - // See Port::drop for what's going on - if self.port_dropped.load(Ordering::SeqCst) { - return Err(t); - } - - // Note that the multiple sender case is a little trickier - // semantically than the single sender case. The logic for - // incrementing is "add and if disconnected store disconnected". - // This could end up leading some senders to believe that there - // wasn't a disconnect if in fact there was a disconnect. This means - // that while one thread is attempting to re-store the disconnected - // states, other threads could walk through merrily incrementing - // this very-negative disconnected count. To prevent senders from - // spuriously attempting to send when the channels is actually - // disconnected, the count has a ranged check here. - // - // This is also done for another reason. Remember that the return - // value of this function is: - // - // `true` == the data *may* be received, this essentially has no - // meaning - // `false` == the data will *never* be received, this has a lot of - // meaning - // - // In the SPSC case, we have a check of 'queue.is_empty()' to see - // whether the data was actually received, but this same condition - // means nothing in a multi-producer context. As a result, this - // preflight check serves as the definitive "this will never be - // received". Once we get beyond this check, we have permanently - // entered the realm of "this may be received" - if self.cnt.load(Ordering::SeqCst) < DISCONNECTED + FUDGE { - return Err(t); - } - - self.queue.push(t); - match self.cnt.fetch_add(1, Ordering::SeqCst) { - -1 => { - self.take_to_wake().signal(); - } - - // In this case, we have possibly failed to send our data, and - // we need to consider re-popping the data in order to fully - // destroy it. We must arbitrate among the multiple senders, - // however, because the queues that we're using are - // single-consumer queues. In order to do this, all exiting - // pushers will use an atomic count in order to count those - // flowing through. Pushers who see 0 are required to drain as - // much as possible, and then can only exit when they are the - // only pusher (otherwise they must try again). - n if n < DISCONNECTED + FUDGE => { - // see the comment in 'try' for a shared channel for why this - // window of "not disconnected" is ok. - self.cnt.store(DISCONNECTED, Ordering::SeqCst); - - if self.sender_drain.fetch_add(1, Ordering::SeqCst) == 0 { - loop { - // drain the queue, for info on the thread yield see the - // discussion in try_recv - loop { - match self.queue.pop() { - mpsc::Data(..) => {} - mpsc::Empty => break, - mpsc::Inconsistent => thread::yield_now(), - } - } - // maybe we're done, if we're not the last ones - // here, then we need to go try again. - if self.sender_drain.fetch_sub(1, Ordering::SeqCst) == 1 { - break; - } - } - - // At this point, there may still be data on the queue, - // but only if the count hasn't been incremented and - // some other sender hasn't finished pushing data just - // yet. That sender in question will drain its own data. - } - } - - // Can't make any assumptions about this case like in the SPSC case. - _ => {} - } - - Ok(()) - } - - pub fn recv(&self, deadline: Option) -> Result { - // This code is essentially the exact same as that found in the stream - // case (see stream.rs) - match self.try_recv() { - Err(Empty) => {} - data => return data, - } - - let (wait_token, signal_token) = blocking::tokens(); - if self.decrement(signal_token) == Installed { - if let Some(deadline) = deadline { - let timed_out = !wait_token.wait_max_until(deadline); - if timed_out { - self.abort_selection(false); - } - } else { - wait_token.wait(); - } - } - - match self.try_recv() { - data @ Ok(..) => unsafe { - *self.steals.get() -= 1; - data - }, - data => data, - } - } - - // Essentially the exact same thing as the stream decrement function. - // Returns true if blocking should proceed. - fn decrement(&self, token: SignalToken) -> StartResult { - unsafe { - assert_eq!( - self.to_wake.load(Ordering::SeqCst), - EMPTY, - "This is a known bug in the Rust standard library. See https://github.com/rust-lang/rust/issues/39364" - ); - let ptr = token.to_raw(); - self.to_wake.store(ptr, Ordering::SeqCst); - - let steals = ptr::replace(self.steals.get(), 0); - - match self.cnt.fetch_sub(1 + steals, Ordering::SeqCst) { - DISCONNECTED => { - self.cnt.store(DISCONNECTED, Ordering::SeqCst); - } - // If we factor in our steals and notice that the channel has no - // data, we successfully sleep - n => { - assert!(n >= 0); - if n - steals <= 0 { - return Installed; - } - } - } - - self.to_wake.store(EMPTY, Ordering::SeqCst); - drop(SignalToken::from_raw(ptr)); - Abort - } - } - - pub fn try_recv(&self) -> Result { - let ret = match self.queue.pop() { - mpsc::Data(t) => Some(t), - mpsc::Empty => None, - - // This is a bit of an interesting case. The channel is reported as - // having data available, but our pop() has failed due to the queue - // being in an inconsistent state. This means that there is some - // pusher somewhere which has yet to complete, but we are guaranteed - // that a pop will eventually succeed. In this case, we spin in a - // yield loop because the remote sender should finish their enqueue - // operation "very quickly". - // - // Avoiding this yield loop would require a different queue - // abstraction which provides the guarantee that after M pushes have - // succeeded, at least M pops will succeed. The current queues - // guarantee that if there are N active pushes, you can pop N times - // once all N have finished. - mpsc::Inconsistent => { - let data; - loop { - thread::yield_now(); - match self.queue.pop() { - mpsc::Data(t) => { - data = t; - break; - } - mpsc::Empty => panic!("inconsistent => empty"), - mpsc::Inconsistent => {} - } - } - Some(data) - } - }; - match ret { - // See the discussion in the stream implementation for why we - // might decrement steals. - Some(data) => unsafe { - if *self.steals.get() > MAX_STEALS { - match self.cnt.swap(0, Ordering::SeqCst) { - DISCONNECTED => { - self.cnt.store(DISCONNECTED, Ordering::SeqCst); - } - n => { - let m = cmp::min(n, *self.steals.get()); - *self.steals.get() -= m; - self.bump(n - m); - } - } - assert!(*self.steals.get() >= 0); - } - *self.steals.get() += 1; - Ok(data) - }, - - // See the discussion in the stream implementation for why we try - // again. - None => { - match self.cnt.load(Ordering::SeqCst) { - n if n != DISCONNECTED => Err(Empty), - _ => { - match self.queue.pop() { - mpsc::Data(t) => Ok(t), - mpsc::Empty => Err(Disconnected), - // with no senders, an inconsistency is impossible. - mpsc::Inconsistent => unreachable!(), - } - } - } - } - } - } - - // Prepares this shared packet for a channel clone, essentially just bumping - // a refcount. - pub fn clone_chan(&self) { - let old_count = self.channels.fetch_add(1, Ordering::SeqCst); - - // See comments on Arc::clone() on why we do this (for `mem::forget`). - if old_count > MAX_REFCOUNT { - abort(); - } - } - - // Decrement the reference count on a channel. This is called whenever a - // Chan is dropped and may end up waking up a receiver. It's the receiver's - // responsibility on the other end to figure out that we've disconnected. - pub fn drop_chan(&self) { - match self.channels.fetch_sub(1, Ordering::SeqCst) { - 1 => {} - n if n > 1 => return, - n => panic!("bad number of channels left {n}"), - } - - match self.cnt.swap(DISCONNECTED, Ordering::SeqCst) { - -1 => { - self.take_to_wake().signal(); - } - DISCONNECTED => {} - n => { - assert!(n >= 0); - } - } - } - - // See the long discussion inside of stream.rs for why the queue is drained, - // and why it is done in this fashion. - #[allow(clippy::while_let_loop)] - pub fn drop_port(&self) { - self.port_dropped.store(true, Ordering::SeqCst); - let mut steals = unsafe { *self.steals.get() }; - while match self.cnt.compare_exchange( - steals, - DISCONNECTED, - Ordering::SeqCst, - Ordering::SeqCst, - ) { - Ok(_) => false, - Err(old) => old != DISCONNECTED, - } { - // See the discussion in 'try_recv' for why we yield - // control of this thread. - loop { - match self.queue.pop() { - mpsc::Data(..) => { - steals += 1; - } - mpsc::Empty | mpsc::Inconsistent => break, - } - } - } - } - - // Consumes ownership of the 'to_wake' field. - fn take_to_wake(&self) -> SignalToken { - let ptr = self.to_wake.load(Ordering::SeqCst); - self.to_wake.store(EMPTY, Ordering::SeqCst); - assert!(ptr != EMPTY); - unsafe { SignalToken::from_raw(ptr) } - } - - //////////////////////////////////////////////////////////////////////////// - // select implementation - //////////////////////////////////////////////////////////////////////////// - - // increment the count on the channel (used for selection) - fn bump(&self, amt: isize) -> isize { - match self.cnt.fetch_add(amt, Ordering::SeqCst) { - DISCONNECTED => { - self.cnt.store(DISCONNECTED, Ordering::SeqCst); - DISCONNECTED - } - n => n, - } - } - - // Cancels a previous thread waiting on this port, returning whether there's - // data on the port. - // - // This is similar to the stream implementation (hence fewer comments), but - // uses a different value for the "steals" variable. - pub fn abort_selection(&self, _was_upgrade: bool) -> bool { - // Before we do anything else, we bounce on this lock. The reason for - // doing this is to ensure that any upgrade-in-progress is gone and - // done with. Without this bounce, we can race with inherit_blocker - // about looking at and dealing with to_wake. Once we have acquired the - // lock, we are guaranteed that inherit_blocker is done. - { - let _guard = self.select_lock.lock().unwrap(); - } - - // Like the stream implementation, we want to make sure that the count - // on the channel goes non-negative. We don't know how negative the - // stream currently is, so instead of using a steal value of 1, we load - // the channel count and figure out what we should do to make it - // positive. - let steals = { - let cnt = self.cnt.load(Ordering::SeqCst); - if cnt < 0 && cnt != DISCONNECTED { -cnt } else { 0 } - }; - let prev = self.bump(steals + 1); - - if prev == DISCONNECTED { - assert_eq!(self.to_wake.load(Ordering::SeqCst), EMPTY); - true - } else { - let cur = prev + steals + 1; - assert!(cur >= 0); - if prev < 0 { - drop(self.take_to_wake()); - } else { - while self.to_wake.load(Ordering::SeqCst) != EMPTY { - thread::yield_now(); - } - } - unsafe { - // if the number of steals is -1, it was the pre-emptive -1 steal - // count from when we inherited a blocker. This is fine because - // we're just going to overwrite it with a real value. - let old = self.steals.get(); - assert!(*old == 0 || *old == -1); - *old = steals; - prev >= 0 - } - } - } -} - -impl Drop for Packet { - fn drop(&mut self) { - // Note that this load is not only an assert for correctness about - // disconnection, but also a proper fence before the read of - // `to_wake`, so this assert cannot be removed with also removing - // the `to_wake` assert. - assert_eq!(self.cnt.load(Ordering::SeqCst), DISCONNECTED); - assert_eq!(self.to_wake.load(Ordering::SeqCst), EMPTY); - assert_eq!(self.channels.load(Ordering::SeqCst), 0); - } -} diff --git a/sgx_tstd/src/sync/mpsc/spsc_queue.rs b/sgx_tstd/src/sync/mpsc/spsc_queue.rs deleted file mode 100644 index 28392aa79..000000000 --- a/sgx_tstd/src/sync/mpsc/spsc_queue.rs +++ /dev/null @@ -1,253 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 single-producer single-consumer concurrent queue -//! -//! This module contains the implementation of an SPSC queue which can be used -//! concurrently between two threads. This data structure is safe to use and -//! enforces the semantics that there is one pusher and one popper. - -// https://www.1024cores.net/home/lock-free-algorithms/queues/unbounded-spsc-queue - -#[cfg(feature = "unit_test")] -mod tests; - -use core::cell::UnsafeCell; -use core::ptr; - -use crate::boxed::Box; -use crate::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; - -use super::cache_aligned::CacheAligned; - -// Node within the linked list queue of messages to send -struct Node { - // FIXME: this could be an uninitialized T if we're careful enough, and - // that would reduce memory usage (and be a bit faster). - // is it worth it? - value: Option, // nullable for re-use of nodes - cached: bool, // This node goes into the node cache - next: AtomicPtr>, // next node in the queue -} - -/// The single-producer single-consumer queue. This structure is not cloneable, -/// but it can be safely shared in an Arc if it is guaranteed that there -/// is only one popper and one pusher touching the queue at any one point in -/// time. -pub struct Queue { - // consumer fields - consumer: CacheAligned>, - - // producer fields - producer: CacheAligned>, -} - -struct Consumer { - tail: UnsafeCell<*mut Node>, // where to pop from - tail_prev: AtomicPtr>, // where to pop from - cache_bound: usize, // maximum cache size - cached_nodes: AtomicUsize, // number of nodes marked as cacheable - addition: Addition, -} - -struct Producer { - head: UnsafeCell<*mut Node>, // where to push to - first: UnsafeCell<*mut Node>, // where to get new nodes from - tail_copy: UnsafeCell<*mut Node>, // between first/tail - addition: Addition, -} - -unsafe impl Send for Queue {} - -unsafe impl Sync for Queue {} - -impl Node { - fn new() -> *mut Node { - Box::into_raw(box Node { - value: None, - cached: false, - next: AtomicPtr::new(ptr::null_mut::>()), - }) - } -} - -impl Queue { - /// Creates a new queue. With given additional elements in the producer and - /// consumer portions of the queue. - /// - /// Due to the performance implications of cache-contention, - /// we wish to keep fields used mainly by the producer on a separate cache - /// line than those used by the consumer. - /// Since cache lines are usually 64 bytes, it is unreasonably expensive to - /// allocate one for small fields, so we allow users to insert additional - /// fields into the cache lines already allocated by this for the producer - /// and consumer. - /// - /// This is unsafe as the type system doesn't enforce a single - /// consumer-producer relationship. It also allows the consumer to `pop` - /// items while there is a `peek` active due to all methods having a - /// non-mutable receiver. - /// - /// # Arguments - /// - /// * `bound` - This queue implementation is implemented with a linked - /// list, and this means that a push is always a malloc. In - /// order to amortize this cost, an internal cache of nodes is - /// maintained to prevent a malloc from always being - /// necessary. This bound is the limit on the size of the - /// cache (if desired). If the value is 0, then the cache has - /// no bound. Otherwise, the cache will never grow larger than - /// `bound` (although the queue itself could be much larger. - pub unsafe fn with_additions( - bound: usize, - producer_addition: ProducerAddition, - consumer_addition: ConsumerAddition, - ) -> Self { - let n1 = Node::new(); - let n2 = Node::new(); - (*n1).next.store(n2, Ordering::Relaxed); - Queue { - consumer: CacheAligned::new(Consumer { - tail: UnsafeCell::new(n2), - tail_prev: AtomicPtr::new(n1), - cache_bound: bound, - cached_nodes: AtomicUsize::new(0), - addition: consumer_addition, - }), - producer: CacheAligned::new(Producer { - head: UnsafeCell::new(n2), - first: UnsafeCell::new(n1), - tail_copy: UnsafeCell::new(n1), - addition: producer_addition, - }), - } - } - - /// Pushes a new value onto this queue. Note that to use this function - /// safely, it must be externally guaranteed that there is only one pusher. - pub fn push(&self, t: T) { - unsafe { - // Acquire a node (which either uses a cached one or allocates a new - // one), and then append this to the 'head' node. - let n = self.alloc(); - assert!((*n).value.is_none()); - (*n).value = Some(t); - (*n).next.store(ptr::null_mut(), Ordering::Relaxed); - (**self.producer.head.get()).next.store(n, Ordering::Release); - *(&self.producer.head).get() = n; - } - } - - unsafe fn alloc(&self) -> *mut Node { - // First try to see if we can consume the 'first' node for our uses. - if *self.producer.first.get() != *self.producer.tail_copy.get() { - let ret = *self.producer.first.get(); - *self.producer.0.first.get() = (*ret).next.load(Ordering::Relaxed); - return ret; - } - // If the above fails, then update our copy of the tail and try - // again. - *self.producer.0.tail_copy.get() = self.consumer.tail_prev.load(Ordering::Acquire); - if *self.producer.first.get() != *self.producer.tail_copy.get() { - let ret = *self.producer.first.get(); - *self.producer.0.first.get() = (*ret).next.load(Ordering::Relaxed); - return ret; - } - // If all of that fails, then we have to allocate a new node - // (there's nothing in the node cache). - Node::new() - } - - /// Attempts to pop a value from this queue. Remember that to use this type - /// safely you must ensure that there is only one popper at a time. - pub fn pop(&self) -> Option { - unsafe { - // The `tail` node is not actually a used node, but rather a - // sentinel from where we should start popping from. Hence, look at - // tail's next field and see if we can use it. If we do a pop, then - // the current tail node is a candidate for going into the cache. - let tail = *self.consumer.tail.get(); - let next = (*tail).next.load(Ordering::Acquire); - if next.is_null() { - return None; - } - assert!((*next).value.is_some()); - let ret = (*next).value.take(); - - *self.consumer.0.tail.get() = next; - if self.consumer.cache_bound == 0 { - self.consumer.tail_prev.store(tail, Ordering::Release); - } else { - let cached_nodes = self.consumer.cached_nodes.load(Ordering::Relaxed); - if cached_nodes < self.consumer.cache_bound && !(*tail).cached { - self.consumer.cached_nodes.store(cached_nodes, Ordering::Relaxed); - (*tail).cached = true; - } - - if (*tail).cached { - self.consumer.tail_prev.store(tail, Ordering::Release); - } else { - (*self.consumer.tail_prev.load(Ordering::Relaxed)) - .next - .store(next, Ordering::Relaxed); - // We have successfully erased all references to 'tail', so - // now we can safely drop it. - let _: Box> = Box::from_raw(tail); - } - } - ret - } - } - - /// Attempts to peek at the head of the queue, returning `None` if the queue - /// has no data currently - /// - /// # Warning - /// The reference returned is invalid if it is not used before the consumer - /// pops the value off the queue. If the producer then pushes another value - /// onto the queue, it will overwrite the value pointed to by the reference. - pub fn peek(&self) -> Option<&mut T> { - // This is essentially the same as above with all the popping bits - // stripped out. - unsafe { - let tail = *self.consumer.tail.get(); - let next = (*tail).next.load(Ordering::Acquire); - if next.is_null() { None } else { (*next).value.as_mut() } - } - } - - pub fn producer_addition(&self) -> &ProducerAddition { - &self.producer.addition - } - - pub fn consumer_addition(&self) -> &ConsumerAddition { - &self.consumer.addition - } -} - -impl Drop for Queue { - fn drop(&mut self) { - unsafe { - let mut cur = *self.producer.first.get(); - while !cur.is_null() { - let next = (*cur).next.load(Ordering::Relaxed); - let _n: Box> = Box::from_raw(cur); - cur = next; - } - } - } -} diff --git a/sgx_tstd/src/sync/mpsc/spsc_queue/tests.rs b/sgx_tstd/src/sync/mpsc/spsc_queue/tests.rs deleted file mode 100644 index 75ae8ea08..000000000 --- a/sgx_tstd/src/sync/mpsc/spsc_queue/tests.rs +++ /dev/null @@ -1,121 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 super::Queue; -use crate::sync::mpsc::channel; -use crate::sync::Arc; -use crate::thread; - -use sgx_test_utils::test_case; - -#[test_case] -fn smoke() { - unsafe { - let queue = Queue::with_additions(0, (), ()); - queue.push(1); - queue.push(2); - assert_eq!(queue.pop(), Some(1)); - assert_eq!(queue.pop(), Some(2)); - assert_eq!(queue.pop(), None); - queue.push(3); - queue.push(4); - assert_eq!(queue.pop(), Some(3)); - assert_eq!(queue.pop(), Some(4)); - assert_eq!(queue.pop(), None); - } -} - -#[test_case] -fn peek() { - unsafe { - let queue = Queue::with_additions(0, (), ()); - queue.push(vec![1]); - - // Ensure the borrowchecker works - match queue.peek() { - Some(vec) => { - assert_eq!(&*vec, &[1]); - } - None => unreachable!(), - } - - match queue.pop() { - Some(vec) => { - assert_eq!(&*vec, &[1]); - } - None => unreachable!(), - } - } -} - -#[test_case] -fn drop_full() { - unsafe { - let q: Queue> = Queue::with_additions(0, (), ()); - q.push(Box::new(1)); - q.push(Box::new(2)); - } -} - -#[test_case] -fn smoke_bound() { - unsafe { - let q = Queue::with_additions(0, (), ()); - q.push(1); - q.push(2); - assert_eq!(q.pop(), Some(1)); - assert_eq!(q.pop(), Some(2)); - assert_eq!(q.pop(), None); - q.push(3); - q.push(4); - assert_eq!(q.pop(), Some(3)); - assert_eq!(q.pop(), Some(4)); - assert_eq!(q.pop(), None); - } -} - -#[test_case] -fn stress() { - unsafe { - stress_bound(0); - stress_bound(1); - } - - unsafe fn stress_bound(bound: usize) { - let count = 100000; - let q = Arc::new(Queue::with_additions(bound, (), ())); - - let (tx, rx) = channel(); - let q2 = q.clone(); - let _t = thread::spawn(move || { - for _ in 0..count { - loop { - match q2.pop() { - Some(1) => break, - Some(_) => panic!(), - None => {} - } - } - } - tx.send(()).unwrap(); - }); - for _ in 0..count { - q.push(1); - } - rx.recv().unwrap(); - } -} diff --git a/sgx_tstd/src/sync/mpsc/stream.rs b/sgx_tstd/src/sync/mpsc/stream.rs deleted file mode 100644 index 1f5051e7a..000000000 --- a/sgx_tstd/src/sync/mpsc/stream.rs +++ /dev/null @@ -1,470 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License.. - -/// Stream channels -/// -/// This is the flavor of channels which are optimized for one sender and one -/// receiver. The sender will be upgraded to a shared channel if the channel is -/// cloned. -/// -/// High level implementation details can be found in the comment of the parent -/// module. -pub use self::Failure::*; -use self::Message::*; -pub use self::UpgradeResult::*; - -use core::cmp; - -use crate::cell::UnsafeCell; -use crate::ptr; -use crate::thread; -use crate::time::Instant; - -use crate::sync::atomic::{AtomicBool, AtomicIsize, AtomicPtr, Ordering}; -use crate::sync::mpsc::blocking::{self, SignalToken}; -use crate::sync::mpsc::spsc_queue as spsc; -use crate::sync::mpsc::Receiver; - -const DISCONNECTED: isize = isize::MIN; -const MAX_STEALS: isize = 1 << 20; -const EMPTY: *mut u8 = ptr::null_mut(); // initial state: no data, no blocked receiver - -pub struct Packet { - // internal queue for all messages - queue: spsc::Queue, ProducerAddition, ConsumerAddition>, -} - -struct ProducerAddition { - cnt: AtomicIsize, // How many items are on this channel - to_wake: AtomicPtr, // SignalToken for the blocked thread to wake up - - port_dropped: AtomicBool, // flag if the channel has been destroyed. -} - -struct ConsumerAddition { - steals: UnsafeCell, // How many times has a port received without blocking? -} - -pub enum Failure { - Empty, - Disconnected, - Upgraded(Receiver), -} - -#[allow(clippy::enum_variant_names)] -pub enum UpgradeResult { - UpSuccess, - UpDisconnected, - UpWoke(SignalToken), -} - -// Any message could contain an "upgrade request" to a new shared port, so the -// internal queue it's a queue of T, but rather Message -enum Message { - Data(T), - GoUp(Receiver), -} - -impl Packet { - pub fn new() -> Packet { - Packet { - queue: unsafe { - spsc::Queue::with_additions( - 128, - ProducerAddition { - cnt: AtomicIsize::new(0), - to_wake: AtomicPtr::new(EMPTY), - - port_dropped: AtomicBool::new(false), - }, - ConsumerAddition { steals: UnsafeCell::new(0) }, - ) - }, - } - } - - pub fn send(&self, t: T) -> Result<(), T> { - // If the other port has deterministically gone away, then definitely - // must return the data back up the stack. Otherwise, the data is - // considered as being sent. - if self.queue.producer_addition().port_dropped.load(Ordering::SeqCst) { - return Err(t); - } - - match self.do_send(Data(t)) { - UpSuccess | UpDisconnected => {} - UpWoke(token) => { - token.signal(); - } - } - Ok(()) - } - - pub fn upgrade(&self, up: Receiver) -> UpgradeResult { - // If the port has gone away, then there's no need to proceed any - // further. - if self.queue.producer_addition().port_dropped.load(Ordering::SeqCst) { - return UpDisconnected; - } - - self.do_send(GoUp(up)) - } - - fn do_send(&self, t: Message) -> UpgradeResult { - self.queue.push(t); - match self.queue.producer_addition().cnt.fetch_add(1, Ordering::SeqCst) { - // As described in the mod's doc comment, -1 == wakeup - -1 => UpWoke(self.take_to_wake()), - // As as described before, SPSC queues must be >= -2 - -2 => UpSuccess, - - // Be sure to preserve the disconnected state, and the return value - // in this case is going to be whether our data was received or not. - // This manifests itself on whether we have an empty queue or not. - // - // Primarily, are required to drain the queue here because the port - // will never remove this data. We can only have at most one item to - // drain (the port drains the rest). - DISCONNECTED => { - self.queue.producer_addition().cnt.store(DISCONNECTED, Ordering::SeqCst); - let first = self.queue.pop(); - let second = self.queue.pop(); - assert!(second.is_none()); - - match first { - Some(..) => UpSuccess, // we failed to send the data - None => UpDisconnected, // we successfully sent data - } - } - - // Otherwise we just sent some data on a non-waiting queue, so just - // make sure the world is sane and carry on! - n => { - assert!(n >= 0); - UpSuccess - } - } - } - - // Consumes ownership of the 'to_wake' field. - fn take_to_wake(&self) -> SignalToken { - let ptr = self.queue.producer_addition().to_wake.load(Ordering::SeqCst); - self.queue.producer_addition().to_wake.store(EMPTY, Ordering::SeqCst); - assert!(ptr != EMPTY); - unsafe { SignalToken::from_raw(ptr) } - } - - // Decrements the count on the channel for a sleeper, returning the sleeper - // back if it shouldn't sleep. Note that this is the location where we take - // steals into account. - fn decrement(&self, token: SignalToken) -> Result<(), SignalToken> { - assert_eq!(self.queue.producer_addition().to_wake.load(Ordering::SeqCst), EMPTY); - let ptr = unsafe { token.to_raw() }; - self.queue.producer_addition().to_wake.store(ptr, Ordering::SeqCst); - - let steals = unsafe { ptr::replace(self.queue.consumer_addition().steals.get(), 0) }; - - match self.queue.producer_addition().cnt.fetch_sub(1 + steals, Ordering::SeqCst) { - DISCONNECTED => { - self.queue.producer_addition().cnt.store(DISCONNECTED, Ordering::SeqCst); - } - // If we factor in our steals and notice that the channel has no - // data, we successfully sleep - n => { - assert!(n >= 0); - if n - steals <= 0 { - return Ok(()); - } - } - } - - self.queue.producer_addition().to_wake.store(EMPTY, Ordering::SeqCst); - Err(unsafe { SignalToken::from_raw(ptr) }) - } - - pub fn recv(&self, deadline: Option) -> Result> { - // Optimistic preflight check (scheduling is expensive). - match self.try_recv() { - Err(Empty) => {} - data => return data, - } - - // Welp, our channel has no data. Deschedule the current thread and - // initiate the blocking protocol. - let (wait_token, signal_token) = blocking::tokens(); - if self.decrement(signal_token).is_ok() { - if let Some(deadline) = deadline { - let timed_out = !wait_token.wait_max_until(deadline); - if timed_out { - self.abort_selection(/* was_upgrade = */ false).map_err(Upgraded)?; - } - } else { - wait_token.wait(); - } - } - - match self.try_recv() { - // Messages which actually popped from the queue shouldn't count as - // a steal, so offset the decrement here (we already have our - // "steal" factored into the channel count above). - data @ (Ok(..) | Err(Upgraded(..))) => unsafe { - *self.queue.consumer_addition().steals.get() -= 1; - data - }, - - data => data, - } - } - - pub fn try_recv(&self) -> Result> { - match self.queue.pop() { - // If we stole some data, record to that effect (this will be - // factored into cnt later on). - // - // Note that we don't allow steals to grow without bound in order to - // prevent eventual overflow of either steals or cnt as an overflow - // would have catastrophic results. Sometimes, steals > cnt, but - // other times cnt > steals, so we don't know the relation between - // steals and cnt. This code path is executed only rarely, so we do - // a pretty slow operation, of swapping 0 into cnt, taking steals - // down as much as possible (without going negative), and then - // adding back in whatever we couldn't factor into steals. - Some(data) => unsafe { - if *self.queue.consumer_addition().steals.get() > MAX_STEALS { - match self.queue.producer_addition().cnt.swap(0, Ordering::SeqCst) { - DISCONNECTED => { - self.queue - .producer_addition() - .cnt - .store(DISCONNECTED, Ordering::SeqCst); - } - n => { - let m = cmp::min(n, *self.queue.consumer_addition().steals.get()); - *self.queue.consumer_addition().steals.get() -= m; - self.bump(n - m); - } - } - assert!(*self.queue.consumer_addition().steals.get() >= 0); - } - *self.queue.consumer_addition().steals.get() += 1; - match data { - Data(t) => Ok(t), - GoUp(up) => Err(Upgraded(up)), - } - }, - - None => { - match self.queue.producer_addition().cnt.load(Ordering::SeqCst) { - n if n != DISCONNECTED => Err(Empty), - - // This is a little bit of a tricky case. We failed to pop - // data above, and then we have viewed that the channel is - // disconnected. In this window more data could have been - // sent on the channel. It doesn't really make sense to - // return that the channel is disconnected when there's - // actually data on it, so be extra sure there's no data by - // popping one more time. - // - // We can ignore steals because the other end is - // disconnected and we'll never need to really factor in our - // steals again. - _ => match self.queue.pop() { - Some(Data(t)) => Ok(t), - Some(GoUp(up)) => Err(Upgraded(up)), - None => Err(Disconnected), - }, - } - } - } - } - - pub fn drop_chan(&self) { - // Dropping a channel is pretty simple, we just flag it as disconnected - // and then wakeup a blocker if there is one. - match self.queue.producer_addition().cnt.swap(DISCONNECTED, Ordering::SeqCst) { - -1 => { - self.take_to_wake().signal(); - } - DISCONNECTED => {} - n => { - assert!(n >= 0); - } - } - } - - pub fn drop_port(&self) { - // Dropping a port seems like a fairly trivial thing. In theory all we - // need to do is flag that we're disconnected and then everything else - // can take over (we don't have anyone to wake up). - // - // The catch for Ports is that we want to drop the entire contents of - // the queue. There are multiple reasons for having this property, the - // largest of which is that if another chan is waiting in this channel - // (but not received yet), then waiting on that port will cause a - // deadlock. - // - // So if we accept that we must now destroy the entire contents of the - // queue, this code may make a bit more sense. The tricky part is that - // we can't let any in-flight sends go un-dropped, we have to make sure - // *everything* is dropped and nothing new will come onto the channel. - - // The first thing we do is set a flag saying that we're done for. All - // sends are gated on this flag, so we're immediately guaranteed that - // there are a bounded number of active sends that we'll have to deal - // with. - self.queue.producer_addition().port_dropped.store(true, Ordering::SeqCst); - - // Now that we're guaranteed to deal with a bounded number of senders, - // we need to drain the queue. This draining process happens atomically - // with respect to the "count" of the channel. If the count is nonzero - // (with steals taken into account), then there must be data on the - // channel. In this case we drain everything and then try again. We will - // continue to fail while active senders send data while we're dropping - // data, but eventually we're guaranteed to break out of this loop - // (because there is a bounded number of senders). - let mut steals = unsafe { *self.queue.consumer_addition().steals.get() }; - while match self.queue.producer_addition().cnt.compare_exchange( - steals, - DISCONNECTED, - Ordering::SeqCst, - Ordering::SeqCst, - ) { - Ok(_) => false, - Err(old) => old != DISCONNECTED, - } { - while self.queue.pop().is_some() { - steals += 1; - } - } - - // At this point in time, we have gated all future senders from sending, - // and we have flagged the channel as being disconnected. The senders - // still have some responsibility, however, because some sends might not - // complete until after we flag the disconnection. There are more - // details in the sending methods that see DISCONNECTED - } - - //////////////////////////////////////////////////////////////////////////// - // select implementation - //////////////////////////////////////////////////////////////////////////// - - // increment the count on the channel (used for selection) - fn bump(&self, amt: isize) -> isize { - match self.queue.producer_addition().cnt.fetch_add(amt, Ordering::SeqCst) { - DISCONNECTED => { - self.queue.producer_addition().cnt.store(DISCONNECTED, Ordering::SeqCst); - DISCONNECTED - } - n => n, - } - } - - // Removes a previous thread from being blocked in this port - pub fn abort_selection(&self, was_upgrade: bool) -> Result> { - // If we're aborting selection after upgrading from a oneshot, then - // we're guarantee that no one is waiting. The only way that we could - // have seen the upgrade is if data was actually sent on the channel - // half again. For us, this means that there is guaranteed to be data on - // this channel. Furthermore, we're guaranteed that there was no - // start_selection previously, so there's no need to modify `self.cnt` - // at all. - // - // Hence, because of these invariants, we immediately return `Ok(true)`. - // Note that the data might not actually be sent on the channel just yet. - // The other end could have flagged the upgrade but not sent data to - // this end. This is fine because we know it's a small bounded windows - // of time until the data is actually sent. - if was_upgrade { - assert_eq!(unsafe { *self.queue.consumer_addition().steals.get() }, 0); - assert_eq!(self.queue.producer_addition().to_wake.load(Ordering::SeqCst), EMPTY); - return Ok(true); - } - - // We want to make sure that the count on the channel goes non-negative, - // and in the stream case we can have at most one steal, so just assume - // that we had one steal. - let steals = 1; - let prev = self.bump(steals + 1); - - // If we were previously disconnected, then we know for sure that there - // is no thread in to_wake, so just keep going - let has_data = if prev == DISCONNECTED { - assert_eq!(self.queue.producer_addition().to_wake.load(Ordering::SeqCst), EMPTY); - true // there is data, that data is that we're disconnected - } else { - let cur = prev + steals + 1; - assert!(cur >= 0); - - // If the previous count was negative, then we just made things go - // positive, hence we passed the -1 boundary and we're responsible - // for removing the to_wake() field and trashing it. - // - // If the previous count was positive then we're in a tougher - // situation. A possible race is that a sender just incremented - // through -1 (meaning it's going to try to wake a thread up), but it - // hasn't yet read the to_wake. In order to prevent a future recv() - // from waking up too early (this sender picking up the plastered - // over to_wake), we spin loop here waiting for to_wake to be 0. - // Note that this entire select() implementation needs an overhaul, - // and this is *not* the worst part of it, so this is not done as a - // final solution but rather out of necessity for now to get - // something working. - if prev < 0 { - drop(self.take_to_wake()); - } else { - while self.queue.producer_addition().to_wake.load(Ordering::SeqCst) != EMPTY { - thread::yield_now(); - } - } - unsafe { - assert_eq!(*self.queue.consumer_addition().steals.get(), 0); - *self.queue.consumer_addition().steals.get() = steals; - } - - // if we were previously positive, then there's surely data to - // receive - prev >= 0 - }; - - // Now that we've determined that this queue "has data", we peek at the - // queue to see if the data is an upgrade or not. If it's an upgrade, - // then we need to destroy this port and abort selection on the - // upgraded port. - if has_data { - match self.queue.peek() { - Some(&mut GoUp(..)) => match self.queue.pop() { - Some(GoUp(port)) => Err(port), - _ => unreachable!(), - }, - _ => Ok(true), - } - } else { - Ok(false) - } - } -} - -impl Drop for Packet { - fn drop(&mut self) { - // Note that this load is not only an assert for correctness about - // disconnection, but also a proper fence before the read of - // `to_wake`, so this assert cannot be removed with also removing - // the `to_wake` assert. - assert_eq!(self.queue.producer_addition().cnt.load(Ordering::SeqCst), DISCONNECTED); - assert_eq!(self.queue.producer_addition().to_wake.load(Ordering::SeqCst), EMPTY); - } -} diff --git a/sgx_tstd/src/sync/mpsc/sync.rs b/sgx_tstd/src/sync/mpsc/sync.rs deleted file mode 100644 index d3f84fb45..000000000 --- a/sgx_tstd/src/sync/mpsc/sync.rs +++ /dev/null @@ -1,514 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License.. - -/// Synchronous channels/ports -/// -/// This channel implementation differs significantly from the asynchronous -/// implementations found next to it (oneshot/stream/share). This is an -/// implementation of a synchronous, bounded buffer channel. -/// -/// Each channel is created with some amount of backing buffer, and sends will -/// *block* until buffer space becomes available. A buffer size of 0 is valid, -/// which means that every successful send is paired with a successful recv. -/// -/// This flavor of channels defines a new `send_opt` method for channels which -/// is the method by which a message is sent but the thread does not panic if it -/// cannot be delivered. -/// -/// Another major difference is that send() will *always* return back the data -/// if it couldn't be sent. This is because it is deterministically known when -/// the data is received and when it is not received. -/// -/// Implementation-wise, it can all be summed up with "use a mutex plus some -/// logic". The mutex used here is an OS native mutex, meaning that no user code -/// is run inside of the mutex (to prevent context switching). This -/// implementation shares almost all code for the buffered and unbuffered cases -/// of a synchronous channel. There are a few branches for the unbuffered case, -/// but they're mostly just relevant to blocking senders. -pub use self::Failure::*; -use self::Blocker::*; - -use core::mem; -use core::ptr; - -use crate::sync::atomic::{AtomicUsize, Ordering}; -use crate::sync::mpsc::blocking::{self, SignalToken, WaitToken}; -use crate::sync::{Mutex, MutexGuard}; -use crate::time::Instant; - -use sgx_trts::error::abort; - -const MAX_REFCOUNT: usize = (isize::MAX) as usize; - -pub struct Packet { - /// Only field outside of the mutex. Just done for kicks, but mainly because - /// the other shared channel already had the code implemented - channels: AtomicUsize, - - lock: Mutex>, -} - -unsafe impl Send for Packet {} - -unsafe impl Sync for Packet {} - -struct State { - disconnected: bool, // Is the channel disconnected yet? - queue: Queue, // queue of senders waiting to send data - blocker: Blocker, // currently blocked thread on this channel - buf: Buffer, // storage for buffered messages - cap: usize, // capacity of this channel - - /// A curious flag used to indicate whether a sender failed or succeeded in - /// blocking. This is used to transmit information back to the thread that it - /// must dequeue its message from the buffer because it was not received. - /// This is only relevant in the 0-buffer case. This obviously cannot be - /// safely constructed, but it's guaranteed to always have a valid pointer - /// value. - canceled: Option<&'static mut bool>, -} - -unsafe impl Send for State {} - -/// Possible flavors of threads who can be blocked on this channel. -enum Blocker { - BlockedSender(SignalToken), - BlockedReceiver(SignalToken), - NoneBlocked, -} - -/// Simple queue for threading threads together. Nodes are stack-allocated, so -/// this structure is not safe at all -struct Queue { - head: *mut Node, - tail: *mut Node, -} - -struct Node { - token: Option, - next: *mut Node, -} - -unsafe impl Send for Node {} - -/// A simple ring-buffer -struct Buffer { - buf: Vec>, - start: usize, - size: usize, -} - -#[derive(Debug)] -pub enum Failure { - Empty, - Disconnected, -} - -/// Atomically blocks the current thread, placing it into `slot`, unlocking `lock` -/// in the meantime. This re-locks the mutex upon returning. -fn wait<'a, 'b, T>( - lock: &'a Mutex>, - mut guard: MutexGuard<'b, State>, - f: fn(SignalToken) -> Blocker, -) -> MutexGuard<'a, State> { - let (wait_token, signal_token) = blocking::tokens(); - match mem::replace(&mut guard.blocker, f(signal_token)) { - NoneBlocked => {} - _ => unreachable!(), - } - drop(guard); // unlock - wait_token.wait(); // block - lock.lock().unwrap() // relock -} - -/// Same as wait, but waiting at most until `deadline`. -fn wait_timeout_receiver<'a, 'b, T>( - lock: &'a Mutex>, - deadline: Instant, - mut guard: MutexGuard<'b, State>, - success: &mut bool, -) -> MutexGuard<'a, State> { - let (wait_token, signal_token) = blocking::tokens(); - match mem::replace(&mut guard.blocker, BlockedReceiver(signal_token)) { - NoneBlocked => {} - _ => unreachable!(), - } - drop(guard); // unlock - *success = wait_token.wait_max_until(deadline); // block - let mut new_guard = lock.lock().unwrap(); // relock - if !*success { - abort_selection(&mut new_guard); - } - new_guard -} - -fn abort_selection(guard: &mut MutexGuard<'_, State>) -> bool { - match mem::replace(&mut guard.blocker, NoneBlocked) { - NoneBlocked => true, - BlockedSender(token) => { - guard.blocker = BlockedSender(token); - true - } - BlockedReceiver(token) => { - drop(token); - false - } - } -} - -/// Wakes up a thread, dropping the lock at the correct time -fn wakeup(token: SignalToken, guard: MutexGuard<'_, State>) { - // We need to be careful to wake up the waiting thread *outside* of the mutex - // in case it incurs a context switch. - drop(guard); - token.signal(); -} - -impl Packet { - #[allow(clippy::bool_to_int_with_if)] - pub fn new(capacity: usize) -> Packet { - Packet { - channels: AtomicUsize::new(1), - lock: Mutex::new(State { - disconnected: false, - blocker: NoneBlocked, - cap: capacity, - canceled: None, - queue: Queue { head: ptr::null_mut(), tail: ptr::null_mut() }, - buf: Buffer { - buf: (0..capacity + if capacity == 0 { 1 } else { 0 }).map(|_| None).collect(), - start: 0, - size: 0, - }, - }), - } - } - - // wait until a send slot is available, returning locked access to - // the channel state. - fn acquire_send_slot(&self) -> MutexGuard<'_, State> { - let mut node = Node { token: None, next: ptr::null_mut() }; - loop { - let mut guard = self.lock.lock().unwrap(); - // are we ready to go? - if guard.disconnected || guard.buf.size() < guard.buf.capacity() { - return guard; - } - // no room; actually block - let wait_token = guard.queue.enqueue(&mut node); - drop(guard); - wait_token.wait(); - } - } - - pub fn send(&self, t: T) -> Result<(), T> { - let mut guard = self.acquire_send_slot(); - if guard.disconnected { - return Err(t); - } - guard.buf.enqueue(t); - - match mem::replace(&mut guard.blocker, NoneBlocked) { - // if our capacity is 0, then we need to wait for a receiver to be - // available to take our data. After waiting, we check again to make - // sure the port didn't go away in the meantime. If it did, we need - // to hand back our data. - NoneBlocked if guard.cap == 0 => { - let mut canceled = false; - assert!(guard.canceled.is_none()); - guard.canceled = Some(unsafe { mem::transmute(&mut canceled) }); - let mut guard = wait(&self.lock, guard, BlockedSender); - if canceled { Err(guard.buf.dequeue()) } else { Ok(()) } - } - - // success, we buffered some data - NoneBlocked => Ok(()), - - // success, someone's about to receive our buffered data. - BlockedReceiver(token) => { - wakeup(token, guard); - Ok(()) - } - - BlockedSender(..) => panic!("lolwut"), - } - } - - pub fn try_send(&self, t: T) -> Result<(), super::TrySendError> { - let mut guard = self.lock.lock().unwrap(); - if guard.disconnected { - Err(super::TrySendError::Disconnected(t)) - } else if guard.buf.size() == guard.buf.capacity() { - Err(super::TrySendError::Full(t)) - } else if guard.cap == 0 { - // With capacity 0, even though we have buffer space we can't - // transfer the data unless there's a receiver waiting. - match mem::replace(&mut guard.blocker, NoneBlocked) { - NoneBlocked => Err(super::TrySendError::Full(t)), - BlockedSender(..) => unreachable!(), - BlockedReceiver(token) => { - guard.buf.enqueue(t); - wakeup(token, guard); - Ok(()) - } - } - } else { - // If the buffer has some space and the capacity isn't 0, then we - // just enqueue the data for later retrieval, ensuring to wake up - // any blocked receiver if there is one. - assert!(guard.buf.size() < guard.buf.capacity()); - guard.buf.enqueue(t); - match mem::replace(&mut guard.blocker, NoneBlocked) { - BlockedReceiver(token) => wakeup(token, guard), - NoneBlocked => {} - BlockedSender(..) => unreachable!(), - } - Ok(()) - } - } - - // Receives a message from this channel - // - // When reading this, remember that there can only ever be one receiver at - // time. - pub fn recv(&self, deadline: Option) -> Result { - let mut guard = self.lock.lock().unwrap(); - - let mut woke_up_after_waiting = false; - // Wait for the buffer to have something in it. No need for a - // while loop because we're the only receiver. - if !guard.disconnected && guard.buf.size() == 0 { - if let Some(deadline) = deadline { - guard = - wait_timeout_receiver(&self.lock, deadline, guard, &mut woke_up_after_waiting); - } else { - guard = wait(&self.lock, guard, BlockedReceiver); - woke_up_after_waiting = true; - } - } - - // N.B., channel could be disconnected while waiting, so the order of - // these conditionals is important. - if guard.disconnected && guard.buf.size() == 0 { - return Err(Disconnected); - } - - // Pick up the data, wake up our neighbors, and carry on - assert!(guard.buf.size() > 0 || (deadline.is_some() && !woke_up_after_waiting)); - - if guard.buf.size() == 0 { - return Err(Empty); - } - - let ret = guard.buf.dequeue(); - self.wakeup_senders(woke_up_after_waiting, guard); - Ok(ret) - } - - pub fn try_recv(&self) -> Result { - let mut guard = self.lock.lock().unwrap(); - - // Easy cases first - if guard.disconnected && guard.buf.size() == 0 { - return Err(Disconnected); - } - if guard.buf.size() == 0 { - return Err(Empty); - } - - // Be sure to wake up neighbors - let ret = Ok(guard.buf.dequeue()); - self.wakeup_senders(false, guard); - ret - } - - // Wake up pending senders after some data has been received - // - // * `waited` - flag if the receiver blocked to receive some data, or if it - // just picked up some data on the way out - // * `guard` - the lock guard that is held over this channel's lock - fn wakeup_senders(&self, waited: bool, mut guard: MutexGuard<'_, State>) { - let pending_sender1: Option = guard.queue.dequeue(); - - // If this is a no-buffer channel (cap == 0), then if we didn't wait we - // need to ACK the sender. If we waited, then the sender waking us up - // was already the ACK. - let pending_sender2 = if guard.cap == 0 && !waited { - match mem::replace(&mut guard.blocker, NoneBlocked) { - NoneBlocked => None, - BlockedReceiver(..) => unreachable!(), - BlockedSender(token) => { - guard.canceled.take(); - Some(token) - } - } - } else { - None - }; - mem::drop(guard); - - // only outside of the lock do we wake up the pending threads - if let Some(token) = pending_sender1 { - token.signal(); - } - if let Some(token) = pending_sender2 { - token.signal(); - } - } - - // Prepares this shared packet for a channel clone, essentially just bumping - // a refcount. - pub fn clone_chan(&self) { - let old_count = self.channels.fetch_add(1, Ordering::SeqCst); - - // See comments on Arc::clone() on why we do this (for `mem::forget`). - if old_count > MAX_REFCOUNT { - abort(); - } - } - - pub fn drop_chan(&self) { - // Only flag the channel as disconnected if we're the last channel - match self.channels.fetch_sub(1, Ordering::SeqCst) { - 1 => {} - _ => return, - } - - // Not much to do other than wake up a receiver if one's there - let mut guard = self.lock.lock().unwrap(); - if guard.disconnected { - return; - } - guard.disconnected = true; - match mem::replace(&mut guard.blocker, NoneBlocked) { - NoneBlocked => {} - BlockedSender(..) => unreachable!(), - BlockedReceiver(token) => wakeup(token, guard), - } - } - - pub fn drop_port(&self) { - let mut guard = self.lock.lock().unwrap(); - - if guard.disconnected { - return; - } - guard.disconnected = true; - - // If the capacity is 0, then the sender may want its data back after - // we're disconnected. Otherwise it's now our responsibility to destroy - // the buffered data. As with many other portions of this code, this - // needs to be careful to destroy the data *outside* of the lock to - // prevent deadlock. - let _data = if guard.cap != 0 { mem::take(&mut guard.buf.buf) } else { Vec::new() }; - let mut queue = - mem::replace(&mut guard.queue, Queue { head: ptr::null_mut(), tail: ptr::null_mut() }); - - let waiter = match mem::replace(&mut guard.blocker, NoneBlocked) { - NoneBlocked => None, - BlockedSender(token) => { - *guard.canceled.take().unwrap() = true; - Some(token) - } - BlockedReceiver(..) => unreachable!(), - }; - mem::drop(guard); - - while let Some(token) = queue.dequeue() { - token.signal(); - } - if let Some(token) = waiter { - token.signal(); - } - } -} - -impl Drop for Packet { - fn drop(&mut self) { - assert_eq!(self.channels.load(Ordering::SeqCst), 0); - let mut guard = self.lock.lock().unwrap(); - assert!(guard.queue.dequeue().is_none()); - assert!(guard.canceled.is_none()); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// Buffer, a simple ring buffer backed by Vec -//////////////////////////////////////////////////////////////////////////////// - -impl Buffer { - fn enqueue(&mut self, t: T) { - let pos = (self.start + self.size) % self.buf.len(); - self.size += 1; - let prev = mem::replace(&mut self.buf[pos], Some(t)); - assert!(prev.is_none()); - } - - fn dequeue(&mut self) -> T { - let start = self.start; - self.size -= 1; - self.start = (self.start + 1) % self.buf.len(); - let result = &mut self.buf[start]; - result.take().unwrap() - } - - fn size(&self) -> usize { - self.size - } - fn capacity(&self) -> usize { - self.buf.len() - } -} - -//////////////////////////////////////////////////////////////////////////////// -// Queue, a simple queue to enqueue threads with (stack-allocated nodes) -//////////////////////////////////////////////////////////////////////////////// - -impl Queue { - fn enqueue(&mut self, node: &mut Node) -> WaitToken { - let (wait_token, signal_token) = blocking::tokens(); - node.token = Some(signal_token); - node.next = ptr::null_mut(); - - if self.tail.is_null() { - self.head = node as *mut Node; - self.tail = node as *mut Node; - } else { - unsafe { - (*self.tail).next = node as *mut Node; - self.tail = node as *mut Node; - } - } - - wait_token - } - - fn dequeue(&mut self) -> Option { - if self.head.is_null() { - return None; - } - let node = self.head; - self.head = unsafe { (*node).next }; - if self.head.is_null() { - self.tail = ptr::null_mut(); - } - unsafe { - (*node).next = ptr::null_mut(); - Some((*node).token.take().unwrap()) - } - } -} diff --git a/sgx_tstd/src/sync/mpsc/sync_tests.rs b/sgx_tstd/src/sync/mpsc/sync_tests.rs index dcf46a60b..4f5da1d5b 100644 --- a/sgx_tstd/src/sync/mpsc/sync_tests.rs +++ b/sgx_tstd/src/sync/mpsc/sync_tests.rs @@ -17,6 +17,8 @@ use super::*; use crate::env; +use crate::rc::Rc; +use crate::sync::mpmc::SendTimeoutError; use crate::thread; use crate::time::Duration; @@ -61,6 +63,13 @@ fn recv_timeout() { assert_eq!(rx.recv_timeout(Duration::from_millis(1)), Ok(1)); } +#[test_case] +fn send_timeout() { + let (tx, _rx) = sync_channel::(1); + assert_eq!(tx.send_timeout(1, Duration::from_millis(1)), Ok(())); + assert_eq!(tx.send_timeout(1, Duration::from_millis(1)), Err(SendTimeoutError::Timeout(1))); +} + #[test_case] fn smoke_threads() { let (tx, rx) = sync_channel::(0); @@ -669,3 +678,15 @@ fn issue_15761() { repro() } } + +#[test_case] +fn drop_unreceived() { + let (tx, rx) = sync_channel::>(1); + let msg = Rc::new(()); + let weak = Rc::downgrade(&msg); + assert!(tx.send(msg).is_ok()); + drop(rx); + // Messages should be dropped immediately when the last receiver is destroyed. + assert!(weak.upgrade().is_none()); + drop(tx); +} diff --git a/sgx_tstd/src/sync/mpsc/tests.rs b/sgx_tstd/src/sync/mpsc/tests.rs index 5929ca6e7..a028f080c 100644 --- a/sgx_tstd/src/sync/mpsc/tests.rs +++ b/sgx_tstd/src/sync/mpsc/tests.rs @@ -730,3 +730,18 @@ fn issue_32114() { let _ = tx.send(123); assert_eq!(tx.send(123), Err(SendError(123))); } + +#[test_case] +fn issue_39364() { + let (tx, rx) = channel::<()>(); + let t = thread::spawn(move || { + thread::sleep(Duration::from_millis(300)); + let _ = tx.clone(); + // Don't drop; hand back to caller. + tx + }); + + let _ = rx.recv_timeout(Duration::from_millis(500)); + let _tx = t.join().unwrap(); // delay dropping until end of test + let _ = rx.recv_timeout(Duration::from_millis(500)); +} diff --git a/sgx_tstd/src/sync/mutex.rs b/sgx_tstd/src/sync/mutex.rs index 438e39446..8b16c7e58 100644 --- a/sgx_tstd/src/sync/mutex.rs +++ b/sgx_tstd/src/sync/mutex.rs @@ -124,8 +124,8 @@ use crate::sys_common::mutex as sys; /// *guard += 1; /// ``` /// -/// It is sometimes necessary to manually drop the mutex guard to unlock it -/// sooner than the end of the enclosing scope. +/// To unlock a mutex guard sooner than the end of the enclosing scope, +/// either create an inner scope or drop the guard manually. /// /// ``` /// use std::sync::{Arc, Mutex}; @@ -142,11 +142,18 @@ use crate::sys_common::mutex as sys; /// let res_mutex_clone = Arc::clone(&res_mutex); /// /// threads.push(thread::spawn(move || { -/// let mut data = data_mutex_clone.lock().unwrap(); -/// // This is the result of some important and long-ish work. -/// let result = data.iter().fold(0, |acc, x| acc + x * 2); -/// data.push(result); -/// drop(data); +/// // Here we use a block to limit the lifetime of the lock guard. +/// let result = { +/// let mut data = data_mutex_clone.lock().unwrap(); +/// // This is the result of some important and long-ish work. +/// let result = data.iter().fold(0, |acc, x| acc + x * 2); +/// data.push(result); +/// result +/// // The mutex guard gets dropped here, together with any other values +/// // created in the critical section. +/// }; +/// // The guard created here is a temporary dropped at the end of the statement, i.e. +/// // the lock would not remain being held even if the thread did some additional work. /// *res_mutex_clone.lock().unwrap() += result; /// })); /// }); @@ -163,6 +170,8 @@ use crate::sys_common::mutex as sys; /// // It's even more important here than in the threads because we `.join` the /// // threads after that. If we had not dropped the mutex guard, a thread could /// // be waiting forever for it, causing a deadlock. +/// // As in the threads, a block could have been used instead of calling the +/// // `drop` function. /// drop(data); /// // Here the mutex guard is not assigned to a variable and so, even if the /// // scope does not end after this line, the mutex is still released: there is @@ -177,9 +186,10 @@ use crate::sys_common::mutex as sys; /// /// assert_eq!(*res_mutex.lock().unwrap(), 800); /// ``` +/// #[cfg_attr(not(test), rustc_diagnostic_item = "Mutex")] pub struct Mutex { - inner: sys::MovableMutex, + inner: sys::Mutex, poison: poison::Flag, data: UnsafeCell, } @@ -225,11 +235,7 @@ impl Mutex { /// ``` #[inline] pub const fn new(t: T) -> Mutex { - Mutex { - inner: sys::MovableMutex::new(), - poison: poison::Flag::new(), - data: UnsafeCell::new(t), - } + Mutex { inner: sys::Mutex::new(), poison: poison::Flag::new(), data: UnsafeCell::new(t) } } } @@ -271,7 +277,7 @@ impl Mutex { /// ``` pub fn lock(&self) -> LockResult> { unsafe { - self.inner.raw_lock(); + self.inner.lock(); MutexGuard::new(self) } } @@ -482,13 +488,7 @@ impl fmt::Debug for Mutex { d.field("data", &&**err.get_ref()); } Err(TryLockError::WouldBlock) => { - struct LockedPlaceholder; - impl fmt::Debug for LockedPlaceholder { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str("") - } - } - d.field("data", &LockedPlaceholder); + d.field("data", &format_args!("")); } } d.field("poisoned", &self.poison.get()); @@ -521,7 +521,7 @@ impl Drop for MutexGuard<'_, T> { fn drop(&mut self) { unsafe { self.lock.poison.done(&self.poison); - self.lock.inner.raw_unlock(); + self.lock.inner.unlock(); } } } @@ -538,7 +538,7 @@ impl fmt::Display for MutexGuard<'_, T> { } } -pub fn guard_lock<'a, T: ?Sized>(guard: &MutexGuard<'a, T>) -> &'a sys::MovableMutex { +pub fn guard_lock<'a, T: ?Sized>(guard: &MutexGuard<'a, T>) -> &'a sys::Mutex { &guard.lock.inner } diff --git a/sgx_tstd/src/sync/mutex/tests.rs b/sgx_tstd/src/sync/mutex/tests.rs index 008c724da..9223dcb6c 100644 --- a/sgx_tstd/src/sync/mutex/tests.rs +++ b/sgx_tstd/src/sync/mutex/tests.rs @@ -152,13 +152,13 @@ fn test_mutex_arc_condvar() { let _t = thread::spawn(move || { // wait until parent gets in rx.recv().unwrap(); - let &(ref lock, ref cvar) = &*packet2.0; + let (lock, cvar) = &*packet2.0; let mut lock = lock.lock().unwrap(); *lock = true; cvar.notify_one(); }); - let &(ref lock, ref cvar) = &*packet.0; + let (lock, cvar) = &*packet.0; let mut lock = lock.lock().unwrap(); tx.send(()).unwrap(); assert!(!*lock); @@ -175,14 +175,14 @@ fn test_arc_condvar_poison() { let _t = thread::spawn(move || -> () { rx.recv().unwrap(); - let &(ref lock, ref cvar) = &*packet2.0; + let (lock, cvar) = &*packet2.0; let _g = lock.lock().unwrap(); cvar.notify_one(); // Parent should fail when it wakes up. panic!(); }); - let &(ref lock, ref cvar) = &*packet.0; + let (lock, cvar) = &*packet.0; let mut lock = lock.lock().unwrap(); tx.send(()).unwrap(); while *lock == 1 { @@ -203,7 +203,7 @@ fn test_mutex_arc_poison() { let arc2 = arc.clone(); let _ = thread::spawn(move || { let lock = arc2.lock().unwrap(); - assert_eq!(*lock, 2); + assert_eq!(*lock, 2); // deliberate assertion failure to poison the mutex }) .join(); assert!(arc.lock().is_err()); diff --git a/sgx_tstd/src/sync/once.rs b/sgx_tstd/src/sync/once.rs index 7a8c72142..d657b6761 100644 --- a/sgx_tstd/src/sync/once.rs +++ b/sgx_tstd/src/sync/once.rs @@ -56,6 +56,12 @@ pub struct OnceState { pub(crate) inner: sys::OnceState, } +pub(crate) enum ExclusiveState { + Incomplete, + Poisoned, + Complete, +} + /// Initialization value for static [`Once`] values. /// /// # Examples @@ -90,7 +96,7 @@ impl Once { /// return). /// /// If the given closure recursively invokes `call_once` on the same [`Once`] - /// instance the exact behavior is not specified, allowed outcomes are + /// instance, the exact behavior is not specified: allowed outcomes are /// a panic or a deadlock. /// /// # Examples @@ -124,7 +130,7 @@ impl Once { /// /// # Panics /// - /// The closure `f` will only be executed once if this is called + /// The closure `f` will only be executed once even if this is called /// concurrently amongst many threads. If that closure panics, however, then /// it will *poison* this [`Once`] instance, causing all future invocations of /// `call_once` to also panic. @@ -250,6 +256,16 @@ impl Once { pub fn is_completed(&self) -> bool { self.inner.is_completed() } + + /// Returns the current state of the `Once` instance. + /// + /// Since this takes a mutable reference, no initialization can currently + /// be running, so the state must be either "incomplete", "poisoned" or + /// "complete". + #[inline] + pub(crate) fn state(&mut self) -> ExclusiveState { + self.inner.state() + } } impl fmt::Debug for Once { diff --git a/sgx_tstd/src/sync/once_lock.rs b/sgx_tstd/src/sync/once_lock.rs index 221b57517..f5cdc83bd 100644 --- a/sgx_tstd/src/sync/once_lock.rs +++ b/sgx_tstd/src/sync/once_lock.rs @@ -26,13 +26,13 @@ use crate::sync::Once; /// A synchronization primitive which can be written to only once. /// -/// This type is a thread-safe `OnceCell`. +/// This type is a thread-safe [`OnceCell`], and can be used in statics. +/// +/// [`OnceCell`]: crate::cell::OnceCell /// /// # Examples /// /// ``` -/// #![feature(once_cell)] -/// /// use std::sync::OnceLock; /// /// static CELL: OnceLock = OnceLock::new(); @@ -51,13 +51,11 @@ use crate::sync::Once; /// ``` pub struct OnceLock { once: Once, - // Whether or not the value is initialized is tracked by `state_and_queue`. + // Whether or not the value is initialized is tracked by `once.is_completed()`. value: UnsafeCell>, /// `PhantomData` to make sure dropck understands we're dropping T in our Drop impl. /// /// ```compile_fail,E0597 - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// /// struct A<'a>(&'a str); @@ -77,6 +75,7 @@ pub struct OnceLock { impl OnceLock { /// Creates a new empty cell. + #[inline] #[must_use] pub const fn new() -> OnceLock { OnceLock { @@ -90,6 +89,7 @@ impl OnceLock { /// /// Returns `None` if the cell is empty, or being initialized. This /// method never blocks. + #[inline] pub fn get(&self) -> Option<&T> { if self.is_initialized() { // Safe b/c checked is_initialized @@ -102,6 +102,7 @@ impl OnceLock { /// Gets the mutable reference to the underlying value. /// /// Returns `None` if the cell is empty. This method never blocks. + #[inline] pub fn get_mut(&mut self) -> Option<&mut T> { if self.is_initialized() { // Safe b/c checked is_initialized and we have a unique access @@ -121,13 +122,11 @@ impl OnceLock { /// # Examples /// /// ``` - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// /// static CELL: OnceLock = OnceLock::new(); /// - /// fn main() { + /// fn needless_main() { /// assert!(CELL.get().is_none()); /// /// std::thread::spawn(|| { @@ -138,12 +137,49 @@ impl OnceLock { /// assert_eq!(CELL.get(), Some(&92)); /// } /// ``` + #[inline] pub fn set(&self, value: T) -> Result<(), T> { + match self.try_insert(value) { + Ok(_) => Ok(()), + Err((_, value)) => Err(value), + } + } + + /// Sets the contents of this cell to `value` if the cell was empty, then + /// returns a reference to it. + /// + /// May block if another thread is currently attempting to initialize the cell. The cell is + /// guaranteed to contain a value when set returns, though not necessarily the one provided. + /// + /// Returns `Ok(&value)` if the cell was empty and `Err(¤t_value, value)` if it was full. + /// + /// # Examples + /// + /// ``` + /// #![feature(once_cell_try_insert)] + /// + /// use std::sync::OnceLock; + /// + /// static CELL: OnceLock = OnceLock::new(); + /// + /// fn needless_main() { + /// assert!(CELL.get().is_none()); + /// + /// std::thread::spawn(|| { + /// assert_eq!(CELL.try_insert(92), Ok(&92)); + /// }).join().unwrap(); + /// + /// assert_eq!(CELL.try_insert(62), Err((&92, 62))); + /// assert_eq!(CELL.get(), Some(&92)); + /// } + /// ``` + #[inline] + pub fn try_insert(&self, value: T) -> Result<&T, (&T, T)> { let mut value = Some(value); - self.get_or_init(|| value.take().unwrap()); + let res = self.get_or_init(|| value.take().unwrap()); match value { - None => Ok(()), - Some(value) => Err(value), + None => Ok(res), + Some(value) => Err((res, value)), } } @@ -166,8 +202,6 @@ impl OnceLock { /// # Examples /// /// ``` - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// /// let cell = OnceLock::new(); @@ -176,6 +210,7 @@ impl OnceLock { /// let value = cell.get_or_init(|| unreachable!()); /// assert_eq!(value, &92); /// ``` + #[inline] pub fn get_or_init(&self, f: F) -> &T where F: FnOnce() -> T, @@ -202,7 +237,7 @@ impl OnceLock { /// # Examples /// /// ``` - /// #![feature(once_cell)] + /// #![feature(once_cell_try)] /// /// use std::sync::OnceLock; /// @@ -215,6 +250,7 @@ impl OnceLock { /// assert_eq!(value, Ok(&92)); /// assert_eq!(cell.get(), Some(&92)) /// ``` + #[inline] pub fn get_or_try_init(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result, @@ -241,8 +277,6 @@ impl OnceLock { /// # Examples /// /// ``` - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// /// let cell: OnceLock = OnceLock::new(); @@ -252,6 +286,7 @@ impl OnceLock { /// cell.set("hello".to_string()).unwrap(); /// assert_eq!(cell.into_inner(), Some("hello".to_string())); /// ``` + #[inline] pub fn into_inner(mut self) -> Option { self.take() } @@ -265,8 +300,6 @@ impl OnceLock { /// # Examples /// /// ``` - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// /// let mut cell: OnceLock = OnceLock::new(); @@ -277,6 +310,7 @@ impl OnceLock { /// assert_eq!(cell.take(), Some("hello".to_string())); /// assert_eq!(cell.get(), None); /// ``` + #[inline] pub fn take(&mut self) -> Option { if self.is_initialized() { self.once = Once::new(); @@ -324,6 +358,7 @@ impl OnceLock { /// # Safety /// /// The value must be initialized + #[inline] unsafe fn get_unchecked(&self) -> &T { debug_assert!(self.is_initialized()); (&*self.value.get()).assume_init_ref() @@ -332,6 +367,7 @@ impl OnceLock { /// # Safety /// /// The value must be initialized + #[inline] unsafe fn get_unchecked_mut(&mut self) -> &mut T { debug_assert!(self.is_initialized()); (&mut *self.value.get()).assume_init_mut() @@ -349,20 +385,19 @@ unsafe impl Send for OnceLock {} impl RefUnwindSafe for OnceLock {} impl UnwindSafe for OnceLock {} -impl const Default for OnceLock { +impl Default for OnceLock { /// Creates a new empty cell. /// /// # Example /// /// ``` - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// /// fn needless_main() { /// assert_eq!(OnceLock::<()>::new(), OnceLock::default()); /// } /// ``` + #[inline] fn default() -> OnceLock { OnceLock::new() } @@ -370,14 +405,17 @@ impl const Default for OnceLock { impl fmt::Debug for OnceLock { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut d = f.debug_tuple("OnceLock"); match self.get() { - Some(v) => f.debug_tuple("Once").field(v).finish(), - None => f.write_str("Once(Uninit)"), - } + Some(v) => d.field(v), + None => d.field(&format_args!("")), + }; + d.finish() } } impl Clone for OnceLock { + #[inline] fn clone(&self) -> OnceLock { let cell = Self::new(); if let Some(value) = self.get() { @@ -396,11 +434,9 @@ impl From for OnceLock { /// # Example /// /// ``` - /// #![feature(once_cell)] - /// /// use std::sync::OnceLock; /// - /// # fn main() -> Result<(), i32> { + /// # fn needless_main() -> Result<(), i32> { /// let a = OnceLock::from(3); /// let b = OnceLock::new(); /// b.set(3)?; @@ -408,6 +444,7 @@ impl From for OnceLock { /// Ok(()) /// # } /// ``` + #[inline] fn from(value: T) -> Self { let cell = Self::new(); match cell.set(value) { @@ -418,6 +455,7 @@ impl From for OnceLock { } impl PartialEq for OnceLock { + #[inline] fn eq(&self, other: &OnceLock) -> bool { self.get() == other.get() } @@ -426,6 +464,7 @@ impl PartialEq for OnceLock { impl Eq for OnceLock {} unsafe impl<#[may_dangle] T> Drop for OnceLock { + #[inline] fn drop(&mut self) { if self.is_initialized() { // SAFETY: The cell is initialized and being dropped, so it can't diff --git a/sgx_tstd/src/sync/once_lock/tests.rs b/sgx_tstd/src/sync/once_lock/tests.rs index 3477c0988..501e1da01 100644 --- a/sgx_tstd/src/sync/once_lock/tests.rs +++ b/sgx_tstd/src/sync/once_lock/tests.rs @@ -42,7 +42,7 @@ fn sync_once_cell() { assert_eq!(ONCE_CELL.get(), Some(&92)); }); - ONCE_CELL.get_or_init(|| panic!("Kabom!")); + ONCE_CELL.get_or_init(|| panic!("Kaboom!")); assert_eq!(ONCE_CELL.get(), Some(&92)); } @@ -193,8 +193,6 @@ fn sync_once_cell_does_not_leak_partially_constructed_boxes() { tx.send(msg).unwrap(); break; } - #[cfg(target_env = "sgx")] - crate::thread::yield_now(); } }); } diff --git a/sgx_tstd/src/personality.rs b/sgx_tstd/src/sync/remutex.rs similarity index 60% rename from sgx_tstd/src/personality.rs rename to sgx_tstd/src/sync/remutex.rs index 08e20d5b7..9ed1aeca7 100644 --- a/sgx_tstd/src/personality.rs +++ b/sgx_tstd/src/sync/remutex.rs @@ -15,17 +15,7 @@ // specific language governing permissions and limitations // under the License.. -//! This module contains the implementation of the `eh_personality` lang item. -//! -//! The actual implementation is heavily dependent on the target since Rust -//! tries to use the native stack unwinding mechanism whenever possible. -//! -//! This personality function is still required with `-C panic=abort` because -//! it is used to catch foreign exceptions from `extern "C-unwind"` and turn -//! them into aborts. -//! -//! Additionally, ARM EHABI uses the personality function when generating -//! backtraces. +#[cfg(feature = "unit_test")] +mod tests; -mod dwarf; -mod gcc; +pub use crate::sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard}; diff --git a/sgx_tstd/src/sys_common/remutex/tests.rs b/sgx_tstd/src/sync/remutex/tests.rs similarity index 95% rename from sgx_tstd/src/sys_common/remutex/tests.rs rename to sgx_tstd/src/sync/remutex/tests.rs index 57c6800de..131c4708e 100644 --- a/sgx_tstd/src/sys_common/remutex/tests.rs +++ b/sgx_tstd/src/sync/remutex/tests.rs @@ -15,16 +15,15 @@ // specific language governing permissions and limitations // under the License.. -#![allow(clippy::unit_cmp)] - +use super::{ReentrantMutex, ReentrantMutexGuard}; use crate::cell::RefCell; use crate::sync::Arc; -use crate::sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard}; use crate::thread; use sgx_test_utils::test_case; #[test_case] +#[allow(clippy::unit_cmp)] fn smoke() { let m = ReentrantMutex::new(()); { diff --git a/sgx_tstd/src/sync/rwlock.rs b/sgx_tstd/src/sync/rwlock.rs index c0cb21a2d..312f7e3ba 100644 --- a/sgx_tstd/src/sync/rwlock.rs +++ b/sgx_tstd/src/sync/rwlock.rs @@ -93,7 +93,7 @@ use crate::sys_common::rwlock as sys; /// /// [`Mutex`]: super::Mutex pub struct RwLock { - inner: sys::MovableRwLock, + inner: sys::RwLock, poison: poison::Flag, data: UnsafeCell, } @@ -120,7 +120,7 @@ pub struct RwLockReadGuard<'a, T: ?Sized + 'a> { // `NonNull` is also covariant over `T`, just like we would have with `&T`. `NonNull` // is preferable over `const* T` to allow for niche optimization. data: NonNull, - inner_lock: &'a sys::MovableRwLock, + inner_lock: &'a sys::RwLock, } impl !Send for RwLockReadGuard<'_, T> {} @@ -160,11 +160,7 @@ impl RwLock { /// ``` #[inline] pub const fn new(t: T) -> RwLock { - RwLock { - inner: sys::MovableRwLock::new(), - poison: poison::Flag::new(), - data: UnsafeCell::new(t), - } + RwLock { inner: sys::RwLock::new(), poison: poison::Flag::new(), data: UnsafeCell::new(t) } } } @@ -381,7 +377,7 @@ impl RwLock { /// /// If the lock is poisoned, it will remain poisoned until this function is called. This allows /// recovering from a poisoned state and marking that it has recovered. For example, if the - /// value is overwritten by a known-good value, then the mutex can be marked as un-poisoned. Or + /// value is overwritten by a known-good value, then the lock can be marked as un-poisoned. Or /// possibly, the value could be inspected to determine if it is in a consistent state, and if /// so the poison is removed. /// @@ -398,7 +394,7 @@ impl RwLock { /// /// let _ = thread::spawn(move || { /// let _lock = c_lock.write().unwrap(); - /// panic!(); // the mutex gets poisoned + /// panic!(); // the lock gets poisoned /// }).join(); /// /// assert_eq!(lock.is_poisoned(), true); @@ -482,13 +478,7 @@ impl fmt::Debug for RwLock { d.field("data", &&**err.get_ref()); } Err(TryLockError::WouldBlock) => { - struct LockedPlaceholder; - impl fmt::Debug for LockedPlaceholder { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str("") - } - } - d.field("data", &LockedPlaceholder); + d.field("data", &format_args!("")); } } d.field("poisoned", &self.poison.get()); diff --git a/sgx_tstd/src/sync/rwlock/tests.rs b/sgx_tstd/src/sync/rwlock/tests.rs index 06025441d..30d0ad8e3 100644 --- a/sgx_tstd/src/sync/rwlock/tests.rs +++ b/sgx_tstd/src/sync/rwlock/tests.rs @@ -19,7 +19,7 @@ use crate::sync::atomic::{AtomicUsize, Ordering}; use crate::sync::mpsc::channel; -use crate::sync::{Arc, RwLock, TryLockError}; +use crate::sync::{Arc, RwLock, RwLockReadGuard, TryLockError}; use crate::thread; use sgx_trts::rand::Rng; @@ -268,3 +268,15 @@ fn test_get_mut_poison() { Ok(x) => panic!("get_mut of poisoned RwLock is Ok: {x:?}"), } } + +#[test_case] +fn test_read_guard_covariance() { + fn do_stuff<'a>(_: RwLockReadGuard<'_, &'a i32>, _: &'a i32) {} + let j: i32 = 5; + let lock = RwLock::new(&j); + { + let i = 6; + do_stuff(lock.read().unwrap(), &i); + } + // drop(lock); +} diff --git a/sgx_tstd/src/sys/backtrace/mod.rs b/sgx_tstd/src/sys/backtrace/mod.rs index 6ded5807a..75aef3640 100644 --- a/sgx_tstd/src/sys/backtrace/mod.rs +++ b/sgx_tstd/src/sys/backtrace/mod.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -pub use self::printing::{BacktraceFmt, BacktraceFrameFmt, PrintFmt}; +pub use self::printing::{BacktraceFmt, PrintFmt}; /// Backtrace support built on libgcc with some extra OS-specific support /// /// Some methods of getting a backtrace: diff --git a/sgx_tstd/src/sys/cmath.rs b/sgx_tstd/src/sys/cmath.rs index 632097f74..df4acf69c 100644 --- a/sgx_tstd/src/sys/cmath.rs +++ b/sgx_tstd/src/sys/cmath.rs @@ -45,4 +45,8 @@ extern "C" { pub fn tanf(n: f32) -> f32; pub fn tanh(n: f64) -> f64; pub fn tanhf(n: f32) -> f32; + pub fn tgamma(n: f64) -> f64; + pub fn tgammaf(n: f32) -> f32; + pub fn lgamma_r(n: f64, s: &mut i32) -> f64; + pub fn lgammaf_r(n: f32, s: &mut i32) -> f32; } diff --git a/sgx_tstd/src/sys/common/mod.rs b/sgx_tstd/src/sys/common/mod.rs index d67b333f9..e1eed39b8 100644 --- a/sgx_tstd/src/sys/common/mod.rs +++ b/sgx_tstd/src/sys/common/mod.rs @@ -15,7 +15,10 @@ // specific language governing permissions and limitations // under the License.. +#![allow(dead_code)] pub mod small_c_string; +#[allow(unused_imports)] +pub mod thread_local; #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/sys/common/small_c_string.rs b/sgx_tstd/src/sys/common/small_c_string.rs index ca118f0d1..8c2f59734 100644 --- a/sgx_tstd/src/sys/common/small_c_string.rs +++ b/sgx_tstd/src/sys/common/small_c_string.rs @@ -31,7 +31,7 @@ pub fn run_path_with_cstr(path: &Path, f: F) -> io::Result where F: FnOnce(&CStr) -> io::Result, { - run_with_cstr(path.as_os_str().bytes(), f) + run_with_cstr(path.as_os_str().as_encoded_bytes(), f) } #[inline] diff --git a/sgx_tstd/src/sys/common/tests.rs b/sgx_tstd/src/sys/common/tests.rs index 5e18b435d..5913ab3d6 100644 --- a/sgx_tstd/src/sys/common/tests.rs +++ b/sgx_tstd/src/sys/common/tests.rs @@ -28,7 +28,7 @@ use sgx_test_utils::{bench_case, Bencher}; fn stack_allocation_works() { let path = Path::new("abc"); let result = run_path_with_cstr(path, |p| { - assert_eq!(p, &*CString::new(path.as_os_str().bytes()).unwrap()); + assert_eq!(p, &*CString::new(path.as_os_str().as_encoded_bytes()).unwrap()); Ok(42) }); assert_eq!(result.unwrap(), 42); @@ -45,7 +45,7 @@ fn heap_allocation_works() { let path = repeat("a").take(128).collect::(); let path = Path::new(&path); let result = run_path_with_cstr(path, |p| { - assert_eq!(p, &*CString::new(path.as_os_str().bytes()).unwrap()); + assert_eq!(p, &*CString::new(path.as_os_str().as_encoded_bytes()).unwrap()); Ok(42) }); assert_eq!(result.unwrap(), 42); diff --git a/sgx_tstd/src/sys/common/thread_local/fast_local.rs b/sgx_tstd/src/sys/common/thread_local/fast_local.rs new file mode 100644 index 000000000..1d655eec6 --- /dev/null +++ b/sgx_tstd/src/sys/common/thread_local/fast_local.rs @@ -0,0 +1,254 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT 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 super::lazy::LazyKeyInner; +use crate::cell::Cell; +use crate::sys::thread_local_dtor::register_dtor; +use crate::thread::AccessError; +use crate::{fmt, mem, panic}; + +#[allow_internal_unstable(thread_local_internals, cfg_target_thread_local, thread_local)] +#[allow_internal_unsafe] +#[rustc_macro_transparency = "semitransparent"] +pub macro thread_local_inner { + // used to generate the `LocalKey` value for const-initialized thread locals + (@key $t:ty, const $init:expr) => {{ + #[inline] + unsafe fn __getit( + _init: $crate::option::Option<&mut $crate::option::Option<$t>>, + ) -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { + const INIT_EXPR: $t = $init; + // If the platform has support for `#[thread_local]`, use it. + #[thread_local] + static mut VAL: $t = INIT_EXPR; + + // If a dtor isn't needed we can do something "very raw" and + // just get going. + if !$crate::mem::needs_drop::<$t>() { + return $crate::result::Result::Ok(&VAL) + } + + // 0 == dtor not registered + // 1 == dtor registered, dtor not run + // 2 == dtor registered and is running or has run + #[thread_local] + static STATE: $crate::cell::Cell<$crate::primitive::u8> = $crate::cell::Cell::new(0); + + // Safety: Performs `drop_in_place(ptr as *mut $t)`, and requires + // all that comes with it. + unsafe extern "C" fn destroy(ptr: *mut $crate::primitive::u8) { + $crate::thread::local_impl::abort_on_dtor_unwind(|| { + let old_state = STATE.replace(2); + $crate::debug_assert_eq!(old_state, 1); + // Safety: safety requirement is passed on to caller. + unsafe { $crate::ptr::drop_in_place(ptr.cast::<$t>()); } + }); + } + + match STATE.get() { + // 0 == we haven't registered a destructor, so do + // so now. + 0 => { + $crate::thread::local_impl::Key::<$t>::register_dtor( + $crate::ptr::addr_of_mut!(VAL) as *mut $crate::primitive::u8, + destroy, + ); + STATE.set(1); + $crate::result::Result::Ok(&VAL) + } + // 1 == the destructor is registered and the value + // is valid, so return the pointer. + 1 => $crate::result::Result::Ok(&VAL), + // otherwise the destructor has already run, so we + // can't give access. + _ => $crate::result::Result::Err($crate::thread::AccessError::new( + "The destructor has already run." + )), + } + } + + unsafe { + $crate::thread::LocalKey::new(__getit) + } + }}, + + // used to generate the `LocalKey` value for `thread_local!` + (@key $t:ty, $init:expr) => { + { + #[inline] + fn __init() -> $t { $init } + + #[inline] + unsafe fn __getit( + init: $crate::option::Option<&mut $crate::option::Option<$t>>, + ) -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { + #[thread_local] + static __KEY: $crate::thread::local_impl::Key<$t> = + $crate::thread::local_impl::Key::<$t>::new(); + + #[allow(unused_unsafe)] + unsafe { + __KEY.get(move || { + if let $crate::option::Option::Some(init) = init { + if let $crate::option::Option::Some(value) = init.take() { + return value; + } else if $crate::cfg!(debug_assertions) { + $crate::unreachable!("missing default value"); + } + } + __init() + }) + } + } + + unsafe { + $crate::thread::LocalKey::new(__getit) + } + } + }, + ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $($init:tt)*) => { + $(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> = + $crate::thread::local_impl::thread_local_inner!(@key $t, $($init)*); + }, +} + +#[derive(Copy, Clone)] +enum DtorState { + Unregistered, + Registered, + RunningOrHasRun, +} + +// This data structure has been carefully constructed so that the fast path +// only contains one branch on x86. That optimization is necessary to avoid +// duplicated tls lookups on OSX. +// +// LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722 +pub struct Key { + // If `LazyKeyInner::get` returns `None`, that indicates either: + // * The value has never been initialized + // * The value is being recursively initialized + // * The value has already been destroyed or is being destroyed + // To determine which kind of `None`, check `dtor_state`. + // + // This is very optimizer friendly for the fast path - initialized but + // not yet dropped. + inner: LazyKeyInner, + + // Metadata to keep track of the state of the destructor. Remember that + // this variable is thread-local, not global. + dtor_state: Cell, +} + +impl fmt::Debug for Key { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Key").finish_non_exhaustive() + } +} +impl Key { + pub const fn new() -> Key { + Key { inner: LazyKeyInner::new(), dtor_state: Cell::new(DtorState::Unregistered) } + } + + // note that this is just a publicly-callable function only for the + // const-initialized form of thread locals, basically a way to call the + // free `register_dtor` function defined elsewhere in std. + pub unsafe fn register_dtor(a: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { + register_dtor(a, dtor); + } + + pub unsafe fn get T>(&self, init: F) -> Result<&'static T, AccessError> { + // SAFETY: See the definitions of `LazyKeyInner::get` and + // `try_initialize` for more information. + // + // The caller must ensure no mutable references are ever active to + // the inner cell or the inner T when this is called. + // The `try_initialize` is dependant on the passed `init` function + // for this. + match self.inner.get() { + Some(val) => Ok(val), + None => self.try_initialize(init), + } + } + + // `try_initialize` is only called once per fast thread local variable, + // except in corner cases where thread_local dtors reference other + // thread_local's, or it is being recursively initialized. + // + // Macos: Inlining this function can cause two `tlv_get_addr` calls to + // be performed for every call to `Key::get`. + // LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722 + #[inline(never)] + unsafe fn try_initialize T>(&self, init: F) -> Result<&'static T, AccessError> { + // SAFETY: See comment above (this function doc). + if !mem::needs_drop::() || self.try_register_dtor() { + // SAFETY: See comment above (this function doc). + Ok(self.inner.initialize(init)) + } else { + Err(AccessError::new("Failed to register destructor.")) + } + } + + // `try_register_dtor` is only called once per fast thread local + // variable, except in corner cases where thread_local dtors reference + // other thread_local's, or it is being recursively initialized. + unsafe fn try_register_dtor(&self) -> bool { + match self.dtor_state.get() { + DtorState::Unregistered => { + // SAFETY: dtor registration happens before initialization. + // Passing `self` as a pointer while using `destroy_value` + // is safe because the function will build a pointer to a + // Key, which is the type of self and so find the correct + // size. + register_dtor(self as *const _ as *mut u8, destroy_value::); + self.dtor_state.set(DtorState::Registered); + true + } + DtorState::Registered => { + // recursively initialized + true + } + DtorState::RunningOrHasRun => false, + } + } +} + +unsafe extern "C" fn destroy_value(ptr: *mut u8) { + let ptr = ptr as *mut Key; + + // SAFETY: + // + // The pointer `ptr` has been built just above and comes from + // `try_register_dtor` where it is originally a Key coming from `self`, + // making it non-NUL and of the correct type. + // + // Right before we run the user destructor be sure to set the + // `Option` to `None`, and `dtor_state` to `RunningOrHasRun`. This + // causes future calls to `get` to run `try_initialize_drop` again, + // which will now fail, and return `None`. + // + // Wrap the call in a catch to ensure unwinding is caught in the event + // a panic takes place in a destructor. + let ret = panic::catch_unwind(panic::AssertUnwindSafe(|| unsafe { + let value = (*ptr).inner.take(); + (*ptr).dtor_state.set(DtorState::RunningOrHasRun); + drop(value); + })); + if ret.is_err() { + rtabort!("thread local panicked on drop"); + } +} diff --git a/sgx_tstd/src/sys/common/thread_local/mod.rs b/sgx_tstd/src/sys/common/thread_local/mod.rs new file mode 100644 index 000000000..930dd6149 --- /dev/null +++ b/sgx_tstd/src/sys/common/thread_local/mod.rs @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +// There are three thread-local implementations: "static", "fast", "OS". +// The "OS" thread local key type is accessed via platform-specific API calls and is slow, while the +// "fast" key type is accessed via code generated via LLVM, where TLS keys are set up by the linker. +// "static" is for single-threaded platforms where a global static is sufficient. + +#[cfg(not(feature = "thread"))] +#[doc(hidden)] +mod static_local; +#[cfg(not(feature = "thread"))] +#[doc(hidden)] +pub use static_local::{Key, thread_local_inner}; + +#[cfg(feature = "thread")] +#[doc(hidden)] +mod fast_local; +#[cfg(feature = "thread")] +#[doc(hidden)] +pub use fast_local::{Key, thread_local_inner}; + +#[cfg(feature = "thread")] +#[doc(hidden)] +mod os_local; +// #[cfg(feature = "thread")] +// #[doc(hidden)] +// pub use os_local::{Key, thread_local_inner}; + +mod lazy { + use crate::cell::UnsafeCell; + use crate::hint; + use crate::mem; + + pub struct LazyKeyInner { + inner: UnsafeCell>, + } + + impl LazyKeyInner { + pub const fn new() -> LazyKeyInner { + LazyKeyInner { inner: UnsafeCell::new(None) } + } + + pub unsafe fn get(&self) -> Option<&'static T> { + // SAFETY: The caller must ensure no reference is ever handed out to + // the inner cell nor mutable reference to the Option inside said + // cell. This make it safe to hand a reference, though the lifetime + // of 'static is itself unsafe, making the get method unsafe. + (*self.inner.get()).as_ref() + } + + /// The caller must ensure that no reference is active: this method + /// needs unique access. + pub unsafe fn initialize T>(&self, init: F) -> &'static T { + // Execute the initialization up front, *then* move it into our slot, + // just in case initialization fails. + let value = init(); + let ptr = self.inner.get(); + + // SAFETY: + // + // note that this can in theory just be `*ptr = Some(value)`, but due to + // the compiler will currently codegen that pattern with something like: + // + // ptr::drop_in_place(ptr) + // ptr::write(ptr, Some(value)) + // + // Due to this pattern it's possible for the destructor of the value in + // `ptr` (e.g., if this is being recursively initialized) to re-access + // TLS, in which case there will be a `&` and `&mut` pointer to the same + // value (an aliasing violation). To avoid setting the "I'm running a + // destructor" flag we just use `mem::replace` which should sequence the + // operations a little differently and make this safe to call. + // + // The precondition also ensures that we are the only one accessing + // `self` at the moment so replacing is fine. + let _ = mem::replace(&mut *ptr, Some(value)); + + // SAFETY: With the call to `mem::replace` it is guaranteed there is + // a `Some` behind `ptr`, not a `None` so `unreachable_unchecked` + // will never be reached. + // After storing `Some` we want to get a reference to the contents of + // what we just stored. While we could use `unwrap` here and it should + // always work it empirically doesn't seem to always get optimized away, + // which means that using something like `try_with` can pull in + // panicking code and cause a large size bloat. + match *ptr { + Some(ref x) => x, + None => hint::unreachable_unchecked(), + } + } + + /// The other methods hand out references while taking &self. + /// As such, callers of this method must ensure no `&` and `&mut` are + /// available and used at the same time. + #[allow(unused)] + pub unsafe fn take(&mut self) -> Option { + // SAFETY: See doc comment for this method. + (*self.inner.get()).take() + } + } +} + +/// Run a callback in a scenario which must not unwind (such as a `extern "C" +/// fn` declared in a user crate). If the callback unwinds anyway, then +/// `rtabort` with a message about thread local panicking on drop. +#[inline] +pub fn abort_on_dtor_unwind(f: impl FnOnce()) { + // Using a guard like this is lower cost. + let guard = DtorUnwindGuard; + f(); + core::mem::forget(guard); + + struct DtorUnwindGuard; + impl Drop for DtorUnwindGuard { + #[inline] + fn drop(&mut self) { + // This is not terribly descriptive, but it doesn't need to be as we'll + // already have printed a panic message at this point. + rtabort!("thread local panicked on drop"); + } + } +} diff --git a/sgx_tstd/src/sys/common/thread_local/os_local.rs b/sgx_tstd/src/sys/common/thread_local/os_local.rs new file mode 100644 index 000000000..4f4daace8 --- /dev/null +++ b/sgx_tstd/src/sys/common/thread_local/os_local.rs @@ -0,0 +1,201 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT 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 super::lazy::LazyKeyInner; +use crate::cell::Cell; +use crate::sys_common::thread_local_key::StaticKey as OsStaticKey; +use crate::thread::AccessError; +use crate::{fmt, marker, panic, ptr}; + +#[allow_internal_unstable(thread_local_internals)] +#[allow_internal_unsafe] +#[rustc_macro_transparency = "semitransparent"] +pub macro thread_local_inner { + // used to generate the `LocalKey` value for const-initialized thread locals + (@key $t:ty, const $init:expr) => {{ + #[inline] + unsafe fn __getit( + _init: $crate::option::Option<&mut $crate::option::Option<$t>>, + ) -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { + const INIT_EXPR: $t = $init; + + // On platforms without `#[thread_local]` we fall back to the + // same implementation as below for os thread locals. + #[inline] + const fn __init() -> $t { INIT_EXPR } + static __KEY: $crate::thread::local_impl::Key<$t> = + $crate::thread::local_impl::Key::new(); + unsafe { + __KEY.get(move || { + if let $crate::option::Option::Some(init) = _init { + if let $crate::option::Option::Some(value) = init.take() { + return value; + } else if $crate::cfg!(debug_assertions) { + $crate::unreachable!("missing initial value"); + } + } + __init() + }) + } + } + + unsafe { + $crate::thread::LocalKey::new(__getit) + } + }}, + + // used to generate the `LocalKey` value for `thread_local!` + (@key $t:ty, $init:expr) => { + { + #[inline] + fn __init() -> $t { $init } + + // `#[inline] does not work on windows-gnu due to linking errors around dllimports. + // See https://github.com/rust-lang/rust/issues/109797. + #[cfg_attr(not(windows), inline)] + unsafe fn __getit( + init: $crate::option::Option<&mut $crate::option::Option<$t>>, + ) -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { + static __KEY: $crate::thread::local_impl::Key<$t> = + $crate::thread::local_impl::Key::new(); + + unsafe { + __KEY.get(move || { + if let $crate::option::Option::Some(init) = init { + if let $crate::option::Option::Some(value) = init.take() { + return value; + } else if $crate::cfg!(debug_assertions) { + $crate::unreachable!("missing default value"); + } + } + __init() + }) + } + } + + unsafe { + $crate::thread::LocalKey::new(__getit) + } + } + }, + ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $($init:tt)*) => { + $(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> = + $crate::thread::local_impl::thread_local_inner!(@key $t, $($init)*); + }, +} + +/// Use a regular global static to store this key; the state provided will then be +/// thread-local. +pub struct Key { + // OS-TLS key that we'll use to key off. + os: OsStaticKey, + marker: marker::PhantomData>, +} + +impl fmt::Debug for Key { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Key").finish_non_exhaustive() + } +} + +unsafe impl Sync for Key {} + +struct Value { + inner: LazyKeyInner, + key: &'static Key, +} + +impl Key { + // Note: + // 1. os::Key can be destructed normally when used for threads created by `pthread_create`. + // 2. os::Key used in untrusted thread, the destructor will not be called. + pub const fn new() -> Key { + Key { os: OsStaticKey::new(Some(destroy_value::)), marker: marker::PhantomData } + } + + /// It is a requirement for the caller to ensure that no mutable + /// reference is active when this method is called. + pub unsafe fn get(&'static self, init: impl FnOnce() -> T) -> Result<&'static T, AccessError> { + // SAFETY: See the documentation for this method. + let ptr = self.os.get() as *mut Value; + if ptr.addr() > 1 { + // SAFETY: the check ensured the pointer is safe (its destructor + // is not running) + it is coming from a trusted source (self). + if let Some(ref value) = (*ptr).inner.get() { + return Ok(value); + } + } + // SAFETY: At this point we are sure we have no value and so + // initializing (or trying to) is safe. + self.try_initialize(init) + } + + // `try_initialize` is only called once per os thread local variable, + // except in corner cases where thread_local dtors reference other + // thread_local's, or it is being recursively initialized. + unsafe fn try_initialize(&'static self, init: impl FnOnce() -> T) -> Result<&'static T, AccessError> { + // SAFETY: No mutable references are ever handed out meaning getting + // the value is ok. + let ptr = self.os.get() as *mut Value; + if ptr.addr() == 1 { + // destructor is running + return Err(AccessError::new("The destructor has already run.")); + } + + let ptr = if ptr.is_null() { + // If the lookup returned null, we haven't initialized our own + // local copy, so do that now. + let ptr = Box::into_raw(Box::new(Value { inner: LazyKeyInner::new(), key: self })); + // SAFETY: At this point we are sure there is no value inside + // ptr so setting it will not affect anyone else. + self.os.set(ptr as *mut u8); + ptr + } else { + // recursive initialization + ptr + }; + + // SAFETY: ptr has been ensured as non-NUL just above an so can be + // dereferenced safely. + Ok((*ptr).inner.initialize(init)) + } +} + +unsafe extern "C" fn destroy_value(ptr: *mut u8) { + // SAFETY: + // + // The OS TLS ensures that this key contains a null value when this + // destructor starts to run. We set it back to a sentinel value of 1 to + // ensure that any future calls to `get` for this thread will return + // `None`. + // + // Note that to prevent an infinite loop we reset it back to null right + // before we return from the destructor ourselves. + // + // Wrap the call in a catch to ensure unwinding is caught in the event + // a panic takes place in a destructor. + let ret = panic::catch_unwind(|| unsafe { + let ptr = Box::from_raw(ptr as *mut Value); + let key = ptr.key; + key.os.set(ptr::invalid_mut(1)); + drop(ptr); + key.os.set(ptr::null_mut()); + }); + if ret.is_err() { + rtabort!("thread local panicked on drop"); + } +} diff --git a/sgx_tstd/src/sys/common/thread_local/static_local.rs b/sgx_tstd/src/sys/common/thread_local/static_local.rs new file mode 100644 index 000000000..e81cb66f4 --- /dev/null +++ b/sgx_tstd/src/sys/common/thread_local/static_local.rs @@ -0,0 +1,126 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT 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 super::lazy::LazyKeyInner; +use crate::fmt; +use crate::mem; +use crate::thread::AccessError; + +use sgx_trts::tcs::{self, TcsPolicy}; + +#[allow_internal_unstable(thread_local_internals, cfg_target_thread_local, thread_local)] +#[allow_internal_unsafe] +#[rustc_macro_transparency = "semitransparent"] +pub macro thread_local_inner { + // used to generate the `LocalKey` value for const-initialized thread locals + (@key $t:ty, const $init:expr) => {{ + #[inline] // see comments below + unsafe fn __getit( + _init: $crate::option::Option<&mut $crate::option::Option<$t>>, + ) -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { + const INIT_EXPR: $t = $init; + + if !$crate::mem::needs_drop::<$t>() || $crate::thread::tcs_policy() == $crate::thread::TcsPolicy::Bind { + #[thread_local] + static mut VAL: $t = INIT_EXPR; + Ok(&VAL) + } else { + $crate::result::Result::Err($crate::thread::AccessError::new( + "If TLS data needs to be destructed, TCS policy must be bound." + )) + } + } + + unsafe { + $crate::thread::LocalKey::new(__getit) + } + }}, + + // used to generate the `LocalKey` value for `thread_local!` + (@key $t:ty, $init:expr) => { + { + #[inline] + fn __init() -> $t { $init } + #[inline] + unsafe fn __getit( + init: $crate::option::Option<&mut $crate::option::Option<$t>>, + ) -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { + #[thread_local] + static __KEY: $crate::thread::local_impl::Key<$t> = + $crate::thread::local_impl::Key::new(); + + #[allow(unused_unsafe)] + unsafe { + __KEY.get(move || { + if let $crate::option::Option::Some(init) = init { + if let $crate::option::Option::Some(value) = init.take() { + return value; + } else if $crate::cfg!(debug_assertions) { + $crate::unreachable!("missing default value"); + } + } + __init() + }) + } + } + + unsafe { + $crate::thread::LocalKey::new(__getit) + } + } + }, + ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $($init:tt)*) => { + $(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> = + $crate::thread::local_impl::thread_local_inner!(@key $t, $($init)*); + }, +} + +pub struct Key { + inner: LazyKeyInner, +} + +unsafe impl Sync for Key {} + +impl fmt::Debug for Key { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Key").finish_non_exhaustive() + } +} + +impl Key { + pub const fn new() -> Key { + Key { inner: LazyKeyInner::new() } + } + + pub unsafe fn get(&self, init: impl FnOnce() -> T) -> Result<&'static T, AccessError> { + if !mem::needs_drop::() || tcs::tcs_policy() == TcsPolicy::Bind { + // SAFETY: The caller must ensure no reference is ever handed out to + // the inner cell nor mutable reference to the Option inside said + // cell. This make it safe to hand a reference, though the lifetime + // of 'static is itself unsafe, making the get method unsafe. + let value = match self.inner.get() { + Some(value) => value, + None => self.inner.initialize(init), + }; + Ok(value) + } else { + Err(AccessError::new( + "If TLS data needs to be destructed, TCS policy must be bound." + )) + } + } +} diff --git a/sgx_tstd/src/sys/fd.rs b/sgx_tstd/src/sys/fd.rs index 570ee4fbb..c140f2fcc 100644 --- a/sgx_tstd/src/sys/fd.rs +++ b/sgx_tstd/src/sys/fd.rs @@ -58,7 +58,7 @@ impl FileDesc { } pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { - cvt_ocall(unsafe { libc::pread64(self.as_raw_fd(), buf, offset as i64) }) + cvt_ocall(unsafe { libc::pread64(self.as_raw_fd(), buf, offset as _) }) } pub fn read_buf(&self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> { @@ -73,6 +73,13 @@ impl FileDesc { Ok(()) } + pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result { + let len = cmp::min(bufs.len(), max_iov()); + let vbufs: Vec<&mut [u8]> = bufs[..len].iter_mut().map(|msl| &mut **msl).collect(); + let ret = cvt_ocall(unsafe { libc::preadv64(self.as_raw_fd(), vbufs, offset as _) })?; + Ok(ret) + } + pub fn write(&self, buf: &[u8]) -> io::Result { let ret = cvt_ocall(unsafe { libc::write(self.as_raw_fd(), buf) })?; Ok(ret) @@ -96,6 +103,15 @@ impl FileDesc { cvt_ocall(unsafe { libc::pwrite64(self.as_raw_fd(), buf, offset as i64) }) } + pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result { + let vbufs: Vec<&[u8]> = bufs[..cmp::min(bufs.len(), max_iov())] + .iter() + .map(|msl| &**msl) + .collect(); + let ret = cvt_ocall(unsafe { libc::pwritev64(self.as_raw_fd(), vbufs, offset as _) })?; + Ok(ret) + } + pub fn get_cloexec(&self) -> io::Result { unsafe { Ok((cvt_ocall(libc::fcntl_arg0(self.as_raw_fd(), libc::F_GETFD))? & libc::FD_CLOEXEC) != 0) } } @@ -133,9 +149,23 @@ impl<'a> Read for &'a FileDesc { fn read(&mut self, buf: &mut [u8]) -> io::Result { (**self).read(buf) } + + fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { + (**self).read_buf(cursor) + } + + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) + } + + #[inline] + fn is_read_vectored(&self) -> bool { + (**self).is_read_vectored() + } } impl AsInner for FileDesc { + #[inline] fn as_inner(&self) -> &OwnedFd { &self.0 } @@ -160,6 +190,7 @@ impl AsFd for FileDesc { } impl AsRawFd for FileDesc { + #[inline] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } @@ -179,8 +210,7 @@ impl FromRawFd for FileDesc { mod libc { pub use sgx_oc::ocall::{ - close, fcntl_arg0, fcntl_arg1, ioctl_arg0, ioctl_arg1, pread64, pwrite64, read, readv, - write, writev, + fcntl_arg0, fcntl_arg1, ioctl_arg1, pread64, preadv64, pwrite64, pwritev64, read, readv, write, writev, }; pub use sgx_oc::*; } diff --git a/sgx_tstd/src/sys/fs.rs b/sgx_tstd/src/sys/fs.rs index e50f86895..58f236907 100644 --- a/sgx_tstd/src/sys/fs.rs +++ b/sgx_tstd/src/sys/fs.rs @@ -55,6 +55,12 @@ pub struct ReadDir { end_of_stream: bool, } +impl ReadDir { + fn new(inner: InnerReadDir) -> Self { + Self { inner: Arc::new(inner), end_of_stream: false } + } +} + struct Dir(DirPtr); unsafe impl Send for Dir {} @@ -90,11 +96,23 @@ pub struct FileTimes { modified: Option, } -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, Eq, Debug)] pub struct FileType { mode: mode_t, } +impl PartialEq for FileType { + fn eq(&self, other: &Self) -> bool { + self.masked() == other.masked() + } +} + +impl core::hash::Hash for FileType { + fn hash(&self, state: &mut H) { + self.masked().hash(state); + } +} + #[derive(Debug)] pub struct DirBuilder { mode: mode_t, @@ -138,6 +156,7 @@ impl FileAttr { } impl AsInner for FileAttr { + #[inline] fn as_inner(&self) -> &stat64 { &self.stat } @@ -185,7 +204,11 @@ impl FileType { } pub fn is(&self, mode: mode_t) -> bool { - self.mode & libc::S_IFMT == mode + self.masked() == mode + } + + fn masked(&self) -> mode_t { + self.mode & libc::S_IFMT } } @@ -240,7 +263,7 @@ impl Drop for Dir { fn drop(&mut self) { let r = unsafe { libc::closedir(self.0) }; assert!( - r.is_ok() || crate::io::Error::last_os_error().kind() == crate::io::ErrorKind::Interrupted, + r.is_ok() || crate::io::Error::last_os_error().is_interrupted(), "unexpected error during closedir: {:?}", crate::io::Error::last_os_error() ); @@ -436,6 +459,10 @@ impl File { self.0.read_buf(cursor) } + pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result { + self.0.read_vectored_at(bufs, offset) + } + pub fn write(&self, buf: &[u8]) -> io::Result { self.0.write(buf) } @@ -453,6 +480,11 @@ impl File { self.0.write_at(buf, offset) } + pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result { + self.0.write_vectored_at(bufs, offset) + } + + #[inline] pub fn flush(&self) -> io::Result<()> { Ok(()) } @@ -479,13 +511,17 @@ impl File { } pub fn set_times(&self, times: FileTimes) -> io::Result<()> { - let to_timespec = |time: Option| { - match time { - Some(time) if let Some(ts) = time.t.to_timespec() => Ok(ts), - Some(time) if time > crate::sys::time::UNIX_EPOCH => Err(io::const_io_error!(io::ErrorKind::InvalidInput, "timestamp is too large to set as a file time")), - Some(_) => Err(io::const_io_error!(io::ErrorKind::InvalidInput, "timestamp is too small to set as a file time")), - None => Ok(libc::timespec { tv_sec: 0, tv_nsec: libc::UTIME_OMIT as _ }), - } + let to_timespec = |time: Option| match time { + Some(time) if let Some(ts) = time.t.to_timespec() => Ok(ts), + Some(time) if time > crate::sys::time::UNIX_EPOCH => Err(io::const_io_error!( + io::ErrorKind::InvalidInput, + "timestamp is too large to set as a file time" + )), + Some(_) => Err(io::const_io_error!( + io::ErrorKind::InvalidInput, + "timestamp is too small to set as a file time" + )), + None => Ok(libc::timespec { tv_sec: 0, tv_nsec: libc::UTIME_OMIT as _ }), }; let times = [to_timespec(times.accessed)?, to_timespec(times.modified)?]; cvt_ocall(unsafe { libc::futimens(self.as_raw_fd(), ×) })?; @@ -508,12 +544,14 @@ impl DirBuilder { } impl AsInner for File { + #[inline] fn as_inner(&self) -> &FileDesc { &self.0 } } impl AsInnerMut for File { + #[inline] fn as_inner_mut(&mut self) -> &mut FileDesc { &mut self.0 } @@ -532,12 +570,14 @@ impl FromInner for File { } impl AsFd for File { + #[inline] fn as_fd(&self) -> BorrowedFd<'_> { self.0.as_fd() } } impl AsRawFd for File { + #[inline] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } diff --git a/sgx_tstd/src/sys/kernel_copy.rs b/sgx_tstd/src/sys/kernel_copy.rs index 8799ee2f9..0bb76d627 100644 --- a/sgx_tstd/src/sys/kernel_copy.rs +++ b/sgx_tstd/src/sys/kernel_copy.rs @@ -34,11 +34,9 @@ //! Once it has obtained all necessary pieces and brought any wrapper types into a state where they //! can be safely bypassed it will attempt to use the `copy_file_range(2)`, //! `sendfile(2)` or `splice(2)` syscalls to move data directly between file descriptors. -//! Since those syscalls have requirements that cannot be fully checked in advance and -//! gathering additional information about file descriptors would require additional syscalls -//! anyway it simply attempts to use them one after another (guided by inaccurate hints) to -//! figure out which one works and falls back to the generic read-write copy loop if none of them -//! does. +//! Since those syscalls have requirements that cannot be fully checked in advance it attempts +//! to use them one after another (guided by hints) to figure out which one works and +//! falls back to the generic read-write copy loop if none of them does. //! Once a working syscall is found for a pair of file descriptors it will be called in a loop //! until the copy operation is completed. //! @@ -96,17 +94,19 @@ pub(crate) fn copy_spec( /// The methods on this type only provide hints, due to `AsRawFd` and `FromRawFd` the inferred /// type may be wrong. enum FdMeta { - /// We obtained the FD from a type that can contain any type of `FileType` and queried the metadata - /// because it is cheaper than probing all possible syscalls (reader side) Metadata(Metadata), Socket, Pipe, - /// We don't have any metadata, e.g. because the original type was `File` which can represent - /// any `FileType` and we did not query the metadata either since it did not seem beneficial - /// (writer side) + /// We don't have any metadata because the stat syscall failed NoneObtained, } +#[derive(PartialEq)] +enum FdHandle { + Input, + Output, +} + impl FdMeta { fn maybe_fifo(&self) -> bool { match self { @@ -132,17 +132,52 @@ impl FdMeta { } } - fn copy_file_range_candidate(&self) -> bool { + fn copy_file_range_candidate(&self, f: FdHandle) -> bool { match self { // copy_file_range will fail on empty procfs files. `read` can determine whether EOF has been reached // without extra cost and skip the write, thus there is no benefit in attempting copy_file_range - FdMeta::Metadata(meta) if meta.is_file() && meta.len() > 0 => true, - FdMeta::NoneObtained => true, + FdMeta::Metadata(meta) if f == FdHandle::Input && meta.is_file() && meta.len() > 0 => { + true + } + FdMeta::Metadata(meta) if f == FdHandle::Output && meta.is_file() => true, _ => false, } } } +/// Returns true either if changes made to the source after a sendfile/splice call won't become +/// visible in the sink or the source has explicitly opted into such behavior (e.g. by splicing +/// a file into a pipe, the pipe being the source in this case). +/// +/// This will prevent File -> Pipe and File -> Socket splicing/sendfile optimizations to uphold +/// the Read/Write API semantics of io::copy. +/// +/// Note: This is not 100% airtight, the caller can use the RawFd conversion methods to turn a +/// regular file into a TcpSocket which will be treated as a socket here without checking. +fn safe_kernel_copy(source: &FdMeta, sink: &FdMeta) -> bool { + match (source, sink) { + // Data arriving from a socket is safe because the sender can't modify the socket buffer. + // Data arriving from a pipe is safe(-ish) because either the sender *copied* + // the bytes into the pipe OR explicitly performed an operation that enables zero-copy, + // thus promising not to modify the data later. + (FdMeta::Socket, _) => true, + (FdMeta::Pipe, _) => true, + (FdMeta::Metadata(meta), _) + if meta.file_type().is_fifo() || meta.file_type().is_socket() => + { + true + } + // Data going into non-pipes/non-sockets is safe because the "later changes may become visible" issue + // only happens for pages sitting in send buffers or pipes. + (_, FdMeta::Metadata(meta)) + if !meta.file_type().is_fifo() && !meta.file_type().is_socket() => + { + true + } + _ => false, + } +} + struct CopyParams(FdMeta, Option); struct Copier<'a, 'b, R: Read + ?Sized, W: Write + ?Sized> { @@ -182,7 +217,9 @@ impl SpecCopy for Copier<'_, '_, R, W> { written += flush()?; let max_write = reader.min_limit(); - if input_meta.copy_file_range_candidate() && output_meta.copy_file_range_candidate() { + if input_meta.copy_file_range_candidate(FdHandle::Input) + && output_meta.copy_file_range_candidate(FdHandle::Output) + { let result = copy_regular_files(readfd, writefd, max_write); result.update_take(reader); @@ -198,7 +235,8 @@ impl SpecCopy for Copier<'_, '_, R, W> { // So we just try and fallback if needed. // If current file offsets + write sizes overflow it may also fail, we do not try to fix that and instead // fall back to the generic copy loop. - if input_meta.potential_sendfile_source() { + if input_meta.potential_sendfile_source() && safe_kernel_copy(&input_meta, &output_meta) + { let result = sendfile_splice(SpliceMode::Sendfile, readfd, writefd, max_write); result.update_take(reader); @@ -209,7 +247,9 @@ impl SpecCopy for Copier<'_, '_, R, W> { } } - if input_meta.maybe_fifo() || output_meta.maybe_fifo() { + if (input_meta.maybe_fifo() || output_meta.maybe_fifo()) + && safe_kernel_copy(&input_meta, &output_meta) + { let result = sendfile_splice(SpliceMode::Splice, readfd, writefd, max_write); result.update_take(reader); @@ -310,13 +350,13 @@ impl CopyRead for &File { impl CopyWrite for File { fn properties(&self) -> CopyParams { - CopyParams(FdMeta::NoneObtained, Some(self.as_raw_fd())) + CopyParams(fd_to_meta(self), Some(self.as_raw_fd())) } } impl CopyWrite for &File { fn properties(&self) -> CopyParams { - CopyParams(FdMeta::NoneObtained, Some(self.as_raw_fd())) + CopyParams(fd_to_meta(*self), Some(self.as_raw_fd())) } } @@ -405,14 +445,14 @@ impl CopyRead for StdinLock<'_> { #[cfg(feature = "stdio")] impl CopyWrite for StdoutLock<'_> { fn properties(&self) -> CopyParams { - CopyParams(FdMeta::NoneObtained, Some(self.as_raw_fd())) + CopyParams(fd_to_meta(self), Some(self.as_raw_fd())) } } #[cfg(feature = "stdio")] impl CopyWrite for StderrLock<'_> { fn properties(&self) -> CopyParams { - CopyParams(FdMeta::NoneObtained, Some(self.as_raw_fd())) + CopyParams(fd_to_meta(self), Some(self.as_raw_fd())) } } @@ -441,7 +481,7 @@ impl CopyRead for Take { } } -impl CopyRead for BufReader { +impl CopyRead for BufReader { fn drain_to(&mut self, writer: &mut W, outer_limit: u64) -> Result { let buf = self.buffer(); let buf = &buf[0..min(buf.len(), outer_limit.try_into().unwrap_or(usize::MAX))]; @@ -470,7 +510,7 @@ impl CopyRead for BufReader { } } -impl CopyWrite for BufWriter { +impl CopyWrite for BufWriter { fn properties(&self) -> CopyParams { self.get_ref().properties() } @@ -581,7 +621,7 @@ pub(super) fn copy_regular_files(reader: RawFd, writer: RawFd, max_len: u64) -> // - copy_file_range file is immutable or syscall is blocked by seccomp¹ (EPERM) // - copy_file_range cannot be used with pipes or device nodes (EINVAL) // - the writer fd was opened with O_APPEND (EBADF²) - // and no bytes were written successfully yet. (All these errnos should + // and no bytes were written successfully yet. (All these errnos should // not be returned if something was already written, but they happen in // the wild, see #91152.) // diff --git a/sgx_tstd/src/sys/kernel_copy/tests.rs b/sgx_tstd/src/sys/kernel_copy/tests.rs index 2268b244e..2707c4fd6 100644 --- a/sgx_tstd/src/sys/kernel_copy/tests.rs +++ b/sgx_tstd/src/sys/kernel_copy/tests.rs @@ -90,18 +90,18 @@ fn copies_append_mode_sink() { let source_path = tmp_path.join("copies_append_mode.source"); let sink_path = tmp_path.join("copies_append_mode.sink"); let mut source = - OpenOptions::new().create(true).truncate(true).write(true).read(true).open(&source_path).unwrap(); + OpenOptions::new().create(true).truncate(true).write(true).read(true).open(source_path).unwrap(); write!(source, "not empty").unwrap(); source.seek(SeekFrom::Start(0)).unwrap(); - let mut sink = OpenOptions::new().create(true).append(true).open(&sink_path).unwrap(); + let mut sink = OpenOptions::new().create(true).append(true).open(sink_path).unwrap(); let copied = crate::io::copy(&mut source, &mut sink).unwrap(); assert_eq!(copied, 9); } -#[bench_case] -fn bench_file_to_file_copy(b: &mut Bencher) { +#[bench] +fn bench_file_to_file_copy(b: &mut test::Bencher) { const BYTES: usize = 128 * 1024; let temp_path = tmpdir(); let src_path = temp_path.join("file-copy-bench-src"); diff --git a/sgx_tstd/src/sys/mod.rs b/sgx_tstd/src/sys/mod.rs index db0c2b781..b9bf53941 100644 --- a/sgx_tstd/src/sys/mod.rs +++ b/sgx_tstd/src/sys/mod.rs @@ -58,6 +58,8 @@ pub mod thread_local_key; pub mod time; pub mod unsupported; +mod personality; + // SAFETY: must be called only once during runtime initialization. // NOTE: this is not guaranteed to run, for example when Rust code is called externally. pub unsafe fn init(env: Vec, args: Vec) { @@ -69,6 +71,11 @@ pub unsafe fn init(env: Vec, args: Vec) { // NOTE: this is not guaranteed to run, for example when the program aborts. pub unsafe fn cleanup() {} +#[inline] +pub(crate) fn is_interrupted(errno: i32) -> bool { + errno == libc::EINTR +} + pub fn decode_error_kind(errno: i32) -> ErrorKind { use ErrorKind::*; match errno as libc::c_int { @@ -118,6 +125,8 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { } } +pub type RawOsError = i32; + #[doc(hidden)] pub trait IsMinusOne { fn is_minus_one(&self) -> bool; @@ -164,7 +173,7 @@ where { loop { match cvt_ocall(f()) { - Err(ref e) if e.kind() == ErrorKind::Interrupted => {} + Err(ref e) if e.is_interrupted() => {} other => return other, } } diff --git a/sgx_tstd/src/sys/net.rs b/sgx_tstd/src/sys/net.rs index e621be921..18fa2bc67 100644 --- a/sgx_tstd/src/sys/net.rs +++ b/sgx_tstd/src/sys/net.rs @@ -16,13 +16,13 @@ // under the License.. use crate::cmp; -use crate::convert::TryInto; -use crate::io::{self, IoSlice, IoSliceMut}; +use crate::io::{self, BorrowedBuf, BorrowedCursor, IoSlice, IoSliceMut}; +use crate::mem::MaybeUninit; use crate::net::{Shutdown, SocketAddr}; use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; use crate::sys::fd::FileDesc; use crate::sys_common::net::{getsockopt, setsockopt}; -use crate::sys_common::{AsInner, FromInner, IntoInner}; +use crate::sys_common::{AsInner, FromInner, IntoInner, TryIntoInner}; use crate::time::{Duration, Instant}; #[cfg(not(feature = "untrusted_time"))] use crate::untrusted::time::InstantEx; @@ -83,10 +83,26 @@ impl Socket { } } + pub fn connect(&self, addr: &SocketAddr) -> io::Result<()> { + let addr: SockAddr = addr.to_owned().into_inner(); + loop { + let result = unsafe { cvt_ocall(libc::connect(self.as_raw_fd(), &addr)) }; + if result.is_err() { + let err = crate::sys::os::errno(); + match err { + libc::EINTR => continue, + libc::EISCONN => return Ok(()), + _ => return Err(io::Error::from_raw_os_error(err)), + } + } + return Ok(()); + } + } + pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> { self.set_nonblocking(true)?; let r = unsafe { - let addr = addr.to_owned().into(); + let addr = addr.to_owned().into_inner(); cvt_ocall(libc::connect(self.as_raw_fd(), &addr)) }; self.set_nonblocking(false)?; @@ -144,7 +160,7 @@ impl Socket { return Ok(()); } } - Err(ref e) if e.raw_os_error() == Some(libc::EINTR) => {} + Err(ref e) if e.is_interrupted() => {} Err(e) => return Err(e), } } @@ -171,17 +187,34 @@ impl Socket { self.0.duplicate().map(Socket) } - fn recv_with_flags(&self, buf: &mut [u8], flags: c_int) -> io::Result { - let ret = cvt_ocall(unsafe { libc::recv(self.as_raw_fd(), buf, flags) })?; - Ok(ret) + fn recv_with_flags(&self, mut buf: BorrowedCursor<'_>, flags: c_int) -> io::Result<()> { + let ret = cvt_ocall(unsafe { + libc::recv( + self.as_raw_fd(), + MaybeUninit::slice_assume_init_mut(buf.as_mut()), + flags, + ) + })?; + unsafe { + buf.advance(ret as usize); + } + Ok(()) } pub fn read(&self, buf: &mut [u8]) -> io::Result { - self.recv_with_flags(buf, 0) + let mut buf = BorrowedBuf::from(buf); + self.recv_with_flags(buf.unfilled(), 0)?; + Ok(buf.len()) } pub fn peek(&self, buf: &mut [u8]) -> io::Result { - self.recv_with_flags(buf, MSG_PEEK) + let mut buf = BorrowedBuf::from(buf); + self.recv_with_flags(buf.unfilled(), MSG_PEEK)?; + Ok(buf.len()) + } + + pub fn read_buf(&self, buf: BorrowedCursor<'_>) -> io::Result<()> { + self.recv_with_flags(buf, 0) } pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { @@ -199,7 +232,7 @@ impl Socket { flags: c_int, ) -> io::Result<(usize, SocketAddr)> { let (n, addr) = cvt_ocall(unsafe { libc::recvfrom(self.as_raw_fd(), buf, flags) })?; - Ok((n, addr.try_into()?)) + Ok((n, addr.try_into_inner()?)) } pub fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { @@ -208,7 +241,7 @@ impl Socket { pub fn recv_msg(&self, msg: &mut libc::MsgHdrMut) -> io::Result { let n = cvt_ocall(unsafe { libc::recvmsg(self.as_raw_fd(), msg, libc::MSG_CMSG_CLOEXEC) })?; - Ok(n) + Ok(n as usize) } pub fn peek_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { @@ -230,7 +263,7 @@ impl Socket { pub fn send_msg(&self, msg: &libc::MsgHdr) -> io::Result { let n = cvt_ocall(unsafe { libc::sendmsg(self.as_raw_fd(), msg, 0) })?; - Ok(n) + Ok(n as usize) } pub fn set_timeout(&self, dur: Option, kind: c_int) -> io::Result<()> { @@ -347,6 +380,7 @@ impl Socket { } impl AsInner for Socket { + #[inline] fn as_inner(&self) -> &FileDesc { &self.0 } @@ -371,6 +405,7 @@ impl AsFd for Socket { } impl AsRawFd for Socket { + #[inline] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } diff --git a/sgx_tstd/src/sys/os.rs b/sgx_tstd/src/sys/os.rs index 424ee0856..ee8d247f7 100644 --- a/sgx_tstd/src/sys/os.rs +++ b/sgx_tstd/src/sys/os.rs @@ -168,6 +168,34 @@ pub struct Env { iter: vec::IntoIter<(OsString, OsString)>, } +// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when ::fmt matches ::fmt. +pub struct EnvStrDebug<'a> { + slice: &'a [(OsString, OsString)], +} + +impl fmt::Debug for EnvStrDebug<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let Self { slice } = self; + f.debug_list() + .entries(slice.iter().map(|(a, b)| (a.to_str().unwrap(), b.to_str().unwrap()))) + .finish() + } +} + +impl Env { + pub fn str_debug(&self) -> impl fmt::Debug + '_ { + let Self { iter } = self; + EnvStrDebug { slice: iter.as_slice() } + } +} + +impl fmt::Debug for Env { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let Self { iter } = self; + f.debug_list().entries(iter.as_slice()).finish() + } +} + impl !Send for Env {} impl !Sync for Env {} @@ -265,5 +293,4 @@ mod libc { #[cfg(feature = "unsupported_process")] pub use sgx_oc::ocall::getpid; pub use sgx_oc::ocall::{env, getenv, setenv, unsetenv, getcwd}; - pub use sgx_oc::*; } diff --git a/sgx_tstd/src/sys/os_str.rs b/sgx_tstd/src/sys/os_str.rs index 3c59183c9..58322a8d7 100644 --- a/sgx_tstd/src/sys/os_str.rs +++ b/sgx_tstd/src/sys/os_str.rs @@ -105,12 +105,23 @@ impl IntoInner> for Buf { } impl AsInner<[u8]> for Buf { + #[inline] fn as_inner(&self) -> &[u8] { &self.inner } } impl Buf { + #[inline] + pub fn into_encoded_bytes(self) -> Vec { + self.inner + } + + #[inline] + pub unsafe fn from_encoded_bytes_unchecked(s: Vec) -> Self { + Self { inner: s } + } + pub fn from_string(s: String) -> Buf { Buf { inner: s.into_bytes() } } @@ -208,17 +219,22 @@ impl Buf { impl Slice { #[inline] - fn from_u8_slice(s: &[u8]) -> &Slice { + pub fn as_encoded_bytes(&self) -> &[u8] { + &self.inner + } + + #[inline] + pub unsafe fn from_encoded_bytes_unchecked(s: &[u8]) -> &Slice { unsafe { mem::transmute(s) } } #[inline] pub fn from_str(s: &str) -> &Slice { - Slice::from_u8_slice(s.as_bytes()) + unsafe { Slice::from_encoded_bytes_unchecked(s.as_bytes()) } } - pub fn to_str(&self) -> Option<&str> { - str::from_utf8(&self.inner).ok() + pub fn to_str(&self) -> Result<&str, crate::str::Utf8Error> { + str::from_utf8(&self.inner) } pub fn to_string_lossy(&self) -> Cow<'_, str> { diff --git a/sgx_tstd/src/sys/os_str/tests.rs b/sgx_tstd/src/sys/os_str/tests.rs index 00df7731c..4daa30314 100644 --- a/sgx_tstd/src/sys/os_str/tests.rs +++ b/sgx_tstd/src/sys/os_str/tests.rs @@ -21,7 +21,7 @@ use sgx_test_utils::test_case; #[test_case] fn slice_debug_output() { - let input = Slice::from_u8_slice(b"\xF0hello,\tworld"); + let input = unsafe { Slice::from_encoded_bytes_unchecked(b"\xF0hello,\tworld") }; let expected = r#""\xF0hello,\tworld""#; let output = format!("{input:?}"); @@ -30,8 +30,7 @@ fn slice_debug_output() { #[test_case] fn display() { - assert_eq!( - "Hello\u{FFFD}\u{FFFD} There\u{FFFD} Goodbye", - Slice::from_u8_slice(b"Hello\xC0\x80 There\xE6\x83 Goodbye").to_string(), - ); + assert_eq!("Hello\u{FFFD}\u{FFFD} There\u{FFFD} Goodbye", unsafe { + Slice::from_encoded_bytes_unchecked(b"Hello\xC0\x80 There\xE6\x83 Goodbye").to_string() + },); } diff --git a/sgx_tstd/src/sys/path.rs b/sgx_tstd/src/sys/path.rs index fb9790054..ccc852ceb 100644 --- a/sgx_tstd/src/sys/path.rs +++ b/sgx_tstd/src/sys/path.rs @@ -47,7 +47,7 @@ pub(crate) fn absolute(path: &Path) -> io::Result { // Get the components, skipping the redundant leading "." component if it exists. let mut components = path.strip_prefix(".").unwrap_or(path).components(); - let path_os = path.as_os_str().bytes(); + let path_os = path.as_os_str().as_encoded_bytes(); let mut normalized = if path.is_absolute() { // "If a pathname begins with two successive characters, the diff --git a/sgx_tstd/src/personality/dwarf/eh.rs b/sgx_tstd/src/sys/personality/dwarf/eh.rs similarity index 54% rename from sgx_tstd/src/personality/dwarf/eh.rs rename to sgx_tstd/src/sys/personality/dwarf/eh.rs index 9d1cc1dfb..9886c72d6 100644 --- a/sgx_tstd/src/personality/dwarf/eh.rs +++ b/sgx_tstd/src/sys/personality/dwarf/eh.rs @@ -18,6 +18,7 @@ //! Parsing of GCC-style Language-Specific Data Area (LSDA) //! For details see: //! * +//! * //! * //! * //! * @@ -30,6 +31,7 @@ use super::DwarfReader; use core::mem; +use core::ptr; pub const DW_EH_PE_omit: u8 = 0xFF; pub const DW_EH_PE_absptr: u8 = 0x00; @@ -53,16 +55,19 @@ pub const DW_EH_PE_indirect: u8 = 0x80; #[derive(Copy, Clone)] pub struct EHContext<'a> { - pub ip: usize, // Current instruction pointer - pub func_start: usize, // Address of the current function - pub get_text_start: &'a dyn Fn() -> usize, // Get address of the code section - pub get_data_start: &'a dyn Fn() -> usize, // Get address of the data section + pub ip: *const u8, // Current instruction pointer + pub func_start: *const u8, // Pointer to the current function + pub get_text_start: &'a dyn Fn() -> *const u8, // Get pointer to the code section + pub get_data_start: &'a dyn Fn() -> *const u8, // Get pointer to the data section } +/// Landing pad. +type LPad = *const u8; pub enum EHAction { None, - Cleanup(usize), - Catch(usize), + Cleanup(LPad), + Catch(LPad), + Filter(LPad), Terminate, } @@ -96,22 +101,24 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>) -> Result let ip = context.ip; if !USING_SJLJ_EXCEPTIONS { + // read the callsite table while reader.ptr < action_table { - let cs_start = read_encoded_pointer(&mut reader, context, call_site_encoding)?; - let cs_len = read_encoded_pointer(&mut reader, context, call_site_encoding)?; - let cs_lpad = read_encoded_pointer(&mut reader, context, call_site_encoding)?; - let cs_action = reader.read_uleb128(); + // these are offsets rather than pointers; + let cs_start = read_encoded_offset(&mut reader, call_site_encoding)?; + let cs_len = read_encoded_offset(&mut reader, call_site_encoding)?; + let cs_lpad = read_encoded_offset(&mut reader, call_site_encoding)?; + let cs_action_entry = reader.read_uleb128(); // Callsite table is sorted by cs_start, so if we've passed the ip, we // may stop searching. - if ip < func_start + cs_start { + if ip < func_start.wrapping_add(cs_start) { break; } - if ip < func_start + cs_start + cs_len { + if ip < func_start.wrapping_add(cs_start + cs_len) { if cs_lpad == 0 { return Ok(EHAction::None); } else { - let lpad = lpad_base + cs_lpad; - return Ok(interpret_cs_action(cs_action, lpad)); + let lpad = lpad_base.wrapping_add(cs_lpad); + return Ok(interpret_cs_action(action_table, cs_action_entry, lpad)); } } } @@ -121,34 +128,50 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>) -> Result // SjLj version: // The "IP" is an index into the call-site table, with two exceptions: // -1 means 'no-action', and 0 means 'terminate'. - match ip as isize { + match ip.addr() as isize { -1 => return Ok(EHAction::None), 0 => return Ok(EHAction::Terminate), _ => (), } - let mut idx = ip; + let mut idx = ip.addr(); loop { let cs_lpad = reader.read_uleb128(); - let cs_action = reader.read_uleb128(); + let cs_action_entry = reader.read_uleb128(); idx -= 1; if idx == 0 { // Can never have null landing pad for sjlj -- that would have // been indicated by a -1 call site index. - let lpad = (cs_lpad + 1) as usize; - return Ok(interpret_cs_action(cs_action, lpad)); + // FIXME(strict provenance) + let lpad = ptr::from_exposed_addr((cs_lpad + 1) as usize); + return Ok(interpret_cs_action(action_table, cs_action_entry, lpad)); } } } } -fn interpret_cs_action(cs_action: u64, lpad: usize) -> EHAction { - if cs_action == 0 { - // If cs_action is 0 then this is a cleanup (Drop::drop). We run these +unsafe fn interpret_cs_action( + action_table: *const u8, + cs_action_entry: u64, + lpad: LPad, +) -> EHAction { + if cs_action_entry == 0 { + // If cs_action_entry is 0 then this is a cleanup (Drop::drop). We run these // for both Rust panics and foreign exceptions. EHAction::Cleanup(lpad) } else { - // Stop unwinding Rust panics at catch_unwind. - EHAction::Catch(lpad) + // If lpad != 0 and cs_action_entry != 0, we have to check ttype_index. + // If ttype_index == 0 under the condition, we take cleanup action. + let action_record = action_table.offset(cs_action_entry as isize - 1); + let mut action_reader = DwarfReader::new(action_record); + let ttype_index = action_reader.read_sleb128(); + if ttype_index == 0 { + EHAction::Cleanup(lpad) + } else if ttype_index > 0 { + // Stop unwinding Rust panics at catch_unwind. + EHAction::Catch(lpad) + } else { + EHAction::Filter(lpad) + } } } @@ -157,22 +180,24 @@ fn round_up(unrounded: usize, align: usize) -> Result { if align.is_power_of_two() { Ok((unrounded + align - 1) & !(align - 1)) } else { Err(()) } } -unsafe fn read_encoded_pointer( - reader: &mut DwarfReader, - context: &EHContext<'_>, - encoding: u8, -) -> Result { - if encoding == DW_EH_PE_omit { +/// Read a offset (`usize`) from `reader` whose encoding is described by `encoding`. +/// +/// `encoding` must be a [DWARF Exception Header Encoding as described by the LSB spec][LSB-dwarf-ext]. +/// In addition the upper ("application") part must be zero. +/// +/// # Errors +/// Returns `Err` if `encoding` +/// * is not a valid DWARF Exception Header Encoding, +/// * is `DW_EH_PE_omit`, or +/// * has a non-zero application part. +/// +/// [LSB-dwarf-ext]: https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/dwarfext.html +unsafe fn read_encoded_offset(reader: &mut DwarfReader, encoding: u8) -> Result { + if encoding == DW_EH_PE_omit || encoding & 0xF0 != 0 { return Err(()); } - - // DW_EH_PE_aligned implies it's an absolute pointer value - if encoding == DW_EH_PE_aligned { - reader.ptr = round_up(reader.ptr as usize, mem::size_of::())? as *const u8; - return Ok(reader.read::()); - } - - let mut result = match encoding & 0x0F { + let result = match encoding & 0x0F { + // despite the name, LLVM also uses absptr for offsets instead of pointers DW_EH_PE_absptr => reader.read::(), DW_EH_PE_uleb128 => reader.read_uleb128() as usize, DW_EH_PE_udata2 => reader.read::() as usize, @@ -184,25 +209,66 @@ unsafe fn read_encoded_pointer( DW_EH_PE_sdata8 => reader.read::() as usize, _ => return Err(()), }; + Ok(result) +} - result += match encoding & 0x70 { - DW_EH_PE_absptr => 0, +/// Read a pointer from `reader` whose encoding is described by `encoding`. +/// +/// `encoding` must be a [DWARF Exception Header Encoding as described by the LSB spec][LSB-dwarf-ext]. +/// +/// # Errors +/// Returns `Err` if `encoding` +/// * is not a valid DWARF Exception Header Encoding, +/// * is `DW_EH_PE_omit`, or +/// * combines `DW_EH_PE_absptr` or `DW_EH_PE_aligned` application part with an integer encoding +/// (not `DW_EH_PE_absptr`) in the value format part. +/// +/// [LSB-dwarf-ext]: https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/dwarfext.html +unsafe fn read_encoded_pointer( + reader: &mut DwarfReader, + context: &EHContext<'_>, + encoding: u8, +) -> Result<*const u8, ()> { + if encoding == DW_EH_PE_omit { + return Err(()); + } + + let base_ptr = match encoding & 0x70 { + DW_EH_PE_absptr => core::ptr::null(), // relative to address of the encoded value, despite the name - DW_EH_PE_pcrel => reader.ptr as usize, + DW_EH_PE_pcrel => reader.ptr, DW_EH_PE_funcrel => { - if context.func_start == 0 { + if context.func_start.is_null() { return Err(()); } context.func_start } DW_EH_PE_textrel => (*context.get_text_start)(), DW_EH_PE_datarel => (*context.get_data_start)(), + // aligned means the value is aligned to the size of a pointer + DW_EH_PE_aligned => { + reader.ptr = + reader.ptr.with_addr(round_up(reader.ptr.addr(), mem::size_of::<*const u8>())?); + core::ptr::null() + } _ => return Err(()), }; + let mut ptr = if base_ptr.is_null() { + // any value encoding other than absptr would be nonsensical here; + // there would be no source of pointer provenance + if encoding & 0x0F != DW_EH_PE_absptr { + return Err(()); + } + reader.read::<*const u8>() + } else { + let offset = read_encoded_offset(reader, encoding & 0x0F)?; + base_ptr.wrapping_add(offset) + }; + if encoding & DW_EH_PE_indirect != 0 { - result = *(result as *const usize); + ptr = *(ptr.cast::<*const u8>()); } - Ok(result) + Ok(ptr) } diff --git a/sgx_tstd/src/personality/dwarf/mod.rs b/sgx_tstd/src/sys/personality/dwarf/mod.rs similarity index 98% rename from sgx_tstd/src/personality/dwarf/mod.rs rename to sgx_tstd/src/sys/personality/dwarf/mod.rs index 6ce558354..8cdd26ac9 100644 --- a/sgx_tstd/src/personality/dwarf/mod.rs +++ b/sgx_tstd/src/sys/personality/dwarf/mod.rs @@ -83,7 +83,7 @@ impl DwarfReader { } // sign-extend if shift < u64::BITS && (byte & 0x40) != 0 { - result |= (!0) << shift; + result |= (!0 as u64) << shift; } result as i64 } diff --git a/sgx_tstd/src/personality/dwarf/tests.rs b/sgx_tstd/src/sys/personality/dwarf/tests.rs similarity index 100% rename from sgx_tstd/src/personality/dwarf/tests.rs rename to sgx_tstd/src/sys/personality/dwarf/tests.rs diff --git a/sgx_tstd/src/personality/gcc.rs b/sgx_tstd/src/sys/personality/gcc.rs similarity index 92% rename from sgx_tstd/src/personality/gcc.rs rename to sgx_tstd/src/sys/personality/gcc.rs index 7c0a8da52..1b526a668 100644 --- a/sgx_tstd/src/personality/gcc.rs +++ b/sgx_tstd/src/sys/personality/gcc.rs @@ -54,7 +54,7 @@ //! and the last personality routine transfers control to the catch block. use super::dwarf::eh::{self, EHAction, EHContext}; -use sgx_types::types::{c_int, uintptr_t}; +use sgx_types::types::c_int; use sgx_unwind as uw; // Register ids were lifted from LLVM's TargetLowering::getExceptionPointerRegister() @@ -90,19 +90,21 @@ unsafe extern "C" fn rust_eh_personality_impl( if actions as i32 & uw::_UA_SEARCH_PHASE as i32 != 0 { match eh_action { EHAction::None | EHAction::Cleanup(_) => uw::_URC_CONTINUE_UNWIND, - EHAction::Catch(_) => uw::_URC_HANDLER_FOUND, + EHAction::Catch(_) | EHAction::Filter(_) => uw::_URC_HANDLER_FOUND, EHAction::Terminate => uw::_URC_FATAL_PHASE1_ERROR, } } else { match eh_action { EHAction::None => uw::_URC_CONTINUE_UNWIND, - EHAction::Cleanup(lpad) | EHAction::Catch(lpad) => { + // Forced unwinding hits a terminate action. + EHAction::Filter(_) if actions as i32 & uw::_UA_FORCE_UNWIND as i32 != 0 => uw::_URC_CONTINUE_UNWIND, + EHAction::Cleanup(lpad) | EHAction::Catch(lpad) | EHAction::Filter(lpad) => { uw::_Unwind_SetGR( context, UNWIND_DATA_REG.0, - exception_object as uintptr_t, + exception_object.cast(), ); - uw::_Unwind_SetGR(context, UNWIND_DATA_REG.1, 0); + uw::_Unwind_SetGR(context, UNWIND_DATA_REG.1, core::ptr::null()); uw::_Unwind_SetIP(context, lpad); uw::_URC_INSTALL_CONTEXT } diff --git a/sgx_tstd/src/sys/personality/mod.rs b/sgx_tstd/src/sys/personality/mod.rs new file mode 100644 index 000000000..04c836c00 --- /dev/null +++ b/sgx_tstd/src/sys/personality/mod.rs @@ -0,0 +1,14 @@ +//! This module contains the implementation of the `eh_personality` lang item. +//! +//! The actual implementation is heavily dependent on the target since Rust +//! tries to use the native stack unwinding mechanism whenever possible. +//! +//! This personality function is still required with `-C panic=abort` because +//! it is used to catch foreign exceptions from `extern "C-unwind"` and turn +//! them into aborts. +//! +//! Additionally, ARM EHABI uses the personality function when generating +//! backtraces. + +mod dwarf; +mod gcc; diff --git a/sgx_tstd/src/sys/pipe.rs b/sgx_tstd/src/sys/pipe.rs index 0b0576528..066bc40e8 100644 --- a/sgx_tstd/src/sys/pipe.rs +++ b/sgx_tstd/src/sys/pipe.rs @@ -15,12 +15,12 @@ // specific language governing permissions and limitations // under the License.. -use crate::io::{self, IoSlice, IoSliceMut}; +use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; use crate::mem; use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; use crate::sys::fd::FileDesc; use crate::sys::{cvt_ocall, cvt_ocall_r}; -use crate::sys_common::IntoInner; +use crate::sys_common::{FromInner, IntoInner}; //////////////////////////////////////////////////////////////////////////////// // Anonymous pipes @@ -42,6 +42,10 @@ impl AnonPipe { self.0.read(buf) } + pub fn read_buf(&self, buf: BorrowedCursor<'_>) -> io::Result<()> { + self.0.read_buf(buf) + } + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.0.read_vectored(bufs) } @@ -51,6 +55,10 @@ impl AnonPipe { self.0.is_read_vectored() } + pub fn read_to_end(&self, buf: &mut Vec) -> io::Result { + self.0.read_to_end(buf) + } + pub fn write(&self, buf: &[u8]) -> io::Result { self.0.write(buf) } @@ -120,6 +128,7 @@ pub fn read2(p1: AnonPipe, v1: &mut Vec, p2: AnonPipe, v2: &mut Vec) -> } impl AsRawFd for AnonPipe { + #[inline] fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } @@ -143,6 +152,12 @@ impl FromRawFd for AnonPipe { } } +impl FromInner for AnonPipe { + fn from_inner(fd: FileDesc) -> Self { + Self(fd) + } +} + mod libc { pub use sgx_oc::ocall::{pipe2, poll}; pub use sgx_oc::*; diff --git a/sgx_tstd/src/sys/stdio.rs b/sgx_tstd/src/sys/stdio.rs index 65daff635..f6862670a 100644 --- a/sgx_tstd/src/sys/stdio.rs +++ b/sgx_tstd/src/sys/stdio.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License.. -use crate::io::{self, IoSlice, IoSliceMut}; +use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; use crate::mem::ManuallyDrop; use crate::os::unix::io::FromRawFd; use crate::sys::fd::FileDesc; @@ -37,6 +37,10 @@ impl io::Read for Stdin { unsafe { ManuallyDrop::new(FileDesc::from_raw_fd(libc::STDIN_FILENO)).read(buf) } } + fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + unsafe { ManuallyDrop::new(FileDesc::from_raw_fd(libc::STDIN_FILENO)).read_buf(buf) } + } + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { unsafe { ManuallyDrop::new(FileDesc::from_raw_fd(libc::STDIN_FILENO)).read_vectored(bufs) } } @@ -69,6 +73,7 @@ impl io::Write for Stdout { true } + #[inline] fn flush(&mut self) -> io::Result<()> { Ok(()) } @@ -96,6 +101,7 @@ impl io::Write for Stderr { true } + #[inline] fn flush(&mut self) -> io::Result<()> { Ok(()) } diff --git a/sgx_tstd/src/sys/thread.rs b/sgx_tstd/src/sys/thread.rs index bd3f5d97c..f7b85c8c1 100644 --- a/sgx_tstd/src/sys/thread.rs +++ b/sgx_tstd/src/sys/thread.rs @@ -37,7 +37,7 @@ unsafe impl Sync for Thread {} impl Thread { // unsafe: see thread::Builder::spawn_unchecked for safety requirements pub unsafe fn new(p: Box) -> io::Result { - let p = Box::into_raw(box p); + let p = Box::into_raw(Box::new(p)); let ret = NativeThread::new(thread_start, p as *mut _) .map(|t| Thread { native: t }) .map_err(|e| { diff --git a/sgx_tstd/src/sys/time.rs b/sgx_tstd/src/sys/time.rs index a8e35bf14..bdf8dea3e 100644 --- a/sgx_tstd/src/sys/time.rs +++ b/sgx_tstd/src/sys/time.rs @@ -18,8 +18,7 @@ use crate::fmt; use crate::time::Duration; -pub use self::inner::Instant; - +use crate::sys::cvt_ocall; use sgx_oc as libc; const NSEC_PER_SEC: u64 = 1_000_000_000; @@ -47,6 +46,10 @@ impl SystemTime { SystemTime { t: Timespec::new(tv_sec, tv_nsec) } } + pub fn now() -> SystemTime { + SystemTime { t: Timespec::now(libc::CLOCK_REALTIME) } + } + pub fn sub_time(&self, other: &SystemTime) -> Result { self.t.sub_timespec(&other.t) } @@ -86,6 +89,12 @@ impl Timespec { Timespec { tv_sec, tv_nsec: unsafe { Nanoseconds(tv_nsec as u32) } } } + pub fn now(clock: libc::clockid_t) -> Timespec { + let mut t = libc::timespec { tv_sec: 0, tv_nsec: 0 }; + cvt_ocall(unsafe { libc::ocall::clock_gettime(clock, &mut t) }).unwrap(); + Timespec::from(t) + } + pub fn sub_timespec(&self, other: &Timespec) -> Result { if self >= other { // NOTE(eddyb) two aspects of this `if`-`else` are required for LLVM @@ -120,11 +129,7 @@ impl Timespec { } pub fn checked_add_duration(&self, other: &Duration) -> Option { - let mut secs = other - .as_secs() - .try_into() // <- target type would be `i64` - .ok() - .and_then(|secs| self.tv_sec.checked_add(secs))?; + let mut secs = self.tv_sec.checked_add_unsigned(other.as_secs())?; // Nano calculations can't overflow because nanos are <1B which fit // in a u32. @@ -133,15 +138,11 @@ impl Timespec { nsec -= NSEC_PER_SEC as u32; secs = secs.checked_add(1)?; } - Some(Timespec::new(secs, nsec as i64)) + Some(Timespec::new(secs, nsec.into())) } pub fn checked_sub_duration(&self, other: &Duration) -> Option { - let mut secs = other - .as_secs() - .try_into() // <- target type would be `i64` - .ok() - .and_then(|secs| self.tv_sec.checked_sub(secs))?; + let mut secs = self.tv_sec.checked_sub_unsigned(other.as_secs())?; // Similar to above, nanos can't overflow. let mut nsec = self.tv_nsec.0 as i32 - other.subsec_nanos() as i32; @@ -149,7 +150,7 @@ impl Timespec { nsec += NSEC_PER_SEC as i32; secs = secs.checked_sub(1)?; } - Some(Timespec::new(secs, nsec as i64)) + Some(Timespec::new(secs, nsec.into())) } #[allow(dead_code)] @@ -157,7 +158,7 @@ impl Timespec { pub fn to_timespec(&self) -> Option { Some(libc::timespec { tv_sec: self.tv_sec.try_into().ok()?, - tv_nsec: self.tv_nsec.0.try_into().ok()?, + tv_nsec: self.tv_nsec.0.into(), }) } } @@ -168,59 +169,34 @@ impl From for Timespec { } } -mod inner { - use crate::fmt; - use crate::sys::cvt_ocall; - use crate::time::Duration; - - use super::libc; - use super::{SystemTime, Timespec}; +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct Instant { + t: Timespec, +} - #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] - pub struct Instant { - t: Timespec, +impl Instant { + pub fn now() -> Instant { + Instant { t: Timespec::now(libc::CLOCK_MONOTONIC) } } - impl Instant { - pub fn now() -> Instant { - Instant { t: Timespec::now(libc::CLOCK_MONOTONIC) } - } - - pub fn checked_sub_instant(&self, other: &Instant) -> Option { - self.t.sub_timespec(&other.t).ok() - } - - pub fn checked_add_duration(&self, other: &Duration) -> Option { - Some(Instant { t: self.t.checked_add_duration(other)? }) - } - - pub fn checked_sub_duration(&self, other: &Duration) -> Option { - Some(Instant { t: self.t.checked_sub_duration(other)? }) - } + pub fn checked_sub_instant(&self, other: &Instant) -> Option { + self.t.sub_timespec(&other.t).ok() } - impl fmt::Debug for Instant { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Instant") - .field("tv_sec", &self.t.tv_sec) - .field("tv_nsec", &self.t.tv_nsec.0) - .finish() - } + pub fn checked_add_duration(&self, other: &Duration) -> Option { + Some(Instant { t: self.t.checked_add_duration(other)? }) } - impl SystemTime { - pub fn now() -> SystemTime { - SystemTime { t: Timespec::now(libc::CLOCK_REALTIME) } - } + pub fn checked_sub_duration(&self, other: &Duration) -> Option { + Some(Instant { t: self.t.checked_sub_duration(other)? }) } +} - pub type clock_t = libc::c_int; - - impl Timespec { - pub fn now(clock: clock_t) -> Timespec { - let mut t = libc::timespec { tv_sec: 0, tv_nsec: 0 }; - cvt_ocall(unsafe { libc::ocall::clock_gettime(clock, &mut t) }).unwrap(); - Timespec::from(t) - } +impl fmt::Debug for Instant { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Instant") + .field("tv_sec", &self.t.tv_sec) + .field("tv_nsec", &self.t.tv_nsec.0) + .finish() } } diff --git a/sgx_tstd/src/sys/unsupported/common.rs b/sgx_tstd/src/sys/unsupported/common.rs index fde0ff60e..43b5d169c 100644 --- a/sgx_tstd/src/sys/unsupported/common.rs +++ b/sgx_tstd/src/sys/unsupported/common.rs @@ -3,6 +3,7 @@ use crate::io as std_io; use sgx_trts::error::abort; pub mod memchr { + #[allow(unused_imports)] pub use core::slice::memchr::{memchr, memrchr}; } diff --git a/sgx_tstd/src/sys/unsupported/pipe.rs b/sgx_tstd/src/sys/unsupported/pipe.rs index cf4c11971..049963aed 100644 --- a/sgx_tstd/src/sys/unsupported/pipe.rs +++ b/sgx_tstd/src/sys/unsupported/pipe.rs @@ -15,11 +15,11 @@ // specific language governing permissions and limitations // under the License.. -use crate::io::{self, IoSlice, IoSliceMut}; +use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; use crate::sys::fd::FileDesc; use crate::sys::unsupported::unsupported; -use crate::sys_common::IntoInner; +use crate::sys_common::{FromInner, IntoInner}; pub struct AnonPipe(FileDesc); @@ -32,6 +32,10 @@ impl AnonPipe { unsupported() } + pub fn read_buf(&self, _buf: BorrowedCursor<'_>) -> io::Result<()> { + unsupported() + } + pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { unsupported() } @@ -40,6 +44,11 @@ impl AnonPipe { false } + #[allow(clippy::ptr_arg)] + pub fn read_to_end(&self, _buf: &mut Vec) -> io::Result { + unsupported() + } + pub fn write(&self, _buf: &[u8]) -> io::Result { unsupported() } @@ -87,3 +96,9 @@ impl FromRawFd for AnonPipe { Self(FromRawFd::from_raw_fd(raw_fd)) } } + +impl FromInner for AnonPipe { + fn from_inner(fd: FileDesc) -> Self { + Self(fd) + } +} diff --git a/sgx_tstd/src/sys/unsupported/process.rs b/sgx_tstd/src/sys/unsupported/process.rs index bd405b9c9..832c823e2 100644 --- a/sgx_tstd/src/sys/unsupported/process.rs +++ b/sgx_tstd/src/sys/unsupported/process.rs @@ -21,6 +21,7 @@ use crate::fmt; use crate::io; use crate::marker::PhantomData; use crate::num::NonZeroI32; +use crate::os::unix::io::BorrowedFd; use crate::path::Path; use crate::sys::fd::FileDesc; use crate::sys::fs::File; @@ -56,6 +57,7 @@ pub enum Stdio { Null, MakePipe, Fd(FileDesc), + StaticFd(BorrowedFd<'static>), } impl Command { @@ -118,6 +120,11 @@ impl Command { ) -> io::Result<(Process, StdioPipes)> { unsupported() } + + pub fn output(&mut self) -> io::Result<(ExitStatus, Vec, Vec)> { + let (proc, pipes) = self.spawn(Stdio::MakePipe, false)?; + crate::sys_common::process::wait_with_output(proc, pipes) + } } impl From for Stdio { @@ -126,6 +133,30 @@ impl From for Stdio { } } +#[cfg(feature = "stdio")] +impl From for Stdio { + fn from(_: io::Stdout) -> Stdio { + // This ought really to be is Stdio::StaticFd(input_argument.as_fd()). + // But AsFd::as_fd takes its argument by reference, and yields + // a bounded lifetime, so it's no use here. There is no AsStaticFd. + // + // Additionally AsFd is only implemented for the *locked* versions. + // We don't want to lock them here. (The implications of not locking + // are the same as those for process::Stdio::inherit().) + // + // Arguably the hypothetical AsStaticFd and AsFd<'static> + // should be implemented for io::Stdout, not just for StdoutLocked. + Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw(libc::STDOUT_FILENO) }) + } +} + +#[cfg(feature = "stdio")] +impl From for Stdio { + fn from(_: io::Stderr) -> Stdio { + Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw(libc::STDERR_FILENO) }) + } +} + impl From for Stdio { fn from(file: File) -> Stdio { Stdio::Fd(file.into_inner()) @@ -142,7 +173,7 @@ impl fmt::Debug for Command { // // This is not actually an "exit status" in Unix terminology. Rather, it is a "wait status". // See the discussion in comments and doc comments for `std::process::ExitStatus`. -#[derive(PartialEq, Eq, Clone, Copy)] +#[derive(PartialEq, Eq, Clone, Copy, Default)] pub struct ExitStatus(c_int); impl fmt::Debug for ExitStatus { @@ -291,13 +322,20 @@ impl ExitStatusError { } } -#[derive(PartialEq, Eq, Clone, Copy, Debug)] -pub struct ExitCode(bool); +#[derive(PartialEq, Eq, Clone, Copy)] +pub struct ExitCode(u8); + +impl fmt::Debug for ExitCode { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_tuple("unix_exit_status").field(&self.0).finish() + } +} impl ExitCode { - pub const SUCCESS: ExitCode = ExitCode(false); - pub const FAILURE: ExitCode = ExitCode(true); + pub const SUCCESS: ExitCode = ExitCode(libc::EXIT_SUCCESS as _); + pub const FAILURE: ExitCode = ExitCode(libc::EXIT_FAILURE as _); + #[inline] pub fn as_i32(&self) -> i32 { self.0 as i32 } @@ -305,10 +343,7 @@ impl ExitCode { impl From for ExitCode { fn from(code: u8) -> Self { - match code { - 0 => Self::SUCCESS, - 1..=255 => Self::FAILURE, - } + Self(code) } } diff --git a/sgx_tstd/src/sys_common/at_exit_imp.rs b/sgx_tstd/src/sys_common/at_exit_imp.rs index 40f588e0b..607e85f77 100644 --- a/sgx_tstd/src/sys_common/at_exit_imp.rs +++ b/sgx_tstd/src/sys_common/at_exit_imp.rs @@ -43,7 +43,7 @@ const ITERS: usize = 10; unsafe fn init() -> bool { if QUEUE.is_null() { - let state: Box = box Vec::new(); + let state: Box = Box::default(); QUEUE = Box::into_raw(state); } else if QUEUE == DONE { // can't re-init after a cleanup diff --git a/sgx_tstd/src/sys_common/io.rs b/sgx_tstd/src/sys_common/io.rs index ca8c6f11e..c0889a3e6 100644 --- a/sgx_tstd/src/sys_common/io.rs +++ b/sgx_tstd/src/sys_common/io.rs @@ -57,7 +57,7 @@ pub mod test { pub fn tmpdir() -> TempDir { let p = env::temp_dir(); let mut rng = Rng::new(); - let ret = p.join(&format!("rust-{}", rng.next_u32())); + let ret = p.join(format!("rust-{}", rng.next_u32())); fs::create_dir(&ret).unwrap(); TempDir(ret) } diff --git a/sgx_tstd/src/sys_common/lazy_box.rs b/sgx_tstd/src/sys_common/lazy_box.rs new file mode 100644 index 000000000..326a59547 --- /dev/null +++ b/sgx_tstd/src/sys_common/lazy_box.rs @@ -0,0 +1,107 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +#![allow(dead_code)] // Only used on some platforms. + +// This is used to wrap pthread {Mutex, Condvar, RwLock} in. + +use crate::marker::PhantomData; +use crate::ops::{Deref, DerefMut}; +use crate::ptr::null_mut; +use crate::sync::atomic::{ + AtomicPtr, + Ordering::{AcqRel, Acquire}, +}; + +pub(crate) struct LazyBox { + ptr: AtomicPtr, + _phantom: PhantomData, +} + +pub(crate) trait LazyInit { + /// This is called before the box is allocated, to provide the value to + /// move into the new box. + /// + /// It might be called more than once per LazyBox, as multiple threads + /// might race to initialize it concurrently, each constructing and initializing + /// their own box. All but one of them will be passed to `cancel_init` right after. + fn init() -> Box; + + /// Any surplus boxes from `init()` that lost the initialization race + /// are passed to this function for disposal. + /// + /// The default implementation calls destroy(). + fn cancel_init(x: Box) { + Self::destroy(x); + } + + /// This is called to destroy a used box. + /// + /// The default implementation just drops it. + fn destroy(_: Box) {} +} + +impl LazyBox { + #[inline] + pub const fn new() -> Self { + Self { ptr: AtomicPtr::new(null_mut()), _phantom: PhantomData } + } + + #[inline] + fn get_pointer(&self) -> *mut T { + let ptr = self.ptr.load(Acquire); + if ptr.is_null() { self.initialize() } else { ptr } + } + + #[cold] + fn initialize(&self) -> *mut T { + let new_ptr = Box::into_raw(T::init()); + match self.ptr.compare_exchange(null_mut(), new_ptr, AcqRel, Acquire) { + Ok(_) => new_ptr, + Err(ptr) => { + // Lost the race to another thread. + // Drop the box we created, and use the one from the other thread instead. + T::cancel_init(unsafe { Box::from_raw(new_ptr) }); + ptr + } + } + } +} + +impl Deref for LazyBox { + type Target = T; + #[inline] + fn deref(&self) -> &T { + unsafe { &*self.get_pointer() } + } +} + +impl DerefMut for LazyBox { + #[inline] + fn deref_mut(&mut self) -> &mut T { + unsafe { &mut *self.get_pointer() } + } +} + +impl Drop for LazyBox { + fn drop(&mut self) { + let ptr = *self.ptr.get_mut(); + if !ptr.is_null() { + T::destroy(unsafe { Box::from_raw(ptr) }); + } + } +} diff --git a/sgx_tstd/src/sys_common/mod.rs b/sgx_tstd/src/sys_common/mod.rs index d2fa6b8b9..a8dda5f27 100644 --- a/sgx_tstd/src/sys_common/mod.rs +++ b/sgx_tstd/src/sys_common/mod.rs @@ -45,6 +45,7 @@ pub mod fs; #[cfg(feature = "backtrace")] pub mod gnu; pub mod io; +pub mod lazy_box; pub mod memchr; pub mod mutex; pub mod once; @@ -61,7 +62,8 @@ pub mod thread_info; pub mod thread_local_dtor; #[cfg(feature = "thread")] pub mod thread_local_key; -pub mod thread_parker; +pub mod thread_parking; +pub mod wstr; pub mod wtf8; /// A trait for viewing representations from std types @@ -88,6 +90,23 @@ pub trait FromInner { fn from_inner(inner: Inner) -> Self; } +/// A trait for creating std types from internal representations +#[doc(hidden)] +pub trait TryFromInner: Sized { + type Error; + + fn try_from_inner(inner: Inner) -> Result; +} + +/// A trait for creating std types from internal representations +pub trait TryIntoInner: Sized { + /// The type returned in the event of a conversion error. + type Error; + + /// Performs the conversion. + fn try_into_inner(self) -> Result; +} + /// Enqueues a procedure to run when the main thread exits. /// /// Currently these closures are only run once the main *Rust* thread exits. diff --git a/sgx_tstd/src/sys_common/mutex.rs b/sgx_tstd/src/sys_common/mutex.rs index 0c9fd8d6c..651c72b03 100644 --- a/sgx_tstd/src/sys_common/mutex.rs +++ b/sgx_tstd/src/sys_common/mutex.rs @@ -15,4 +15,6 @@ // specific language governing permissions and limitations // under the License.. -pub use sgx_sync::{MovableMutex, StaticMutex, StaticMutexGuard}; +#[allow(unused_imports)] +pub use sgx_sync::{StaticMutex, StaticMutexGuard}; +pub use sgx_sync::MovableMutex as Mutex; diff --git a/sgx_tstd/src/sys_common/net.rs b/sgx_tstd/src/sys_common/net.rs index 1464dafd2..186618fc2 100644 --- a/sgx_tstd/src/sys_common/net.rs +++ b/sgx_tstd/src/sys_common/net.rs @@ -18,15 +18,14 @@ #[cfg(feature = "unit_test")] mod tests; -use crate::convert::{TryFrom, TryInto}; use crate::fmt; -use crate::io::{self, ErrorKind, IoSlice, IoSliceMut}; +use crate::io::{self, BorrowedCursor, ErrorKind, IoSlice, IoSliceMut}; use crate::mem; use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr}; use crate::sys::common::small_c_string::run_with_cstr; use crate::sys::net::{init, Socket}; use crate::sys::{cvt_ocall, cvt_ocall_r}; -use crate::sys_common::{AsInner, FromInner, IntoInner}; +use crate::sys_common::{AsInner, FromInner, IntoInner, TryIntoInner}; use crate::time::Duration; use crate::vec; @@ -77,7 +76,7 @@ where F: FnOnce() -> OCallResult, { let sa = cvt_ocall(f())?; - sa.try_into() + sa.try_into_inner() } pub fn sockaddr_to_addr(storage: &c::sockaddr_storage, len: usize) -> io::Result { @@ -182,8 +181,7 @@ impl TcpStream { init(); let sock = Socket::new(addr, c::SOCK_STREAM)?; - let sock_addr = addr.to_owned().into(); - cvt_ocall_r(|| unsafe { c::connect(sock.as_raw(), &sock_addr) })?; + sock.connect(addr)?; Ok(TcpStream { inner: sock }) } @@ -195,6 +193,7 @@ impl TcpStream { Ok(TcpStream { inner: sock }) } + #[inline] pub fn socket(&self) -> &Socket { &self.inner } @@ -227,6 +226,10 @@ impl TcpStream { self.inner.read(buf) } + pub fn read_buf(&self, buf: BorrowedCursor<'_>) -> io::Result<()> { + self.inner.read_buf(buf) + } + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.inner.read_vectored(bufs) } @@ -240,7 +243,7 @@ impl TcpStream { let ret = cvt_ocall(unsafe { c::send(self.inner.as_raw(), buf, c::MSG_NOSIGNAL) })?; - Ok(ret) + Ok(ret as usize) } pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { @@ -303,6 +306,7 @@ impl TcpStream { } impl AsInner for TcpStream { + #[inline] fn as_inner(&self) -> &Socket { &self.inner } @@ -353,7 +357,7 @@ impl TcpListener { setsockopt(&sock, c::SOL_SOCKET, c::SO_REUSEADDR, 1_i32)?; // Bind our new socket - let sock_addr = addr.into(); + let sock_addr = addr.into_inner(); cvt_ocall(unsafe { c::bind(sock.as_raw(), &sock_addr) })?; // Start listening @@ -361,6 +365,7 @@ impl TcpListener { Ok(TcpListener { inner: sock }) } + #[inline] pub fn socket(&self) -> &Socket { &self.inner } @@ -375,7 +380,7 @@ impl TcpListener { pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> { let (sock, addr) = self.inner.accept()?; - let addr = addr.try_into()?; + let addr = addr.try_into_inner()?; Ok((TcpStream { inner: sock }, addr)) } @@ -444,7 +449,7 @@ impl UdpSocket { init(); let sock = Socket::new(addr, c::SOCK_DGRAM)?; - let sock_addr = addr.into(); + let sock_addr: SockAddr = addr.into_inner(); cvt_ocall(unsafe { c::bind(sock.as_raw(), &sock_addr) })?; Ok(UdpSocket { inner: sock }) } @@ -474,11 +479,11 @@ impl UdpSocket { } pub fn send_to(&self, buf: &[u8], dst: &SocketAddr) -> io::Result { - let dst = dst.into(); + let dst = dst.into_inner(); let ret = cvt_ocall(unsafe { c::sendto(self.inner.as_raw(), buf, c::MSG_NOSIGNAL, &dst) })?; - Ok(ret) + Ok(ret as usize) } pub fn duplicate(&self) -> io::Result { @@ -612,7 +617,7 @@ impl UdpSocket { } pub fn connect(&self, addr: io::Result<&SocketAddr>) -> io::Result<()> { - let sock_addr = addr?.into(); + let sock_addr: SockAddr = addr?.into_inner(); cvt_ocall_r(|| unsafe { c::connect(self.inner.as_raw(), &sock_addr) }).map(drop) } } diff --git a/sgx_tstd/src/sys_common/net/tests.rs b/sgx_tstd/src/sys_common/net/tests.rs index feaf06aab..4aead0574 100644 --- a/sgx_tstd/src/sys_common/net/tests.rs +++ b/sgx_tstd/src/sys_common/net/tests.rs @@ -25,7 +25,7 @@ fn no_lookup_host_duplicates() { let mut addrs = HashMap::new(); let lh = match LookupHost::try_from(("localhost", 0)) { Ok(lh) => lh, - Err(e) => panic!("couldn't resolve `localhost': {e}"), + Err(e) => panic!("couldn't resolve `localhost`: {e}"), }; for sa in lh { *addrs.entry(sa).or_insert(0) += 1; diff --git a/sgx_tstd/src/sys_common/once/futex.rs b/sgx_tstd/src/sys_common/once/futex.rs index 82296d59a..69303081b 100644 --- a/sgx_tstd/src/sys_common/once/futex.rs +++ b/sgx_tstd/src/sys_common/once/futex.rs @@ -21,6 +21,7 @@ use crate::sync::atomic::{ AtomicU32, Ordering::{Acquire, Relaxed, Release}, }; +use crate::sync::once::ExclusiveState; use crate::sys::futex::{futex_wait, futex_wake_all}; // On some platforms, the OS is very nice and handles the waiter queue for us. @@ -95,6 +96,16 @@ impl Once { self.state.load(Acquire) == COMPLETE } + #[inline] + pub(crate) fn state(&mut self) -> ExclusiveState { + match *self.state.get_mut() { + INCOMPLETE => ExclusiveState::Incomplete, + POISONED => ExclusiveState::Poisoned, + COMPLETE => ExclusiveState::Complete, + _ => unreachable!("invalid Once state"), + } + } + // This uses FnMut to match the API of the generic implementation. As this // implementation is quite light-weight, it is generic over the closure and // so avoids the cost of dynamic dispatch. @@ -134,7 +145,8 @@ impl Once { RUNNING | QUEUED => { // Set the state to QUEUED if it is not already. if state == RUNNING - && let Err(new) = self.state.compare_exchange_weak(RUNNING, QUEUED, Relaxed, Acquire) + && let Err(new) = + self.state.compare_exchange_weak(RUNNING, QUEUED, Relaxed, Acquire) { state = new; continue; diff --git a/sgx_tstd/src/sys_common/once/mod.rs b/sgx_tstd/src/sys_common/once/mod.rs index 94b3e65f4..53992389e 100644 --- a/sgx_tstd/src/sys_common/once/mod.rs +++ b/sgx_tstd/src/sys_common/once/mod.rs @@ -43,5 +43,5 @@ mod futex; pub use futex::{Once, OnceState}; -// mod generic; -// pub use generic::{Once, OnceState}; +// mod queue; +// pub use queue::{Once, OnceState}; diff --git a/sgx_tstd/src/sys_common/once/generic.rs b/sgx_tstd/src/sys_common/once/queue.rs similarity index 97% rename from sgx_tstd/src/sys_common/once/generic.rs rename to sgx_tstd/src/sys_common/once/queue.rs index cddffca9d..a4fed8c52 100644 --- a/sgx_tstd/src/sys_common/once/generic.rs +++ b/sgx_tstd/src/sys_common/once/queue.rs @@ -77,6 +77,7 @@ use crate::fmt; use crate::ptr; use crate::sync as public; use crate::sync::atomic::{AtomicBool, AtomicPtr, Ordering}; +use crate::sync::once::ExclusiveState; use crate::thread::{self, Thread}; type Masked = (); @@ -137,6 +138,16 @@ impl Once { self.state_and_queue.load(Ordering::Acquire).addr() == COMPLETE } + #[inline] + pub(crate) fn state(&mut self) -> ExclusiveState { + match self.state_and_queue.get_mut().addr() { + INCOMPLETE => ExclusiveState::Incomplete, + POISONED => ExclusiveState::Poisoned, + COMPLETE => ExclusiveState::Complete, + _ => unreachable!("invalid Once state"), + } + } + // This is a non-generic function to reduce the monomorphization cost of // using `call_once` (this isn't exactly a trivial or small implementation). // diff --git a/sgx_tstd/src/sys_common/process.rs b/sgx_tstd/src/sys_common/process.rs index 6b24469ed..e60a862fb 100644 --- a/sgx_tstd/src/sys_common/process.rs +++ b/sgx_tstd/src/sys_common/process.rs @@ -20,10 +20,13 @@ use crate::collections::BTreeMap; use crate::env; use crate::ffi::{OsStr, OsString}; -use crate::sys::process::EnvKey; +use crate::fmt; +use crate::io; +use crate::sys::unsupported::pipe::read2; +use crate::sys::process::{EnvKey, ExitStatus, Process, StdioPipes}; // Stores a set of changes to an environment -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct CommandEnv { clear: bool, saw_path: bool, @@ -37,6 +40,14 @@ impl Default for CommandEnv { } } +impl fmt::Debug for CommandEnv { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut debug_command_env = f.debug_struct("CommandEnv"); + debug_command_env.field("clear", &self.clear).field("vars", &self.vars); + debug_command_env.finish() + } +} + impl CommandEnv { // Capture the current environment with these changes applied #[allow(clippy::useless_conversion)] @@ -48,7 +59,7 @@ impl CommandEnv { } } for (k, maybe_v) in &self.vars { - if let &Some(ref v) = maybe_v { + if let Some(v) = maybe_v { result.insert(k.clone(), v.clone()); } else { result.remove(k); @@ -87,6 +98,10 @@ impl CommandEnv { self.vars.clear(); } + pub fn does_clear(&self) -> bool { + self.clear + } + pub fn have_changed_path(&self) -> bool { self.saw_path || self.clear } @@ -132,3 +147,30 @@ impl<'a> ExactSizeIterator for CommandEnvs<'a> { self.iter.is_empty() } } + +pub fn wait_with_output( + mut process: Process, + mut pipes: StdioPipes, +) -> io::Result<(ExitStatus, Vec, Vec)> { + drop(pipes.stdin.take()); + + let (mut stdout, mut stderr) = (Vec::new(), Vec::new()); + match (pipes.stdout.take(), pipes.stderr.take()) { + (None, None) => {} + (Some(out), None) => { + let res = out.read_to_end(&mut stdout); + res.unwrap(); + } + (None, Some(err)) => { + let res = err.read_to_end(&mut stderr); + res.unwrap(); + } + (Some(out), Some(err)) => { + let res = read2(out, &mut stdout, err, &mut stderr); + res.unwrap(); + } + } + + let status = process.wait()?; + Ok((status, stdout, stderr)) +} diff --git a/sgx_tstd/src/sys_common/remutex.rs b/sgx_tstd/src/sys_common/remutex.rs index 0c7f5c486..e081652c1 100644 --- a/sgx_tstd/src/sys_common/remutex.rs +++ b/sgx_tstd/src/sys_common/remutex.rs @@ -15,7 +15,4 @@ // specific language governing permissions and limitations // under the License.. -#[cfg(feature = "unit_test")] -mod tests; - pub use sgx_sync::{ReentrantMutex, ReentrantMutexGuard}; diff --git a/sgx_tstd/src/sys_common/rwlock.rs b/sgx_tstd/src/sys_common/rwlock.rs index 013e4ff73..bdd698b94 100644 --- a/sgx_tstd/src/sys_common/rwlock.rs +++ b/sgx_tstd/src/sys_common/rwlock.rs @@ -15,4 +15,6 @@ // specific language governing permissions and limitations // under the License.. -pub use sgx_sync::{MovableRwLock, StaticRwLock, StaticRwLockReadGuard, StaticRwLockWriteGuard}; +#[allow(unused_imports)] +pub use sgx_sync::{StaticRwLock, StaticRwLockReadGuard, StaticRwLockWriteGuard}; +pub use sgx_sync::MovableRwLock as RwLock; diff --git a/sgx_tstd/src/sys_common/thread_info.rs b/sgx_tstd/src/sys_common/thread_info.rs index c0ffdf706..7ff17de67 100644 --- a/sgx_tstd/src/sys_common/thread_info.rs +++ b/sgx_tstd/src/sys_common/thread_info.rs @@ -15,40 +15,62 @@ // specific language governing permissions and limitations // under the License.. -use crate::cell::RefCell; +use crate::cell::OnceCell; use crate::thread::Thread; +use guard::Guard; struct ThreadInfo { - thread: Thread, + stack_guard: OnceCell, + thread: OnceCell, } -thread_local! { static THREAD_INFO: RefCell> = const { RefCell::new(None) } } +thread_local! { + static THREAD_INFO: ThreadInfo = const { ThreadInfo { + stack_guard: OnceCell::new(), + thread: OnceCell::new() + } }; +} impl ThreadInfo { fn with(f: F) -> Option where - F: FnOnce(&mut ThreadInfo) -> R, + F: FnOnce(&Thread, &OnceCell) -> R, { THREAD_INFO .try_with(move |thread_info| { - let mut thread_info = thread_info.borrow_mut(); - let thread_info = thread_info.get_or_insert_with(|| ThreadInfo { - thread: Thread::new(None), - }); - f(thread_info) + let thread = thread_info.thread.get_or_init(|| Thread::new(None)); + f(thread, &thread_info.stack_guard) }) .ok() } } pub fn current_thread() -> Option { - ThreadInfo::with(|info| info.thread.clone()) + ThreadInfo::with(|thread, _| thread.clone()) +} + +pub fn stack_guard() -> Option { + ThreadInfo::with(|_, guard| guard.get().cloned()).flatten() } -pub fn set(thread: Thread) { +/// Set new thread info, panicking if it has already been initialized +#[allow(unreachable_code, unreachable_patterns)] // some platforms don't use stack_guard +pub fn set(stack_guard: Option, thread: Thread) { THREAD_INFO.with(move |thread_info| { - let mut thread_info = thread_info.borrow_mut(); - //rtassert!(thread_info.is_none()); - *thread_info = Some(ThreadInfo { thread }); + rtassert!(thread_info.stack_guard.get().is_none() && thread_info.thread.get().is_none()); + if let Some(guard) = stack_guard { + thread_info.stack_guard.set(guard).unwrap(); + } + thread_info.thread.set(thread).unwrap(); }); } + +pub mod guard { + pub type Guard = !; + pub unsafe fn current() -> Option { + None + } + pub unsafe fn init() -> Option { + None + } +} diff --git a/sgx_tstd/src/sys_common/thread_local_dtor.rs b/sgx_tstd/src/sys_common/thread_local_dtor.rs index ab04fd5d4..11d8caa7e 100644 --- a/sgx_tstd/src/sys_common/thread_local_dtor.rs +++ b/sgx_tstd/src/sys_common/thread_local_dtor.rs @@ -29,6 +29,7 @@ #![allow(dead_code)] +use crate::cell::RefCell; use crate::ptr; use crate::sys_common::thread_local_key::StaticKey; @@ -44,17 +45,23 @@ pub unsafe fn register_dtor_fallback(t: *mut u8, dtor: unsafe extern "C" fn(*mut // flagged for destruction. static DTORS: StaticKey = StaticKey::new(Some(run_dtors)); - type List = Vec<(*mut u8, unsafe extern "C" fn(*mut u8))>; + // FIXME(joboet): integrate RefCell into pointer to avoid infinite recursion + // when the global allocator tries to register a destructor and just panic + // instead. + type List = RefCell>; if DTORS.get().is_null() { - let v: Box = box Vec::new(); + let v: Box = Box::new(RefCell::new(Vec::new())); DTORS.set(Box::into_raw(v) as *mut u8); } - let list: &mut List = &mut *(DTORS.get() as *mut List); - list.push((t, dtor)); + let list = &*(DTORS.get() as *const List); + match list.try_borrow_mut() { + Ok(mut dtors) => dtors.push((t, dtor)), + Err(_) => rtabort!("global allocator may not use TLS"), + } unsafe extern "C" fn run_dtors(mut ptr: *mut u8) { while !ptr.is_null() { - let list: Box = Box::from_raw(ptr as *mut List); + let list = Box::from_raw(ptr as *mut List).into_inner(); for (ptr, dtor) in list.into_iter() { dtor(ptr); } diff --git a/sgx_tstd/src/sys_common/thread_local_key.rs b/sgx_tstd/src/sys_common/thread_local_key.rs index 78d66f219..1a071f8ec 100644 --- a/sgx_tstd/src/sys_common/thread_local_key.rs +++ b/sgx_tstd/src/sys_common/thread_local_key.rs @@ -133,9 +133,13 @@ pub struct Key { /// This value specifies no destructor by default. pub const INIT: StaticKey = StaticKey::new(None); +// Define a sentinel value that is likely not to be returned +// as a TLS key. +const KEY_SENTVAL: usize = 0; + impl StaticKey { pub const fn new(dtor: Option) -> StaticKey { - StaticKey { key: atomic::AtomicUsize::new(0), dtor } + StaticKey { key: atomic::AtomicUsize::new(KEY_SENTVAL), dtor } } /// Gets the value associated with this TLS key @@ -159,33 +163,38 @@ impl StaticKey { #[inline] unsafe fn key(&self) -> imp::Key { match self.key.load(Ordering::Relaxed) { - 0 => self.lazy_init() as imp::Key, + KEY_SENTVAL => self.lazy_init() as imp::Key, n => n as imp::Key, } } unsafe fn lazy_init(&self) -> usize { - // POSIX allows the key created here to be 0, but the compare_exchange - // below relies on using 0 as a sentinel value to check who won the + // POSIX allows the key created here to be KEY_SENTVAL, but the compare_exchange + // below relies on using KEY_SENTVAL as a sentinel value to check who won the // race to set the shared TLS key. As far as I know, there is no // guaranteed value that cannot be returned as a posix_key_create key, // so there is no value we can initialize the inner key with to // prove that it has not yet been set. As such, we'll continue using a - // value of 0, but with some gyrations to make sure we have a non-0 + // value of KEY_SENTVAL, but with some gyrations to make sure we have a non-KEY_SENTVAL // value returned from the creation routine. // FIXME: this is clearly a hack, and should be cleaned up. let key1 = imp::create(self.dtor); - let key = if key1 != 0 { + let key = if key1 as usize != KEY_SENTVAL { key1 } else { let key2 = imp::create(self.dtor); imp::destroy(key1); key2 }; - rtassert!(key != 0); - match self.key.compare_exchange(0, key, Ordering::SeqCst, Ordering::SeqCst) { + rtassert!(key as usize != KEY_SENTVAL); + match self.key.compare_exchange( + KEY_SENTVAL, + key as usize, + Ordering::SeqCst, + Ordering::SeqCst, + ) { // The CAS succeeded, so we've created the actual key - Ok(_) => key, + Ok(_) => key as usize, // If someone beat us to the punch, use their key instead Err(n) => { imp::destroy(key); diff --git a/sgx_tstd/src/sys_common/thread_parker/futex.rs b/sgx_tstd/src/sys_common/thread_parking/futex.rs similarity index 98% rename from sgx_tstd/src/sys_common/thread_parker/futex.rs rename to sgx_tstd/src/sys_common/thread_parking/futex.rs index c076fb037..b887af643 100644 --- a/sgx_tstd/src/sys_common/thread_parker/futex.rs +++ b/sgx_tstd/src/sys_common/thread_parking/futex.rs @@ -53,7 +53,7 @@ impl Parker { /// Construct the futex parker. The UNIX parker implementation /// requires this to happen in-place. #[allow(clippy::new_ret_no_self)] - pub unsafe fn new(parker: *mut Parker) { + pub unsafe fn new_in_place(parker: *mut Parker) { parker.write(Self { state: AtomicU32::new(EMPTY) }); } diff --git a/sgx_tstd/src/sys_common/thread_parker/generic.rs b/sgx_tstd/src/sys_common/thread_parking/generic.rs similarity index 99% rename from sgx_tstd/src/sys_common/thread_parker/generic.rs rename to sgx_tstd/src/sys_common/thread_parking/generic.rs index 58012b499..f8145ac47 100644 --- a/sgx_tstd/src/sys_common/thread_parker/generic.rs +++ b/sgx_tstd/src/sys_common/thread_parking/generic.rs @@ -37,7 +37,7 @@ impl Parker { /// Construct the generic parker. The UNIX parker implementation /// requires this to happen in-place. #[allow(clippy::new_ret_no_self)] - pub unsafe fn new(parker: *mut Parker) { + pub unsafe fn new_in_place(parker: *mut Parker) { parker.write(Parker { state: AtomicUsize::new(EMPTY), lock: Mutex::new(()), diff --git a/sgx_tstd/src/sys_common/thread_parker/mod.rs b/sgx_tstd/src/sys_common/thread_parking/mod.rs similarity index 100% rename from sgx_tstd/src/sys_common/thread_parker/mod.rs rename to sgx_tstd/src/sys_common/thread_parking/mod.rs diff --git a/sgx_tstd/src/sys_common/wstr.rs b/sgx_tstd/src/sys_common/wstr.rs new file mode 100644 index 000000000..52f681f32 --- /dev/null +++ b/sgx_tstd/src/sys_common/wstr.rs @@ -0,0 +1,76 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License.. + +//! This module contains constructs to work with 16-bit characters (UCS-2 or UTF-16) +#![allow(dead_code)] + +use crate::marker::PhantomData; +use crate::num::NonZeroU16; +use crate::ptr::NonNull; + +/// A safe iterator over a LPWSTR +/// (aka a pointer to a series of UTF-16 code units terminated by a NULL). +pub struct WStrUnits<'a> { + // The pointer must never be null... + lpwstr: NonNull, + // ...and the memory it points to must be valid for this lifetime. + lifetime: PhantomData<&'a [u16]>, +} + +impl WStrUnits<'_> { + /// Create the iterator. Returns `None` if `lpwstr` is null. + /// + /// SAFETY: `lpwstr` must point to a null-terminated wide string that lives + /// at least as long as the lifetime of this struct. + pub unsafe fn new(lpwstr: *const u16) -> Option { + Some(Self { lpwstr: NonNull::new(lpwstr as _)?, lifetime: PhantomData }) + } + + pub fn peek(&self) -> Option { + // SAFETY: It's always safe to read the current item because we don't + // ever move out of the array's bounds. + unsafe { NonZeroU16::new(*self.lpwstr.as_ptr()) } + } + + /// Advance the iterator while `predicate` returns true. + /// Returns the number of items it advanced by. + pub fn advance_while bool>(&mut self, mut predicate: P) -> usize { + let mut counter = 0; + while let Some(w) = self.peek() { + if !predicate(w) { + break; + } + counter += 1; + self.next(); + } + counter + } +} + +impl Iterator for WStrUnits<'_> { + // This can never return zero as that marks the end of the string. + type Item = NonZeroU16; + fn next(&mut self) -> Option { + // SAFETY: If NULL is reached we immediately return. + // Therefore it's safe to advance the pointer after that. + unsafe { + let next = self.peek()?; + self.lpwstr = NonNull::new_unchecked(self.lpwstr.as_ptr().add(1)); + Some(next) + } + } +} diff --git a/sgx_tstd/src/sys_common/wtf8.rs b/sgx_tstd/src/sys_common/wtf8.rs index 6ad371b3f..a7ab1ba6f 100644 --- a/sgx_tstd/src/sys_common/wtf8.rs +++ b/sgx_tstd/src/sys_common/wtf8.rs @@ -32,7 +32,7 @@ // unix (it's mostly used on windows), so don't worry about dead code here. #![allow(dead_code)] -#![allow(clippy::derive_hash_xor_eq)] +#![allow(clippy::derived_hash_with_manual_eq)] #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/sys_common/wtf8/tests.rs b/sgx_tstd/src/sys_common/wtf8/tests.rs index 04de77086..7163439fb 100644 --- a/sgx_tstd/src/sys_common/wtf8/tests.rs +++ b/sgx_tstd/src/sys_common/wtf8/tests.rs @@ -536,7 +536,7 @@ fn wtf8_as_str() { assert_eq!(Wtf8::from_str("aé 💩").as_str(), Some("aé 💩")); let mut string = Wtf8Buf::new(); string.push(CodePoint::from_u32(0xD800).unwrap()); - assert_eq!(string.as_str(), None); + assert!(string.as_str().is_none()); } #[test_case] diff --git a/sgx_tstd/src/thread/local.rs b/sgx_tstd/src/thread/local.rs index 73196d1c7..dde3f9967 100644 --- a/sgx_tstd/src/thread/local.rs +++ b/sgx_tstd/src/thread/local.rs @@ -33,8 +33,8 @@ use crate::fmt; /// target platform. It is instantiated with the [`thread_local!`] macro and the /// primary method is the [`with`] method. /// -/// The [`with`] method yields a reference to the contained value which cannot be -/// sent across threads or escape the given closure. +/// The [`with`] method yields a reference to the contained value which cannot +/// outlive the current thread or escape the given closure. /// /// [`thread_local!`]: crate::thread_local /// @@ -44,9 +44,9 @@ use crate::fmt; /// within a thread, and values that implement [`Drop`] get destructed when a /// thread exits. Some caveats apply, which are explained below. /// -/// A `LocalKey`'s initializer cannot recursively depend on itself, and using -/// a `LocalKey` in this way will cause the initializer to infinitely recurse -/// on the first call to `with`. +/// A `LocalKey`'s initializer cannot recursively depend on itself. Using a +/// `LocalKey` in this way may cause panics, aborts or infinite recursion on +/// the first call to `with`. /// /// # Examples /// @@ -147,10 +147,28 @@ impl fmt::Debug for LocalKey { /// thread_local! { /// pub static FOO: RefCell = RefCell::new(1); /// -/// #[allow(unused)] /// static BAR: RefCell = RefCell::new(1.0); /// } -/// # fn main() {} +/// +/// FOO.with(|foo| assert_eq!(*foo.borrow(), 1)); +/// BAR.with(|bar| assert_eq!(*bar.borrow(), 1.0)); +/// ``` +/// +/// This macro supports a special `const {}` syntax that can be used +/// when the initialization expression can be evaluated as a constant. +/// This can enable a more efficient thread local implementation that +/// can avoid lazy initialization. For types that do not +/// [need to be dropped][crate::mem::needs_drop], this can enable an +/// even more efficient implementation that does not need to +/// track any additional state. +/// +/// ``` +/// use std::cell::Cell; +/// thread_local! { +/// pub static FOO: Cell = const { Cell::new(1) }; +/// } +/// +/// FOO.with(|foo| assert_eq!(foo.get(), 1)); /// ``` /// /// See [`LocalKey` documentation][`std::thread::LocalKey`] for more @@ -165,250 +183,26 @@ macro_rules! thread_local { () => {}; ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const { $init:expr }; $($rest:tt)*) => ( - $crate::__thread_local_inner!($(#[$attr])* $vis $name, $t, const $init); + $crate::thread::local_impl::thread_local_inner!($(#[$attr])* $vis $name, $t, const $init); $crate::thread_local!($($rest)*); ); ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const { $init:expr }) => ( - $crate::__thread_local_inner!($(#[$attr])* $vis $name, $t, const $init); + $crate::thread::local_impl::thread_local_inner!($(#[$attr])* $vis $name, $t, const $init); ); // process multiple declarations ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr; $($rest:tt)*) => ( - $crate::__thread_local_inner!($(#[$attr])* $vis $name, $t, $init); + $crate::thread::local_impl::thread_local_inner!($(#[$attr])* $vis $name, $t, $init); $crate::thread_local!($($rest)*); ); // handle a single declaration ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr) => ( - $crate::__thread_local_inner!($(#[$attr])* $vis $name, $t, $init); + $crate::thread::local_impl::thread_local_inner!($(#[$attr])* $vis $name, $t, $init); ); } -#[cfg(not(feature = "thread"))] -#[macro_export] -#[allow_internal_unstable(thread_local_internals, cfg_target_thread_local, thread_local)] -#[allow_internal_unsafe] -macro_rules! __thread_local_inner { - // used to generate the `LocalKey` value for const-initialized thread locals - (@key $t:ty, const $init:expr) => {{ - #[inline] // see comments below - unsafe fn __getit( - _init: $crate::option::Option<&mut $crate::option::Option<$t>>, - ) -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { - const INIT_EXPR: $t = $init; - - if !$crate::mem::needs_drop::<$t>() || $crate::thread::tcs_policy() == $crate::thread::TcsPolicy::Bind { - #[thread_local] - static mut VAL: $t = INIT_EXPR; - Ok(&VAL) - } else { - $crate::result::Result::Err($crate::thread::AccessError::new( - "If TLS data needs to be destructed, TCS policy must be bound." - )) - } - } - - unsafe { - $crate::thread::LocalKey::new(__getit) - } - }}; - - // used to generate the `LocalKey` value for `thread_local!` - (@key $t:ty, $init:expr) => { - { - #[inline] - fn __init() -> $t { $init } - - // When reading this function you might ask "why is this inlined - // everywhere other than Windows?", and that's a very reasonable - // question to ask. The short story is that it segfaults rustc if - // this function is inlined. The longer story is that Windows looks - // to not support `extern` references to thread locals across DLL - // boundaries. This appears to at least not be supported in the ABI - // that LLVM implements. - // - // Because of this we never inline on Windows, but we do inline on - // other platforms (where external references to thread locals - // across DLLs are supported). A better fix for this would be to - // inline this function on Windows, but only for "statically linked" - // components. For example if two separately compiled rlibs end up - // getting linked into a DLL then it's fine to inline this function - // across that boundary. It's only not fine to inline this function - // across a DLL boundary. Unfortunately rustc doesn't currently - // have this sort of logic available in an attribute, and it's not - // clear that rustc is even equipped to answer this (it's more of a - // Cargo question kinda). This means that, unfortunately, Windows - // gets the pessimistic path for now where it's never inlined. - // - // The issue of "should enable on Windows sometimes" is #84933 - #[inline] - unsafe fn __getit( - init: $crate::option::Option<&mut $crate::option::Option<$t>>, - ) -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { - #[thread_local] - static __KEY: $crate::thread::__StaticLocalKeyInner<$t> = - $crate::thread::__StaticLocalKeyInner::new(); - - // FIXME: remove the #[allow(...)] marker when macros don't - // raise warning for missing/extraneous unsafe blocks anymore. - // See https://github.com/rust-lang/rust/issues/74838. - #[allow(unused_unsafe)] - unsafe { - __KEY.get(move || { - if let $crate::option::Option::Some(init) = init { - if let $crate::option::Option::Some(value) = init.take() { - return value; - } else if $crate::cfg!(debug_assertions) { - $crate::unreachable!("missing default value"); - } - } - __init() - }) - } - } - - unsafe { - $crate::thread::LocalKey::new(__getit) - } - } - }; - ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $($init:tt)*) => { - $(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> = - $crate::__thread_local_inner!(@key $t, $($init)*); - } -} - -#[cfg(feature = "thread")] -#[macro_export] -#[allow_internal_unstable(thread_local_internals, cfg_target_thread_local, thread_local)] -#[allow_internal_unsafe] -macro_rules! __thread_local_inner { - // used to generate the `LocalKey` value for const-initialized thread locals - (@key $t:ty, const $init:expr) => {{ - #[inline] - unsafe fn __getit( - _init: $crate::option::Option<&mut $crate::option::Option<$t>>, - ) -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { - const INIT_EXPR: $t = $init; - - #[thread_local] - static mut VAL: $t = INIT_EXPR; - - // If a dtor isn't needed we can do something "very raw" and - // just get going. - if !$crate::mem::needs_drop::<$t>() { - return $crate::result::Result::Ok(&VAL) - } - - // 0 == dtor not registered - // 1 == dtor registered, dtor not run - // 2 == dtor registered and is running or has run - #[thread_local] - static mut STATE: $crate::primitive::u8 = 0; - - unsafe extern "C" fn destroy(ptr: *mut $crate::primitive::u8) { - let ptr = ptr as *mut $t; - - unsafe { - $crate::debug_assert_eq!(STATE, 1); - STATE = 2; - $crate::ptr::drop_in_place(ptr); - } - } - - match STATE { - // 0 == we haven't registered a destructor, so do - // so now. - 0 => { - $crate::thread::__FastLocalKeyInner::<$t>::register_dtor( - $crate::ptr::addr_of_mut!(VAL) as *mut $crate::primitive::u8, - destroy, - ); - STATE = 1; - $crate::result::Result::Ok(&VAL) - } - // 1 == the destructor is registered and the value - // is valid, so return the pointer. - 1 => $crate::result::Result::Ok(&VAL), - // otherwise the destructor has already run, so we - // can't give access. - _ => $crate::result::Result::Err($crate::thread::AccessError::new( - "The destructor has already run." - )), - } - } - - unsafe { - $crate::thread::LocalKey::new(__getit) - } - }}; - - // used to generate the `LocalKey` value for `thread_local!` - (@key $t:ty, $init:expr) => { - { - #[inline] - fn __init() -> $t { $init } - - // When reading this function you might ask "why is this inlined - // everywhere other than Windows?", and that's a very reasonable - // question to ask. The short story is that it segfaults rustc if - // this function is inlined. The longer story is that Windows looks - // to not support `extern` references to thread locals across DLL - // boundaries. This appears to at least not be supported in the ABI - // that LLVM implements. - // - // Because of this we never inline on Windows, but we do inline on - // other platforms (where external references to thread locals - // across DLLs are supported). A better fix for this would be to - // inline this function on Windows, but only for "statically linked" - // components. For example if two separately compiled rlibs end up - // getting linked into a DLL then it's fine to inline this function - // across that boundary. It's only not fine to inline this function - // across a DLL boundary. Unfortunately rustc doesn't currently - // have this sort of logic available in an attribute, and it's not - // clear that rustc is even equipped to answer this (it's more of a - // Cargo question kinda). This means that, unfortunately, Windows - // gets the pessimistic path for now where it's never inlined. - // - // The issue of "should enable on Windows sometimes" is #84933 - #[inline] - unsafe fn __getit( - init: $crate::option::Option<&mut $crate::option::Option<$t>>, - ) -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { - #[thread_local] - static __KEY: $crate::thread::__FastLocalKeyInner<$t> = - $crate::thread::__FastLocalKeyInner::new(); - - // FIXME: remove the #[allow(...)] marker when macros don't - // raise warning for missing/extraneous unsafe blocks anymore. - // See https://github.com/rust-lang/rust/issues/74838. - #[allow(unused_unsafe)] - unsafe { - __KEY.get(move || { - if let $crate::option::Option::Some(init) = init { - if let $crate::option::Option::Some(value) = init.take() { - return value; - } else if $crate::cfg!(debug_assertions) { - $crate::unreachable!("missing default value"); - } - } - __init() - }) - } - } - - unsafe { - $crate::thread::LocalKey::new(__getit) - } - } - }; - ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $($init:tt)*) => { - $(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> = - $crate::__thread_local_inner!(@key $t, $($init)*); - } -} - /// An error returned by [`LocalKey::try_with`](struct.LocalKey.html#method.try_with). #[derive(Debug)] pub struct AccessError { @@ -516,7 +310,6 @@ impl LocalKey> { /// # Examples /// /// ``` - /// #![feature(local_key_cell_methods)] /// use std::cell::Cell; /// /// thread_local! { @@ -553,7 +346,6 @@ impl LocalKey> { /// # Examples /// /// ``` - /// #![feature(local_key_cell_methods)] /// use std::cell::Cell; /// /// thread_local! { @@ -582,7 +374,6 @@ impl LocalKey> { /// # Examples /// /// ``` - /// #![feature(local_key_cell_methods)] /// use std::cell::Cell; /// /// thread_local! { @@ -612,7 +403,6 @@ impl LocalKey> { /// # Examples /// /// ``` - /// #![feature(local_key_cell_methods)] /// use std::cell::Cell; /// /// thread_local! { @@ -643,7 +433,6 @@ impl LocalKey> { /// # Example /// /// ``` - /// #![feature(local_key_cell_methods)] /// use std::cell::RefCell; /// /// thread_local! { @@ -674,7 +463,6 @@ impl LocalKey> { /// # Example /// /// ``` - /// #![feature(local_key_cell_methods)] /// use std::cell::RefCell; /// /// thread_local! { @@ -708,7 +496,6 @@ impl LocalKey> { /// # Examples /// /// ``` - /// #![feature(local_key_cell_methods)] /// use std::cell::RefCell; /// /// thread_local! { @@ -747,7 +534,6 @@ impl LocalKey> { /// # Examples /// /// ``` - /// #![feature(local_key_cell_methods)] /// use std::cell::RefCell; /// /// thread_local! { @@ -781,7 +567,6 @@ impl LocalKey> { /// # Examples /// /// ``` - /// #![feature(local_key_cell_methods)] /// use std::cell::RefCell; /// /// thread_local! { @@ -797,358 +582,3 @@ impl LocalKey> { self.with(|cell| cell.replace(value)) } } - -mod lazy { - use crate::cell::UnsafeCell; - use crate::hint; - use crate::mem; - - pub struct LazyKeyInner { - inner: UnsafeCell>, - } - - impl LazyKeyInner { - pub const fn new() -> LazyKeyInner { - LazyKeyInner { inner: UnsafeCell::new(None) } - } - - pub unsafe fn get(&self) -> Option<&'static T> { - // SAFETY: The caller must ensure no reference is ever handed out to - // the inner cell nor mutable reference to the Option inside said - // cell. This make it safe to hand a reference, though the lifetime - // of 'static is itself unsafe, making the get method unsafe. - (*self.inner.get()).as_ref() - } - - /// The caller must ensure that no reference is active: this method - /// needs unique access. - pub unsafe fn initialize T>(&self, init: F) -> &'static T { - // Execute the initialization up front, *then* move it into our slot, - // just in case initialization fails. - let value = init(); - let ptr = self.inner.get(); - - // SAFETY: - // - // note that this can in theory just be `*ptr = Some(value)`, but due to - // the compiler will currently codegen that pattern with something like: - // - // ptr::drop_in_place(ptr) - // ptr::write(ptr, Some(value)) - // - // Due to this pattern it's possible for the destructor of the value in - // `ptr` (e.g., if this is being recursively initialized) to re-access - // TLS, in which case there will be a `&` and `&mut` pointer to the same - // value (an aliasing violation). To avoid setting the "I'm running a - // destructor" flag we just use `mem::replace` which should sequence the - // operations a little differently and make this safe to call. - // - // The precondition also ensures that we are the only one accessing - // `self` at the moment so replacing is fine. - let _ = mem::replace(&mut *ptr, Some(value)); - - // SAFETY: With the call to `mem::replace` it is guaranteed there is - // a `Some` behind `ptr`, not a `None` so `unreachable_unchecked` - // will never be reached. - // After storing `Some` we want to get a reference to the contents of - // what we just stored. While we could use `unwrap` here and it should - // always work it empirically doesn't seem to always get optimized away, - // which means that using something like `try_with` can pull in - // panicking code and cause a large size bloat. - match *ptr { - Some(ref x) => x, - None => hint::unreachable_unchecked(), - } - } - - /// The other methods hand out references while taking &self. - /// As such, callers of this method must ensure no `&` and `&mut` are - /// available and used at the same time. - #[allow(unused)] - pub unsafe fn take(&mut self) -> Option { - // SAFETY: See doc comment for this method. - (*self.inner.get()).take() - } - } -} - -pub mod statik { - use super::lazy::LazyKeyInner; - use super::AccessError; - use crate::fmt; - use crate::mem; - - use sgx_trts::tcs::{self, TcsPolicy}; - - pub struct Key { - inner: LazyKeyInner, - } - - unsafe impl Sync for Key {} - - impl fmt::Debug for Key { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Key").finish_non_exhaustive() - } - } - - impl Key { - pub const fn new() -> Key { - Key { inner: LazyKeyInner::new() } - } - - pub unsafe fn get(&self, init: impl FnOnce() -> T) -> Result<&'static T, AccessError> { - if !mem::needs_drop::() || tcs::tcs_policy() == TcsPolicy::Bind { - // SAFETY: The caller must ensure no reference is ever handed out to - // the inner cell nor mutable reference to the Option inside said - // cell. This make it safe to hand a reference, though the lifetime - // of 'static is itself unsafe, making the get method unsafe. - let value = match self.inner.get() { - Some(value) => value, - None => self.inner.initialize(init), - }; - Ok(value) - } else { - Err(AccessError::new( - "If TLS data needs to be destructed, TCS policy must be bound." - )) - } - } - } -} - -#[cfg(feature = "thread")] -pub mod fast { - use super::lazy::LazyKeyInner; - use super::AccessError; - use crate::cell::Cell; - use crate::fmt; - use crate::mem; - use crate::sys::thread_local_dtor::register_dtor; - - #[derive(Copy, Clone)] - enum DtorState { - Unregistered, - Registered, - RunningOrHasRun, - } - - // This data structure has been carefully constructed so that the fast path - // only contains one branch on x86. That optimization is necessary to avoid - // duplicated tls lookups on OSX. - // - // LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722 - pub struct Key { - // If `LazyKeyInner::get` returns `None`, that indicates either: - // * The value has never been initialized - // * The value is being recursively initialized - // * The value has already been destroyed or is being destroyed - // To determine which kind of `None`, check `dtor_state`. - // - // This is very optimizer friendly for the fast path - initialized but - // not yet dropped. - inner: LazyKeyInner, - - // Metadata to keep track of the state of the destructor. Remember that - // this variable is thread-local, not global. - dtor_state: Cell, - } - - impl fmt::Debug for Key { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Key").finish_non_exhaustive() - } - } - - impl Key { - pub const fn new() -> Key { - Key { inner: LazyKeyInner::new(), dtor_state: Cell::new(DtorState::Unregistered) } - } - - // note that this is just a publicly-callable function only for the - // const-initialized form of thread locals, basically a way to call the - // free `register_dtor` function defined elsewhere in libstd. - pub unsafe fn register_dtor(a: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { - register_dtor(a, dtor); - } - - pub unsafe fn get T>(&self, init: F) -> Result<&'static T, AccessError> { - // SAFETY: See the definitions of `LazyKeyInner::get` and - // `try_initialize` for more information. - // - // The caller must ensure no mutable references are ever active to - // the inner cell or the inner T when this is called. - // The `try_initialize` is dependant on the passed `init` function - // for this. - match self.inner.get() { - Some(val) => Ok(val), - None => self.try_initialize(init), - } - } - - // `try_initialize` is only called once per fast thread local variable, - // except in corner cases where thread_local dtors reference other - // thread_local's, or it is being recursively initialized. - // - // Macos: Inlining this function can cause two `tlv_get_addr` calls to - // be performed for every call to `Key::get`. - // LLVM issue: https://bugs.llvm.org/show_bug.cgi?id=41722 - #[inline(never)] - unsafe fn try_initialize T>(&self, init: F) -> Result<&'static T, AccessError> { - // SAFETY: See comment above (this function doc). - if !mem::needs_drop::() || self.try_register_dtor() { - // SAFETY: See comment above (his function doc). - Ok(self.inner.initialize(init)) - } else { - Err(AccessError::new("Failed to register destructor.")) - } - } - - // `try_register_dtor` is only called once per fast thread local - // variable, except in corner cases where thread_local dtors reference - // other thread_local's, or it is being recursively initialized. - unsafe fn try_register_dtor(&self) -> bool { - match self.dtor_state.get() { - DtorState::Unregistered => { - // SAFETY: dtor registration happens before initialization. - // Passing `self` as a pointer while using `destroy_value` - // is safe because the function will build a pointer to a - // Key, which is the type of self and so find the correct - // size. - register_dtor(self as *const _ as *mut u8, destroy_value::); - self.dtor_state.set(DtorState::Registered); - true - } - DtorState::Registered => { - // recursively initialized - true - } - DtorState::RunningOrHasRun => false, - } - } - } - - unsafe extern "C" fn destroy_value(ptr: *mut u8) { - let ptr = ptr as *mut Key; - - // SAFETY: - // - // The pointer `ptr` has been built just above and comes from - // `try_register_dtor` where it is originally a Key coming from `self`, - // making it non-NUL and of the correct type. - // - // Right before we run the user destructor be sure to set the - // `Option` to `None`, and `dtor_state` to `RunningOrHasRun`. This - // causes future calls to `get` to run `try_initialize_drop` again, - // which will now fail, and return `None`. - let value = (*ptr).inner.take(); - (*ptr).dtor_state.set(DtorState::RunningOrHasRun); - drop(value); - } -} - -#[cfg(feature = "thread")] -pub mod os { - use super::lazy::LazyKeyInner; - use super::AccessError; - use crate::cell::Cell; - use crate::fmt; - use crate::marker; - use crate::ptr; - use crate::sys_common::thread_local_key::StaticKey as OsStaticKey; - - /// Use a regular global static to store this key; the state provided will then be - /// thread-local. - pub struct Key { - // OS-TLS key that we'll use to key off. - os: OsStaticKey, - marker: marker::PhantomData>, - } - - impl fmt::Debug for Key { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Key").finish_non_exhaustive() - } - } - - unsafe impl Sync for Key {} - - struct Value { - inner: LazyKeyInner, - key: &'static Key, - } - - impl Key { - // Note: - // 1. os::Key can be destructed normally when used for threads created by `pthread_create`. - // 2. os::Key used in untrusted thread, the destructor will not be called. - pub const fn new() -> Key { - Key { os: OsStaticKey::new(Some(destroy_value::)), marker: marker::PhantomData } - } - - /// It is a requirement for the caller to ensure that no mutable - /// reference is active when this method is called. - pub unsafe fn get(&'static self, init: impl FnOnce() -> T) -> Result<&'static T, AccessError> { - // SAFETY: See the documentation for this method. - let ptr = self.os.get() as *mut Value; - if ptr.addr() > 1 { - // SAFETY: the check ensured the pointer is safe (its destructor - // is not running) + it is coming from a trusted source (self). - if let Some(ref value) = (*ptr).inner.get() { - return Ok(value); - } - } - // SAFETY: At this point we are sure we have no value and so - // initializing (or trying to) is safe. - self.try_initialize(init) - } - - // `try_initialize` is only called once per os thread local variable, - // except in corner cases where thread_local dtors reference other - // thread_local's, or it is being recursively initialized. - unsafe fn try_initialize(&'static self, init: impl FnOnce() -> T) -> Result<&'static T, AccessError> { - // SAFETY: No mutable references are ever handed out meaning getting - // the value is ok. - let ptr = self.os.get() as *mut Value; - if ptr.addr() == 1 { - // destructor is running - return Err(AccessError::new("The destructor has already run.")); - } - - let ptr = if ptr.is_null() { - // If the lookup returned null, we haven't initialized our own - // local copy, so do that now. - let ptr: Box> = box Value { inner: LazyKeyInner::new(), key: self }; - let ptr = Box::into_raw(ptr); - // SAFETY: At this point we are sure there is no value inside - // ptr so setting it will not affect anyone else. - self.os.set(ptr as *mut u8); - ptr - } else { - // recursive initialization - ptr - }; - - // SAFETY: ptr has been ensured as non-NUL just above an so can be - // dereferenced safely. - Ok((*ptr).inner.initialize(init)) - } - } - - unsafe extern "C" fn destroy_value(ptr: *mut u8) { - // SAFETY: - // - // The OS TLS ensures that this key contains a null value when this - // destructor starts to run. We set it back to a sentinel value of 1 to - // ensure that any future calls to `get` for this thread will return - // `None`. - // - // Note that to prevent an infinite loop we reset it back to null right - // before we return from the destructor ourselves. - let ptr = Box::from_raw(ptr as *mut Value); - let key = ptr.key; - key.os.set(ptr::invalid_mut(1)); - drop(ptr); - key.os.set(ptr::null_mut()); - } -} diff --git a/sgx_tstd/src/thread/local/tests.rs b/sgx_tstd/src/thread/local/tests.rs index 0aeff814e..5d08d053f 100644 --- a/sgx_tstd/src/thread/local/tests.rs +++ b/sgx_tstd/src/thread/local/tests.rs @@ -17,18 +17,37 @@ use crate::cell::{Cell, UnsafeCell}; use crate::sync::atomic::{AtomicU8, Ordering}; -use crate::sync::mpsc::{channel, Sender}; +use crate::sync::{Arc, Condvar, Mutex}; use crate::thread::{self, LocalKey}; use crate::thread_local; use sgx_test_utils::test_case; -struct Foo(Sender<()>); +#[derive(Clone, Default)] +struct Signal(Arc<(Mutex, Condvar)>); -impl Drop for Foo { +impl Signal { + fn notify(&self) { + let (set, cvar) = &*self.0; + *set.lock().unwrap() = true; + cvar.notify_one(); + } + + fn wait(&self) { + let (set, cvar) = &*self.0; + let mut set = set.lock().unwrap(); + while !*set { + set = cvar.wait(set).unwrap(); + } + } +} + +struct NotifyOnDrop(Signal); + +impl Drop for NotifyOnDrop { fn drop(&mut self) { - let Foo(ref s) = *self; - s.send(()).unwrap(); + let NotifyOnDrop(ref f) = *self; + f.notify(); } } @@ -82,20 +101,21 @@ fn states() { #[test_case] fn smoke_dtor() { - thread_local!(static FOO: UnsafeCell> = UnsafeCell::new(None)); + thread_local!(static FOO: UnsafeCell> = UnsafeCell::new(None)); run(&FOO); - thread_local!(static FOO2: UnsafeCell> = const { UnsafeCell::new(None) }); + thread_local!(static FOO2: UnsafeCell> = const { UnsafeCell::new(None) }); run(&FOO2); - fn run(key: &'static LocalKey>>) { - let (tx, rx) = channel(); + fn run(key: &'static LocalKey>>) { + let signal = Signal::default(); + let signal2 = signal.clone(); let t = thread::spawn(move || unsafe { - let mut tx = Some(tx); + let mut signal = Some(signal2); key.with(|f| { - *f.get() = Some(Foo(tx.take().unwrap())); + *f.get() = Some(NotifyOnDrop(signal.take().unwrap())); }); }); - rx.recv().unwrap(); + signal.wait(); t.join().unwrap(); } } @@ -185,48 +205,50 @@ fn self_referential() { // requires the destructor to be run to pass the test). #[test_case] fn dtors_in_dtors_in_dtors() { - struct S1(Sender<()>); + struct S1(Signal); thread_local!(static K1: UnsafeCell> = UnsafeCell::new(None)); - thread_local!(static K2: UnsafeCell> = UnsafeCell::new(None)); + thread_local!(static K2: UnsafeCell> = UnsafeCell::new(None)); impl Drop for S1 { fn drop(&mut self) { - let S1(ref tx) = *self; + let S1(ref signal) = *self; unsafe { - let _ = K2.try_with(|s| *s.get() = Some(Foo(tx.clone()))); + let _ = K2.try_with(|s| *s.get() = Some(NotifyOnDrop(signal.clone()))); } } } - let (tx, rx) = channel(); + let signal = Signal::default(); + let signal2 = signal.clone(); let _t = thread::spawn(move || unsafe { - let mut tx = Some(tx); - K1.with(|s| *s.get() = Some(S1(tx.take().unwrap()))); + let mut signal = Some(signal2); + K1.with(|s| *s.get() = Some(S1(signal.take().unwrap()))); }); - rx.recv().unwrap(); + signal.wait(); } #[test_case] fn dtors_in_dtors_in_dtors_const_init() { - struct S1(Sender<()>); + struct S1(Signal); thread_local!(static K1: UnsafeCell> = const { UnsafeCell::new(None) }); - thread_local!(static K2: UnsafeCell> = const { UnsafeCell::new(None) }); + thread_local!(static K2: UnsafeCell> = const { UnsafeCell::new(None) }); impl Drop for S1 { fn drop(&mut self) { - let S1(ref tx) = *self; + let S1(ref signal) = *self; unsafe { - let _ = K2.try_with(|s| *s.get() = Some(Foo(tx.clone()))); + let _ = K2.try_with(|s| *s.get() = Some(NotifyOnDrop(signal.clone()))); } } } - let (tx, rx) = channel(); + let signal = Signal::default(); + let signal2 = signal.clone(); let _t = thread::spawn(move || unsafe { - let mut tx = Some(tx); - K1.with(|s| *s.get() = Some(S1(tx.take().unwrap()))); + let mut signal = Some(signal2); + K1.with(|s| *s.get() = Some(S1(signal.take().unwrap()))); }); - rx.recv().unwrap(); + signal.wait(); } // This test tests that TLS destructors have run before the thread joins. The diff --git a/sgx_tstd/src/thread/mod.rs b/sgx_tstd/src/thread/mod.rs index b2f23cbe4..47babe3d0 100644 --- a/sgx_tstd/src/thread/mod.rs +++ b/sgx_tstd/src/thread/mod.rs @@ -139,10 +139,6 @@ //! * The thread name is provided to the OS where applicable (e.g., `pthread_setname_np` in //! unix-like platforms). //! -//! * Build the thread with [`Builder`] and pass the desired stack size to [`Builder::stack_size`]. -//! * Set the `RUST_MIN_STACK` environment variable to an integer representing the desired stack -//! size (in bytes). Note that setting [`Builder::stack_size`] will override this. -//! //! Note that the stack size of the main thread is *not* determined by Rust. //! //! [channels]: crate::sync::mpsc @@ -187,13 +183,23 @@ use crate::sync::Arc; #[cfg(feature = "thread")] use crate::sys::thread as imp; use crate::sys_common::thread_info; -use crate::sys_common::thread_parker::Parker; +use crate::sys_common::thread_parking::Parker; #[cfg(feature = "thread")] use crate::sys_common::{AsInner, IntoInner}; use crate::time::Duration; +#[cfg(feature = "thread")] +use crate::time::Instant; +#[cfg(all(feature = "thread", not(feature = "untrusted_time")))] +use crate::untrusted::time::InstantEx; pub use sgx_trts::tcs::TcsPolicy; +#[cfg(feature = "thread")] +mod scoped; + +#[cfg(feature = "thread")] +pub use scoped::{scope, Scope, ScopedJoinHandle}; + //////////////////////////////////////////////////////////////////////////////// // Thread-local storage //////////////////////////////////////////////////////////////////////////////// @@ -201,26 +207,13 @@ pub use sgx_trts::tcs::TcsPolicy; #[macro_use] mod local; -#[cfg(feature = "thread")] -mod scoped; - -#[cfg(feature = "thread")] -pub use scoped::{scope, Scope, ScopedJoinHandle}; - pub use self::local::{AccessError, LocalKey}; -// Select the type used by the thread_local! macro to access TLS keys. There -// are three types: "static", "fast", "OS". The "OS" thread local key -// type is accessed via platform-specific API calls and is slow, while the "fast" -// key type is accessed via code generated via LLVM, where TLS keys are set up -// by the elf linker. "static" is for single-threaded platforms where a global -// static is sufficient. - -#[cfg(feature = "thread")] -pub use self::local::fast::Key as __FastLocalKeyInner; -#[cfg(feature = "thread")] -pub use self::local::os::Key as __OsLocalKeyInner; -pub use self::local::statik::Key as __StaticLocalKeyInner; +// Implementation details used by the thread_local!{} macro. +#[doc(hidden)] +pub mod local_impl { + pub use crate::sys::common::thread_local::{thread_local_inner, Key, abort_on_dtor_unwind}; +} //////////////////////////////////////////////////////////////////////////////// // Builder @@ -486,7 +479,7 @@ impl Builder { MaybeDangling(mem::MaybeUninit::new(x)) } fn into_inner(self) -> T { - // SAFETY: we are always initiailized. + // SAFETY: we are always initialized. let ret = unsafe { self.0.assume_init_read() }; // Make sure we don't drop. mem::forget(self); @@ -495,7 +488,7 @@ impl Builder { } impl Drop for MaybeDangling { fn drop(&mut self) { - // SAFETY: we are always initiailized. + // SAFETY: we are always initialized. unsafe { self.0.assume_init_drop() }; } } @@ -514,7 +507,7 @@ impl Builder { // SAFETY: the stack guard passed is the one for the current thread. // This means the current thread's stack and the new thread's stack // are properly set and protected from each other. - thread_info::set(their_thread); + thread_info::set(thread_info::guard::current(), their_thread); #[cfg(feature = "backtrace")] let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| { crate::sys_common::backtrace::__rust_begin_short_backtrace(f) @@ -538,6 +531,11 @@ impl Builder { scope_data.increment_num_running_threads(); } + let main = Box::new(main); + // SAFETY: dynamic size and alignment of the Box remain the same. See below for why the + // lifetime change is justified. + let main = unsafe { Box::from_raw(Box::into_raw(main) as *mut (dyn FnOnce() + 'static)) }; + Ok(JoinInner { // SAFETY: // @@ -552,11 +550,7 @@ impl Builder { // Similarly, the `sys` implementation must guarantee that no references to the closure // exist after the thread has terminated, which is signaled by `Thread::join` // returning. - native: imp::Thread::new( - mem::transmute::, Box>( - Box::new(main), - ), - )?, + native: unsafe { imp::Thread::new(main)? }, thread: my_thread, packet: my_packet, }) @@ -858,6 +852,86 @@ pub fn sleep(dur: Duration) { imp::Thread::sleep(dur) } +/// Puts the current thread to sleep until the specified deadline has passed. +/// +/// The thread may still be asleep after the deadline specified due to +/// scheduling specifics or platform-dependent functionality. It will never +/// wake before. +/// +/// This function is blocking, and should not be used in `async` functions. +/// +/// # Platform-specific behavior +/// +/// This function uses [`sleep`] internally, see its platform-specific behaviour. +/// +/// +/// # Examples +/// +/// A simple game loop that limits the game to 60 frames per second. +/// +/// ```no_run +/// #![feature(thread_sleep_until)] +/// # use std::time::{Duration, Instant}; +/// # use std::thread; +/// # +/// # fn update() {} +/// # fn render() {} +/// # +/// let max_fps = 60.0; +/// let frame_time = Duration::from_secs_f32(1.0/max_fps); +/// let mut next_frame = Instant::now(); +/// loop { +/// thread::sleep_until(next_frame); +/// next_frame += frame_time; +/// update(); +/// render(); +/// } +/// ``` +/// +/// A slow api we must not call too fast and which takes a few +/// tries before succeeding. By using `sleep_until` the time the +/// api call takes does not influence when we retry or when we give up +/// +/// ```no_run +/// #![feature(thread_sleep_until)] +/// # use std::time::{Duration, Instant}; +/// # use std::thread; +/// # +/// # enum Status { +/// # Ready(usize), +/// # Waiting, +/// # } +/// # fn slow_web_api_call() -> Status { Status::Ready(42) } +/// # +/// # const MAX_DURATION: Duration = Duration::from_secs(10); +/// # +/// # fn try_api_call() -> Result { +/// let deadline = Instant::now() + MAX_DURATION; +/// let delay = Duration::from_millis(250); +/// let mut next_attempt = Instant::now(); +/// loop { +/// if Instant::now() > deadline { +/// break Err(()); +/// } +/// if let Status::Ready(data) = slow_web_api_call() { +/// break Ok(data); +/// } +/// +/// next_attempt = deadline.min(next_attempt + delay); +/// thread::sleep_until(next_attempt); +/// } +/// # } +/// # let _data = try_api_call(); +/// ``` +#[cfg(feature = "thread")] +pub fn sleep_until(deadline: Instant) { + let now = Instant::now(); + + if let Some(delay) = deadline.checked_duration_since(now) { + sleep(delay); + } +} + /// Used to ensure that `park` and `park_timeout` do not unwind, as that can /// cause undefined behaviour if not handled correctly (see #102398 for context). struct PanicGuard; @@ -875,7 +949,7 @@ impl Drop for PanicGuard { /// it is guaranteed that this function will not panic (it may abort the /// process if the implementation encounters some rare errors). /// -/// # park and unpark +/// # `park` and `unpark` /// /// Every thread is equipped with some basic low-level blocking support, via the /// [`thread::park`][`park`] function and [`thread::Thread::unpark`][`unpark`] @@ -896,14 +970,6 @@ impl Drop for PanicGuard { /// if it wasn't already. Because the token is initially absent, [`unpark`] /// followed by [`park`] will result in the second call returning immediately. /// -/// In other words, each [`Thread`] acts a bit like a spinlock that can be -/// locked and unlocked using `park` and `unpark`. -/// -/// Notice that being unblocked does not imply any synchronization with someone -/// that unparked this thread, it could also be spurious. -/// For example, it would be a valid, but inefficient, implementation to make both [`park`] and -/// [`unpark`] return immediately without doing anything. -/// /// The API is typically used by acquiring a handle to the current thread, /// placing that handle in a shared data structure so that other threads can /// find it, and then `park`ing in a loop. When some desired condition is met, another @@ -917,6 +983,23 @@ impl Drop for PanicGuard { /// /// * It can be implemented very efficiently on many platforms. /// +/// # Memory Ordering +/// +/// Calls to `park` _synchronize-with_ calls to `unpark`, meaning that memory +/// operations performed before a call to `unpark` are made visible to the thread that +/// consumes the token and returns from `park`. Note that all `park` and `unpark` +/// operations for a given thread form a total order and `park` synchronizes-with +/// _all_ prior `unpark` operations. +/// +/// In atomic ordering terms, `unpark` performs a `Release` operation and `park` +/// performs the corresponding `Acquire` operation. Calls to `unpark` for the same +/// thread form a [release sequence]. +/// +/// Note that being unblocked does not imply a call was made to `unpark`, because +/// wakeups can also be spurious. For example, a valid, but inefficient, +/// implementation could have `park` and `unpark` return immediately without doing anything, +/// making *all* wakeups spurious. +/// /// # Examples /// /// ``` @@ -930,7 +1013,7 @@ impl Drop for PanicGuard { /// let parked_thread = thread::spawn(move || { /// // We want to wait until the flag is set. We *could* just spin, but using /// // park/unpark is more efficient. -/// while !flag2.load(Ordering::Acquire) { +/// while !flag2.load(Ordering::Relaxed) { /// println!("Parking thread"); /// thread::park(); /// // We *could* get here spuriously, i.e., way before the 10ms below are over! @@ -947,7 +1030,7 @@ impl Drop for PanicGuard { /// // There is no race condition here, if `unpark` /// // happens first, `park` will return immediately. /// // Hence there is no risk of a deadlock. -/// flag.store(true, Ordering::Release); +/// flag.store(true, Ordering::Relaxed); /// println!("Unpark the thread"); /// parked_thread.thread().unpark(); /// @@ -956,6 +1039,7 @@ impl Drop for PanicGuard { /// /// [`unpark`]: Thread::unpark /// [`thread::park_timeout`]: park_timeout +/// [release sequence]: https://en.cppreference.com/w/cpp/atomic/memory_order#Release_sequence pub fn park() { let guard = PanicGuard; // SAFETY: park_timeout is called on the parker owned by this thread. @@ -1174,7 +1258,7 @@ impl Thread { let ptr = Arc::get_mut_unchecked(&mut arc).as_mut_ptr(); addr_of_mut!((*ptr).name).write(name); addr_of_mut!((*ptr).id).write(ThreadId::new()); - Parker::new(addr_of_mut!((*ptr).parker)); + Parker::new_in_place(addr_of_mut!((*ptr).parker)); Pin::new_unchecked(arc.assume_init()) }; diff --git a/sgx_tstd/src/thread/scoped.rs b/sgx_tstd/src/thread/scoped.rs index f20156641..dc37a8103 100644 --- a/sgx_tstd/src/thread/scoped.rs +++ b/sgx_tstd/src/thread/scoped.rs @@ -61,7 +61,7 @@ impl ScopeData { // We check for 'overflow' with usize::MAX / 2, to make sure there's no // chance it overflows to 0, which would result in unsoundness. if self.num_running_threads.fetch_add(1, Ordering::Relaxed) > usize::MAX / 2 { - // This can only reasonably happen by mem::forget()'ing many many ScopedJoinHandles. + // This can only reasonably happen by mem::forget()'ing a lot of ScopedJoinHandles. self.decrement_num_running_threads(false); panic!("too many running threads in thread scope"); } diff --git a/sgx_tstd/src/thread/tests.rs b/sgx_tstd/src/thread/tests.rs index b28fd879b..8daa20f5c 100644 --- a/sgx_tstd/src/thread/tests.rs +++ b/sgx_tstd/src/thread/tests.rs @@ -292,12 +292,15 @@ fn test_scoped_threads_drop_result_before_join() { } #[test_case] -#[allow(clippy::drop_ref)] +#[allow(dropping_references)] +#[allow(clippy::match_single_binding)] fn test_scoped_threads_nll() { // this is mostly a *compilation test* for this exact function: fn foo(x: &u8) { thread::scope(|s| { - s.spawn(|| drop(x)); + s.spawn(|| match x { + _ => (), + }); }); } // let's also run it for good measure diff --git a/sgx_tstd/src/time.rs b/sgx_tstd/src/time.rs index 229347316..a09b50240 100644 --- a/sgx_tstd/src/time.rs +++ b/sgx_tstd/src/time.rs @@ -17,7 +17,7 @@ //! Temporal quantification. //! -//! # Examples: +//! # Examples //! //! There are multiple ways to create a new [`Duration`]: //! @@ -59,7 +59,7 @@ use crate::sys_common::{FromInner, IntoInner}; pub use core::time::Duration; -pub use core::time::FromFloatSecsError; +pub use core::time::TryFromFloatSecsError; /// A measurement of a monotonically nondecreasing clock. /// Opaque and useful only with [`Duration`]. @@ -73,6 +73,8 @@ pub use core::time::FromFloatSecsError; /// some seconds may be longer than others). An instant may jump forwards or /// experience time dilation (slow down or speed up), but it will never go /// backwards. +/// As part of this non-guarantee it is also not specified whether system suspends count as +/// elapsed time or not. The behavior varies across platforms and rust versions. /// /// Instants are opaque types that can only be compared to one another. There is /// no method to get "the number of seconds" from an instant. Instead, it only @@ -124,7 +126,7 @@ pub use core::time::FromFloatSecsError; /// |-----------|----------------------------------------------------------------------| /// | SGX | [`insecure_time` usercall]. More information on [timekeeping in SGX] | /// | UNIX | [clock_gettime (Monotonic Clock)] | -/// | Darwin | [mach_absolute_time] | +/// | Darwin | [clock_gettime (Monotonic Clock)] | /// | VXWorks | [clock_gettime (Monotonic Clock)] | /// | SOLID | `get_tim` | /// | WASI | [__wasi_clock_time_get (Monotonic Clock)] | @@ -134,9 +136,8 @@ pub use core::time::FromFloatSecsError; /// [QueryPerformanceCounter]: https://docs.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter /// [`insecure_time` usercall]: https://edp.fortanix.com/docs/api/fortanix_sgx_abi/struct.Usercalls.html#method.insecure_time /// [timekeeping in SGX]: https://edp.fortanix.com/docs/concepts/rust-std/#codestdtimecode -/// [__wasi_clock_time_get (Monotonic Clock)]: https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/docs.md#clock_time_get +/// [__wasi_clock_time_get (Monotonic Clock)]: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#clock_time_get /// [clock_gettime (Monotonic Clock)]: https://linux.die.net/man/3/clock_gettime -/// [mach_absolute_time]: https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/services/services.html /// /// **Disclaimer:** These system calls might change over time. /// @@ -190,6 +191,14 @@ pub struct Instant(time::Instant); /// The size of a `SystemTime` struct may vary depending on the target operating /// system. /// +/// A `SystemTime` does not count leap seconds. +/// `SystemTime::now()`'s behaviour around a leap second +/// is the same as the operating system's wall clock. +/// The precise behaviour near a leap second +/// (e.g. whether the clock appears to run slow or fast, or stop, or jump) +/// depends on platform and configuration, +/// so should not be relied on. +/// /// Example: /// /// ```no_run @@ -228,7 +237,7 @@ pub struct Instant(time::Instant); /// |-----------|----------------------------------------------------------------------| /// | SGX | [`insecure_time` usercall]. More information on [timekeeping in SGX] | /// | UNIX | [clock_gettime (Realtime Clock)] | -/// | Darwin | [gettimeofday] | +/// | Darwin | [clock_gettime (Realtime Clock)] | /// | VXWorks | [clock_gettime (Realtime Clock)] | /// | SOLID | `SOLID_RTC_ReadTime` | /// | WASI | [__wasi_clock_time_get (Realtime Clock)] | @@ -239,7 +248,7 @@ pub struct Instant(time::Instant); /// [timekeeping in SGX]: https://edp.fortanix.com/docs/concepts/rust-std/#codestdtimecode /// [gettimeofday]: https://man7.org/linux/man-pages/man2/gettimeofday.2.html /// [clock_gettime (Realtime Clock)]: https://linux.die.net/man/3/clock_gettime -/// [__wasi_clock_time_get (Realtime Clock)]: https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/docs.md#clock_time_get +/// [__wasi_clock_time_get (Realtime Clock)]: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#clock_time_get /// [GetSystemTimePreciseAsFileTime]: https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimepreciseasfiletime /// [GetSystemTimeAsFileTime]: https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimeasfiletime /// @@ -371,7 +380,7 @@ impl Instant { self.checked_duration_since(earlier).unwrap_or_default() } - /// Returns the amount of time elapsed since this instant was created. + /// Returns the amount of time elapsed since this instant. /// /// # Panics /// @@ -473,6 +482,9 @@ impl fmt::Debug for Instant { impl SystemTime { /// An anchor in time which can be used to create new `SystemTime` instances or /// learn about where in time a `SystemTime` lies. + // + // NOTE! this documentation is duplicated, here and in std::time::UNIX_EPOCH. + // The two copies are not quite identical, because of the difference in naming. /// /// This constant is defined to be "1970-01-01 00:00:00 UTC" on all systems with /// respect to the system clock. Using `duration_since` on an existing @@ -480,6 +492,11 @@ impl SystemTime { /// measurement lies, and using `UNIX_EPOCH + duration` can be used to create a /// `SystemTime` instance to represent another fixed point in time. /// + /// `duration_since(UNIX_EPOCH).unwrap().as_secs()` returns + /// the number of non-leap seconds since the start of 1970 UTC. + /// This is a POSIX `time_t` (as a `u64`), + /// and is the same time representation as used in many Internet protocols. + /// /// # Examples /// /// ```no_run @@ -542,8 +559,8 @@ impl SystemTime { self.0.sub_time(&earlier.0).map_err(SystemTimeError) } - /// Returns the difference between the clock time when this - /// system time was created, and the current clock time. + /// Returns the difference from this system time to the + /// current clock time. /// /// This function may fail as the underlying system clock is susceptible to /// drift and updates (e.g., the system clock could go backwards), so this @@ -628,6 +645,9 @@ impl fmt::Debug for SystemTime { /// An anchor in time which can be used to create new `SystemTime` instances or /// learn about where in time a `SystemTime` lies. +// +// NOTE! this documentation is duplicated, here and in SystemTime::UNIX_EPOCH. +// The two copies are not quite identical, because of the difference in naming. /// /// This constant is defined to be "1970-01-01 00:00:00 UTC" on all systems with /// respect to the system clock. Using `duration_since` on an existing @@ -635,6 +655,11 @@ impl fmt::Debug for SystemTime { /// measurement lies, and using `UNIX_EPOCH + duration` can be used to create a /// [`SystemTime`] instance to represent another fixed point in time. /// +/// `duration_since(UNIX_EPOCH).unwrap().as_secs()` returns +/// the number of non-leap seconds since the start of 1970 UTC. +/// This is a POSIX `time_t` (as a `u64`), +/// and is the same time representation as used in many Internet protocols. +/// /// # Examples /// /// ```no_run diff --git a/sgx_tstd/src/time/tests.rs b/sgx_tstd/src/time/tests.rs index c514e4d54..31fc23917 100644 --- a/sgx_tstd/src/time/tests.rs +++ b/sgx_tstd/src/time/tests.rs @@ -16,7 +16,7 @@ // under the License.. use super::{Duration, Instant, SystemTime, UNIX_EPOCH}; - +use core::fmt::Debug; use sgx_test_utils::{bench_case, black_box, test_case}; use sgx_test_utils::Bencher; @@ -104,6 +104,14 @@ fn instant_math_is_associative() { // Changing the order of instant math shouldn't change the results, // especially when the expression reduces to X + identity. assert_eq!((now + offset) - now, (now - now) + offset); + + // On any platform, `Instant` should have the same resolution as `Duration` (e.g. 1 nanosecond) + // or better. Otherwise, math will be non-associative (see #91417). + let now = Instant::now(); + let provided_offset = Duration::from_nanos(1); + let later = now + provided_offset; + let measured_offset = later - now; + assert_eq!(measured_offset, provided_offset); } #[test_case] @@ -207,6 +215,32 @@ fn since_epoch() { assert!(a < hundred_twenty_years); } +#[test_case] +fn big_math() { + // Check that the same result occurs when adding/subtracting each duration one at a time as when + // adding/subtracting them all at once. + #[track_caller] + fn check(start: Option, op: impl Fn(&T, Duration) -> Option) { + const DURATIONS: [Duration; 2] = + [Duration::from_secs(i64::MAX as _), Duration::from_secs(50)]; + if let Some(start) = start { + assert_eq!( + op(&start, DURATIONS.into_iter().sum()), + DURATIONS.into_iter().try_fold(start, |t, d| op(&t, d)) + ) + } + } + + check(SystemTime::UNIX_EPOCH.checked_sub(Duration::from_secs(100)), SystemTime::checked_add); + check(SystemTime::UNIX_EPOCH.checked_add(Duration::from_secs(100)), SystemTime::checked_sub); + + let instant = Instant::now(); + check(instant.checked_sub(Duration::from_secs(100)), Instant::checked_add); + check(instant.checked_sub(Duration::from_secs(i64::MAX as _)), Instant::checked_add); + check(instant.checked_add(Duration::from_secs(100)), Instant::checked_sub); + check(instant.checked_add(Duration::from_secs(i64::MAX as _)), Instant::checked_sub); +} + macro_rules! bench_instant_threaded { ($bench_name:ident, $thread_count:expr) => { #[bench_case] diff --git a/sgx_unwind/src/lib.rs b/sgx_unwind/src/lib.rs index 913385ae3..a677a9466 100644 --- a/sgx_unwind/src/lib.rs +++ b/sgx_unwind/src/lib.rs @@ -18,8 +18,9 @@ #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] #![unstable(feature = "panic_unwind", issue = "32837")] -#![feature(c_unwind)] #![feature(staged_api)] +#![feature(c_unwind)] +#![allow(internal_features)] #![allow(clippy::upper_case_acronyms)] #[macro_use] diff --git a/sgx_unwind/src/libunwind.rs b/sgx_unwind/src/libunwind.rs index 311e8502d..e2f43bbc1 100644 --- a/sgx_unwind/src/libunwind.rs +++ b/sgx_unwind/src/libunwind.rs @@ -19,10 +19,9 @@ use core::ffi::c_void; type c_int = i32; -type uintptr_t = usize; #[repr(C)] -#[derive(Debug, Copy, Clone, Eq, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq)] pub enum _Unwind_Reason_Code { _URC_NO_REASON = 0, _URC_FOREIGN_EXCEPTION_CAUGHT = 1, @@ -38,8 +37,8 @@ pub enum _Unwind_Reason_Code { pub use _Unwind_Reason_Code::*; pub type _Unwind_Exception_Class = u64; -pub type _Unwind_Word = uintptr_t; -pub type _Unwind_Ptr = uintptr_t; +pub type _Unwind_Word = *const u8; +pub type _Unwind_Ptr = *const u8; pub type _Unwind_Trace_Fn = extern "C" fn(ctx: *mut _Unwind_Context, arg: *mut c_void) -> _Unwind_Reason_Code; @@ -47,7 +46,7 @@ pub type _Unwind_Trace_Fn = pub const unwinder_private_data_size: usize = 5; #[cfg(target_arch = "x86_64")] -pub const unwinder_private_data_size: usize = 6; +pub const unwinder_private_data_size: usize = 2; #[repr(C)] pub struct _Unwind_Exception { @@ -73,7 +72,7 @@ extern "C" { } #[repr(C)] -#[derive(Copy, Clone, Eq, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub enum _Unwind_Action { _UA_SEARCH_PHASE = 1, _UA_CLEANUP_PHASE = 2, diff --git a/sgx_urts/src/lib.rs b/sgx_urts/src/lib.rs index 06ec72786..4ccbbc900 100644 --- a/sgx_urts/src/lib.rs +++ b/sgx_urts/src/lib.rs @@ -16,7 +16,6 @@ // under the License.. #![feature(allocator_api)] -#![feature(nonnull_slice_from_raw_parts)] #![allow(clippy::missing_safety_doc)] #[cfg(all(feature = "sim", feature = "hyper"))] diff --git a/tests/enclave/src/lib.rs b/tests/enclave/src/lib.rs index eb4164071..c3e9c4632 100644 --- a/tests/enclave/src/lib.rs +++ b/tests/enclave/src/lib.rs @@ -22,7 +22,9 @@ extern crate sgx_tstd as std; extern crate sgx_types; +use std::backtrace::{self, PrintFormat}; use sgx_types::error::SgxStatus; + #[macro_use] extern crate sgx_unit_test; use sgx_unit_test::{run_bench_cases, run_test_cases, sgx_test_utils}; @@ -30,6 +32,7 @@ use sgx_unit_test::{run_bench_cases, run_test_cases, sgx_test_utils}; ///# Safety #[no_mangle] pub unsafe extern "C" fn run_test_cases() -> SgxStatus { + let _ = backtrace::enable_backtrace(PrintFormat::Short); run_test_cases!(); SgxStatus::Success } diff --git a/tools/docker/06_rust.sh b/tools/docker/06_rust.sh index 9a504998e..26e1d609b 100755 --- a/tools/docker/06_rust.sh +++ b/tools/docker/06_rust.sh @@ -22,6 +22,6 @@ curl 'https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-i chmod +x /root/rustup-init && \ echo '1' | /root/rustup-init --default-toolchain "$RUST_TOOLCHAIN" && \ echo 'source /root/.cargo/env' >> /root/.bashrc && \ -/root/.cargo/bin/rustup component add rust-src rls rust-analysis && \ +/root/.cargo/bin/rustup component add rust-src rust-analysis && \ /root/.cargo/bin/cargo install xargo && \ rm /root/rustup-init && rm -rf /root/.cargo/registry && rm -rf /root/.cargo/git diff --git a/tools/docker/Dockerfile.centos8 b/tools/docker/Dockerfile.centos8 index 2154df76f..a46d3c113 100644 --- a/tools/docker/Dockerfile.centos8 +++ b/tools/docker/Dockerfile.centos8 @@ -80,7 +80,7 @@ ENV SGX_SDK_PKGS_VERSION 2.17.100.3 ENV SGX_DCAP_PKGS_VERSION 1.14.100.3 ENV SGX_SDK_VERSION ${SGX_SDK_PKGS_VERSION} ENV SGX_DCAP_VERSION ${SGX_DCAP_PKGS_VERSION} -ENV RUST_TOOLCHAIN nightly-2022-10-22 +ENV RUST_TOOLCHAIN nightly-2023-11-17 ENV OS_NAME centos ENV BINUTILS_DIST centos8 ENV SGX_SDK_URL "https://download.01.org/intel-sgx/sgx-linux/${SGX_SDK_CODE_VERSION}/distro/${OS_NAME}-stream/sgx_linux_x64_sdk_${SGX_SDK_BIN_VERSION}.bin" diff --git a/tools/docker/Dockerfile.ubuntu18.04 b/tools/docker/Dockerfile.ubuntu18.04 index 6d747d99f..a8d912bde 100644 --- a/tools/docker/Dockerfile.ubuntu18.04 +++ b/tools/docker/Dockerfile.ubuntu18.04 @@ -87,7 +87,7 @@ ENV SGX_SDK_PKGS_VERSION 2.17.100.3 ENV SGX_DCAP_PKGS_VERSION 1.14.100.3 ENV SGX_SDK_VERSION ${SGX_SDK_PKGS_VERSION}-bionic1 ENV SGX_DCAP_VERSION ${SGX_DCAP_PKGS_VERSION}-bionic1 -ENV RUST_TOOLCHAIN nightly-2022-10-22 +ENV RUST_TOOLCHAIN nightly-2023-11-17 ENV OS_NAME ubuntu ENV BINUTILS_DIST ubuntu18.04 ENV SGX_SDK_URL "https://download.01.org/intel-sgx/sgx-linux/${SGX_SDK_CODE_VERSION}/distro/${BINUTILS_DIST}-server/sgx_linux_x64_sdk_${SGX_SDK_BIN_VERSION}.bin" diff --git a/tools/docker/Dockerfile.ubuntu20.04 b/tools/docker/Dockerfile.ubuntu20.04 index 5ff63ff7f..a0c7bd6b6 100644 --- a/tools/docker/Dockerfile.ubuntu20.04 +++ b/tools/docker/Dockerfile.ubuntu20.04 @@ -86,7 +86,7 @@ ENV SGX_SDK_PKGS_VERSION 2.17.100.3 ENV SGX_DCAP_PKGS_VERSION 1.14.100.3 ENV SGX_SDK_VERSION ${SGX_SDK_PKGS_VERSION}-focal1 ENV SGX_DCAP_VERSION ${SGX_DCAP_PKGS_VERSION}-focal1 -ENV RUST_TOOLCHAIN nightly-2022-10-22 +ENV RUST_TOOLCHAIN nightly-2023-11-17 ENV OS_NAME ubuntu ENV BINUTILS_DIST ubuntu20.04 ENV SGX_SDK_URL "https://download.01.org/intel-sgx/sgx-linux/${SGX_SDK_CODE_VERSION}/distro/${BINUTILS_DIST}-server/sgx_linux_x64_sdk_${SGX_SDK_BIN_VERSION}.bin" From d4f678117ca59c2530adaa5a778f4c6cbf69359e Mon Sep 17 00:00:00 2001 From: Jean-Jacques Lafay Date: Tue, 23 Jan 2024 14:19:11 +0100 Subject: [PATCH 09/34] Introduce use_sgx_sdk feature Currently, the code base assumes creation of full rust enclaves, including the entry point. This allows minimal dependency on Intel's SGX SDK. However, this doesn't allow creating static libraries that are to be consumed by existing enclaves, typically written in C or C++ with the full SGX SDK from Intel. We introduce a new use_sgx_sdk feature that mainly allows using symbols from Intel's SGX SDK instead of locally defined ones. This feature is enabled for a new target "x86_64-sgx_sdk_linux_sgx", which is identical to x86_64-unknown-linux-sgx, except for its name and for a specific "sgx_sdk" abi, which allows to manage dependencies. --- rustlib/x86_64-sgx_sdk-linux-sgx.json | 46 +++++++++++++++ sgx_rsrvmm/Cargo.toml | 1 + sgx_rsrvmm/build.rs | 27 +++++++++ sgx_rsrvmm/src/rsrvmm/mod.rs | 5 ++ sgx_trts/Cargo.toml | 6 ++ sgx_trts/build.rs | 5 ++ sgx_trts/src/arch.rs | 6 ++ sgx_trts/src/asm/sgx_sdk.S | 83 +++++++++++++++++++++++++++ sgx_trts/src/asm_sgx_sdk.rs | 19 ++++++ sgx_trts/src/call/mod.rs | 14 ++++- sgx_trts/src/call/ocall.rs | 1 + sgx_trts/src/capi_sgx_sdk.rs | 30 ++++++++++ sgx_trts/src/enclave/init.rs | 10 ++++ sgx_trts/src/enclave/mem.rs | 3 + sgx_trts/src/enclave/mod.rs | 5 +- sgx_trts/src/error.rs | 14 +++++ sgx_trts/src/feature/mod.rs | 8 +++ sgx_trts/src/feature/sys.rs | 42 ++++++++++++++ sgx_trts/src/inst/hw/inst.rs | 6 ++ sgx_trts/src/inst/sim/derive.rs | 10 ++++ sgx_trts/src/inst/sim/mod.rs | 7 +++ sgx_trts/src/lib.rs | 9 +++ sgx_trts/src/tcs/tls.rs | 7 +++ sgx_trts/src/veh/mod.rs | 1 + sgx_trts/src/xsave.rs | 4 +- 25 files changed, 363 insertions(+), 6 deletions(-) create mode 100644 rustlib/x86_64-sgx_sdk-linux-sgx.json create mode 100644 sgx_rsrvmm/build.rs create mode 100644 sgx_trts/src/asm/sgx_sdk.S create mode 100644 sgx_trts/src/asm_sgx_sdk.rs create mode 100644 sgx_trts/src/capi_sgx_sdk.rs diff --git a/rustlib/x86_64-sgx_sdk-linux-sgx.json b/rustlib/x86_64-sgx_sdk-linux-sgx.json new file mode 100644 index 000000000..40ea3f45e --- /dev/null +++ b/rustlib/x86_64-sgx_sdk-linux-sgx.json @@ -0,0 +1,46 @@ +{ + "abi": "sgx_sdk", + "arch": "x86_64", + "cpu": "x86-64", + "crt-static-respected": true, + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", + "dynamic-linking": true, + "env": "gnu", + "executables": true, + "has-rpath": true, + "has-thread-local": true, + "linker-flavor": "gcc", + "linker-is-gnu": true, + "llvm-target": "x86_64-unknown-linux-gnu", + "max-atomic-width": 64, + "os": "linux", + "position-independent-executables": true, + "pre-link-args": { + "gcc": [ + "-Wl,--as-needed", + "-Wl,-z,noexecstack", + "-m64" + ] + }, + "relro-level": "full", + "stack-probes": { + "kind": "inline-or-call", + "min-llvm-version-for-inline": [ + 11, + 0, + 1 + ] + }, + "supported-sanitizers": [ + "address", + "cfi", + "leak", + "memory", + "thread" + ], + "target-c-int-width": "32", + "target-endian": "little", + "target-family": "unix", + "target-pointer-width": "64", + "vendor": "teaclave" +} diff --git a/sgx_rsrvmm/Cargo.toml b/sgx_rsrvmm/Cargo.toml index 59ee89635..6efd68e15 100644 --- a/sgx_rsrvmm/Cargo.toml +++ b/sgx_rsrvmm/Cargo.toml @@ -32,6 +32,7 @@ crate-type = ["rlib"] [features] default = [] capi = [] +use_sgx_sdk = ["sgx_trts/use_sgx_sdk"] [dependencies] sgx_sync = { path = "../sgx_sync" } diff --git a/sgx_rsrvmm/build.rs b/sgx_rsrvmm/build.rs new file mode 100644 index 000000000..42a457c8c --- /dev/null +++ b/sgx_rsrvmm/build.rs @@ -0,0 +1,27 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT 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 std::env; + +fn main() -> Result<(), &'static str> { + println!("cargo:rerun-if-changed=build.rs"); + let target = env::var("TARGET").unwrap(); + if target == "x86_64-sgx_sdk-linux-sgx" { + println!("cargo:rustc-cfg=feature=\"use_sgx_sdk\""); + } + Ok(()) +} diff --git a/sgx_rsrvmm/src/rsrvmm/mod.rs b/sgx_rsrvmm/src/rsrvmm/mod.rs index dbae758ac..921693863 100644 --- a/sgx_rsrvmm/src/rsrvmm/mod.rs +++ b/sgx_rsrvmm/src/rsrvmm/mod.rs @@ -35,8 +35,13 @@ pub(crate) mod manager; static mut RSRV_MEM: Option = None; static RSRV_MEM_INIT: Once = Once::new(); +#[cfg(not(feature = "use_sgx_sdk"))] #[no_mangle] static mut g_peak_rsrv_mem_committed: usize = 0; +#[cfg(feature = "use_sgx_sdk")] +extern "C" { + pub static mut g_peak_rsrv_mem_committed: usize; +} macro_rules! round_to_page { ($num:expr) => { diff --git a/sgx_trts/Cargo.toml b/sgx_trts/Cargo.toml index 82282e683..c168b5009 100644 --- a/sgx_trts/Cargo.toml +++ b/sgx_trts/Cargo.toml @@ -34,8 +34,14 @@ default = [] thread = [] sim = ["sgx_types/sim"] hyper = ["sgx_types/hyper"] +use_sgx_sdk = [] [dependencies] sgx_types = { path = "../sgx_types" } + +# cannot condition to feature, as the feature is set in build.rs, *after* the dependencies resolution +# the full target name is not usable either as we need a block to negate it, +# so we check for a custom target_abi, as defined in x86_64-sgx_sdk_linux_sgx.json +[target.'cfg(not(target_abi = "sgx_sdk"))'.dependencies] sgx_crypto_sys = { path = "../sgx_crypto/sgx_crypto_sys" } sgx_tlibc_sys = { path = "../sgx_libc/sgx_tlibc_sys" } diff --git a/sgx_trts/build.rs b/sgx_trts/build.rs index d17eb62e6..f3ba7b057 100644 --- a/sgx_trts/build.rs +++ b/sgx_trts/build.rs @@ -32,5 +32,10 @@ fn main() -> Result<(), &'static str> { "HYPER" => println!("cargo:rustc-cfg=feature=\"hyper\""), _ => (), } + + let target = env::var("TARGET").unwrap(); + if target == "x86_64-sgx_sdk-linux-sgx" { + println!("cargo:rustc-cfg=feature=\"use_sgx_sdk\""); + } Ok(()) } diff --git a/sgx_trts/src/arch.rs b/sgx_trts/src/arch.rs index d36fb09a9..86106a98b 100644 --- a/sgx_trts/src/arch.rs +++ b/sgx_trts/src/arch.rs @@ -19,6 +19,7 @@ use crate::edmm::{self, PageType}; use crate::tcs::tc; +#[cfg(not(feature = "use_sgx_sdk"))] use crate::version::*; use crate::xsave; use core::convert::From; @@ -52,12 +53,17 @@ macro_rules! trim_to_page { }; } +#[cfg(not(feature = "use_sgx_sdk"))] #[link_section = ".niprod"] #[no_mangle] pub static mut g_global_data: GlobalData = GlobalData { version: VERSION_UINT, data: [0_u8; GLOBAL_DATA_SIZE], }; +#[cfg(feature = "use_sgx_sdk")] +extern "C" { + pub static mut g_global_data: GlobalData; +} const GLOBAL_DATA_SIZE: usize = mem::size_of::() - mem::size_of::(); diff --git a/sgx_trts/src/asm/sgx_sdk.S b/sgx_trts/src/asm/sgx_sdk.S new file mode 100644 index 000000000..e7e718607 --- /dev/null +++ b/sgx_trts/src/asm/sgx_sdk.S @@ -0,0 +1,83 @@ +/* Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT 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 "get_tds.S" +.section absolute + +.equ SE_GUARD_PAGE_SHIFT, 16 +.equ SE_GUARD_PAGE_SIZE, (1 << SE_GUARD_PAGE_SHIFT) +.equ RED_ZONE_SIZE, 128 +.equ STATIC_STACK_SIZE, 2656 + +.equ OCMD_ERET, -1 + +.equ last_sp, (SE_WORDSIZE * 1) +.equ stack_base_addr, (SE_WORDSIZE * 2) +.equ stack_limit_addr, (SE_WORDSIZE * 3) +.equ first_ssa_gpr, (SE_WORDSIZE * 4) +.equ xsave_size, (SE_WORDSIZE * 7) +.equ self_addr, 0 +.equ stack_guard, (SE_WORDSIZE * 5) +.equ aex_notify_flag, (SE_WORDSIZE * 10) + +/* SSA GPR */ +.equ ssa_sp_t, 32 +.equ ssa_sp_u, 144 +.equ ssa_bp_u, 152 +.equ ssa_exit_info, 160 +.equ aex_notify, 167 + +.equ EXIT_INFO_VALID, 0x80000000 +/* OCALL command */ +.equ OCALL_FLAG, 0x04F434944 + +.equ RDRAND_RETRY_TIMES, 10 + +.equ ENCLAVE_INIT_NOT_STARTED, 0 +.equ ENCLAVE_INIT_IN_PROGRESS, 1 +.equ ENCLAVE_INIT_DONE, 2 +.equ ENCLAVE_CRASHED, 3 + + +.section .nipx,"ax",@progbits + +/* + * --------------------------------------------------------------------- + * Get the address of Tds + * --------------------------------------------------------------------- + */ +DECLARE_LOCAL_FUNC get_tds + READ_TD_DATA self_addr + ret + +.section .nipd,"aw" + +XSAVE_ENABLED: + .int 0 + +.section .text,"ax",@progbits + +DECLARE_LOCAL_FUNC get_xsave_enabled + lea_pic XSAVE_ENABLED, %rcx + xor %rax, %rax + movl (%rcx), %eax + ret + +DECLARE_LOCAL_FUNC set_xsave_enabled + lea_pic XSAVE_ENABLED, %rax + movl %edi, (%rax) + ret diff --git a/sgx_trts/src/asm_sgx_sdk.rs b/sgx_trts/src/asm_sgx_sdk.rs new file mode 100644 index 000000000..d5f4c3fac --- /dev/null +++ b/sgx_trts/src/asm_sgx_sdk.rs @@ -0,0 +1,19 @@ +use core::arch::global_asm; + +global_asm!(include_str!("asm/cet.S")); +global_asm!(include_str!("asm/macro.S")); + +cfg_if! { + if #[cfg(feature = "sim")] { + global_asm!(include_str!("inst/sim/td.S"), options(att_syntax)); + global_asm!(include_str!("inst/sim/xsave_mask.S"), options(att_syntax)); + } else if #[cfg(feature = "hyper")] { + global_asm!(include_str!("inst/hyper/td.S"), options(att_syntax)); + global_asm!(include_str!("inst/hyper/xsave_mask.S"), options(att_syntax)); + } else { + global_asm!(include_str!("inst/hw/td.S"), options(att_syntax)); + global_asm!(include_str!("inst/hw/xsave_mask.S"), options(att_syntax)); + } +} + +global_asm!(include_str!("asm/sgx_sdk.S"), options(att_syntax)); diff --git a/sgx_trts/src/call/mod.rs b/sgx_trts/src/call/mod.rs index 811c2baa3..533bcd25f 100644 --- a/sgx_trts/src/call/mod.rs +++ b/sgx_trts/src/call/mod.rs @@ -24,6 +24,14 @@ mod ocalloc; #[cfg(feature = "hyper")] pub(crate) use msbuf::MsbufInfo; -pub use ecall::{ecall, ECallIndex, FIRST_ECALL}; -pub use ocall::{ocall, oret, OCallIndex}; -pub use ocalloc::{OcAlloc, OcBuffer}; +pub use ecall::FIRST_ECALL; +#[cfg(not(feature = "use_sgx_sdk"))] +pub use ecall::{ecall, ECallIndex}; +pub use ocall::ocall; +#[cfg(not(feature = "use_sgx_sdk"))] +pub use ocall::oret; +#[cfg(not(all(feature = "use_sgx_sdk", any(feature = "sim", feature = "hyper"))))] +pub use ocall::OCallIndex; +#[cfg(not(any(feature = "sim", feature = "hyper")))] +pub use ocalloc::OcAlloc; +pub use ocalloc::OcBuffer; diff --git a/sgx_trts/src/call/ocall.rs b/sgx_trts/src/call/ocall.rs index ea60ea485..03efb8af6 100644 --- a/sgx_trts/src/call/ocall.rs +++ b/sgx_trts/src/call/ocall.rs @@ -100,6 +100,7 @@ pub fn ocall(idx: OCallIndex, ms: Option<&mut T>) -> SgxResult { } } +#[cfg(not(feature = "use_sgx_sdk"))] #[no_mangle] pub unsafe extern "C" fn update_ocall_lastsp(context: &mut OCallContext) -> usize { let mut tc = tcs::current(); diff --git a/sgx_trts/src/capi_sgx_sdk.rs b/sgx_trts/src/capi_sgx_sdk.rs new file mode 100644 index 000000000..7c7806770 --- /dev/null +++ b/sgx_trts/src/capi_sgx_sdk.rs @@ -0,0 +1,30 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT 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 crate::enclave::MmLayout; + +#[inline] +#[no_mangle] +pub extern "C" fn sgx_get_image_base() -> *const u8 { + MmLayout::image_base() as *const u8 +} + +#[inline] +#[no_mangle] +pub extern "C" fn sgx_get_heap_base() -> *const u8 { + MmLayout::heap_base() as *const u8 +} diff --git a/sgx_trts/src/enclave/init.rs b/sgx_trts/src/enclave/init.rs index 1e61526d0..336c94c92 100644 --- a/sgx_trts/src/enclave/init.rs +++ b/sgx_trts/src/enclave/init.rs @@ -28,12 +28,15 @@ use core::ffi::c_void; use core::ptr; use core::ptr::NonNull; use core::slice; +#[cfg(not(feature = "use_sgx_sdk"))] use sgx_crypto_sys::sgx_init_crypto_lib; +#[cfg(not(feature = "use_sgx_sdk"))] use sgx_tlibc_sys::{sgx_heap_init, sgx_init_string_lib}; use sgx_types::error::{SgxResult, SgxStatus}; use sgx_types::marker::ContiguousMemory; use sgx_types::types::EnclaveId; +#[cfg(not(feature = "use_sgx_sdk"))] #[allow(unused_variables)] #[link_section = ".nipx"] pub fn rtinit(tcs: &mut Tcs, ms: *mut SystemFeatures, tidx: usize) -> SgxResult { @@ -96,6 +99,13 @@ pub fn rtinit(tcs: &mut Tcs, ms: *mut SystemFeatures, tidx: usize) -> SgxResult Ok(()) } +#[cfg(feature = "use_sgx_sdk")] +#[no_mangle] +pub extern "C" fn rtinit_with_sgx_sdk() { + mem::Image::init(); + let _ = SysFeatures::init_from_sgx_sdk(); +} + pub fn ctors() -> SgxResult { if let Some(init_array) = parse::init_array()? { let fn_array = init_array.get_array(); diff --git a/sgx_trts/src/enclave/mem.rs b/sgx_trts/src/enclave/mem.rs index 480a9aa87..7658bb28e 100644 --- a/sgx_trts/src/enclave/mem.rs +++ b/sgx_trts/src/enclave/mem.rs @@ -111,8 +111,11 @@ pub struct Image { pub entry_address: usize, } +#[cfg(not(feature = "use_sgx_sdk"))] #[link_section = ".data.rel.ro"] static mut IMAGE: MaybeUninit = MaybeUninit::uninit(); +#[cfg(feature = "use_sgx_sdk")] +static mut IMAGE: MaybeUninit = MaybeUninit::uninit(); impl Image { pub fn init() { diff --git a/sgx_trts/src/enclave/mod.rs b/sgx_trts/src/enclave/mod.rs index ec05e154c..adb77fca8 100644 --- a/sgx_trts/src/enclave/mod.rs +++ b/sgx_trts/src/enclave/mod.rs @@ -18,6 +18,7 @@ #![allow(unused_imports)] mod atexit; +#[cfg(not(feature = "use_sgx_sdk"))] mod entry; mod init; mod mem; @@ -27,6 +28,8 @@ pub mod parse; pub mod state; pub use atexit::{at_exit, cleanup}; -pub use init::{ctors, global_init, rtinit}; +pub use init::{ctors, global_init}; +#[cfg(not(feature = "use_sgx_sdk"))] +pub use init::rtinit; pub use mem::{is_within_enclave, is_within_host, EnclaveRange, MmLayout}; pub use uninit::{global_exit, rtuninit, UNINIT_FLAG}; diff --git a/sgx_trts/src/error.rs b/sgx_trts/src/error.rs index 79b5d5cc9..8dae0cb8f 100644 --- a/sgx_trts/src/error.rs +++ b/sgx_trts/src/error.rs @@ -15,15 +15,22 @@ // specific language governing permissions and limitations // under the License.. +#[cfg(not(feature = "use_sgx_sdk"))] use crate::arch::Tds; use crate::enclave::state::{self, State}; +#[cfg(not(feature = "use_sgx_sdk"))] use crate::tcs::tc; +#[cfg(not(feature = "use_sgx_sdk"))] #[no_mangle] pub extern "C" fn get_errno_addr() -> *mut i32 { let tds = unsafe { Tds::from_raw_mut(tc::get_tds()) }; &mut tds.last_error as *mut usize as *mut i32 } +#[cfg(feature = "use_sgx_sdk")] +extern "C" { + fn get_errno_addr() -> *mut i32; +} pub fn errno() -> i32 { unsafe { *get_errno_addr() } @@ -33,8 +40,15 @@ pub fn set_errno(e: i32) { unsafe { *get_errno_addr() = e } } +#[cfg(not(feature = "use_sgx_sdk"))] #[no_mangle] pub extern "C" fn abort() -> ! { state::set_state(State::Crashed); core::intrinsics::abort() } + +#[cfg(feature = "use_sgx_sdk")] +pub fn abort() -> ! { + state::set_state(State::Crashed); + core::intrinsics::abort() +} diff --git a/sgx_trts/src/feature/mod.rs b/sgx_trts/src/feature/mod.rs index f748ea7d2..869e0ab37 100644 --- a/sgx_trts/src/feature/mod.rs +++ b/sgx_trts/src/feature/mod.rs @@ -87,6 +87,14 @@ macro_rules! is_x86_feature_detected { ("bmi") => { $crate::feature::check_for($crate::feature::Feature::bmi) }; + // although bmi1 should be an alias for bmi, and bmi2 always present + // on Intel processors if bmi1 is, it seems unreliable + ("bmi1") => { + false + }; + ("bmi2") => { + false + }; ("lzcnt") => { $crate::feature::check_for($crate::feature::Feature::lzcnt) }; diff --git a/sgx_trts/src/feature/sys.rs b/sgx_trts/src/feature/sys.rs index da2a076e3..3a37054f7 100644 --- a/sgx_trts/src/feature/sys.rs +++ b/sgx_trts/src/feature/sys.rs @@ -219,6 +219,7 @@ pub struct SysFeatures { unsafe impl ContiguousMemory for SysFeatures {} +#[cfg(not(feature = "use_sgx_sdk"))] #[link_section = ".data.rel.ro"] static mut SYS_FEATURES: SysFeatures = SysFeatures { version: Version::Sdk1_5, @@ -229,12 +230,31 @@ static mut SYS_FEATURES: SysFeatures = SysFeatures { is_edmm: false, is_aexnotify: false, }; +#[cfg(feature = "use_sgx_sdk")] +static mut SYS_FEATURES: SysFeatures = SysFeatures { + version: Version::Sdk1_5, + xfrm: types::XFRM_LEGACY, + cpu_features: 0, + cpu_core_num: 0, + cpuinfo_table: [[0; 4]; 8], + is_edmm: false, + is_aexnotify: false, +}; // Improve compatibility // e.g. intel-sgx-ssl handles CPUID with this global variable. +#[cfg(not(feature = "use_sgx_sdk"))] #[link_section = ".data.rel.ro"] #[no_mangle] pub static mut g_cpu_feature_indicator: u64 = 0; +#[cfg(feature = "use_sgx_sdk")] +extern "C" { + static mut g_cpu_feature_indicator: u64; + static g_sdk_version: u32; + static g_cpu_core_num: u32; + static EDMM_supported: i32; + static g_aexnotify_supported: i32; +} impl SysFeatures { pub fn init(raw: NonNull) -> SgxResult<&'static SysFeatures> { @@ -261,6 +281,28 @@ impl SysFeatures { Ok(SysFeatures::get()) } + #[cfg(feature = "use_sgx_sdk")] + pub fn init_from_sgx_sdk() -> SgxResult<&'static SysFeatures> { + unsafe { + let version = Version::try_from(g_sdk_version).map_err(|_| SgxStatus::Unexpected)?; + let feature = SysFeatures::get_mut(); + + match version { + Version::Sdk1_5 | Version::Sdk3_0 => (), + _ => return Err(SgxStatus::Unexpected), + }; + + feature.version = version; + feature.xfrm = xsave::get_xfrm(); + feature.cpu_core_num = g_cpu_core_num; + feature.is_edmm = EDMM_supported != 0; + feature.is_aexnotify = g_aexnotify_supported != 0; + feature.cpu_features = g_cpu_feature_indicator; + } + + Ok(SysFeatures::get()) + } + #[inline] pub fn get() -> &'static SysFeatures { unsafe { &SYS_FEATURES } diff --git a/sgx_trts/src/inst/hw/inst.rs b/sgx_trts/src/inst/hw/inst.rs index c97a5a2c8..fd9c94ee7 100644 --- a/sgx_trts/src/inst/hw/inst.rs +++ b/sgx_trts/src/inst/hw/inst.rs @@ -44,9 +44,15 @@ impl EncluInst { pub fn everify_report2(r: &AlignReport2Mac) -> Result<(), u32> { extern "C" { + #[cfg(not(feature = "use_sgx_sdk"))] fn everifyreport2(r: *const AlignReport2Mac) -> u32; + #[cfg(feature = "use_sgx_sdk")] + fn do_everifyreport2(r: *const AlignReport2Mac) -> u32; } + #[cfg(not(feature = "use_sgx_sdk"))] let error = unsafe { everifyreport2(r) }; + #[cfg(feature = "use_sgx_sdk")] + let error = unsafe { do_everifyreport2(r) }; if error == 0 { Ok(()) } else { diff --git a/sgx_trts/src/inst/sim/derive.rs b/sgx_trts/src/inst/sim/derive.rs index fdf027a66..eddb5ac5e 100644 --- a/sgx_trts/src/inst/sim/derive.rs +++ b/sgx_trts/src/inst/sim/derive.rs @@ -18,7 +18,17 @@ use crate::arch::Align16; use crate::error::abort; use crate::se::AlignKey; +#[cfg(not(feature = "use_sgx_sdk"))] use sgx_crypto_sys::sgx_rijndael128_cmac_msg; +#[cfg(feature = "use_sgx_sdk")] +extern "C" { + pub fn sgx_rijndael128_cmac_msg( + p_key: *const Key128bit, + p_src: *const u8, + src_len: u32, + p_mac: *mut sgx_types::types::Mac128bit, + ) -> sgx_types::error::SgxStatus; +} use sgx_types::types::{ Attributes, ConfigId, CpuSvn, IsvExtProdId, IsvFamilyId, Key128bit, KeyId, KeyName, KeyPolicy, Mac, Measurement, MiscSelect, diff --git a/sgx_trts/src/inst/sim/mod.rs b/sgx_trts/src/inst/sim/mod.rs index 5d047a838..43c6c853c 100644 --- a/sgx_trts/src/inst/sim/mod.rs +++ b/sgx_trts/src/inst/sim/mod.rs @@ -19,6 +19,7 @@ use crate::arch::{Enclu, SecInfo, Secs, Tcs}; use crate::error::abort; use crate::se::{AlignKey, AlignKeyRequest, AlignReport, AlignReportData, AlignTargetInfo}; use core::convert::TryFrom; +#[cfg(not(feature = "use_sgx_sdk"))] use core::ptr; use core::sync::atomic::AtomicUsize; use inst::EncluInst; @@ -86,6 +87,7 @@ pub struct GlobalSim { pub seed: u64, } +#[cfg(not(feature = "use_sgx_sdk"))] #[no_mangle] pub static mut g_global_data_sim: GlobalSim = GlobalSim { secs: ptr::null(), @@ -93,6 +95,11 @@ pub static mut g_global_data_sim: GlobalSim = GlobalSim { seed: 0, }; +#[cfg(feature = "use_sgx_sdk")] +extern "C" { + pub static mut g_global_data_sim: GlobalSim; +} + impl GlobalSim { #[inline] pub fn get() -> &'static GlobalSim { diff --git a/sgx_trts/src/lib.rs b/sgx_trts/src/lib.rs index 7469f7e11..1325de094 100644 --- a/sgx_trts/src/lib.rs +++ b/sgx_trts/src/lib.rs @@ -41,16 +41,22 @@ extern crate alloc; #[macro_use] extern crate sgx_types; +#[cfg(not(feature = "use_sgx_sdk"))] extern crate sgx_crypto_sys; +#[cfg(not(feature = "use_sgx_sdk"))] extern crate sgx_tlibc_sys; #[macro_use] mod arch; +#[cfg(not(feature = "use_sgx_sdk"))] mod asm; +#[cfg(feature = "use_sgx_sdk")] +mod asm_sgx_sdk; mod call; #[macro_use] mod elf; mod enclave; + mod inst; #[cfg(not(feature = "hyper"))] mod pkru; @@ -58,7 +64,10 @@ mod stackchk; mod version; mod xsave; +#[cfg(not(feature = "use_sgx_sdk"))] pub mod capi; +#[cfg(feature = "use_sgx_sdk")] +pub mod capi_sgx_sdk; #[cfg(not(any(feature = "sim", feature = "hyper")))] pub mod aexnotify; diff --git a/sgx_trts/src/tcs/tls.rs b/sgx_trts/src/tcs/tls.rs index ae56fa3e3..7c86efd01 100644 --- a/sgx_trts/src/tcs/tls.rs +++ b/sgx_trts/src/tcs/tls.rs @@ -15,7 +15,9 @@ // specific language governing permissions and limitations // under the License.. +#[cfg(not(feature = "use_sgx_sdk"))] use crate::arch::Tds; +#[cfg(not(feature = "use_sgx_sdk"))] use crate::tcs::tc; #[repr(C)] @@ -25,9 +27,14 @@ pub struct TlsIndex { offset: usize, } +#[cfg(not(feature = "use_sgx_sdk"))] #[no_mangle] pub unsafe extern "C" fn __tls_get_addr(ti: *const TlsIndex) -> *mut u8 { let ti = &*ti; let tds = Tds::from_raw(tc::get_tds()); (tds.tls_addr + ti.offset) as *mut u8 } +#[cfg(feature = "use_sgx_sdk")] +extern "C" { + pub fn __tls_get_addr(ti: *const TlsIndex) -> *mut u8; +} diff --git a/sgx_trts/src/veh/mod.rs b/sgx_trts/src/veh/mod.rs index a233a7556..1b16a6f15 100644 --- a/sgx_trts/src/veh/mod.rs +++ b/sgx_trts/src/veh/mod.rs @@ -19,6 +19,7 @@ mod exception; mod list; mod register; +#[cfg(not(feature = "use_sgx_sdk"))] pub(crate) use exception::handle; pub use register::*; diff --git a/sgx_trts/src/xsave.rs b/sgx_trts/src/xsave.rs index 8be142aca..6eaa432eb 100644 --- a/sgx_trts/src/xsave.rs +++ b/sgx_trts/src/xsave.rs @@ -35,9 +35,9 @@ pub fn get_xfrm() -> u64 { } } - let enbaled = i32::from(xfrm != types::XFRM_LEGACY); + let enabled = i32::from(xfrm != types::XFRM_LEGACY); unsafe { - set_xsave_enabled(enbaled); + set_xsave_enabled(enabled); } #[cfg(feature = "sim")] From ec23fbf891416794318e1b4f7d51dfb7b93ed803 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Lafay Date: Thu, 15 Feb 2024 15:26:02 +0100 Subject: [PATCH 10/34] Expose sgx_trts::veh in std Useful for convenient handling of sgx exceptions. --- sgx_tstd/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/sgx_tstd/src/lib.rs b/sgx_tstd/src/lib.rs index 520ff1657..e8887de34 100644 --- a/sgx_tstd/src/lib.rs +++ b/sgx_tstd/src/lib.rs @@ -298,6 +298,7 @@ pub mod arch { } pub use sgx_trts::macros::is_x86_feature_detected; +pub use sgx_trts::veh; // Platform-abstraction modules mod sys; From ad57a8fc5fd0b1219596c75f3970eaa98146373d Mon Sep 17 00:00:00 2001 From: Jean-Jacques Lafay Date: Thu, 22 Feb 2024 18:56:39 +0100 Subject: [PATCH 11/34] Simplify use of sgx_urts - add a top-level CMakeLists.txt - expose the headers not in full sgx sdk on their own --- CMakeLists.txt | 24 +++++ .../edl/sgx_sdk_additional_include/netdb.h | 55 +++++++++++ sgx_edl/edl/sgx_sdk_additional_include/poll.h | 47 ++++++++++ .../edl/sgx_sdk_additional_include/sched.h | 73 +++++++++++++++ .../sgx_sdk_additional_include/sys/epoll.h | 50 ++++++++++ .../sgx_sdk_additional_include/sys/sockaddr.h | 32 +++++++ .../sgx_sdk_additional_include/sys/socket.h | 91 +++++++++++++++++++ .../edl/sgx_sdk_additional_include/sys/uio.h | 49 ++++++++++ 8 files changed, 421 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 sgx_edl/edl/sgx_sdk_additional_include/netdb.h create mode 100644 sgx_edl/edl/sgx_sdk_additional_include/poll.h create mode 100644 sgx_edl/edl/sgx_sdk_additional_include/sched.h create mode 100644 sgx_edl/edl/sgx_sdk_additional_include/sys/epoll.h create mode 100644 sgx_edl/edl/sgx_sdk_additional_include/sys/sockaddr.h create mode 100644 sgx_edl/edl/sgx_sdk_additional_include/sys/socket.h create mode 100644 sgx_edl/edl/sgx_sdk_additional_include/sys/uio.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..57f401e7f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +message("sgx_urts_rust") + +set(SGX_URTS_OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/sgx_urts/target/release/libsgx_urts.a) +add_custom_command( + OUTPUT ${SGX_URTS_OUTPUT} + COMMAND cargo build --release + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/sgx_urts +) + +add_custom_target(sgx_urts_target + DEPENDS ${SGX_URTS_OUTPUT} +) + +add_library(sgx_urts_rust STATIC IMPORTED GLOBAL) +add_dependencies(sgx_urts_rust sgx_urts_target) + +set_target_properties(sgx_urts_rust + PROPERTIES + IMPORTED_LOCATION "${SGX_URTS_OUTPUT}" +) + +# IMPORTED libraries cannot be installed, so we just copy the files, +# and define (in Secretarium.cmake) sgx_urts_rust as an IMPORTED library pointing to the installed file +install(FILES ${SGX_URTS_OUTPUT} DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/sgx_edl/edl/sgx_sdk_additional_include/netdb.h b/sgx_edl/edl/sgx_sdk_additional_include/netdb.h new file mode 100644 index 000000000..db1433842 --- /dev/null +++ b/sgx_edl/edl/sgx_sdk_additional_include/netdb.h @@ -0,0 +1,55 @@ +// +// Copyright © 2005-2020 Rich Felker, et al. +// Licensed under the MIT license.s +// + +/* Copyright © 2005-2020 Rich Felker, et al. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#ifndef _NETDB_H +#define _NETDB_H + +#include +#include +#include + +#ifndef HACK_ADDRINFO_REDEF +struct addrinfo { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + socklen_t ai_addrlen; + struct sockaddr *ai_addr; + char *ai_canonname; + struct addrinfo *ai_next; +}; +#endif + +__BEGIN_DECLS + +// ocall +int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict); +void freeaddrinfo (struct addrinfo *); + +__END_DECLS + +#endif diff --git a/sgx_edl/edl/sgx_sdk_additional_include/poll.h b/sgx_edl/edl/sgx_sdk_additional_include/poll.h new file mode 100644 index 000000000..68a6c1a50 --- /dev/null +++ b/sgx_edl/edl/sgx_sdk_additional_include/poll.h @@ -0,0 +1,47 @@ +// +// Copyright © 2005-2020 Rich Felker, et al. +// Licensed under the MIT license. +// + +/* Copyright © 2005-2020 Rich Felker, et al. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#ifndef _POLL_H_ +#define _POLL_H_ + +#include + +typedef unsigned long nfds_t; + +struct pollfd { + int fd; + short int events; + short int revents; +}; + +__BEGIN_DECLS + +// ocall +int poll(struct pollfd *, nfds_t, int); + +__END_DECLS + +#endif diff --git a/sgx_edl/edl/sgx_sdk_additional_include/sched.h b/sgx_edl/edl/sgx_sdk_additional_include/sched.h new file mode 100644 index 000000000..6738bb985 --- /dev/null +++ b/sgx_edl/edl/sgx_sdk_additional_include/sched.h @@ -0,0 +1,73 @@ +// +// Copyright © 2005-2020 Rich Felker, et al. +// Licensed under the MIT license.s +// + +/* Copyright © 2005-2020 Rich Felker, et al. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#ifndef _SCHED_H_ +#define _SCHED_H_ + +#include +#include + +typedef struct { + unsigned long __bits[128/sizeof(long)]; +} cpu_set_t; + +#define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \ + (((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) ) + +#define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=) +#define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~) +#define CPU_ISSET_S(i, size, set) __CPU_op_S(i, size, set, &) + +#define __CPU_op_func_S(func, op) \ +static __inline void __CPU_##func##_S(size_t __size, cpu_set_t *__dest, \ + const cpu_set_t *__src1, const cpu_set_t *__src2) \ +{ \ + size_t __i; \ + for (__i=0; __i<__size/sizeof(long); __i++) \ + ((unsigned long *)__dest)[__i] = ((unsigned long *)__src1)[__i] \ + op ((unsigned long *)__src2)[__i] ; \ +} + +__CPU_op_func_S(AND, &) +__CPU_op_func_S(OR, |) +__CPU_op_func_S(XOR, ^) + +#define CPU_AND_S(a,b,c,d) __CPU_AND_S(a,b,c,d) +#define CPU_OR_S(a,b,c,d) __CPU_OR_S(a,b,c,d) +#define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d) + +__BEGIN_DECLS + +typedef unsigned int pid_t; + +// ocall +int sched_yield(void); +int sched_getaffinity(pid_t, size_t, cpu_set_t *); +int sched_setaffinity(pid_t, size_t, const cpu_set_t *); + +__END_DECLS + +#endif /* _SCHED_H_ */ diff --git a/sgx_edl/edl/sgx_sdk_additional_include/sys/epoll.h b/sgx_edl/edl/sgx_sdk_additional_include/sys/epoll.h new file mode 100644 index 000000000..5f61d356e --- /dev/null +++ b/sgx_edl/edl/sgx_sdk_additional_include/sys/epoll.h @@ -0,0 +1,50 @@ +// +// Copyright © 2005-2020 Rich Felker, et al. +// Licensed under the MIT license. +// + +/* Copyright © 2005-2020 Rich Felker, et al. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#ifndef _SYS_EPOLL_H_ +#define _SYS_EPOLL_H_ + +#include + +typedef union epoll_data { + void *ptr; + int fd; + uint32_t u32; + uint64_t u64; +} epoll_data_t; + +struct epoll_event { + uint32_t events; + epoll_data_t data; +} __attribute__ ((__packed__)); + +// ocall +int epoll_create1(int); +int epoll_create(int); +int epoll_ctl(int, int, int, struct epoll_event *); +int epoll_wait(int, struct epoll_event *, int, int); + +#endif /* _SYS_EPOLL_H_ */ diff --git a/sgx_edl/edl/sgx_sdk_additional_include/sys/sockaddr.h b/sgx_edl/edl/sgx_sdk_additional_include/sys/sockaddr.h new file mode 100644 index 000000000..1a7938a9e --- /dev/null +++ b/sgx_edl/edl/sgx_sdk_additional_include/sys/sockaddr.h @@ -0,0 +1,32 @@ +// +// Copyright © 2005-2020 Rich Felker, et al. +// Licensed under the MIT license. +// + +/* Copyright © 2005-2020 Rich Felker, et al. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#ifndef _SYS_SOCKADDR_H_ +#define _SYS_SOCKADDR_H_ + +typedef unsigned short int sa_family_t; + +#endif /* _SYS_SOCKADDR_H_ */ diff --git a/sgx_edl/edl/sgx_sdk_additional_include/sys/socket.h b/sgx_edl/edl/sgx_sdk_additional_include/sys/socket.h new file mode 100644 index 000000000..7a7078618 --- /dev/null +++ b/sgx_edl/edl/sgx_sdk_additional_include/sys/socket.h @@ -0,0 +1,91 @@ +// +// Copyright © 2005-2020 Rich Felker, et al. +// Licensed under the MIT license. +// + +/* Copyright © 2005-2020 Rich Felker, et al. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#ifndef _SYS_SOCKET_H_ +#define _SYS_SOCKET_H_ + +#include +#include +#include +#include + +typedef unsigned int socklen_t; + +#ifndef HACK_SOCKADDR_REDEF +struct sockaddr { + sa_family_t sa_family; + char sa_data[14]; +}; +#endif + +struct sockaddr_storage { + sa_family_t ss_family; + char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)]; + unsigned long __ss_align; +}; + +struct msghdr { + void *msg_name; + socklen_t msg_namelen; + + struct iovec *msg_iov; + size_t msg_iovlen; + + void *msg_control; + size_t msg_controllen; + + int msg_flags; +}; + +__BEGIN_DECLS + +// ocall +int socket(int, int, int); +int socketpair(int, int, int, int [2]); + +int shutdown (int, int); + +int bind(int, const struct sockaddr *, socklen_t); +int connect(int, const struct sockaddr *, socklen_t); +int listen(int, int); +int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); + +int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict); +int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); + +ssize_t send (int, const void *, size_t, int); +ssize_t recv (int, void *, size_t, int); +ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); +ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); +ssize_t sendmsg (int, const struct msghdr *, int); +ssize_t recvmsg (int, struct msghdr *, int); + +int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict); +int setsockopt (int, int, int, const void *, socklen_t); + +__END_DECLS + +#endif /* _SYS_SOCKET_H_ */ diff --git a/sgx_edl/edl/sgx_sdk_additional_include/sys/uio.h b/sgx_edl/edl/sgx_sdk_additional_include/sys/uio.h new file mode 100644 index 000000000..7eeac89b3 --- /dev/null +++ b/sgx_edl/edl/sgx_sdk_additional_include/sys/uio.h @@ -0,0 +1,49 @@ +// +// Copyright © 2005-2020 Rich Felker, et al. +// Licensed under the MIT license. +// + +/* Copyright © 2005-2020 Rich Felker, et al. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#ifndef _SYS_UIO_H_ +#define _SYS_UIO_H_ + +#include +#include + +struct iovec { + void *iov_base; + size_t iov_len; +}; + +__BEGIN_DECLS + +// ocall +ssize_t readv(int, const struct iovec *, int); +ssize_t writev(int, const struct iovec *, int); + +ssize_t preadv64(int, const struct iovec *, int, uint64_t); +ssize_t pwritev64(int, const struct iovec *, int, uint64_t); + +__END_DECLS + +#endif /* _SYS_UIO_H_ */ From 32bcb8741fabd51a7bc9f93f65cdb6f528f9c0cd Mon Sep 17 00:00:00 2001 From: Jean-Jacques Lafay Date: Tue, 19 Nov 2024 16:37:43 +0100 Subject: [PATCH 12/34] Make teaklave build with rust 1.84 Including exposing some new features now available in std. --- rust-toolchain | 2 +- rustlib/panic_abort/src/lib.rs | 1 - rustlib/panic_unwind/src/lib.rs | 1 - rustlib/std/Cargo.toml | 1 + rustlib/x86_64-sgx_sdk-linux-sgx.json | 2 +- sgx_alloc/src/lib.rs | 1 + sgx_oc/src/lib.rs | 4 +- sgx_rsrvmm/src/lib.rs | 1 + sgx_sync/src/lib.rs | 1 + sgx_sync/src/once_lock.rs | 2 +- sgx_trts/src/feature/mod.rs | 4 + sgx_trts/src/lib.rs | 3 +- sgx_trts/src/sync/lazy.rs | 2 +- sgx_tstd/hashbrown/src/lib.rs | 5 +- sgx_tstd/hashbrown/src/raw/mod.rs | 16 +- sgx_tstd/src/hash/random.rs | 2 +- sgx_tstd/src/io/mod.rs | 5 +- sgx_tstd/src/io/util.rs | 5 +- sgx_tstd/src/lib.rs | 51 +++-- sgx_tstd/src/num.rs | 2 +- sgx_tstd/src/panic.rs | 199 ++++++++++++++++-- sgx_tstd/src/panicking.rs | 145 ++++++++----- sgx_tstd/src/prelude/v1.rs | 3 - .../src/sys/common/thread_local/os_local.rs | 2 +- sgx_tstd/src/sys/fd.rs | 6 +- sgx_tstd/src/sys/net.rs | 6 +- sgx_tstd/src/sys/os_str.rs | 6 +- sgx_tstd/src/sys/personality/dwarf/eh.rs | 2 +- sgx_tstd/src/sys/unsupported/process.rs | 6 +- sgx_types/src/lib.rs | 1 - sgx_unwind/src/lib.rs | 1 - 31 files changed, 334 insertions(+), 154 deletions(-) diff --git a/rust-toolchain b/rust-toolchain index 33cc62763..d7b2dc6bf 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2023-11-17 +nightly-2024-11-14 diff --git a/rustlib/panic_abort/src/lib.rs b/rustlib/panic_abort/src/lib.rs index 99b10fdb3..7dc8c5767 100644 --- a/rustlib/panic_abort/src/lib.rs +++ b/rustlib/panic_abort/src/lib.rs @@ -14,7 +14,6 @@ #![feature(std_internals)] #![feature(staged_api)] #![feature(rustc_attrs)] -#![feature(c_unwind)] extern crate sgx_trts; diff --git a/rustlib/panic_unwind/src/lib.rs b/rustlib/panic_unwind/src/lib.rs index 60d7af26f..237a8919f 100644 --- a/rustlib/panic_unwind/src/lib.rs +++ b/rustlib/panic_unwind/src/lib.rs @@ -22,7 +22,6 @@ #![feature(rustc_attrs)] #![panic_runtime] #![feature(panic_runtime)] -#![feature(c_unwind)] #![allow(internal_features)] extern crate alloc; diff --git a/rustlib/std/Cargo.toml b/rustlib/std/Cargo.toml index 6ede65f1f..d8b32ddf1 100644 --- a/rustlib/std/Cargo.toml +++ b/rustlib/std/Cargo.toml @@ -44,6 +44,7 @@ unsupported_process = [] panic-unwind = ["panic_unwind"] profiler = ["profiler_builtins"] capi = ["sgx_sync/capi", "sgx_rsrvmm/capi"] +unit_test = [] [dependencies] sgx_alloc = { path = "../../sgx_alloc" } diff --git a/rustlib/x86_64-sgx_sdk-linux-sgx.json b/rustlib/x86_64-sgx_sdk-linux-sgx.json index 40ea3f45e..5d456deec 100644 --- a/rustlib/x86_64-sgx_sdk-linux-sgx.json +++ b/rustlib/x86_64-sgx_sdk-linux-sgx.json @@ -3,7 +3,7 @@ "arch": "x86_64", "cpu": "x86-64", "crt-static-respected": true, - "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", "dynamic-linking": true, "env": "gnu", "executables": true, diff --git a/sgx_alloc/src/lib.rs b/sgx_alloc/src/lib.rs index 8af6102af..7a0309338 100644 --- a/sgx_alloc/src/lib.rs +++ b/sgx_alloc/src/lib.rs @@ -26,6 +26,7 @@ #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] #![allow(clippy::missing_safety_doc)] #![allow(non_camel_case_types)] +#![allow(internal_features)] #![feature(allocator_api)] #![feature(alloc_layout_extra)] #![feature(core_intrinsics)] diff --git a/sgx_oc/src/lib.rs b/sgx_oc/src/lib.rs index c891d666a..fcaea2039 100644 --- a/sgx_oc/src/lib.rs +++ b/sgx_oc/src/lib.rs @@ -17,9 +17,9 @@ #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] +#![allow(internal_features)] +#![allow(static_mut_refs)] #![feature(allocator_api)] -#![feature(error_in_core)] -#![feature(const_extern_fn)] #![feature(negative_impls)] #![feature(ptr_internals)] #![feature(slice_index_methods)] diff --git a/sgx_rsrvmm/src/lib.rs b/sgx_rsrvmm/src/lib.rs index 3f60fb0ea..e787c7b39 100644 --- a/sgx_rsrvmm/src/lib.rs +++ b/sgx_rsrvmm/src/lib.rs @@ -18,6 +18,7 @@ #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] #![feature(slice_ptr_get)] +#![allow(static_mut_refs)] #![allow(clippy::missing_safety_doc)] #[macro_use] diff --git a/sgx_sync/src/lib.rs b/sgx_sync/src/lib.rs index c86ec3599..40b0c3e52 100644 --- a/sgx_sync/src/lib.rs +++ b/sgx_sync/src/lib.rs @@ -18,6 +18,7 @@ #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] #![deny(unused_features)] +#![allow(internal_features)] #![feature(const_trait_impl)] #![feature(core_intrinsics)] #![feature(dropck_eyepatch)] diff --git a/sgx_sync/src/once_lock.rs b/sgx_sync/src/once_lock.rs index bd54de13f..5cb6f4430 100644 --- a/sgx_sync/src/once_lock.rs +++ b/sgx_sync/src/once_lock.rs @@ -227,7 +227,7 @@ unsafe impl Send for OnceLock {} impl RefUnwindSafe for OnceLock {} impl UnwindSafe for OnceLock {} -impl const Default for OnceLock { +impl Default for OnceLock { /// Creates a new empty cell. /// fn default() -> OnceLock { diff --git a/sgx_trts/src/feature/mod.rs b/sgx_trts/src/feature/mod.rs index 869e0ab37..ddedba0ad 100644 --- a/sgx_trts/src/feature/mod.rs +++ b/sgx_trts/src/feature/mod.rs @@ -203,6 +203,10 @@ macro_rules! is_x86_feature_detected { ("pconfig") => { $crate::feature::check_for($crate::feature::Feature::pconfig) }; + // surely supported on SGX2 platforms (that we require) + ("cmpxchg16b") => { + true + }; ($t:tt,) => { is_x86_feature_detected!($t); }; diff --git a/sgx_trts/src/lib.rs b/sgx_trts/src/lib.rs index 1325de094..32823cae1 100644 --- a/sgx_trts/src/lib.rs +++ b/sgx_trts/src/lib.rs @@ -19,6 +19,7 @@ #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] +#![allow(internal_features)] #![feature(allocator_api)] #![feature(const_trait_impl)] #![feature(core_intrinsics)] @@ -29,10 +30,10 @@ #![feature(never_type)] #![feature(ptr_internals)] #![feature(thread_local)] -#![cfg_attr(feature = "sim", feature(unchecked_math))] #![allow(clippy::missing_safety_doc)] #![allow(dead_code)] #![allow(non_camel_case_types)] +#![allow(static_mut_refs)] #[cfg(all(feature = "sim", feature = "hyper"))] compile_error!("feature \"sim\" and feature \"hyper\" cannot be enabled at the same time"); diff --git a/sgx_trts/src/sync/lazy.rs b/sgx_trts/src/sync/lazy.rs index 10aa1b2b5..390a41dc3 100644 --- a/sgx_trts/src/sync/lazy.rs +++ b/sgx_trts/src/sync/lazy.rs @@ -66,7 +66,7 @@ impl PartialEq for OnceCell { impl Eq for OnceCell {} -impl const From for OnceCell { +impl From for OnceCell { /// Creates a new `OnceCell` which already contains the given `value`. fn from(value: T) -> Self { OnceCell { diff --git a/sgx_tstd/hashbrown/src/lib.rs b/sgx_tstd/hashbrown/src/lib.rs index 6e9592abe..aa6ca4a9d 100644 --- a/sgx_tstd/hashbrown/src/lib.rs +++ b/sgx_tstd/hashbrown/src/lib.rs @@ -10,6 +10,7 @@ //! [CppCon talk]: https://www.youtube.com/watch?v=ncHmEUmJZf4 #![no_std] +#![allow(internal_features)] #![cfg_attr( feature = "nightly", feature( @@ -20,8 +21,7 @@ extend_one, allocator_api, slice_ptr_get, - maybe_uninit_array_assume_init, - strict_provenance + maybe_uninit_array_assume_init ) )] #![allow( @@ -36,6 +36,7 @@ )] #![warn(missing_docs)] #![warn(rust_2018_idioms)] +#![feature(strict_provenance_lints)] #![cfg_attr(feature = "nightly", warn(fuzzy_provenance_casts))] #[cfg(test)] diff --git a/sgx_tstd/hashbrown/src/raw/mod.rs b/sgx_tstd/hashbrown/src/raw/mod.rs index 25c5d1c4d..01ef6e001 100644 --- a/sgx_tstd/hashbrown/src/raw/mod.rs +++ b/sgx_tstd/hashbrown/src/raw/mod.rs @@ -57,16 +57,6 @@ use core::convert::identity as unlikely; #[cfg(feature = "nightly")] use core::intrinsics::{likely, unlikely}; -// Use strict provenance functions if available. -#[cfg(feature = "nightly")] -use core::ptr::invalid_mut; -// Implement it with a cast otherwise. -#[cfg(not(feature = "nightly"))] -#[inline(always)] -fn invalid_mut(addr: usize) -> *mut T { - addr as *mut T -} - #[inline] unsafe fn offset_from(to: *const T, from: *const T) -> usize { to.offset_from(from) as usize @@ -379,7 +369,7 @@ impl Bucket { // won't overflow because index must be less than length (bucket_mask) // and bucket_mask is guaranteed to be less than `isize::MAX` // (see TableLayout::calculate_layout_for method) - invalid_mut(index + 1) + ptr::without_provenance_mut(index + 1) } else { base.as_ptr().sub(index) }; @@ -516,7 +506,7 @@ impl Bucket { if T::IS_ZERO_SIZED { // Just return an arbitrary ZST pointer which is properly aligned // invalid pointer is good enough for ZST - invalid_mut(mem::align_of::()) + ptr::without_provenance_mut(mem::align_of::()) } else { unsafe { self.ptr.as_ptr().sub(1) } } @@ -563,7 +553,7 @@ impl Bucket { unsafe fn next_n(&self, offset: usize) -> Self { let ptr = if T::IS_ZERO_SIZED { // invalid pointer is good enough for ZST - invalid_mut(self.ptr.as_ptr() as usize + offset) + ptr::without_provenance_mut(self.ptr.as_ptr() as usize + offset) } else { self.ptr.as_ptr().sub(offset) }; diff --git a/sgx_tstd/src/hash/random.rs b/sgx_tstd/src/hash/random.rs index 56a27be83..63cd357a2 100644 --- a/sgx_tstd/src/hash/random.rs +++ b/sgx_tstd/src/hash/random.rs @@ -118,7 +118,7 @@ impl DefaultHasher { #[inline] #[allow(deprecated)] #[must_use] - pub const fn new() -> DefaultHasher { + pub fn new() -> DefaultHasher { DefaultHasher(SipHasher13::new_with_keys(0, 0)) } } diff --git a/sgx_tstd/src/io/mod.rs b/sgx_tstd/src/io/mod.rs index a69119386..71d664b53 100644 --- a/sgx_tstd/src/io/mod.rs +++ b/sgx_tstd/src/io/mod.rs @@ -539,10 +539,7 @@ where F: FnOnce(&mut [u8]) -> Result, { let n = read(cursor.ensure_init().init_mut())?; - unsafe { - // SAFETY: we initialised using `ensure_init` so there is no uninit data to advance to. - cursor.advance(n); - } + cursor.advance(n); Ok(()) } diff --git a/sgx_tstd/src/io/util.rs b/sgx_tstd/src/io/util.rs index 4e1b335f5..f2cf7dce8 100644 --- a/sgx_tstd/src/io/util.rs +++ b/sgx_tstd/src/io/util.rs @@ -202,10 +202,7 @@ impl Read for Repeat { let remaining = buf.capacity(); - // SAFETY: the entire unfilled portion of buf has been initialized - unsafe { - buf.advance(remaining); - } + buf.advance(remaining); Ok(()) } diff --git a/sgx_tstd/src/lib.rs b/sgx_tstd/src/lib.rs index e8887de34..7ea24564c 100644 --- a/sgx_tstd/src/lib.rs +++ b/sgx_tstd/src/lib.rs @@ -34,14 +34,15 @@ #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] #![needs_panic_runtime] -#![allow(non_camel_case_types)] -#![allow(unused_must_use)] #![allow(dead_code)] #![allow(deprecated)] #![allow(incomplete_features)] #![allow(internal_features)] +#![allow(non_camel_case_types)] +#![allow(static_mut_refs)] #![allow(unused_assignments)] - #![allow(unused_features)] +#![allow(unused_features)] +#![allow(unused_must_use)] #![allow(clippy::assertions_on_constants)] #![allow(clippy::err_expect)] #![allow(clippy::explicit_auto_deref)] @@ -62,9 +63,7 @@ #![feature(allocator_internals)] #![feature(allow_internal_unsafe)] #![feature(allow_internal_unstable)] -#![feature(c_unwind)] #![feature(concat_idents)] -#![feature(const_mut_refs)] #![feature(const_trait_impl)] #![feature(decl_macro)] #![feature(dropck_eyepatch)] @@ -81,7 +80,7 @@ #![feature(thread_local)] #![feature(try_blocks)] #![feature(type_alias_impl_trait)] -#![feature(utf8_chunks)] +// #![feature(utf8_chunks)] // // Library features (core): // tidy-alphabetical-start @@ -90,29 +89,25 @@ #![feature(core_io_borrowed_buf)] #![feature(duration_constants)] #![feature(error_generic_member_access)] -#![feature(error_in_core)] #![feature(error_iter)] #![feature(exact_size_is_empty)] #![feature(exclusive_wrapper)] #![feature(extend_one)] #![feature(float_minimum_maximum)] +#![feature(fmt_internals)] #![feature(hasher_prefixfree_extras)] #![feature(hashmap_internals)] #![feature(ip)] -#![feature(ip_in_core)] #![feature(maybe_uninit_slice)] #![feature(maybe_uninit_uninit_array)] #![feature(maybe_uninit_write_slice)] #![feature(panic_can_unwind)] -#![feature(panic_info_message)] #![feature(panic_internals)] #![feature(prelude_2024)] #![feature(ptr_as_uninit)] -#![feature(raw_os_nonzero)] #![feature(slice_internals)] #![feature(std_internals)] #![feature(str_internals)] -#![feature(strict_provenance)] #![feature(type_ascription)] // tidy-alphabetical-end // @@ -121,7 +116,6 @@ #![feature(allocator_api)] #![feature(get_mut_unchecked)] #![feature(map_try_insert)] -#![feature(new_uninit)] #![feature(slice_concat_trait)] #![feature(try_reserve_kind)] #![feature(vec_into_raw_parts)] @@ -141,23 +135,14 @@ #![feature(cfg_eval)] #![feature(concat_bytes)] #![feature(const_format_args)] -#![feature(core_panic)] #![feature(custom_test_frameworks)] #![feature(edition_panic)] #![feature(format_args_nl)] -#![feature(lazy_cell)] #![feature(log_syntax)] #![feature(test)] #![feature(trace_macros)] // tidy-alphabetical-end // -// Only used in tests/benchmarks: -// -// Only for const-ness: -// tidy-alphabetical-start -#![feature(const_hash)] -// tidy-alphabetical-end -// #![default_lib_allocator] @@ -255,6 +240,30 @@ pub mod thread; pub mod ascii; #[cfg(feature = "backtrace")] pub mod backtrace; +// some libraries (typically anyhow) always assume backtrace is available when using std +#[cfg(not(feature = "backtrace"))] +pub mod backtrace { + pub struct Backtrace(); + impl Backtrace { + pub fn capture() -> Backtrace { + Backtrace() + } + pub fn status(&self) -> BacktraceStatus { + BacktraceStatus::Unsupported + } + } + impl crate::fmt::Display for Backtrace { + fn fmt(&self, fmt: &mut crate::fmt::Formatter<'_>) -> crate::fmt::Result { + fmt.write_str("unsupported backtrace") + } + } + pub enum BacktraceStatus { + Unsupported, + Disabled, + Captured, + } +} + pub mod collections; pub mod env; pub mod error; diff --git a/sgx_tstd/src/num.rs b/sgx_tstd/src/num.rs index 2e2d7cb99..be8558fd6 100644 --- a/sgx_tstd/src/num.rs +++ b/sgx_tstd/src/num.rs @@ -28,7 +28,7 @@ mod tests; #[cfg(feature = "unit_test")] mod benches; -pub use core::num::Wrapping; +pub use core::num::{Saturating, Wrapping}; pub use core::num::{FpCategory, ParseFloatError, ParseIntError, TryFromIntError}; pub use core::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize}; pub use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize}; diff --git a/sgx_tstd/src/panic.rs b/sgx_tstd/src/panic.rs index 1af078cf0..991660d3f 100644 --- a/sgx_tstd/src/panic.rs +++ b/sgx_tstd/src/panic.rs @@ -19,34 +19,193 @@ use crate::any::Any; use crate::collections; +use crate::fmt; use crate::panicking; #[cfg(feature = "backtrace")] use crate::sync::atomic::{AtomicUsize, Ordering}; use crate::sync::{Mutex, RwLock}; use crate::thread::Result; -#[doc(hidden)] -#[allow_internal_unstable(libstd_sys_internals, const_format_args, core_panic, rt)] -#[cfg_attr(not(test), rustc_diagnostic_item = "std_panic_2015_macro")] -#[rustc_macro_transparency = "semitransparent"] -pub macro panic_2015 { - () => ({ - $crate::rt::begin_panic("explicit panic") - }), - ($msg:expr $(,)?) => ({ - $crate::rt::begin_panic($msg); - }), - // Special-case the single-argument case for const_panic. - ("{}", $arg:expr $(,)?) => ({ - $crate::rt::panic_display(&$arg); - }), - ($fmt:expr, $($arg:tt)+) => ({ - // Semicolon to prevent temporaries inside the formatting machinery from - // being considered alive in the caller after the panic_fmt call. - $crate::rt::panic_fmt($crate::const_format_args!($fmt, $($arg)+)); - }), +/// A struct providing information about a panic. +/// +/// `PanicHookInfo` structure is passed to a panic hook set by the [`set_hook`] function. +/// +/// # Examples +/// +/// ```should_panic +/// use std::panic; +/// +/// panic::set_hook(Box::new(|panic_info| { +/// println!("panic occurred: {panic_info}"); +/// })); +/// +/// panic!("critical system failure"); +/// ``` +/// +/// [`set_hook`]: ../../std/panic/fn.set_hook.html +#[derive(Debug)] +pub struct PanicHookInfo<'a> { + payload: &'a (dyn Any + Send), + location: &'a Location<'a>, + can_unwind: bool, + force_no_backtrace: bool, } +impl<'a> PanicHookInfo<'a> { + #[inline] + pub(crate) fn new( + location: &'a Location<'a>, + payload: &'a (dyn Any + Send), + can_unwind: bool, + force_no_backtrace: bool, + ) -> Self { + PanicHookInfo { payload, location, can_unwind, force_no_backtrace } + } + + /// Returns the payload associated with the panic. + /// + /// This will commonly, but not always, be a `&'static str` or [`String`]. + /// + /// A invocation of the `panic!()` macro in Rust 2021 or later will always result in a + /// panic payload of type `&'static str` or `String`. + /// + /// Only an invocation of [`panic_any`] + /// (or, in Rust 2018 and earlier, `panic!(x)` where `x` is something other than a string) + /// can result in a panic payload other than a `&'static str` or `String`. + /// + /// [`String`]: ../../std/string/struct.String.html + /// + /// # Examples + /// + /// ```should_panic + /// use std::panic; + /// + /// panic::set_hook(Box::new(|panic_info| { + /// if let Some(s) = panic_info.payload().downcast_ref::<&str>() { + /// println!("panic occurred: {s:?}"); + /// } else if let Some(s) = panic_info.payload().downcast_ref::() { + /// println!("panic occurred: {s:?}"); + /// } else { + /// println!("panic occurred"); + /// } + /// })); + /// + /// panic!("Normal panic"); + /// ``` + #[must_use] + #[inline] + pub fn payload(&self) -> &(dyn Any + Send) { + self.payload + } + + /// Returns the payload associated with the panic, if it is a string. + /// + /// This returns the payload if it is of type `&'static str` or `String`. + /// + /// A invocation of the `panic!()` macro in Rust 2021 or later will always result in a + /// panic payload where `payload_as_str` returns `Some`. + /// + /// Only an invocation of [`panic_any`] + /// (or, in Rust 2018 and earlier, `panic!(x)` where `x` is something other than a string) + /// can result in a panic payload where `payload_as_str` returns `None`. + /// + /// # Example + /// + /// ```should_panic + /// #![feature(panic_payload_as_str)] + /// + /// std::panic::set_hook(Box::new(|panic_info| { + /// if let Some(s) = panic_info.payload_as_str() { + /// println!("panic occurred: {s:?}"); + /// } else { + /// println!("panic occurred"); + /// } + /// })); + /// + /// panic!("Normal panic"); + /// ``` + #[must_use] + #[inline] + pub fn payload_as_str(&self) -> Option<&str> { + if let Some(s) = self.payload.downcast_ref::<&str>() { + Some(s) + } else if let Some(s) = self.payload.downcast_ref::() { + Some(s) + } else { + None + } + } + + /// Returns information about the location from which the panic originated, + /// if available. + /// + /// This method will currently always return [`Some`], but this may change + /// in future versions. + /// + /// # Examples + /// + /// ```should_panic + /// use std::panic; + /// + /// panic::set_hook(Box::new(|panic_info| { + /// if let Some(location) = panic_info.location() { + /// println!("panic occurred in file '{}' at line {}", + /// location.file(), + /// location.line(), + /// ); + /// } else { + /// println!("panic occurred but can't get location information..."); + /// } + /// })); + /// + /// panic!("Normal panic"); + /// ``` + #[must_use] + #[inline] + pub fn location(&self) -> Option<&Location<'_>> { + // NOTE: If this is changed to sometimes return None, + // deal with that case in std::panicking::default_hook and core::panicking::panic_fmt. + Some(&self.location) + } + + /// Returns whether the panic handler is allowed to unwind the stack from + /// the point where the panic occurred. + /// + /// This is true for most kinds of panics with the exception of panics + /// caused by trying to unwind out of a `Drop` implementation or a function + /// whose ABI does not support unwinding. + /// + /// It is safe for a panic handler to unwind even when this function returns + /// false, however this will simply cause the panic handler to be called + /// again. + #[must_use] + #[inline] + pub fn can_unwind(&self) -> bool { + self.can_unwind + } + + #[doc(hidden)] + #[inline] + pub fn force_no_backtrace(&self) -> bool { + self.force_no_backtrace + } +} + +impl fmt::Display for PanicHookInfo<'_> { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + formatter.write_str("panicked at ")?; + self.location.fmt(formatter)?; + if let Some(payload) = self.payload_as_str() { + formatter.write_str(":\n")?; + formatter.write_str(payload)?; + } + Ok(()) + } +} + +#[doc(hidden)] +pub use core::panic::panic_2015; + #[doc(hidden)] pub use core::panic::panic_2021; diff --git a/sgx_tstd/src/panicking.rs b/sgx_tstd/src/panicking.rs index 06eb3a8c3..373e19106 100644 --- a/sgx_tstd/src/panicking.rs +++ b/sgx_tstd/src/panicking.rs @@ -27,6 +27,7 @@ #[cfg(feature = "backtrace")] use crate::panic::BacktraceStyle; use core::panic::{Location, PanicInfo, PanicPayload}; +use crate::panic::PanicHookInfo; use crate::any::Any; use crate::fmt; @@ -84,12 +85,12 @@ extern "C" fn __rust_foreign_exception() -> ! { enum Hook { Default, - Custom(Box) + 'static + Sync + Send>), + Custom(Box) + 'static + Sync + Send>), } impl Hook { #[inline] - fn into_box(self) -> Box) + 'static + Sync + Send> { + fn into_box(self) -> Box) + 'static + Sync + Send> { match self { Hook::Default => Box::new(default_hook), Hook::Custom(hook) => hook, @@ -142,7 +143,7 @@ static HOOK: RwLock = RwLock::new(Hook::Default); /// /// panic!("Normal panic"); /// ``` -pub fn set_hook(hook: Box) + 'static + Sync + Send>) { +pub fn set_hook(hook: Box) + 'static + Sync + Send>) { if thread::panicking() { panic!("cannot modify the panic hook from a panicking thread"); } @@ -185,7 +186,7 @@ pub fn set_hook(hook: Box) + 'static + Sync + Send>) { /// panic!("Normal panic"); /// ``` #[must_use] -pub fn take_hook() -> Box) + 'static + Sync + Send> { +pub fn take_hook() -> Box) + 'static + Sync + Send> { if thread::panicking() { panic!("cannot modify the panic hook from a panicking thread"); } @@ -230,7 +231,7 @@ pub fn take_hook() -> Box) + 'static + Sync + Send> { /// ``` pub fn update_hook(hook_fn: F) where - F: Fn(&(dyn Fn(&PanicInfo<'_>) + Send + Sync + 'static), &PanicInfo<'_>) + F: Fn(&(dyn Fn(&PanicHookInfo<'_>) + Send + Sync + 'static), &PanicHookInfo<'_>) + Sync + Send + 'static, @@ -245,11 +246,11 @@ where } #[cfg(not(feature = "stdio"))] -fn default_hook(_info: &PanicInfo<'_>) {} +fn default_hook(_info: &PanicHookInfo<'_>) {} /// The default panic handler. #[cfg(feature = "stdio")] -fn default_hook(info: &PanicInfo<'_>) { +fn default_hook(info: &PanicHookInfo<'_>) { // If this is a double panic, make sure that we print a backtrace // for this panic. Otherwise only print it if logging is enabled. #[cfg(feature = "backtrace")] @@ -432,7 +433,6 @@ pub mod panic_count { } } -/// Invoke a closure, capturing the cause of an unwinding panic if one occurs. /// Invoke a closure, capturing the cause of an unwinding panic if one occurs. pub unsafe fn r#try R>(f: F) -> Result> { union Data { @@ -478,7 +478,7 @@ pub unsafe fn r#try R>(f: F) -> Result> // - `do_catch`, the second argument, can be called with the `data_ptr` as well. // See their safety preconditions for more information unsafe { - return if intrinsics::r#try(do_call::, data_ptr, do_catch::) == 0 { + return if intrinsics::catch_unwind(do_call::, data_ptr, do_catch::) == 0 { Ok(ManuallyDrop::into_inner(data.r)) } else { Err(ManuallyDrop::into_inner(data.p)) @@ -556,29 +556,24 @@ pub fn panicking() -> bool { #[panic_handler] pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { struct FormatStringPayload<'a> { - inner: &'a fmt::Arguments<'a>, + inner: &'a core::panic::PanicMessage<'a>, string: Option, } - impl<'a> FormatStringPayload<'a> { - fn new(inner: &'a fmt::Arguments<'a>) -> Self { - Self { inner, string: None } - } - + impl FormatStringPayload<'_> { fn fill(&mut self) -> &mut String { - use crate::fmt::Write; - let inner = self.inner; // Lazily, the first time this gets called, run the actual string formatting. self.string.get_or_insert_with(|| { let mut s = String::new(); - let _err = s.write_fmt(*inner); + let mut fmt = fmt::Formatter::new(&mut s); + let _err = fmt::Display::fmt(&inner, &mut fmt); s }) } } - unsafe impl<'a> PanicPayload for FormatStringPayload<'a> { + unsafe impl PanicPayload for FormatStringPayload<'_> { fn take_box(&mut self) -> *mut (dyn Any + Send) { // We do two allocations here, unfortunately. But (a) they're required with the current // scheme, and (b) we don't handle panic + OOM properly anyway (see comment in @@ -592,6 +587,16 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { } } + impl fmt::Display for FormatStringPayload<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if let Some(s) = &self.string { + f.write_str(s) + } else { + fmt::Display::fmt(&self.inner, f) + } + } + } + struct StaticStrPayload(&'static str); unsafe impl PanicPayload for StaticStrPayload { @@ -602,27 +607,33 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { fn get(&mut self) -> &(dyn Any + Send) { &self.0 } + + fn as_str(&mut self) -> Option<&str> { + Some(self.0) + } + } + + impl fmt::Display for StaticStrPayload { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.0) + } } let loc = info.location().unwrap(); // The current implementation always returns Some - let msg = info.message().unwrap(); // The current implementation always returns Some + let msg = info.message(); #[cfg(feature = "backtrace")] { - crate::sys_common::backtrace::__rust_end_short_backtrace(move || { - // FIXME: can we just pass `info` along rather than taking it apart here, only to have - // `rust_panic_with_hook` construct a new `PanicInfo`? - if let Some(msg) = msg.as_str() { + crate::sys::backtrace::__rust_end_short_backtrace(move || { + if let Some(s) = msg.as_str() { rust_panic_with_hook( - &mut StaticStrPayload(msg), - info.message(), + &mut StaticStrPayload(s), loc, info.can_unwind(), info.force_no_backtrace(), ); } else { rust_panic_with_hook( - &mut FormatStringPayload::new(msg), - info.message(), + &mut FormatStringPayload { inner: &msg, string: None }, loc, info.can_unwind(), info.force_no_backtrace(), @@ -632,21 +643,19 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { } #[cfg(not(feature = "backtrace"))] { - if let Some(msg) = msg.as_str() { + if let Some(s) = msg.as_str() { rust_panic_with_hook( - &mut StaticStrPayload(msg), - info.message(), + &mut StaticStrPayload(s), loc, info.can_unwind(), - /* force_no_backtrace */ true, + info.force_no_backtrace(), ); } else { rust_panic_with_hook( - &mut FormatStringPayload::new(msg), - info.message(), + &mut FormatStringPayload { inner: &msg, string: None }, loc, info.can_unwind(), - /* force_no_backtrace */ true, + info.force_no_backtrace(), ); } } @@ -696,12 +705,21 @@ pub const fn begin_panic(msg: M) -> ! { } } + impl fmt::Display for Payload { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match &self.inner { + Some(a) => f.write_str(payload_as_str(a)), + None => crate::sys::abort_internal(), + } + } + } + let loc = Location::caller(); - #[cfg(feature = "backtrace")] { - crate::sys_common::backtrace::__rust_end_short_backtrace(move || { + #[cfg(feature = "backtrace")] + { + crate::sys::backtrace::__rust_end_short_backtrace(move || { rust_panic_with_hook( &mut Payload::new(msg), - None, loc, /* can_unwind */ true, /* force_no_backtrace */ false, @@ -711,7 +729,6 @@ pub const fn begin_panic(msg: M) -> ! { #[cfg(not(feature = "backtrace"))] { rust_panic_with_hook( &mut Payload::new(msg), - None, loc, /* can_unwind */ true, /* force_no_backtrace */ true, @@ -719,6 +736,16 @@ pub const fn begin_panic(msg: M) -> ! { } } +fn payload_as_str(payload: &dyn Any) -> &str { + if let Some(&s) = payload.downcast_ref::<&'static str>() { + s + } else if let Some(s) = payload.downcast_ref::() { + s.as_str() + } else { + "Box" + } +} + /// Central point for dispatching panics. /// /// Executes the primary logic for a panic, including checking for recursive @@ -726,7 +753,6 @@ pub const fn begin_panic(msg: M) -> ! { /// abort or unwind. fn rust_panic_with_hook( payload: &mut dyn PanicPayload, - message: Option<&fmt::Arguments<'_>>, location: &Location<'_>, can_unwind: bool, force_no_backtrace: bool, @@ -737,27 +763,21 @@ fn rust_panic_with_hook( if let Some(must_abort) = must_abort { match must_abort { panic_count::MustAbort::PanicInHook => { - // Don't try to print the message in this case - // - perhaps that is causing the recursive panics. - rtprintpanic!("thread panicked while processing panic. aborting.\n"); + // Don't try to format the message in this case, perhaps that is causing the + // recursive panics. However if the message is just a string, no user-defined + // code is involved in printing it, so that is risk-free. + let message: &str = payload.as_str().unwrap_or_default(); + rtprintpanic!( + "panicked at {location}:\n{message}\nthread panicked while processing panic. aborting.\n" + ); } panic_count::MustAbort::AlwaysAbort => { - // Unfortunately, this does not print a backtrace, because creating - // a `Backtrace` will allocate, which we must to avoid here. - let panicinfo = PanicInfo::internal_constructor( - message, - location, - can_unwind, - force_no_backtrace, - ); - rtprintpanic!("{panicinfo}\npanicked after panic::always_abort(), aborting.\n"); + rtprintpanic!("aborting due to panic at {location}:\n{payload}\n"); } } crate::sys::abort_internal(); } - let mut info = - PanicInfo::internal_constructor(message, location, can_unwind, force_no_backtrace); let hook = HOOK.read().unwrap_or_else(PoisonError::into_inner); match *hook { // Some platforms (like wasm) know that printing to stderr won't ever actually @@ -769,12 +789,15 @@ fn rust_panic_with_hook( #[cfg(feature = "stdio")] Hook::Default if panic_output().is_none() => {} Hook::Default => { - info.set_payload(payload.get()); - default_hook(&info); + default_hook(&PanicHookInfo::new( + location, + payload.get(), + can_unwind, + force_no_backtrace, + )); } Hook::Custom(ref hook) => { - info.set_payload(payload.get()); - hook(&info); + hook(&PanicHookInfo::new(location, payload.get(), can_unwind, force_no_backtrace)); } }; drop(hook); @@ -812,6 +835,12 @@ pub fn rust_panic_without_hook(payload: Box) -> ! { } } + impl fmt::Display for RewrapBox { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(payload_as_str(&self.0)) + } + } + rust_panic(&mut RewrapBox(payload)) } diff --git a/sgx_tstd/src/prelude/v1.rs b/sgx_tstd/src/prelude/v1.rs index 8ea33cdf2..838739022 100644 --- a/sgx_tstd/src/prelude/v1.rs +++ b/sgx_tstd/src/prelude/v1.rs @@ -53,9 +53,6 @@ pub use core::prelude::v1::{ #[doc(no_inline)] pub use core::prelude::v1::concat_bytes; -#[allow(deprecated)] -pub use core::prelude::v1::{RustcDecodable, RustcEncodable}; - // Do not `doc(no_inline)` so that they become doc items on their own // (no public module for them to be re-exported from). pub use core::prelude::v1::{ diff --git a/sgx_tstd/src/sys/common/thread_local/os_local.rs b/sgx_tstd/src/sys/common/thread_local/os_local.rs index 4f4daace8..c3579e051 100644 --- a/sgx_tstd/src/sys/common/thread_local/os_local.rs +++ b/sgx_tstd/src/sys/common/thread_local/os_local.rs @@ -191,7 +191,7 @@ unsafe extern "C" fn destroy_value(ptr: *mut u8) { let ret = panic::catch_unwind(|| unsafe { let ptr = Box::from_raw(ptr as *mut Value); let key = ptr.key; - key.os.set(ptr::invalid_mut(1)); + key.os.set(ptr::without_provenance_mut(1)); drop(ptr); key.os.set(ptr::null_mut()); }); diff --git a/sgx_tstd/src/sys/fd.rs b/sgx_tstd/src/sys/fd.rs index c140f2fcc..9d24b5924 100644 --- a/sgx_tstd/src/sys/fd.rs +++ b/sgx_tstd/src/sys/fd.rs @@ -66,10 +66,8 @@ impl FileDesc { libc::read(self.as_raw_fd(), MaybeUninit::slice_assume_init_mut(cursor.as_mut())) })?; - // Safety: `ret` bytes were written to the initialized portion of the buffer - unsafe { - cursor.advance(ret); - } + cursor.advance(ret); + Ok(()) } diff --git a/sgx_tstd/src/sys/net.rs b/sgx_tstd/src/sys/net.rs index 18fa2bc67..8c78f8ae4 100644 --- a/sgx_tstd/src/sys/net.rs +++ b/sgx_tstd/src/sys/net.rs @@ -195,9 +195,9 @@ impl Socket { flags, ) })?; - unsafe { - buf.advance(ret as usize); - } + + buf.advance(ret as usize); + Ok(()) } diff --git a/sgx_tstd/src/sys/os_str.rs b/sgx_tstd/src/sys/os_str.rs index 58322a8d7..1ca471d29 100644 --- a/sgx_tstd/src/sys/os_str.rs +++ b/sgx_tstd/src/sys/os_str.rs @@ -28,8 +28,6 @@ use crate::str; use crate::sync::Arc; use crate::sys_common::{AsInner, IntoInner}; -use core::str::Utf8Chunks; - #[cfg(feature = "unit_test")] mod tests; @@ -46,7 +44,7 @@ pub struct Slice { impl fmt::Debug for Slice { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(&Utf8Chunks::new(&self.inner).debug(), f) + fmt::Debug::fmt(&self.inner.utf8_chunks().debug(), f) } } @@ -58,7 +56,7 @@ impl fmt::Display for Slice { return "".fmt(f); } - for chunk in Utf8Chunks::new(&self.inner) { + for chunk in self.inner.utf8_chunks() { let valid = chunk.valid(); // If we successfully decoded the whole chunk as a valid string then // we can return a direct formatting of the string which will also diff --git a/sgx_tstd/src/sys/personality/dwarf/eh.rs b/sgx_tstd/src/sys/personality/dwarf/eh.rs index 9886c72d6..e5c24d90b 100644 --- a/sgx_tstd/src/sys/personality/dwarf/eh.rs +++ b/sgx_tstd/src/sys/personality/dwarf/eh.rs @@ -142,7 +142,7 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>) -> Result // Can never have null landing pad for sjlj -- that would have // been indicated by a -1 call site index. // FIXME(strict provenance) - let lpad = ptr::from_exposed_addr((cs_lpad + 1) as usize); + let lpad = ptr::with_exposed_provenance((cs_lpad + 1) as usize); return Ok(interpret_cs_action(action_table, cs_action_entry, lpad)); } } diff --git a/sgx_tstd/src/sys/unsupported/process.rs b/sgx_tstd/src/sys/unsupported/process.rs index 832c823e2..f390bdd11 100644 --- a/sgx_tstd/src/sys/unsupported/process.rs +++ b/sgx_tstd/src/sys/unsupported/process.rs @@ -29,7 +29,7 @@ use crate::sys::unsupported::pipe::AnonPipe; use crate::sys::unsupported::{unsupported, unsupported_err}; use crate::sys_common::IntoInner; use crate::sys_common::process::{CommandEnv, CommandEnvs}; -use core::ffi::NonZero_c_int; +use core::num::NonZero; use sgx_oc as libc; use libc::{c_int, gid_t, pid_t, uid_t}; @@ -197,7 +197,7 @@ impl ExitStatus { // https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html . If it is not // true for a platform pretending to be Unix, the tests (our doctests, and also // procsss_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too. - match NonZero_c_int::try_from(self.0) { + match NonZero::::try_from(self.0) { /* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)), /* was zero, couldn't convert */ Err(_) => Ok(()), } @@ -301,7 +301,7 @@ impl fmt::Display for ExitStatus { } #[derive(PartialEq, Eq, Clone, Copy)] -pub struct ExitStatusError(NonZero_c_int); +pub struct ExitStatusError(NonZero); #[allow(clippy::from_over_into)] impl Into for ExitStatusError { diff --git a/sgx_types/src/lib.rs b/sgx_types/src/lib.rs index f43a1cb1b..b94da4f94 100644 --- a/sgx_types/src/lib.rs +++ b/sgx_types/src/lib.rs @@ -16,7 +16,6 @@ // under the License.. #![no_std] -#![feature(error_in_core)] #![feature(min_specialization)] #![allow(clippy::upper_case_acronyms)] #![allow(non_camel_case_types)] diff --git a/sgx_unwind/src/lib.rs b/sgx_unwind/src/lib.rs index a677a9466..92b3884ef 100644 --- a/sgx_unwind/src/lib.rs +++ b/sgx_unwind/src/lib.rs @@ -19,7 +19,6 @@ #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] #![unstable(feature = "panic_unwind", issue = "32837")] #![feature(staged_api)] -#![feature(c_unwind)] #![allow(internal_features)] #![allow(clippy::upper_case_acronyms)] From 1a777e39831640860b6e275b1cd94311124689e7 Mon Sep 17 00:00:00 2001 From: Edward Boggis-Rolfe Date: Tue, 17 Dec 2024 13:16:06 +0000 Subject: [PATCH 13/34] Add more headers to complement SGX SDK ones (#1) --------- Co-authored-by: Edward Boggis-Rolfe --- .../edl/sgx_sdk_additional_include/netdb.h | 13 +++ .../sgx_sdk_additional_include/netinet/in.h | 85 +++++++++++++++++++ .../edl/sgx_sdk_additional_include/sched.h | 2 +- .../sgx_sdk_additional_include/sys/epoll.h | 2 +- .../sgx_sdk_additional_include/sys/socket.h | 1 - .../sys/struct_timespec.h | 41 +++++++++ 6 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 sgx_edl/edl/sgx_sdk_additional_include/netinet/in.h create mode 100644 sgx_edl/edl/sgx_sdk_additional_include/sys/struct_timespec.h diff --git a/sgx_edl/edl/sgx_sdk_additional_include/netdb.h b/sgx_edl/edl/sgx_sdk_additional_include/netdb.h index db1433842..adefbbea6 100644 --- a/sgx_edl/edl/sgx_sdk_additional_include/netdb.h +++ b/sgx_edl/edl/sgx_sdk_additional_include/netdb.h @@ -49,6 +49,19 @@ __BEGIN_DECLS // ocall int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict); void freeaddrinfo (struct addrinfo *); +/* Description of data base entry for a single host. */ + +struct hostent +{ + char *h_name; /* Official name of host. */ + char **h_aliases; /* Alias list. */ + int h_addrtype; /* Host address type. */ + int h_length; /* Length of address. */ + char **h_addr_list; /* List of addresses from name server. */ +#ifdef __USE_MISC +# define h_addr h_addr_list[0] /* Address, for backward compatibility.*/ +#endif +}; __END_DECLS diff --git a/sgx_edl/edl/sgx_sdk_additional_include/netinet/in.h b/sgx_edl/edl/sgx_sdk_additional_include/netinet/in.h new file mode 100644 index 000000000..242c8100f --- /dev/null +++ b/sgx_edl/edl/sgx_sdk_additional_include/netinet/in.h @@ -0,0 +1,85 @@ +/* Copyright (C) 1991-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#pragma once + +#include +#include +#include +#include + +__BEGIN_DECLS + +/* Internet address. */ +typedef uint32_t in_addr_t; +struct in_addr + { + in_addr_t s_addr; + }; + +/* Type to represent a port. */ +typedef uint16_t in_port_t; + + +/* IPv6 address */ +struct in6_addr + { + union + { + uint8_t __u6_addr8[16]; + uint16_t __u6_addr16[8]; + uint32_t __u6_addr32[4]; + } __in6_u; +#define s6_addr __in6_u.__u6_addr8 +#ifdef __USE_MISC +# define s6_addr16 __in6_u.__u6_addr16 +# define s6_addr32 __in6_u.__u6_addr32 +#endif + }; + +extern const struct in6_addr in6addr_any; /* :: */ +extern const struct in6_addr in6addr_loopback; /* ::1 */ +#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } +#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } + +#define INET_ADDRSTRLEN 16 +#define INET6_ADDRSTRLEN 46 + +typedef unsigned short int sa_family_t; + +/* Structure describing an Internet socket address. */ +struct sockaddr_in + { + sa_family_t sin_family; + in_port_t sin_port; /* Port number. */ + struct in_addr sin_addr; /* Internet address. */ + + /* Pad to size of `struct sockaddr'. */ + unsigned char sin_zero[sizeof (struct sockaddr) + - sizeof (unsigned short int) + - sizeof (in_port_t) + - sizeof (struct in_addr)]; + }; + +/* Ditto, for IPv6. */ +struct sockaddr_in6 + { + sa_family_t sin6_family; + in_port_t sin6_port; /* Transport layer port # */ + uint32_t sin6_flowinfo; /* IPv6 flow information */ + struct in6_addr sin6_addr; /* IPv6 address */ + uint32_t sin6_scope_id; /* IPv6 scope-id */ + }; + +__END_DECLS \ No newline at end of file diff --git a/sgx_edl/edl/sgx_sdk_additional_include/sched.h b/sgx_edl/edl/sgx_sdk_additional_include/sched.h index 6738bb985..159956978 100644 --- a/sgx_edl/edl/sgx_sdk_additional_include/sched.h +++ b/sgx_edl/edl/sgx_sdk_additional_include/sched.h @@ -61,7 +61,7 @@ __CPU_op_func_S(XOR, ^) __BEGIN_DECLS -typedef unsigned int pid_t; +typedef int pid_t; // ocall int sched_yield(void); diff --git a/sgx_edl/edl/sgx_sdk_additional_include/sys/epoll.h b/sgx_edl/edl/sgx_sdk_additional_include/sys/epoll.h index 5f61d356e..386e569c1 100644 --- a/sgx_edl/edl/sgx_sdk_additional_include/sys/epoll.h +++ b/sgx_edl/edl/sgx_sdk_additional_include/sys/epoll.h @@ -27,7 +27,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef _SYS_EPOLL_H_ #define _SYS_EPOLL_H_ -#include +#include typedef union epoll_data { void *ptr; diff --git a/sgx_edl/edl/sgx_sdk_additional_include/sys/socket.h b/sgx_edl/edl/sgx_sdk_additional_include/sys/socket.h index 7a7078618..5c548f804 100644 --- a/sgx_edl/edl/sgx_sdk_additional_include/sys/socket.h +++ b/sgx_edl/edl/sgx_sdk_additional_include/sys/socket.h @@ -28,7 +28,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #define _SYS_SOCKET_H_ #include -#include #include #include diff --git a/sgx_edl/edl/sgx_sdk_additional_include/sys/struct_timespec.h b/sgx_edl/edl/sgx_sdk_additional_include/sys/struct_timespec.h new file mode 100644 index 000000000..ba86e3839 --- /dev/null +++ b/sgx_edl/edl/sgx_sdk_additional_include/sys/struct_timespec.h @@ -0,0 +1,41 @@ +// +// Copyright © 2005-2020 Rich Felker, et al. +// Licensed under the MIT license. +// + +/* Copyright © 2005-2020 Rich Felker, et al. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#ifndef _SYS_TIMESPEC_H_ +#define _SYS_TIMESPEC_H_ + +#ifdef _IN_ENCLAVE + +#include + +struct timespec { + __time_t tv_sec; + long tv_nsec; +}; + +#endif /* _IN_ENCLAVE*/ + +#endif /* _SYS_TIMESPEC_H_ */ From fb01dae28cfd9a9eba98c25b8bba54f523fd1752 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Lafay Date: Tue, 21 Jan 2025 13:07:17 +0100 Subject: [PATCH 14/34] Support intel-sgx-sdk 2.25 The global_data_t struct has a couple of new fields, and more important, the elrange_size field now defaults to 0 instead of enclave_size. --- sgx_trts/src/arch.rs | 2 ++ sgx_trts/src/enclave/mem.rs | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sgx_trts/src/arch.rs b/sgx_trts/src/arch.rs index 86106a98b..090d22926 100644 --- a/sgx_trts/src/arch.rs +++ b/sgx_trts/src/arch.rs @@ -423,6 +423,8 @@ pub struct Global { pub elrange_start_base: u64, pub elrange_size: u64, pub edmm_bk_overhead: usize, + pub fips_on: u32, + pub reserved2: u32, } #[repr(C, packed)] diff --git a/sgx_trts/src/enclave/mem.rs b/sgx_trts/src/enclave/mem.rs index 7658bb28e..2ea9a70ca 100644 --- a/sgx_trts/src/enclave/mem.rs +++ b/sgx_trts/src/enclave/mem.rs @@ -158,7 +158,13 @@ impl Image { #[inline] fn elrange_size() -> usize { - arch::Global::get().elrange_size as usize + let global_data = arch::Global::get(); + + if global_data.elrange_size != 0 { + global_data.elrange_size as usize + } else { + global_data.enclave_size + } } #[inline] From b742e7f63a49f0cffd2ab39d9a02cd700413b66b Mon Sep 17 00:00:00 2001 From: bfoing <40759640+bfoing@users.noreply.github.com> Date: Tue, 24 Feb 2026 16:29:09 +0000 Subject: [PATCH 15/34] chore: Fix Merge --- sgx_rsrvmm/build.rs | 11 +---------- sgx_trts/src/capi_sgx_sdk.rs | 9 +-------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/sgx_rsrvmm/build.rs b/sgx_rsrvmm/build.rs index 6168a1c55..2915380c5 100644 --- a/sgx_rsrvmm/build.rs +++ b/sgx_rsrvmm/build.rs @@ -15,7 +15,6 @@ // specific language governing permissions and limitations // under the License.. -<<<<<<<< HEAD:sgx_rsrvmm/build.rs use std::env; fn main() -> Result<(), &'static str> { @@ -25,12 +24,4 @@ fn main() -> Result<(), &'static str> { println!("cargo:rustc-cfg=feature=\"use_sgx_sdk\""); } Ok(()) -} -======== -//! Linux and Android-specific networking functionality. - -pub(crate) mod addr; -pub(crate) mod tcp; -#[cfg(feature = "unit_test")] -mod tests; ->>>>>>>> 92e3703d5ad134f0a5e9870700c640044ca70468:sgx_tstd/src/os/net/linux_ext/mod.rs +} \ No newline at end of file diff --git a/sgx_trts/src/capi_sgx_sdk.rs b/sgx_trts/src/capi_sgx_sdk.rs index 163755c96..c7a53a4be 100644 --- a/sgx_trts/src/capi_sgx_sdk.rs +++ b/sgx_trts/src/capi_sgx_sdk.rs @@ -15,7 +15,6 @@ // specific language governing permissions and limitations // under the License.. -<<<<<<<< HEAD:sgx_trts/src/capi_sgx_sdk.rs use crate::enclave::MmLayout; #[inline] @@ -28,10 +27,4 @@ pub extern "C" fn sgx_get_image_base() -> *const u8 { #[no_mangle] pub extern "C" fn sgx_get_heap_base() -> *const u8 { MmLayout::heap_base() as *const u8 -} -======== -#[cfg(feature = "unit_test")] -mod tests; - -pub use crate::sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard}; ->>>>>>>> 92e3703d5ad134f0a5e9870700c640044ca70468:sgx_tstd/src/sync/remutex.rs +} \ No newline at end of file From 00b440785e3a8f970c4bf6fccdda936d20d5f9ef Mon Sep 17 00:00:00 2001 From: volcano Date: Wed, 7 Feb 2024 11:23:08 +0800 Subject: [PATCH 16/34] Fix IPP CPUID initialization to support some AVX512 advanced instruction sets --- .../tcrypto/sgx_common_init_ipp.cpp | 24 +++++++++++++++---- sgx_protected_fs/tfs/src/sys/metadata.rs | 4 ++-- sgx_protected_fs/tfs/src/sys/node.rs | 4 ++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/sgx_common_init_ipp.cpp b/sgx_crypto/sgx_crypto_sys/tcrypto/sgx_common_init_ipp.cpp index b63a064e5..24d661748 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/sgx_common_init_ipp.cpp +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/sgx_common_init_ipp.cpp @@ -101,12 +101,12 @@ extern "C" sgx_status_t init_ipp_cpuid(uint64_t cpu_feature_indicator) { ippCpuFeatures |= ippCPUID_RDSEED; } - if ((cpu_feature_indicator & CPU_FEATURE_SHA) == CPU_FEATURE_SHA) + if ((cpu_feature_indicator & CPU_FEATURE_SHA) == CPU_FEATURE_SHA) { ippCpuFeatures |= ippCPUID_SHA; } - - // AVX512 + + // AVX512 if ((cpu_feature_indicator & CPU_FEATURE_AVX512F) == CPU_FEATURE_AVX512F) { ippCpuFeatures |= ippCPUID_AVX512F; @@ -148,11 +148,26 @@ extern "C" sgx_status_t init_ipp_cpuid(uint64_t cpu_feature_indicator) { ippCpuFeatures |= ippCPUID_AVX512_4FMADDPS; } - + if((cpu_feature_indicator & CPU_FEATURE_VAES) == CPU_FEATURE_VAES) + { + ippCpuFeatures |= ippCPUID_AVX512VAES; + } if ((cpu_feature_indicator & CPU_FEATURE_AVX512IFMA52) == CPU_FEATURE_AVX512IFMA52) { ippCpuFeatures |= ippCPUID_AVX512IFMA; } + if ((cpu_feature_indicator & CPU_FEATURE_GFNI) == CPU_FEATURE_GFNI) + { + ippCpuFeatures |= ippCPUID_AVX512GFNI; + } + if((cpu_feature_indicator & CPU_FEATURE_AVX512_VBMI2) == CPU_FEATURE_AVX512_VBMI2) + { + ippCpuFeatures |= ippCPUID_AVX512VBMI2; + } + if((cpu_feature_indicator & CPU_FEATURE_VPCLMULQDQ) == CPU_FEATURE_VPCLMULQDQ) + { + ippCpuFeatures |= ippCPUID_AVX512VCLMUL; + } } else { @@ -171,4 +186,3 @@ extern "C" sgx_status_t init_ipp_cpuid(uint64_t cpu_feature_indicator) } return SGX_SUCCESS; } - diff --git a/sgx_protected_fs/tfs/src/sys/metadata.rs b/sgx_protected_fs/tfs/src/sys/metadata.rs index 7f0e0f4ae..019765390 100644 --- a/sgx_protected_fs/tfs/src/sys/metadata.rs +++ b/sgx_protected_fs/tfs/src/sys/metadata.rs @@ -248,7 +248,7 @@ impl MetadataInfo { )? } else { let mut aes = AesGcm::new(key, Nonce::zeroed(), Aad::from(&self.encrypted_plain))?; - let mac = aes.encrypt(&[], &mut [])?; + let mac = aes.mac()?; self.node .metadata .ciphertext @@ -276,7 +276,7 @@ impl MetadataInfo { Nonce::zeroed(), Aad::from(&self.node.metadata.ciphertext), )?; - aes.decrypt(&[], &mut [], &self.node.metadata.plaintext.gmac)?; + aes.verify_mac(&self.node.metadata.plaintext.gmac)?; self.encrypted_plain .as_mut() .copy_from_slice(self.node.metadata.ciphertext.as_ref()); diff --git a/sgx_protected_fs/tfs/src/sys/node.rs b/sgx_protected_fs/tfs/src/sys/node.rs index 813aca3ee..853e52923 100644 --- a/sgx_protected_fs/tfs/src/sys/node.rs +++ b/sgx_protected_fs/tfs/src/sys/node.rs @@ -279,7 +279,7 @@ impl FileNode { aes.encrypt(self.plaintext.as_ref(), self.ciphertext.node_data.as_mut())? } else { let mut aes = AesGcm::new(key, Nonce::zeroed(), Aad::from(&self.plaintext))?; - let mac = aes.encrypt(&[], &mut [])?; + let mac = aes.mac()?; self.ciphertext .node_data .as_mut() @@ -312,7 +312,7 @@ impl FileNode { )? } else { let mut aes = AesGcm::new(key, Nonce::zeroed(), Aad::from(&self.ciphertext.node_data))?; - aes.decrypt(&[], &mut [], mac)?; + aes.verify_mac(mac)?; self.plaintext .as_mut() .copy_from_slice(self.ciphertext.node_data.as_ref()); From 613f1d2fd2e11b6d1788127c35dd9323b4ad03e9 Mon Sep 17 00:00:00 2001 From: volcano Date: Tue, 26 Mar 2024 22:38:53 +0800 Subject: [PATCH 17/34] Reimplement sgx_read_rand for ucrypto --- sgx_crypto/sgx_crypto_sys/Cargo.toml | 4 +- sgx_crypto/sgx_crypto_sys/src/lib.rs | 29 ++++++++++++ .../tcrypto/ipp/sgx_tcrypto_common.cpp | 45 ------------------- 3 files changed, 32 insertions(+), 46 deletions(-) diff --git a/sgx_crypto/sgx_crypto_sys/Cargo.toml b/sgx_crypto/sgx_crypto_sys/Cargo.toml index 3a935918b..32312c8f7 100644 --- a/sgx_crypto/sgx_crypto_sys/Cargo.toml +++ b/sgx_crypto/sgx_crypto_sys/Cargo.toml @@ -31,10 +31,12 @@ crate-type = ["rlib"] [features] default = [] -ucrypto = [] +ucrypto = ["rdrand", "rand_core"] [dependencies] sgx_types = { path = "../../sgx_types" } +rdrand = { version = "0.8", optional = true } +rand_core = { version = "0.6", optional = true } [build-dependencies] sgx_build_helper = { path = "../../sgx_build_helper/build_helper" } diff --git a/sgx_crypto/sgx_crypto_sys/src/lib.rs b/sgx_crypto/sgx_crypto_sys/src/lib.rs index c190880e1..eff0b118e 100644 --- a/sgx_crypto/sgx_crypto_sys/src/lib.rs +++ b/sgx_crypto/sgx_crypto_sys/src/lib.rs @@ -642,3 +642,32 @@ mod bindings { ) -> SgxStatus; } } + +#[cfg(feature = "ucrypto")] +mod rand { + use core::slice; + use rand_core::RngCore; + use rdrand::RdRand; + use sgx_types::error::{SgxResult, SgxStatus}; + + /// # Safety + #[no_mangle] + pub unsafe extern "C" fn sgx_read_rand(p: *mut u8, len: usize) -> u32 { + if p.is_null() || len == 0 { + return SgxStatus::InvalidParameter.into(); + } + + let buf = slice::from_raw_parts_mut(p, len); + match rand(buf) { + Ok(_) => SgxStatus::Success.into(), + Err(e) => e.into(), + } + } + + #[inline] + fn rand(nonce: &mut [u8]) -> SgxResult { + let mut rd = RdRand::new().map_err(|_| SgxStatus::Unexpected)?; + rd.fill_bytes(nonce); + Ok(()) + } +} diff --git a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/sgx_tcrypto_common.cpp b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/sgx_tcrypto_common.cpp index a87e5d9f6..d322309a7 100644 --- a/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/sgx_tcrypto_common.cpp +++ b/sgx_crypto/sgx_crypto_sys/tcrypto/ipp/sgx_tcrypto_common.cpp @@ -210,49 +210,4 @@ int consttime_memequal(const void *b1, const void *b2, size_t len) return (1 & ((res - 1) >> 8)); } -sgx_status_t sgx_read_rand(unsigned char *rand, size_t length_in_bytes) -{ - // check parameters - if (!rand || !length_in_bytes) { - return SGX_ERROR_INVALID_PARAMETER; - } - - int ctxSize = 0; - int length_in_bits = length_in_bytes * 8; - IppsPRNGState* pPRNG = NULL; - IppStatus ipp_ret = ippStsNoErr; - - do { - ipp_ret = ippsPRNGGetSize(&ctxSize); - ERROR_BREAK(ipp_ret); - - pPRNG = (IppsPRNGState*)(malloc(ctxSize)); - if (!pPRNG) { - ipp_ret = ippStsNoMemErr; - break; - } - - ipp_ret = ippsPRNGInit(length_in_bits, pPRNG); - ERROR_BREAK(ipp_ret); - - ipp_ret = ippsPRNGen((Ipp32u *)rand, length_in_bits, pPRNG); - ERROR_BREAK(ipp_ret); - } while (0); - - CLEAR_FREE_MEM(pPRNG, ctxSize); - - switch (ipp_ret) - { - case ippStsNoErr: return SGX_SUCCESS; - case ippStsNoMemErr: - case ippStsMemAllocErr: return SGX_ERROR_OUT_OF_MEMORY; - case ippStsNullPtrErr: - case ippStsLengthErr: - case ippStsOutOfRangeErr: - case ippStsSizeErr: - case ippStsBadArgErr: return SGX_ERROR_INVALID_PARAMETER; - default: return SGX_ERROR_UNEXPECTED; - } -} - #endif From a3df5da84515b384275e840942b8ed9e4e99cf67 Mon Sep 17 00:00:00 2001 From: volcano0dr Date: Tue, 11 Mar 2025 13:25:27 +0800 Subject: [PATCH 18/34] fix trim_range_commit bug --- sgx_trts/src/edmm/mem.rs | 15 ++++++++++++--- sgx_trts/src/edmm/trim.rs | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/sgx_trts/src/edmm/mem.rs b/sgx_trts/src/edmm/mem.rs index 0d6ac634d..2f5e1e570 100644 --- a/sgx_trts/src/edmm/mem.rs +++ b/sgx_trts/src/edmm/mem.rs @@ -39,7 +39,10 @@ mod hw { use sgx_types::types::ProtectPerm; pub fn apply_epc_pages(addr: usize, count: usize) -> SgxResult { - ensure!(addr != 0 && count != 0, SgxStatus::InvalidParameter); + ensure!( + addr != 0 && is_page_aligned!(addr) && count != 0, + SgxStatus::InvalidParameter + ); if let Some(attr) = LayoutTable::new().check_dyn_range(addr, count, None) { let pages = PageRange::new( @@ -61,7 +64,10 @@ mod hw { } pub fn trim_epc_pages(addr: usize, count: usize) -> SgxResult { - ensure!(addr != 0 && count != 0, SgxStatus::InvalidParameter); + ensure!( + addr != 0 && is_page_aligned!(addr) && count != 0, + SgxStatus::InvalidParameter + ); LayoutTable::new() .check_dyn_range(addr, count, None) @@ -85,7 +91,10 @@ mod hw { } pub fn expand_stack_epc_pages(addr: usize, count: usize) -> SgxResult { - ensure!(addr != 0 && count != 0, SgxStatus::InvalidParameter); + ensure!( + addr != 0 && is_page_aligned!(addr) && count != 0, + SgxStatus::InvalidParameter + ); LayoutTable::new() .check_dyn_range(addr, count, None) diff --git a/sgx_trts/src/edmm/trim.rs b/sgx_trts/src/edmm/trim.rs index ce278cecc..6e51bd801 100644 --- a/sgx_trts/src/edmm/trim.rs +++ b/sgx_trts/src/edmm/trim.rs @@ -50,7 +50,7 @@ pub fn trim_range_commit(addr: usize, count: usize) -> SgxResult { for i in 0..count { let mut trim = Box::try_new_in( TrimRangeCommitOcall { - addr: addr + i * SE_PAGE_SHIFT, + addr: addr + (i << SE_PAGE_SHIFT), }, OcAlloc, ) From 2f48a0bf722eeac4e297dee4aca8ba340a681a52 Mon Sep 17 00:00:00 2001 From: volcano Date: Fri, 11 Apr 2025 15:58:45 +0800 Subject: [PATCH 19/34] Fixed dereferencing pointers in untrusted memory --- sgx_trts/src/enclave/init.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/sgx_trts/src/enclave/init.rs b/sgx_trts/src/enclave/init.rs index 336c94c92..559f34896 100644 --- a/sgx_trts/src/enclave/init.rs +++ b/sgx_trts/src/enclave/init.rs @@ -117,13 +117,21 @@ pub fn ctors() -> SgxResult { } pub fn global_init(tcs: &mut Tcs, raw: *mut InitInfoHeader, tidx: usize) -> SgxResult { - let mut header = NonNull::new(raw).ok_or(SgxStatus::Unexpected)?; - let header = unsafe { header.as_mut() }; - ensure!(header.is_host_range(), SgxStatus::Unexpected); + let u_header = NonNull::new(raw) + .map(|h| unsafe { h.as_ref() }) + .ok_or(SgxStatus::Unexpected)?; + ensure!(u_header.is_host_range(), SgxStatus::Unexpected); lfence(); + // copy to trusted memory. + let header = *u_header; ensure!(header.check(), SgxStatus::Unexpected); - ensure!(header.as_ref().is_host_range(), SgxStatus::Unexpected); + lfence(); + + let u_bytes = u_header + .as_bytes(header.info_size) + .ok_or(SgxStatus::Unexpected)?; + ensure!(u_bytes.is_host_range(), SgxStatus::Unexpected); lfence(); ensure!(state::get_state() == State::InitDone, SgxStatus::Unexpected); @@ -138,7 +146,8 @@ pub fn global_init(tcs: &mut Tcs, raw: *mut InitInfoHeader, tidx: usize) -> SgxR let env_len = header.env_len; let args_len = header.args_len; - let bytes: Vec = header.as_mut().into(); + // copy to trusted memory. + let bytes: Vec = u_bytes.into(); unsafe { extern "C" { @@ -186,18 +195,14 @@ impl InitInfoHeader { false } } -} - -unsafe impl ContiguousMemory for InitInfoHeader {} -impl AsRef<[u8]> for InitInfoHeader { - fn as_ref(&self) -> &[u8] { - unsafe { slice::from_raw_parts(self as *const _ as *const u8, self.info_size) } + fn as_ptr(&self) -> *const InitInfoHeader { + self } -} -impl AsMut<[u8]> for InitInfoHeader { - fn as_mut(&mut self) -> &mut [u8] { - unsafe { slice::from_raw_parts_mut(self as *mut _ as *mut u8, self.info_size) } + fn as_bytes(&self, len: usize) -> Option<&[u8]> { + (self.info_size == len).then(|| unsafe { slice::from_raw_parts(self.as_ptr().cast(), len) }) } } + +unsafe impl ContiguousMemory for InitInfoHeader {} From a28bb7dd51fa96138a86c1e5a2218b62f387b703 Mon Sep 17 00:00:00 2001 From: Zhaofeng Chen Date: Sun, 20 Jul 2025 04:00:19 +0000 Subject: [PATCH 20/34] license: fix and pass skywalking-eyes check --- .bazelversion | 1 - .github/workflows/license-check.yml | 33 +++ .licenserc.yaml | 56 +++++ DISCLAIMER | 8 + LICENSE | 29 +++ buildenv.mk | 2 +- common/inc/sgx_dcap_key_exchange.h | 2 +- common/inc/sgx_dcap_tkey_exchange.h | 2 +- licenses/LICENSE-common-inc.txt | 2 +- licenses/LICENSE-hashbrown.txt | 229 ++++++++++++++++++ licenses/LICENSE-intel-sgx.txt | 29 +++ rustlib/profiler_builtins/src/lib.rs | 2 +- samplecode/backtrace/app/build.rs | 2 +- samplecode/backtrace/app/src/main.rs | 2 +- samplecode/backtrace/enclave/src/lib.rs | 2 +- samplecode/cov/app/build.rs | 2 +- samplecode/cov/app/src/main.rs | 2 +- samplecode/cov/enclave/src/lib.rs | 2 +- samplecode/crypto/app/build.rs | 2 +- samplecode/crypto/app/src/main.rs | 2 +- samplecode/crypto/enclave/src/lib.rs | 2 +- samplecode/helloworld/app/build.rs | 2 +- samplecode/helloworld/app/src/main.rs | 2 +- samplecode/helloworld/enclave/src/lib.rs | 2 +- samplecode/httpreq/app/build.rs | 2 +- samplecode/httpreq/app/src/main.rs | 2 +- samplecode/httpreq/enclave/src/lib.rs | 2 +- .../hyper-rustls-https-server/app/build.rs | 2 +- .../hyper-rustls-https-server/app/src/main.rs | 2 +- .../enclave/src/lib.rs | 2 +- samplecode/logger/app/build.rs | 2 +- samplecode/logger/app/src/main.rs | 2 +- samplecode/logger/enclave/src/lib.rs | 2 +- samplecode/mutual-ra/app/build.rs | 2 +- samplecode/mutual-ra/app/src/main.rs | 2 +- samplecode/mutual-ra/enclave/src/cert.rs | 17 ++ samplecode/mutual-ra/enclave/src/hex.rs | 17 ++ samplecode/mutual-ra/enclave/src/lib.rs | 2 +- samplecode/regex/app/build.rs | 2 +- samplecode/regex/app/src/main.rs | 2 +- samplecode/regex/enclave/src/lib.rs | 2 +- samplecode/rpc/client/app/build.rs | 2 +- samplecode/rpc/client/app/src/main.rs | 2 +- samplecode/rpc/client/enclave/build.rs | 2 +- samplecode/rpc/client/enclave/src/lib.rs | 2 +- samplecode/rpc/proto/helloworld.proto | 2 +- samplecode/rpc/server/app/build.rs | 2 +- samplecode/rpc/server/app/src/main.rs | 2 +- samplecode/rpc/server/enclave/build.rs | 2 +- samplecode/rpc/server/enclave/src/lib.rs | 2 +- samplecode/seal/app/build.rs | 2 +- samplecode/seal/app/src/main.rs | 2 +- samplecode/seal/enclave/src/lib.rs | 2 +- samplecode/switchless/app/build.rs | 2 +- samplecode/switchless/app/src/main.rs | 2 +- samplecode/switchless/enclave/src/lib.rs | 2 +- samplecode/template/app/build.rs | 2 +- samplecode/template/app/src/main.rs | 2 +- samplecode/template/enclave/src/lib.rs | 2 +- .../zlib-lazy-static-sample/app/build.rs | 2 +- .../zlib-lazy-static-sample/app/src/main.rs | 2 +- .../enclave/src/lib.rs | 2 +- sgx_alloc/src/alignalloc.rs | 2 +- sgx_alloc/src/alignbox.rs | 2 +- sgx_alloc/src/capi.rs | 2 +- sgx_alloc/src/lib.rs | 2 +- sgx_alloc/src/system.rs | 2 +- sgx_backtrace/sgx_backtrace_sys/build.rs | 2 +- sgx_backtrace/sgx_backtrace_sys/src/lib.rs | 2 +- sgx_backtrace/src/backtrace/libunwind.rs | 2 +- sgx_backtrace/src/backtrace/mod.rs | 2 +- sgx_backtrace/src/capture.rs | 2 +- sgx_backtrace/src/lib.rs | 2 +- sgx_backtrace/src/print.rs | 2 +- sgx_backtrace/src/symbolize/libbacktrace.rs | 2 +- sgx_backtrace/src/symbolize/mod.rs | 2 +- sgx_backtrace/src/types.rs | 2 +- sgx_build_helper/build_helper/src/lib.rs | 2 +- sgx_build_helper/download_prebuilt/build.rs | 2 +- sgx_build_helper/download_prebuilt/src/lib.rs | 2 +- sgx_crypto/sgx_crypto_sys/build.rs | 2 +- sgx_crypto/sgx_crypto_sys/src/lib.rs | 2 +- sgx_crypto/src/aes/cbc.rs | 2 +- sgx_crypto/src/aes/ccm.rs | 2 +- sgx_crypto/src/aes/ctr.rs | 2 +- sgx_crypto/src/aes/gcm.rs | 2 +- sgx_crypto/src/aes/mod.rs | 2 +- sgx_crypto/src/ecc/mod.rs | 2 +- sgx_crypto/src/lib.rs | 2 +- sgx_crypto/src/mac/cmac.rs | 2 +- sgx_crypto/src/mac/hmac.rs | 2 +- sgx_crypto/src/mac/mod.rs | 2 +- sgx_crypto/src/rsa/mod.rs | 2 +- sgx_crypto/src/rsa/rsa2048.rs | 2 +- sgx_crypto/src/rsa/rsa3072.rs | 2 +- sgx_crypto/src/sha/mod.rs | 2 +- sgx_crypto/src/sha/sha1.rs | 2 +- sgx_crypto/src/sha/sha256.rs | 2 +- sgx_crypto/src/sha/sha384.rs | 2 +- sgx_crypto/src/sm/mod.rs | 2 +- sgx_crypto/src/sm/sm2/mod.rs | 2 +- sgx_crypto/src/sm/sm3/mod.rs | 2 +- sgx_crypto/src/sm/sm4/cbc.rs | 2 +- sgx_crypto/src/sm/sm4/ccm.rs | 2 +- sgx_crypto/src/sm/sm4/ctr.rs | 2 +- sgx_crypto/src/sm/sm4/mod.rs | 2 +- sgx_dcap/message/src/lib.rs | 2 +- sgx_dcap/message/src/message.rs | 2 +- sgx_dcap/tkey_exchange/src/capi/initiator.rs | 2 +- sgx_dcap/tkey_exchange/src/capi/mod.rs | 2 +- sgx_dcap/tkey_exchange/src/capi/responder.rs | 2 +- sgx_dcap/tkey_exchange/src/ecall/initiator.rs | 2 +- sgx_dcap/tkey_exchange/src/ecall/mod.rs | 2 +- sgx_dcap/tkey_exchange/src/ecall/responder.rs | 2 +- sgx_dcap/tkey_exchange/src/lib.rs | 2 +- .../tkey_exchange/src/session/initiator.rs | 2 +- sgx_dcap/tkey_exchange/src/session/manager.rs | 2 +- sgx_dcap/tkey_exchange/src/session/mod.rs | 2 +- .../tkey_exchange/src/session/responder.rs | 2 +- sgx_dcap/tvl/src/capi.rs | 2 +- sgx_dcap/tvl/src/lib.rs | 2 +- sgx_dcap/tvl/src/tvl.rs | 2 +- sgx_demangle/src/legacy.rs | 2 +- sgx_demangle/src/lib.rs | 2 +- sgx_demangle/src/v0.rs | 2 +- sgx_edl/edl/inc/addrinfo.h | 2 +- sgx_edl/edl/inc/dirent.h | 2 +- sgx_edl/edl/inc/stat.h | 2 +- sgx_edl/src/lib.rs | 2 +- sgx_ffi/src/ascii.rs | 2 +- sgx_ffi/src/c_str.rs | 2 +- sgx_ffi/src/lib.rs | 2 +- sgx_ffi/src/memchr.rs | 2 +- sgx_ffi/src/memchr/tests.rs | 2 +- sgx_key_exchange/message/src/lib.rs | 2 +- sgx_key_exchange/message/src/message.rs | 2 +- sgx_key_exchange/tkey_exchange/src/capi.rs | 2 +- sgx_key_exchange/tkey_exchange/src/lib.rs | 2 +- .../tkey_exchange/src/session/ecall.rs | 2 +- .../tkey_exchange/src/session/initiator.rs | 2 +- .../tkey_exchange/src/session/manager.rs | 2 +- .../tkey_exchange/src/session/mod.rs | 2 +- sgx_key_exchange/ukey_exchange/build.rs | 2 +- sgx_key_exchange/ukey_exchange/src/capi.rs | 2 +- sgx_key_exchange/ukey_exchange/src/lib.rs | 2 +- sgx_key_exchange/ukey_exchange/src/session.rs | 2 +- sgx_libc/sgx_tlibc_sys/build.rs | 2 +- sgx_libc/sgx_tlibc_sys/src/lib.rs | 2 +- sgx_libc/src/android/aarch64/mod.rs | 2 +- sgx_libc/src/android/mod.rs | 2 +- sgx_libc/src/lib.rs | 2 +- sgx_libc/src/linux/edl/mod.rs | 2 +- sgx_libc/src/linux/mod.rs | 2 +- sgx_libc/src/linux/ocall/asyncio.rs | 2 +- sgx_libc/src/linux/ocall/env.rs | 2 +- sgx_libc/src/linux/ocall/fd.rs | 2 +- sgx_libc/src/linux/ocall/file.rs | 2 +- sgx_libc/src/linux/ocall/mem.rs | 2 +- sgx_libc/src/linux/ocall/mod.rs | 2 +- sgx_libc/src/linux/ocall/net.rs | 2 +- sgx_libc/src/linux/ocall/pipe.rs | 2 +- sgx_libc/src/linux/ocall/process.rs | 2 +- sgx_libc/src/linux/ocall/socket.rs | 2 +- sgx_libc/src/linux/ocall/sync.rs | 2 +- sgx_libc/src/linux/ocall/sys.rs | 2 +- sgx_libc/src/linux/ocall/syscall.rs | 2 +- sgx_libc/src/linux/ocall/thread.rs | 2 +- sgx_libc/src/linux/ocall/time.rs | 2 +- sgx_libc/src/linux/pthread/mod.rs | 2 +- sgx_libc/src/linux/x86_64/mod.rs | 2 +- sgx_libc/src/macros.rs | 2 +- sgx_macros/src/lib.rs | 2 +- sgx_no_tstd/src/lib.rs | 2 +- sgx_oc/src/android/aarch64/mod.rs | 2 +- sgx_oc/src/android/mod.rs | 2 +- sgx_oc/src/lib.rs | 2 +- sgx_oc/src/linux/edl/asyncio.rs | 2 +- sgx_oc/src/linux/edl/cpuid.rs | 2 +- sgx_oc/src/linux/edl/env.rs | 2 +- sgx_oc/src/linux/edl/fd.rs | 2 +- sgx_oc/src/linux/edl/file.rs | 2 +- sgx_oc/src/linux/edl/mem.rs | 2 +- sgx_oc/src/linux/edl/mod.rs | 2 +- sgx_oc/src/linux/edl/msbuf.rs | 2 +- sgx_oc/src/linux/edl/net.rs | 2 +- sgx_oc/src/linux/edl/pipe.rs | 2 +- sgx_oc/src/linux/edl/process.rs | 2 +- sgx_oc/src/linux/edl/socket.rs | 2 +- sgx_oc/src/linux/edl/sys.rs | 2 +- sgx_oc/src/linux/edl/thread.rs | 2 +- sgx_oc/src/linux/edl/time.rs | 2 +- sgx_oc/src/linux/mod.rs | 2 +- sgx_oc/src/linux/ocall/asyncio.rs | 2 +- sgx_oc/src/linux/ocall/cpuid.rs | 2 +- sgx_oc/src/linux/ocall/env.rs | 2 +- sgx_oc/src/linux/ocall/fd.rs | 2 +- sgx_oc/src/linux/ocall/file.rs | 2 +- sgx_oc/src/linux/ocall/hostbuf.rs | 2 +- sgx_oc/src/linux/ocall/mem.rs | 2 +- sgx_oc/src/linux/ocall/mod.rs | 2 +- sgx_oc/src/linux/ocall/msbuf.rs | 2 +- sgx_oc/src/linux/ocall/net.rs | 2 +- sgx_oc/src/linux/ocall/pipe.rs | 2 +- sgx_oc/src/linux/ocall/process.rs | 2 +- sgx_oc/src/linux/ocall/socket.rs | 2 +- sgx_oc/src/linux/ocall/socket_msg.rs | 2 +- sgx_oc/src/linux/ocall/sys.rs | 2 +- sgx_oc/src/linux/ocall/thread.rs | 2 +- sgx_oc/src/linux/ocall/time.rs | 2 +- sgx_oc/src/linux/x86_64/mod.rs | 2 +- sgx_oc/src/macros.rs | 2 +- sgx_protected_fs/tfs/src/capi.rs | 2 +- sgx_protected_fs/tfs/src/fs.rs | 2 +- sgx_protected_fs/tfs/src/lib.rs | 2 +- sgx_protected_fs/tfs/src/sys/cache/list.rs | 2 +- sgx_protected_fs/tfs/src/sys/cache/mod.rs | 2 +- sgx_protected_fs/tfs/src/sys/error.rs | 2 +- sgx_protected_fs/tfs/src/sys/file/close.rs | 2 +- sgx_protected_fs/tfs/src/sys/file/flush.rs | 2 +- sgx_protected_fs/tfs/src/sys/file/mod.rs | 2 +- sgx_protected_fs/tfs/src/sys/file/node.rs | 2 +- sgx_protected_fs/tfs/src/sys/file/open.rs | 2 +- sgx_protected_fs/tfs/src/sys/file/other.rs | 2 +- sgx_protected_fs/tfs/src/sys/file/read.rs | 2 +- sgx_protected_fs/tfs/src/sys/file/write.rs | 2 +- sgx_protected_fs/tfs/src/sys/host/mod.rs | 2 +- sgx_protected_fs/tfs/src/sys/host/ocall.rs | 2 +- sgx_protected_fs/tfs/src/sys/host/ufs.rs | 2 +- sgx_protected_fs/tfs/src/sys/keys.rs | 2 +- sgx_protected_fs/tfs/src/sys/metadata.rs | 2 +- sgx_protected_fs/tfs/src/sys/mod.rs | 2 +- sgx_protected_fs/tfs/src/sys/node.rs | 2 +- sgx_protected_fs/ufs/src/lib.rs | 2 +- sgx_rand/derive/src/lib.rs | 2 +- sgx_rand/src/chacha.rs | 2 +- sgx_rand/src/distributions/exponential.rs | 2 +- sgx_rand/src/distributions/gamma.rs | 2 +- sgx_rand/src/distributions/mod.rs | 2 +- sgx_rand/src/distributions/range.rs | 2 +- sgx_rand/src/distributions/ziggurat_tables.rs | 2 +- sgx_rand/src/isaac.rs | 2 +- sgx_rand/src/lib.rs | 2 +- sgx_rand/src/os.rs | 2 +- sgx_rand/src/rand_impls.rs | 2 +- sgx_rand/src/read.rs | 2 +- sgx_rand/src/reseeding.rs | 2 +- sgx_rsrvmm/src/alloc.rs | 2 +- sgx_rsrvmm/src/capi.rs | 2 +- sgx_rsrvmm/src/lib.rs | 2 +- sgx_rsrvmm/src/map.rs | 2 +- sgx_rsrvmm/src/rsrvmm/area.rs | 2 +- sgx_rsrvmm/src/rsrvmm/manager.rs | 2 +- sgx_rsrvmm/src/rsrvmm/mod.rs | 2 +- sgx_rsrvmm/src/rsrvmm/range.rs | 2 +- sgx_serialize/derive/src/bound.rs | 2 +- sgx_serialize/derive/src/decode.rs | 2 +- sgx_serialize/derive/src/encode.rs | 2 +- sgx_serialize/derive/src/fragment.rs | 2 +- sgx_serialize/derive/src/internals/ast.rs | 2 +- sgx_serialize/derive/src/internals/ctxt.rs | 2 +- sgx_serialize/derive/src/internals/mod.rs | 2 +- sgx_serialize/derive/src/lib.rs | 2 +- sgx_serialize/derive/src/param.rs | 2 +- sgx_serialize/src/collection.rs | 2 +- sgx_serialize/src/json.rs | 2 +- sgx_serialize/src/leb128.rs | 2 +- sgx_serialize/src/lib.rs | 2 +- sgx_serialize/src/opaque.rs | 2 +- sgx_serialize/src/serialize.rs | 2 +- sgx_serialize/src/types.rs | 2 +- sgx_sync/src/barrier.rs | 2 +- sgx_sync/src/capi.rs | 2 +- sgx_sync/src/condvar.rs | 2 +- sgx_sync/src/condvar/check.rs | 2 +- sgx_sync/src/futex.rs | 2 +- sgx_sync/src/lazy_lock.rs | 2 +- sgx_sync/src/lib.rs | 2 +- sgx_sync/src/lock_api.rs | 2 +- sgx_sync/src/mutex.rs | 2 +- sgx_sync/src/once.rs | 2 +- sgx_sync/src/once_lock.rs | 2 +- sgx_sync/src/remutex/generic.rs | 2 +- sgx_sync/src/remutex/legacy.rs | 2 +- sgx_sync/src/remutex/mod.rs | 2 +- sgx_sync/src/rwlock.rs | 2 +- sgx_sync/src/spin.rs | 2 +- sgx_sync/src/sys/futex.rs | 2 +- sgx_sync/src/sys/lazy_box.rs | 2 +- sgx_sync/src/sys/locks/futex/condvar.rs | 2 +- sgx_sync/src/sys/locks/futex/mod.rs | 2 +- sgx_sync/src/sys/locks/futex/mutex.rs | 2 +- sgx_sync/src/sys/locks/futex/rwlock.rs | 2 +- sgx_sync/src/sys/locks/futex/wait.rs | 2 +- sgx_sync/src/sys/locks/generic/condvar.rs | 2 +- sgx_sync/src/sys/locks/generic/mod.rs | 2 +- sgx_sync/src/sys/locks/generic/mutex.rs | 2 +- sgx_sync/src/sys/locks/generic/rwlock.rs | 2 +- sgx_sync/src/sys/locks/mod.rs | 2 +- sgx_sync/src/sys/mod.rs | 2 +- sgx_sync/src/sys/ocall/mod.rs | 2 +- sgx_tdh/src/capi.rs | 2 +- sgx_tdh/src/lib.rs | 2 +- sgx_tdh/src/message.rs | 2 +- sgx_tdh/src/session/initiator.rs | 2 +- sgx_tdh/src/session/mod.rs | 2 +- sgx_tdh/src/session/responder.rs | 2 +- sgx_tests/cov/src/lib.rs | 2 +- sgx_tests/unit/src/lib.rs | 2 +- sgx_tests/utils/src/bench.rs | 2 +- sgx_tests/utils/src/lib.rs | 2 +- sgx_tests/utils/src/stats.rs | 2 +- sgx_tests/utils/src/time.rs | 2 +- sgx_trts/build.rs | 2 +- sgx_trts/src/arch.rs | 2 +- sgx_trts/src/asm/cet.S | 2 +- sgx_trts/src/asm/macro.S | 2 +- sgx_trts/src/asm/metadata.S | 2 +- sgx_trts/src/asm/mod.rs | 2 +- sgx_trts/src/asm/pic.S | 2 +- sgx_trts/src/asm/thunk.S | 2 +- sgx_trts/src/asm/xsave.S | 2 +- sgx_trts/src/call/ecall.rs | 2 +- sgx_trts/src/call/mod.rs | 2 +- sgx_trts/src/call/msbuf.rs | 2 +- sgx_trts/src/call/ocall.rs | 2 +- sgx_trts/src/call/ocalloc.rs | 2 +- sgx_trts/src/capi.rs | 2 +- sgx_trts/src/edmm/epc.rs | 2 +- sgx_trts/src/edmm/layout.rs | 2 +- sgx_trts/src/edmm/mem.rs | 2 +- sgx_trts/src/edmm/mod.rs | 2 +- sgx_trts/src/edmm/perm.rs | 2 +- sgx_trts/src/edmm/tcs.rs | 2 +- sgx_trts/src/edmm/trim.rs | 2 +- sgx_trts/src/elf/control_flow.rs | 2 +- sgx_trts/src/elf/dynamic.rs | 2 +- sgx_trts/src/elf/header.rs | 2 +- sgx_trts/src/elf/mod.rs | 2 +- sgx_trts/src/elf/program.rs | 2 +- sgx_trts/src/elf/sections.rs | 2 +- sgx_trts/src/elf/slice.rs | 2 +- sgx_trts/src/elf/symtabl.rs | 2 +- sgx_trts/src/elf/zero.rs | 2 +- sgx_trts/src/enclave/atexit.rs | 2 +- sgx_trts/src/enclave/entry.rs | 2 +- sgx_trts/src/enclave/init.rs | 2 +- sgx_trts/src/enclave/mem.rs | 2 +- sgx_trts/src/enclave/mod.rs | 2 +- sgx_trts/src/enclave/parse.rs | 2 +- sgx_trts/src/enclave/state.rs | 2 +- sgx_trts/src/enclave/uninit.rs | 2 +- sgx_trts/src/error.rs | 2 +- sgx_trts/src/feature/mod.rs | 2 +- sgx_trts/src/feature/sys.rs | 2 +- sgx_trts/src/fence.rs | 2 +- sgx_trts/src/inst/hw/enclu.S | 2 +- sgx_trts/src/inst/hw/everifyreport.S | 2 +- sgx_trts/src/inst/hw/inst.rs | 2 +- sgx_trts/src/inst/hw/mod.rs | 2 +- sgx_trts/src/inst/hw/td.S | 2 +- sgx_trts/src/inst/hw/xsave_mask.S | 2 +- sgx_trts/src/inst/hyper/enclu.S | 2 +- sgx_trts/src/inst/hyper/inst.rs | 2 +- sgx_trts/src/inst/hyper/mod.rs | 2 +- sgx_trts/src/inst/hyper/td.S | 2 +- sgx_trts/src/inst/hyper/xsave_mask.S | 2 +- sgx_trts/src/inst/mod.rs | 2 +- sgx_trts/src/inst/sim/derive.rs | 2 +- sgx_trts/src/inst/sim/enclu.S | 2 +- sgx_trts/src/inst/sim/inst.rs | 2 +- sgx_trts/src/inst/sim/lowlib.S | 2 +- sgx_trts/src/inst/sim/mod.rs | 2 +- sgx_trts/src/inst/sim/td.S | 2 +- sgx_trts/src/inst/sim/tls/gnu.rs | 2 +- sgx_trts/src/inst/sim/tls/mod.rs | 2 +- sgx_trts/src/inst/sim/xsave_mask.S | 2 +- sgx_trts/src/lib.rs | 2 +- sgx_trts/src/macros.rs | 2 +- sgx_trts/src/pkru.rs | 2 +- sgx_trts/src/rand.rs | 2 +- sgx_trts/src/se/key.rs | 2 +- sgx_trts/src/se/mod.rs | 2 +- sgx_trts/src/se/report.rs | 2 +- sgx_trts/src/stackchk.rs | 2 +- sgx_trts/src/sync/lazy.rs | 2 +- sgx_trts/src/sync/lock_api.rs | 2 +- sgx_trts/src/sync/mod.rs | 2 +- sgx_trts/src/sync/mutex.rs | 2 +- sgx_trts/src/sync/once.rs | 2 +- sgx_trts/src/sync/remutex.rs | 2 +- sgx_trts/src/sync/rwlock.rs | 2 +- sgx_trts/src/tcs/list.rs | 2 +- sgx_trts/src/tcs/mod.rs | 2 +- sgx_trts/src/tcs/tc.rs | 2 +- sgx_trts/src/tcs/tls.rs | 2 +- sgx_trts/src/thread/info.rs | 2 +- sgx_trts/src/thread/mod.rs | 2 +- sgx_trts/src/thread/native.rs | 2 +- sgx_trts/src/thread/task.rs | 2 +- sgx_trts/src/thread/tls/bitset.rs | 2 +- sgx_trts/src/thread/tls/mod.rs | 2 +- sgx_trts/src/trts.rs | 2 +- sgx_trts/src/veh/exception.rs | 2 +- sgx_trts/src/veh/list.rs | 4 +- sgx_trts/src/veh/mod.rs | 2 +- sgx_trts/src/veh/register.rs | 2 +- sgx_trts/src/version.rs | 2 +- sgx_trts/src/xsave.rs | 2 +- sgx_tse/src/capi.rs | 2 +- sgx_tse/src/lib.rs | 2 +- sgx_tse/src/se.rs | 2 +- sgx_tseal/src/aad.rs | 2 +- sgx_tseal/src/capi.rs | 2 +- sgx_tseal/src/internal.rs | 2 +- sgx_tseal/src/lib.rs | 2 +- sgx_tseal/src/seal.rs | 2 +- sgx_tstd/src/alloc.rs | 2 +- sgx_tstd/src/ascii.rs | 2 +- sgx_tstd/src/backtrace.rs | 2 +- sgx_tstd/src/backtrace/tests.rs | 2 +- sgx_tstd/src/collections/hash/benches/map.rs | 2 +- sgx_tstd/src/collections/hash/benches/mod.rs | 2 +- .../src/collections/hash/benches/set_ops.rs | 2 +- sgx_tstd/src/collections/hash/map.rs | 2 +- sgx_tstd/src/collections/hash/map/tests.rs | 2 +- sgx_tstd/src/collections/hash/mod.rs | 2 +- sgx_tstd/src/collections/hash/set.rs | 2 +- sgx_tstd/src/collections/hash/set/tests.rs | 2 +- sgx_tstd/src/collections/mod.rs | 2 +- sgx_tstd/src/enclave.rs | 2 +- sgx_tstd/src/env.rs | 2 +- sgx_tstd/src/env/tests.rs | 2 +- sgx_tstd/src/error.rs | 2 +- sgx_tstd/src/error/tests.rs | 2 +- sgx_tstd/src/f32.rs | 2 +- sgx_tstd/src/f32/tests.rs | 2 +- sgx_tstd/src/f64.rs | 2 +- sgx_tstd/src/f64/tests.rs | 2 +- sgx_tstd/src/ffi/mod.rs | 2 +- sgx_tstd/src/ffi/os_str.rs | 2 +- sgx_tstd/src/ffi/os_str/tests.rs | 2 +- sgx_tstd/src/fs.rs | 2 +- sgx_tstd/src/fs/tests.rs | 2 +- sgx_tstd/src/hash/mod.rs | 2 +- sgx_tstd/src/hash/random.rs | 2 +- sgx_tstd/src/io/buffered/bufreader.rs | 2 +- sgx_tstd/src/io/buffered/bufreader/buffer.rs | 2 +- sgx_tstd/src/io/buffered/bufwriter.rs | 2 +- sgx_tstd/src/io/buffered/linewriter.rs | 2 +- sgx_tstd/src/io/buffered/linewritershim.rs | 2 +- sgx_tstd/src/io/buffered/mod.rs | 2 +- sgx_tstd/src/io/buffered/tests.rs | 2 +- sgx_tstd/src/io/copy.rs | 2 +- sgx_tstd/src/io/copy/tests.rs | 2 +- sgx_tstd/src/io/cursor.rs | 2 +- sgx_tstd/src/io/cursor/tests.rs | 2 +- sgx_tstd/src/io/error.rs | 2 +- sgx_tstd/src/io/error/repr_bitpacked.rs | 2 +- sgx_tstd/src/io/error/repr_unpacked.rs | 2 +- sgx_tstd/src/io/error/tests.rs | 2 +- sgx_tstd/src/io/impls.rs | 2 +- sgx_tstd/src/io/impls/tests.rs | 2 +- sgx_tstd/src/io/mod.rs | 2 +- sgx_tstd/src/io/prelude.rs | 2 +- sgx_tstd/src/io/stdio.rs | 2 +- sgx_tstd/src/io/stdio/tests.rs | 2 +- sgx_tstd/src/io/tests.rs | 2 +- sgx_tstd/src/io/util.rs | 2 +- sgx_tstd/src/io/util/tests.rs | 2 +- sgx_tstd/src/lib.rs | 2 +- sgx_tstd/src/macros.rs | 2 +- sgx_tstd/src/net/ip_addr.rs | 2 +- sgx_tstd/src/net/ip_addr/tests.rs | 2 +- sgx_tstd/src/net/mod.rs | 2 +- sgx_tstd/src/net/socket_addr.rs | 2 +- sgx_tstd/src/net/socket_addr/tests.rs | 2 +- sgx_tstd/src/net/tcp.rs | 2 +- sgx_tstd/src/net/tcp/tests.rs | 2 +- sgx_tstd/src/net/test.rs | 2 +- sgx_tstd/src/net/udp.rs | 2 +- sgx_tstd/src/net/udp/tests.rs | 2 +- sgx_tstd/src/num.rs | 2 +- sgx_tstd/src/num/benches.rs | 2 +- sgx_tstd/src/num/tests.rs | 2 +- sgx_tstd/src/os/fd/mod.rs | 2 +- sgx_tstd/src/os/fd/net.rs | 2 +- sgx_tstd/src/os/fd/owned.rs | 2 +- sgx_tstd/src/os/fd/raw.rs | 2 +- sgx_tstd/src/os/fd/tests.rs | 2 +- sgx_tstd/src/os/linux/fs.rs | 2 +- sgx_tstd/src/os/linux/mod.rs | 2 +- sgx_tstd/src/os/linux/net.rs | 2 +- sgx_tstd/src/os/linux/process.rs | 2 +- sgx_tstd/src/os/linux/raw.rs | 2 +- sgx_tstd/src/os/mod.rs | 2 +- sgx_tstd/src/os/net/linux_ext/addr.rs | 2 +- sgx_tstd/src/os/net/linux_ext/mod.rs | 2 +- sgx_tstd/src/os/net/linux_ext/tcp.rs | 2 +- sgx_tstd/src/os/net/linux_ext/tests.rs | 2 +- sgx_tstd/src/os/net/mod.rs | 2 +- sgx_tstd/src/os/raw/mod.rs | 2 +- sgx_tstd/src/os/raw/tests.rs | 2 +- sgx_tstd/src/os/unix/ffi/mod.rs | 2 +- sgx_tstd/src/os/unix/ffi/os_str.rs | 2 +- sgx_tstd/src/os/unix/fs.rs | 2 +- sgx_tstd/src/os/unix/fs/tests.rs | 2 +- sgx_tstd/src/os/unix/io/mod.rs | 2 +- sgx_tstd/src/os/unix/io/tests.rs | 2 +- sgx_tstd/src/os/unix/mod.rs | 2 +- sgx_tstd/src/os/unix/net/addr.rs | 2 +- sgx_tstd/src/os/unix/net/ancillary.rs | 2 +- sgx_tstd/src/os/unix/net/datagram.rs | 2 +- sgx_tstd/src/os/unix/net/listener.rs | 2 +- sgx_tstd/src/os/unix/net/mod.rs | 2 +- sgx_tstd/src/os/unix/net/stream.rs | 2 +- sgx_tstd/src/os/unix/net/tests.rs | 2 +- sgx_tstd/src/os/unix/process.rs | 2 +- sgx_tstd/src/os/unix/raw.rs | 2 +- sgx_tstd/src/os/unix/thread.rs | 2 +- sgx_tstd/src/os/unix/ucred.rs | 2 +- sgx_tstd/src/os/unix/ucred/tests.rs | 2 +- sgx_tstd/src/panic.rs | 2 +- sgx_tstd/src/panic/tests.rs | 2 +- sgx_tstd/src/panicking.rs | 2 +- sgx_tstd/src/path.rs | 2 +- sgx_tstd/src/path/tests.rs | 2 +- sgx_tstd/src/prelude/mod.rs | 2 +- sgx_tstd/src/prelude/v1.rs | 2 +- sgx_tstd/src/process.rs | 2 +- sgx_tstd/src/rt.rs | 2 +- sgx_tstd/src/sync/barrier.rs | 2 +- sgx_tstd/src/sync/barrier/tests.rs | 2 +- sgx_tstd/src/sync/condvar.rs | 2 +- sgx_tstd/src/sync/condvar/tests.rs | 2 +- sgx_tstd/src/sync/lazy_lock.rs | 2 +- sgx_tstd/src/sync/lazy_lock/tests.rs | 2 +- sgx_tstd/src/sync/mod.rs | 2 +- sgx_tstd/src/sync/mpmc/array.rs | 2 +- sgx_tstd/src/sync/mpmc/context.rs | 2 +- sgx_tstd/src/sync/mpmc/counter.rs | 2 +- sgx_tstd/src/sync/mpmc/error.rs | 2 +- sgx_tstd/src/sync/mpmc/list.rs | 2 +- sgx_tstd/src/sync/mpmc/mod.rs | 2 +- sgx_tstd/src/sync/mpmc/select.rs | 2 +- sgx_tstd/src/sync/mpmc/utils.rs | 2 +- sgx_tstd/src/sync/mpmc/waker.rs | 2 +- sgx_tstd/src/sync/mpmc/zero.rs | 2 +- sgx_tstd/src/sync/mpsc/mod.rs | 2 +- sgx_tstd/src/sync/mpsc/sync_tests.rs | 2 +- sgx_tstd/src/sync/mpsc/tests.rs | 2 +- sgx_tstd/src/sync/mutex.rs | 2 +- sgx_tstd/src/sync/mutex/tests.rs | 2 +- sgx_tstd/src/sync/once.rs | 2 +- sgx_tstd/src/sync/once/tests.rs | 2 +- sgx_tstd/src/sync/once_lock.rs | 2 +- sgx_tstd/src/sync/once_lock/tests.rs | 2 +- sgx_tstd/src/sync/poison.rs | 2 +- sgx_tstd/src/sync/remutex.rs | 2 +- sgx_tstd/src/sync/remutex/tests.rs | 2 +- sgx_tstd/src/sync/rwlock.rs | 2 +- sgx_tstd/src/sync/rwlock/tests.rs | 2 +- sgx_tstd/src/sys/args.rs | 2 +- sgx_tstd/src/sys/backtrace/mod.rs | 2 +- sgx_tstd/src/sys/backtrace/printing/mod.rs | 2 +- sgx_tstd/src/sys/backtrace/tracing/gcc_s.rs | 2 +- sgx_tstd/src/sys/backtrace/tracing/mod.rs | 2 +- sgx_tstd/src/sys/cmath.rs | 2 +- sgx_tstd/src/sys/common/mod.rs | 2 +- sgx_tstd/src/sys/common/small_c_string.rs | 2 +- sgx_tstd/src/sys/common/tests.rs | 2 +- .../src/sys/common/thread_local/fast_local.rs | 2 +- sgx_tstd/src/sys/common/thread_local/mod.rs | 2 +- .../src/sys/common/thread_local/os_local.rs | 2 +- .../sys/common/thread_local/static_local.rs | 2 +- sgx_tstd/src/sys/env.rs | 2 +- sgx_tstd/src/sys/fd.rs | 2 +- sgx_tstd/src/sys/fd/tests.rs | 2 +- sgx_tstd/src/sys/fs.rs | 2 +- sgx_tstd/src/sys/futex.rs | 2 +- sgx_tstd/src/sys/io.rs | 2 +- sgx_tstd/src/sys/kernel_copy.rs | 2 +- sgx_tstd/src/sys/kernel_copy/tests.rs | 2 +- sgx_tstd/src/sys/memchr.rs | 2 +- sgx_tstd/src/sys/mod.rs | 2 +- sgx_tstd/src/sys/net.rs | 2 +- sgx_tstd/src/sys/os.rs | 2 +- sgx_tstd/src/sys/os_str.rs | 2 +- sgx_tstd/src/sys/os_str/tests.rs | 2 +- sgx_tstd/src/sys/path.rs | 2 +- sgx_tstd/src/sys/personality/dwarf/eh.rs | 2 +- sgx_tstd/src/sys/personality/dwarf/mod.rs | 2 +- sgx_tstd/src/sys/personality/dwarf/tests.rs | 2 +- sgx_tstd/src/sys/personality/gcc.rs | 2 +- sgx_tstd/src/sys/personality/mod.rs | 18 +- sgx_tstd/src/sys/pipe.rs | 2 +- sgx_tstd/src/sys/process.rs | 2 +- sgx_tstd/src/sys/rand.rs | 2 +- sgx_tstd/src/sys/stdio.rs | 2 +- sgx_tstd/src/sys/thread.rs | 2 +- sgx_tstd/src/sys/thread_local_dtor.rs | 2 +- sgx_tstd/src/sys/thread_local_key.rs | 2 +- sgx_tstd/src/sys/time.rs | 2 +- sgx_tstd/src/sys/unsupported/common.rs | 17 ++ sgx_tstd/src/sys/unsupported/mod.rs | 2 +- sgx_tstd/src/sys/unsupported/pipe.rs | 2 +- sgx_tstd/src/sys/unsupported/process.rs | 2 +- sgx_tstd/src/sys_common/at_exit_imp.rs | 2 +- sgx_tstd/src/sys_common/backtrace.rs | 2 +- sgx_tstd/src/sys_common/condvar.rs | 2 +- sgx_tstd/src/sys_common/fs.rs | 2 +- sgx_tstd/src/sys_common/gnu/libbacktrace.rs | 2 +- sgx_tstd/src/sys_common/gnu/mod.rs | 2 +- sgx_tstd/src/sys_common/io.rs | 2 +- sgx_tstd/src/sys_common/lazy_box.rs | 2 +- sgx_tstd/src/sys_common/memchr.rs | 2 +- sgx_tstd/src/sys_common/mod.rs | 2 +- sgx_tstd/src/sys_common/mutex.rs | 2 +- sgx_tstd/src/sys_common/net.rs | 2 +- sgx_tstd/src/sys_common/net/tests.rs | 2 +- sgx_tstd/src/sys_common/once/futex.rs | 2 +- sgx_tstd/src/sys_common/once/mod.rs | 2 +- sgx_tstd/src/sys_common/once/queue.rs | 2 +- sgx_tstd/src/sys_common/process.rs | 2 +- sgx_tstd/src/sys_common/remutex.rs | 2 +- sgx_tstd/src/sys_common/rwlock.rs | 2 +- sgx_tstd/src/sys_common/tests.rs | 2 +- sgx_tstd/src/sys_common/thread.rs | 2 +- sgx_tstd/src/sys_common/thread_info.rs | 2 +- sgx_tstd/src/sys_common/thread_local_dtor.rs | 2 +- sgx_tstd/src/sys_common/thread_local_key.rs | 2 +- .../src/sys_common/thread_local_key/tests.rs | 2 +- .../src/sys_common/thread_parking/futex.rs | 2 +- .../src/sys_common/thread_parking/generic.rs | 2 +- sgx_tstd/src/sys_common/thread_parking/mod.rs | 2 +- sgx_tstd/src/sys_common/wstr.rs | 2 +- sgx_tstd/src/sys_common/wtf8.rs | 2 +- sgx_tstd/src/sys_common/wtf8/tests.rs | 2 +- sgx_tstd/src/thread/local.rs | 2 +- sgx_tstd/src/thread/local/dynamic_tests.rs | 2 +- sgx_tstd/src/thread/local/tests.rs | 2 +- sgx_tstd/src/thread/mod.rs | 2 +- sgx_tstd/src/thread/scoped.rs | 2 +- sgx_tstd/src/thread/tests.rs | 2 +- sgx_tstd/src/time.rs | 2 +- sgx_tstd/src/time/tests.rs | 2 +- sgx_tstd/src/untrusted/fs.rs | 2 +- sgx_tstd/src/untrusted/mod.rs | 2 +- sgx_tstd/src/untrusted/path.rs | 2 +- sgx_tstd/src/untrusted/time.rs | 2 +- sgx_types/build.rs | 2 +- sgx_types/src/cpu_features.rs | 2 +- sgx_types/src/error/errno.rs | 2 +- sgx_types/src/error/mod.rs | 2 +- sgx_types/src/function.rs | 2 +- sgx_types/src/lib.rs | 2 +- sgx_types/src/macros.rs | 2 +- sgx_types/src/marker.rs | 2 +- sgx_types/src/memeq.rs | 2 +- sgx_types/src/metadata.rs | 2 +- sgx_types/src/types/crypto.rs | 2 +- sgx_types/src/types/dcap.rs | 2 +- sgx_types/src/types/dh.rs | 2 +- sgx_types/src/types/key_exchange.rs | 2 +- sgx_types/src/types/mod.rs | 2 +- sgx_types/src/types/quote.rs | 2 +- sgx_types/src/types/ra.rs | 2 +- sgx_types/src/types/raw.rs | 2 +- sgx_types/src/types/report2.rs | 2 +- sgx_types/src/types/seal.rs | 2 +- sgx_types/src/types/switchless.rs | 2 +- sgx_types/src/types/tdx.rs | 2 +- sgx_types/src/types/urts.rs | 2 +- sgx_unwind/build.rs | 2 +- sgx_unwind/src/lib.rs | 2 +- sgx_unwind/src/libunwind.rs | 2 +- sgx_unwind/src/macros.rs | 2 +- sgx_urts/build.rs | 2 +- sgx_urts/src/capi.rs | 2 +- sgx_urts/src/enclave/init.rs | 2 +- sgx_urts/src/enclave/mod.rs | 2 +- sgx_urts/src/enclave/uninit.rs | 2 +- sgx_urts/src/lib.rs | 2 +- sgx_urts/src/msbuf.rs | 2 +- sgx_urts/src/ocall/asyncio.rs | 2 +- sgx_urts/src/ocall/env.rs | 2 +- sgx_urts/src/ocall/fd.rs | 2 +- sgx_urts/src/ocall/file.rs | 2 +- sgx_urts/src/ocall/mem.rs | 2 +- sgx_urts/src/ocall/mod.rs | 2 +- sgx_urts/src/ocall/msbuf.rs | 2 +- sgx_urts/src/ocall/net.rs | 2 +- sgx_urts/src/ocall/pipe.rs | 2 +- sgx_urts/src/ocall/process.rs | 2 +- sgx_urts/src/ocall/sgxfile.rs | 2 +- sgx_urts/src/ocall/socket.rs | 2 +- sgx_urts/src/ocall/sync.rs | 2 +- sgx_urts/src/ocall/sys.rs | 2 +- sgx_urts/src/ocall/thread.rs | 2 +- sgx_urts/src/ocall/time.rs | 2 +- sgx_urts/src/ocall/util.rs | 2 +- tests/app/build.rs | 2 +- tests/app/src/main.rs | 2 +- tests/enclave/src/lib.rs | 2 +- 703 files changed, 1145 insertions(+), 695 deletions(-) delete mode 100644 .bazelversion create mode 100644 .github/workflows/license-check.yml create mode 100644 .licenserc.yaml create mode 100644 DISCLAIMER create mode 100644 licenses/LICENSE-hashbrown.txt create mode 100644 licenses/LICENSE-intel-sgx.txt diff --git a/.bazelversion b/.bazelversion deleted file mode 100644 index 48f7a71df..000000000 --- a/.bazelversion +++ /dev/null @@ -1 +0,0 @@ -0.28.1 diff --git a/.github/workflows/license-check.yml b/.github/workflows/license-check.yml new file mode 100644 index 000000000..c6a06eb23 --- /dev/null +++ b/.github/workflows/license-check.yml @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: License Check + +on: [push, pull_request] + +jobs: + license: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Check License Header + uses: apache/skywalking-eyes/header@501a28d2fb4a9b962661987e50cf0219631b32ff + # with: + # log: debug # optional: set the log level. The default value is `info`. + # config: .licenserc.yaml # optional: set the config file. The default value is `.licenserc.yaml`. + # token: # optional: the token that license eye uses when it needs to comment on the pull request. Set to empty ("") to disable commenting on pull request. The default value is ${{ github.token }} + # mode: # optional: Which mode License-Eye should be run in. Choices are `check` or `fix`. The default value is `check`. \ No newline at end of file diff --git a/.licenserc.yaml b/.licenserc.yaml new file mode 100644 index 000000000..81a138cdb --- /dev/null +++ b/.licenserc.yaml @@ -0,0 +1,56 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +header: + license: + spdx-id: Apache-2.0 + copyright-owner: Apache Software Foundation + + paths-ignore: + # License and notice files + - 'licenses' + - 'LICENSE' + - 'NOTICE' + - 'DISCLAIMER' + + # Documentation and configuration files + - '**/*.md' + - '**/Cargo.lock' + - 'rust-toolchain' + - '**/*.lds' + + # Cryptographic and binary files for testing + - '**/*.pem' + - '**/*.key' + - '**/*.crt' + - '**/*.rsa' + - '**/*.der' + + # Third-party libraries - included in licenses directory + - 'common/inc' # LICENSE-common-inc.txt + - 'sgx_tstd/hashbrown' # LICENSE-hashbrown.txt + - 'sgx_edl/edl/sgx_sync.edl' # LICENSE-intel-sgx.txt + - 'sgx_backtrace/sgx_backtrace_sys' # LICENSE-libbacktrace.txt + - 'sgx_unwind/libunwind' # LICENSE-libunwind.txt + - 'rustlib/' # LICENSE-rust.txt + - 'sgx_crypto/sgx_crypto_sys/tcrypto' # LICENSE-tcrypto.txt + - 'sgx_libc/sgx_tlibc_sys/tlibc/' # LICENSE-tlibc.txt + - 'sgx_libc/sgx_tlibc_sys/tsafecrt/' # LICENSE-tsafecrt.txt + +dependency: + files: + - 'Cargo.toml' \ No newline at end of file diff --git a/DISCLAIMER b/DISCLAIMER new file mode 100644 index 000000000..f755dfd9f --- /dev/null +++ b/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Teaclave (incubating) is an effort undergoing incubation at The Apache +Software Foundation (ASF), sponsored by the Apache Incubator. +Incubation is required of all newly accepted projects until a further review +indicates that the infrastructure, communications, and decision making process +have stabilized in a manner consistent with other successful ASF projects. +While incubation status is not necessarily a reflection of the completeness or +stability of the code, it does indicate that the project has yet to be fully +endorsed by the ASF. \ No newline at end of file diff --git a/LICENSE b/LICENSE index 24ffd1966..489525996 100644 --- a/LICENSE +++ b/LICENSE @@ -205,3 +205,32 @@ This product bundles various third-party components under other open source licenses. This section summarizes those components and their licenses. See licenses/ for text of these licenses. + +Third-party components included in this distribution: + +- common/inc + License: See licenses/LICENSE-common-inc.txt + +- sgx_tstd/hashbrown + License: See licenses/LICENSE-hashbrown.txt + +- sgx_edl/edl/sgx_sync.edl + License: See licenses/LICENSE-intel-sgx.txt + +- sgx_backtrace/sgx_backtrace_sys + License: See licenses/LICENSE-libbacktrace.txt + +- sgx_unwind/libunwind + License: See licenses/LICENSE-libunwind.txt + +- rustlib/ + License: See licenses/LICENSE-rust.txt + +- sgx_crypto/sgx_crypto_sys/tcrypto + License: See licenses/LICENSE-tcrypto.txt + +- sgx_libc/sgx_tlibc_sys/tlibc/ + License: See licenses/LICENSE-tlibc.txt + +- sgx_libc/sgx_tlibc_sys/tsafecrt/ + License: See licenses/LICENSE-tsafecrt.txt diff --git a/buildenv.mk b/buildenv.mk index 73974b6b0..b37c9085e 100644 --- a/buildenv.mk +++ b/buildenv.mk @@ -13,7 +13,7 @@ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations -# under the License.. +# under the License. # # diff --git a/common/inc/sgx_dcap_key_exchange.h b/common/inc/sgx_dcap_key_exchange.h index cbdae3182..8421e7261 100644 --- a/common/inc/sgx_dcap_key_exchange.h +++ b/common/inc/sgx_dcap_key_exchange.h @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #ifndef _SGX_DCAP_KEY_EXCHANGE_H_ #define _SGX_DCAP_KEY_EXCHANGE_H_ diff --git a/common/inc/sgx_dcap_tkey_exchange.h b/common/inc/sgx_dcap_tkey_exchange.h index 76b4165f3..e57a4ed88 100644 --- a/common/inc/sgx_dcap_tkey_exchange.h +++ b/common/inc/sgx_dcap_tkey_exchange.h @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #ifndef _SGX_DCAP_TKEY_EXCHANGE_H_ #define _SGX_DCAP_TKEY_EXCHANGE_H_ diff --git a/licenses/LICENSE-common-inc.txt b/licenses/LICENSE-common-inc.txt index aafca617c..0197e6286 100644 --- a/licenses/LICENSE-common-inc.txt +++ b/licenses/LICENSE-common-inc.txt @@ -57,4 +57,4 @@ software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations -under the License.. +under the License. diff --git a/licenses/LICENSE-hashbrown.txt b/licenses/LICENSE-hashbrown.txt new file mode 100644 index 000000000..da730d8dc --- /dev/null +++ b/licenses/LICENSE-hashbrown.txt @@ -0,0 +1,229 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT 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) 2016 Amanieu d'Antras + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/licenses/LICENSE-intel-sgx.txt b/licenses/LICENSE-intel-sgx.txt new file mode 100644 index 000000000..dfac5e57c --- /dev/null +++ b/licenses/LICENSE-intel-sgx.txt @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (C) 2011-2019 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. \ No newline at end of file diff --git a/rustlib/profiler_builtins/src/lib.rs b/rustlib/profiler_builtins/src/lib.rs index ef90f5fc7..50e378104 100644 --- a/rustlib/profiler_builtins/src/lib.rs +++ b/rustlib/profiler_builtins/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![feature(profiler_runtime)] diff --git a/samplecode/backtrace/app/build.rs b/samplecode/backtrace/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/backtrace/app/build.rs +++ b/samplecode/backtrace/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/backtrace/app/src/main.rs b/samplecode/backtrace/app/src/main.rs index cf9bec40d..c59237c82 100644 --- a/samplecode/backtrace/app/src/main.rs +++ b/samplecode/backtrace/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/backtrace/enclave/src/lib.rs b/samplecode/backtrace/enclave/src/lib.rs index 9997c07f0..630e5d011 100644 --- a/samplecode/backtrace/enclave/src/lib.rs +++ b/samplecode/backtrace/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![cfg_attr(not(target_vendor = "teaclave"), no_std)] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/samplecode/cov/app/build.rs b/samplecode/cov/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/cov/app/build.rs +++ b/samplecode/cov/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/cov/app/src/main.rs b/samplecode/cov/app/src/main.rs index 8809f552b..7c631d878 100644 --- a/samplecode/cov/app/src/main.rs +++ b/samplecode/cov/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/cov/enclave/src/lib.rs b/samplecode/cov/enclave/src/lib.rs index f1c12fa1e..bc8e3d582 100644 --- a/samplecode/cov/enclave/src/lib.rs +++ b/samplecode/cov/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![cfg_attr(not(target_vendor = "teaclave"), no_std)] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/samplecode/crypto/app/build.rs b/samplecode/crypto/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/crypto/app/build.rs +++ b/samplecode/crypto/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/crypto/app/src/main.rs b/samplecode/crypto/app/src/main.rs index e4ce9f5a9..6eb2e09c0 100644 --- a/samplecode/crypto/app/src/main.rs +++ b/samplecode/crypto/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::redundant_static_lifetimes)] #![allow(clippy::print_literal)] diff --git a/samplecode/crypto/enclave/src/lib.rs b/samplecode/crypto/enclave/src/lib.rs index 748247dc7..4ddb96f7b 100644 --- a/samplecode/crypto/enclave/src/lib.rs +++ b/samplecode/crypto/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![cfg_attr(not(target_vendor = "teaclave"), no_std)] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/samplecode/helloworld/app/build.rs b/samplecode/helloworld/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/helloworld/app/build.rs +++ b/samplecode/helloworld/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/helloworld/app/src/main.rs b/samplecode/helloworld/app/src/main.rs index 8809f552b..7c631d878 100644 --- a/samplecode/helloworld/app/src/main.rs +++ b/samplecode/helloworld/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/helloworld/enclave/src/lib.rs b/samplecode/helloworld/enclave/src/lib.rs index 5fd6daf4d..2ab1bdf23 100644 --- a/samplecode/helloworld/enclave/src/lib.rs +++ b/samplecode/helloworld/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![cfg_attr(not(target_vendor = "teaclave"), no_std)] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/samplecode/httpreq/app/build.rs b/samplecode/httpreq/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/httpreq/app/build.rs +++ b/samplecode/httpreq/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/httpreq/app/src/main.rs b/samplecode/httpreq/app/src/main.rs index 41a53498f..e61e52aaf 100644 --- a/samplecode/httpreq/app/src/main.rs +++ b/samplecode/httpreq/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/httpreq/enclave/src/lib.rs b/samplecode/httpreq/enclave/src/lib.rs index 6643d4a38..a581e2254 100644 --- a/samplecode/httpreq/enclave/src/lib.rs +++ b/samplecode/httpreq/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_libc; extern crate sgx_oc; diff --git a/samplecode/hyper-rustls-https-server/app/build.rs b/samplecode/hyper-rustls-https-server/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/hyper-rustls-https-server/app/build.rs +++ b/samplecode/hyper-rustls-https-server/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/hyper-rustls-https-server/app/src/main.rs b/samplecode/hyper-rustls-https-server/app/src/main.rs index d9b922c08..712ad0eab 100644 --- a/samplecode/hyper-rustls-https-server/app/src/main.rs +++ b/samplecode/hyper-rustls-https-server/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/hyper-rustls-https-server/enclave/src/lib.rs b/samplecode/hyper-rustls-https-server/enclave/src/lib.rs index 72102bff9..52ba701fc 100644 --- a/samplecode/hyper-rustls-https-server/enclave/src/lib.rs +++ b/samplecode/hyper-rustls-https-server/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_libc; extern crate sgx_types; diff --git a/samplecode/logger/app/build.rs b/samplecode/logger/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/logger/app/build.rs +++ b/samplecode/logger/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/logger/app/src/main.rs b/samplecode/logger/app/src/main.rs index c896afadd..92a475742 100644 --- a/samplecode/logger/app/src/main.rs +++ b/samplecode/logger/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/logger/enclave/src/lib.rs b/samplecode/logger/enclave/src/lib.rs index 01ef10a83..6a07d4842 100644 --- a/samplecode/logger/enclave/src/lib.rs +++ b/samplecode/logger/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_libc; extern crate sgx_types; diff --git a/samplecode/mutual-ra/app/build.rs b/samplecode/mutual-ra/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/mutual-ra/app/build.rs +++ b/samplecode/mutual-ra/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/mutual-ra/app/src/main.rs b/samplecode/mutual-ra/app/src/main.rs index 9adf44360..e9a288d71 100644 --- a/samplecode/mutual-ra/app/src/main.rs +++ b/samplecode/mutual-ra/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/mutual-ra/enclave/src/cert.rs b/samplecode/mutual-ra/enclave/src/cert.rs index 605a5cad4..a98f47eff 100644 --- a/samplecode/mutual-ra/enclave/src/cert.rs +++ b/samplecode/mutual-ra/enclave/src/cert.rs @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT 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 std::{str, ptr,io}; use std::time::*; use std::untrusted::time::SystemTimeEx; diff --git a/samplecode/mutual-ra/enclave/src/hex.rs b/samplecode/mutual-ra/enclave/src/hex.rs index 028b4a743..47e247a13 100644 --- a/samplecode/mutual-ra/enclave/src/hex.rs +++ b/samplecode/mutual-ra/enclave/src/hex.rs @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + // hex encoder and decoder used by rust-protobuf unittests use std::char; diff --git a/samplecode/mutual-ra/enclave/src/lib.rs b/samplecode/mutual-ra/enclave/src/lib.rs index d0c9ce6ef..1376333ea 100644 --- a/samplecode/mutual-ra/enclave/src/lib.rs +++ b/samplecode/mutual-ra/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_trts; diff --git a/samplecode/regex/app/build.rs b/samplecode/regex/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/regex/app/build.rs +++ b/samplecode/regex/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/regex/app/src/main.rs b/samplecode/regex/app/src/main.rs index 2f628ba9d..04c3890bd 100644 --- a/samplecode/regex/app/src/main.rs +++ b/samplecode/regex/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/regex/enclave/src/lib.rs b/samplecode/regex/enclave/src/lib.rs index 7a25487f0..7484ecdae 100644 --- a/samplecode/regex/enclave/src/lib.rs +++ b/samplecode/regex/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; diff --git a/samplecode/rpc/client/app/build.rs b/samplecode/rpc/client/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/rpc/client/app/build.rs +++ b/samplecode/rpc/client/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/rpc/client/app/src/main.rs b/samplecode/rpc/client/app/src/main.rs index 5f98aa1bf..83e24f4e7 100644 --- a/samplecode/rpc/client/app/src/main.rs +++ b/samplecode/rpc/client/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/rpc/client/enclave/build.rs b/samplecode/rpc/client/enclave/build.rs index df957770d..65674b826 100644 --- a/samplecode/rpc/client/enclave/build.rs +++ b/samplecode/rpc/client/enclave/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; use std::path::PathBuf; diff --git a/samplecode/rpc/client/enclave/src/lib.rs b/samplecode/rpc/client/enclave/src/lib.rs index cd0d98763..0b1377249 100644 --- a/samplecode/rpc/client/enclave/src/lib.rs +++ b/samplecode/rpc/client/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_libc; extern crate sgx_types; diff --git a/samplecode/rpc/proto/helloworld.proto b/samplecode/rpc/proto/helloworld.proto index dea91d328..c330e5a0b 100644 --- a/samplecode/rpc/proto/helloworld.proto +++ b/samplecode/rpc/proto/helloworld.proto @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. syntax = "proto3"; diff --git a/samplecode/rpc/server/app/build.rs b/samplecode/rpc/server/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/rpc/server/app/build.rs +++ b/samplecode/rpc/server/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/rpc/server/app/src/main.rs b/samplecode/rpc/server/app/src/main.rs index 2decf4c0c..8e4fe5f31 100644 --- a/samplecode/rpc/server/app/src/main.rs +++ b/samplecode/rpc/server/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/rpc/server/enclave/build.rs b/samplecode/rpc/server/enclave/build.rs index df957770d..65674b826 100644 --- a/samplecode/rpc/server/enclave/build.rs +++ b/samplecode/rpc/server/enclave/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; use std::path::PathBuf; diff --git a/samplecode/rpc/server/enclave/src/lib.rs b/samplecode/rpc/server/enclave/src/lib.rs index 27fd42ac3..b928ddc14 100644 --- a/samplecode/rpc/server/enclave/src/lib.rs +++ b/samplecode/rpc/server/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_libc; extern crate sgx_types; diff --git a/samplecode/seal/app/build.rs b/samplecode/seal/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/seal/app/build.rs +++ b/samplecode/seal/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/seal/app/src/main.rs b/samplecode/seal/app/src/main.rs index 066b596c0..151096145 100644 --- a/samplecode/seal/app/src/main.rs +++ b/samplecode/seal/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/seal/enclave/src/lib.rs b/samplecode/seal/enclave/src/lib.rs index 95c3f81fc..26ffb9ae2 100644 --- a/samplecode/seal/enclave/src/lib.rs +++ b/samplecode/seal/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![cfg_attr(not(target_vendor = "teaclave"), no_std)] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/samplecode/switchless/app/build.rs b/samplecode/switchless/app/build.rs index 002ffed91..5e2652d82 100644 --- a/samplecode/switchless/app/build.rs +++ b/samplecode/switchless/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/switchless/app/src/main.rs b/samplecode/switchless/app/src/main.rs index 2bcad663f..c78787bfb 100644 --- a/samplecode/switchless/app/src/main.rs +++ b/samplecode/switchless/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/switchless/enclave/src/lib.rs b/samplecode/switchless/enclave/src/lib.rs index 9bc7332ab..8bb1989fe 100644 --- a/samplecode/switchless/enclave/src/lib.rs +++ b/samplecode/switchless/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/samplecode/template/app/build.rs b/samplecode/template/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/template/app/build.rs +++ b/samplecode/template/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/template/app/src/main.rs b/samplecode/template/app/src/main.rs index 4f9436e62..a8e7bcc3d 100644 --- a/samplecode/template/app/src/main.rs +++ b/samplecode/template/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/template/enclave/src/lib.rs b/samplecode/template/enclave/src/lib.rs index 10358e955..24098b48e 100644 --- a/samplecode/template/enclave/src/lib.rs +++ b/samplecode/template/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; diff --git a/samplecode/zlib-lazy-static-sample/app/build.rs b/samplecode/zlib-lazy-static-sample/app/build.rs index 23b8f5e70..935390b08 100644 --- a/samplecode/zlib-lazy-static-sample/app/build.rs +++ b/samplecode/zlib-lazy-static-sample/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/samplecode/zlib-lazy-static-sample/app/src/main.rs b/samplecode/zlib-lazy-static-sample/app/src/main.rs index c9f761d55..53ba19606 100644 --- a/samplecode/zlib-lazy-static-sample/app/src/main.rs +++ b/samplecode/zlib-lazy-static-sample/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; extern crate sgx_urts; diff --git a/samplecode/zlib-lazy-static-sample/enclave/src/lib.rs b/samplecode/zlib-lazy-static-sample/enclave/src/lib.rs index 084ce5154..f76320c2f 100644 --- a/samplecode/zlib-lazy-static-sample/enclave/src/lib.rs +++ b/samplecode/zlib-lazy-static-sample/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_types; diff --git a/sgx_alloc/src/alignalloc.rs b/sgx_alloc/src/alignalloc.rs index cc71359ec..e8daa955e 100644 --- a/sgx_alloc/src/alignalloc.rs +++ b/sgx_alloc/src/alignalloc.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! # align alloc crate for Rust SGX SDK //! diff --git a/sgx_alloc/src/alignbox.rs b/sgx_alloc/src/alignbox.rs index ebdc2c4bd..b5d1a3bcf 100644 --- a/sgx_alloc/src/alignbox.rs +++ b/sgx_alloc/src/alignbox.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! # align box crate for Rust SGX SDK diff --git a/sgx_alloc/src/capi.rs b/sgx_alloc/src/capi.rs index b83ecacf7..97f60be3b 100644 --- a/sgx_alloc/src/capi.rs +++ b/sgx_alloc/src/capi.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::alignalloc::{AlignAlloc, AlignReq}; use core::alloc::Layout; diff --git a/sgx_alloc/src/lib.rs b/sgx_alloc/src/lib.rs index 7a0309338..24d6e04f5 100644 --- a/sgx_alloc/src/lib.rs +++ b/sgx_alloc/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! # liballoc crate for Rust SGX SDK //! diff --git a/sgx_alloc/src/system.rs b/sgx_alloc/src/system.rs index 3d33f0418..532699579 100644 --- a/sgx_alloc/src/system.rs +++ b/sgx_alloc/src/system.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! # liballoc crate for Rust SGX SDK diff --git a/sgx_backtrace/sgx_backtrace_sys/build.rs b/sgx_backtrace/sgx_backtrace_sys/build.rs index 3097d75e9..13a406b61 100644 --- a/sgx_backtrace/sgx_backtrace_sys/build.rs +++ b/sgx_backtrace/sgx_backtrace_sys/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use sgx_build_helper as build_helper; diff --git a/sgx_backtrace/sgx_backtrace_sys/src/lib.rs b/sgx_backtrace/sgx_backtrace_sys/src/lib.rs index bdcb96988..a6e7f7e23 100644 --- a/sgx_backtrace/sgx_backtrace_sys/src/lib.rs +++ b/sgx_backtrace/sgx_backtrace_sys/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_backtrace/src/backtrace/libunwind.rs b/sgx_backtrace/src/backtrace/libunwind.rs index 1352ca62e..23f196ce7 100644 --- a/sgx_backtrace/src/backtrace/libunwind.rs +++ b/sgx_backtrace/src/backtrace/libunwind.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Backtrace support using libunwind/gcc_s/etc APIs. //! diff --git a/sgx_backtrace/src/backtrace/mod.rs b/sgx_backtrace/src/backtrace/mod.rs index f0cca5922..eae555eeb 100644 --- a/sgx_backtrace/src/backtrace/mod.rs +++ b/sgx_backtrace/src/backtrace/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::ffi::c_void; use core::fmt; diff --git a/sgx_backtrace/src/capture.rs b/sgx_backtrace/src/capture.rs index 8d48376b2..feaa71d36 100644 --- a/sgx_backtrace/src/capture.rs +++ b/sgx_backtrace/src/capture.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::PrintFmt; use crate::{resolve, resolve_frame, trace, BacktraceFmt, Symbol, SymbolName}; diff --git a/sgx_backtrace/src/lib.rs b/sgx_backtrace/src/lib.rs index d0da8b771..a9de80eba 100644 --- a/sgx_backtrace/src/lib.rs +++ b/sgx_backtrace/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! A library for acquiring a backtrace at runtime //! diff --git a/sgx_backtrace/src/print.rs b/sgx_backtrace/src/print.rs index f70a9caa7..02d4e5c43 100644 --- a/sgx_backtrace/src/print.rs +++ b/sgx_backtrace/src/print.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::{BacktraceFrame, BacktraceSymbol}; use super::{BytesOrWideString, Frame, SymbolName}; diff --git a/sgx_backtrace/src/symbolize/libbacktrace.rs b/sgx_backtrace/src/symbolize/libbacktrace.rs index b45d5ee35..f8e3e9405 100644 --- a/sgx_backtrace/src/symbolize/libbacktrace.rs +++ b/sgx_backtrace/src/symbolize/libbacktrace.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Symbolication strategy using the DWARF-parsing code in libbacktrace. //! diff --git a/sgx_backtrace/src/symbolize/mod.rs b/sgx_backtrace/src/symbolize/mod.rs index 3abd580f5..1a0508c23 100644 --- a/sgx_backtrace/src/symbolize/mod.rs +++ b/sgx_backtrace/src/symbolize/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use alloc::vec::Vec; use core::{fmt, str}; diff --git a/sgx_backtrace/src/types.rs b/sgx_backtrace/src/types.rs index a4d9675fb..d01ed31a0 100644 --- a/sgx_backtrace/src/types.rs +++ b/sgx_backtrace/src/types.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Platform dependent types. diff --git a/sgx_build_helper/build_helper/src/lib.rs b/sgx_build_helper/build_helper/src/lib.rs index f59e28cfb..18e451991 100644 --- a/sgx_build_helper/build_helper/src/lib.rs +++ b/sgx_build_helper/build_helper/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::ffi::OsStr; use std::fs::File; diff --git a/sgx_build_helper/download_prebuilt/build.rs b/sgx_build_helper/download_prebuilt/build.rs index c2552858d..e115b1ee9 100644 --- a/sgx_build_helper/download_prebuilt/build.rs +++ b/sgx_build_helper/download_prebuilt/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use sgx_build_helper as build_helper; diff --git a/sgx_build_helper/download_prebuilt/src/lib.rs b/sgx_build_helper/download_prebuilt/src/lib.rs index 46950e2d4..b248758bc 100644 --- a/sgx_build_helper/download_prebuilt/src/lib.rs +++ b/sgx_build_helper/download_prebuilt/src/lib.rs @@ -13,4 +13,4 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. diff --git a/sgx_crypto/sgx_crypto_sys/build.rs b/sgx_crypto/sgx_crypto_sys/build.rs index 10e561616..c2938a3fe 100644 --- a/sgx_crypto/sgx_crypto_sys/build.rs +++ b/sgx_crypto/sgx_crypto_sys/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(unused_imports)] diff --git a/sgx_crypto/sgx_crypto_sys/src/lib.rs b/sgx_crypto/sgx_crypto_sys/src/lib.rs index eff0b118e..6b759fde7 100644 --- a/sgx_crypto/sgx_crypto_sys/src/lib.rs +++ b/sgx_crypto/sgx_crypto_sys/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! # Cryptography Library //! diff --git a/sgx_crypto/src/aes/cbc.rs b/sgx_crypto/src/aes/cbc.rs index f0b6bdfdd..9ba390b36 100644 --- a/sgx_crypto/src/aes/cbc.rs +++ b/sgx_crypto/src/aes/cbc.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::array::TryFromSliceError; use core::convert::{From, TryFrom, TryInto}; diff --git a/sgx_crypto/src/aes/ccm.rs b/sgx_crypto/src/aes/ccm.rs index 52190b755..a75c48c9b 100644 --- a/sgx_crypto/src/aes/ccm.rs +++ b/sgx_crypto/src/aes/ccm.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::array::TryFromSliceError; use core::convert::{From, TryFrom, TryInto}; diff --git a/sgx_crypto/src/aes/ctr.rs b/sgx_crypto/src/aes/ctr.rs index bd2a49223..fee879cf0 100644 --- a/sgx_crypto/src/aes/ctr.rs +++ b/sgx_crypto/src/aes/ctr.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::array::TryFromSliceError; use core::convert::{From, TryFrom, TryInto}; diff --git a/sgx_crypto/src/aes/gcm.rs b/sgx_crypto/src/aes/gcm.rs index ab7d2a462..ba873e7bc 100644 --- a/sgx_crypto/src/aes/gcm.rs +++ b/sgx_crypto/src/aes/gcm.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::array::TryFromSliceError; use core::convert::{From, TryFrom, TryInto}; diff --git a/sgx_crypto/src/aes/mod.rs b/sgx_crypto/src/aes/mod.rs index 1302d5e59..c98618e4b 100644 --- a/sgx_crypto/src/aes/mod.rs +++ b/sgx_crypto/src/aes/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub mod cbc; pub mod ccm; diff --git a/sgx_crypto/src/ecc/mod.rs b/sgx_crypto/src/ecc/mod.rs index 4f7657f05..2032002c0 100644 --- a/sgx_crypto/src/ecc/mod.rs +++ b/sgx_crypto/src/ecc/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::mac::AesCMac; use core::convert::From; diff --git a/sgx_crypto/src/lib.rs b/sgx_crypto/src/lib.rs index e5797ef9a..02ec2caa6 100644 --- a/sgx_crypto/src/lib.rs +++ b/sgx_crypto/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! # Cryptography Library //! diff --git a/sgx_crypto/src/mac/cmac.rs b/sgx_crypto/src/mac/cmac.rs index 94daf3c9f..b5271b3f1 100644 --- a/sgx_crypto/src/mac/cmac.rs +++ b/sgx_crypto/src/mac/cmac.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::mem; use core::ptr; diff --git a/sgx_crypto/src/mac/hmac.rs b/sgx_crypto/src/mac/hmac.rs index ae8e0390f..fd184301b 100644 --- a/sgx_crypto/src/mac/hmac.rs +++ b/sgx_crypto/src/mac/hmac.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use alloc::borrow::ToOwned; use alloc::vec::Vec; diff --git a/sgx_crypto/src/mac/mod.rs b/sgx_crypto/src/mac/mod.rs index 6e57e830c..780754681 100644 --- a/sgx_crypto/src/mac/mod.rs +++ b/sgx_crypto/src/mac/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod cmac; mod hmac; diff --git a/sgx_crypto/src/rsa/mod.rs b/sgx_crypto/src/rsa/mod.rs index f2365bb2c..7b75c9c7f 100644 --- a/sgx_crypto/src/rsa/mod.rs +++ b/sgx_crypto/src/rsa/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod rsa2048; mod rsa3072; diff --git a/sgx_crypto/src/rsa/rsa2048.rs b/sgx_crypto/src/rsa/rsa2048.rs index e8c148ce0..acdaa732a 100644 --- a/sgx_crypto/src/rsa/rsa2048.rs +++ b/sgx_crypto/src/rsa/rsa2048.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::rsa::RsaPrivateType; use alloc::vec::Vec; diff --git a/sgx_crypto/src/rsa/rsa3072.rs b/sgx_crypto/src/rsa/rsa3072.rs index 5040bb06b..6fbbbdeee 100644 --- a/sgx_crypto/src/rsa/rsa3072.rs +++ b/sgx_crypto/src/rsa/rsa3072.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::rsa::RsaPrivateType; use alloc::vec::Vec; diff --git a/sgx_crypto/src/sha/mod.rs b/sgx_crypto/src/sha/mod.rs index c9c70bca5..7b45c1886 100644 --- a/sgx_crypto/src/sha/mod.rs +++ b/sgx_crypto/src/sha/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod sha1; mod sha256; diff --git a/sgx_crypto/src/sha/sha1.rs b/sgx_crypto/src/sha/sha1.rs index f661dc407..2e3ea8aca 100644 --- a/sgx_crypto/src/sha/sha1.rs +++ b/sgx_crypto/src/sha/sha1.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::mem; use core::ptr; diff --git a/sgx_crypto/src/sha/sha256.rs b/sgx_crypto/src/sha/sha256.rs index aecf841e7..6a479f255 100644 --- a/sgx_crypto/src/sha/sha256.rs +++ b/sgx_crypto/src/sha/sha256.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::mem; use core::ptr; diff --git a/sgx_crypto/src/sha/sha384.rs b/sgx_crypto/src/sha/sha384.rs index 44d4d6446..a7a714c4d 100644 --- a/sgx_crypto/src/sha/sha384.rs +++ b/sgx_crypto/src/sha/sha384.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::mem; use core::ptr; diff --git a/sgx_crypto/src/sm/mod.rs b/sgx_crypto/src/sm/mod.rs index f1e2644c4..3bdef972a 100644 --- a/sgx_crypto/src/sm/mod.rs +++ b/sgx_crypto/src/sm/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub mod sm2; pub mod sm3; diff --git a/sgx_crypto/src/sm/sm2/mod.rs b/sgx_crypto/src/sm/sm2/mod.rs index 53cff256c..08d15e2b0 100644 --- a/sgx_crypto/src/sm/sm2/mod.rs +++ b/sgx_crypto/src/sm/sm2/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sm4::ccm::{Aad, Nonce, Sm4Ccm}; use core::convert::From; diff --git a/sgx_crypto/src/sm/sm3/mod.rs b/sgx_crypto/src/sm/sm3/mod.rs index ab104c2e3..1329dc9a4 100644 --- a/sgx_crypto/src/sm/sm3/mod.rs +++ b/sgx_crypto/src/sm/sm3/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::mem; use core::ptr; diff --git a/sgx_crypto/src/sm/sm4/cbc.rs b/sgx_crypto/src/sm/sm4/cbc.rs index 3d903a59c..b59c7a159 100644 --- a/sgx_crypto/src/sm/sm4/cbc.rs +++ b/sgx_crypto/src/sm/sm4/cbc.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::array::TryFromSliceError; use core::convert::{From, TryFrom, TryInto}; diff --git a/sgx_crypto/src/sm/sm4/ccm.rs b/sgx_crypto/src/sm/sm4/ccm.rs index b065d8b93..1d17a95d4 100644 --- a/sgx_crypto/src/sm/sm4/ccm.rs +++ b/sgx_crypto/src/sm/sm4/ccm.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::array::TryFromSliceError; use core::convert::{From, TryFrom, TryInto}; diff --git a/sgx_crypto/src/sm/sm4/ctr.rs b/sgx_crypto/src/sm/sm4/ctr.rs index 8889573af..8deeb916b 100644 --- a/sgx_crypto/src/sm/sm4/ctr.rs +++ b/sgx_crypto/src/sm/sm4/ctr.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::array::TryFromSliceError; use core::convert::{From, TryFrom, TryInto}; diff --git a/sgx_crypto/src/sm/sm4/mod.rs b/sgx_crypto/src/sm/sm4/mod.rs index 851f6e2ec..28fafafdc 100644 --- a/sgx_crypto/src/sm/sm4/mod.rs +++ b/sgx_crypto/src/sm/sm4/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub mod cbc; pub mod ccm; diff --git a/sgx_dcap/message/src/lib.rs b/sgx_dcap/message/src/lib.rs index c3eb2d2f3..d61a73c16 100644 --- a/sgx_dcap/message/src/lib.rs +++ b/sgx_dcap/message/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_dcap/message/src/message.rs b/sgx_dcap/message/src/message.rs index 1437e7116..3fdc2c0ea 100644 --- a/sgx_dcap/message/src/message.rs +++ b/sgx_dcap/message/src/message.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use alloc::alloc::Global; use alloc::boxed::Box; diff --git a/sgx_dcap/tkey_exchange/src/capi/initiator.rs b/sgx_dcap/tkey_exchange/src/capi/initiator.rs index d642a1f89..b5919a2fb 100644 --- a/sgx_dcap/tkey_exchange/src/capi/initiator.rs +++ b/sgx_dcap/tkey_exchange/src/capi/initiator.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::session::Initiator; use crate::QveReportInfo; diff --git a/sgx_dcap/tkey_exchange/src/capi/mod.rs b/sgx_dcap/tkey_exchange/src/capi/mod.rs index 1cd9bd158..a892110cb 100644 --- a/sgx_dcap/tkey_exchange/src/capi/mod.rs +++ b/sgx_dcap/tkey_exchange/src/capi/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod initiator; mod responder; diff --git a/sgx_dcap/tkey_exchange/src/capi/responder.rs b/sgx_dcap/tkey_exchange/src/capi/responder.rs index 11d256c76..6a742951a 100644 --- a/sgx_dcap/tkey_exchange/src/capi/responder.rs +++ b/sgx_dcap/tkey_exchange/src/capi/responder.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::session::Responder; use crate::QveReportInfo; diff --git a/sgx_dcap/tkey_exchange/src/ecall/initiator.rs b/sgx_dcap/tkey_exchange/src/ecall/initiator.rs index 286bf349d..52f5c9f79 100644 --- a/sgx_dcap/tkey_exchange/src/ecall/initiator.rs +++ b/sgx_dcap/tkey_exchange/src/ecall/initiator.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::session::Initiator; use crate::QveReportInfo; diff --git a/sgx_dcap/tkey_exchange/src/ecall/mod.rs b/sgx_dcap/tkey_exchange/src/ecall/mod.rs index 1cd9bd158..a892110cb 100644 --- a/sgx_dcap/tkey_exchange/src/ecall/mod.rs +++ b/sgx_dcap/tkey_exchange/src/ecall/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod initiator; mod responder; diff --git a/sgx_dcap/tkey_exchange/src/ecall/responder.rs b/sgx_dcap/tkey_exchange/src/ecall/responder.rs index 9bc5b1e27..f0b975208 100644 --- a/sgx_dcap/tkey_exchange/src/ecall/responder.rs +++ b/sgx_dcap/tkey_exchange/src/ecall/responder.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::session::Responder; use crate::QveReportInfo; diff --git a/sgx_dcap/tkey_exchange/src/lib.rs b/sgx_dcap/tkey_exchange/src/lib.rs index 666ecb990..4b85a074f 100644 --- a/sgx_dcap/tkey_exchange/src/lib.rs +++ b/sgx_dcap/tkey_exchange/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_dcap/tkey_exchange/src/session/initiator.rs b/sgx_dcap/tkey_exchange/src/session/initiator.rs index 03f00b8e3..cedb34dd7 100644 --- a/sgx_dcap/tkey_exchange/src/session/initiator.rs +++ b/sgx_dcap/tkey_exchange/src/session/initiator.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::manager::INITIATOR_SESSION_MAGAGER; use super::manager::{Context, InitiatorState, Role, Session}; diff --git a/sgx_dcap/tkey_exchange/src/session/manager.rs b/sgx_dcap/tkey_exchange/src/session/manager.rs index de0f54c86..8e7af88c9 100644 --- a/sgx_dcap/tkey_exchange/src/session/manager.rs +++ b/sgx_dcap/tkey_exchange/src/session/manager.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use alloc::collections::LinkedList; use alloc::sync::Arc; diff --git a/sgx_dcap/tkey_exchange/src/session/mod.rs b/sgx_dcap/tkey_exchange/src/session/mod.rs index 612fb938e..d8624e3cc 100644 --- a/sgx_dcap/tkey_exchange/src/session/mod.rs +++ b/sgx_dcap/tkey_exchange/src/session/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod initiator; mod manager; diff --git a/sgx_dcap/tkey_exchange/src/session/responder.rs b/sgx_dcap/tkey_exchange/src/session/responder.rs index 3d8f7fb05..e6eb1210e 100644 --- a/sgx_dcap/tkey_exchange/src/session/responder.rs +++ b/sgx_dcap/tkey_exchange/src/session/responder.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::manager::RESPONDER_SESSION_MAGAGER; use super::manager::{DropKey, DropPrivateKey, DropShareKey}; diff --git a/sgx_dcap/tvl/src/capi.rs b/sgx_dcap/tvl/src/capi.rs index 30b8d08e3..72e4ec901 100644 --- a/sgx_dcap/tvl/src/capi.rs +++ b/sgx_dcap/tvl/src/capi.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::QveReportInfo; use core::ptr; diff --git a/sgx_dcap/tvl/src/lib.rs b/sgx_dcap/tvl/src/lib.rs index 751530f04..529599b50 100644 --- a/sgx_dcap/tvl/src/lib.rs +++ b/sgx_dcap/tvl/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_dcap/tvl/src/tvl.rs b/sgx_dcap/tvl/src/tvl.rs index 9f95f0cc8..e377eecdd 100644 --- a/sgx_dcap/tvl/src/tvl.rs +++ b/sgx_dcap/tvl/src/tvl.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::mem; use sgx_crypto::sha::Sha256; diff --git a/sgx_demangle/src/legacy.rs b/sgx_demangle/src/legacy.rs index 5f05d2a90..aa38c58a9 100644 --- a/sgx_demangle/src/legacy.rs +++ b/sgx_demangle/src/legacy.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::manual_strip)] diff --git a/sgx_demangle/src/lib.rs b/sgx_demangle/src/lib.rs index 5491e4c71..ba895492f 100644 --- a/sgx_demangle/src/lib.rs +++ b/sgx_demangle/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Demangle Rust compiler symbol names. //! diff --git a/sgx_demangle/src/v0.rs b/sgx_demangle/src/v0.rs index b034925c7..cd3ab2d22 100644 --- a/sgx_demangle/src/v0.rs +++ b/sgx_demangle/src/v0.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::convert::TryFrom; use core::{char, fmt, iter, mem, str}; diff --git a/sgx_edl/edl/inc/addrinfo.h b/sgx_edl/edl/inc/addrinfo.h index 4317805f4..48f9be256 100644 --- a/sgx_edl/edl/inc/addrinfo.h +++ b/sgx_edl/edl/inc/addrinfo.h @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #ifndef _EDL_ADDRINFO_H_ #define _EDL_ADDRINFO_H_ diff --git a/sgx_edl/edl/inc/dirent.h b/sgx_edl/edl/inc/dirent.h index 8ae83dede..ed07c4516 100644 --- a/sgx_edl/edl/inc/dirent.h +++ b/sgx_edl/edl/inc/dirent.h @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #ifndef _EDL_DIRENT_H_ #define _EDL_DIRENT_H_ diff --git a/sgx_edl/edl/inc/stat.h b/sgx_edl/edl/inc/stat.h index 451108128..ae81fafa1 100644 --- a/sgx_edl/edl/inc/stat.h +++ b/sgx_edl/edl/inc/stat.h @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #ifndef _EDL_STAT_H_ #define _EDL_STAT_H_ diff --git a/sgx_edl/src/lib.rs b/sgx_edl/src/lib.rs index 5ad485bcb..1e12dcfcb 100644 --- a/sgx_edl/src/lib.rs +++ b/sgx_edl/src/lib.rs @@ -13,6 +13,6 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] diff --git a/sgx_ffi/src/ascii.rs b/sgx_ffi/src/ascii.rs index 5f96fb86e..2b3cc0ae4 100644 --- a/sgx_ffi/src/ascii.rs +++ b/sgx_ffi/src/ascii.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Operations on ASCII strings and characters. //! diff --git a/sgx_ffi/src/c_str.rs b/sgx_ffi/src/c_str.rs index bce0e7ad3..a727a562d 100644 --- a/sgx_ffi/src/c_str.rs +++ b/sgx_ffi/src/c_str.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use alloc::ffi::{CString, FromVecWithNulError, IntoStringError, NulError}; pub use core::ffi::FromBytesUntilNulError; diff --git a/sgx_ffi/src/lib.rs b/sgx_ffi/src/lib.rs index 3c88849b5..82de1430d 100644 --- a/sgx_ffi/src/lib.rs +++ b/sgx_ffi/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_ffi/src/memchr.rs b/sgx_ffi/src/memchr.rs index 64eb51db9..559751e58 100644 --- a/sgx_ffi/src/memchr.rs +++ b/sgx_ffi/src/memchr.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_ffi/src/memchr/tests.rs b/sgx_ffi/src/memchr/tests.rs index dc73f59fd..83b5e5f6d 100644 --- a/sgx_ffi/src/memchr/tests.rs +++ b/sgx_ffi/src/memchr/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. // test the implementations for the current platform use super::{memchr, memrchr}; diff --git a/sgx_key_exchange/message/src/lib.rs b/sgx_key_exchange/message/src/lib.rs index c3eb2d2f3..d61a73c16 100644 --- a/sgx_key_exchange/message/src/lib.rs +++ b/sgx_key_exchange/message/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_key_exchange/message/src/message.rs b/sgx_key_exchange/message/src/message.rs index 20959cd36..8adb091b2 100644 --- a/sgx_key_exchange/message/src/message.rs +++ b/sgx_key_exchange/message/src/message.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use alloc::alloc::Global; use alloc::boxed::Box; diff --git a/sgx_key_exchange/tkey_exchange/src/capi.rs b/sgx_key_exchange/tkey_exchange/src/capi.rs index b50107969..479294048 100644 --- a/sgx_key_exchange/tkey_exchange/src/capi.rs +++ b/sgx_key_exchange/tkey_exchange/src/capi.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::session::Initiator; use core::mem::{self, ManuallyDrop}; diff --git a/sgx_key_exchange/tkey_exchange/src/lib.rs b/sgx_key_exchange/tkey_exchange/src/lib.rs index 11e066d06..1a408b860 100644 --- a/sgx_key_exchange/tkey_exchange/src/lib.rs +++ b/sgx_key_exchange/tkey_exchange/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_key_exchange/tkey_exchange/src/session/ecall.rs b/sgx_key_exchange/tkey_exchange/src/session/ecall.rs index e2525bdb1..a66c688a5 100644 --- a/sgx_key_exchange/tkey_exchange/src/session/ecall.rs +++ b/sgx_key_exchange/tkey_exchange/src/session/ecall.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::Initiator; use core::mem::{self, ManuallyDrop}; diff --git a/sgx_key_exchange/tkey_exchange/src/session/initiator.rs b/sgx_key_exchange/tkey_exchange/src/session/initiator.rs index f597aaa86..84e4ba531 100644 --- a/sgx_key_exchange/tkey_exchange/src/session/initiator.rs +++ b/sgx_key_exchange/tkey_exchange/src/session/initiator.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::manager::SESSION_MAGAGER; use super::manager::{Context, Session, State}; diff --git a/sgx_key_exchange/tkey_exchange/src/session/manager.rs b/sgx_key_exchange/tkey_exchange/src/session/manager.rs index 14b1b0432..d5f55c5f2 100644 --- a/sgx_key_exchange/tkey_exchange/src/session/manager.rs +++ b/sgx_key_exchange/tkey_exchange/src/session/manager.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use alloc::boxed::Box; use alloc::collections::LinkedList; diff --git a/sgx_key_exchange/tkey_exchange/src/session/mod.rs b/sgx_key_exchange/tkey_exchange/src/session/mod.rs index 88978faa6..c9d5d261b 100644 --- a/sgx_key_exchange/tkey_exchange/src/session/mod.rs +++ b/sgx_key_exchange/tkey_exchange/src/session/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod ecall; mod initiator; diff --git a/sgx_key_exchange/ukey_exchange/build.rs b/sgx_key_exchange/ukey_exchange/build.rs index f539790a0..f32117995 100644 --- a/sgx_key_exchange/ukey_exchange/build.rs +++ b/sgx_key_exchange/ukey_exchange/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/sgx_key_exchange/ukey_exchange/src/capi.rs b/sgx_key_exchange/ukey_exchange/src/capi.rs index 76b8cd9a3..0bf9fe747 100644 --- a/sgx_key_exchange/ukey_exchange/src/capi.rs +++ b/sgx_key_exchange/ukey_exchange/src/capi.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::Initiator; use sgx_ra_msg::RaMsg2; diff --git a/sgx_key_exchange/ukey_exchange/src/lib.rs b/sgx_key_exchange/ukey_exchange/src/lib.rs index 852d79e9f..f0248add1 100644 --- a/sgx_key_exchange/ukey_exchange/src/lib.rs +++ b/sgx_key_exchange/ukey_exchange/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![feature(allocator_api)] #![feature(lazy_cell)] diff --git a/sgx_key_exchange/ukey_exchange/src/session.rs b/sgx_key_exchange/ukey_exchange/src/session.rs index 97cec6988..a0917b475 100644 --- a/sgx_key_exchange/ukey_exchange/src/session.rs +++ b/sgx_key_exchange/ukey_exchange/src/session.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(dead_code)] diff --git a/sgx_libc/sgx_tlibc_sys/build.rs b/sgx_libc/sgx_tlibc_sys/build.rs index a153874bf..16fa98d00 100644 --- a/sgx_libc/sgx_tlibc_sys/build.rs +++ b/sgx_libc/sgx_tlibc_sys/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(unused_imports)] diff --git a/sgx_libc/sgx_tlibc_sys/src/lib.rs b/sgx_libc/sgx_tlibc_sys/src/lib.rs index 04bce7524..97ddd86ac 100644 --- a/sgx_libc/sgx_tlibc_sys/src/lib.rs +++ b/sgx_libc/sgx_tlibc_sys/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_libc/src/android/aarch64/mod.rs b/sgx_libc/src/android/aarch64/mod.rs index ac1277b9e..3e37a9836 100644 --- a/sgx_libc/src/android/aarch64/mod.rs +++ b/sgx_libc/src/android/aarch64/mod.rs @@ -13,6 +13,6 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use sgx_oc::android::aarch64::*; diff --git a/sgx_libc/src/android/mod.rs b/sgx_libc/src/android/mod.rs index 9ed58b920..e4ee236c7 100644 --- a/sgx_libc/src/android/mod.rs +++ b/sgx_libc/src/android/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. cfg_if! { if #[cfg(target_arch = "aarch64")] { diff --git a/sgx_libc/src/lib.rs b/sgx_libc/src/lib.rs index 80e517ca5..963541ddd 100644 --- a/sgx_libc/src/lib.rs +++ b/sgx_libc/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_libc/src/linux/edl/mod.rs b/sgx_libc/src/linux/edl/mod.rs index 43d72da11..69943379e 100644 --- a/sgx_libc/src/linux/edl/mod.rs +++ b/sgx_libc/src/linux/edl/mod.rs @@ -13,6 +13,6 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use sgx_oc::linux::edl::*; diff --git a/sgx_libc/src/linux/mod.rs b/sgx_libc/src/linux/mod.rs index 1b8074bb5..a35de71bf 100644 --- a/sgx_libc/src/linux/mod.rs +++ b/sgx_libc/src/linux/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::mem; use core::ptr; diff --git a/sgx_libc/src/linux/ocall/asyncio.rs b/sgx_libc/src/linux/ocall/asyncio.rs index 34d9678f4..ac6b8e1fd 100644 --- a/sgx_libc/src/linux/ocall/asyncio.rs +++ b/sgx_libc/src/linux/ocall/asyncio.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use alloc::vec::Vec; diff --git a/sgx_libc/src/linux/ocall/env.rs b/sgx_libc/src/linux/ocall/env.rs index 36fc6479b..ae21dbfff 100644 --- a/sgx_libc/src/linux/ocall/env.rs +++ b/sgx_libc/src/linux/ocall/env.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use core::ptr; diff --git a/sgx_libc/src/linux/ocall/fd.rs b/sgx_libc/src/linux/ocall/fd.rs index 3ab67ba05..199a9d43d 100644 --- a/sgx_libc/src/linux/ocall/fd.rs +++ b/sgx_libc/src/linux/ocall/fd.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use alloc::vec::Vec; diff --git a/sgx_libc/src/linux/ocall/file.rs b/sgx_libc/src/linux/ocall/file.rs index 2a68d423c..be8c364e5 100644 --- a/sgx_libc/src/linux/ocall/file.rs +++ b/sgx_libc/src/linux/ocall/file.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use core::ptr; diff --git a/sgx_libc/src/linux/ocall/mem.rs b/sgx_libc/src/linux/ocall/mem.rs index 1a29d49a8..de103597a 100644 --- a/sgx_libc/src/linux/ocall/mem.rs +++ b/sgx_libc/src/linux/ocall/mem.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use core::alloc::Layout; diff --git a/sgx_libc/src/linux/ocall/mod.rs b/sgx_libc/src/linux/ocall/mod.rs index 39e939984..c0de973f4 100644 --- a/sgx_libc/src/linux/ocall/mod.rs +++ b/sgx_libc/src/linux/ocall/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use crate::linux::edl::*; diff --git a/sgx_libc/src/linux/ocall/net.rs b/sgx_libc/src/linux/ocall/net.rs index 7e4189181..9a1c6e772 100644 --- a/sgx_libc/src/linux/ocall/net.rs +++ b/sgx_libc/src/linux/ocall/net.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use alloc::boxed::Box; diff --git a/sgx_libc/src/linux/ocall/pipe.rs b/sgx_libc/src/linux/ocall/pipe.rs index badbda576..cca0eefac 100644 --- a/sgx_libc/src/linux/ocall/pipe.rs +++ b/sgx_libc/src/linux/ocall/pipe.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use sgx_oc::linux::ocall; diff --git a/sgx_libc/src/linux/ocall/process.rs b/sgx_libc/src/linux/ocall/process.rs index c99007912..7da537e37 100644 --- a/sgx_libc/src/linux/ocall/process.rs +++ b/sgx_libc/src/linux/ocall/process.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use sgx_oc::linux::ocall; diff --git a/sgx_libc/src/linux/ocall/socket.rs b/sgx_libc/src/linux/ocall/socket.rs index 6a17b57b1..cb448a95a 100644 --- a/sgx_libc/src/linux/ocall/socket.rs +++ b/sgx_libc/src/linux/ocall/socket.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use core::cmp; diff --git a/sgx_libc/src/linux/ocall/sync.rs b/sgx_libc/src/linux/ocall/sync.rs index a05707a3a..ba38d9a20 100644 --- a/sgx_libc/src/linux/ocall/sync.rs +++ b/sgx_libc/src/linux/ocall/sync.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use core::convert::TryFrom; diff --git a/sgx_libc/src/linux/ocall/sys.rs b/sgx_libc/src/linux/ocall/sys.rs index 3e95dc262..ef9ba0f7f 100644 --- a/sgx_libc/src/linux/ocall/sys.rs +++ b/sgx_libc/src/linux/ocall/sys.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use core::mem; diff --git a/sgx_libc/src/linux/ocall/syscall.rs b/sgx_libc/src/linux/ocall/syscall.rs index 49b02f210..205a72b36 100644 --- a/sgx_libc/src/linux/ocall/syscall.rs +++ b/sgx_libc/src/linux/ocall/syscall.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::ocall::*; use crate::linux::*; diff --git a/sgx_libc/src/linux/ocall/thread.rs b/sgx_libc/src/linux/ocall/thread.rs index 0adf0a6ab..bb937399c 100644 --- a/sgx_libc/src/linux/ocall/thread.rs +++ b/sgx_libc/src/linux/ocall/thread.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use core::mem; diff --git a/sgx_libc/src/linux/ocall/time.rs b/sgx_libc/src/linux/ocall/time.rs index 51032adc7..6414861ce 100644 --- a/sgx_libc/src/linux/ocall/time.rs +++ b/sgx_libc/src/linux/ocall/time.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use core::mem; diff --git a/sgx_libc/src/linux/pthread/mod.rs b/sgx_libc/src/linux/pthread/mod.rs index 0e3d9627a..a5de45472 100644 --- a/sgx_libc/src/linux/pthread/mod.rs +++ b/sgx_libc/src/linux/pthread/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::linux::*; use core::mem; diff --git a/sgx_libc/src/linux/x86_64/mod.rs b/sgx_libc/src/linux/x86_64/mod.rs index b3320be37..921db36cf 100644 --- a/sgx_libc/src/linux/x86_64/mod.rs +++ b/sgx_libc/src/linux/x86_64/mod.rs @@ -13,6 +13,6 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use sgx_oc::linux::x86_64::*; diff --git a/sgx_libc/src/macros.rs b/sgx_libc/src/macros.rs index e105de98c..4fd5ce16a 100644 --- a/sgx_libc/src/macros.rs +++ b/sgx_libc/src/macros.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. macro_rules! cfg_if { // match if/else chains with a final `else` diff --git a/sgx_macros/src/lib.rs b/sgx_macros/src/lib.rs index 0480841c3..281b5ec96 100644 --- a/sgx_macros/src/lib.rs +++ b/sgx_macros/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate proc_macro; extern crate syn; diff --git a/sgx_no_tstd/src/lib.rs b/sgx_no_tstd/src/lib.rs index 683511c48..2f938cdfb 100644 --- a/sgx_no_tstd/src/lib.rs +++ b/sgx_no_tstd/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_oc/src/android/aarch64/mod.rs b/sgx_oc/src/android/aarch64/mod.rs index 46950e2d4..b248758bc 100644 --- a/sgx_oc/src/android/aarch64/mod.rs +++ b/sgx_oc/src/android/aarch64/mod.rs @@ -13,4 +13,4 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. diff --git a/sgx_oc/src/android/mod.rs b/sgx_oc/src/android/mod.rs index 2841c15b3..a4a41b40c 100644 --- a/sgx_oc/src/android/mod.rs +++ b/sgx_oc/src/android/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. cfg_if! { if #[cfg(target_arch = "aarch64")] { diff --git a/sgx_oc/src/lib.rs b/sgx_oc/src/lib.rs index fcaea2039..355a64d84 100644 --- a/sgx_oc/src/lib.rs +++ b/sgx_oc/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_oc/src/linux/edl/asyncio.rs b/sgx_oc/src/linux/edl/asyncio.rs index 3329133d0..5780e14f6 100644 --- a/sgx_oc/src/linux/edl/asyncio.rs +++ b/sgx_oc/src/linux/edl/asyncio.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/edl/cpuid.rs b/sgx_oc/src/linux/edl/cpuid.rs index 6f8883f9c..2f1f53d3c 100644 --- a/sgx_oc/src/linux/edl/cpuid.rs +++ b/sgx_oc/src/linux/edl/cpuid.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/edl/env.rs b/sgx_oc/src/linux/edl/env.rs index 647632175..2841b0e08 100644 --- a/sgx_oc/src/linux/edl/env.rs +++ b/sgx_oc/src/linux/edl/env.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/edl/fd.rs b/sgx_oc/src/linux/edl/fd.rs index 77a1b30c5..7b6f09ee7 100644 --- a/sgx_oc/src/linux/edl/fd.rs +++ b/sgx_oc/src/linux/edl/fd.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/edl/file.rs b/sgx_oc/src/linux/edl/file.rs index c0d81a155..25e5080e6 100644 --- a/sgx_oc/src/linux/edl/file.rs +++ b/sgx_oc/src/linux/edl/file.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/edl/mem.rs b/sgx_oc/src/linux/edl/mem.rs index 64bb10c81..ce14f7216 100644 --- a/sgx_oc/src/linux/edl/mem.rs +++ b/sgx_oc/src/linux/edl/mem.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/edl/mod.rs b/sgx_oc/src/linux/edl/mod.rs index d621cf34b..b2d44eeed 100644 --- a/sgx_oc/src/linux/edl/mod.rs +++ b/sgx_oc/src/linux/edl/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use sgx_types::error::SgxStatus; diff --git a/sgx_oc/src/linux/edl/msbuf.rs b/sgx_oc/src/linux/edl/msbuf.rs index 4b9a79678..7deba8d9a 100644 --- a/sgx_oc/src/linux/edl/msbuf.rs +++ b/sgx_oc/src/linux/edl/msbuf.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/edl/net.rs b/sgx_oc/src/linux/edl/net.rs index 27981ad73..98b7c5175 100644 --- a/sgx_oc/src/linux/edl/net.rs +++ b/sgx_oc/src/linux/edl/net.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/edl/pipe.rs b/sgx_oc/src/linux/edl/pipe.rs index 0cb1da356..71bf0debf 100644 --- a/sgx_oc/src/linux/edl/pipe.rs +++ b/sgx_oc/src/linux/edl/pipe.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/edl/process.rs b/sgx_oc/src/linux/edl/process.rs index c4fd2f37a..61037412a 100644 --- a/sgx_oc/src/linux/edl/process.rs +++ b/sgx_oc/src/linux/edl/process.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/edl/socket.rs b/sgx_oc/src/linux/edl/socket.rs index 91f5acedf..47caae754 100644 --- a/sgx_oc/src/linux/edl/socket.rs +++ b/sgx_oc/src/linux/edl/socket.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/edl/sys.rs b/sgx_oc/src/linux/edl/sys.rs index 794685c2f..bdf1fdc85 100644 --- a/sgx_oc/src/linux/edl/sys.rs +++ b/sgx_oc/src/linux/edl/sys.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/edl/thread.rs b/sgx_oc/src/linux/edl/thread.rs index 65dff2c78..035e50d53 100644 --- a/sgx_oc/src/linux/edl/thread.rs +++ b/sgx_oc/src/linux/edl/thread.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/edl/time.rs b/sgx_oc/src/linux/edl/time.rs index dfc41d460..0ac766470 100644 --- a/sgx_oc/src/linux/edl/time.rs +++ b/sgx_oc/src/linux/edl/time.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::sgx_status_t; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/mod.rs b/sgx_oc/src/linux/mod.rs index b3f9f59ee..6a5c09c46 100644 --- a/sgx_oc/src/linux/mod.rs +++ b/sgx_oc/src/linux/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::mem; diff --git a/sgx_oc/src/linux/ocall/asyncio.rs b/sgx_oc/src/linux/ocall/asyncio.rs index d100de494..e4860eba0 100644 --- a/sgx_oc/src/linux/ocall/asyncio.rs +++ b/sgx_oc/src/linux/ocall/asyncio.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use core::mem; diff --git a/sgx_oc/src/linux/ocall/cpuid.rs b/sgx_oc/src/linux/ocall/cpuid.rs index 4ed98272b..86496ab3f 100644 --- a/sgx_oc/src/linux/ocall/cpuid.rs +++ b/sgx_oc/src/linux/ocall/cpuid.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use sgx_types::marker::ContiguousMemory; diff --git a/sgx_oc/src/linux/ocall/env.rs b/sgx_oc/src/linux/ocall/env.rs index 87257552a..31e2126cc 100644 --- a/sgx_oc/src/linux/ocall/env.rs +++ b/sgx_oc/src/linux/ocall/env.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use alloc::boxed::Box; diff --git a/sgx_oc/src/linux/ocall/fd.rs b/sgx_oc/src/linux/ocall/fd.rs index c09049ee9..e387cd320 100644 --- a/sgx_oc/src/linux/ocall/fd.rs +++ b/sgx_oc/src/linux/ocall/fd.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use core::cmp; diff --git a/sgx_oc/src/linux/ocall/file.rs b/sgx_oc/src/linux/ocall/file.rs index c87c51fa9..7e37ec7cd 100644 --- a/sgx_oc/src/linux/ocall/file.rs +++ b/sgx_oc/src/linux/ocall/file.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use core::ptr; diff --git a/sgx_oc/src/linux/ocall/hostbuf.rs b/sgx_oc/src/linux/ocall/hostbuf.rs index 39c40f988..148e05530 100644 --- a/sgx_oc/src/linux/ocall/hostbuf.rs +++ b/sgx_oc/src/linux/ocall/hostbuf.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use core::convert::From; diff --git a/sgx_oc/src/linux/ocall/mem.rs b/sgx_oc/src/linux/ocall/mem.rs index dee68f2c6..13b0e98a4 100644 --- a/sgx_oc/src/linux/ocall/mem.rs +++ b/sgx_oc/src/linux/ocall/mem.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use core::alloc::{AllocError, Allocator, Layout}; diff --git a/sgx_oc/src/linux/ocall/mod.rs b/sgx_oc/src/linux/ocall/mod.rs index e450aa74a..2a726bf01 100644 --- a/sgx_oc/src/linux/ocall/mod.rs +++ b/sgx_oc/src/linux/ocall/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::alloc::borrow::ToOwned; use crate::linux::x86_64::*; diff --git a/sgx_oc/src/linux/ocall/msbuf.rs b/sgx_oc/src/linux/ocall/msbuf.rs index 626b6a75e..72d4ace0f 100644 --- a/sgx_oc/src/linux/ocall/msbuf.rs +++ b/sgx_oc/src/linux/ocall/msbuf.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use core::cmp; diff --git a/sgx_oc/src/linux/ocall/net.rs b/sgx_oc/src/linux/ocall/net.rs index d4f11a3ce..cfb758ea8 100644 --- a/sgx_oc/src/linux/ocall/net.rs +++ b/sgx_oc/src/linux/ocall/net.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use alloc::vec::Vec; diff --git a/sgx_oc/src/linux/ocall/pipe.rs b/sgx_oc/src/linux/ocall/pipe.rs index 2d98c2a72..fb970525a 100644 --- a/sgx_oc/src/linux/ocall/pipe.rs +++ b/sgx_oc/src/linux/ocall/pipe.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_oc/src/linux/ocall/process.rs b/sgx_oc/src/linux/ocall/process.rs index a070d6a78..82a36ff3c 100644 --- a/sgx_oc/src/linux/ocall/process.rs +++ b/sgx_oc/src/linux/ocall/process.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_oc/src/linux/ocall/socket.rs b/sgx_oc/src/linux/ocall/socket.rs index 5f9d23f7c..e4c0c9ada 100644 --- a/sgx_oc/src/linux/ocall/socket.rs +++ b/sgx_oc/src/linux/ocall/socket.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use core::convert::From; diff --git a/sgx_oc/src/linux/ocall/socket_msg.rs b/sgx_oc/src/linux/ocall/socket_msg.rs index 81362ef64..9793c44d6 100644 --- a/sgx_oc/src/linux/ocall/socket_msg.rs +++ b/sgx_oc/src/linux/ocall/socket_msg.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use core::cmp; diff --git a/sgx_oc/src/linux/ocall/sys.rs b/sgx_oc/src/linux/ocall/sys.rs index e3d578e33..12d77175a 100644 --- a/sgx_oc/src/linux/ocall/sys.rs +++ b/sgx_oc/src/linux/ocall/sys.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use core::mem; diff --git a/sgx_oc/src/linux/ocall/thread.rs b/sgx_oc/src/linux/ocall/thread.rs index 183b446bc..98bed6020 100644 --- a/sgx_oc/src/linux/ocall/thread.rs +++ b/sgx_oc/src/linux/ocall/thread.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_oc/src/linux/ocall/time.rs b/sgx_oc/src/linux/ocall/time.rs index 8d02cda16..04b5a8210 100644 --- a/sgx_oc/src/linux/ocall/time.rs +++ b/sgx_oc/src/linux/ocall/time.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_oc/src/linux/x86_64/mod.rs b/sgx_oc/src/linux/x86_64/mod.rs index 3d88e8ecb..da39123f3 100644 --- a/sgx_oc/src/linux/x86_64/mod.rs +++ b/sgx_oc/src/linux/x86_64/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use sgx_types::error::errno::*; pub use sgx_types::types::time_t; diff --git a/sgx_oc/src/macros.rs b/sgx_oc/src/macros.rs index 1808b9aeb..72e3fbdfc 100644 --- a/sgx_oc/src/macros.rs +++ b/sgx_oc/src/macros.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. macro_rules! cfg_if { // match if/else chains with a final `else` diff --git a/sgx_protected_fs/tfs/src/capi.rs b/sgx_protected_fs/tfs/src/capi.rs index 70f90c7e8..50ad765c0 100644 --- a/sgx_protected_fs/tfs/src/capi.rs +++ b/sgx_protected_fs/tfs/src/capi.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::error::FsResult; use crate::sys::{self as fs_imp, EncryptMode, OpenOptions, RawProtectedFile, SgxFile}; diff --git a/sgx_protected_fs/tfs/src/fs.rs b/sgx_protected_fs/tfs/src/fs.rs index bce162afb..a0fb4179b 100644 --- a/sgx_protected_fs/tfs/src/fs.rs +++ b/sgx_protected_fs/tfs/src/fs.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys as fs_imp; use sgx_types::types::{Key128bit, Mac128bit}; diff --git a/sgx_protected_fs/tfs/src/lib.rs b/sgx_protected_fs/tfs/src/lib.rs index 7a5d45c05..82089816c 100644 --- a/sgx_protected_fs/tfs/src/lib.rs +++ b/sgx_protected_fs/tfs/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![cfg_attr(all(feature = "tfs", not(target_vendor = "teaclave")), no_std)] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_protected_fs/tfs/src/sys/cache/list.rs b/sgx_protected_fs/tfs/src/sys/cache/list.rs index 21f3e0a45..cae8a4d48 100644 --- a/sgx_protected_fs/tfs/src/sys/cache/list.rs +++ b/sgx_protected_fs/tfs/src/sys/cache/list.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::boxed::Box; use std::cmp::Ordering; diff --git a/sgx_protected_fs/tfs/src/sys/cache/mod.rs b/sgx_protected_fs/tfs/src/sys/cache/mod.rs index 6e06eb822..dbaf881f3 100644 --- a/sgx_protected_fs/tfs/src/sys/cache/mod.rs +++ b/sgx_protected_fs/tfs/src/sys/cache/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(dead_code)] diff --git a/sgx_protected_fs/tfs/src/sys/error.rs b/sgx_protected_fs/tfs/src/sys/error.rs index 6ee728204..00b7510ce 100644 --- a/sgx_protected_fs/tfs/src/sys/error.rs +++ b/sgx_protected_fs/tfs/src/sys/error.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use sgx_types::error::SgxStatus; use std::error::Error; diff --git a/sgx_protected_fs/tfs/src/sys/file/close.rs b/sgx_protected_fs/tfs/src/sys/file/close.rs index fe1d91443..fffd7a54e 100644 --- a/sgx_protected_fs/tfs/src/sys/file/close.rs +++ b/sgx_protected_fs/tfs/src/sys/file/close.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::error::FsResult; use crate::sys::file::{CloseMode, FileInner, FileStatus}; diff --git a/sgx_protected_fs/tfs/src/sys/file/flush.rs b/sgx_protected_fs/tfs/src/sys/file/flush.rs index 8b47e523a..0ad3b8ab3 100644 --- a/sgx_protected_fs/tfs/src/sys/file/flush.rs +++ b/sgx_protected_fs/tfs/src/sys/file/flush.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::error::FsResult; use crate::sys::file::{FileInner, FileStatus}; diff --git a/sgx_protected_fs/tfs/src/sys/file/mod.rs b/sgx_protected_fs/tfs/src/sys/file/mod.rs index 9d9ba9cc6..83cf7ccd2 100644 --- a/sgx_protected_fs/tfs/src/sys/file/mod.rs +++ b/sgx_protected_fs/tfs/src/sys/file/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::cache::LruCache; use crate::sys::error::{FsError, FsResult}; diff --git a/sgx_protected_fs/tfs/src/sys/file/node.rs b/sgx_protected_fs/tfs/src/sys/file/node.rs index 24ad03c42..1dd815f88 100644 --- a/sgx_protected_fs/tfs/src/sys/file/node.rs +++ b/sgx_protected_fs/tfs/src/sys/file/node.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::error::FsResult; use crate::sys::file::{FileInner, FileStatus}; diff --git a/sgx_protected_fs/tfs/src/sys/file/open.rs b/sgx_protected_fs/tfs/src/sys/file/open.rs index 4b3987199..f54e8730e 100644 --- a/sgx_protected_fs/tfs/src/sys/file/open.rs +++ b/sgx_protected_fs/tfs/src/sys/file/open.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::cache::LruCache; use crate::sys::error::FsResult; diff --git a/sgx_protected_fs/tfs/src/sys/file/other.rs b/sgx_protected_fs/tfs/src/sys/file/other.rs index 2e2fa9187..8e2ea8943 100644 --- a/sgx_protected_fs/tfs/src/sys/file/other.rs +++ b/sgx_protected_fs/tfs/src/sys/file/other.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::error::{FsError, FsResult}; use crate::sys::file::{FileInner, FileStatus}; diff --git a/sgx_protected_fs/tfs/src/sys/file/read.rs b/sgx_protected_fs/tfs/src/sys/file/read.rs index d3b9b7c5b..3b6011ea0 100644 --- a/sgx_protected_fs/tfs/src/sys/file/read.rs +++ b/sgx_protected_fs/tfs/src/sys/file/read.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::error::FsResult; use crate::sys::file::FileInner; diff --git a/sgx_protected_fs/tfs/src/sys/file/write.rs b/sgx_protected_fs/tfs/src/sys/file/write.rs index d35c1e5b7..6ac76de54 100644 --- a/sgx_protected_fs/tfs/src/sys/file/write.rs +++ b/sgx_protected_fs/tfs/src/sys/file/write.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::error::FsResult; use crate::sys::file::FileInner; diff --git a/sgx_protected_fs/tfs/src/sys/host/mod.rs b/sgx_protected_fs/tfs/src/sys/host/mod.rs index b85b7eaf4..9303257d7 100644 --- a/sgx_protected_fs/tfs/src/sys/host/mod.rs +++ b/sgx_protected_fs/tfs/src/sys/host/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::error::FsResult; diff --git a/sgx_protected_fs/tfs/src/sys/host/ocall.rs b/sgx_protected_fs/tfs/src/sys/host/ocall.rs index 3bb2607eb..4ea6bb885 100644 --- a/sgx_protected_fs/tfs/src/sys/host/ocall.rs +++ b/sgx_protected_fs/tfs/src/sys/host/ocall.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::HostFs; use crate::sys::error::FsResult; diff --git a/sgx_protected_fs/tfs/src/sys/host/ufs.rs b/sgx_protected_fs/tfs/src/sys/host/ufs.rs index d069c1698..f5f3ac679 100644 --- a/sgx_protected_fs/tfs/src/sys/host/ufs.rs +++ b/sgx_protected_fs/tfs/src/sys/host/ufs.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::HostFs; use crate::sys::error::FsResult; diff --git a/sgx_protected_fs/tfs/src/sys/keys.rs b/sgx_protected_fs/tfs/src/sys/keys.rs index fa17e453a..22c18a535 100644 --- a/sgx_protected_fs/tfs/src/sys/keys.rs +++ b/sgx_protected_fs/tfs/src/sys/keys.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::error::FsResult; use crate::sys::file::OpenMode; diff --git a/sgx_protected_fs/tfs/src/sys/metadata.rs b/sgx_protected_fs/tfs/src/sys/metadata.rs index 019765390..79cb1d16b 100644 --- a/sgx_protected_fs/tfs/src/sys/metadata.rs +++ b/sgx_protected_fs/tfs/src/sys/metadata.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::error::FsResult; use crate::sys::file::OpenMode; diff --git a/sgx_protected_fs/tfs/src/sys/mod.rs b/sgx_protected_fs/tfs/src/sys/mod.rs index 19517eaea..593114adf 100644 --- a/sgx_protected_fs/tfs/src/sys/mod.rs +++ b/sgx_protected_fs/tfs/src/sys/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::error::FsError; use crate::sys::file::{self as file_imp, ProtectedFile}; diff --git a/sgx_protected_fs/tfs/src/sys/node.rs b/sgx_protected_fs/tfs/src/sys/node.rs index 853e52923..9ae8e1bfc 100644 --- a/sgx_protected_fs/tfs/src/sys/node.rs +++ b/sgx_protected_fs/tfs/src/sys/node.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::arc_with_non_send_sync)] diff --git a/sgx_protected_fs/ufs/src/lib.rs b/sgx_protected_fs/ufs/src/lib.rs index 4e304f019..f8ed28a6e 100644 --- a/sgx_protected_fs/ufs/src/lib.rs +++ b/sgx_protected_fs/ufs/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[macro_use] extern crate sgx_types; diff --git a/sgx_rand/derive/src/lib.rs b/sgx_rand/derive/src/lib.rs index d8c154d58..458f49cd1 100644 --- a/sgx_rand/derive/src/lib.rs +++ b/sgx_rand/derive/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Support for `#[derive(Rand)]` //! diff --git a/sgx_rand/src/chacha.rs b/sgx_rand/src/chacha.rs index 8c86b4fa7..7fe1f7036 100644 --- a/sgx_rand/src/chacha.rs +++ b/sgx_rand/src/chacha.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! The ChaCha random number generator. diff --git a/sgx_rand/src/distributions/exponential.rs b/sgx_rand/src/distributions/exponential.rs index cccffaaca..7f262edf0 100644 --- a/sgx_rand/src/distributions/exponential.rs +++ b/sgx_rand/src/distributions/exponential.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! The exponential distribution. diff --git a/sgx_rand/src/distributions/gamma.rs b/sgx_rand/src/distributions/gamma.rs index 07d0a810e..f94d98284 100644 --- a/sgx_rand/src/distributions/gamma.rs +++ b/sgx_rand/src/distributions/gamma.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! The Gamma and derived distributions. diff --git a/sgx_rand/src/distributions/mod.rs b/sgx_rand/src/distributions/mod.rs index dc55ee700..f8661ff1e 100644 --- a/sgx_rand/src/distributions/mod.rs +++ b/sgx_rand/src/distributions/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Sampling from random distributions. //! diff --git a/sgx_rand/src/distributions/range.rs b/sgx_rand/src/distributions/range.rs index cc3f1c7a6..3cc7dbc16 100644 --- a/sgx_rand/src/distributions/range.rs +++ b/sgx_rand/src/distributions/range.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Generating numbers between two others. diff --git a/sgx_rand/src/distributions/ziggurat_tables.rs b/sgx_rand/src/distributions/ziggurat_tables.rs index e8c202744..e6f227638 100644 --- a/sgx_rand/src/distributions/ziggurat_tables.rs +++ b/sgx_rand/src/distributions/ziggurat_tables.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::excessive_precision)] diff --git a/sgx_rand/src/isaac.rs b/sgx_rand/src/isaac.rs index 13c5d4f23..86c72bbb8 100644 --- a/sgx_rand/src/isaac.rs +++ b/sgx_rand/src/isaac.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! The ISAAC random number generator. diff --git a/sgx_rand/src/lib.rs b/sgx_rand/src/lib.rs index 9ed620632..ea2a41c6d 100644 --- a/sgx_rand/src/lib.rs +++ b/sgx_rand/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Utilities for random number generation diff --git a/sgx_rand/src/os.rs b/sgx_rand/src/os.rs index 200a2cb05..0ed2ef772 100644 --- a/sgx_rand/src/os.rs +++ b/sgx_rand/src/os.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Interfaces to the operating system provided random number //! generators. diff --git a/sgx_rand/src/rand_impls.rs b/sgx_rand/src/rand_impls.rs index 10019cb30..aef92dd4a 100644 --- a/sgx_rand/src/rand_impls.rs +++ b/sgx_rand/src/rand_impls.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! The implementations of `Rand` for the built-in types. diff --git a/sgx_rand/src/read.rs b/sgx_rand/src/read.rs index d73080456..c6a1f6bf2 100644 --- a/sgx_rand/src/read.rs +++ b/sgx_rand/src/read.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! A wrapper around any Read to treat it as an RNG. diff --git a/sgx_rand/src/reseeding.rs b/sgx_rand/src/reseeding.rs index 34088c422..8b9c912cd 100644 --- a/sgx_rand/src/reseeding.rs +++ b/sgx_rand/src/reseeding.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! A wrapper around another RNG that reseeds it after it //! generates a certain number of random bytes. diff --git a/sgx_rsrvmm/src/alloc.rs b/sgx_rsrvmm/src/alloc.rs index 8d64ab453..4413aff60 100644 --- a/sgx_rsrvmm/src/alloc.rs +++ b/sgx_rsrvmm/src/alloc.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::rsrvmm::manager::MmAllocAddr; use crate::rsrvmm::RsrvMem; diff --git a/sgx_rsrvmm/src/capi.rs b/sgx_rsrvmm/src/capi.rs index a81b10055..7c3521fcb 100644 --- a/sgx_rsrvmm/src/capi.rs +++ b/sgx_rsrvmm/src/capi.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::rsrvmm::manager::MmAllocAddr; use crate::rsrvmm::RsrvMem; diff --git a/sgx_rsrvmm/src/lib.rs b/sgx_rsrvmm/src/lib.rs index e787c7b39..9613cb1a4 100644 --- a/sgx_rsrvmm/src/lib.rs +++ b/sgx_rsrvmm/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_rsrvmm/src/map.rs b/sgx_rsrvmm/src/map.rs index 6a6ffedc6..5362e5ce5 100644 --- a/sgx_rsrvmm/src/map.rs +++ b/sgx_rsrvmm/src/map.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::rsrvmm::RsrvMem; use alloc_crate::sync::Arc; diff --git a/sgx_rsrvmm/src/rsrvmm/area.rs b/sgx_rsrvmm/src/rsrvmm/area.rs index bb74c9345..a9f5648f0 100644 --- a/sgx_rsrvmm/src/rsrvmm/area.rs +++ b/sgx_rsrvmm/src/rsrvmm/area.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::map::{Map, MapObject}; use crate::rsrvmm::range::MmRange; diff --git a/sgx_rsrvmm/src/rsrvmm/manager.rs b/sgx_rsrvmm/src/rsrvmm/manager.rs index 656bd7a3e..dc491e201 100644 --- a/sgx_rsrvmm/src/rsrvmm/manager.rs +++ b/sgx_rsrvmm/src/rsrvmm/manager.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::map::{MapAddr, Nothing}; use crate::rsrvmm::area::{MmArea, MmPerm, MmState, MmType}; diff --git a/sgx_rsrvmm/src/rsrvmm/mod.rs b/sgx_rsrvmm/src/rsrvmm/mod.rs index 921693863..795488b5c 100644 --- a/sgx_rsrvmm/src/rsrvmm/mod.rs +++ b/sgx_rsrvmm/src/rsrvmm/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use self::area::{MmArea, MmPerm, MmState, MmType}; use self::manager::{MmAllocAddr, MmManager}; diff --git a/sgx_rsrvmm/src/rsrvmm/range.rs b/sgx_rsrvmm/src/rsrvmm/range.rs index 9836f1a61..c14dc4a86 100644 --- a/sgx_rsrvmm/src/rsrvmm/range.rs +++ b/sgx_rsrvmm/src/rsrvmm/range.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use alloc_crate::vec::Vec; use core::fmt; diff --git a/sgx_serialize/derive/src/bound.rs b/sgx_serialize/derive/src/bound.rs index f8ff30b99..ed62a447c 100644 --- a/sgx_serialize/derive/src/bound.rs +++ b/sgx_serialize/derive/src/bound.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use syn::{self}; diff --git a/sgx_serialize/derive/src/decode.rs b/sgx_serialize/derive/src/decode.rs index ad26a52aa..d21ff74ef 100644 --- a/sgx_serialize/derive/src/decode.rs +++ b/sgx_serialize/derive/src/decode.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! //! The mod implements the function of Decodable. diff --git a/sgx_serialize/derive/src/encode.rs b/sgx_serialize/derive/src/encode.rs index e9e368651..e91358fb1 100644 --- a/sgx_serialize/derive/src/encode.rs +++ b/sgx_serialize/derive/src/encode.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! //! The mod implements the function of Encodable. diff --git a/sgx_serialize/derive/src/fragment.rs b/sgx_serialize/derive/src/fragment.rs index 9fdf9dd27..e6a546881 100644 --- a/sgx_serialize/derive/src/fragment.rs +++ b/sgx_serialize/derive/src/fragment.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use quote::{ToTokens, Tokens}; diff --git a/sgx_serialize/derive/src/internals/ast.rs b/sgx_serialize/derive/src/internals/ast.rs index 963288842..1dc1c82b4 100644 --- a/sgx_serialize/derive/src/internals/ast.rs +++ b/sgx_serialize/derive/src/internals/ast.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::Ctxt; diff --git a/sgx_serialize/derive/src/internals/ctxt.rs b/sgx_serialize/derive/src/internals/ctxt.rs index 3f9daefa2..b6f5ab223 100644 --- a/sgx_serialize/derive/src/internals/ctxt.rs +++ b/sgx_serialize/derive/src/internals/ctxt.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::cell::RefCell; use std::fmt::Display; diff --git a/sgx_serialize/derive/src/internals/mod.rs b/sgx_serialize/derive/src/internals/mod.rs index f21b71449..8c3649529 100644 --- a/sgx_serialize/derive/src/internals/mod.rs +++ b/sgx_serialize/derive/src/internals/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! //! It's helpful for parsing the structure and fields of struct and enum. diff --git a/sgx_serialize/derive/src/lib.rs b/sgx_serialize/derive/src/lib.rs index f305154c7..7a61eee1d 100644 --- a/sgx_serialize/derive/src/lib.rs +++ b/sgx_serialize/derive/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! This crate provides sgx_serialize's two derive macros. //! diff --git a/sgx_serialize/derive/src/param.rs b/sgx_serialize/derive/src/param.rs index 70ef8d5b4..f99991dd0 100644 --- a/sgx_serialize/derive/src/param.rs +++ b/sgx_serialize/derive/src/param.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::bound; use crate::internals::ast::Container; diff --git a/sgx_serialize/src/collection.rs b/sgx_serialize/src/collection.rs index f87dd3fa6..d1b7d1ae6 100644 --- a/sgx_serialize/src/collection.rs +++ b/sgx_serialize/src/collection.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Implementations of serialization for structures found in liballoc diff --git a/sgx_serialize/src/json.rs b/sgx_serialize/src/json.rs index bb1ca2277..536c7c4bf 100644 --- a/sgx_serialize/src/json.rs +++ b/sgx_serialize/src/json.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![forbid(non_camel_case_types)] #![allow(missing_docs)] diff --git a/sgx_serialize/src/leb128.rs b/sgx_serialize/src/leb128.rs index 1bd1d25f3..163efb96b 100644 --- a/sgx_serialize/src/leb128.rs +++ b/sgx_serialize/src/leb128.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![macro_use] diff --git a/sgx_serialize/src/lib.rs b/sgx_serialize/src/lib.rs index ff97eef0d..a2f442d4c 100644 --- a/sgx_serialize/src/lib.rs +++ b/sgx_serialize/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Support code for encoding and decoding types. diff --git a/sgx_serialize/src/opaque.rs b/sgx_serialize/src/opaque.rs index 910f2714f..0e92f9c5a 100644 --- a/sgx_serialize/src/opaque.rs +++ b/sgx_serialize/src/opaque.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! //! The mod opaque Encoder and Decoder container to save buffer of target types diff --git a/sgx_serialize/src/serialize.rs b/sgx_serialize/src/serialize.rs index caf211d7e..516eecce0 100644 --- a/sgx_serialize/src/serialize.rs +++ b/sgx_serialize/src/serialize.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. // Support code for encoding and decoding types. /* diff --git a/sgx_serialize/src/types.rs b/sgx_serialize/src/types.rs index 35dc9006c..f4be14d1e 100644 --- a/sgx_serialize/src/types.rs +++ b/sgx_serialize/src/types.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::{Decodable, Decoder, Encodable, Encoder}; use sgx_types::types::EnclaveIdentity; diff --git a/sgx_sync/src/barrier.rs b/sgx_sync/src/barrier.rs index d92d12803..14fd3af30 100644 --- a/sgx_sync/src/barrier.rs +++ b/sgx_sync/src/barrier.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::spin::SpinMutex; use core::fmt; diff --git a/sgx_sync/src/capi.rs b/sgx_sync/src/capi.rs index 82b700514..704718ed1 100644 --- a/sgx_sync/src/capi.rs +++ b/sgx_sync/src/capi.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::spin::SpinMutex; use crate::sys::locks::generic::condvar::Condvar; diff --git a/sgx_sync/src/condvar.rs b/sgx_sync/src/condvar.rs index e6a3da3be..6aa34816c 100644 --- a/sgx_sync/src/condvar.rs +++ b/sgx_sync/src/condvar.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::mutex::MovableMutex; use crate::sys::locks::condvar as imp; diff --git a/sgx_sync/src/condvar/check.rs b/sgx_sync/src/condvar/check.rs index 690976020..873cea399 100644 --- a/sgx_sync/src/condvar/check.rs +++ b/sgx_sync/src/condvar/check.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::lazy_box::{LazyBox, LazyInit}; use crate::sys::locks::futex; use crate::sys::locks::generic; diff --git a/sgx_sync/src/futex.rs b/sgx_sync/src/futex.rs index 06434510a..e6eaa2e13 100644 --- a/sgx_sync/src/futex.rs +++ b/sgx_sync/src/futex.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::futex as imp; use crate::Timespec; diff --git a/sgx_sync/src/lazy_lock.rs b/sgx_sync/src/lazy_lock.rs index bbdffe6aa..9a65b6c60 100644 --- a/sgx_sync/src/lazy_lock.rs +++ b/sgx_sync/src/lazy_lock.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::once_lock::OnceLock; use core::cell::Cell; diff --git a/sgx_sync/src/lib.rs b/sgx_sync/src/lib.rs index 40b0c3e52..a1797c65f 100644 --- a/sgx_sync/src/lib.rs +++ b/sgx_sync/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_sync/src/lock_api.rs b/sgx_sync/src/lock_api.rs index f1715f914..7d4cf959d 100644 --- a/sgx_sync/src/lock_api.rs +++ b/sgx_sync/src/lock_api.rs @@ -13,6 +13,6 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use sgx_trts::sync::{RawMutex, RawRwLock}; diff --git a/sgx_sync/src/mutex.rs b/sgx_sync/src/mutex.rs index ea8fee1d7..d3643d74a 100644 --- a/sgx_sync/src/mutex.rs +++ b/sgx_sync/src/mutex.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::lock_api::RawMutex; use crate::sys::locks::mutex as imp; diff --git a/sgx_sync/src/once.rs b/sgx_sync/src/once.rs index 65fd22f2e..5c384ed7d 100644 --- a/sgx_sync/src/once.rs +++ b/sgx_sync/src/once.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::cell::Cell; use core::fmt; diff --git a/sgx_sync/src/once_lock.rs b/sgx_sync/src/once_lock.rs index 5cb6f4430..f01c848ac 100644 --- a/sgx_sync/src/once_lock.rs +++ b/sgx_sync/src/once_lock.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::once::Once; use core::cell::UnsafeCell; diff --git a/sgx_sync/src/remutex/generic.rs b/sgx_sync/src/remutex/generic.rs index e6d337864..82dea5814 100644 --- a/sgx_sync/src/remutex/generic.rs +++ b/sgx_sync/src/remutex/generic.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::mutex as sys; use core::cell::UnsafeCell; diff --git a/sgx_sync/src/remutex/legacy.rs b/sgx_sync/src/remutex/legacy.rs index 275a9a8bc..5a8350546 100644 --- a/sgx_sync/src/remutex/legacy.rs +++ b/sgx_sync/src/remutex/legacy.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::locks::generic::mutex as sys; use core::fmt; diff --git a/sgx_sync/src/remutex/mod.rs b/sgx_sync/src/remutex/mod.rs index babdd013e..df1c29fb6 100644 --- a/sgx_sync/src/remutex/mod.rs +++ b/sgx_sync/src/remutex/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod generic; pub use generic::{ReentrantMutex, ReentrantMutexGuard}; diff --git a/sgx_sync/src/rwlock.rs b/sgx_sync/src/rwlock.rs index 7782585ac..de026d3b9 100644 --- a/sgx_sync/src/rwlock.rs +++ b/sgx_sync/src/rwlock.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::lock_api::RawRwLock; use crate::sys::locks::rwlock as imp; diff --git a/sgx_sync/src/spin.rs b/sgx_sync/src/spin.rs index 3400062b5..2b61b42b7 100644 --- a/sgx_sync/src/spin.rs +++ b/sgx_sync/src/spin.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use sgx_trts::sync::{ SpinMutex, SpinMutexGuard, SpinRwLock, SpinRwLockReadGuard, SpinRwLockWriteGuard, diff --git a/sgx_sync/src/sys/futex.rs b/sgx_sync/src/sys/futex.rs index 119d4ec66..b06fbb335 100644 --- a/sgx_sync/src/sys/futex.rs +++ b/sgx_sync/src/sys/futex.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(deprecated)] diff --git a/sgx_sync/src/sys/lazy_box.rs b/sgx_sync/src/sys/lazy_box.rs index c26e21f7a..45682c9a5 100644 --- a/sgx_sync/src/sys/lazy_box.rs +++ b/sgx_sync/src/sys/lazy_box.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(dead_code)] // Only used on some platforms. diff --git a/sgx_sync/src/sys/locks/futex/condvar.rs b/sgx_sync/src/sys/locks/futex/condvar.rs index 5858bd88e..77ac76db7 100644 --- a/sgx_sync/src/sys/locks/futex/condvar.rs +++ b/sgx_sync/src/sys/locks/futex/condvar.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::mutex::Mutex; use super::wait::{futex_wait, futex_wake, futex_wake_all}; diff --git a/sgx_sync/src/sys/locks/futex/mod.rs b/sgx_sync/src/sys/locks/futex/mod.rs index 60c09347f..1d66ac2ed 100644 --- a/sgx_sync/src/sys/locks/futex/mod.rs +++ b/sgx_sync/src/sys/locks/futex/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod wait; diff --git a/sgx_sync/src/sys/locks/futex/mutex.rs b/sgx_sync/src/sys/locks/futex/mutex.rs index 7caa5b6be..dbd6e0c59 100644 --- a/sgx_sync/src/sys/locks/futex/mutex.rs +++ b/sgx_sync/src/sys/locks/futex/mutex.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::wait::{futex_wait, futex_wake}; use core::sync::atomic::{ diff --git a/sgx_sync/src/sys/locks/futex/rwlock.rs b/sgx_sync/src/sys/locks/futex/rwlock.rs index 654d3744d..14eac0a11 100644 --- a/sgx_sync/src/sys/locks/futex/rwlock.rs +++ b/sgx_sync/src/sys/locks/futex/rwlock.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::wait::{futex_wait, futex_wake, futex_wake_all}; use core::sync::atomic::{ diff --git a/sgx_sync/src/sys/locks/futex/wait.rs b/sgx_sync/src/sys/locks/futex/wait.rs index 5255e35d5..65fa82fab 100644 --- a/sgx_sync/src/sys/locks/futex/wait.rs +++ b/sgx_sync/src/sys/locks/futex/wait.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::futex::Futex; use core::sync::atomic::AtomicU32; diff --git a/sgx_sync/src/sys/locks/generic/condvar.rs b/sgx_sync/src/sys/locks/generic/condvar.rs index c60c94d5c..73edf51f7 100644 --- a/sgx_sync/src/sys/locks/generic/condvar.rs +++ b/sgx_sync/src/sys/locks/generic/condvar.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::mutex::Mutex; use crate::sys::lazy_box::{LazyBox, LazyInit}; diff --git a/sgx_sync/src/sys/locks/generic/mod.rs b/sgx_sync/src/sys/locks/generic/mod.rs index bf1bab895..aa46bf609 100644 --- a/sgx_sync/src/sys/locks/generic/mod.rs +++ b/sgx_sync/src/sys/locks/generic/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub mod condvar; pub mod mutex; diff --git a/sgx_sync/src/sys/locks/generic/mutex.rs b/sgx_sync/src/sys/locks/generic/mutex.rs index 4aed9dc4e..658fe6223 100644 --- a/sgx_sync/src/sys/locks/generic/mutex.rs +++ b/sgx_sync/src/sys/locks/generic/mutex.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::lazy_box::{LazyBox, LazyInit}; use crate::sys::ocall; diff --git a/sgx_sync/src/sys/locks/generic/rwlock.rs b/sgx_sync/src/sys/locks/generic/rwlock.rs index d97c50668..40d09a5f5 100644 --- a/sgx_sync/src/sys/locks/generic/rwlock.rs +++ b/sgx_sync/src/sys/locks/generic/rwlock.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::lazy_box::{LazyBox, LazyInit}; use crate::sys::ocall; diff --git a/sgx_sync/src/sys/locks/mod.rs b/sgx_sync/src/sys/locks/mod.rs index 2b0be11d6..05716f974 100644 --- a/sgx_sync/src/sys/locks/mod.rs +++ b/sgx_sync/src/sys/locks/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub mod futex; pub mod generic; diff --git a/sgx_sync/src/sys/mod.rs b/sgx_sync/src/sys/mod.rs index ee5e8e1ea..d152eb2a1 100644 --- a/sgx_sync/src/sys/mod.rs +++ b/sgx_sync/src/sys/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub mod futex; pub mod lazy_box; diff --git a/sgx_sync/src/sys/ocall/mod.rs b/sgx_sync/src/sys/ocall/mod.rs index 09a5f0016..c027b422f 100644 --- a/sgx_sync/src/sys/ocall/mod.rs +++ b/sgx_sync/src/sys/ocall/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::cmp::{self, Ordering}; use core::convert::{From, TryFrom}; diff --git a/sgx_tdh/src/capi.rs b/sgx_tdh/src/capi.rs index db7c1a6b9..78d28b12d 100644 --- a/sgx_tdh/src/capi.rs +++ b/sgx_tdh/src/capi.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::message::{DhMsg1, DhMsg2, DhMsg3}; use crate::session::{DhResult, Initiator, Responder}; diff --git a/sgx_tdh/src/lib.rs b/sgx_tdh/src/lib.rs index e19ee7610..786a85358 100644 --- a/sgx_tdh/src/lib.rs +++ b/sgx_tdh/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_tdh/src/message.rs b/sgx_tdh/src/message.rs index 068c3c313..ceb55d5a8 100644 --- a/sgx_tdh/src/message.rs +++ b/sgx_tdh/src/message.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use alloc::boxed::Box; use alloc::vec::Vec; diff --git a/sgx_tdh/src/session/initiator.rs b/sgx_tdh/src/session/initiator.rs index 6bb02eabb..13c103044 100644 --- a/sgx_tdh/src/session/initiator.rs +++ b/sgx_tdh/src/session/initiator.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::DhResult; use crate::message::{DhMsg1, DhMsg2, DhMsg3}; diff --git a/sgx_tdh/src/session/mod.rs b/sgx_tdh/src/session/mod.rs index 831680d67..fe4cf7fee 100644 --- a/sgx_tdh/src/session/mod.rs +++ b/sgx_tdh/src/session/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use sgx_types::types::{EnclaveIdentity, Key128bit}; diff --git a/sgx_tdh/src/session/responder.rs b/sgx_tdh/src/session/responder.rs index b6948cdfb..b797a50d5 100644 --- a/sgx_tdh/src/session/responder.rs +++ b/sgx_tdh/src/session/responder.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::DhResult; use crate::message::{DhMsg1, DhMsg2, DhMsg3}; diff --git a/sgx_tests/cov/src/lib.rs b/sgx_tests/cov/src/lib.rs index 1f8fd66b2..3c010bb86 100644 --- a/sgx_tests/cov/src/lib.rs +++ b/sgx_tests/cov/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![cfg_attr(not(target_vendor = "teaclave"), no_std)] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_tests/unit/src/lib.rs b/sgx_tests/unit/src/lib.rs index ffb479a18..b6432cf7a 100644 --- a/sgx_tests/unit/src/lib.rs +++ b/sgx_tests/unit/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! sgx_unit_test is for performing unit tests in enclaves. //! diff --git a/sgx_tests/utils/src/bench.rs b/sgx_tests/utils/src/bench.rs index e16ba5496..857d11c64 100644 --- a/sgx_tests/utils/src/bench.rs +++ b/sgx_tests/utils/src/bench.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::stats; use crate::time::Instant; diff --git a/sgx_tests/utils/src/lib.rs b/sgx_tests/utils/src/lib.rs index 8cd222a5a..43c309e6b 100644 --- a/sgx_tests/utils/src/lib.rs +++ b/sgx_tests/utils/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_tests/utils/src/stats.rs b/sgx_tests/utils/src/stats.rs index 4fb17b8a7..b6cdf9871 100644 --- a/sgx_tests/utils/src/stats.rs +++ b/sgx_tests/utils/src/stats.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use alloc::vec::Vec; use core::{intrinsics, mem}; diff --git a/sgx_tests/utils/src/time.rs b/sgx_tests/utils/src/time.rs index e863f10d0..93949aaaa 100644 --- a/sgx_tests/utils/src/time.rs +++ b/sgx_tests/utils/src/time.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::arch::x86_64::{__rdtscp, _mm_lfence, _rdtsc}; use core::time::Duration; diff --git a/sgx_trts/build.rs b/sgx_trts/build.rs index f3ba7b057..61a74f9fc 100644 --- a/sgx_trts/build.rs +++ b/sgx_trts/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/sgx_trts/src/arch.rs b/sgx_trts/src/arch.rs index 090d22926..d57aa1d06 100644 --- a/sgx_trts/src/arch.rs +++ b/sgx_trts/src/arch.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::enum_variant_names)] diff --git a/sgx_trts/src/asm/cet.S b/sgx_trts/src/asm/cet.S index f00103c88..1a9f683dc 100644 --- a/sgx_trts/src/asm/cet.S +++ b/sgx_trts/src/asm/cet.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "cet.S" diff --git a/sgx_trts/src/asm/macro.S b/sgx_trts/src/asm/macro.S index 4de0804b3..678deb3a8 100644 --- a/sgx_trts/src/asm/macro.S +++ b/sgx_trts/src/asm/macro.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "macro.S" diff --git a/sgx_trts/src/asm/metadata.S b/sgx_trts/src/asm/metadata.S index c530d9057..1bcb1bce7 100644 --- a/sgx_trts/src/asm/metadata.S +++ b/sgx_trts/src/asm/metadata.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "metadata.S" diff --git a/sgx_trts/src/asm/mod.rs b/sgx_trts/src/asm/mod.rs index 61acd766d..accde68ed 100644 --- a/sgx_trts/src/asm/mod.rs +++ b/sgx_trts/src/asm/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::Align64; use core::arch::global_asm; diff --git a/sgx_trts/src/asm/pic.S b/sgx_trts/src/asm/pic.S index 47cea6cda..5d393d3df 100644 --- a/sgx_trts/src/asm/pic.S +++ b/sgx_trts/src/asm/pic.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "pic.S" .section absolute diff --git a/sgx_trts/src/asm/thunk.S b/sgx_trts/src/asm/thunk.S index ab8a3c658..e7c121f2d 100644 --- a/sgx_trts/src/asm/thunk.S +++ b/sgx_trts/src/asm/thunk.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "thunk.S" diff --git a/sgx_trts/src/asm/xsave.S b/sgx_trts/src/asm/xsave.S index 08eaac551..32bb98451 100644 --- a/sgx_trts/src/asm/xsave.S +++ b/sgx_trts/src/asm/xsave.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "xsave.S" .section .nipd,"aw" diff --git a/sgx_trts/src/call/ecall.rs b/sgx_trts/src/call/ecall.rs index c9c2f5025..f3c5e83dc 100644 --- a/sgx_trts/src/call/ecall.rs +++ b/sgx_trts/src/call/ecall.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::{OCallContext, Tcs, TcsPolicy}; use crate::call::ocall; diff --git a/sgx_trts/src/call/mod.rs b/sgx_trts/src/call/mod.rs index 533bcd25f..4093fd850 100644 --- a/sgx_trts/src/call/mod.rs +++ b/sgx_trts/src/call/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod ecall; #[cfg(feature = "hyper")] diff --git a/sgx_trts/src/call/msbuf.rs b/sgx_trts/src/call/msbuf.rs index 22a4f543b..1e6af975f 100644 --- a/sgx_trts/src/call/msbuf.rs +++ b/sgx_trts/src/call/msbuf.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::SE_PAGE_SIZE; use crate::enclave::{is_within_enclave, is_within_host, EnclaveRange}; diff --git a/sgx_trts/src/call/ocall.rs b/sgx_trts/src/call/ocall.rs index 03efb8af6..21d970e65 100644 --- a/sgx_trts/src/call/ocall.rs +++ b/sgx_trts/src/call/ocall.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::ecall::EntryTable; use crate::arch::OCallContext; diff --git a/sgx_trts/src/call/ocalloc.rs b/sgx_trts/src/call/ocalloc.rs index a0858f15f..903d77d58 100644 --- a/sgx_trts/src/call/ocalloc.rs +++ b/sgx_trts/src/call/ocalloc.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::alloc::{Allocator, Layout}; use core::mem::ManuallyDrop; diff --git a/sgx_trts/src/capi.rs b/sgx_trts/src/capi.rs index 9cf01743f..fcfa52ada 100644 --- a/sgx_trts/src/capi.rs +++ b/sgx_trts/src/capi.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::call::{ocall, OCallIndex, OcBuffer}; use crate::edmm::mem::{apply_epc_pages, trim_epc_pages}; diff --git a/sgx_trts/src/edmm/epc.rs b/sgx_trts/src/edmm/epc.rs index 05c966ad1..44b056428 100644 --- a/sgx_trts/src/edmm/epc.rs +++ b/sgx_trts/src/edmm/epc.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::{SecInfo, SE_PAGE_SHIFT, SE_PAGE_SIZE}; use crate::enclave::is_within_enclave; diff --git a/sgx_trts/src/edmm/layout.rs b/sgx_trts/src/edmm/layout.rs index a3e0e309c..8e5335ac7 100644 --- a/sgx_trts/src/edmm/layout.rs +++ b/sgx_trts/src/edmm/layout.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::{self, Layout}; use crate::enclave::MmLayout; diff --git a/sgx_trts/src/edmm/mem.rs b/sgx_trts/src/edmm/mem.rs index 2f5e1e570..02fb979ff 100644 --- a/sgx_trts/src/edmm/mem.rs +++ b/sgx_trts/src/edmm/mem.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. cfg_if! { if #[cfg(not(any(feature = "sim", feature = "hyper")))] { diff --git a/sgx_trts/src/edmm/mod.rs b/sgx_trts/src/edmm/mod.rs index 420dbccb4..4d06bcc67 100644 --- a/sgx_trts/src/edmm/mod.rs +++ b/sgx_trts/src/edmm/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub(crate) mod epc; #[cfg(not(any(feature = "sim", feature = "hyper")))] diff --git a/sgx_trts/src/edmm/perm.rs b/sgx_trts/src/edmm/perm.rs index 4e17e67e5..0517243ae 100644 --- a/sgx_trts/src/edmm/perm.rs +++ b/sgx_trts/src/edmm/perm.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. cfg_if! { if #[cfg(not(any(feature = "sim", feature = "hyper")))] { diff --git a/sgx_trts/src/edmm/tcs.rs b/sgx_trts/src/edmm/tcs.rs index 271b94e24..a59d13038 100644 --- a/sgx_trts/src/edmm/tcs.rs +++ b/sgx_trts/src/edmm/tcs.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::Tcs; use crate::enclave::is_within_host; diff --git a/sgx_trts/src/edmm/trim.rs b/sgx_trts/src/edmm/trim.rs index 6e51bd801..85ce72973 100644 --- a/sgx_trts/src/edmm/trim.rs +++ b/sgx_trts/src/edmm/trim.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::SE_PAGE_SHIFT; use crate::call::{ocall, OCallIndex, OcAlloc}; diff --git a/sgx_trts/src/elf/control_flow.rs b/sgx_trts/src/elf/control_flow.rs index 887ff67dc..30b3b1406 100644 --- a/sgx_trts/src/elf/control_flow.rs +++ b/sgx_trts/src/elf/control_flow.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum ControlFlow { diff --git a/sgx_trts/src/elf/dynamic.rs b/sgx_trts/src/elf/dynamic.rs index 74b5002d3..c6aa20f79 100644 --- a/sgx_trts/src/elf/dynamic.rs +++ b/sgx_trts/src/elf/dynamic.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::fmt; use sgx_types::marker::ContiguousMemory; diff --git a/sgx_trts/src/elf/header.rs b/sgx_trts/src/elf/header.rs index 91011fa22..28c7e7bbd 100644 --- a/sgx_trts/src/elf/header.rs +++ b/sgx_trts/src/elf/header.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::elf::slice::{self, AsSlice}; use crate::elf::zero::read; diff --git a/sgx_trts/src/elf/mod.rs b/sgx_trts/src/elf/mod.rs index 06a4cca4a..d7f59e17c 100644 --- a/sgx_trts/src/elf/mod.rs +++ b/sgx_trts/src/elf/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::elf::header::{Header, Header64Pt2, HeaderPt1, HeaderPt2}; use crate::elf::program::{ProgramHeader, ProgramIter}; diff --git a/sgx_trts/src/elf/program.rs b/sgx_trts/src/elf/program.rs index 8907c9f53..c8a2e05fd 100644 --- a/sgx_trts/src/elf/program.rs +++ b/sgx_trts/src/elf/program.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::elf::control_flow::ControlFlow; use crate::elf::dynamic::Dynamic; diff --git a/sgx_trts/src/elf/sections.rs b/sgx_trts/src/elf/sections.rs index 1f022b90e..6dd3e52ed 100644 --- a/sgx_trts/src/elf/sections.rs +++ b/sgx_trts/src/elf/sections.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::elf::dynamic::Dynamic; use crate::elf::symtabl; diff --git a/sgx_trts/src/elf/slice.rs b/sgx_trts/src/elf/slice.rs index 59defb9df..576acde0f 100644 --- a/sgx_trts/src/elf/slice.rs +++ b/sgx_trts/src/elf/slice.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::intrinsics::assume; use core::marker::PhantomData; diff --git a/sgx_trts/src/elf/symtabl.rs b/sgx_trts/src/elf/symtabl.rs index 1aa8097d8..52144614c 100644 --- a/sgx_trts/src/elf/symtabl.rs +++ b/sgx_trts/src/elf/symtabl.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::fmt; use core::mem; diff --git a/sgx_trts/src/elf/zero.rs b/sgx_trts/src/elf/zero.rs index 02c4fdebd..29a488df1 100644 --- a/sgx_trts/src/elf/zero.rs +++ b/sgx_trts/src/elf/zero.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::elf::slice::{self, AsSlice}; use crate::error; diff --git a/sgx_trts/src/enclave/atexit.rs b/sgx_trts/src/enclave/atexit.rs index 418e158f3..f73751dd3 100644 --- a/sgx_trts/src/enclave/atexit.rs +++ b/sgx_trts/src/enclave/atexit.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::rand::Rng; use crate::sync::SpinMutex; diff --git a/sgx_trts/src/enclave/entry.rs b/sgx_trts/src/enclave/entry.rs index 3bf7cac59..ae758ca56 100644 --- a/sgx_trts/src/enclave/entry.rs +++ b/sgx_trts/src/enclave/entry.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::Tcs; use crate::call; diff --git a/sgx_trts/src/enclave/init.rs b/sgx_trts/src/enclave/init.rs index 559f34896..f7203da26 100644 --- a/sgx_trts/src/enclave/init.rs +++ b/sgx_trts/src/enclave/init.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::Tcs; use crate::enclave::state::State; diff --git a/sgx_trts/src/enclave/mem.rs b/sgx_trts/src/enclave/mem.rs index 2ea9a70ca..a820acc87 100644 --- a/sgx_trts/src/enclave/mem.rs +++ b/sgx_trts/src/enclave/mem.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch; use crate::enclave::parse; diff --git a/sgx_trts/src/enclave/mod.rs b/sgx_trts/src/enclave/mod.rs index adb77fca8..5f91eb307 100644 --- a/sgx_trts/src/enclave/mod.rs +++ b/sgx_trts/src/enclave/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(unused_imports)] diff --git a/sgx_trts/src/enclave/parse.rs b/sgx_trts/src/enclave/parse.rs index f1fe61754..470c6b133 100644 --- a/sgx_trts/src/enclave/parse.rs +++ b/sgx_trts/src/enclave/parse.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::elf::dynamic::Tag as DynTag; use crate::elf::header::Type as HeaderType; diff --git a/sgx_trts/src/enclave/state.rs b/sgx_trts/src/enclave/state.rs index 7bfcdf4c1..4c6fed3d0 100644 --- a/sgx_trts/src/enclave/state.rs +++ b/sgx_trts/src/enclave/state.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[link_section = ".nipd"] #[no_mangle] diff --git a/sgx_trts/src/enclave/uninit.rs b/sgx_trts/src/enclave/uninit.rs index 78a79dcb8..e9f8259cf 100644 --- a/sgx_trts/src/enclave/uninit.rs +++ b/sgx_trts/src/enclave/uninit.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::enclave::state::{self, State}; use crate::enclave::{atexit, parse}; diff --git a/sgx_trts/src/error.rs b/sgx_trts/src/error.rs index 8dae0cb8f..06fb1905e 100644 --- a/sgx_trts/src/error.rs +++ b/sgx_trts/src/error.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(not(feature = "use_sgx_sdk"))] use crate::arch::Tds; diff --git a/sgx_trts/src/feature/mod.rs b/sgx_trts/src/feature/mod.rs index ddedba0ad..31649d7a0 100644 --- a/sgx_trts/src/feature/mod.rs +++ b/sgx_trts/src/feature/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod sys; diff --git a/sgx_trts/src/feature/sys.rs b/sgx_trts/src/feature/sys.rs index 3a37054f7..71429a7d5 100644 --- a/sgx_trts/src/feature/sys.rs +++ b/sgx_trts/src/feature/sys.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "hyper")] use crate::call::MsbufInfo; diff --git a/sgx_trts/src/fence.rs b/sgx_trts/src/fence.rs index 2f0422c97..bcba612f9 100644 --- a/sgx_trts/src/fence.rs +++ b/sgx_trts/src/fence.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(target_arch = "x86")] use core::arch::x86::{_mm_lfence, _mm_mfence}; diff --git a/sgx_trts/src/inst/hw/enclu.S b/sgx_trts/src/inst/hw/enclu.S index a49727fa5..2c6622b52 100644 --- a/sgx_trts/src/inst/hw/enclu.S +++ b/sgx_trts/src/inst/hw/enclu.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "enclu.S" diff --git a/sgx_trts/src/inst/hw/everifyreport.S b/sgx_trts/src/inst/hw/everifyreport.S index 0b7ca25dc..97058b3e4 100644 --- a/sgx_trts/src/inst/hw/everifyreport.S +++ b/sgx_trts/src/inst/hw/everifyreport.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "everifyreport.S" diff --git a/sgx_trts/src/inst/hw/inst.rs b/sgx_trts/src/inst/hw/inst.rs index fd9c94ee7..dcebdef81 100644 --- a/sgx_trts/src/inst/hw/inst.rs +++ b/sgx_trts/src/inst/hw/inst.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::{Enclu, SecInfo}; use crate::se::{ diff --git a/sgx_trts/src/inst/hw/mod.rs b/sgx_trts/src/inst/hw/mod.rs index fd01ada37..0a3b77c0b 100644 --- a/sgx_trts/src/inst/hw/mod.rs +++ b/sgx_trts/src/inst/hw/mod.rs @@ -13,6 +13,6 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub mod inst; diff --git a/sgx_trts/src/inst/hw/td.S b/sgx_trts/src/inst/hw/td.S index 42c750155..573d7cd0c 100644 --- a/sgx_trts/src/inst/hw/td.S +++ b/sgx_trts/src/inst/hw/td.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "td.S" diff --git a/sgx_trts/src/inst/hw/xsave_mask.S b/sgx_trts/src/inst/hw/xsave_mask.S index 870821779..6b97ab400 100644 --- a/sgx_trts/src/inst/hw/xsave_mask.S +++ b/sgx_trts/src/inst/hw/xsave_mask.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "xsave_mask.S" diff --git a/sgx_trts/src/inst/hyper/enclu.S b/sgx_trts/src/inst/hyper/enclu.S index fcbe76549..34f566991 100644 --- a/sgx_trts/src/inst/hyper/enclu.S +++ b/sgx_trts/src/inst/hyper/enclu.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "enclu.S" diff --git a/sgx_trts/src/inst/hyper/inst.rs b/sgx_trts/src/inst/hyper/inst.rs index b7b97f21b..b1c1a86ab 100644 --- a/sgx_trts/src/inst/hyper/inst.rs +++ b/sgx_trts/src/inst/hyper/inst.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::enum_variant_names)] diff --git a/sgx_trts/src/inst/hyper/mod.rs b/sgx_trts/src/inst/hyper/mod.rs index 9d638b5f9..7c4ccc0e7 100644 --- a/sgx_trts/src/inst/hyper/mod.rs +++ b/sgx_trts/src/inst/hyper/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::{Enclu, SecInfo}; use crate::call::MsbufInfo; diff --git a/sgx_trts/src/inst/hyper/td.S b/sgx_trts/src/inst/hyper/td.S index 42c750155..573d7cd0c 100644 --- a/sgx_trts/src/inst/hyper/td.S +++ b/sgx_trts/src/inst/hyper/td.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "td.S" diff --git a/sgx_trts/src/inst/hyper/xsave_mask.S b/sgx_trts/src/inst/hyper/xsave_mask.S index 870821779..6b97ab400 100644 --- a/sgx_trts/src/inst/hyper/xsave_mask.S +++ b/sgx_trts/src/inst/hyper/xsave_mask.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "xsave_mask.S" diff --git a/sgx_trts/src/inst/mod.rs b/sgx_trts/src/inst/mod.rs index a08088823..1f6d36fed 100644 --- a/sgx_trts/src/inst/mod.rs +++ b/sgx_trts/src/inst/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub const INVALID_LEAF: u32 = 1 << 1; pub const INVALID_ATTRIBUTE: u32 = 1 << 1; diff --git a/sgx_trts/src/inst/sim/derive.rs b/sgx_trts/src/inst/sim/derive.rs index eddb5ac5e..a87e268a1 100644 --- a/sgx_trts/src/inst/sim/derive.rs +++ b/sgx_trts/src/inst/sim/derive.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::Align16; use crate::error::abort; diff --git a/sgx_trts/src/inst/sim/enclu.S b/sgx_trts/src/inst/sim/enclu.S index a21b6c1b3..1a8f07b78 100644 --- a/sgx_trts/src/inst/sim/enclu.S +++ b/sgx_trts/src/inst/sim/enclu.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "enclu.S" diff --git a/sgx_trts/src/inst/sim/inst.rs b/sgx_trts/src/inst/sim/inst.rs index 93287cd8f..67dd2a785 100644 --- a/sgx_trts/src/inst/sim/inst.rs +++ b/sgx_trts/src/inst/sim/inst.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::{SecInfo, Tcs}; use crate::enclave::EnclaveRange; diff --git a/sgx_trts/src/inst/sim/lowlib.S b/sgx_trts/src/inst/sim/lowlib.S index aa61988e6..080a1b470 100644 --- a/sgx_trts/src/inst/sim/lowlib.S +++ b/sgx_trts/src/inst/sim/lowlib.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "lowlib.S" .section .nipx,"ax",@progbits diff --git a/sgx_trts/src/inst/sim/mod.rs b/sgx_trts/src/inst/sim/mod.rs index 43c6c853c..4d638c57c 100644 --- a/sgx_trts/src/inst/sim/mod.rs +++ b/sgx_trts/src/inst/sim/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::{Enclu, SecInfo, Secs, Tcs}; use crate::error::abort; diff --git a/sgx_trts/src/inst/sim/td.S b/sgx_trts/src/inst/sim/td.S index 9add382c1..de3fd3b9d 100644 --- a/sgx_trts/src/inst/sim/td.S +++ b/sgx_trts/src/inst/sim/td.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "td.S" diff --git a/sgx_trts/src/inst/sim/tls/gnu.rs b/sgx_trts/src/inst/sim/tls/gnu.rs index 357381a05..639cb956f 100644 --- a/sgx_trts/src/inst/sim/tls/gnu.rs +++ b/sgx_trts/src/inst/sim/tls/gnu.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::arch::asm; use core::ffi::c_void; diff --git a/sgx_trts/src/inst/sim/tls/mod.rs b/sgx_trts/src/inst/sim/tls/mod.rs index 3b79b0d59..7deebc79f 100644 --- a/sgx_trts/src/inst/sim/tls/mod.rs +++ b/sgx_trts/src/inst/sim/tls/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::Tcs; use crate::inst::sim::TcsSim; diff --git a/sgx_trts/src/inst/sim/xsave_mask.S b/sgx_trts/src/inst/sim/xsave_mask.S index 23f9f3645..f7a67822e 100644 --- a/sgx_trts/src/inst/sim/xsave_mask.S +++ b/sgx_trts/src/inst/sim/xsave_mask.S @@ -13,7 +13,7 @@ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations - under the License.. */ + under the License. */ .file "xsave_mask.S" .section .nipd,"aw" diff --git a/sgx_trts/src/lib.rs b/sgx_trts/src/lib.rs index 32823cae1..a048d759d 100644 --- a/sgx_trts/src/lib.rs +++ b/sgx_trts/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! # Trusted Runtime System diff --git a/sgx_trts/src/macros.rs b/sgx_trts/src/macros.rs index 05b103d06..300fdcb09 100644 --- a/sgx_trts/src/macros.rs +++ b/sgx_trts/src/macros.rs @@ -13,6 +13,6 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use crate::is_x86_feature_detected; diff --git a/sgx_trts/src/pkru.rs b/sgx_trts/src/pkru.rs index 8a0eea277..e928aeadb 100644 --- a/sgx_trts/src/pkru.rs +++ b/sgx_trts/src/pkru.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::feature::SysFeatures; use core::arch::asm; diff --git a/sgx_trts/src/rand.rs b/sgx_trts/src/rand.rs index 83c455fae..fe0aeaaa6 100644 --- a/sgx_trts/src/rand.rs +++ b/sgx_trts/src/rand.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::enclave::EnclaveRange; use crate::error; diff --git a/sgx_trts/src/se/key.rs b/sgx_trts/src/se/key.rs index 3d56b8c84..ed52199aa 100644 --- a/sgx_trts/src/se/key.rs +++ b/sgx_trts/src/se/key.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::{Align16, Align512}; use crate::enclave::EnclaveRange; diff --git a/sgx_trts/src/se/mod.rs b/sgx_trts/src/se/mod.rs index 7da91d933..10073005e 100644 --- a/sgx_trts/src/se/mod.rs +++ b/sgx_trts/src/se/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod key; mod report; diff --git a/sgx_trts/src/se/report.rs b/sgx_trts/src/se/report.rs index 2f8079496..4f3a04acc 100644 --- a/sgx_trts/src/se/report.rs +++ b/sgx_trts/src/se/report.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::{Align128, Align256, Align512}; use crate::enclave::EnclaveRange; diff --git a/sgx_trts/src/stackchk.rs b/sgx_trts/src/stackchk.rs index 382a5ebdf..b4ccd9c33 100644 --- a/sgx_trts/src/stackchk.rs +++ b/sgx_trts/src/stackchk.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::error::abort; diff --git a/sgx_trts/src/sync/lazy.rs b/sgx_trts/src/sync/lazy.rs index 390a41dc3..a596771f1 100644 --- a/sgx_trts/src/sync/lazy.rs +++ b/sgx_trts/src/sync/lazy.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::cell::{Cell, UnsafeCell}; use core::fmt; diff --git a/sgx_trts/src/sync/lock_api.rs b/sgx_trts/src/sync/lock_api.rs index 6b9eaf1a0..d3f7bc771 100644 --- a/sgx_trts/src/sync/lock_api.rs +++ b/sgx_trts/src/sync/lock_api.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub trait RawMutex { fn lock(&self); diff --git a/sgx_trts/src/sync/mod.rs b/sgx_trts/src/sync/mod.rs index 5cf0fbdfd..792fba992 100644 --- a/sgx_trts/src/sync/mod.rs +++ b/sgx_trts/src/sync/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod lazy; mod lock_api; diff --git a/sgx_trts/src/sync/mutex.rs b/sgx_trts/src/sync/mutex.rs index 0b909ac86..865a320c8 100644 --- a/sgx_trts/src/sync/mutex.rs +++ b/sgx_trts/src/sync/mutex.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sync::lock_api::RawMutex; use core::cell::UnsafeCell; diff --git a/sgx_trts/src/sync/once.rs b/sgx_trts/src/sync/once.rs index 3261f0113..90f355386 100644 --- a/sgx_trts/src/sync/once.rs +++ b/sgx_trts/src/sync/once.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sync::{SpinMutex, SpinMutexGuard}; use core::sync::atomic::{AtomicUsize, Ordering}; diff --git a/sgx_trts/src/sync/remutex.rs b/sgx_trts/src/sync/remutex.rs index 3dbbc274c..ac7e2a0fe 100644 --- a/sgx_trts/src/sync/remutex.rs +++ b/sgx_trts/src/sync/remutex.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sync::lock_api::RawMutex; use crate::tcs; diff --git a/sgx_trts/src/sync/rwlock.rs b/sgx_trts/src/sync/rwlock.rs index 5f4d9ccc9..1c629c44c 100644 --- a/sgx_trts/src/sync/rwlock.rs +++ b/sgx_trts/src/sync/rwlock.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sync::lock_api::RawRwLock; use core::cell::UnsafeCell; diff --git a/sgx_trts/src/tcs/list.rs b/sgx_trts/src/tcs/list.rs index 1358983a6..2bbeb07ba 100644 --- a/sgx_trts/src/tcs/list.rs +++ b/sgx_trts/src/tcs/list.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::Tcs; use crate::rand::Rng; diff --git a/sgx_trts/src/tcs/mod.rs b/sgx_trts/src/tcs/mod.rs index 7860d818f..f4cb83729 100644 --- a/sgx_trts/src/tcs/mod.rs +++ b/sgx_trts/src/tcs/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub(crate) mod list; pub(crate) mod tc; diff --git a/sgx_trts/src/tcs/tc.rs b/sgx_trts/src/tcs/tc.rs index 629426e7a..6ab943f49 100644 --- a/sgx_trts/src/tcs/tc.rs +++ b/sgx_trts/src/tcs/tc.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::{self, Global, Tcs, TcsPolicy, Tds}; use crate::enclave::parse; diff --git a/sgx_trts/src/tcs/tls.rs b/sgx_trts/src/tcs/tls.rs index 7c86efd01..e6dffed0f 100644 --- a/sgx_trts/src/tcs/tls.rs +++ b/sgx_trts/src/tcs/tls.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(not(feature = "use_sgx_sdk"))] use crate::arch::Tds; diff --git a/sgx_trts/src/thread/info.rs b/sgx_trts/src/thread/info.rs index c1d609d95..6097392a2 100644 --- a/sgx_trts/src/thread/info.rs +++ b/sgx_trts/src/thread/info.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::thread::Thread; use core::cell::RefCell; diff --git a/sgx_trts/src/thread/mod.rs b/sgx_trts/src/thread/mod.rs index 388da0d8f..34cc49fbd 100644 --- a/sgx_trts/src/thread/mod.rs +++ b/sgx_trts/src/thread/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod info; mod native; diff --git a/sgx_trts/src/thread/native.rs b/sgx_trts/src/thread/native.rs index 83e5c7143..f60e75b98 100644 --- a/sgx_trts/src/thread/native.rs +++ b/sgx_trts/src/thread/native.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::enclave::{is_within_enclave, EnclaveRange, UNINIT_FLAG}; use crate::error; diff --git a/sgx_trts/src/thread/task.rs b/sgx_trts/src/thread/task.rs index 775661b4a..654f20d52 100644 --- a/sgx_trts/src/thread/task.rs +++ b/sgx_trts/src/thread/task.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sync::SpinMutex; use crate::thread::Thread; diff --git a/sgx_trts/src/thread/tls/bitset.rs b/sgx_trts/src/thread/tls/bitset.rs index 7441dea46..6b96f39d3 100644 --- a/sgx_trts/src/thread/tls/bitset.rs +++ b/sgx_trts/src/thread/tls/bitset.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::thread::tls::{TLS_KEYS_BITSET_SIZE, USIZE_BITS}; use core::iter::{Enumerate, Peekable}; diff --git a/sgx_trts/src/thread/tls/mod.rs b/sgx_trts/src/thread/tls/mod.rs index cb77ef5de..48af05de5 100644 --- a/sgx_trts/src/thread/tls/mod.rs +++ b/sgx_trts/src/thread/tls/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::enclave::is_within_enclave; use crate::thread::tls::bitset::Bitset; diff --git a/sgx_trts/src/trts.rs b/sgx_trts/src/trts.rs index 207b363a9..ca9743d0e 100644 --- a/sgx_trts/src/trts.rs +++ b/sgx_trts/src/trts.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::feature::SysFeatures; use sgx_types::types::EnclaveMode; diff --git a/sgx_trts/src/veh/exception.rs b/sgx_trts/src/veh/exception.rs index d24f11e25..e0789b3f8 100644 --- a/sgx_trts/src/veh/exception.rs +++ b/sgx_trts/src/veh/exception.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::{self, MiscExInfo, SsaGpr, Tcs, Tds}; use crate::edmm; diff --git a/sgx_trts/src/veh/list.rs b/sgx_trts/src/veh/list.rs index 64ad66815..8c6613b92 100644 --- a/sgx_trts/src/veh/list.rs +++ b/sgx_trts/src/veh/list.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. // Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file @@ -30,7 +30,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::rand::Rng; use crate::sync::OnceCell; diff --git a/sgx_trts/src/veh/mod.rs b/sgx_trts/src/veh/mod.rs index 1b16a6f15..5dbb993de 100644 --- a/sgx_trts/src/veh/mod.rs +++ b/sgx_trts/src/veh/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod exception; mod list; diff --git a/sgx_trts/src/veh/register.rs b/sgx_trts/src/veh/register.rs index c72bad563..950740f41 100644 --- a/sgx_trts/src/veh/register.rs +++ b/sgx_trts/src/veh/register.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::enclave::is_within_enclave; use crate::error; diff --git a/sgx_trts/src/version.rs b/sgx_trts/src/version.rs index 15a378441..c9c9d719c 100644 --- a/sgx_trts/src/version.rs +++ b/sgx_trts/src/version.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub const MAJOR_VERSION: usize = 2; pub const MINOR_VERSION: usize = 21; diff --git a/sgx_trts/src/xsave.rs b/sgx_trts/src/xsave.rs index 6eaa432eb..c3080b658 100644 --- a/sgx_trts/src/xsave.rs +++ b/sgx_trts/src/xsave.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::arch::Global; use sgx_types::types; diff --git a/sgx_tse/src/capi.rs b/sgx_tse/src/capi.rs index ea581a0fd..9e7c5f177 100644 --- a/sgx_tse/src/capi.rs +++ b/sgx_tse/src/capi.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::se::{EnclaveKey, EnclaveReport, EnclaveTarget, TeeReport}; use sgx_types::error::SgxStatus; diff --git a/sgx_tse/src/lib.rs b/sgx_tse/src/lib.rs index a22ae713b..da3bea0c7 100644 --- a/sgx_tse/src/lib.rs +++ b/sgx_tse/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! # Trusted SE Library //! diff --git a/sgx_tse/src/se.rs b/sgx_tse/src/se.rs index af55bb109..27a34e894 100644 --- a/sgx_tse/src/se.rs +++ b/sgx_tse/src/se.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::mem; use core::ptr; diff --git a/sgx_tseal/src/aad.rs b/sgx_tseal/src/aad.rs index 2b8e1fb37..c6a6dd01e 100644 --- a/sgx_tseal/src/aad.rs +++ b/sgx_tseal/src/aad.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::internal::InnerSealedData; use alloc::boxed::Box; diff --git a/sgx_tseal/src/capi.rs b/sgx_tseal/src/capi.rs index 0107c33eb..ede6c0606 100644 --- a/sgx_tseal/src/capi.rs +++ b/sgx_tseal/src/capi.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::aad::MacAad; use crate::internal::InnerSealedData; diff --git a/sgx_tseal/src/internal.rs b/sgx_tseal/src/internal.rs index 82975fe29..24a1132a0 100644 --- a/sgx_tseal/src/internal.rs +++ b/sgx_tseal/src/internal.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use alloc::alloc::Global; use alloc::boxed::Box; diff --git a/sgx_tseal/src/lib.rs b/sgx_tseal/src/lib.rs index fbc385bf0..6627042b5 100644 --- a/sgx_tseal/src/lib.rs +++ b/sgx_tseal/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_tseal/src/seal.rs b/sgx_tseal/src/seal.rs index a9ae8a341..072a47d9e 100644 --- a/sgx_tseal/src/seal.rs +++ b/sgx_tseal/src/seal.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::internal::InnerSealedData; use alloc::boxed::Box; diff --git a/sgx_tstd/src/alloc.rs b/sgx_tstd/src/alloc.rs index 508e6bd98..fe4d8da83 100644 --- a/sgx_tstd/src/alloc.rs +++ b/sgx_tstd/src/alloc.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Memory allocation APIs. //! diff --git a/sgx_tstd/src/ascii.rs b/sgx_tstd/src/ascii.rs index 0654099e9..f7b384b24 100644 --- a/sgx_tstd/src/ascii.rs +++ b/sgx_tstd/src/ascii.rs @@ -13,6 +13,6 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use sgx_ffi::ascii::*; diff --git a/sgx_tstd/src/backtrace.rs b/sgx_tstd/src/backtrace.rs index dde5ca010..0d1b144cb 100644 --- a/sgx_tstd/src/backtrace.rs +++ b/sgx_tstd/src/backtrace.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Support for capturing a stack backtrace of an OS thread //! diff --git a/sgx_tstd/src/backtrace/tests.rs b/sgx_tstd/src/backtrace/tests.rs index 3cff61d6d..ff60a18fe 100644 --- a/sgx_tstd/src/backtrace/tests.rs +++ b/sgx_tstd/src/backtrace/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use crate::panic::{RefUnwindSafe, UnwindSafe}; diff --git a/sgx_tstd/src/collections/hash/benches/map.rs b/sgx_tstd/src/collections/hash/benches/map.rs index 932c3686f..2e9d29d35 100644 --- a/sgx_tstd/src/collections/hash/benches/map.rs +++ b/sgx_tstd/src/collections/hash/benches/map.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::collections::HashMap; diff --git a/sgx_tstd/src/collections/hash/benches/mod.rs b/sgx_tstd/src/collections/hash/benches/mod.rs index 90010fe58..21c7d9ac9 100644 --- a/sgx_tstd/src/collections/hash/benches/mod.rs +++ b/sgx_tstd/src/collections/hash/benches/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod map; mod set_ops; diff --git a/sgx_tstd/src/collections/hash/benches/set_ops.rs b/sgx_tstd/src/collections/hash/benches/set_ops.rs index 95191422c..76a7556dd 100644 --- a/sgx_tstd/src/collections/hash/benches/set_ops.rs +++ b/sgx_tstd/src/collections/hash/benches/set_ops.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::collections::HashSet; diff --git a/sgx_tstd/src/collections/hash/map.rs b/sgx_tstd/src/collections/hash/map.rs index 731c24693..42b04898d 100644 --- a/sgx_tstd/src/collections/hash/map.rs +++ b/sgx_tstd/src/collections/hash/map.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/collections/hash/map/tests.rs b/sgx_tstd/src/collections/hash/map/tests.rs index d2673485f..d7d67e7f8 100644 --- a/sgx_tstd/src/collections/hash/map/tests.rs +++ b/sgx_tstd/src/collections/hash/map/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::Entry::{Occupied, Vacant}; use super::HashMap; diff --git a/sgx_tstd/src/collections/hash/mod.rs b/sgx_tstd/src/collections/hash/mod.rs index be4625e52..4b99f4ac3 100644 --- a/sgx_tstd/src/collections/hash/mod.rs +++ b/sgx_tstd/src/collections/hash/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Unordered containers, implemented as hash-tables diff --git a/sgx_tstd/src/collections/hash/set.rs b/sgx_tstd/src/collections/hash/set.rs index 41835d2f0..204514663 100644 --- a/sgx_tstd/src/collections/hash/set.rs +++ b/sgx_tstd/src/collections/hash/set.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/collections/hash/set/tests.rs b/sgx_tstd/src/collections/hash/set/tests.rs index 0c01bd7fe..7b3f77f0b 100644 --- a/sgx_tstd/src/collections/hash/set/tests.rs +++ b/sgx_tstd/src/collections/hash/set/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::HashSet; diff --git a/sgx_tstd/src/collections/mod.rs b/sgx_tstd/src/collections/mod.rs index ed87791cf..33f360f95 100644 --- a/sgx_tstd/src/collections/mod.rs +++ b/sgx_tstd/src/collections/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Collection types. //! diff --git a/sgx_tstd/src/enclave.rs b/sgx_tstd/src/enclave.rs index 89a312f2f..7649cb220 100644 --- a/sgx_tstd/src/enclave.rs +++ b/sgx_tstd/src/enclave.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::fs; use crate::io; diff --git a/sgx_tstd/src/env.rs b/sgx_tstd/src/env.rs index ecc2fa79c..500cdf2cc 100644 --- a/sgx_tstd/src/env.rs +++ b/sgx_tstd/src/env.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Inspection and manipulation of the process's environment. //! diff --git a/sgx_tstd/src/env/tests.rs b/sgx_tstd/src/env/tests.rs index bc7e8c9ee..01d3988ed 100644 --- a/sgx_tstd/src/env/tests.rs +++ b/sgx_tstd/src/env/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::unnecessary_mut_passed)] diff --git a/sgx_tstd/src/error.rs b/sgx_tstd/src/error.rs index 736843f2a..3b45c4be7 100644 --- a/sgx_tstd/src/error.rs +++ b/sgx_tstd/src/error.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Traits for working with Errors. diff --git a/sgx_tstd/src/error/tests.rs b/sgx_tstd/src/error/tests.rs index 5fba6ecf0..9adf97df5 100644 --- a/sgx_tstd/src/error/tests.rs +++ b/sgx_tstd/src/error/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::Error; use crate::fmt; diff --git a/sgx_tstd/src/f32.rs b/sgx_tstd/src/f32.rs index e762be630..53ad7e8aa 100644 --- a/sgx_tstd/src/f32.rs +++ b/sgx_tstd/src/f32.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Constants for the `f32` single-precision floating point type. //! diff --git a/sgx_tstd/src/f32/tests.rs b/sgx_tstd/src/f32/tests.rs index a44f3883e..2dd94c9b2 100644 --- a/sgx_tstd/src/f32/tests.rs +++ b/sgx_tstd/src/f32/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::approx_constant)] #![allow(clippy::excessive_precision)] diff --git a/sgx_tstd/src/f64.rs b/sgx_tstd/src/f64.rs index 8c1979935..9fe630f50 100644 --- a/sgx_tstd/src/f64.rs +++ b/sgx_tstd/src/f64.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Constants for the `f64` double-precision floating point type. //! diff --git a/sgx_tstd/src/f64/tests.rs b/sgx_tstd/src/f64/tests.rs index 6aed8c08d..7d3a13b3a 100644 --- a/sgx_tstd/src/f64/tests.rs +++ b/sgx_tstd/src/f64/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::approx_constant)] #![allow(clippy::excessive_precision)] diff --git a/sgx_tstd/src/ffi/mod.rs b/sgx_tstd/src/ffi/mod.rs index 16635a3f8..9b75d5e66 100644 --- a/sgx_tstd/src/ffi/mod.rs +++ b/sgx_tstd/src/ffi/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Utilities related to FFI bindings. //! diff --git a/sgx_tstd/src/ffi/os_str.rs b/sgx_tstd/src/ffi/os_str.rs index 02d599148..c48607947 100644 --- a/sgx_tstd/src/ffi/os_str.rs +++ b/sgx_tstd/src/ffi/os_str.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::op_ref)] diff --git a/sgx_tstd/src/ffi/os_str/tests.rs b/sgx_tstd/src/ffi/os_str/tests.rs index 33fbb40fa..a13a722d2 100644 --- a/sgx_tstd/src/ffi/os_str/tests.rs +++ b/sgx_tstd/src/ffi/os_str/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use crate::sys_common::{AsInner, IntoInner}; diff --git a/sgx_tstd/src/fs.rs b/sgx_tstd/src/fs.rs index c259af4b0..cf6859916 100644 --- a/sgx_tstd/src/fs.rs +++ b/sgx_tstd/src/fs.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Filesystem manipulation operations. diff --git a/sgx_tstd/src/fs/tests.rs b/sgx_tstd/src/fs/tests.rs index 3d2f3fd2a..babbeede8 100644 --- a/sgx_tstd/src/fs/tests.rs +++ b/sgx_tstd/src/fs/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::op_ref)] #![allow(clippy::single_match)] diff --git a/sgx_tstd/src/hash/mod.rs b/sgx_tstd/src/hash/mod.rs index 8460b9512..bcea0a43e 100644 --- a/sgx_tstd/src/hash/mod.rs +++ b/sgx_tstd/src/hash/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Generic hashing support. //! diff --git a/sgx_tstd/src/hash/random.rs b/sgx_tstd/src/hash/random.rs index 63cd357a2..197636b76 100644 --- a/sgx_tstd/src/hash/random.rs +++ b/sgx_tstd/src/hash/random.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! This module exists to isolate [`RandomState`] and [`DefaultHasher`] outside of the diff --git a/sgx_tstd/src/io/buffered/bufreader.rs b/sgx_tstd/src/io/buffered/bufreader.rs index 65f4f846c..ced201271 100644 --- a/sgx_tstd/src/io/buffered/bufreader.rs +++ b/sgx_tstd/src/io/buffered/bufreader.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod buffer; diff --git a/sgx_tstd/src/io/buffered/bufreader/buffer.rs b/sgx_tstd/src/io/buffered/bufreader/buffer.rs index fb248802c..fd5777bca 100644 --- a/sgx_tstd/src/io/buffered/bufreader/buffer.rs +++ b/sgx_tstd/src/io/buffered/bufreader/buffer.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. /// An encapsulation of `BufReader`'s buffer management logic. /// diff --git a/sgx_tstd/src/io/buffered/bufwriter.rs b/sgx_tstd/src/io/buffered/bufwriter.rs index 8dd44a539..f921d149a 100644 --- a/sgx_tstd/src/io/buffered/bufwriter.rs +++ b/sgx_tstd/src/io/buffered/bufwriter.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::error; use crate::fmt; diff --git a/sgx_tstd/src/io/buffered/linewriter.rs b/sgx_tstd/src/io/buffered/linewriter.rs index b0997db2e..441f5b204 100644 --- a/sgx_tstd/src/io/buffered/linewriter.rs +++ b/sgx_tstd/src/io/buffered/linewriter.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::fmt; use crate::io::{self, buffered::LineWriterShim, BufWriter, IntoInnerError, IoSlice, Write}; diff --git a/sgx_tstd/src/io/buffered/linewritershim.rs b/sgx_tstd/src/io/buffered/linewritershim.rs index 470db0a9c..4fc851f0a 100644 --- a/sgx_tstd/src/io/buffered/linewritershim.rs +++ b/sgx_tstd/src/io/buffered/linewritershim.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::io::{self, BufWriter, IoSlice, Write}; use crate::sys_common::memchr; diff --git a/sgx_tstd/src/io/buffered/mod.rs b/sgx_tstd/src/io/buffered/mod.rs index 14d6097e1..60de6d38b 100644 --- a/sgx_tstd/src/io/buffered/mod.rs +++ b/sgx_tstd/src/io/buffered/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Buffering wrappers for I/O traits diff --git a/sgx_tstd/src/io/buffered/tests.rs b/sgx_tstd/src/io/buffered/tests.rs index 14de647e7..5c72f0eef 100644 --- a/sgx_tstd/src/io/buffered/tests.rs +++ b/sgx_tstd/src/io/buffered/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::io::prelude::*; use crate::io::{ diff --git a/sgx_tstd/src/io/copy.rs b/sgx_tstd/src/io/copy.rs index 1bed96d56..6f30fde27 100644 --- a/sgx_tstd/src/io/copy.rs +++ b/sgx_tstd/src/io/copy.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::{BorrowedBuf, BufReader, BufWriter, Read, Result, Write, DEFAULT_BUF_SIZE}; use crate::alloc::Allocator; diff --git a/sgx_tstd/src/io/copy/tests.rs b/sgx_tstd/src/io/copy/tests.rs index 80d4903da..d5df9ff9b 100644 --- a/sgx_tstd/src/io/copy/tests.rs +++ b/sgx_tstd/src/io/copy/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::cmp::{max, min}; use crate::collections::VecDeque; diff --git a/sgx_tstd/src/io/cursor.rs b/sgx_tstd/src/io/cursor.rs index e5fc84157..9f8da589d 100644 --- a/sgx_tstd/src/io/cursor.rs +++ b/sgx_tstd/src/io/cursor.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/io/cursor/tests.rs b/sgx_tstd/src/io/cursor/tests.rs index b61a46f33..fa93f4783 100644 --- a/sgx_tstd/src/io/cursor/tests.rs +++ b/sgx_tstd/src/io/cursor/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::unnecessary_cast)] diff --git a/sgx_tstd/src/io/error.rs b/sgx_tstd/src/io/error.rs index 6481cc07d..01c8c4a4b 100644 --- a/sgx_tstd/src/io/error.rs +++ b/sgx_tstd/src/io/error.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/io/error/repr_bitpacked.rs b/sgx_tstd/src/io/error/repr_bitpacked.rs index ac44b3ab0..6d1d5e46d 100644 --- a/sgx_tstd/src/io/error/repr_bitpacked.rs +++ b/sgx_tstd/src/io/error/repr_bitpacked.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! This is a densely packed error representation which is used on targets with //! 64-bit pointers. diff --git a/sgx_tstd/src/io/error/repr_unpacked.rs b/sgx_tstd/src/io/error/repr_unpacked.rs index 92aeb2e93..b47ac06c9 100644 --- a/sgx_tstd/src/io/error/repr_unpacked.rs +++ b/sgx_tstd/src/io/error/repr_unpacked.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! This is a fairly simple unpacked error representation that's used on //! non-64bit targets, where the packed 64 bit representation wouldn't work, and diff --git a/sgx_tstd/src/io/error/tests.rs b/sgx_tstd/src/io/error/tests.rs index 58d6e1148..8373ba91a 100644 --- a/sgx_tstd/src/io/error/tests.rs +++ b/sgx_tstd/src/io/error/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::{const_io_error, Custom, Error, ErrorData, ErrorKind, Repr, SimpleMessage}; use crate::assert_matches::assert_matches; diff --git a/sgx_tstd/src/io/impls.rs b/sgx_tstd/src/io/impls.rs index 0992d69df..8e7f61a1f 100644 --- a/sgx_tstd/src/io/impls.rs +++ b/sgx_tstd/src/io/impls.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/io/impls/tests.rs b/sgx_tstd/src/io/impls/tests.rs index 7adabb83e..c1f5233ea 100644 --- a/sgx_tstd/src/io/impls/tests.rs +++ b/sgx_tstd/src/io/impls/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::io::prelude::*; diff --git a/sgx_tstd/src/io/mod.rs b/sgx_tstd/src/io/mod.rs index 71d664b53..ee861b4da 100644 --- a/sgx_tstd/src/io/mod.rs +++ b/sgx_tstd/src/io/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Traits, helpers, and type definitions for core I/O functionality. //! diff --git a/sgx_tstd/src/io/prelude.rs b/sgx_tstd/src/io/prelude.rs index ca50e5dc6..e7211b4fe 100644 --- a/sgx_tstd/src/io/prelude.rs +++ b/sgx_tstd/src/io/prelude.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! The I/O Prelude. //! diff --git a/sgx_tstd/src/io/stdio.rs b/sgx_tstd/src/io/stdio.rs index b629fba40..8a02e6145 100644 --- a/sgx_tstd/src/io/stdio.rs +++ b/sgx_tstd/src/io/stdio.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/io/stdio/tests.rs b/sgx_tstd/src/io/stdio/tests.rs index 9b4a6201b..7a110ae88 100644 --- a/sgx_tstd/src/io/stdio/tests.rs +++ b/sgx_tstd/src/io/stdio/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use crate::panic::{RefUnwindSafe, UnwindSafe}; diff --git a/sgx_tstd/src/io/tests.rs b/sgx_tstd/src/io/tests.rs index 5b16a547d..edaa5ee6c 100644 --- a/sgx_tstd/src/io/tests.rs +++ b/sgx_tstd/src/io/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::{repeat, BorrowedBuf, Cursor, SeekFrom}; use crate::cmp::{self, min}; diff --git a/sgx_tstd/src/io/util.rs b/sgx_tstd/src/io/util.rs index f2cf7dce8..0bc7a7470 100644 --- a/sgx_tstd/src/io/util.rs +++ b/sgx_tstd/src/io/util.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(missing_copy_implementations)] diff --git a/sgx_tstd/src/io/util/tests.rs b/sgx_tstd/src/io/util/tests.rs index c0b42f9d7..279f6f85c 100644 --- a/sgx_tstd/src/io/util/tests.rs +++ b/sgx_tstd/src/io/util/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::io::prelude::*; use crate::io::{empty, repeat, sink, BorrowedBuf, Empty, Repeat, SeekFrom, Sink}; diff --git a/sgx_tstd/src/lib.rs b/sgx_tstd/src/lib.rs index 7ea24564c..d7d0465fe 100644 --- a/sgx_tstd/src/lib.rs +++ b/sgx_tstd/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! # The Rust SGX SDK Standard Library //! diff --git a/sgx_tstd/src/macros.rs b/sgx_tstd/src/macros.rs index 49a6b9561..03e6a1cf2 100644 --- a/sgx_tstd/src/macros.rs +++ b/sgx_tstd/src/macros.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Standard library macros //! diff --git a/sgx_tstd/src/net/ip_addr.rs b/sgx_tstd/src/net/ip_addr.rs index ae8e8e11b..010d26a53 100644 --- a/sgx_tstd/src/net/ip_addr.rs +++ b/sgx_tstd/src/net/ip_addr.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. // Tests for this module #[cfg(feature = "unit_test")] diff --git a/sgx_tstd/src/net/ip_addr/tests.rs b/sgx_tstd/src/net/ip_addr/tests.rs index 78b3377d9..950a12077 100644 --- a/sgx_tstd/src/net/ip_addr/tests.rs +++ b/sgx_tstd/src/net/ip_addr/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::net::test::{sa4, tsa}; use crate::net::Ipv4Addr; diff --git a/sgx_tstd/src/net/mod.rs b/sgx_tstd/src/net/mod.rs index 74dd1244b..04089ea7f 100644 --- a/sgx_tstd/src/net/mod.rs +++ b/sgx_tstd/src/net/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Networking primitives for TCP/UDP communication. //! diff --git a/sgx_tstd/src/net/socket_addr.rs b/sgx_tstd/src/net/socket_addr.rs index 94d038283..45a4cbcd0 100644 --- a/sgx_tstd/src/net/socket_addr.rs +++ b/sgx_tstd/src/net/socket_addr.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::derived_hash_with_manual_eq)] diff --git a/sgx_tstd/src/net/socket_addr/tests.rs b/sgx_tstd/src/net/socket_addr/tests.rs index b8e5afe05..b4a289c50 100644 --- a/sgx_tstd/src/net/socket_addr/tests.rs +++ b/sgx_tstd/src/net/socket_addr/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::net::test::{sa4, sa6, tsa}; use crate::net::*; diff --git a/sgx_tstd/src/net/tcp.rs b/sgx_tstd/src/net/tcp.rs index d615a2d67..4d60a3163 100644 --- a/sgx_tstd/src/net/tcp.rs +++ b/sgx_tstd/src/net/tcp.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/net/tcp/tests.rs b/sgx_tstd/src/net/tcp/tests.rs index 9e72449ca..a89eb2d37 100644 --- a/sgx_tstd/src/net/tcp/tests.rs +++ b/sgx_tstd/src/net/tcp/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::bool_assert_comparison)] #![allow(clippy::needless_lifetimes)] diff --git a/sgx_tstd/src/net/test.rs b/sgx_tstd/src/net/test.rs index f34c10de8..0e472c6b0 100644 --- a/sgx_tstd/src/net/test.rs +++ b/sgx_tstd/src/net/test.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(warnings)] // not used on emscripten diff --git a/sgx_tstd/src/net/udp.rs b/sgx_tstd/src/net/udp.rs index 54a85b259..bd59f829b 100644 --- a/sgx_tstd/src/net/udp.rs +++ b/sgx_tstd/src/net/udp.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/net/udp/tests.rs b/sgx_tstd/src/net/udp/tests.rs index 540d25e5d..7c815e03a 100644 --- a/sgx_tstd/src/net/udp/tests.rs +++ b/sgx_tstd/src/net/udp/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::io::ErrorKind; use crate::net::test::{next_test_ip4, next_test_ip6}; diff --git a/sgx_tstd/src/num.rs b/sgx_tstd/src/num.rs index be8558fd6..245927dfa 100644 --- a/sgx_tstd/src/num.rs +++ b/sgx_tstd/src/num.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Additional functionality for numerics. //! diff --git a/sgx_tstd/src/num/benches.rs b/sgx_tstd/src/num/benches.rs index f84da2982..2a546f898 100644 --- a/sgx_tstd/src/num/benches.rs +++ b/sgx_tstd/src/num/benches.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use sgx_test_utils::{bench_case, Bencher}; diff --git a/sgx_tstd/src/num/tests.rs b/sgx_tstd/src/num/tests.rs index cfe9a9b56..444804620 100644 --- a/sgx_tstd/src/num/tests.rs +++ b/sgx_tstd/src/num/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ops::Mul; diff --git a/sgx_tstd/src/os/fd/mod.rs b/sgx_tstd/src/os/fd/mod.rs index 137ef2192..683672536 100644 --- a/sgx_tstd/src/os/fd/mod.rs +++ b/sgx_tstd/src/os/fd/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Owned and borrowed Unix-like file descriptors. //! diff --git a/sgx_tstd/src/os/fd/net.rs b/sgx_tstd/src/os/fd/net.rs index 23b04d62f..e02e58d7e 100644 --- a/sgx_tstd/src/os/fd/net.rs +++ b/sgx_tstd/src/os/fd/net.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::os::fd::owned::OwnedFd; use crate::os::fd::raw::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; diff --git a/sgx_tstd/src/os/fd/owned.rs b/sgx_tstd/src/os/fd/owned.rs index 9809485f2..052bd9a3f 100644 --- a/sgx_tstd/src/os/fd/owned.rs +++ b/sgx_tstd/src/os/fd/owned.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Owned and borrowed Unix-like file descriptors. diff --git a/sgx_tstd/src/os/fd/raw.rs b/sgx_tstd/src/os/fd/raw.rs index baa8696c1..1715c08b5 100644 --- a/sgx_tstd/src/os/fd/raw.rs +++ b/sgx_tstd/src/os/fd/raw.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Raw Unix-like file descriptors. diff --git a/sgx_tstd/src/os/fd/tests.rs b/sgx_tstd/src/os/fd/tests.rs index 7b4d1d536..b80ba6970 100644 --- a/sgx_tstd/src/os/fd/tests.rs +++ b/sgx_tstd/src/os/fd/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use sgx_test_utils::test_case; diff --git a/sgx_tstd/src/os/linux/fs.rs b/sgx_tstd/src/os/linux/fs.rs index 7f2874eb2..31fc29724 100644 --- a/sgx_tstd/src/os/linux/fs.rs +++ b/sgx_tstd/src/os/linux/fs.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Linux-specific extensions to primitives in the [`std::fs`] module. //! diff --git a/sgx_tstd/src/os/linux/mod.rs b/sgx_tstd/src/os/linux/mod.rs index 13f93ce06..11fbab739 100644 --- a/sgx_tstd/src/os/linux/mod.rs +++ b/sgx_tstd/src/os/linux/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Linux-specific definitions. diff --git a/sgx_tstd/src/os/linux/net.rs b/sgx_tstd/src/os/linux/net.rs index 710cdac56..e63b64144 100644 --- a/sgx_tstd/src/os/linux/net.rs +++ b/sgx_tstd/src/os/linux/net.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Linux-specific networking functionality. diff --git a/sgx_tstd/src/os/linux/process.rs b/sgx_tstd/src/os/linux/process.rs index 305aeb8b4..a83f372e3 100644 --- a/sgx_tstd/src/os/linux/process.rs +++ b/sgx_tstd/src/os/linux/process.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Linux-specific extensions to primitives in the [`std::process`] module. //! diff --git a/sgx_tstd/src/os/linux/raw.rs b/sgx_tstd/src/os/linux/raw.rs index ae453f631..de353510c 100644 --- a/sgx_tstd/src/os/linux/raw.rs +++ b/sgx_tstd/src/os/linux/raw.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Linux-specific raw type definitions. diff --git a/sgx_tstd/src/os/mod.rs b/sgx_tstd/src/os/mod.rs index e54d139eb..d1b8c8ad8 100644 --- a/sgx_tstd/src/os/mod.rs +++ b/sgx_tstd/src/os/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! OS-specific functionality. diff --git a/sgx_tstd/src/os/net/linux_ext/addr.rs b/sgx_tstd/src/os/net/linux_ext/addr.rs index a2515a50c..d6bf1c827 100644 --- a/sgx_tstd/src/os/net/linux_ext/addr.rs +++ b/sgx_tstd/src/os/net/linux_ext/addr.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Linux and Android-specific extensions to socket addresses. diff --git a/sgx_tstd/src/os/net/linux_ext/mod.rs b/sgx_tstd/src/os/net/linux_ext/mod.rs index 43176af03..78936c6f5 100644 --- a/sgx_tstd/src/os/net/linux_ext/mod.rs +++ b/sgx_tstd/src/os/net/linux_ext/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Linux and Android-specific networking functionality. diff --git a/sgx_tstd/src/os/net/linux_ext/tcp.rs b/sgx_tstd/src/os/net/linux_ext/tcp.rs index 3badd2dbd..c8002c9cd 100644 --- a/sgx_tstd/src/os/net/linux_ext/tcp.rs +++ b/sgx_tstd/src/os/net/linux_ext/tcp.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Linux and Android-specific tcp extensions to primitives in the [`std::net`] module. //! diff --git a/sgx_tstd/src/os/net/linux_ext/tests.rs b/sgx_tstd/src/os/net/linux_ext/tests.rs index 6340e10c9..4dc9d20d3 100644 --- a/sgx_tstd/src/os/net/linux_ext/tests.rs +++ b/sgx_tstd/src/os/net/linux_ext/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use sgx_test_utils::test_case; diff --git a/sgx_tstd/src/os/net/mod.rs b/sgx_tstd/src/os/net/mod.rs index bf6c909dd..0b585801e 100644 --- a/sgx_tstd/src/os/net/mod.rs +++ b/sgx_tstd/src/os/net/mod.rs @@ -13,6 +13,6 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub(super) mod linux_ext; diff --git a/sgx_tstd/src/os/raw/mod.rs b/sgx_tstd/src/os/raw/mod.rs index ac98a34a5..006c0dde9 100644 --- a/sgx_tstd/src/os/raw/mod.rs +++ b/sgx_tstd/src/os/raw/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Compatibility module for C platform-specific types. Use [`core::ffi`] instead. diff --git a/sgx_tstd/src/os/raw/tests.rs b/sgx_tstd/src/os/raw/tests.rs index 0440de60a..0e37bc534 100644 --- a/sgx_tstd/src/os/raw/tests.rs +++ b/sgx_tstd/src/os/raw/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::any::TypeId; diff --git a/sgx_tstd/src/os/unix/ffi/mod.rs b/sgx_tstd/src/os/unix/ffi/mod.rs index 342bb7491..0d2ee2652 100644 --- a/sgx_tstd/src/os/unix/ffi/mod.rs +++ b/sgx_tstd/src/os/unix/ffi/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Unix-specific extensions to primitives in the [`std::ffi`] module. //! diff --git a/sgx_tstd/src/os/unix/ffi/os_str.rs b/sgx_tstd/src/os/unix/ffi/os_str.rs index 5ba5083f7..7b520e516 100644 --- a/sgx_tstd/src/os/unix/ffi/os_str.rs +++ b/sgx_tstd/src/os/unix/ffi/os_str.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ffi::{OsStr, OsString}; use crate::mem; diff --git a/sgx_tstd/src/os/unix/fs.rs b/sgx_tstd/src/os/unix/fs.rs index a6c856711..e74eae810 100644 --- a/sgx_tstd/src/os/unix/fs.rs +++ b/sgx_tstd/src/os/unix/fs.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Unix-specific extensions to primitives in the [`std::fs`] module. //! diff --git a/sgx_tstd/src/os/unix/fs/tests.rs b/sgx_tstd/src/os/unix/fs/tests.rs index 1607362f8..52030caa2 100644 --- a/sgx_tstd/src/os/unix/fs/tests.rs +++ b/sgx_tstd/src/os/unix/fs/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_tstd/src/os/unix/io/mod.rs b/sgx_tstd/src/os/unix/io/mod.rs index b1484338b..8a6446adf 100644 --- a/sgx_tstd/src/os/unix/io/mod.rs +++ b/sgx_tstd/src/os/unix/io/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Unix-specific extensions to general I/O primitives. //! diff --git a/sgx_tstd/src/os/unix/io/tests.rs b/sgx_tstd/src/os/unix/io/tests.rs index ac9576022..f759793d1 100644 --- a/sgx_tstd/src/os/unix/io/tests.rs +++ b/sgx_tstd/src/os/unix/io/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::mem::size_of; use crate::os::unix::io::RawFd; diff --git a/sgx_tstd/src/os/unix/mod.rs b/sgx_tstd/src/os/unix/mod.rs index 377f98e7d..4244e31b1 100644 --- a/sgx_tstd/src/os/unix/mod.rs +++ b/sgx_tstd/src/os/unix/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Platform-specific extensions to `std` for Unix platforms. //! diff --git a/sgx_tstd/src/os/unix/net/addr.rs b/sgx_tstd/src/os/unix/net/addr.rs index 55f0404fb..e89d448f6 100644 --- a/sgx_tstd/src/os/unix/net/addr.rs +++ b/sgx_tstd/src/os/unix/net/addr.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::convert::{TryFrom, TryInto}; use crate::ffi::OsStr; diff --git a/sgx_tstd/src/os/unix/net/ancillary.rs b/sgx_tstd/src/os/unix/net/ancillary.rs index 6a6627576..848a54315 100644 --- a/sgx_tstd/src/os/unix/net/ancillary.rs +++ b/sgx_tstd/src/os/unix/net/ancillary.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::{sockaddr_un, SocketAddr}; diff --git a/sgx_tstd/src/os/unix/net/datagram.rs b/sgx_tstd/src/os/unix/net/datagram.rs index 8e9430f85..a1e9bbd38 100644 --- a/sgx_tstd/src/os/unix/net/datagram.rs +++ b/sgx_tstd/src/os/unix/net/datagram.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::{recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to, SocketAncillary}; use super::{sockaddr_un, SocketAddr}; diff --git a/sgx_tstd/src/os/unix/net/listener.rs b/sgx_tstd/src/os/unix/net/listener.rs index 4c249a635..d49925f03 100644 --- a/sgx_tstd/src/os/unix/net/listener.rs +++ b/sgx_tstd/src/os/unix/net/listener.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::{sockaddr_un, SocketAddr, UnixStream}; use crate::convert::TryInto; diff --git a/sgx_tstd/src/os/unix/net/mod.rs b/sgx_tstd/src/os/unix/net/mod.rs index 78783ebe7..f4e7fbb76 100644 --- a/sgx_tstd/src/os/unix/net/mod.rs +++ b/sgx_tstd/src/os/unix/net/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Unix-specific networking functionality. diff --git a/sgx_tstd/src/os/unix/net/stream.rs b/sgx_tstd/src/os/unix/net/stream.rs index 6b2d866a4..a66dcc9e4 100644 --- a/sgx_tstd/src/os/unix/net/stream.rs +++ b/sgx_tstd/src/os/unix/net/stream.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::{recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to, SocketAncillary}; use super::{sockaddr_un, SocketAddr}; diff --git a/sgx_tstd/src/os/unix/net/tests.rs b/sgx_tstd/src/os/unix/net/tests.rs index 5b2e95773..d5a561b58 100644 --- a/sgx_tstd/src/os/unix/net/tests.rs +++ b/sgx_tstd/src/os/unix/net/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::bool_assert_comparison)] #![allow(clippy::needless_borrow)] diff --git a/sgx_tstd/src/os/unix/process.rs b/sgx_tstd/src/os/unix/process.rs index ddafe3b02..6f355d9e6 100644 --- a/sgx_tstd/src/os/unix/process.rs +++ b/sgx_tstd/src/os/unix/process.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Unix-specific extensions to primitives in the [`std::process`] module. //! diff --git a/sgx_tstd/src/os/unix/raw.rs b/sgx_tstd/src/os/unix/raw.rs index 93de8f8f0..6189809cf 100644 --- a/sgx_tstd/src/os/unix/raw.rs +++ b/sgx_tstd/src/os/unix/raw.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Unix-specific primitives available on all unix platforms. diff --git a/sgx_tstd/src/os/unix/thread.rs b/sgx_tstd/src/os/unix/thread.rs index 5ac3ed1b5..9d31cfdb4 100644 --- a/sgx_tstd/src/os/unix/thread.rs +++ b/sgx_tstd/src/os/unix/thread.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Unix-specific extensions to primitives in the [`std::thread`] module. //! diff --git a/sgx_tstd/src/os/unix/ucred.rs b/sgx_tstd/src/os/unix/ucred.rs index cb6571030..344dab06b 100644 --- a/sgx_tstd/src/os/unix/ucred.rs +++ b/sgx_tstd/src/os/unix/ucred.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Unix peer credentials. diff --git a/sgx_tstd/src/os/unix/ucred/tests.rs b/sgx_tstd/src/os/unix/ucred/tests.rs index eb8fb78c8..9ecba9d27 100644 --- a/sgx_tstd/src/os/unix/ucred/tests.rs +++ b/sgx_tstd/src/os/unix/ucred/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::os::unix::net::UnixStream; use libc::{getgid, getpid, getuid}; diff --git a/sgx_tstd/src/panic.rs b/sgx_tstd/src/panic.rs index 991660d3f..983866503 100644 --- a/sgx_tstd/src/panic.rs +++ b/sgx_tstd/src/panic.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Panic support in the standard library. diff --git a/sgx_tstd/src/panic/tests.rs b/sgx_tstd/src/panic/tests.rs index 8e298c1c4..5079c40f9 100644 --- a/sgx_tstd/src/panic/tests.rs +++ b/sgx_tstd/src/panic/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(dead_code)] diff --git a/sgx_tstd/src/panicking.rs b/sgx_tstd/src/panicking.rs index ae3d4ef43..c9595d58a 100644 --- a/sgx_tstd/src/panicking.rs +++ b/sgx_tstd/src/panicking.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Implementation of various bits and pieces of the `panic!` macro and //! associated runtime pieces. diff --git a/sgx_tstd/src/path.rs b/sgx_tstd/src/path.rs index d7e92c2f6..04319a32f 100644 --- a/sgx_tstd/src/path.rs +++ b/sgx_tstd/src/path.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Cross-platform path manipulation. //! diff --git a/sgx_tstd/src/path/tests.rs b/sgx_tstd/src/path/tests.rs index 82821b9b8..d96054479 100644 --- a/sgx_tstd/src/path/tests.rs +++ b/sgx_tstd/src/path/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_tstd/src/prelude/mod.rs b/sgx_tstd/src/prelude/mod.rs index e3109bf4e..581a3faea 100644 --- a/sgx_tstd/src/prelude/mod.rs +++ b/sgx_tstd/src/prelude/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! # The Rust Prelude //! diff --git a/sgx_tstd/src/prelude/v1.rs b/sgx_tstd/src/prelude/v1.rs index 838739022..83f97077d 100644 --- a/sgx_tstd/src/prelude/v1.rs +++ b/sgx_tstd/src/prelude/v1.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! The first version of the prelude of The Rust Standard Library. //! diff --git a/sgx_tstd/src/process.rs b/sgx_tstd/src/process.rs index a36a2b76a..a4ce47308 100644 --- a/sgx_tstd/src/process.rs +++ b/sgx_tstd/src/process.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! A module for working with processes. //! diff --git a/sgx_tstd/src/rt.rs b/sgx_tstd/src/rt.rs index a2a5225f9..b8928b4d9 100644 --- a/sgx_tstd/src/rt.rs +++ b/sgx_tstd/src/rt.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Runtime services diff --git a/sgx_tstd/src/sync/barrier.rs b/sgx_tstd/src/sync/barrier.rs index 103ea0be8..dff761206 100644 --- a/sgx_tstd/src/sync/barrier.rs +++ b/sgx_tstd/src/sync/barrier.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/sync/barrier/tests.rs b/sgx_tstd/src/sync/barrier/tests.rs index e2bf151df..6bfad06e5 100644 --- a/sgx_tstd/src/sync/barrier/tests.rs +++ b/sgx_tstd/src/sync/barrier/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sync::mpsc::{channel, TryRecvError}; use crate::sync::{Arc, Barrier}; diff --git a/sgx_tstd/src/sync/condvar.rs b/sgx_tstd/src/sync/condvar.rs index f763801fa..c806aab2b 100644 --- a/sgx_tstd/src/sync/condvar.rs +++ b/sgx_tstd/src/sync/condvar.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/sync/condvar/tests.rs b/sgx_tstd/src/sync/condvar/tests.rs index d4f565e15..30a34d7ae 100644 --- a/sgx_tstd/src/sync/condvar/tests.rs +++ b/sgx_tstd/src/sync/condvar/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::mutex_atomic)] diff --git a/sgx_tstd/src/sync/lazy_lock.rs b/sgx_tstd/src/sync/lazy_lock.rs index d57534d2d..f056d99f9 100644 --- a/sgx_tstd/src/sync/lazy_lock.rs +++ b/sgx_tstd/src/sync/lazy_lock.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::cell::UnsafeCell; use crate::mem::ManuallyDrop; diff --git a/sgx_tstd/src/sync/lazy_lock/tests.rs b/sgx_tstd/src/sync/lazy_lock/tests.rs index 2fc0bfac6..34e65c734 100644 --- a/sgx_tstd/src/sync/lazy_lock/tests.rs +++ b/sgx_tstd/src/sync/lazy_lock/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::{ cell::LazyCell, diff --git a/sgx_tstd/src/sync/mod.rs b/sgx_tstd/src/sync/mod.rs index 712c6988c..3496aa75a 100644 --- a/sgx_tstd/src/sync/mod.rs +++ b/sgx_tstd/src/sync/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Useful synchronization primitives. //! diff --git a/sgx_tstd/src/sync/mpmc/array.rs b/sgx_tstd/src/sync/mpmc/array.rs index 230db92c1..2aef77443 100644 --- a/sgx_tstd/src/sync/mpmc/array.rs +++ b/sgx_tstd/src/sync/mpmc/array.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Bounded channel based on a preallocated array. //! diff --git a/sgx_tstd/src/sync/mpmc/context.rs b/sgx_tstd/src/sync/mpmc/context.rs index 14cac3546..9a6f3cc9f 100644 --- a/sgx_tstd/src/sync/mpmc/context.rs +++ b/sgx_tstd/src/sync/mpmc/context.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Thread-local channel context. diff --git a/sgx_tstd/src/sync/mpmc/counter.rs b/sgx_tstd/src/sync/mpmc/counter.rs index c34cb55bf..565465ed1 100644 --- a/sgx_tstd/src/sync/mpmc/counter.rs +++ b/sgx_tstd/src/sync/mpmc/counter.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ops; use crate::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; diff --git a/sgx_tstd/src/sync/mpmc/error.rs b/sgx_tstd/src/sync/mpmc/error.rs index 28e1fe42f..a8f265633 100644 --- a/sgx_tstd/src/sync/mpmc/error.rs +++ b/sgx_tstd/src/sync/mpmc/error.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::error; use crate::fmt; diff --git a/sgx_tstd/src/sync/mpmc/list.rs b/sgx_tstd/src/sync/mpmc/list.rs index 07285b673..ba4bb369c 100644 --- a/sgx_tstd/src/sync/mpmc/list.rs +++ b/sgx_tstd/src/sync/mpmc/list.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Unbounded channel implemented as a linked list. diff --git a/sgx_tstd/src/sync/mpmc/mod.rs b/sgx_tstd/src/sync/mpmc/mod.rs index f1cead50f..c90bd69b4 100644 --- a/sgx_tstd/src/sync/mpmc/mod.rs +++ b/sgx_tstd/src/sync/mpmc/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Multi-producer multi-consumer channels. diff --git a/sgx_tstd/src/sync/mpmc/select.rs b/sgx_tstd/src/sync/mpmc/select.rs index 94e20eb53..0b774babc 100644 --- a/sgx_tstd/src/sync/mpmc/select.rs +++ b/sgx_tstd/src/sync/mpmc/select.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. /// Temporary data that gets initialized during a blocking operation, and is consumed by /// `read` or `write`. diff --git a/sgx_tstd/src/sync/mpmc/utils.rs b/sgx_tstd/src/sync/mpmc/utils.rs index 998b1bd65..399c727e3 100644 --- a/sgx_tstd/src/sync/mpmc/utils.rs +++ b/sgx_tstd/src/sync/mpmc/utils.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::cell::Cell; use crate::ops::{Deref, DerefMut}; diff --git a/sgx_tstd/src/sync/mpmc/waker.rs b/sgx_tstd/src/sync/mpmc/waker.rs index a3e4a6c2d..290efa7db 100644 --- a/sgx_tstd/src/sync/mpmc/waker.rs +++ b/sgx_tstd/src/sync/mpmc/waker.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Waking mechanism for threads blocked on channel operations. diff --git a/sgx_tstd/src/sync/mpmc/zero.rs b/sgx_tstd/src/sync/mpmc/zero.rs index a35eb6e64..de6faa41a 100644 --- a/sgx_tstd/src/sync/mpmc/zero.rs +++ b/sgx_tstd/src/sync/mpmc/zero.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Zero-capacity channel. //! diff --git a/sgx_tstd/src/sync/mpsc/mod.rs b/sgx_tstd/src/sync/mpsc/mod.rs index 312d1257c..2635ca456 100644 --- a/sgx_tstd/src/sync/mpsc/mod.rs +++ b/sgx_tstd/src/sync/mpsc/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Multi-producer, single-consumer FIFO queue communication primitives. //! diff --git a/sgx_tstd/src/sync/mpsc/sync_tests.rs b/sgx_tstd/src/sync/mpsc/sync_tests.rs index 4f5da1d5b..233226efb 100644 --- a/sgx_tstd/src/sync/mpsc/sync_tests.rs +++ b/sgx_tstd/src/sync/mpsc/sync_tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use crate::env; diff --git a/sgx_tstd/src/sync/mpsc/tests.rs b/sgx_tstd/src/sync/mpsc/tests.rs index a028f080c..373688d24 100644 --- a/sgx_tstd/src/sync/mpsc/tests.rs +++ b/sgx_tstd/src/sync/mpsc/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::bool_assert_comparison)] #![allow(clippy::ok_expect)] diff --git a/sgx_tstd/src/sync/mutex.rs b/sgx_tstd/src/sync/mutex.rs index 8b16c7e58..e2fb2e62c 100644 --- a/sgx_tstd/src/sync/mutex.rs +++ b/sgx_tstd/src/sync/mutex.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/sync/mutex/tests.rs b/sgx_tstd/src/sync/mutex/tests.rs index 9223dcb6c..61e004274 100644 --- a/sgx_tstd/src/sync/mutex/tests.rs +++ b/sgx_tstd/src/sync/mutex/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::unused_unit)] diff --git a/sgx_tstd/src/sync/once.rs b/sgx_tstd/src/sync/once.rs index d657b6761..1da807bc3 100644 --- a/sgx_tstd/src/sync/once.rs +++ b/sgx_tstd/src/sync/once.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! A "once initialization" primitive //! diff --git a/sgx_tstd/src/sync/once/tests.rs b/sgx_tstd/src/sync/once/tests.rs index 481860c59..b71d2941f 100644 --- a/sgx_tstd/src/sync/once/tests.rs +++ b/sgx_tstd/src/sync/once/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::Once; use crate::panic; diff --git a/sgx_tstd/src/sync/once_lock.rs b/sgx_tstd/src/sync/once_lock.rs index f5cdc83bd..6a4c3d4da 100644 --- a/sgx_tstd/src/sync/once_lock.rs +++ b/sgx_tstd/src/sync/once_lock.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::unnecessary_mut_passed)] diff --git a/sgx_tstd/src/sync/once_lock/tests.rs b/sgx_tstd/src/sync/once_lock/tests.rs index 501e1da01..eb597f9c5 100644 --- a/sgx_tstd/src/sync/once_lock/tests.rs +++ b/sgx_tstd/src/sync/once_lock/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::{ panic, diff --git a/sgx_tstd/src/sync/poison.rs b/sgx_tstd/src/sync/poison.rs index 3b9e34e69..b9c1e7a26 100644 --- a/sgx_tstd/src/sync/poison.rs +++ b/sgx_tstd/src/sync/poison.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::error::Error; use crate::fmt; diff --git a/sgx_tstd/src/sync/remutex.rs b/sgx_tstd/src/sync/remutex.rs index 9ed1aeca7..d84826a54 100644 --- a/sgx_tstd/src/sync/remutex.rs +++ b/sgx_tstd/src/sync/remutex.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/sync/remutex/tests.rs b/sgx_tstd/src/sync/remutex/tests.rs index 131c4708e..c1752eb2e 100644 --- a/sgx_tstd/src/sync/remutex/tests.rs +++ b/sgx_tstd/src/sync/remutex/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::{ReentrantMutex, ReentrantMutexGuard}; use crate::cell::RefCell; diff --git a/sgx_tstd/src/sync/rwlock.rs b/sgx_tstd/src/sync/rwlock.rs index 312f7e3ba..85d8a1f07 100644 --- a/sgx_tstd/src/sync/rwlock.rs +++ b/sgx_tstd/src/sync/rwlock.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/sync/rwlock/tests.rs b/sgx_tstd/src/sync/rwlock/tests.rs index 30d0ad8e3..855261ed1 100644 --- a/sgx_tstd/src/sync/rwlock/tests.rs +++ b/sgx_tstd/src/sync/rwlock/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::assertions_on_constants)] diff --git a/sgx_tstd/src/sys/args.rs b/sgx_tstd/src/sys/args.rs index 7f40b7f02..b420f665e 100644 --- a/sgx_tstd/src/sys/args.rs +++ b/sgx_tstd/src/sys/args.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Global initialization and retrieval of command line arguments. //! diff --git a/sgx_tstd/src/sys/backtrace/mod.rs b/sgx_tstd/src/sys/backtrace/mod.rs index 75aef3640..276541d12 100644 --- a/sgx_tstd/src/sys/backtrace/mod.rs +++ b/sgx_tstd/src/sys/backtrace/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use self::printing::{BacktraceFmt, PrintFmt}; /// Backtrace support built on libgcc with some extra OS-specific support diff --git a/sgx_tstd/src/sys/backtrace/printing/mod.rs b/sgx_tstd/src/sys/backtrace/printing/mod.rs index 267406082..789966d39 100644 --- a/sgx_tstd/src/sys/backtrace/printing/mod.rs +++ b/sgx_tstd/src/sys/backtrace/printing/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ffi::c_void; use crate::fmt; diff --git a/sgx_tstd/src/sys/backtrace/tracing/gcc_s.rs b/sgx_tstd/src/sys/backtrace/tracing/gcc_s.rs index 771a4e813..34b35eed7 100644 --- a/sgx_tstd/src/sys/backtrace/tracing/gcc_s.rs +++ b/sgx_tstd/src/sys/backtrace/tracing/gcc_s.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ffi::c_void; use crate::sys::backtrace::Bomb; diff --git a/sgx_tstd/src/sys/backtrace/tracing/mod.rs b/sgx_tstd/src/sys/backtrace/tracing/mod.rs index 41d9677d1..516ce89f8 100644 --- a/sgx_tstd/src/sys/backtrace/tracing/mod.rs +++ b/sgx_tstd/src/sys/backtrace/tracing/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ffi::c_void; use crate::fmt; diff --git a/sgx_tstd/src/sys/cmath.rs b/sgx_tstd/src/sys/cmath.rs index df4acf69c..e6870afdc 100644 --- a/sgx_tstd/src/sys/cmath.rs +++ b/sgx_tstd/src/sys/cmath.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. // These symbols are all defined by `libm`, // or by `compiler-builtins` on unsupported platforms. diff --git a/sgx_tstd/src/sys/common/mod.rs b/sgx_tstd/src/sys/common/mod.rs index e1eed39b8..5e5c784d3 100644 --- a/sgx_tstd/src/sys/common/mod.rs +++ b/sgx_tstd/src/sys/common/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(dead_code)] pub mod small_c_string; diff --git a/sgx_tstd/src/sys/common/small_c_string.rs b/sgx_tstd/src/sys/common/small_c_string.rs index 8c2f59734..74c38526a 100644 --- a/sgx_tstd/src/sys/common/small_c_string.rs +++ b/sgx_tstd/src/sys/common/small_c_string.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ffi::{CStr, CString}; use crate::mem::MaybeUninit; diff --git a/sgx_tstd/src/sys/common/tests.rs b/sgx_tstd/src/sys/common/tests.rs index 5913ab3d6..eb5738243 100644 --- a/sgx_tstd/src/sys/common/tests.rs +++ b/sgx_tstd/src/sys/common/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ffi::CString; use crate::hint::black_box; diff --git a/sgx_tstd/src/sys/common/thread_local/fast_local.rs b/sgx_tstd/src/sys/common/thread_local/fast_local.rs index 1d655eec6..3b15fa3fe 100644 --- a/sgx_tstd/src/sys/common/thread_local/fast_local.rs +++ b/sgx_tstd/src/sys/common/thread_local/fast_local.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::lazy::LazyKeyInner; use crate::cell::Cell; diff --git a/sgx_tstd/src/sys/common/thread_local/mod.rs b/sgx_tstd/src/sys/common/thread_local/mod.rs index 930dd6149..dfe9bcda8 100644 --- a/sgx_tstd/src/sys/common/thread_local/mod.rs +++ b/sgx_tstd/src/sys/common/thread_local/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. // There are three thread-local implementations: "static", "fast", "OS". // The "OS" thread local key type is accessed via platform-specific API calls and is slow, while the diff --git a/sgx_tstd/src/sys/common/thread_local/os_local.rs b/sgx_tstd/src/sys/common/thread_local/os_local.rs index c3579e051..22f0224fd 100644 --- a/sgx_tstd/src/sys/common/thread_local/os_local.rs +++ b/sgx_tstd/src/sys/common/thread_local/os_local.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::lazy::LazyKeyInner; use crate::cell::Cell; diff --git a/sgx_tstd/src/sys/common/thread_local/static_local.rs b/sgx_tstd/src/sys/common/thread_local/static_local.rs index e81cb66f4..0e6b104ac 100644 --- a/sgx_tstd/src/sys/common/thread_local/static_local.rs +++ b/sgx_tstd/src/sys/common/thread_local/static_local.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::lazy::LazyKeyInner; use crate::fmt; diff --git a/sgx_tstd/src/sys/env.rs b/sgx_tstd/src/sys/env.rs index 19dec25cb..620dd17f7 100644 --- a/sgx_tstd/src/sys/env.rs +++ b/sgx_tstd/src/sys/env.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub mod os { pub const FAMILY: &str = "unix"; diff --git a/sgx_tstd/src/sys/fd.rs b/sgx_tstd/src/sys/fd.rs index 9d24b5924..1e07b12f2 100644 --- a/sgx_tstd/src/sys/fd.rs +++ b/sgx_tstd/src/sys/fd.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/sys/fd/tests.rs b/sgx_tstd/src/sys/fd/tests.rs index 8e1583b98..ee8bdb2cc 100644 --- a/sgx_tstd/src/sys/fd/tests.rs +++ b/sgx_tstd/src/sys/fd/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::{FileDesc, IoSlice}; use crate::os::unix::io::FromRawFd; diff --git a/sgx_tstd/src/sys/fs.rs b/sgx_tstd/src/sys/fs.rs index 58f236907..206bd86e1 100644 --- a/sgx_tstd/src/sys/fs.rs +++ b/sgx_tstd/src/sys/fs.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::os::unix::prelude::*; diff --git a/sgx_tstd/src/sys/futex.rs b/sgx_tstd/src/sys/futex.rs index e1b86da51..923008fc1 100644 --- a/sgx_tstd/src/sys/futex.rs +++ b/sgx_tstd/src/sys/futex.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sync::atomic::AtomicU32; use crate::time::Duration; diff --git a/sgx_tstd/src/sys/io.rs b/sgx_tstd/src/sys/io.rs index 318b32029..cb6375c97 100644 --- a/sgx_tstd/src/sys/io.rs +++ b/sgx_tstd/src/sys/io.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::marker::PhantomData; use crate::os::fd::{AsFd, AsRawFd}; diff --git a/sgx_tstd/src/sys/kernel_copy.rs b/sgx_tstd/src/sys/kernel_copy.rs index 0bb76d627..b09413441 100644 --- a/sgx_tstd/src/sys/kernel_copy.rs +++ b/sgx_tstd/src/sys/kernel_copy.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! This module contains specializations that can offload `io::copy()` operations on file descriptor //! containing types (`File`, `TcpStream`, etc.) to more efficient syscalls than `read(2)` and `write(2)`. diff --git a/sgx_tstd/src/sys/kernel_copy/tests.rs b/sgx_tstd/src/sys/kernel_copy/tests.rs index 2707c4fd6..7dc60c63b 100644 --- a/sgx_tstd/src/sys/kernel_copy/tests.rs +++ b/sgx_tstd/src/sys/kernel_copy/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::fs::OpenOptions; use crate::io; diff --git a/sgx_tstd/src/sys/memchr.rs b/sgx_tstd/src/sys/memchr.rs index 2ca033187..79e99e3e5 100644 --- a/sgx_tstd/src/sys/memchr.rs +++ b/sgx_tstd/src/sys/memchr.rs @@ -13,6 +13,6 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use sgx_ffi::memchr::*; diff --git a/sgx_tstd/src/sys/mod.rs b/sgx_tstd/src/sys/mod.rs index b9bf53941..5aee14b05 100644 --- a/sgx_tstd/src/sys/mod.rs +++ b/sgx_tstd/src/sys/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ffi::CString; use crate::io::ErrorKind; diff --git a/sgx_tstd/src/sys/net.rs b/sgx_tstd/src/sys/net.rs index 8c78f8ae4..ad417f0ea 100644 --- a/sgx_tstd/src/sys/net.rs +++ b/sgx_tstd/src/sys/net.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::cmp; use crate::io::{self, BorrowedBuf, BorrowedCursor, IoSlice, IoSliceMut}; diff --git a/sgx_tstd/src/sys/os.rs b/sgx_tstd/src/sys/os.rs index ee8d247f7..30452cbc4 100644 --- a/sgx_tstd/src/sys/os.rs +++ b/sgx_tstd/src/sys/os.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::os::unix::prelude::*; diff --git a/sgx_tstd/src/sys/os_str.rs b/sgx_tstd/src/sys/os_str.rs index 1ca471d29..453879e08 100644 --- a/sgx_tstd/src/sys/os_str.rs +++ b/sgx_tstd/src/sys/os_str.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! The underlying OsString/OsStr implementation on Unix and many other //! systems: just a `Vec`/`[u8]`. diff --git a/sgx_tstd/src/sys/os_str/tests.rs b/sgx_tstd/src/sys/os_str/tests.rs index 4daa30314..5c06700e9 100644 --- a/sgx_tstd/src/sys/os_str/tests.rs +++ b/sgx_tstd/src/sys/os_str/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_tstd/src/sys/path.rs b/sgx_tstd/src/sys/path.rs index ccc852ceb..1ceb5a665 100644 --- a/sgx_tstd/src/sys/path.rs +++ b/sgx_tstd/src/sys/path.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ffi::OsStr; use crate::io; diff --git a/sgx_tstd/src/sys/personality/dwarf/eh.rs b/sgx_tstd/src/sys/personality/dwarf/eh.rs index e5c24d90b..36a50f72f 100644 --- a/sgx_tstd/src/sys/personality/dwarf/eh.rs +++ b/sgx_tstd/src/sys/personality/dwarf/eh.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Parsing of GCC-style Language-Specific Data Area (LSDA) //! For details see: diff --git a/sgx_tstd/src/sys/personality/dwarf/mod.rs b/sgx_tstd/src/sys/personality/dwarf/mod.rs index 8cdd26ac9..c60e7e69c 100644 --- a/sgx_tstd/src/sys/personality/dwarf/mod.rs +++ b/sgx_tstd/src/sys/personality/dwarf/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Utilities for parsing DWARF-encoded data streams. //! See , diff --git a/sgx_tstd/src/sys/personality/dwarf/tests.rs b/sgx_tstd/src/sys/personality/dwarf/tests.rs index 78e5d0ba3..e7dfa8885 100644 --- a/sgx_tstd/src/sys/personality/dwarf/tests.rs +++ b/sgx_tstd/src/sys/personality/dwarf/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_tstd/src/sys/personality/gcc.rs b/sgx_tstd/src/sys/personality/gcc.rs index 1b526a668..9dcb401f1 100644 --- a/sgx_tstd/src/sys/personality/gcc.rs +++ b/sgx_tstd/src/sys/personality/gcc.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Implementation of panics backed by libgcc/libunwind (in some form). //! diff --git a/sgx_tstd/src/sys/personality/mod.rs b/sgx_tstd/src/sys/personality/mod.rs index 04c836c00..f935e4e21 100644 --- a/sgx_tstd/src/sys/personality/mod.rs +++ b/sgx_tstd/src/sys/personality/mod.rs @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + //! This module contains the implementation of the `eh_personality` lang item. //! //! The actual implementation is heavily dependent on the target since Rust @@ -9,6 +26,5 @@ //! //! Additionally, ARM EHABI uses the personality function when generating //! backtraces. - mod dwarf; mod gcc; diff --git a/sgx_tstd/src/sys/pipe.rs b/sgx_tstd/src/sys/pipe.rs index 066bc40e8..fa0fae426 100644 --- a/sgx_tstd/src/sys/pipe.rs +++ b/sgx_tstd/src/sys/pipe.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; use crate::mem; diff --git a/sgx_tstd/src/sys/process.rs b/sgx_tstd/src/sys/process.rs index 333c34096..c5fb4a86a 100644 --- a/sgx_tstd/src/sys/process.rs +++ b/sgx_tstd/src/sys/process.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[path = "unsupported/process.rs"] mod process_inner; diff --git a/sgx_tstd/src/sys/rand.rs b/sgx_tstd/src/sys/rand.rs index 43b91a041..d47c28c5b 100644 --- a/sgx_tstd/src/sys/rand.rs +++ b/sgx_tstd/src/sys/rand.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub fn hashmap_random_keys() -> (u64, u64) { const KEY_LEN: usize = core::mem::size_of::(); diff --git a/sgx_tstd/src/sys/stdio.rs b/sgx_tstd/src/sys/stdio.rs index f6862670a..88cff4771 100644 --- a/sgx_tstd/src/sys/stdio.rs +++ b/sgx_tstd/src/sys/stdio.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; use crate::mem::ManuallyDrop; diff --git a/sgx_tstd/src/sys/thread.rs b/sgx_tstd/src/sys/thread.rs index f7b85c8c1..92465ed9e 100644 --- a/sgx_tstd/src/sys/thread.rs +++ b/sgx_tstd/src/sys/thread.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::cmp; use crate::ffi::CStr; diff --git a/sgx_tstd/src/sys/thread_local_dtor.rs b/sgx_tstd/src/sys/thread_local_dtor.rs index 6972f7b79..c36764d3c 100644 --- a/sgx_tstd/src/sys/thread_local_dtor.rs +++ b/sgx_tstd/src/sys/thread_local_dtor.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Provides thread-local destructors without an associated "key", which //! can be more efficient. diff --git a/sgx_tstd/src/sys/thread_local_key.rs b/sgx_tstd/src/sys/thread_local_key.rs index 871b766da..5ee9fc022 100644 --- a/sgx_tstd/src/sys/thread_local_key.rs +++ b/sgx_tstd/src/sys/thread_local_key.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ptr; diff --git a/sgx_tstd/src/sys/time.rs b/sgx_tstd/src/sys/time.rs index bdf8dea3e..bd6c6a38f 100644 --- a/sgx_tstd/src/sys/time.rs +++ b/sgx_tstd/src/sys/time.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::fmt; use crate::time::Duration; diff --git a/sgx_tstd/src/sys/unsupported/common.rs b/sgx_tstd/src/sys/unsupported/common.rs index 43b5d169c..3789ff0a7 100644 --- a/sgx_tstd/src/sys/unsupported/common.rs +++ b/sgx_tstd/src/sys/unsupported/common.rs @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT 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 crate::io as std_io; use sgx_trts::error::abort; diff --git a/sgx_tstd/src/sys/unsupported/mod.rs b/sgx_tstd/src/sys/unsupported/mod.rs index 876aaf0b7..1db7b45d7 100644 --- a/sgx_tstd/src/sys/unsupported/mod.rs +++ b/sgx_tstd/src/sys/unsupported/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub mod pipe; diff --git a/sgx_tstd/src/sys/unsupported/pipe.rs b/sgx_tstd/src/sys/unsupported/pipe.rs index 049963aed..eda55a4d6 100644 --- a/sgx_tstd/src/sys/unsupported/pipe.rs +++ b/sgx_tstd/src/sys/unsupported/pipe.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; diff --git a/sgx_tstd/src/sys/unsupported/process.rs b/sgx_tstd/src/sys/unsupported/process.rs index f390bdd11..c2ff01b9b 100644 --- a/sgx_tstd/src/sys/unsupported/process.rs +++ b/sgx_tstd/src/sys/unsupported/process.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::convert::{TryFrom, TryInto}; use crate::ffi::OsStr; diff --git a/sgx_tstd/src/sys_common/at_exit_imp.rs b/sgx_tstd/src/sys_common/at_exit_imp.rs index 607e85f77..b2fe8b64f 100644 --- a/sgx_tstd/src/sys_common/at_exit_imp.rs +++ b/sgx_tstd/src/sys_common/at_exit_imp.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Implementation of running at_exit routines //! diff --git a/sgx_tstd/src/sys_common/backtrace.rs b/sgx_tstd/src/sys_common/backtrace.rs index fffdfa142..769191a87 100644 --- a/sgx_tstd/src/sys_common/backtrace.rs +++ b/sgx_tstd/src/sys_common/backtrace.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. /// Common code for printing the backtrace in the same way across the different /// supported platforms. diff --git a/sgx_tstd/src/sys_common/condvar.rs b/sgx_tstd/src/sys_common/condvar.rs index 6b788f6d4..e75808a2e 100644 --- a/sgx_tstd/src/sys_common/condvar.rs +++ b/sgx_tstd/src/sys_common/condvar.rs @@ -13,6 +13,6 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use sgx_sync::Condvar; diff --git a/sgx_tstd/src/sys_common/fs.rs b/sgx_tstd/src/sys_common/fs.rs index e006f9aa5..f6c1e7972 100644 --- a/sgx_tstd/src/sys_common/fs.rs +++ b/sgx_tstd/src/sys_common/fs.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::fs; use crate::io::{self, Error, ErrorKind}; diff --git a/sgx_tstd/src/sys_common/gnu/libbacktrace.rs b/sgx_tstd/src/sys_common/gnu/libbacktrace.rs index c13310cba..0a7d363b2 100644 --- a/sgx_tstd/src/sys_common/gnu/libbacktrace.rs +++ b/sgx_tstd/src/sys_common/gnu/libbacktrace.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::marker; use crate::mem; diff --git a/sgx_tstd/src/sys_common/gnu/mod.rs b/sgx_tstd/src/sys_common/gnu/mod.rs index 67985f43f..3530762e0 100644 --- a/sgx_tstd/src/sys_common/gnu/mod.rs +++ b/sgx_tstd/src/sys_common/gnu/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ffi::c_void; use crate::fmt; diff --git a/sgx_tstd/src/sys_common/io.rs b/sgx_tstd/src/sys_common/io.rs index c0889a3e6..8524be80c 100644 --- a/sgx_tstd/src/sys_common/io.rs +++ b/sgx_tstd/src/sys_common/io.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub const DEFAULT_BUF_SIZE: usize = 8 * 1024; diff --git a/sgx_tstd/src/sys_common/lazy_box.rs b/sgx_tstd/src/sys_common/lazy_box.rs index 326a59547..4d27e6cdf 100644 --- a/sgx_tstd/src/sys_common/lazy_box.rs +++ b/sgx_tstd/src/sys_common/lazy_box.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(dead_code)] // Only used on some platforms. diff --git a/sgx_tstd/src/sys_common/memchr.rs b/sgx_tstd/src/sys_common/memchr.rs index de5e2e265..7e5b9c4a4 100644 --- a/sgx_tstd/src/sys_common/memchr.rs +++ b/sgx_tstd/src/sys_common/memchr.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::sys::memchr as sys; diff --git a/sgx_tstd/src/sys_common/mod.rs b/sgx_tstd/src/sys_common/mod.rs index a8dda5f27..b12ad0569 100644 --- a/sgx_tstd/src/sys_common/mod.rs +++ b/sgx_tstd/src/sys_common/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Platform-independent platform abstraction //! diff --git a/sgx_tstd/src/sys_common/mutex.rs b/sgx_tstd/src/sys_common/mutex.rs index 651c72b03..61b28b804 100644 --- a/sgx_tstd/src/sys_common/mutex.rs +++ b/sgx_tstd/src/sys_common/mutex.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[allow(unused_imports)] pub use sgx_sync::{StaticMutex, StaticMutexGuard}; diff --git a/sgx_tstd/src/sys_common/net.rs b/sgx_tstd/src/sys_common/net.rs index 186618fc2..d4142b116 100644 --- a/sgx_tstd/src/sys_common/net.rs +++ b/sgx_tstd/src/sys_common/net.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[cfg(feature = "unit_test")] mod tests; diff --git a/sgx_tstd/src/sys_common/net/tests.rs b/sgx_tstd/src/sys_common/net/tests.rs index 4aead0574..1b7bdb6d3 100644 --- a/sgx_tstd/src/sys_common/net/tests.rs +++ b/sgx_tstd/src/sys_common/net/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use crate::collections::HashMap; diff --git a/sgx_tstd/src/sys_common/once/futex.rs b/sgx_tstd/src/sys_common/once/futex.rs index 69303081b..44448b358 100644 --- a/sgx_tstd/src/sys_common/once/futex.rs +++ b/sgx_tstd/src/sys_common/once/futex.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::cell::Cell; use crate::sync as public; diff --git a/sgx_tstd/src/sys_common/once/mod.rs b/sgx_tstd/src/sys_common/once/mod.rs index 53992389e..87309d0c8 100644 --- a/sgx_tstd/src/sys_common/once/mod.rs +++ b/sgx_tstd/src/sys_common/once/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. // A "once" is a relatively simple primitive, and it's also typically provided // by the OS as well (see `pthread_once` or `InitOnceExecuteOnce`). The OS diff --git a/sgx_tstd/src/sys_common/once/queue.rs b/sgx_tstd/src/sys_common/once/queue.rs index a4fed8c52..699c7df67 100644 --- a/sgx_tstd/src/sys_common/once/queue.rs +++ b/sgx_tstd/src/sys_common/once/queue.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. // Each `Once` has one word of atomic state, and this state is CAS'd on to // determine what to do. There are four possible state of a `Once`: diff --git a/sgx_tstd/src/sys_common/process.rs b/sgx_tstd/src/sys_common/process.rs index e60a862fb..cdc79cd3e 100644 --- a/sgx_tstd/src/sys_common/process.rs +++ b/sgx_tstd/src/sys_common/process.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(dead_code)] diff --git a/sgx_tstd/src/sys_common/remutex.rs b/sgx_tstd/src/sys_common/remutex.rs index e081652c1..35097e375 100644 --- a/sgx_tstd/src/sys_common/remutex.rs +++ b/sgx_tstd/src/sys_common/remutex.rs @@ -13,6 +13,6 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use sgx_sync::{ReentrantMutex, ReentrantMutexGuard}; diff --git a/sgx_tstd/src/sys_common/rwlock.rs b/sgx_tstd/src/sys_common/rwlock.rs index bdd698b94..8c3389bef 100644 --- a/sgx_tstd/src/sys_common/rwlock.rs +++ b/sgx_tstd/src/sys_common/rwlock.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[allow(unused_imports)] pub use sgx_sync::{StaticRwLock, StaticRwLockReadGuard, StaticRwLockWriteGuard}; diff --git a/sgx_tstd/src/sys_common/tests.rs b/sgx_tstd/src/sys_common/tests.rs index d97e08a9b..fbea636a3 100644 --- a/sgx_tstd/src/sys_common/tests.rs +++ b/sgx_tstd/src/sys_common/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::mul_div_u64; diff --git a/sgx_tstd/src/sys_common/thread.rs b/sgx_tstd/src/sys_common/thread.rs index 46950e2d4..b248758bc 100644 --- a/sgx_tstd/src/sys_common/thread.rs +++ b/sgx_tstd/src/sys_common/thread.rs @@ -13,4 +13,4 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. diff --git a/sgx_tstd/src/sys_common/thread_info.rs b/sgx_tstd/src/sys_common/thread_info.rs index 7ff17de67..5c0c3c498 100644 --- a/sgx_tstd/src/sys_common/thread_info.rs +++ b/sgx_tstd/src/sys_common/thread_info.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::cell::OnceCell; use crate::thread::Thread; diff --git a/sgx_tstd/src/sys_common/thread_local_dtor.rs b/sgx_tstd/src/sys_common/thread_local_dtor.rs index 11d8caa7e..7191d9f58 100644 --- a/sgx_tstd/src/sys_common/thread_local_dtor.rs +++ b/sgx_tstd/src/sys_common/thread_local_dtor.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Thread-local destructor //! diff --git a/sgx_tstd/src/sys_common/thread_local_key.rs b/sgx_tstd/src/sys_common/thread_local_key.rs index 1a071f8ec..ea261800d 100644 --- a/sgx_tstd/src/sys_common/thread_local_key.rs +++ b/sgx_tstd/src/sys_common/thread_local_key.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! OS-based thread local storage //! diff --git a/sgx_tstd/src/sys_common/thread_local_key/tests.rs b/sgx_tstd/src/sys_common/thread_local_key/tests.rs index 38abaf693..03db39da6 100644 --- a/sgx_tstd/src/sys_common/thread_local_key/tests.rs +++ b/sgx_tstd/src/sys_common/thread_local_key/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::{Key, StaticKey}; use core::ptr; diff --git a/sgx_tstd/src/sys_common/thread_parking/futex.rs b/sgx_tstd/src/sys_common/thread_parking/futex.rs index b887af643..c50aca14f 100644 --- a/sgx_tstd/src/sys_common/thread_parking/futex.rs +++ b/sgx_tstd/src/sys_common/thread_parking/futex.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::pin::Pin; use crate::sync::atomic::AtomicU32; diff --git a/sgx_tstd/src/sys_common/thread_parking/generic.rs b/sgx_tstd/src/sys_common/thread_parking/generic.rs index f8145ac47..a3b15f180 100644 --- a/sgx_tstd/src/sys_common/thread_parking/generic.rs +++ b/sgx_tstd/src/sys_common/thread_parking/generic.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Parker implementation based on a Mutex and Condvar. diff --git a/sgx_tstd/src/sys_common/thread_parking/mod.rs b/sgx_tstd/src/sys_common/thread_parking/mod.rs index e910b3d98..13a94b3fa 100644 --- a/sgx_tstd/src/sys_common/thread_parking/mod.rs +++ b/sgx_tstd/src/sys_common/thread_parking/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. mod futex; pub use futex::Parker; diff --git a/sgx_tstd/src/sys_common/wstr.rs b/sgx_tstd/src/sys_common/wstr.rs index 52f681f32..66c12cc8e 100644 --- a/sgx_tstd/src/sys_common/wstr.rs +++ b/sgx_tstd/src/sys_common/wstr.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! This module contains constructs to work with 16-bit characters (UCS-2 or UTF-16) #![allow(dead_code)] diff --git a/sgx_tstd/src/sys_common/wtf8.rs b/sgx_tstd/src/sys_common/wtf8.rs index a7ab1ba6f..aaaa70ad8 100644 --- a/sgx_tstd/src/sys_common/wtf8.rs +++ b/sgx_tstd/src/sys_common/wtf8.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Implementation of [the WTF-8 encoding](https://simonsapin.github.io/wtf-8/). //! diff --git a/sgx_tstd/src/sys_common/wtf8/tests.rs b/sgx_tstd/src/sys_common/wtf8/tests.rs index 7163439fb..0fa840915 100644 --- a/sgx_tstd/src/sys_common/wtf8/tests.rs +++ b/sgx_tstd/src/sys_common/wtf8/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use crate::borrow::Cow; diff --git a/sgx_tstd/src/thread/local.rs b/sgx_tstd/src/thread/local.rs index dde3f9967..0b1c9ea88 100644 --- a/sgx_tstd/src/thread/local.rs +++ b/sgx_tstd/src/thread/local.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Thread local storage diff --git a/sgx_tstd/src/thread/local/dynamic_tests.rs b/sgx_tstd/src/thread/local/dynamic_tests.rs index 47df7d4fa..61461e9f6 100644 --- a/sgx_tstd/src/thread/local/dynamic_tests.rs +++ b/sgx_tstd/src/thread/local/dynamic_tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::cell::RefCell; use crate::collections::HashMap; diff --git a/sgx_tstd/src/thread/local/tests.rs b/sgx_tstd/src/thread/local/tests.rs index 5d08d053f..40e02932c 100644 --- a/sgx_tstd/src/thread/local/tests.rs +++ b/sgx_tstd/src/thread/local/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::cell::{Cell, UnsafeCell}; use crate::sync::atomic::{AtomicU8, Ordering}; diff --git a/sgx_tstd/src/thread/mod.rs b/sgx_tstd/src/thread/mod.rs index 47babe3d0..bc4da3027 100644 --- a/sgx_tstd/src/thread/mod.rs +++ b/sgx_tstd/src/thread/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Native threads. //! diff --git a/sgx_tstd/src/thread/scoped.rs b/sgx_tstd/src/thread/scoped.rs index dc37a8103..eb3896cf8 100644 --- a/sgx_tstd/src/thread/scoped.rs +++ b/sgx_tstd/src/thread/scoped.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::{current, park, Builder, JoinInner, Result, Thread}; use crate::fmt; diff --git a/sgx_tstd/src/thread/tests.rs b/sgx_tstd/src/thread/tests.rs index 8daa20f5c..ed230f8a0 100644 --- a/sgx_tstd/src/thread/tests.rs +++ b/sgx_tstd/src/thread/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(clippy::redundant_clone)] #![allow(clippy::redundant_closure)] diff --git a/sgx_tstd/src/time.rs b/sgx_tstd/src/time.rs index a09b50240..84f2efb37 100644 --- a/sgx_tstd/src/time.rs +++ b/sgx_tstd/src/time.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Temporal quantification. //! diff --git a/sgx_tstd/src/time/tests.rs b/sgx_tstd/src/time/tests.rs index 31fc23917..569943036 100644 --- a/sgx_tstd/src/time/tests.rs +++ b/sgx_tstd/src/time/tests.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::{Duration, Instant, SystemTime, UNIX_EPOCH}; use core::fmt::Debug; diff --git a/sgx_tstd/src/untrusted/fs.rs b/sgx_tstd/src/untrusted/fs.rs index 269ecac8e..f5ee2564e 100644 --- a/sgx_tstd/src/untrusted/fs.rs +++ b/sgx_tstd/src/untrusted/fs.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Filesystem manipulation operations. pub use crate::fs::*; diff --git a/sgx_tstd/src/untrusted/mod.rs b/sgx_tstd/src/untrusted/mod.rs index 7b77874e6..0d6d6b853 100644 --- a/sgx_tstd/src/untrusted/mod.rs +++ b/sgx_tstd/src/untrusted/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub mod fs; pub mod path; diff --git a/sgx_tstd/src/untrusted/path.rs b/sgx_tstd/src/untrusted/path.rs index fb6144fef..e0b04cafc 100644 --- a/sgx_tstd/src/untrusted/path.rs +++ b/sgx_tstd/src/untrusted/path.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::fs; use crate::io; diff --git a/sgx_tstd/src/untrusted/time.rs b/sgx_tstd/src/untrusted/time.rs index 02db95a71..f7d9ca8fa 100644 --- a/sgx_tstd/src/untrusted/time.rs +++ b/sgx_tstd/src/untrusted/time.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::time::{Instant, SystemTime, SystemTimeError, Duration}; diff --git a/sgx_types/build.rs b/sgx_types/build.rs index f539790a0..f32117995 100644 --- a/sgx_types/build.rs +++ b/sgx_types/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/sgx_types/src/cpu_features.rs b/sgx_types/src/cpu_features.rs index 8ca608115..e261f4232 100644 --- a/sgx_types/src/cpu_features.rs +++ b/sgx_types/src/cpu_features.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. // // The processor is a generic IA32 CPU diff --git a/sgx_types/src/error/errno.rs b/sgx_types/src/error/errno.rs index ffdd1e074..675aeb14d 100644 --- a/sgx_types/src/error/errno.rs +++ b/sgx_types/src/error/errno.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub const EPERM: i32 = 1; pub const ENOENT: i32 = 2; diff --git a/sgx_types/src/error/mod.rs b/sgx_types/src/error/mod.rs index 02948ec37..e262670b7 100644 --- a/sgx_types/src/error/mod.rs +++ b/sgx_types/src/error/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::error::Error; use core::fmt; diff --git a/sgx_types/src/function.rs b/sgx_types/src/function.rs index bd91e3ab6..13906255d 100644 --- a/sgx_types/src/function.rs +++ b/sgx_types/src/function.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::error::{PceError, QcnlError, Quote3Error, SgxStatus, TdxAttestError}; use crate::metadata::MetaData; diff --git a/sgx_types/src/lib.rs b/sgx_types/src/lib.rs index b94da4f94..b7cff250a 100644 --- a/sgx_types/src/lib.rs +++ b/sgx_types/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![feature(min_specialization)] diff --git a/sgx_types/src/macros.rs b/sgx_types/src/macros.rs index caf9572d8..f7aadaf2e 100644 --- a/sgx_types/src/macros.rs +++ b/sgx_types/src/macros.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #[macro_export] macro_rules! cfg_if { diff --git a/sgx_types/src/marker.rs b/sgx_types/src/marker.rs index 171f15d0d..b493e998e 100644 --- a/sgx_types/src/marker.rs +++ b/sgx_types/src/marker.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use core::cell::{Cell, RefCell, UnsafeCell}; use core::sync::atomic::{ diff --git a/sgx_types/src/memeq.rs b/sgx_types/src/memeq.rs index 9e6e26c72..774c5ec4b 100644 --- a/sgx_types/src/memeq.rs +++ b/sgx_types/src/memeq.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. //! Comparing buffer contents in constant time. //! diff --git a/sgx_types/src/metadata.rs b/sgx_types/src/metadata.rs index 4a25c973d..3fd415ce0 100644 --- a/sgx_types/src/metadata.rs +++ b/sgx_types/src/metadata.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::types::{Attributes, IsvExtProdId, IsvFamilyId, Measurement, MiscSelect}; diff --git a/sgx_types/src/types/crypto.rs b/sgx_types/src/types/crypto.rs index 7ce9ea462..90c058e56 100644 --- a/sgx_types/src/types/crypto.rs +++ b/sgx_types/src/types/crypto.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_types/src/types/dcap.rs b/sgx_types/src/types/dcap.rs index 5b68f2b54..25c858ecc 100644 --- a/sgx_types/src/types/dcap.rs +++ b/sgx_types/src/types/dcap.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_types/src/types/dh.rs b/sgx_types/src/types/dh.rs index 720d870eb..930a15f15 100644 --- a/sgx_types/src/types/dh.rs +++ b/sgx_types/src/types/dh.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_types/src/types/key_exchange.rs b/sgx_types/src/types/key_exchange.rs index afea767a8..dde09abda 100644 --- a/sgx_types/src/types/key_exchange.rs +++ b/sgx_types/src/types/key_exchange.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_types/src/types/mod.rs b/sgx_types/src/types/mod.rs index b6fb85504..9332a6447 100644 --- a/sgx_types/src/types/mod.rs +++ b/sgx_types/src/types/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::marker::BytewiseEquality; use core::convert::{From, TryInto}; diff --git a/sgx_types/src/types/quote.rs b/sgx_types/src/types/quote.rs index 394a0476a..56d4e84e1 100644 --- a/sgx_types/src/types/quote.rs +++ b/sgx_types/src/types/quote.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_types/src/types/ra.rs b/sgx_types/src/types/ra.rs index 6a207ba31..033d18527 100644 --- a/sgx_types/src/types/ra.rs +++ b/sgx_types/src/types/ra.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; use core::mem; diff --git a/sgx_types/src/types/raw.rs b/sgx_types/src/types/raw.rs index 4416d97fe..6aed172d1 100644 --- a/sgx_types/src/types/raw.rs +++ b/sgx_types/src/types/raw.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub use core::ffi::c_void; diff --git a/sgx_types/src/types/report2.rs b/sgx_types/src/types/report2.rs index e27af19ff..f52dd1752 100644 --- a/sgx_types/src/types/report2.rs +++ b/sgx_types/src/types/report2.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_types/src/types/seal.rs b/sgx_types/src/types/seal.rs index 7410528cc..c98f38596 100644 --- a/sgx_types/src/types/seal.rs +++ b/sgx_types/src/types/seal.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_types/src/types/switchless.rs b/sgx_types/src/types/switchless.rs index 55358b7b2..60c346d83 100644 --- a/sgx_types/src/types/switchless.rs +++ b/sgx_types/src/types/switchless.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_types/src/types/tdx.rs b/sgx_types/src/types/tdx.rs index d68dff8bd..fb2504ea5 100644 --- a/sgx_types/src/types/tdx.rs +++ b/sgx_types/src/types/tdx.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_types/src/types/urts.rs b/sgx_types/src/types/urts.rs index 6e5fe2e7d..15da5e185 100644 --- a/sgx_types/src/types/urts.rs +++ b/sgx_types/src/types/urts.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use super::*; diff --git a/sgx_unwind/build.rs b/sgx_unwind/build.rs index ab07c06e2..368d19c5e 100644 --- a/sgx_unwind/build.rs +++ b/sgx_unwind/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate sgx_build_helper as build_helper; diff --git a/sgx_unwind/src/lib.rs b/sgx_unwind/src/lib.rs index 92b3884ef..6ff513429 100644 --- a/sgx_unwind/src/lib.rs +++ b/sgx_unwind/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] diff --git a/sgx_unwind/src/libunwind.rs b/sgx_unwind/src/libunwind.rs index e2f43bbc1..db175c5f0 100644 --- a/sgx_unwind/src/libunwind.rs +++ b/sgx_unwind/src/libunwind.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(nonstandard_style)] diff --git a/sgx_unwind/src/macros.rs b/sgx_unwind/src/macros.rs index ae6fa6e0e..8387e6080 100644 --- a/sgx_unwind/src/macros.rs +++ b/sgx_unwind/src/macros.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. /// A macro for defining `#[cfg]` if-else statements. /// diff --git a/sgx_urts/build.rs b/sgx_urts/build.rs index f539790a0..f32117995 100644 --- a/sgx_urts/build.rs +++ b/sgx_urts/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/sgx_urts/src/capi.rs b/sgx_urts/src/capi.rs index 37204903b..9e023316c 100644 --- a/sgx_urts/src/capi.rs +++ b/sgx_urts/src/capi.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::enclave::{ExtFeatureBits, ExtFeatures, SgxEnclave}; use crate::enclave::{KSS_BIT_IDX, LAST_BIT_IDX, SWITCHLESS_BIT_IDX}; diff --git a/sgx_urts/src/enclave/init.rs b/sgx_urts/src/enclave/init.rs index 8ff080894..94e7762b7 100644 --- a/sgx_urts/src/enclave/init.rs +++ b/sgx_urts/src/enclave/init.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(dead_code)] diff --git a/sgx_urts/src/enclave/mod.rs b/sgx_urts/src/enclave/mod.rs index 271a8a17f..b9a014585 100644 --- a/sgx_urts/src/enclave/mod.rs +++ b/sgx_urts/src/enclave/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use sgx_types::error::{SgxResult, SgxStatus}; use sgx_types::function::*; diff --git a/sgx_urts/src/enclave/uninit.rs b/sgx_urts/src/enclave/uninit.rs index 4d0ea4ffa..3e82ba44c 100644 --- a/sgx_urts/src/enclave/uninit.rs +++ b/sgx_urts/src/enclave/uninit.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::enclave::SgxEnclave; use sgx_types::error::SgxResult; diff --git a/sgx_urts/src/lib.rs b/sgx_urts/src/lib.rs index 4ccbbc900..c6d8533be 100644 --- a/sgx_urts/src/lib.rs +++ b/sgx_urts/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![feature(allocator_api)] #![allow(clippy::missing_safety_doc)] diff --git a/sgx_urts/src/msbuf.rs b/sgx_urts/src/msbuf.rs index 05be5a938..4cd2905a5 100644 --- a/sgx_urts/src/msbuf.rs +++ b/sgx_urts/src/msbuf.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use sgx_types::function::{ sgx_ecall_ms_buffer_alloc_aligned, sgx_ecall_ms_buffer_free, sgx_ecall_ms_buffer_remain_size, diff --git a/sgx_urts/src/ocall/asyncio.rs b/sgx_urts/src/ocall/asyncio.rs index 979c5011b..20a332929 100644 --- a/sgx_urts/src/ocall/asyncio.rs +++ b/sgx_urts/src/ocall/asyncio.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ocall::util::*; use libc::{self, c_int, c_uint, epoll_event, nfds_t, pollfd}; diff --git a/sgx_urts/src/ocall/env.rs b/sgx_urts/src/ocall/env.rs index fde0eb895..0d09d2b9b 100644 --- a/sgx_urts/src/ocall/env.rs +++ b/sgx_urts/src/ocall/env.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::enclave::{args, env}; use crate::ocall::util::*; diff --git a/sgx_urts/src/ocall/fd.rs b/sgx_urts/src/ocall/fd.rs index 32d141a03..9021cd7a8 100644 --- a/sgx_urts/src/ocall/fd.rs +++ b/sgx_urts/src/ocall/fd.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ocall::util::*; use libc::{self, c_int, c_uint, c_ulong, c_void, off64_t, off_t, size_t, ssize_t, timespec}; diff --git a/sgx_urts/src/ocall/file.rs b/sgx_urts/src/ocall/file.rs index cd0529e11..f773907fb 100644 --- a/sgx_urts/src/ocall/file.rs +++ b/sgx_urts/src/ocall/file.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ocall::util::*; use libc::{ diff --git a/sgx_urts/src/ocall/mem.rs b/sgx_urts/src/ocall/mem.rs index 854e3601b..c32936fb1 100644 --- a/sgx_urts/src/ocall/mem.rs +++ b/sgx_urts/src/ocall/mem.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ocall::util::*; use libc::{self, c_int, c_void, off_t, size_t}; diff --git a/sgx_urts/src/ocall/mod.rs b/sgx_urts/src/ocall/mod.rs index 91c2e9e44..711fdbd4a 100644 --- a/sgx_urts/src/ocall/mod.rs +++ b/sgx_urts/src/ocall/mod.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. pub mod asyncio; pub mod env; diff --git a/sgx_urts/src/ocall/msbuf.rs b/sgx_urts/src/ocall/msbuf.rs index f7c38d840..53575b44d 100644 --- a/sgx_urts/src/ocall/msbuf.rs +++ b/sgx_urts/src/ocall/msbuf.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ocall::util::*; use libc::{c_int, c_void, size_t, ssize_t}; diff --git a/sgx_urts/src/ocall/net.rs b/sgx_urts/src/ocall/net.rs index e0b596345..3fa00feb3 100644 --- a/sgx_urts/src/ocall/net.rs +++ b/sgx_urts/src/ocall/net.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ocall::util::*; use libc::{self, addrinfo, c_char, c_int, c_uint, size_t, sockaddr_storage}; diff --git a/sgx_urts/src/ocall/pipe.rs b/sgx_urts/src/ocall/pipe.rs index 56af969e6..fb1f45109 100644 --- a/sgx_urts/src/ocall/pipe.rs +++ b/sgx_urts/src/ocall/pipe.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ocall::util::*; use libc::{self, c_int}; diff --git a/sgx_urts/src/ocall/process.rs b/sgx_urts/src/ocall/process.rs index 81e0e0b4c..653980150 100644 --- a/sgx_urts/src/ocall/process.rs +++ b/sgx_urts/src/ocall/process.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use libc::{self, pid_t}; diff --git a/sgx_urts/src/ocall/sgxfile.rs b/sgx_urts/src/ocall/sgxfile.rs index e602f27b9..e36c3a44a 100644 --- a/sgx_urts/src/ocall/sgxfile.rs +++ b/sgx_urts/src/ocall/sgxfile.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![allow(deprecated)] diff --git a/sgx_urts/src/ocall/socket.rs b/sgx_urts/src/ocall/socket.rs index d726b00b5..991505c97 100644 --- a/sgx_urts/src/ocall/socket.rs +++ b/sgx_urts/src/ocall/socket.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ocall::util::*; use libc::{self, c_int, c_void, iovec, msghdr, size_t, sockaddr, socklen_t, ssize_t}; diff --git a/sgx_urts/src/ocall/sync.rs b/sgx_urts/src/ocall/sync.rs index 5942868ef..d8e076288 100644 --- a/sgx_urts/src/ocall/sync.rs +++ b/sgx_urts/src/ocall/sync.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ocall::util::*; use libc::{self, c_int, size_t, timespec}; diff --git a/sgx_urts/src/ocall/sys.rs b/sgx_urts/src/ocall/sys.rs index 51bbae8a8..bd2bd8010 100644 --- a/sgx_urts/src/ocall/sys.rs +++ b/sgx_urts/src/ocall/sys.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ocall::util::*; use libc::{self, c_int, c_long, c_ulong, cpu_set_t, pid_t, size_t}; diff --git a/sgx_urts/src/ocall/thread.rs b/sgx_urts/src/ocall/thread.rs index 86a9c1560..064eed4f1 100644 --- a/sgx_urts/src/ocall/thread.rs +++ b/sgx_urts/src/ocall/thread.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ocall::util::*; use libc::{self, c_int, timespec}; diff --git a/sgx_urts/src/ocall/time.rs b/sgx_urts/src/ocall/time.rs index b39464c6c..8feab7f38 100644 --- a/sgx_urts/src/ocall/time.rs +++ b/sgx_urts/src/ocall/time.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use crate::ocall::util::*; use libc::{self, c_int, clockid_t, timespec}; diff --git a/sgx_urts/src/ocall/util.rs b/sgx_urts/src/ocall/util.rs index 62575a80b..22acf3085 100644 --- a/sgx_urts/src/ocall/util.rs +++ b/sgx_urts/src/ocall/util.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use libc::c_int; diff --git a/tests/app/build.rs b/tests/app/build.rs index 23b8f5e70..935390b08 100644 --- a/tests/app/build.rs +++ b/tests/app/build.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. use std::env; diff --git a/tests/app/src/main.rs b/tests/app/src/main.rs index 333dde162..03d086b1a 100644 --- a/tests/app/src/main.rs +++ b/tests/app/src/main.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. extern crate raw_cpuid; extern crate sgx_types; diff --git a/tests/enclave/src/lib.rs b/tests/enclave/src/lib.rs index c3e9c4632..82503335f 100644 --- a/tests/enclave/src/lib.rs +++ b/tests/enclave/src/lib.rs @@ -13,7 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License.. +// under the License. #![no_std] #![allow(unused_imports)] From d20e6e651fa97353f1ba2d8067bcefb8b9b2f5ef Mon Sep 17 00:00:00 2001 From: Zhaofeng Chen Date: Sun, 20 Jul 2025 04:20:51 +0000 Subject: [PATCH 21/34] polish readme.md --- README.md | 82 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 02241021b..7d9a60f5a 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,63 @@ -# Teaclave SGX SDK v2.0 preview +# Teaclave SGX SDK -Teaclave SGX SDK v2.0 is a revamped version. It is much more developer friendly -compared to v1.1. +[![License](https://img.shields.io/badge/license-Apache-green.svg)](LICENSE) +[![Homepage](https://img.shields.io/badge/site-homepage-blue)](https://teaclave.apache.org/) -- supports `cargo build` + `no_std`, `xargo build` and `cargo-std-aware` mode. -- Tokio and Tonic is directly available to enclave programming without any change. -- Refactored Intel's SDK using Rust. Only a small portion of Intel's SDK is required. -- Improved testing framework. `sgx_tstd` is well tested now. -- No need to maintain 100+ 3rd party dependencies. Most dependencies are `use`-able without any change. +**Apache Teaclave SGX SDK** is a Rust SDK for developing Intel SGX applications. It enables developers to write secure, privacy-preserving applications using Intel Software Guard Extensions (SGX) technology with the safety and performance benefits of the Rust programming language. -## Build system +## Overview -We still maintain the legacy `no_std` cargo build support, and `xargo build` with a customized sysroot. v2.0 supports `cargo-std-aware` as well. +The Apache Teaclave SGX SDK provides a comprehensive development environment for building Intel SGX enclaves in Rust. The current version (v2.0) offers significant improvements over the [legacy v1.1](https://github.com/apache/incubator-teaclave-sgx-sdk/tree/master) , including: -To switch from these build modes, please specify -- `BUILD_STD=no` to use traditional `no_std` cargo build -- `BUILD_STD=cargo` (default setting) to use the new std aware cargo build -- `BUILD_STD=xargo` to use xargo build +- **Modern Build System**: Supports `cargo build` with `no_std`, `xargo build`, and `cargo-std-aware` modes +- **Rich Ecosystem**: Direct support for Tokio and Tonic in enclave programming without modifications +- **Lightweight Architecture**: Refactored Intel's SGX SDK using Rust, requiring only a minimal portion of Intel's original SDK +- **Robust Testing**: Comprehensive testing framework with well-tested `sgx_tstd` standard library +- **Simplified Dependencies**: Eliminates the need to maintain 100+ third-party dependencies; most Rust crates work without modifications +## Build System -## Samples +The SDK supports multiple build modes to accommodate different development preferences: -We are still working on porting all v1.1 samples to v2.0. Current available samples include: +- **`BUILD_STD=cargo`** (default): Uses the new std-aware cargo build system +- **`BUILD_STD=no`**: Traditional `no_std` cargo build for minimal footprint +- **`BUILD_STD=xargo`**: Uses xargo build with customized sysroot -- backtrace -- cov -- crypto -- hellworld -- httpreq -- hyper-rustls-https-server -- logger -- regex -- rpc (Tonic + Tokio) -- seal -- switchless -- zlib-lazy-static-sample +## Sample Applications + +The following sample applications demonstrate various SGX SDK capabilities: + +- **backtrace**: Stack trace functionality in SGX enclaves +- **cov**: Code coverage analysis tools +- **crypto**: Cryptographic operations within enclaves +- **helloworld**: Basic SGX enclave example +- **httpreq**: HTTP client functionality +- **hyper-rustls-https-server**: HTTPS server using Hyper and Rustls +- **logger**: Logging capabilities for SGX applications +- **regex**: Regular expression processing +- **rpc**: Remote procedure calls using Tonic and Tokio +- **seal**: Data sealing and unsealing operations +- **switchless**: Switchless call optimization +- **zlib-lazy-static-sample**: Compression with lazy static initialization + +*Note: Migration of additional v1.1 samples to v2.0 is ongoing.* + +## Getting Started + +For detailed installation instructions, development guides, and API documentation, please visit: + +- **Project Website**: [https://teaclave.apache.org/](https://teaclave.apache.org/) +- **Documentation**: [Teaclave SGX SDK Documentation](https://teaclave.apache.org/sgx-sdk-docs/) +- **API Reference**: [Teaclave SGX SDK API Reference](https://teaclave.apache.org/api-docs/sgx-sdk/) + +## Contributing + +Teaclave is developed in the open following [The Apache Way](https://www.apache.org/theapacheway/). We strive to maintain a project that is community-driven and inclusive. + +We welcome all forms of contributions. Please refer to our [Contributing Guide](https://teaclave.apache.org/contributing) for more information. A big thank-you to all our [contributors](https://teaclave.apache.org/contributors/)! + +## Community + +- 📬 Join our [mailing list](https://lists.apache.org/list.html?dev@teaclave.apache.org) +- 🐦 Follow us on [Twitter @ApacheTeaclave](https://twitter.com/ApacheTeaclave) +- 🌐 Learn more at [teaclave.apache.org/community](https://teaclave.apache.org/community/) \ No newline at end of file From a1e740c7d1b97dd49ebd5216d8711defe1823586 Mon Sep 17 00:00:00 2001 From: Zhaofeng Chen Date: Mon, 4 Aug 2025 07:34:21 +0000 Subject: [PATCH 22/34] doc: update branding name --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7d9a60f5a..57b3f2c91 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -# Teaclave SGX SDK +# Apache Teaclave™ (incubating) SGX SDK [![License](https://img.shields.io/badge/license-Apache-green.svg)](LICENSE) [![Homepage](https://img.shields.io/badge/site-homepage-blue)](https://teaclave.apache.org/) -**Apache Teaclave SGX SDK** is a Rust SDK for developing Intel SGX applications. It enables developers to write secure, privacy-preserving applications using Intel Software Guard Extensions (SGX) technology with the safety and performance benefits of the Rust programming language. +**Apache Teaclave™ (incubating) SGX SDK** is a Rust SDK for developing Intel SGX applications. It enables developers to write secure, privacy-preserving applications using Intel Software Guard Extensions (SGX) technology with the safety and performance benefits of the Rust programming language. ## Overview -The Apache Teaclave SGX SDK provides a comprehensive development environment for building Intel SGX enclaves in Rust. The current version (v2.0) offers significant improvements over the [legacy v1.1](https://github.com/apache/incubator-teaclave-sgx-sdk/tree/master) , including: +Apache Teaclave™ (incubating) SGX SDK provides a comprehensive development environment for building Intel SGX enclaves in Rust. The current version (v2.0) offers significant improvements over the [legacy v1.1](https://github.com/apache/incubator-teaclave-sgx-sdk/tree/master) , including: - **Modern Build System**: Supports `cargo build` with `no_std`, `xargo build`, and `cargo-std-aware` modes - **Rich Ecosystem**: Direct support for Tokio and Tonic in enclave programming without modifications @@ -52,7 +52,7 @@ For detailed installation instructions, development guides, and API documentatio ## Contributing -Teaclave is developed in the open following [The Apache Way](https://www.apache.org/theapacheway/). We strive to maintain a project that is community-driven and inclusive. +Apache Teaclave™ (incubating) is developed in the open following [The Apache Way](https://www.apache.org/theapacheway/). We strive to maintain a project that is community-driven and inclusive. We welcome all forms of contributions. Please refer to our [Contributing Guide](https://teaclave.apache.org/contributing) for more information. A big thank-you to all our [contributors](https://teaclave.apache.org/contributors/)! From 7036457878a9959d756348c27862bfc347cb538a Mon Sep 17 00:00:00 2001 From: Zhaofeng Chen Date: Wed, 3 Sep 2025 14:40:38 +0000 Subject: [PATCH 23/34] doc: update for graduation --- .asf.yaml | 2 +- DISCLAIMER | 8 -------- NOTICE | 2 +- README.md | 8 ++++---- 4 files changed, 6 insertions(+), 14 deletions(-) delete mode 100644 DISCLAIMER diff --git a/.asf.yaml b/.asf.yaml index 65c4fcb85..733817cf7 100644 --- a/.asf.yaml +++ b/.asf.yaml @@ -14,7 +14,7 @@ # limitations under the License. github: - description: "Apache Teaclave (incubating) SGX SDK helps developers to write Intel SGX applications in the Rust programming language, and also known as Rust SGX SDK." + description: "Apache Teaclave™ SGX SDK helps developers to write Intel SGX applications in the Rust programming language, and also known as Rust SGX SDK." homepage: https://teaclave.apache.org labels: - universal-secure-computing diff --git a/DISCLAIMER b/DISCLAIMER deleted file mode 100644 index f755dfd9f..000000000 --- a/DISCLAIMER +++ /dev/null @@ -1,8 +0,0 @@ -Apache Teaclave (incubating) is an effort undergoing incubation at The Apache -Software Foundation (ASF), sponsored by the Apache Incubator. -Incubation is required of all newly accepted projects until a further review -indicates that the infrastructure, communications, and decision making process -have stabilized in a manner consistent with other successful ASF projects. -While incubation status is not necessarily a reflection of the completeness or -stability of the code, it does indicate that the project has yet to be fully -endorsed by the ASF. \ No newline at end of file diff --git a/NOTICE b/NOTICE index 22629d1f2..9a7670227 100644 --- a/NOTICE +++ b/NOTICE @@ -1,4 +1,4 @@ -Apache Teaclave (incubating) +Apache Teaclave Copyright 2019-2021 The Apache Software Foundation This product includes software developed at diff --git a/README.md b/README.md index 57b3f2c91..fb1ae02ef 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -# Apache Teaclave™ (incubating) SGX SDK +# Apache Teaclave™ SGX SDK [![License](https://img.shields.io/badge/license-Apache-green.svg)](LICENSE) [![Homepage](https://img.shields.io/badge/site-homepage-blue)](https://teaclave.apache.org/) -**Apache Teaclave™ (incubating) SGX SDK** is a Rust SDK for developing Intel SGX applications. It enables developers to write secure, privacy-preserving applications using Intel Software Guard Extensions (SGX) technology with the safety and performance benefits of the Rust programming language. +**Apache Teaclave™ SGX SDK** is a Rust SDK for developing Intel SGX applications. It enables developers to write secure, privacy-preserving applications using Intel Software Guard Extensions (SGX) technology with the safety and performance benefits of the Rust programming language. ## Overview -Apache Teaclave™ (incubating) SGX SDK provides a comprehensive development environment for building Intel SGX enclaves in Rust. The current version (v2.0) offers significant improvements over the [legacy v1.1](https://github.com/apache/incubator-teaclave-sgx-sdk/tree/master) , including: +Apache Teaclave™ SGX SDK provides a comprehensive development environment for building Intel SGX enclaves in Rust. The current version (v2.0) offers significant improvements over the [legacy v1.1](https://github.com/apache/teaclave-sgx-sdk/tree/master) , including: - **Modern Build System**: Supports `cargo build` with `no_std`, `xargo build`, and `cargo-std-aware` modes - **Rich Ecosystem**: Direct support for Tokio and Tonic in enclave programming without modifications @@ -52,7 +52,7 @@ For detailed installation instructions, development guides, and API documentatio ## Contributing -Apache Teaclave™ (incubating) is developed in the open following [The Apache Way](https://www.apache.org/theapacheway/). We strive to maintain a project that is community-driven and inclusive. +Apache Teaclave™ is developed in the open following [The Apache Way](https://www.apache.org/theapacheway/). We strive to maintain a project that is community-driven and inclusive. We welcome all forms of contributions. Please refer to our [Contributing Guide](https://teaclave.apache.org/contributing) for more information. A big thank-you to all our [contributors](https://teaclave.apache.org/contributors/)! From 088e431ad6b6c32821862b9933a1a0a82081348f Mon Sep 17 00:00:00 2001 From: bfoing <40759640+bfoing@users.noreply.github.com> Date: Wed, 25 Feb 2026 11:29:30 +0000 Subject: [PATCH 24/34] Support Intel SGX SDK 2.27 Fix .niprod to .nipd section Increase METADATA_SIZE to 0x6000 Bump version to 2.27 --- sgx_trts/src/arch.rs | 2 +- sgx_trts/src/asm/metadata.S | 2 +- sgx_trts/src/version.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sgx_trts/src/arch.rs b/sgx_trts/src/arch.rs index d57aa1d06..ab4773335 100644 --- a/sgx_trts/src/arch.rs +++ b/sgx_trts/src/arch.rs @@ -54,7 +54,7 @@ macro_rules! trim_to_page { } #[cfg(not(feature = "use_sgx_sdk"))] -#[link_section = ".niprod"] +#[link_section = ".nipd"] #[no_mangle] pub static mut g_global_data: GlobalData = GlobalData { version: VERSION_UINT, diff --git a/sgx_trts/src/asm/metadata.S b/sgx_trts/src/asm/metadata.S index 1bcb1bce7..5debddce2 100644 --- a/sgx_trts/src/asm/metadata.S +++ b/sgx_trts/src/asm/metadata.S @@ -17,7 +17,7 @@ .file "metadata.S" -.equ METADATA_SIZE, 0x5000 +.equ METADATA_SIZE, 0x6000 .section ".note.sgxmeta", "", @note .p2align 2 /* section alignment */ diff --git a/sgx_trts/src/version.rs b/sgx_trts/src/version.rs index c9c9d719c..5b911094b 100644 --- a/sgx_trts/src/version.rs +++ b/sgx_trts/src/version.rs @@ -16,6 +16,6 @@ // under the License. pub const MAJOR_VERSION: usize = 2; -pub const MINOR_VERSION: usize = 21; +pub const MINOR_VERSION: usize = 27; pub const REVISION_VERSION: usize = 100; pub const VERSION_UINT: usize = (MAJOR_VERSION << 32) | (MINOR_VERSION << 16) | REVISION_VERSION; From 7e3d502f92c2457c3d9a79d764bc3b07c2ea4ad1 Mon Sep 17 00:00:00 2001 From: bfoing <40759640+bfoing@users.noreply.github.com> Date: Wed, 25 Feb 2026 11:33:45 +0000 Subject: [PATCH 25/34] Fix Rust 1.84 / LLVM 19 compatibility --- rustlib/x86_64-unknown-linux-sgx.json | 2 +- sgx_trts/src/asm/mod.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rustlib/x86_64-unknown-linux-sgx.json b/rustlib/x86_64-unknown-linux-sgx.json index ece4b8eef..4a19c7c74 100644 --- a/rustlib/x86_64-unknown-linux-sgx.json +++ b/rustlib/x86_64-unknown-linux-sgx.json @@ -2,7 +2,7 @@ "arch": "x86_64", "cpu": "x86-64", "crt-static-respected": true, - "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", "dynamic-linking": true, "env": "gnu", "executables": true, diff --git a/sgx_trts/src/asm/mod.rs b/sgx_trts/src/asm/mod.rs index accde68ed..b1592dbd1 100644 --- a/sgx_trts/src/asm/mod.rs +++ b/sgx_trts/src/asm/mod.rs @@ -65,7 +65,7 @@ global_asm!(include_str!("pic.S"), options(att_syntax)); const SYNTHETIC_STATE_SIZE: usize = 512 + 64; #[link_section = ".niprod"] #[no_mangle] -pub static mut SYNTHETIC_STATE: Align64<[u32; SYNTHETIC_STATE_SIZE / 4]> = Align64([ +pub static SYNTHETIC_STATE: Align64<[u32; SYNTHETIC_STATE_SIZE / 4]> = Align64([ 0x037F, 0, 0, 0, 0, 0, 0x1FBF, 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, 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, 0, 0, 0, @@ -75,7 +75,7 @@ pub static mut SYNTHETIC_STATE: Align64<[u32; SYNTHETIC_STATE_SIZE / 4]> = Align #[inline(always)] #[no_mangle] -pub unsafe extern "C" fn get_synthetic_state_ptr( -) -> &'static mut Align64<[u32; SYNTHETIC_STATE_SIZE / 4]> { - &mut SYNTHETIC_STATE +pub extern "C" fn get_synthetic_state_ptr( +) -> *const Align64<[u32; SYNTHETIC_STATE_SIZE / 4]> { + &SYNTHETIC_STATE as *const _ } From 020d102cd52e70578f407d6cf2921b2ca48cc642 Mon Sep 17 00:00:00 2001 From: bfoing <40759640+bfoing@users.noreply.github.com> Date: Wed, 25 Feb 2026 15:32:53 +0000 Subject: [PATCH 26/34] Support Rust 1.93 (nightly-2025-12-01) / LLVM 21 --- rustlib/panic_abort/src/lib.rs | 4 +- rustlib/panic_unwind/src/lib.rs | 4 +- rustlib/x86_64-unknown-linux-sgx.json | 4 +- sgx_oc/src/linux/mod.rs | 2 + sgx_sync/src/sys/futex.rs | 2 +- sgx_trts/src/enclave/state.rs | 13 +- sgx_trts/src/lib.rs | 1 - sgx_trts/src/veh/exception.rs | 4 +- sgx_tstd/src/alloc.rs | 21 +- sgx_tstd/src/f32.rs | 335 ------------------- sgx_tstd/src/f64.rs | 335 ------------------- sgx_tstd/src/fs/tests.rs | 2 +- sgx_tstd/src/io/buffered/bufreader/buffer.rs | 2 +- sgx_tstd/src/io/mod.rs | 6 +- sgx_tstd/src/lib.rs | 34 +- sgx_tstd/src/net/tcp/tests.rs | 2 +- sgx_tstd/src/panicking.rs | 8 +- sgx_tstd/src/prelude/v1.rs | 2 +- sgx_tstd/src/sys/fd.rs | 2 +- sgx_tstd/src/sys/net.rs | 2 +- sgx_tstd/src/sys_common/once/futex.rs | 11 +- teaclave-patches.bundle | Bin 0 -> 1867 bytes 22 files changed, 61 insertions(+), 735 deletions(-) create mode 100644 teaclave-patches.bundle diff --git a/rustlib/panic_abort/src/lib.rs b/rustlib/panic_abort/src/lib.rs index 7dc8c5767..d56a6041e 100644 --- a/rustlib/panic_abort/src/lib.rs +++ b/rustlib/panic_abort/src/lib.rs @@ -21,7 +21,7 @@ use core::any::Any; use core::panic::PanicPayload; /// # Safety -#[rustc_std_internal_symbol] +#[no_mangle] #[allow(improper_ctypes_definitions)] pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Send + 'static) { unreachable!() @@ -29,7 +29,7 @@ pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Sen /// # Safety // "Leak" the payload and shim to the relevant abort on the platform in question. -#[rustc_std_internal_symbol] +#[no_mangle] pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 { sgx_trts::error::abort(); } diff --git a/rustlib/panic_unwind/src/lib.rs b/rustlib/panic_unwind/src/lib.rs index 237a8919f..71c04bd44 100644 --- a/rustlib/panic_unwind/src/lib.rs +++ b/rustlib/panic_unwind/src/lib.rs @@ -44,7 +44,7 @@ extern "C" { } /// # Safety -#[rustc_std_internal_symbol] +#[no_mangle] #[allow(improper_ctypes_definitions)] pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static) { Box::into_raw(imp::cleanup(payload)) @@ -53,7 +53,7 @@ pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any /// # Safety // Entry point for raising an exception, just delegates to the platform-specific // implementation. -#[rustc_std_internal_symbol] +#[no_mangle] pub unsafe fn __rust_start_panic(payload: &mut dyn PanicPayload) -> u32 { let payload = Box::from_raw(payload.take_box()); diff --git a/rustlib/x86_64-unknown-linux-sgx.json b/rustlib/x86_64-unknown-linux-sgx.json index 4a19c7c74..5eb422246 100644 --- a/rustlib/x86_64-unknown-linux-sgx.json +++ b/rustlib/x86_64-unknown-linux-sgx.json @@ -37,9 +37,9 @@ "memory", "thread" ], - "target-c-int-width": "32", + "target-c-int-width": 32, "target-endian": "little", "target-family": "unix", - "target-pointer-width": "64", + "target-pointer-width": 64, "vendor": "teaclave" } diff --git a/sgx_oc/src/linux/mod.rs b/sgx_oc/src/linux/mod.rs index 6a5c09c46..0c0e5a0b3 100644 --- a/sgx_oc/src/linux/mod.rs +++ b/sgx_oc/src/linux/mod.rs @@ -1,3 +1,5 @@ +#![allow(dangerous_implicit_autorefs)] +#![allow(dangerous_implicit_autorefs)] // Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information diff --git a/sgx_sync/src/sys/futex.rs b/sgx_sync/src/sys/futex.rs index b06fbb335..9d26a0618 100644 --- a/sgx_sync/src/sys/futex.rs +++ b/sgx_sync/src/sys/futex.rs @@ -179,7 +179,7 @@ impl Futex { } fn load_val(&self) -> u32 { - unsafe { intrinsics::atomic_load_seqcst(self.0 as *const u32) } + unsafe { { use core::sync::atomic::{AtomicU32, Ordering}; (*((self.0 as *const u32) as *const AtomicU32)).load(Ordering::SeqCst) } } } fn addr(&self) -> usize { diff --git a/sgx_trts/src/enclave/state.rs b/sgx_trts/src/enclave/state.rs index 4c6fed3d0..3a5d1febf 100644 --- a/sgx_trts/src/enclave/state.rs +++ b/sgx_trts/src/enclave/state.rs @@ -77,12 +77,17 @@ pub fn lock_state() -> State { const IN_PROGRESS: u32 = 1; let state = unsafe { - let (state, _) = core::intrinsics::atomic_cxchg_seqcst_seqcst( - &mut ENCLAVE_STATE, + use core::sync::atomic::{AtomicU32, Ordering}; + let ptr = &ENCLAVE_STATE as *const u32 as *const AtomicU32; + match (*ptr).compare_exchange( NOT_STARTED, IN_PROGRESS, - ); - state + Ordering::SeqCst, + Ordering::SeqCst, + ) { + Ok(v) => v, + Err(v) => v, + } }; match state { 0 => State::NotStarted, diff --git a/sgx_trts/src/lib.rs b/sgx_trts/src/lib.rs index a048d759d..cd2028bce 100644 --- a/sgx_trts/src/lib.rs +++ b/sgx_trts/src/lib.rs @@ -24,7 +24,6 @@ #![feature(const_trait_impl)] #![feature(core_intrinsics)] #![feature(extract_if)] -#![feature(maybe_uninit_uninit_array)] #![feature(min_specialization)] #![feature(negative_impls)] #![feature(never_type)] diff --git a/sgx_trts/src/veh/exception.rs b/sgx_trts/src/veh/exception.rs index e0789b3f8..4ae7c885a 100644 --- a/sgx_trts/src/veh/exception.rs +++ b/sgx_trts/src/veh/exception.rs @@ -323,7 +323,7 @@ extern "C" fn internal_handle(info: &mut ExceptionInfo) { } let mut handlers: [MaybeUninit; MAX_REGISTER_COUNT] = - MaybeUninit::uninit_array(); + [const { MaybeUninit::uninit() }; MAX_REGISTER_COUNT]; // let mut handlers: [ExceptionHandler; MAX_REGISTER_COUNT] = unsafe { mem::zeroed() }; let mut len = 0_usize; @@ -338,7 +338,7 @@ extern "C" fn internal_handle(info: &mut ExceptionInfo) { let mut result = HandleResult::Search; for f in &handlers[..len] { - result = (unsafe { f.assume_init_ref() })(info); + result = (unsafe { f.assume_init_ref() as &ExceptionHandler })(info); if result == HandleResult::Execution { break; } diff --git a/sgx_tstd/src/alloc.rs b/sgx_tstd/src/alloc.rs index fe4d8da83..1ef7b3952 100644 --- a/sgx_tstd/src/alloc.rs +++ b/sgx_tstd/src/alloc.rs @@ -134,18 +134,7 @@ pub fn take_alloc_error_hook() -> fn(Layout) { } fn default_alloc_error_hook(layout: Layout) { - extern "Rust" { - // This symbol is emitted by rustc next to __rust_alloc_error_handler. - // Its value depends on the -Zoom={panic,abort} compiler option. - static __rust_alloc_error_handler_should_panic: u8; - } - - #[allow(unused_unsafe)] - if unsafe { __rust_alloc_error_handler_should_panic != 0 } { - panic!("memory allocation of {} bytes failed", layout.size()); - } else { - rtprintpanic!("memory allocation of {} bytes failed\n", layout.size()); - } + panic!("memory allocation of {} bytes failed", layout.size()); } #[doc(hidden)] @@ -172,7 +161,7 @@ pub mod __default_lib_allocator { // linkage directives are provided as part of the current compiler allocator // ABI - #[rustc_std_internal_symbol] + #[no_mangle] pub unsafe extern "C" fn __rdl_alloc(size: usize, align: usize) -> *mut u8 { // SAFETY: see the guarantees expected by `Layout::from_size_align` and // `GlobalAlloc::alloc`. @@ -180,14 +169,14 @@ pub mod __default_lib_allocator { System.alloc(layout) } - #[rustc_std_internal_symbol] + #[no_mangle] pub unsafe extern "C" fn __rdl_dealloc(ptr: *mut u8, size: usize, align: usize) { // SAFETY: see the guarantees expected by `Layout::from_size_align` and // `GlobalAlloc::dealloc`. System.dealloc(ptr, Layout::from_size_align_unchecked(size, align)) } - #[rustc_std_internal_symbol] + #[no_mangle] pub unsafe extern "C" fn __rdl_realloc( ptr: *mut u8, old_size: usize, @@ -200,7 +189,7 @@ pub mod __default_lib_allocator { System.realloc(ptr, old_layout, new_size) } - #[rustc_std_internal_symbol] + #[no_mangle] pub unsafe extern "C" fn __rdl_alloc_zeroed(size: usize, align: usize) -> *mut u8 { // SAFETY: see the guarantees expected by `Layout::from_size_align` and // `GlobalAlloc::alloc_zeroed`. diff --git a/sgx_tstd/src/f32.rs b/sgx_tstd/src/f32.rs index 53ad7e8aa..fd72bde86 100644 --- a/sgx_tstd/src/f32.rs +++ b/sgx_tstd/src/f32.rs @@ -41,316 +41,6 @@ pub use core::f32::{ }; impl f32 { - /// Returns the largest integer less than or equal to `self`. - /// - /// # Examples - /// - /// ``` - /// let f = 3.7_f32; - /// let g = 3.0_f32; - /// let h = -3.7_f32; - /// - /// assert_eq!(f.floor(), 3.0); - /// assert_eq!(g.floor(), 3.0); - /// assert_eq!(h.floor(), -4.0); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn floor(self) -> f32 { - unsafe { intrinsics::floorf32(self) } - } - - /// Returns the smallest integer greater than or equal to `self`. - /// - /// # Examples - /// - /// ``` - /// let f = 3.01_f32; - /// let g = 4.0_f32; - /// - /// assert_eq!(f.ceil(), 4.0); - /// assert_eq!(g.ceil(), 4.0); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn ceil(self) -> f32 { - unsafe { intrinsics::ceilf32(self) } - } - - /// Returns the nearest integer to `self`. If a value is half-way between two - /// integers, round away from `0.0`. - /// - /// # Examples - /// - /// ``` - /// let f = 3.3_f32; - /// let g = -3.3_f32; - /// let h = -3.7_f32; - /// let i = 3.5_f32; - /// let j = 4.5_f32; - /// - /// assert_eq!(f.round(), 3.0); - /// assert_eq!(g.round(), -3.0); - /// assert_eq!(h.round(), -4.0); - /// assert_eq!(i.round(), 4.0); - /// assert_eq!(j.round(), 5.0); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn round(self) -> f32 { - unsafe { intrinsics::roundf32(self) } - } - - /// Returns the nearest integer to a number. Rounds half-way cases to the number - /// with an even least significant digit. - /// - /// # Examples - /// - /// ``` - /// #![feature(round_ties_even)] - /// - /// let f = 3.3_f32; - /// let g = -3.3_f32; - /// let h = 3.5_f32; - /// let i = 4.5_f32; - /// - /// assert_eq!(f.round_ties_even(), 3.0); - /// assert_eq!(g.round_ties_even(), -3.0); - /// assert_eq!(h.round_ties_even(), 4.0); - /// assert_eq!(i.round_ties_even(), 4.0); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn round_ties_even(self) -> f32 { - unsafe { intrinsics::rintf32(self) } - } - - /// Returns the integer part of `self`. - /// This means that non-integer numbers are always truncated towards zero. - /// - /// # Examples - /// - /// ``` - /// let f = 3.7_f32; - /// let g = 3.0_f32; - /// let h = -3.7_f32; - /// - /// assert_eq!(f.trunc(), 3.0); - /// assert_eq!(g.trunc(), 3.0); - /// assert_eq!(h.trunc(), -3.0); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn trunc(self) -> f32 { - unsafe { intrinsics::truncf32(self) } - } - - /// Returns the fractional part of `self`. - /// - /// # Examples - /// - /// ``` - /// let x = 3.6_f32; - /// let y = -3.6_f32; - /// let abs_difference_x = (x.fract() - 0.6).abs(); - /// let abs_difference_y = (y.fract() - (-0.6)).abs(); - /// - /// assert!(abs_difference_x <= f32::EPSILON); - /// assert!(abs_difference_y <= f32::EPSILON); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn fract(self) -> f32 { - self - self.trunc() - } - - /// Computes the absolute value of `self`. - /// - /// # Examples - /// - /// ``` - /// let x = 3.5_f32; - /// let y = -3.5_f32; - /// - /// let abs_difference_x = (x.abs() - x).abs(); - /// let abs_difference_y = (y.abs() - (-y)).abs(); - /// - /// assert!(abs_difference_x <= f32::EPSILON); - /// assert!(abs_difference_y <= f32::EPSILON); - /// - /// assert!(f32::NAN.abs().is_nan()); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn abs(self) -> f32 { - unsafe { intrinsics::fabsf32(self) } - } - - /// Returns a number that represents the sign of `self`. - /// - /// - `1.0` if the number is positive, `+0.0` or `INFINITY` - /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` - /// - NaN if the number is NaN - /// - /// # Examples - /// - /// ``` - /// let f = 3.5_f32; - /// - /// assert_eq!(f.signum(), 1.0); - /// assert_eq!(f32::NEG_INFINITY.signum(), -1.0); - /// - /// assert!(f32::NAN.signum().is_nan()); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn signum(self) -> f32 { - if self.is_nan() { Self::NAN } else { 1.0_f32.copysign(self) } - } - - /// Returns a number composed of the magnitude of `self` and the sign of - /// `sign`. - /// - /// Equal to `self` if the sign of `self` and `sign` are the same, otherwise - /// equal to `-self`. If `self` is a NaN, then a NaN with the sign bit of - /// `sign` is returned. Note, however, that conserving the sign bit on NaN - /// across arithmetical operations is not generally guaranteed. - /// See [explanation of NaN as a special value](primitive@f32) for more info. - /// - /// # Examples - /// - /// ``` - /// let f = 3.5_f32; - /// - /// assert_eq!(f.copysign(0.42), 3.5_f32); - /// assert_eq!(f.copysign(-0.42), -3.5_f32); - /// assert_eq!((-f).copysign(0.42), 3.5_f32); - /// assert_eq!((-f).copysign(-0.42), -3.5_f32); - /// - /// assert!(f32::NAN.copysign(1.0).is_nan()); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn copysign(self, sign: f32) -> f32 { - unsafe { intrinsics::copysignf32(self, sign) } - } - - /// Fused multiply-add. Computes `(self * a) + b` with only one rounding - /// error, yielding a more accurate result than an unfused multiply-add. - /// - /// Using `mul_add` *may* be more performant than an unfused multiply-add if - /// the target architecture has a dedicated `fma` CPU instruction. However, - /// this is not always true, and will be heavily dependant on designing - /// algorithms with specific target hardware in mind. - /// - /// # Examples - /// - /// ``` - /// let m = 10.0_f32; - /// let x = 4.0_f32; - /// let b = 60.0_f32; - /// - /// // 100.0 - /// let abs_difference = (m.mul_add(x, b) - ((m * x) + b)).abs(); - /// - /// assert!(abs_difference <= f32::EPSILON); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn mul_add(self, a: f32, b: f32) -> f32 { - unsafe { intrinsics::fmaf32(self, a, b) } - } - - /// Calculates Euclidean division, the matching method for `rem_euclid`. - /// - /// This computes the integer `n` such that - /// `self = n * rhs + self.rem_euclid(rhs)`. - /// In other words, the result is `self / rhs` rounded to the integer `n` - /// such that `self >= n * rhs`. - /// - /// # Examples - /// - /// ``` - /// let a: f32 = 7.0; - /// let b = 4.0; - /// assert_eq!(a.div_euclid(b), 1.0); // 7.0 > 4.0 * 1.0 - /// assert_eq!((-a).div_euclid(b), -2.0); // -7.0 >= 4.0 * -2.0 - /// assert_eq!(a.div_euclid(-b), -1.0); // 7.0 >= -4.0 * -1.0 - /// assert_eq!((-a).div_euclid(-b), 2.0); // -7.0 >= -4.0 * 2.0 - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn div_euclid(self, rhs: f32) -> f32 { - let q = (self / rhs).trunc(); - if self % rhs < 0.0 { - return if rhs > 0.0 { q - 1.0 } else { q + 1.0 }; - } - q - } - - /// Calculates the least nonnegative remainder of `self (mod rhs)`. - /// - /// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in - /// most cases. However, due to a floating point round-off error it can - /// result in `r == rhs.abs()`, violating the mathematical definition, if - /// `self` is much smaller than `rhs.abs()` in magnitude and `self < 0.0`. - /// This result is not an element of the function's codomain, but it is the - /// closest floating point number in the real numbers and thus fulfills the - /// property `self == self.div_euclid(rhs) * rhs + self.rem_euclid(rhs)` - /// approximately. - /// - /// # Examples - /// - /// ``` - /// let a: f32 = 7.0; - /// let b = 4.0; - /// assert_eq!(a.rem_euclid(b), 3.0); - /// assert_eq!((-a).rem_euclid(b), 1.0); - /// assert_eq!(a.rem_euclid(-b), 3.0); - /// assert_eq!((-a).rem_euclid(-b), 1.0); - /// // limitation due to round-off error - /// assert!((-f32::EPSILON).rem_euclid(3.0) != 0.0); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn rem_euclid(self, rhs: f32) -> f32 { - let r = self % rhs; - if r < 0.0 { r + rhs.abs() } else { r } - } - - /// Raises a number to an integer power. - /// - /// Using this function is generally faster than using `powf`. - /// It might have a different sequence of rounding operations than `powf`, - /// so the results are not guaranteed to agree. - /// - /// # Examples - /// - /// ``` - /// let x = 2.0_f32; - /// let abs_difference = (x.powi(2) - (x * x)).abs(); - /// - /// assert!(abs_difference <= f32::EPSILON); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn powi(self, n: i32) -> f32 { - unsafe { intrinsics::powif32(self, n) } - } - /// Raises a number to a floating point power. /// /// # Examples @@ -367,31 +57,6 @@ impl f32 { pub fn powf(self, n: f32) -> f32 { unsafe { intrinsics::powf32(self, n) } } - - /// Returns the square root of a number. - /// - /// Returns NaN if `self` is a negative number other than `-0.0`. - /// - /// # Examples - /// - /// ``` - /// let positive = 4.0_f32; - /// let negative = -4.0_f32; - /// let negative_zero = -0.0_f32; - /// - /// let abs_difference = (positive.sqrt() - 2.0).abs(); - /// - /// assert!(abs_difference <= f32::EPSILON); - /// assert!(negative.sqrt().is_nan()); - /// assert!(negative_zero.sqrt() == negative_zero); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn sqrt(self) -> f32 { - unsafe { intrinsics::sqrtf32(self) } - } - /// Returns `e^(self)`, (the exponential function). /// /// # Examples diff --git a/sgx_tstd/src/f64.rs b/sgx_tstd/src/f64.rs index 9fe630f50..b9bf60be5 100644 --- a/sgx_tstd/src/f64.rs +++ b/sgx_tstd/src/f64.rs @@ -41,316 +41,6 @@ pub use core::f64::{ }; impl f64 { - /// Returns the largest integer less than or equal to `self`. - /// - /// # Examples - /// - /// ``` - /// let f = 3.7_f64; - /// let g = 3.0_f64; - /// let h = -3.7_f64; - /// - /// assert_eq!(f.floor(), 3.0); - /// assert_eq!(g.floor(), 3.0); - /// assert_eq!(h.floor(), -4.0); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn floor(self) -> f64 { - unsafe { intrinsics::floorf64(self) } - } - - /// Returns the smallest integer greater than or equal to `self`. - /// - /// # Examples - /// - /// ``` - /// let f = 3.01_f64; - /// let g = 4.0_f64; - /// - /// assert_eq!(f.ceil(), 4.0); - /// assert_eq!(g.ceil(), 4.0); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn ceil(self) -> f64 { - unsafe { intrinsics::ceilf64(self) } - } - - /// Returns the nearest integer to `self`. If a value is half-way between two - /// integers, round away from `0.0`. - /// - /// # Examples - /// - /// ``` - /// let f = 3.3_f64; - /// let g = -3.3_f64; - /// let h = -3.7_f64; - /// let i = 3.5_f64; - /// let j = 4.5_f64; - /// - /// assert_eq!(f.round(), 3.0); - /// assert_eq!(g.round(), -3.0); - /// assert_eq!(h.round(), -4.0); - /// assert_eq!(i.round(), 4.0); - /// assert_eq!(j.round(), 5.0); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn round(self) -> f64 { - unsafe { intrinsics::roundf64(self) } - } - - /// Returns the nearest integer to a number. Rounds half-way cases to the number - /// with an even least significant digit. - /// - /// # Examples - /// - /// ``` - /// #![feature(round_ties_even)] - /// - /// let f = 3.3_f64; - /// let g = -3.3_f64; - /// let h = 3.5_f64; - /// let i = 4.5_f64; - /// - /// assert_eq!(f.round_ties_even(), 3.0); - /// assert_eq!(g.round_ties_even(), -3.0); - /// assert_eq!(h.round_ties_even(), 4.0); - /// assert_eq!(i.round_ties_even(), 4.0); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn round_ties_even(self) -> f64 { - unsafe { intrinsics::rintf64(self) } - } - - /// Returns the integer part of `self`. - /// This means that non-integer numbers are always truncated towards zero. - /// - /// # Examples - /// - /// ``` - /// let f = 3.7_f64; - /// let g = 3.0_f64; - /// let h = -3.7_f64; - /// - /// assert_eq!(f.trunc(), 3.0); - /// assert_eq!(g.trunc(), 3.0); - /// assert_eq!(h.trunc(), -3.0); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn trunc(self) -> f64 { - unsafe { intrinsics::truncf64(self) } - } - - /// Returns the fractional part of `self`. - /// - /// # Examples - /// - /// ``` - /// let x = 3.6_f64; - /// let y = -3.6_f64; - /// let abs_difference_x = (x.fract() - 0.6).abs(); - /// let abs_difference_y = (y.fract() - (-0.6)).abs(); - /// - /// assert!(abs_difference_x < 1e-10); - /// assert!(abs_difference_y < 1e-10); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn fract(self) -> f64 { - self - self.trunc() - } - - /// Computes the absolute value of `self`. - /// - /// # Examples - /// - /// ``` - /// let x = 3.5_f64; - /// let y = -3.5_f64; - /// - /// let abs_difference_x = (x.abs() - x).abs(); - /// let abs_difference_y = (y.abs() - (-y)).abs(); - /// - /// assert!(abs_difference_x < 1e-10); - /// assert!(abs_difference_y < 1e-10); - /// - /// assert!(f64::NAN.abs().is_nan()); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn abs(self) -> f64 { - unsafe { intrinsics::fabsf64(self) } - } - - /// Returns a number that represents the sign of `self`. - /// - /// - `1.0` if the number is positive, `+0.0` or `INFINITY` - /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` - /// - NaN if the number is NaN - /// - /// # Examples - /// - /// ``` - /// let f = 3.5_f64; - /// - /// assert_eq!(f.signum(), 1.0); - /// assert_eq!(f64::NEG_INFINITY.signum(), -1.0); - /// - /// assert!(f64::NAN.signum().is_nan()); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn signum(self) -> f64 { - if self.is_nan() { Self::NAN } else { 1.0_f64.copysign(self) } - } - - /// Returns a number composed of the magnitude of `self` and the sign of - /// `sign`. - /// - /// Equal to `self` if the sign of `self` and `sign` are the same, otherwise - /// equal to `-self`. If `self` is a NaN, then a NaN with the sign bit of - /// `sign` is returned. Note, however, that conserving the sign bit on NaN - /// across arithmetical operations is not generally guaranteed. - /// See [explanation of NaN as a special value](primitive@f32) for more info. - /// - /// # Examples - /// - /// ``` - /// let f = 3.5_f64; - /// - /// assert_eq!(f.copysign(0.42), 3.5_f64); - /// assert_eq!(f.copysign(-0.42), -3.5_f64); - /// assert_eq!((-f).copysign(0.42), 3.5_f64); - /// assert_eq!((-f).copysign(-0.42), -3.5_f64); - /// - /// assert!(f64::NAN.copysign(1.0).is_nan()); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn copysign(self, sign: f64) -> f64 { - unsafe { intrinsics::copysignf64(self, sign) } - } - - /// Fused multiply-add. Computes `(self * a) + b` with only one rounding - /// error, yielding a more accurate result than an unfused multiply-add. - /// - /// Using `mul_add` *may* be more performant than an unfused multiply-add if - /// the target architecture has a dedicated `fma` CPU instruction. However, - /// this is not always true, and will be heavily dependant on designing - /// algorithms with specific target hardware in mind. - /// - /// # Examples - /// - /// ``` - /// let m = 10.0_f64; - /// let x = 4.0_f64; - /// let b = 60.0_f64; - /// - /// // 100.0 - /// let abs_difference = (m.mul_add(x, b) - ((m * x) + b)).abs(); - /// - /// assert!(abs_difference < 1e-10); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn mul_add(self, a: f64, b: f64) -> f64 { - unsafe { intrinsics::fmaf64(self, a, b) } - } - - /// Calculates Euclidean division, the matching method for `rem_euclid`. - /// - /// This computes the integer `n` such that - /// `self = n * rhs + self.rem_euclid(rhs)`. - /// In other words, the result is `self / rhs` rounded to the integer `n` - /// such that `self >= n * rhs`. - /// - /// # Examples - /// - /// ``` - /// let a: f64 = 7.0; - /// let b = 4.0; - /// assert_eq!(a.div_euclid(b), 1.0); // 7.0 > 4.0 * 1.0 - /// assert_eq!((-a).div_euclid(b), -2.0); // -7.0 >= 4.0 * -2.0 - /// assert_eq!(a.div_euclid(-b), -1.0); // 7.0 >= -4.0 * -1.0 - /// assert_eq!((-a).div_euclid(-b), 2.0); // -7.0 >= -4.0 * 2.0 - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn div_euclid(self, rhs: f64) -> f64 { - let q = (self / rhs).trunc(); - if self % rhs < 0.0 { - return if rhs > 0.0 { q - 1.0 } else { q + 1.0 }; - } - q - } - - /// Calculates the least nonnegative remainder of `self (mod rhs)`. - /// - /// In particular, the return value `r` satisfies `0.0 <= r < rhs.abs()` in - /// most cases. However, due to a floating point round-off error it can - /// result in `r == rhs.abs()`, violating the mathematical definition, if - /// `self` is much smaller than `rhs.abs()` in magnitude and `self < 0.0`. - /// This result is not an element of the function's codomain, but it is the - /// closest floating point number in the real numbers and thus fulfills the - /// property `self == self.div_euclid(rhs) * rhs + self.rem_euclid(rhs)` - /// approximately. - /// - /// # Examples - /// - /// ``` - /// let a: f64 = 7.0; - /// let b = 4.0; - /// assert_eq!(a.rem_euclid(b), 3.0); - /// assert_eq!((-a).rem_euclid(b), 1.0); - /// assert_eq!(a.rem_euclid(-b), 3.0); - /// assert_eq!((-a).rem_euclid(-b), 1.0); - /// // limitation due to round-off error - /// assert!((-f64::EPSILON).rem_euclid(3.0) != 0.0); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn rem_euclid(self, rhs: f64) -> f64 { - let r = self % rhs; - if r < 0.0 { r + rhs.abs() } else { r } - } - - /// Raises a number to an integer power. - /// - /// Using this function is generally faster than using `powf`. - /// It might have a different sequence of rounding operations than `powf`, - /// so the results are not guaranteed to agree. - /// - /// # Examples - /// - /// ``` - /// let x = 2.0_f64; - /// let abs_difference = (x.powi(2) - (x * x)).abs(); - /// - /// assert!(abs_difference < 1e-10); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn powi(self, n: i32) -> f64 { - unsafe { intrinsics::powif64(self, n) } - } - /// Raises a number to a floating point power. /// /// # Examples @@ -367,31 +57,6 @@ impl f64 { pub fn powf(self, n: f64) -> f64 { unsafe { intrinsics::powf64(self, n) } } - - /// Returns the square root of a number. - /// - /// Returns NaN if `self` is a negative number other than `-0.0`. - /// - /// # Examples - /// - /// ``` - /// let positive = 4.0_f64; - /// let negative = -4.0_f64; - /// let negative_zero = -0.0_f64; - /// - /// let abs_difference = (positive.sqrt() - 2.0).abs(); - /// - /// assert!(abs_difference < 1e-10); - /// assert!(negative.sqrt().is_nan()); - /// assert!(negative_zero.sqrt() == negative_zero); - /// ``` - #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] - #[inline] - pub fn sqrt(self) -> f64 { - unsafe { intrinsics::sqrtf64(self) } - } - /// Returns `e^(self)`, (the exponential function). /// /// # Examples diff --git a/sgx_tstd/src/fs/tests.rs b/sgx_tstd/src/fs/tests.rs index babbeede8..b27d49532 100644 --- a/sgx_tstd/src/fs/tests.rs +++ b/sgx_tstd/src/fs/tests.rs @@ -319,7 +319,7 @@ fn file_test_read_buf() { let filename = &tmpdir.join("test"); check!(fs::write(filename, [1, 2, 3, 4])); - let mut buf: [MaybeUninit; 128] = MaybeUninit::uninit_array(); + let mut buf: [MaybeUninit; 128] = [const { MaybeUninit::uninit() }; 128]; let mut buf = BorrowedBuf::from(buf.as_mut_slice()); let mut file = check!(File::open(filename)); check!(file.read_buf(buf.unfilled())); diff --git a/sgx_tstd/src/io/buffered/bufreader/buffer.rs b/sgx_tstd/src/io/buffered/bufreader/buffer.rs index fd5777bca..774f02805 100644 --- a/sgx_tstd/src/io/buffered/bufreader/buffer.rs +++ b/sgx_tstd/src/io/buffered/bufreader/buffer.rs @@ -56,7 +56,7 @@ impl Buffer { pub fn buffer(&self) -> &[u8] { // SAFETY: self.pos and self.cap are valid, and self.cap => self.pos, and // that region is initialized because those are all invariants of this type. - unsafe { MaybeUninit::slice_assume_init_ref(self.buf.get_unchecked(self.pos..self.filled)) } + unsafe { self.buf.get_unchecked(self.pos..self.filled).assume_init_ref() } } #[inline] diff --git a/sgx_tstd/src/io/mod.rs b/sgx_tstd/src/io/mod.rs index ee861b4da..b8fbb380e 100644 --- a/sgx_tstd/src/io/mod.rs +++ b/sgx_tstd/src/io/mod.rs @@ -453,7 +453,7 @@ pub(crate) fn default_read_to_end( } // store how much was initialized but not filled - initialized = cursor.init_ref().len(); + initialized = cursor.init_mut().len(); // SAFETY: BorrowedBuf's invariants mean this much memory is initialized. unsafe { @@ -2621,7 +2621,7 @@ impl Read for Take { // if we just use an as cast to convert, limit may wrap around on a 32 bit target let limit = cmp::min(self.limit, usize::MAX as u64) as usize; - let extra_init = cmp::min(limit as usize, buf.init_ref().len()); + let extra_init = cmp::min(limit as usize, buf.init_mut().len()); // SAFETY: no uninit data is written to ibuf let ibuf = unsafe { &mut buf.as_mut()[..limit] }; @@ -2636,7 +2636,7 @@ impl Read for Take { let mut cursor = sliced_buf.unfilled(); self.inner.read_buf(cursor.reborrow())?; - let new_init = cursor.init_ref().len(); + let new_init = cursor.init_mut().len(); let filled = sliced_buf.len(); // cursor / sliced_buf / ibuf must drop here diff --git a/sgx_tstd/src/lib.rs b/sgx_tstd/src/lib.rs index d7d0465fe..e667db650 100644 --- a/sgx_tstd/src/lib.rs +++ b/sgx_tstd/src/lib.rs @@ -63,7 +63,6 @@ #![feature(allocator_internals)] #![feature(allow_internal_unsafe)] #![feature(allow_internal_unstable)] -#![feature(concat_idents)] #![feature(const_trait_impl)] #![feature(decl_macro)] #![feature(dropck_eyepatch)] @@ -76,6 +75,8 @@ #![feature(negative_impls)] #![feature(never_type)] #![feature(prelude_import)] +#![feature(formatting_options)] +#![feature(formatting_options)] #![feature(rustc_attrs)] #![feature(thread_local)] #![feature(try_blocks)] @@ -99,7 +100,6 @@ #![feature(hashmap_internals)] #![feature(ip)] #![feature(maybe_uninit_slice)] -#![feature(maybe_uninit_uninit_array)] #![feature(maybe_uninit_write_slice)] #![feature(panic_can_unwind)] #![feature(panic_internals)] @@ -146,26 +146,18 @@ #![default_lib_allocator] -// Explicitly import the prelude. The compiler uses this same unstable attribute -// to import the prelude implicitly when building crates that depend on std. -#[prelude_import] -#[allow(unused)] -use prelude::rust_2021::*; - -extern crate hashbrown; - -#[allow(unused_imports)] // macros from `alloc` are not used on all platforms -#[macro_use] -extern crate alloc as alloc_crate; - -// We always need an unwinder currently for backtraces -extern crate sgx_unwind; #[cfg(feature = "backtrace")] extern crate sgx_backtrace_sys; #[cfg(feature = "backtrace")] extern crate sgx_demangle; extern crate sgx_alloc; +#[global_allocator] +static GLOBAL: sgx_alloc::System = sgx_alloc::System; + +#[global_allocator] +static GLOBAL: sgx_alloc::System = sgx_alloc::System; + #[macro_use] extern crate sgx_types; pub use sgx_types::cfg_if; @@ -189,6 +181,14 @@ pub mod rt; // The Rust prelude pub mod prelude; +#[prelude_import] +#[allow(unused)] +use prelude::rust_2021::*; + +#[prelude_import] +#[allow(unused)] +use prelude::rust_2021::*; + // Public module declarations and re-exports pub use alloc_crate::borrow; pub use alloc_crate::boxed; @@ -331,7 +331,7 @@ pub use core::{ // Re-export built-in macros defined through core. #[allow(deprecated)] pub use core::{ - assert, assert_matches, cfg, column, compile_error, concat, concat_idents, const_format_args, + assert, assert_matches, cfg, column, compile_error, concat, const_format_args, env, file, format_args, format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env, stringify, trace_macros, }; diff --git a/sgx_tstd/src/net/tcp/tests.rs b/sgx_tstd/src/net/tcp/tests.rs index a89eb2d37..cb5ac76da 100644 --- a/sgx_tstd/src/net/tcp/tests.rs +++ b/sgx_tstd/src/net/tcp/tests.rs @@ -323,7 +323,7 @@ fn read_buf() { }); let mut s = t!(srv.accept()).0; - let mut buf: [MaybeUninit; 128] = MaybeUninit::uninit_array(); + let mut buf: [MaybeUninit; 128] = [const { MaybeUninit::uninit() }; 128]; let mut buf = BorrowedBuf::from(buf.as_mut_slice()); t!(s.read_buf(buf.unfilled())); assert_eq!(buf.filled(), &[1, 2, 3, 4]); diff --git a/sgx_tstd/src/panicking.rs b/sgx_tstd/src/panicking.rs index c9595d58a..038d9cc17 100644 --- a/sgx_tstd/src/panicking.rs +++ b/sgx_tstd/src/panicking.rs @@ -71,14 +71,14 @@ extern "Rust" { /// This function is called by the panic runtime if FFI code catches a Rust /// panic but doesn't rethrow it. We don't support this case since it messes /// with our panic count. -#[rustc_std_internal_symbol] +#[no_mangle] extern "C" fn __rust_drop_panic() -> ! { rtabort!("Rust panics must be rethrown"); } /// This function is called by the panic runtime if it catches an exception /// object which does not correspond to a Rust panic. -#[rustc_std_internal_symbol] +#[no_mangle] extern "C" fn __rust_foreign_exception() -> ! { rtabort!("Rust cannot catch foreign exceptions"); } @@ -566,7 +566,7 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { // Lazily, the first time this gets called, run the actual string formatting. self.string.get_or_insert_with(|| { let mut s = String::new(); - let mut fmt = fmt::Formatter::new(&mut s); + let mut fmt = fmt::Formatter::new(&mut s, fmt::FormattingOptions::new()); let _err = fmt::Display::fmt(&inner, &mut fmt); s }) @@ -848,7 +848,7 @@ pub fn rust_panic_without_hook(payload: Box) -> ! { /// An unmangled function (through `rustc_std_internal_symbol`) on which to slap /// yer breakpoints. #[inline(never)] -#[rustc_std_internal_symbol] +#[no_mangle] fn rust_panic(msg: &mut dyn PanicPayload) -> ! { let code = unsafe { __rust_start_panic(msg) }; rtabort!("failed to initiate panic, error {code}") diff --git a/sgx_tstd/src/prelude/v1.rs b/sgx_tstd/src/prelude/v1.rs index 83f97077d..305c11fb7 100644 --- a/sgx_tstd/src/prelude/v1.rs +++ b/sgx_tstd/src/prelude/v1.rs @@ -45,7 +45,7 @@ pub use crate::result::Result::{self, Err, Ok}; #[allow(deprecated)] #[doc(no_inline)] pub use core::prelude::v1::{ - assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args, + assert, cfg, column, compile_error, concat, env, file, format_args, format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env, stringify, trace_macros, Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, }; diff --git a/sgx_tstd/src/sys/fd.rs b/sgx_tstd/src/sys/fd.rs index 1e07b12f2..c6f02c516 100644 --- a/sgx_tstd/src/sys/fd.rs +++ b/sgx_tstd/src/sys/fd.rs @@ -63,7 +63,7 @@ impl FileDesc { pub fn read_buf(&self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> { let ret = cvt_ocall(unsafe { - libc::read(self.as_raw_fd(), MaybeUninit::slice_assume_init_mut(cursor.as_mut())) + libc::read(self.as_raw_fd(), cursor.as_mut().assume_init_mut()) })?; cursor.advance(ret); diff --git a/sgx_tstd/src/sys/net.rs b/sgx_tstd/src/sys/net.rs index ad417f0ea..e25702e4c 100644 --- a/sgx_tstd/src/sys/net.rs +++ b/sgx_tstd/src/sys/net.rs @@ -191,7 +191,7 @@ impl Socket { let ret = cvt_ocall(unsafe { libc::recv( self.as_raw_fd(), - MaybeUninit::slice_assume_init_mut(buf.as_mut()), + buf.as_mut().assume_init_mut(), flags, ) })?; diff --git a/sgx_tstd/src/sys_common/once/futex.rs b/sgx_tstd/src/sys_common/once/futex.rs index 44448b358..47be747ca 100644 --- a/sgx_tstd/src/sys_common/once/futex.rs +++ b/sgx_tstd/src/sys_common/once/futex.rs @@ -144,12 +144,13 @@ impl Once { } RUNNING | QUEUED => { // Set the state to QUEUED if it is not already. - if state == RUNNING - && let Err(new) = + if state == RUNNING { + if let Err(new) = self.state.compare_exchange_weak(RUNNING, QUEUED, Relaxed, Acquire) - { - state = new; - continue; + { + state = new; + continue; + } } futex_wait(&self.state, QUEUED, None); diff --git a/teaclave-patches.bundle b/teaclave-patches.bundle new file mode 100644 index 0000000000000000000000000000000000000000..c0a411628d9e626c2b4bd332880098a7e7b9ebd5 GIT binary patch literal 1867 zcmaKqdpy&N8^^z!+gcP^F_u=6T(+>;ELI`X54kfWW^)b0$lNPL$0a&$u|qD03_q8Z zh@381ERAX`m#~m>3&$;&j^F?1^?P2g=im41^Ld`PGV+EF(#J0h=@}kG4e)}Z@LCug zRu`{_*CP`Mx&$g-7l*;>QFQQnI2})K3I>a(ce)a@2&J7NCvYulN&muC2zVO^;`U+T7PHb6T^?{cill0E<9Fu$6nk zTPoj+x2)OzVCB<)PhZIP%771Eox0tB^?JG+j~}UawYGlIrr77iYs67|r#X~|+WtJ5 zoaiC0d``C6J^wKu3z?*xa?+vco8!+7lg5G7 zNNad2@w?#w?)*)Nq4tv6)cCl@jK3l!aLK)kWy~*xw(qE!ugjr}U z*6r)EHhO;}HrBRvb)e9HUXaQ{_XaJgm&>2iSGSbgtWr`{j&D0q(MF)jbFVOeu3kb2O=e`b^gI4%&0S&tUoL%uHsh!{ROYR)3Gs!+;v*Mg zns@2e1HN{O(Wdc0TX~^+uFC&zZbd7+0P9%XQu}-~M>9Szr+{T{0SO5pQxt~t{GE?j zP}q>%p?8&a^Jc`Ud;)O?ODl(un(tFNUUZMh$$HgA>Vs~TKWsc*(-WbgUS;y=w3^A$ zMX%~x9-Ii`q0F0h-}{%B=bLZUUmhPeQ9^k#+`e? z3(4H^Xkz7!?gk8`e@;(Q`#2#%N)!m7r(b%Er}iZ&Db!BoCGy>fSlyUb^)w;%fFIK+ zw}al)lh>cFe4)=^N@hRa?uc-Z+OQn_@bhcpmrr%8!*^w_MNwyogSSH79^1&x=3TJBFKDore)B?WsK6Hd0 zRjPX%JJynJ0AIFRYL4++9gbXkHff{XSgGmWybf7tox4(Y57!^F>@1g^?p7Hkb-8*< zsgWV|i3)A?wytsOAJUzLF#;S2K%hoVbH#I zc*8a*xi}mI9e1)9*rJYM`rphB=ws9wOjpk148H_eSxVmI(wFwd!wR~hH=gW{eqCI= z@$;)Ez990yuAVFo z7(Ed`vE?x@9T?G2Jl4+M@^pefIm-#zj5+$jMu{)9VL7LywMKq4^LEa~iqtefXo zi!J4@Un(173(L^I$BCRYm{Fm{@uN!mysOgqLyl8c*w@EhWI?C_2J`yJi;Z~V7jc=j zUeCEY5de)9YyKg6!XakIFz9__)N^jIfc?;$k^-^cOLzhJ>sLNFADrokbDJG~cj}Bm zRCI_QWK6taK!9BxgNviouNLY-Z3C4r0nadAm<1r2*=IXwR-lP49HZ2M3qS z+i%e0oFZ0S6dgOkV74lUJNp|;3{ESd&s20rM1~0--(Okz&HNN^;(b8?kBgQ=e3KJS zCu7R)^>T|0gv(%Vb?v6d z8jEAfHYY8nuK}lMqC-pIfA>|NM=$b8P^eBxEqbFUp1c0c?jmVZ1s&t&G_$=h=&j*s zV+wHeC6)iLD9d%m1y)lwmN~y*>_WJj!7qU_k_?V!R>k*VJE+X`yC*nMMDZuRSe*lo)eN_Me literal 0 HcmV?d00001 From fcf327dc93a91fa40a513775435f45818cde643f Mon Sep 17 00:00:00 2001 From: bfoing <40759640+bfoing@users.noreply.github.com> Date: Wed, 25 Feb 2026 22:38:26 +0000 Subject: [PATCH 27/34] Fix Rust nightly-2025-12-01 build: restore extern crates, add float methods --- sgx_tstd/src/f32.rs | 90 +++++++++++++++++++++++++++++++++++++++++++++ sgx_tstd/src/f64.rs | 90 +++++++++++++++++++++++++++++++++++++++++++++ sgx_tstd/src/lib.rs | 16 ++++---- 3 files changed, 189 insertions(+), 7 deletions(-) diff --git a/sgx_tstd/src/f32.rs b/sgx_tstd/src/f32.rs index fd72bde86..b7f876666 100644 --- a/sgx_tstd/src/f32.rs +++ b/sgx_tstd/src/f32.rs @@ -41,6 +41,96 @@ pub use core::f32::{ }; impl f32 { + /// Returns the largest integer less than or equal to `self`. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub const fn floor(self) -> f32 { + core::f32::math::floor(self) + } + + /// Returns the smallest integer greater than or equal to `self`. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub const fn ceil(self) -> f32 { + core::f32::math::ceil(self) + } + + /// Returns the nearest integer to `self`, rounding half-way cases away from `0.0`. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub const fn round(self) -> f32 { + core::f32::math::round(self) + } + + /// Returns the nearest integer, rounding ties to even. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub const fn round_ties_even(self) -> f32 { + core::f32::math::round_ties_even(self) + } + + /// Returns the integer part of `self`. Truncates towards zero. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub const fn trunc(self) -> f32 { + core::f32::math::trunc(self) + } + + /// Returns the fractional part of `self`. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub const fn fract(self) -> f32 { + core::f32::math::fract(self) + } + + /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn mul_add(self, a: f32, b: f32) -> f32 { + core::f32::math::mul_add(self, a, b) + } + + /// Calculates Euclidean division. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn div_euclid(self, rhs: f32) -> f32 { + core::f32::math::div_euclid(self, rhs) + } + + /// Calculates the least nonnegative remainder of `self (mod rhs)`. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn rem_euclid(self, rhs: f32) -> f32 { + core::f32::math::rem_euclid(self, rhs) + } + + /// Raises a number to an integer power. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn powi(self, n: i32) -> f32 { + core::f32::math::powi(self, n) + } + + /// Returns the square root of a number. + /// + /// Returns NaN if `self` is a negative number other than `-0.0`. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn sqrt(self) -> f32 { + unsafe { intrinsics::sqrtf32(self) } + } + /// Raises a number to a floating point power. /// /// # Examples diff --git a/sgx_tstd/src/f64.rs b/sgx_tstd/src/f64.rs index b9bf60be5..17e42d29b 100644 --- a/sgx_tstd/src/f64.rs +++ b/sgx_tstd/src/f64.rs @@ -41,6 +41,96 @@ pub use core::f64::{ }; impl f64 { + /// Returns the largest integer less than or equal to `self`. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub const fn floor(self) -> f64 { + core::f64::math::floor(self) + } + + /// Returns the smallest integer greater than or equal to `self`. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub const fn ceil(self) -> f64 { + core::f64::math::ceil(self) + } + + /// Returns the nearest integer to `self`, rounding half-way cases away from `0.0`. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub const fn round(self) -> f64 { + core::f64::math::round(self) + } + + /// Returns the nearest integer, rounding ties to even. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub const fn round_ties_even(self) -> f64 { + core::f64::math::round_ties_even(self) + } + + /// Returns the integer part of `self`. Truncates towards zero. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub const fn trunc(self) -> f64 { + core::f64::math::trunc(self) + } + + /// Returns the fractional part of `self`. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub const fn fract(self) -> f64 { + core::f64::math::fract(self) + } + + /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn mul_add(self, a: f64, b: f64) -> f64 { + core::f64::math::mul_add(self, a, b) + } + + /// Calculates Euclidean division. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn div_euclid(self, rhs: f64) -> f64 { + core::f64::math::div_euclid(self, rhs) + } + + /// Calculates the least nonnegative remainder of `self (mod rhs)`. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn rem_euclid(self, rhs: f64) -> f64 { + core::f64::math::rem_euclid(self, rhs) + } + + /// Raises a number to an integer power. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn powi(self, n: i32) -> f64 { + core::f64::math::powi(self, n) + } + + /// Returns the square root of a number. + /// + /// Returns NaN if `self` is a negative number other than `-0.0`. + #[rustc_allow_incoherent_impl] + #[must_use = "method returns a new number and does not mutate the original value"] + #[inline] + pub fn sqrt(self) -> f64 { + unsafe { intrinsics::sqrtf64(self) } + } + /// Raises a number to a floating point power. /// /// # Examples diff --git a/sgx_tstd/src/lib.rs b/sgx_tstd/src/lib.rs index e667db650..5e3440046 100644 --- a/sgx_tstd/src/lib.rs +++ b/sgx_tstd/src/lib.rs @@ -76,7 +76,6 @@ #![feature(never_type)] #![feature(prelude_import)] #![feature(formatting_options)] -#![feature(formatting_options)] #![feature(rustc_attrs)] #![feature(thread_local)] #![feature(try_blocks)] @@ -141,6 +140,7 @@ #![feature(log_syntax)] #![feature(test)] #![feature(trace_macros)] +#![feature(core_float_math)] // tidy-alphabetical-end // @@ -155,8 +155,14 @@ extern crate sgx_alloc; #[global_allocator] static GLOBAL: sgx_alloc::System = sgx_alloc::System; -#[global_allocator] -static GLOBAL: sgx_alloc::System = sgx_alloc::System; +extern crate hashbrown; + +#[allow(unused_imports)] // macros from `alloc` are not used on all platforms +#[macro_use] +extern crate alloc as alloc_crate; + +// We always need an unwinder currently for backtraces +extern crate sgx_unwind; #[macro_use] extern crate sgx_types; @@ -185,10 +191,6 @@ pub mod prelude; #[allow(unused)] use prelude::rust_2021::*; -#[prelude_import] -#[allow(unused)] -use prelude::rust_2021::*; - // Public module declarations and re-exports pub use alloc_crate::borrow; pub use alloc_crate::boxed; From 91b76646fd40edb12b99d66e1aa50318d4008cf2 Mon Sep 17 00:00:00 2001 From: bfoing <40759640+bfoing@users.noreply.github.com> Date: Wed, 25 Feb 2026 22:53:33 +0000 Subject: [PATCH 28/34] Add sgx_sysroot CMake target for building trusted Rust rlibs --- CMakeLists.txt | 124 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 100 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57f401e7f..acfd9097a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,24 +1,100 @@ -message("sgx_urts_rust") - -set(SGX_URTS_OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/sgx_urts/target/release/libsgx_urts.a) -add_custom_command( - OUTPUT ${SGX_URTS_OUTPUT} - COMMAND cargo build --release - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/sgx_urts -) - -add_custom_target(sgx_urts_target - DEPENDS ${SGX_URTS_OUTPUT} -) - -add_library(sgx_urts_rust STATIC IMPORTED GLOBAL) -add_dependencies(sgx_urts_rust sgx_urts_target) - -set_target_properties(sgx_urts_rust - PROPERTIES - IMPORTED_LOCATION "${SGX_URTS_OUTPUT}" -) - -# IMPORTED libraries cannot be installed, so we just copy the files, -# and define (in Secretarium.cmake) sgx_urts_rust as an IMPORTED library pointing to the installed file -install(FILES ${SGX_URTS_OUTPUT} DESTINATION ${CMAKE_INSTALL_LIBDIR}) +cmake_minimum_required(VERSION 3.20) +project(teaclave-sgx-sdk LANGUAGES C CXX) + +include(GNUInstallDirs) + +# ============================================================================= +# Options +# ============================================================================= +option(BUILD_SYSROOT "Build the SGX sysroot (trusted Rust rlibs)" ON) +option(BUILD_URTS "Build sgx_urts (untrusted runtime)" ON) + +set(SGX_TARGET "x86_64-unknown-linux-sgx" CACHE STRING + "Rust target triple for the SGX enclave") +set(SGX_SYSROOT_FEATURES "untrusted_fs;untrusted_time;net;thread" CACHE STRING + "Semicolon-separated std features to enable in the sysroot build") +set(SGX_SYSROOT_OUTPUT "" CACHE PATH + "Where to install the sysroot (default: /sysroot)") + +# ============================================================================= +# Derived paths +# ============================================================================= +set(SDK_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) +set(TARGET_JSON ${SDK_ROOT}/rustlib/${SGX_TARGET}.json) + +if(SGX_SYSROOT_OUTPUT STREQUAL "") + set(SGX_SYSROOT_OUTPUT ${SDK_ROOT}/sysroot) +endif() + +if(CMAKE_BUILD_TYPE STREQUAL "Release") + set(CARGO_PROFILE_FLAG "--release") + set(CARGO_OUT_DIR "release") +else() + set(CARGO_PROFILE_FLAG "") + set(CARGO_OUT_DIR "debug") +endif() + +# Convert semicolon-separated list to comma-separated for cargo --features +string(REPLACE ";" "," SGX_SYSROOT_FEATURES_CSV "${SGX_SYSROOT_FEATURES}") + +# ============================================================================= +# Target: sgx_sysroot — builds trusted Rust rlibs for x86_64-unknown-linux-sgx +# ============================================================================= +if(BUILD_SYSROOT) + set(SYSROOT_STAMP ${CMAKE_CURRENT_BINARY_DIR}/sgx_sysroot.stamp) + set(SYSROOT_LIB_DIR ${SGX_SYSROOT_OUTPUT}/lib/rustlib/${SGX_TARGET}/lib) + + add_custom_command( + OUTPUT ${SYSROOT_STAMP} + COMMENT "Building SGX sysroot (${CARGO_OUT_DIR})..." + COMMAND cargo build ${CARGO_PROFILE_FLAG} + -Zbuild-std=core,alloc + --target ${TARGET_JSON} + --features "${SGX_SYSROOT_FEATURES_CSV}" + COMMAND ${CMAKE_COMMAND} -E rm -rf ${SGX_SYSROOT_OUTPUT} + COMMAND ${CMAKE_COMMAND} -E make_directory ${SYSROOT_LIB_DIR} + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${SDK_ROOT}/rustlib/std/target/${SGX_TARGET}/${CARGO_OUT_DIR}/deps + ${SYSROOT_LIB_DIR} + COMMAND ${CMAKE_COMMAND} -E touch ${SYSROOT_STAMP} + WORKING_DIRECTORY ${SDK_ROOT}/rustlib/std + VERBATIM + ) + + add_custom_target(sgx_sysroot + DEPENDS ${SYSROOT_STAMP} + ) + + # Convenience: expose the sysroot path so consumers can reference it + set(SGX_SYSROOT_PATH ${SGX_SYSROOT_OUTPUT} CACHE INTERNAL + "Path to the installed SGX sysroot") +endif() + +# ============================================================================= +# Target: sgx_urts_rust — builds untrusted runtime +# ============================================================================= +if(BUILD_URTS) + message(STATUS "sgx_urts_rust") + + set(SGX_URTS_OUTPUT ${SDK_ROOT}/sgx_urts/target/release/libsgx_urts.a) + add_custom_command( + OUTPUT ${SGX_URTS_OUTPUT} + COMMAND cargo build --release + WORKING_DIRECTORY ${SDK_ROOT}/sgx_urts + ) + + add_custom_target(sgx_urts_target + DEPENDS ${SGX_URTS_OUTPUT} + ) + + add_library(sgx_urts_rust STATIC IMPORTED GLOBAL) + add_dependencies(sgx_urts_rust sgx_urts_target) + + set_target_properties(sgx_urts_rust + PROPERTIES + IMPORTED_LOCATION "${SGX_URTS_OUTPUT}" + ) + + # IMPORTED libraries cannot be installed, so we just copy the files + install(FILES ${SGX_URTS_OUTPUT} DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif() From 70bbed32e2ae97937de9a97002614071c9510fc2 Mon Sep 17 00:00:00 2001 From: bfoing <40759640+bfoing@users.noreply.github.com> Date: Sat, 28 Feb 2026 21:36:26 +0000 Subject: [PATCH 29/34] fix: Toolchain --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index d7b2dc6bf..dcdb8e3a6 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2024-11-14 +nightly-2025-12-01 From 0702dcc3ad4e8de5e72e689855bdcd81c54c0f82 Mon Sep 17 00:00:00 2001 From: bfoing <40759640+bfoing@users.noreply.github.com> Date: Fri, 20 Mar 2026 00:01:52 +0000 Subject: [PATCH 30/34] fix: resolve all warnings for Rust nightly-2025-12-01 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sgx_trts (49 → 0 warnings): - capi.rs: remove #[inline] from 35 #[no_mangle] extern functions - asm/mod.rs: remove #[inline(always)] from #[no_mangle] extern function - lib.rs: remove stable feature(extract_if) - rand.rs: replace 3 unsafe transmutes with from_ne_bytes() - sync/rwlock.rs: add explicit '_ lifetimes to 5 guard return types - sync/mutex.rs: add explicit '_ lifetime to try_lock return type - sync/once.rs: add explicit '_ lifetime to lock return type - veh/exception.rs: fix 2 function-to-integer casts via *const () sgx_sync (1 → 0 warnings): - sys/futex.rs: remove unused core::intrinsics import sgx_oc (4 → 0 warnings): - macros.rs: remove #[inline] from f! macro, add "C" ABI to safe_f! macro - linux/x86_64/mod.rs: add "C" ABI to extern fn() field, allow unpredictable_function_pointer_comparisons on C FFI struct sigaction std/sgx_tstd (31 → 0 warnings): - lib.rs: remove 4 stable feature flags (let_chains, maybe_uninit_write_slice, prelude_2024, vec_into_raw_parts) - f32.rs, f64.rs: remove #[must_use] from incoherent impl methods (38 each), remove 9 unnecessary unsafe blocks around now-safe intrinsics (each) - sys/fd.rs, sys/net.rs: remove unused MaybeUninit imports - untrusted/path.rs: remove 4 #[must_use] from trait impl methods - untrusted/time.rs: remove 3 #[must_use] from trait impl methods hashbrown_tstd (2 → 0 warnings): - raw/mod.rs: add targeted #[allow(dead_code)] on RawIterHash/RawIterHashInner (public API structs unused in this build config) --- sgx_oc/src/linux/x86_64/mod.rs | 3 +- sgx_oc/src/macros.rs | 3 +- sgx_sync/src/sys/futex.rs | 1 - sgx_trts/src/asm/mod.rs | 1 - sgx_trts/src/capi.rs | 35 ------------------- sgx_trts/src/lib.rs | 1 - sgx_trts/src/rand.rs | 6 ++-- sgx_trts/src/sync/mutex.rs | 2 +- sgx_trts/src/sync/once.rs | 2 +- sgx_trts/src/sync/rwlock.rs | 10 +++--- sgx_trts/src/veh/exception.rs | 4 +-- sgx_tstd/hashbrown/src/raw/mod.rs | 2 ++ sgx_tstd/src/f32.rs | 56 +++++-------------------------- sgx_tstd/src/f64.rs | 56 +++++-------------------------- sgx_tstd/src/lib.rs | 4 --- sgx_tstd/src/sys/fd.rs | 1 - sgx_tstd/src/sys/net.rs | 1 - sgx_tstd/src/untrusted/path.rs | 4 --- sgx_tstd/src/untrusted/time.rs | 3 -- 19 files changed, 35 insertions(+), 160 deletions(-) diff --git a/sgx_oc/src/linux/x86_64/mod.rs b/sgx_oc/src/linux/x86_64/mod.rs index da39123f3..33237502e 100644 --- a/sgx_oc/src/linux/x86_64/mod.rs +++ b/sgx_oc/src/linux/x86_64/mod.rs @@ -315,11 +315,12 @@ s! { pub __val: [u64; 16], } + #[allow(unpredictable_function_pointer_comparisons)] pub struct sigaction { pub sa_sigaction: sighandler_t, pub sa_mask: sigset_t, pub sa_flags: c_int, - pub sa_restorer: Option, + pub sa_restorer: Option, } pub struct siginfo_t { pub si_signo: c_int, diff --git a/sgx_oc/src/macros.rs b/sgx_oc/src/macros.rs index 72e3fbdfc..4494d444f 100644 --- a/sgx_oc/src/macros.rs +++ b/sgx_oc/src/macros.rs @@ -132,7 +132,6 @@ macro_rules! f { $($body:stmt);* })*) => ($( #[no_mangle] - #[inline] pub $($constness)* unsafe extern "C" fn $i($($arg: $argty),*) -> $ret { $($body)* } @@ -147,7 +146,7 @@ macro_rules! safe_f { })*) => ($( #[inline] $(#[$attr])* - pub $($constness)* extern fn $i($($arg: $argty),* + pub $($constness)* extern "C" fn $i($($arg: $argty),* ) -> $ret { $($body);* } diff --git a/sgx_sync/src/sys/futex.rs b/sgx_sync/src/sys/futex.rs index 9d26a0618..a8aa7cd97 100644 --- a/sgx_sync/src/sys/futex.rs +++ b/sgx_sync/src/sys/futex.rs @@ -24,7 +24,6 @@ use alloc::collections::VecDeque; use alloc::sync::Arc; use alloc::vec::Vec; use core::hash::{Hash, Hasher, SipHasher13}; -use core::intrinsics; use core::sync::atomic::{AtomicBool, Ordering}; use core::time::Duration; use sgx_trts::sync::SpinMutex; diff --git a/sgx_trts/src/asm/mod.rs b/sgx_trts/src/asm/mod.rs index b1592dbd1..81d8693a6 100644 --- a/sgx_trts/src/asm/mod.rs +++ b/sgx_trts/src/asm/mod.rs @@ -73,7 +73,6 @@ pub static SYNTHETIC_STATE: Align64<[u32; SYNTHETIC_STATE_SIZE / 4]> = Align64([ 0, 0, 0, 0, 0, 2, 0, 2, 0x80000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]); -#[inline(always)] #[no_mangle] pub extern "C" fn get_synthetic_state_ptr( ) -> *const Align64<[u32; SYNTHETIC_STATE_SIZE / 4]> { diff --git a/sgx_trts/src/capi.rs b/sgx_trts/src/capi.rs index fcfa52ada..17aac995c 100644 --- a/sgx_trts/src/capi.rs +++ b/sgx_trts/src/capi.rs @@ -30,13 +30,11 @@ use core::ptr; use core::slice; use sgx_types::error::SgxStatus; -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_get_enclave_mode() -> i32 { enclave_mode() as i32 } -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_register_exception_handler( first: i32, @@ -48,7 +46,6 @@ pub unsafe extern "C" fn sgx_register_exception_handler( } } -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_unregister_exception_handler(handle: *const c_void) -> i32 { let handle = Handle::from_raw(handle as u64); @@ -56,67 +53,56 @@ pub unsafe extern "C" fn sgx_unregister_exception_handler(handle: *const c_void) i32::from(result) } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_image_base() -> *const u8 { MmLayout::image_base() as *const u8 } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_image_size() -> usize { MmLayout::image_size() } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_elrange_base() -> *const u8 { MmLayout::elrange_base() as *const u8 } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_elrange_size() -> usize { MmLayout::elrange_size() } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_heap_base() -> *const u8 { MmLayout::heap_base() as *const u8 } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_heap_size() -> usize { MmLayout::heap_size() } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_heap_min_size() -> usize { MmLayout::heap_min_size() } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_rsrvmem_base() -> *const u8 { MmLayout::rsrvmem_base() as *const u8 } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_rsrvmem_size() -> usize { MmLayout::rsrvmem_size() } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_rsrvmem_min_size() -> usize { MmLayout::rsrvmem_min_size() } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_rsrvmm_default_perm() -> u32 { MmLayout::rsrvmm_default_perm() as u32 @@ -128,49 +114,41 @@ pub extern "C" fn sgx_is_enclave_crashed() -> i32 { i32::from(enclave::state::is_crashed()) } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_tcs_max_num() -> usize { tcs_max_num() } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_tcs_policy() -> u32 { tcs_policy() as u32 } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_stack_size() -> usize { stack_size() } -#[inline] #[no_mangle] pub extern "C" fn sgx_get_cpu_core_num() -> u32 { cpu_core_num() } -#[inline] #[no_mangle] pub extern "C" fn sgx_is_supported_edmm() -> bool { is_supported_edmm() } -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_is_within_enclave(p: *const u8, len: usize) -> i32 { i32::from(enclave::is_within_enclave(p, len)) } -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_is_outside_enclave(p: *const u8, len: usize) -> i32 { i32::from(enclave::is_within_host(p, len)) } -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_ocall(idx: i32, ms: *mut c_void) -> u32 { if let Ok(index) = OCallIndex::try_from(idx) { @@ -184,7 +162,6 @@ pub unsafe extern "C" fn sgx_ocall(idx: i32, ms: *mut c_void) -> u32 { } } -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_ocalloc(size: usize) -> *mut u8 { if let Some(size) = NonZeroUsize::new(size) { @@ -196,7 +173,6 @@ pub unsafe extern "C" fn sgx_ocalloc(size: usize) -> *mut u8 { } } -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_ocalloc_aligned(align: usize, size: usize) -> *mut u8 { let size = match NonZeroUsize::new(size) { @@ -212,7 +188,6 @@ pub unsafe extern "C" fn sgx_ocalloc_aligned(align: usize, size: usize) -> *mut .unwrap_or(ptr::null_mut()) } -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_ocfree() { if OcBuffer::free().is_err() { @@ -220,13 +195,11 @@ pub unsafe extern "C" fn sgx_ocfree() { } } -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_ocremain_size() -> usize { OcBuffer::remain_size() } -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_apply_epc_pages(addr: usize, count: usize) -> i32 { if apply_epc_pages(addr, count).is_ok() { @@ -236,7 +209,6 @@ pub unsafe extern "C" fn sgx_apply_epc_pages(addr: usize, count: usize) -> i32 { } } -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_trim_epc_pages(addr: usize, count: usize) -> i32 { if trim_epc_pages(addr, count).is_ok() { @@ -247,7 +219,6 @@ pub unsafe extern "C" fn sgx_trim_epc_pages(addr: usize, count: usize) -> i32 { } #[allow(clippy::redundant_closure)] -#[inline] #[no_mangle] pub unsafe extern "C" fn atexit(f: extern "C" fn()) -> i32 { if !enclave::is_within_enclave(f as *const u8, 0) { @@ -262,7 +233,6 @@ pub unsafe extern "C" fn atexit(f: extern "C" fn()) -> i32 { } } -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_read_rand(p: *mut u8, len: usize) -> u32 { if p.is_null() || len == 0 { @@ -276,7 +246,6 @@ pub unsafe extern "C" fn sgx_read_rand(p: *mut u8, len: usize) -> u32 { } } -#[inline] #[no_mangle] pub unsafe extern "C" fn get_thread_data() -> *const c_void { current().tds() as *const _ as *const c_void @@ -285,20 +254,17 @@ pub unsafe extern "C" fn get_thread_data() -> *const c_void { pub type sgx_thread_t = *const c_void; pub const SGX_THREAD_T_NULL: *const c_void = ptr::null(); -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_thread_self() -> sgx_thread_t { get_thread_data() } -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_thread_equal(a: sgx_thread_t, b: sgx_thread_t) -> i32 { i32::from(a == b) } #[cfg(not(feature = "hyper"))] -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_rdpkru(val: *mut u32) -> i32 { if val.is_null() { @@ -315,7 +281,6 @@ pub unsafe extern "C" fn sgx_rdpkru(val: *mut u32) -> i32 { } #[cfg(not(feature = "hyper"))] -#[inline] #[no_mangle] pub unsafe extern "C" fn sgx_wrpkru(val: u32) -> i32 { match crate::pkru::Pkru::write(val) { diff --git a/sgx_trts/src/lib.rs b/sgx_trts/src/lib.rs index cd2028bce..cac30db51 100644 --- a/sgx_trts/src/lib.rs +++ b/sgx_trts/src/lib.rs @@ -23,7 +23,6 @@ #![feature(allocator_api)] #![feature(const_trait_impl)] #![feature(core_intrinsics)] -#![feature(extract_if)] #![feature(min_specialization)] #![feature(negative_impls)] #![feature(never_type)] diff --git a/sgx_trts/src/rand.rs b/sgx_trts/src/rand.rs index fe0aeaaa6..17226c1cf 100644 --- a/sgx_trts/src/rand.rs +++ b/sgx_trts/src/rand.rs @@ -147,17 +147,17 @@ impl Default for Rng { fn next_u32(fill_buf: &mut dyn FnMut(&mut [u8])) -> u32 { let mut buf = [0_u8; 4]; fill_buf(&mut buf); - unsafe { mem::transmute::<[u8; 4], u32>(buf) } + u32::from_ne_bytes(buf) } fn next_u64(fill_buf: &mut dyn FnMut(&mut [u8])) -> u64 { let mut buf = [0_u8; 8]; fill_buf(&mut buf); - unsafe { mem::transmute::<[u8; 8], u64>(buf) } + u64::from_ne_bytes(buf) } fn next_usize(fill_buf: &mut dyn FnMut(&mut [u8])) -> usize { let mut buf = [0_u8; mem::size_of::()]; fill_buf(&mut buf); - unsafe { mem::transmute::<[u8; mem::size_of::()], usize>(buf) } + usize::from_ne_bytes(buf) } diff --git a/sgx_trts/src/sync/mutex.rs b/sgx_trts/src/sync/mutex.rs index 865a320c8..d390eb7bb 100644 --- a/sgx_trts/src/sync/mutex.rs +++ b/sgx_trts/src/sync/mutex.rs @@ -93,7 +93,7 @@ impl SpinMutex { } #[inline] - pub fn try_lock(&self) -> Option> { + pub fn try_lock(&self) -> Option> { if self .lock .compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) diff --git a/sgx_trts/src/sync/once.rs b/sgx_trts/src/sync/once.rs index 90f355386..d706bb83c 100644 --- a/sgx_trts/src/sync/once.rs +++ b/sgx_trts/src/sync/once.rs @@ -38,7 +38,7 @@ impl Once { } } - pub fn lock(&self) -> SpinMutexGuard<()> { + pub fn lock(&self) -> SpinMutexGuard<'_, ()> { self.lock.lock() } diff --git a/sgx_trts/src/sync/rwlock.rs b/sgx_trts/src/sync/rwlock.rs index 1c629c44c..a4e0c194a 100644 --- a/sgx_trts/src/sync/rwlock.rs +++ b/sgx_trts/src/sync/rwlock.rs @@ -74,7 +74,7 @@ impl SpinRwLock { impl SpinRwLock { #[inline] - pub fn read(&self) -> SpinRwLockReadGuard { + pub fn read(&self) -> SpinRwLockReadGuard<'_, T> { loop { match self.try_read() { Some(guard) => return guard, @@ -84,7 +84,7 @@ impl SpinRwLock { } #[inline] - pub fn write(&self) -> SpinRwLockWriteGuard { + pub fn write(&self) -> SpinRwLockWriteGuard<'_, T> { loop { match self.try_write_internal(false) { Some(guard) => return guard, @@ -94,7 +94,7 @@ impl SpinRwLock { } #[inline] - pub fn try_read(&self) -> Option> { + pub fn try_read(&self) -> Option> { let value = self.lock.fetch_add(READER, Ordering::Acquire); if value & WRITER != 0 { self.lock.fetch_sub(READER, Ordering::Release); @@ -108,12 +108,12 @@ impl SpinRwLock { } #[inline] - pub fn try_write(&self) -> Option> { + pub fn try_write(&self) -> Option> { self.try_write_internal(true) } #[inline(always)] - fn try_write_internal(&self, strong: bool) -> Option> { + fn try_write_internal(&self, strong: bool) -> Option> { if compare_exchange( &self.lock, 0, diff --git a/sgx_trts/src/veh/exception.rs b/sgx_trts/src/veh/exception.rs index 4ae7c885a..02f039a91 100644 --- a/sgx_trts/src/veh/exception.rs +++ b/sgx_trts/src/veh/exception.rs @@ -235,7 +235,7 @@ pub fn handle(tcs: &mut Tcs) -> SgxResult { // in the first phase and we should not change anything in the ssa_gpr // prepare the ip for 2nd phrase handling - ssa_gpr.rip = internal_handle as usize as u64; + ssa_gpr.rip = internal_handle as *const () as usize as u64; // new stack for internal_handle_exception ssa_gpr.rsp = new_sp as u64; // 1st parameter (info) for LINUX32 @@ -264,7 +264,7 @@ pub fn handle(tcs: &mut Tcs) -> SgxResult { second_phase( info as *const _, new_sp as *const _, - internal_handle as usize, + internal_handle as *const () as usize, ); } } diff --git a/sgx_tstd/hashbrown/src/raw/mod.rs b/sgx_tstd/hashbrown/src/raw/mod.rs index 01ef6e001..ef746b1a3 100644 --- a/sgx_tstd/hashbrown/src/raw/mod.rs +++ b/sgx_tstd/hashbrown/src/raw/mod.rs @@ -4348,11 +4348,13 @@ impl FusedIterator for RawDrain<'_, T, A> {} /// created will be yielded by that iterator. /// - The order in which the iterator yields buckets is unspecified and may /// change in the future. +#[allow(dead_code)] pub struct RawIterHash { inner: RawIterHashInner, _marker: PhantomData, } +#[allow(dead_code)] struct RawIterHashInner { // See `RawTableInner`'s corresponding fields for details. // We can't store a `*const RawTableInner` as it would get diff --git a/sgx_tstd/src/f32.rs b/sgx_tstd/src/f32.rs index b7f876666..4dfced4be 100644 --- a/sgx_tstd/src/f32.rs +++ b/sgx_tstd/src/f32.rs @@ -43,7 +43,6 @@ pub use core::f32::{ impl f32 { /// Returns the largest integer less than or equal to `self`. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub const fn floor(self) -> f32 { core::f32::math::floor(self) @@ -51,7 +50,6 @@ impl f32 { /// Returns the smallest integer greater than or equal to `self`. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub const fn ceil(self) -> f32 { core::f32::math::ceil(self) @@ -59,7 +57,6 @@ impl f32 { /// Returns the nearest integer to `self`, rounding half-way cases away from `0.0`. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub const fn round(self) -> f32 { core::f32::math::round(self) @@ -67,7 +64,6 @@ impl f32 { /// Returns the nearest integer, rounding ties to even. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub const fn round_ties_even(self) -> f32 { core::f32::math::round_ties_even(self) @@ -75,7 +71,6 @@ impl f32 { /// Returns the integer part of `self`. Truncates towards zero. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub const fn trunc(self) -> f32 { core::f32::math::trunc(self) @@ -83,7 +78,6 @@ impl f32 { /// Returns the fractional part of `self`. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub const fn fract(self) -> f32 { core::f32::math::fract(self) @@ -91,7 +85,6 @@ impl f32 { /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn mul_add(self, a: f32, b: f32) -> f32 { core::f32::math::mul_add(self, a, b) @@ -99,7 +92,6 @@ impl f32 { /// Calculates Euclidean division. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn div_euclid(self, rhs: f32) -> f32 { core::f32::math::div_euclid(self, rhs) @@ -107,7 +99,6 @@ impl f32 { /// Calculates the least nonnegative remainder of `self (mod rhs)`. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn rem_euclid(self, rhs: f32) -> f32 { core::f32::math::rem_euclid(self, rhs) @@ -115,7 +106,6 @@ impl f32 { /// Raises a number to an integer power. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn powi(self, n: i32) -> f32 { core::f32::math::powi(self, n) @@ -125,10 +115,9 @@ impl f32 { /// /// Returns NaN if `self` is a negative number other than `-0.0`. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn sqrt(self) -> f32 { - unsafe { intrinsics::sqrtf32(self) } + intrinsics::sqrtf32(self) } /// Raises a number to a floating point power. @@ -142,10 +131,9 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn powf(self, n: f32) -> f32 { - unsafe { intrinsics::powf32(self, n) } + intrinsics::powf32(self, n) } /// Returns `e^(self)`, (the exponential function). /// @@ -162,10 +150,9 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn exp(self) -> f32 { - unsafe { intrinsics::expf32(self) } + intrinsics::expf32(self) } /// Returns `2^(self)`. @@ -181,10 +168,9 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn exp2(self) -> f32 { - unsafe { intrinsics::exp2f32(self) } + intrinsics::exp2f32(self) } /// Returns the natural logarithm of the number. @@ -202,10 +188,9 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn ln(self) -> f32 { - unsafe { intrinsics::logf32(self) } + intrinsics::logf32(self) } /// Returns the logarithm of the number with respect to an arbitrary base. @@ -225,7 +210,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn log(self, base: f32) -> f32 { self.ln() / base.ln() @@ -244,10 +228,9 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn log2(self) -> f32 { - unsafe { intrinsics::log2f32(self) } + intrinsics::log2f32(self) } /// Returns the base 10 logarithm of the number. @@ -263,10 +246,9 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn log10(self) -> f32 { - unsafe { intrinsics::log10f32(self) } + intrinsics::log10f32(self) } /// The positive difference of two numbers. @@ -287,7 +269,6 @@ impl f32 { /// assert!(abs_difference_y <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] #[deprecated( since = "1.10.0", @@ -316,7 +297,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn cbrt(self) -> f32 { unsafe { cmath::cbrtf(self) } @@ -339,7 +319,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn hypot(self, other: f32) -> f32 { unsafe { cmath::hypotf(self, other) } @@ -357,10 +336,9 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn sin(self) -> f32 { - unsafe { intrinsics::sinf32(self) } + intrinsics::sinf32(self) } /// Computes the cosine of a number (in radians). @@ -375,10 +353,9 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn cos(self) -> f32 { - unsafe { intrinsics::cosf32(self) } + intrinsics::cosf32(self) } /// Computes the tangent of a number (in radians). @@ -392,7 +369,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn tan(self) -> f32 { unsafe { cmath::tanf(self) } @@ -413,7 +389,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn asin(self) -> f32 { unsafe { cmath::asinf(self) } @@ -434,7 +409,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn acos(self) -> f32 { unsafe { cmath::acosf(self) } @@ -454,7 +428,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn atan(self) -> f32 { unsafe { cmath::atanf(self) } @@ -487,7 +460,6 @@ impl f32 { /// assert!(abs_difference_2 <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn atan2(self, other: f32) -> f32 { unsafe { cmath::atan2f(self, other) } @@ -529,7 +501,6 @@ impl f32 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn exp_m1(self) -> f32 { unsafe { cmath::expm1f(self) } @@ -550,7 +521,6 @@ impl f32 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn ln_1p(self) -> f32 { unsafe { cmath::log1pf(self) } @@ -572,7 +542,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn sinh(self) -> f32 { unsafe { cmath::sinhf(self) } @@ -594,7 +563,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn cosh(self) -> f32 { unsafe { cmath::coshf(self) } @@ -616,7 +584,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn tanh(self) -> f32 { unsafe { cmath::tanhf(self) } @@ -635,7 +602,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn asinh(self) -> f32 { let ax = self.abs(); @@ -656,7 +622,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn acosh(self) -> f32 { if self < 1.0 { @@ -679,7 +644,6 @@ impl f32 { /// assert!(abs_difference <= 1e-5); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn atanh(self) -> f32 { 0.5 * ((2.0 * self) / (1.0 - self)).ln_1p() @@ -698,7 +662,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn gamma(self) -> f32 { unsafe { cmath::tgammaf(self) } @@ -719,7 +682,6 @@ impl f32 { /// assert!(abs_difference <= f32::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn ln_gamma(self) -> (f32, i32) { let mut signgamp: i32 = 0; diff --git a/sgx_tstd/src/f64.rs b/sgx_tstd/src/f64.rs index 17e42d29b..d69284bda 100644 --- a/sgx_tstd/src/f64.rs +++ b/sgx_tstd/src/f64.rs @@ -43,7 +43,6 @@ pub use core::f64::{ impl f64 { /// Returns the largest integer less than or equal to `self`. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub const fn floor(self) -> f64 { core::f64::math::floor(self) @@ -51,7 +50,6 @@ impl f64 { /// Returns the smallest integer greater than or equal to `self`. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub const fn ceil(self) -> f64 { core::f64::math::ceil(self) @@ -59,7 +57,6 @@ impl f64 { /// Returns the nearest integer to `self`, rounding half-way cases away from `0.0`. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub const fn round(self) -> f64 { core::f64::math::round(self) @@ -67,7 +64,6 @@ impl f64 { /// Returns the nearest integer, rounding ties to even. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub const fn round_ties_even(self) -> f64 { core::f64::math::round_ties_even(self) @@ -75,7 +71,6 @@ impl f64 { /// Returns the integer part of `self`. Truncates towards zero. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub const fn trunc(self) -> f64 { core::f64::math::trunc(self) @@ -83,7 +78,6 @@ impl f64 { /// Returns the fractional part of `self`. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub const fn fract(self) -> f64 { core::f64::math::fract(self) @@ -91,7 +85,6 @@ impl f64 { /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn mul_add(self, a: f64, b: f64) -> f64 { core::f64::math::mul_add(self, a, b) @@ -99,7 +92,6 @@ impl f64 { /// Calculates Euclidean division. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn div_euclid(self, rhs: f64) -> f64 { core::f64::math::div_euclid(self, rhs) @@ -107,7 +99,6 @@ impl f64 { /// Calculates the least nonnegative remainder of `self (mod rhs)`. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn rem_euclid(self, rhs: f64) -> f64 { core::f64::math::rem_euclid(self, rhs) @@ -115,7 +106,6 @@ impl f64 { /// Raises a number to an integer power. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn powi(self, n: i32) -> f64 { core::f64::math::powi(self, n) @@ -125,10 +115,9 @@ impl f64 { /// /// Returns NaN if `self` is a negative number other than `-0.0`. #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn sqrt(self) -> f64 { - unsafe { intrinsics::sqrtf64(self) } + intrinsics::sqrtf64(self) } /// Raises a number to a floating point power. @@ -142,10 +131,9 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn powf(self, n: f64) -> f64 { - unsafe { intrinsics::powf64(self, n) } + intrinsics::powf64(self, n) } /// Returns `e^(self)`, (the exponential function). /// @@ -162,10 +150,9 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn exp(self) -> f64 { - unsafe { intrinsics::expf64(self) } + intrinsics::expf64(self) } /// Returns `2^(self)`. @@ -181,10 +168,9 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn exp2(self) -> f64 { - unsafe { intrinsics::exp2f64(self) } + intrinsics::exp2f64(self) } /// Returns the natural logarithm of the number. @@ -202,10 +188,9 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn ln(self) -> f64 { - self.log_wrapper(|n| unsafe { intrinsics::logf64(n) }) + self.log_wrapper(|n| intrinsics::logf64(n)) } /// Returns the logarithm of the number with respect to an arbitrary base. @@ -225,7 +210,6 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn log(self, base: f64) -> f64 { self.ln() / base.ln() @@ -244,10 +228,9 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn log2(self) -> f64 { - self.log_wrapper(|n| unsafe { intrinsics::log2f64(n) }) + self.log_wrapper(|n| intrinsics::log2f64(n)) } /// Returns the base 10 logarithm of the number. @@ -263,10 +246,9 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn log10(self) -> f64 { - self.log_wrapper(|n| unsafe { intrinsics::log10f64(n) }) + self.log_wrapper(|n| intrinsics::log10f64(n)) } /// The positive difference of two numbers. @@ -287,7 +269,6 @@ impl f64 { /// assert!(abs_difference_y < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] #[deprecated( since = "1.10.0", @@ -316,7 +297,6 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn cbrt(self) -> f64 { unsafe { cmath::cbrt(self) } @@ -339,7 +319,6 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn hypot(self, other: f64) -> f64 { unsafe { cmath::hypot(self, other) } @@ -357,10 +336,9 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn sin(self) -> f64 { - unsafe { intrinsics::sinf64(self) } + intrinsics::sinf64(self) } /// Computes the cosine of a number (in radians). @@ -375,10 +353,9 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn cos(self) -> f64 { - unsafe { intrinsics::cosf64(self) } + intrinsics::cosf64(self) } /// Computes the tangent of a number (in radians). @@ -392,7 +369,6 @@ impl f64 { /// assert!(abs_difference < 1e-14); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn tan(self) -> f64 { unsafe { cmath::tan(self) } @@ -413,7 +389,6 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn asin(self) -> f64 { unsafe { cmath::asin(self) } @@ -434,7 +409,6 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn acos(self) -> f64 { unsafe { cmath::acos(self) } @@ -454,7 +428,6 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn atan(self) -> f64 { unsafe { cmath::atan(self) } @@ -487,7 +460,6 @@ impl f64 { /// assert!(abs_difference_2 < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn atan2(self, other: f64) -> f64 { unsafe { cmath::atan2(self, other) } @@ -529,7 +501,6 @@ impl f64 { /// assert!(abs_difference < 1e-20); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn exp_m1(self) -> f64 { unsafe { cmath::expm1(self) } @@ -550,7 +521,6 @@ impl f64 { /// assert!(abs_difference < 1e-20); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn ln_1p(self) -> f64 { unsafe { cmath::log1p(self) } @@ -572,7 +542,6 @@ impl f64 { /// assert!(abs_difference < 1e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn sinh(self) -> f64 { unsafe { cmath::sinh(self) } @@ -594,7 +563,6 @@ impl f64 { /// assert!(abs_difference < 1.0e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn cosh(self) -> f64 { unsafe { cmath::cosh(self) } @@ -616,7 +584,6 @@ impl f64 { /// assert!(abs_difference < 1.0e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn tanh(self) -> f64 { unsafe { cmath::tanh(self) } @@ -635,7 +602,6 @@ impl f64 { /// assert!(abs_difference < 1.0e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn asinh(self) -> f64 { let ax = self.abs(); @@ -656,7 +622,6 @@ impl f64 { /// assert!(abs_difference < 1.0e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn acosh(self) -> f64 { if self < 1.0 { @@ -679,7 +644,6 @@ impl f64 { /// assert!(abs_difference < 1.0e-10); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn atanh(self) -> f64 { 0.5 * ((2.0 * self) / (1.0 - self)).ln_1p() @@ -698,7 +662,6 @@ impl f64 { /// assert!(abs_difference <= f64::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn gamma(self) -> f64 { unsafe { cmath::tgamma(self) } @@ -719,7 +682,6 @@ impl f64 { /// assert!(abs_difference <= f64::EPSILON); /// ``` #[rustc_allow_incoherent_impl] - #[must_use = "method returns a new number and does not mutate the original value"] #[inline] pub fn ln_gamma(self) -> (f64, i32) { let mut signgamp: i32 = 0; diff --git a/sgx_tstd/src/lib.rs b/sgx_tstd/src/lib.rs index 5e3440046..301271ddd 100644 --- a/sgx_tstd/src/lib.rs +++ b/sgx_tstd/src/lib.rs @@ -68,7 +68,6 @@ #![feature(dropck_eyepatch)] #![feature(if_let_guard)] #![feature(lang_items)] -#![feature(let_chains)] #![feature(min_specialization)] #![feature(must_not_suspend)] #![feature(needs_panic_runtime)] @@ -99,10 +98,8 @@ #![feature(hashmap_internals)] #![feature(ip)] #![feature(maybe_uninit_slice)] -#![feature(maybe_uninit_write_slice)] #![feature(panic_can_unwind)] #![feature(panic_internals)] -#![feature(prelude_2024)] #![feature(ptr_as_uninit)] #![feature(slice_internals)] #![feature(std_internals)] @@ -117,7 +114,6 @@ #![feature(map_try_insert)] #![feature(slice_concat_trait)] #![feature(try_reserve_kind)] -#![feature(vec_into_raw_parts)] // tidy-alphabetical-end // // Library features (unwind): diff --git a/sgx_tstd/src/sys/fd.rs b/sgx_tstd/src/sys/fd.rs index c6f02c516..080d5fca5 100644 --- a/sgx_tstd/src/sys/fd.rs +++ b/sgx_tstd/src/sys/fd.rs @@ -20,7 +20,6 @@ mod tests; use crate::cmp; use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read}; -use crate::mem::MaybeUninit; use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; use crate::sys::cvt_ocall; use crate::sys_common::{AsInner, FromInner, IntoInner}; diff --git a/sgx_tstd/src/sys/net.rs b/sgx_tstd/src/sys/net.rs index e25702e4c..36173f253 100644 --- a/sgx_tstd/src/sys/net.rs +++ b/sgx_tstd/src/sys/net.rs @@ -17,7 +17,6 @@ use crate::cmp; use crate::io::{self, BorrowedBuf, BorrowedCursor, IoSlice, IoSliceMut}; -use crate::mem::MaybeUninit; use crate::net::{Shutdown, SocketAddr}; use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; use crate::sys::fd::FileDesc; diff --git a/sgx_tstd/src/untrusted/path.rs b/sgx_tstd/src/untrusted/path.rs index e0b04cafc..55e05939b 100644 --- a/sgx_tstd/src/untrusted/path.rs +++ b/sgx_tstd/src/untrusted/path.rs @@ -156,7 +156,6 @@ impl PathEx for Path { /// /// This is a convenience function that coerces errors to false. If you want to /// check errors, call [`fs::metadata`]. - #[must_use] #[inline] fn exists(&self) -> bool { fs::metadata(self).is_ok() @@ -216,7 +215,6 @@ impl PathEx for Path { /// it. Only using `is_file` can break workflows like `diff <( prog_a )` on /// a Unix-like system for example. See [`fs::File::open`] or /// [`fs::OpenOptions::open`] for more information. - #[must_use] fn is_file(&self) -> bool { fs::metadata(self).map(|m| m.is_file()).unwrap_or(false) } @@ -243,7 +241,6 @@ impl PathEx for Path { /// This is a convenience function that coerces errors to false. If you want to /// check errors, call [`fs::metadata`] and handle its [`Result`]. Then call /// [`fs::Metadata::is_dir`] if it was [`Ok`]. - #[must_use] fn is_dir(&self) -> bool { fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false) } @@ -269,7 +266,6 @@ impl PathEx for Path { /// assert_eq!(link_path.is_symlink(), true); /// assert_eq!(link_path.exists(), false); /// ``` - #[must_use] fn is_symlink(&self) -> bool { fs::symlink_metadata(self).map(|m| m.is_symlink()).unwrap_or(false) } diff --git a/sgx_tstd/src/untrusted/time.rs b/sgx_tstd/src/untrusted/time.rs index f7d9ca8fa..92b1c7608 100644 --- a/sgx_tstd/src/untrusted/time.rs +++ b/sgx_tstd/src/untrusted/time.rs @@ -33,7 +33,6 @@ impl InstantEx for Instant { /// /// let now = Instant::now(); /// ``` - #[must_use] fn now() -> Instant { Instant::_now() } @@ -60,7 +59,6 @@ impl InstantEx for Instant { /// sleep(three_secs); /// assert!(instant.elapsed() >= three_secs); /// ``` - #[must_use] fn elapsed(&self) -> Duration { Instant::_now() - *self } @@ -82,7 +80,6 @@ impl SystemTimeEx for SystemTime { /// /// let sys_time = SystemTime::now(); /// ``` - #[must_use] fn now() -> SystemTime { SystemTime::_now() } From ab3ad7bec8e6fb80884be3aca3aefdd3ae79bf0f Mon Sep 17 00:00:00 2001 From: bfoing <40759640+bfoing@users.noreply.github.com> Date: Mon, 22 Jun 2026 12:14:37 +0100 Subject: [PATCH 31/34] feat(toolchain): port to Rust nightly-2026-06-21 / LLVM 22 Bump the SGX sysroot toolchain from nightly-2025-12-01 (rustc 1.93 / LLVM 21) to nightly-2026-06-21 (rustc 1.98 / LLVM 22). Reconcile sgx_tstd (a hard fork of std) with ~6 months of upstream std evolution: - cargo: custom .json target specs now require -Zjson-target-spec - sgx_alloc: Layout::dangling() -> dangling_ptr() - hashbrown: drop the Copy specialization (min_specialization forbids it) - FD/Timespec niche: drop rustc_layout_scalar_valid_range_* attrs (plain fields) - BorrowedBuf: new init API (set_init()/is_init(), bool tracking); BorrowedCursor gained a generic param; advance() is now unsafe; port default_read_to_end and Take::read_buf from matching std - intrinsics::catch_unwind now returns bool (not i32) - thread spawn: raw-ptr `as` casts can't extend trait-object lifetimes (rust#141402) -> launder the lifetime via transmute - re-export drift (VaListImpl/Exclusive/format_args_nl), rustc_macro_transparency value rename ("semitransparent" -> "semiopaque"), feature-gate updates - sgx_trts: fully-qualified AsSlice::as_slice to avoid unstable_name_collisions Full build is clean (0 errors, 0 warnings); deny(unused_features) retained. --- CMakeLists.txt | 1 + rust-toolchain | 2 +- rustlib/panic_unwind/src/lib.rs | 2 - sgx_alloc/src/lib.rs | 1 - sgx_alloc/src/system.rs | 4 +- sgx_sync/src/lib.rs | 1 - sgx_trts/src/elf/header.rs | 18 +- sgx_trts/src/elf/program.rs | 6 +- sgx_trts/src/elf/slice.rs | 10 +- sgx_trts/src/elf/zero.rs | 14 +- sgx_trts/src/enclave/parse.rs | 16 +- sgx_tstd/hashbrown/src/lib.rs | 4 +- sgx_tstd/hashbrown/src/macros.rs | 14 -- sgx_tstd/hashbrown/src/raw/mod.rs | 33 +-- sgx_tstd/src/ffi/mod.rs | 2 +- sgx_tstd/src/fs.rs | 6 +- sgx_tstd/src/io/buffered/bufreader.rs | 2 +- sgx_tstd/src/io/buffered/bufreader/buffer.rs | 13 +- sgx_tstd/src/io/buffered/tests.rs | 8 +- sgx_tstd/src/io/copy.rs | 20 +- sgx_tstd/src/io/cursor.rs | 2 +- sgx_tstd/src/io/impls.rs | 10 +- sgx_tstd/src/io/mod.rs | 188 +++++++++++------- sgx_tstd/src/io/stdio.rs | 6 +- sgx_tstd/src/io/tests.rs | 4 +- sgx_tstd/src/io/util.rs | 6 +- sgx_tstd/src/io/util/tests.rs | 8 +- sgx_tstd/src/lib.rs | 7 +- sgx_tstd/src/net/tcp.rs | 4 +- sgx_tstd/src/os/fd/owned.rs | 8 +- sgx_tstd/src/panicking.rs | 2 +- sgx_tstd/src/prelude/v1.rs | 2 +- sgx_tstd/src/process.rs | 4 +- sgx_tstd/src/sync/mod.rs | 1 - .../src/sys/common/thread_local/fast_local.rs | 2 +- .../src/sys/common/thread_local/os_local.rs | 2 +- sgx_tstd/src/sys/fd.rs | 6 +- sgx_tstd/src/sys/fs.rs | 2 +- sgx_tstd/src/sys/net.rs | 6 +- sgx_tstd/src/sys/pipe.rs | 2 +- sgx_tstd/src/sys/stdio.rs | 2 +- sgx_tstd/src/sys/time.rs | 4 +- sgx_tstd/src/sys/unsupported/pipe.rs | 2 +- sgx_tstd/src/sys_common/net.rs | 2 +- sgx_tstd/src/thread/mod.rs | 7 +- 45 files changed, 228 insertions(+), 238 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index acfd9097a..213cb932a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ if(BUILD_SYSROOT) COMMENT "Building SGX sysroot (${CARGO_OUT_DIR})..." COMMAND cargo build ${CARGO_PROFILE_FLAG} -Zbuild-std=core,alloc + -Zjson-target-spec --target ${TARGET_JSON} --features "${SGX_SYSROOT_FEATURES_CSV}" COMMAND ${CMAKE_COMMAND} -E rm -rf ${SGX_SYSROOT_OUTPUT} diff --git a/rust-toolchain b/rust-toolchain index dcdb8e3a6..000156feb 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2025-12-01 +nightly-2026-06-21 diff --git a/rustlib/panic_unwind/src/lib.rs b/rustlib/panic_unwind/src/lib.rs index 71c04bd44..e2feda5fa 100644 --- a/rustlib/panic_unwind/src/lib.rs +++ b/rustlib/panic_unwind/src/lib.rs @@ -14,8 +14,6 @@ #![no_std] #![unstable(feature = "panic_unwind", issue = "32837")] #![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] -#![feature(core_intrinsics)] -#![feature(lang_items)] #![feature(panic_unwind)] #![feature(staged_api)] #![feature(std_internals)] diff --git a/sgx_alloc/src/lib.rs b/sgx_alloc/src/lib.rs index 24d6e04f5..677fb0457 100644 --- a/sgx_alloc/src/lib.rs +++ b/sgx_alloc/src/lib.rs @@ -28,7 +28,6 @@ #![allow(non_camel_case_types)] #![allow(internal_features)] #![feature(allocator_api)] -#![feature(alloc_layout_extra)] #![feature(core_intrinsics)] #![feature(dropck_eyepatch)] #![feature(ptr_internals)] diff --git a/sgx_alloc/src/system.rs b/sgx_alloc/src/system.rs index 532699579..3d8e3900e 100644 --- a/sgx_alloc/src/system.rs +++ b/sgx_alloc/src/system.rs @@ -36,7 +36,7 @@ impl System { #[inline] fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result, AllocError> { match layout.size() { - 0 => Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0)), + 0 => Ok(NonNull::slice_from_raw_parts(layout.dangling_ptr(), 0)), // SAFETY: `layout` is non-zero in size, size => unsafe { let raw_ptr = if zeroed { @@ -159,7 +159,7 @@ unsafe impl Allocator for System { // SAFETY: conditions must be upheld by the caller 0 => { Allocator::deallocate(&self, ptr, old_layout); - Ok(NonNull::slice_from_raw_parts(new_layout.dangling(), 0)) + Ok(NonNull::slice_from_raw_parts(new_layout.dangling_ptr(), 0)) } // SAFETY: `new_size` is non-zero. Other conditions must be upheld by the caller diff --git a/sgx_sync/src/lib.rs b/sgx_sync/src/lib.rs index a1797c65f..640ebe2ff 100644 --- a/sgx_sync/src/lib.rs +++ b/sgx_sync/src/lib.rs @@ -20,7 +20,6 @@ #![deny(unused_features)] #![allow(internal_features)] #![feature(const_trait_impl)] -#![feature(core_intrinsics)] #![feature(dropck_eyepatch)] #![feature(hashmap_internals)] #![feature(linked_list_remove)] diff --git a/sgx_trts/src/elf/header.rs b/sgx_trts/src/elf/header.rs index 28c7e7bbd..44c1446a1 100644 --- a/sgx_trts/src/elf/header.rs +++ b/sgx_trts/src/elf/header.rs @@ -24,11 +24,11 @@ use sgx_types::marker::ContiguousMemory; pub fn parse_header<'a>(input: &'a [u8]) -> Result, &'static str> { let size_pt1 = mem::size_of::(); - if input.as_slice().len() < size_pt1 { + if AsSlice::as_slice(input).len() < size_pt1 { return Err("File is shorter than the first ELF header part"); } let header_1: &'a HeaderPt1 = - read(unsafe { input.as_slice().into_slice_unchecked((0, size_pt1)) }); + read(unsafe { AsSlice::as_slice(input).into_slice_unchecked((0, size_pt1)) }); if !slice::eq(&header_1.magic, &MAGIC) { return Err("Did not find ELF magic number"); @@ -38,24 +38,22 @@ pub fn parse_header<'a>(input: &'a [u8]) -> Result, &'static str> { Class::None | Class::Other(_) => return Err("Invalid ELF class"), Class::ThirtyTwo => { let size_pt2 = mem::size_of::>(); - if input.as_slice().len() < size_pt1 + size_pt2 { + if AsSlice::as_slice(input).len() < size_pt1 + size_pt2 { return Err("File is shorter than ELF headers"); } let header_2: &'a HeaderPt2_ = read(unsafe { - input - .as_slice() + AsSlice::as_slice(input) .into_slice_unchecked((size_pt1, size_pt1 + mem::size_of::>())) }); HeaderPt2::Header32(header_2) } Class::SixtyFour => { let size_pt2 = mem::size_of::>(); - if input.as_slice().len() < size_pt1 + size_pt2 { + if AsSlice::as_slice(input).len() < size_pt1 + size_pt2 { return Err("File is shorter than ELF headers"); } let header_2: &'a HeaderPt2_ = read(unsafe { - input - .as_slice() + AsSlice::as_slice(input) .into_slice_unchecked((size_pt1, size_pt1 + mem::size_of::>())) }); HeaderPt2::Header64(header_2) @@ -464,12 +462,12 @@ pub fn sanity_check(file: &ElfFile) -> Result<(), &'static str> { check!( pt2.ph_offset() + (pt2.ph_entry_size() as u64) * (pt2.ph_count() as u64) - <= file.input.as_slice().len() as u64, + <= AsSlice::as_slice(file.input).len() as u64, "program header table out of range" ); check!( pt2.sh_offset() + (pt2.sh_entry_size() as u64) * (pt2.sh_count() as u64) - <= file.input.as_slice().len() as u64, + <= AsSlice::as_slice(file.input).len() as u64, "section header table out of range" ); Ok(()) diff --git a/sgx_trts/src/elf/program.rs b/sgx_trts/src/elf/program.rs index c8a2e05fd..19551ce09 100644 --- a/sgx_trts/src/elf/program.rs +++ b/sgx_trts/src/elf/program.rs @@ -42,10 +42,10 @@ pub fn parse_program_header<'a>( match header.pt1.class() { Class::ThirtyTwo => Ok(ProgramHeader::Ph32(read(unsafe { - input.as_slice().into_slice_unchecked((start, end)) + AsSlice::as_slice(input).into_slice_unchecked((start, end)) }))), Class::SixtyFour => Ok(ProgramHeader::Ph64(read(unsafe { - input.as_slice().into_slice_unchecked((start, end)) + AsSlice::as_slice(input).into_slice_unchecked((start, end)) }))), Class::None | Class::Other(_) => abort(), } @@ -240,7 +240,7 @@ macro_rules! ph_impl { Err(_) => false, }); unsafe { - elf_file.input.as_slice().into_slice_unchecked(( + AsSlice::as_slice(elf_file.input).into_slice_unchecked(( self.physical_addr as usize, (self.physical_addr + self.file_size) as usize, )) diff --git a/sgx_trts/src/elf/slice.rs b/sgx_trts/src/elf/slice.rs index 576acde0f..91c603c8d 100644 --- a/sgx_trts/src/elf/slice.rs +++ b/sgx_trts/src/elf/slice.rs @@ -139,7 +139,7 @@ impl Slice { pub fn eq(&self, other: &[T]) -> bool { let t_len = self.len(); - let other = other.as_slice(); + let other = AsSlice::as_slice(other); if t_len != other.len() { return false; } @@ -179,15 +179,15 @@ pub unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T] } pub fn eq(src: &[T], other: &[T]) -> bool { - let t_len = src.as_slice().len(); - if t_len != other.as_slice().len() { + let t_len = AsSlice::as_slice(src).len(); + if t_len != AsSlice::as_slice(other).len() { return false; } unsafe { memcmp( - src.as_slice().as_ptr() as *const u8, - other.as_slice().as_ptr() as *const u8, + AsSlice::as_slice(src).as_ptr() as *const u8, + AsSlice::as_slice(other).as_ptr() as *const u8, mem::size_of::() * t_len, ) } diff --git a/sgx_trts/src/elf/zero.rs b/sgx_trts/src/elf/zero.rs index 29a488df1..cf351004b 100644 --- a/sgx_trts/src/elf/zero.rs +++ b/sgx_trts/src/elf/zero.rs @@ -22,8 +22,8 @@ use core::str::{from_utf8, from_utf8_unchecked}; use sgx_types::marker::ContiguousMemory; pub fn read(input: &[u8]) -> &T { - assert!(mem::size_of::() <= input.as_slice().len()); - let addr = input.as_slice().as_ptr() as usize; + assert!(mem::size_of::() <= AsSlice::as_slice(input).len()); + let addr = AsSlice::as_slice(input).as_ptr() as usize; // Alignment is always a power of 2, so we can use bit ops instead of a mod here. assert!((addr & (mem::align_of::() - 1)) == 0); @@ -33,8 +33,8 @@ pub fn read(input: &[u8]) -> &T { pub fn read_array(input: &[u8]) -> &[T] { let t_size = mem::size_of::(); assert!(t_size > 0, "Can't read arrays of zero-sized types"); - assert!(input.as_slice().len() % t_size == 0); - let addr = input.as_slice().as_ptr() as usize; + assert!(AsSlice::as_slice(input).len() % t_size == 0); + let addr = AsSlice::as_slice(input).as_ptr() as usize; assert!(addr & (mem::align_of::() - 1) == 0); unsafe { read_array_unsafe(input) } @@ -45,12 +45,12 @@ pub fn read_str(input: &[u8]) -> &str { } unsafe fn read_unsafe(input: &[u8]) -> &T { - &*(input.as_slice().as_ptr() as *const T) + &*(AsSlice::as_slice(input).as_ptr() as *const T) } unsafe fn read_array_unsafe(input: &[u8]) -> &[T] { - let ptr = input.as_slice().as_ptr() as *const T; - slice::from_raw_parts(ptr, input.as_slice().len() / mem::size_of::()) + let ptr = AsSlice::as_slice(input).as_ptr() as *const T; + slice::from_raw_parts(ptr, AsSlice::as_slice(input).len() / mem::size_of::()) } unsafe fn read_str_unsafe(input: &[u8]) -> &str { diff --git a/sgx_trts/src/enclave/parse.rs b/sgx_trts/src/enclave/parse.rs index 470c6b133..1eef7bf64 100644 --- a/sgx_trts/src/enclave/parse.rs +++ b/sgx_trts/src/enclave/parse.rs @@ -79,7 +79,7 @@ pub fn relocate() -> SgxResult { let mut plt_size = 0_u64; match segment { - SegmentData::Dynamic64(dyns) => dyns.as_slice().iter().all(|d| { + SegmentData::Dynamic64(dyns) => AsSlice::as_slice(dyns).iter().all(|d| { let tag = try_result_bool!(d.get_tag()); match tag { DynTag::Null => return false, @@ -300,25 +300,23 @@ fn get_sym<'a>(symtabl: *const u8, idx: u32) -> Option<&'a DynEntry64> { } unsafe fn relocate_elf_rela(elf: &ElfFile, sym_offset: u64, rel_offset: u64, rel_size: u64) { - let sym_table = (elf.input.as_slice().as_ptr() as usize + sym_offset as usize) as *const u8; - let rel_raw = elf - .input - .as_slice() + let sym_table = (AsSlice::as_slice(elf.input).as_ptr() as usize + sym_offset as usize) as *const u8; + let rel_raw = AsSlice::as_slice(elf.input) .into_slice_unchecked((rel_offset as usize, (rel_offset + rel_size) as usize)); let rel_array = Rela64Array::new(read_array(rel_raw)); - rel_array.get_array().as_slice().iter().for_each(|rel| { + AsSlice::as_slice(rel_array.get_array()).iter().for_each(|rel| { let reloc_addr = - (elf.input.as_slice().as_ptr() as usize + rel.get_offset() as usize) as *mut u64; + (AsSlice::as_slice(elf.input).as_ptr() as usize + rel.get_offset() as usize) as *mut u64; match rel.get_type() { sections::R_X86_64_RELATIVE => { - *reloc_addr = elf.input.as_slice().as_ptr() as u64 + rel.get_addend(); + *reloc_addr = AsSlice::as_slice(elf.input).as_ptr() as u64 + rel.get_addend(); } sections::R_X86_64_GLOB_DAT | sections::R_X86_64_JMP_SLOT | sections::R_X86_64_64 => { if let Some(sym) = get_sym(sym_table, rel.get_symbol_table_index()) { *reloc_addr = - elf.input.as_slice().as_ptr() as u64 + sym.value() + rel.get_addend(); + AsSlice::as_slice(elf.input).as_ptr() as u64 + sym.value() + rel.get_addend(); } } sections::R_X86_64_DTPMOD64 => *reloc_addr = 1_u64, diff --git a/sgx_tstd/hashbrown/src/lib.rs b/sgx_tstd/hashbrown/src/lib.rs index aa6ca4a9d..7a4a5d5da 100644 --- a/sgx_tstd/hashbrown/src/lib.rs +++ b/sgx_tstd/hashbrown/src/lib.rs @@ -14,14 +14,12 @@ #![cfg_attr( feature = "nightly", feature( - test, core_intrinsics, dropck_eyepatch, min_specialization, extend_one, allocator_api, - slice_ptr_get, - maybe_uninit_array_assume_init + slice_ptr_get ) )] #![allow( diff --git a/sgx_tstd/hashbrown/src/macros.rs b/sgx_tstd/hashbrown/src/macros.rs index eaba6bed1..fa5c8b3f9 100644 --- a/sgx_tstd/hashbrown/src/macros.rs +++ b/sgx_tstd/hashbrown/src/macros.rs @@ -54,17 +54,3 @@ macro_rules! cfg_if { }; } -// Helper macro for specialization. This also helps avoid parse errors if the -// default fn syntax for specialization changes in the future. -#[cfg(feature = "nightly")] -macro_rules! default_fn { - (#[$($a:tt)*] $($tt:tt)*) => { - #[$($a)*] default $($tt)* - } -} -#[cfg(not(feature = "nightly"))] -macro_rules! default_fn { - ($($tt:tt)*) => { - $($tt)* - } -} diff --git a/sgx_tstd/hashbrown/src/raw/mod.rs b/sgx_tstd/hashbrown/src/raw/mod.rs index ef746b1a3..57fd982d7 100644 --- a/sgx_tstd/hashbrown/src/raw/mod.rs +++ b/sgx_tstd/hashbrown/src/raw/mod.rs @@ -933,13 +933,6 @@ impl RawTable { unsafe { NonNull::new_unchecked(self.table.ctrl.as_ptr().cast()) } } - /// Returns pointer to start of data table. - #[inline] - #[cfg(any(feature = "raw", feature = "nightly"))] - pub unsafe fn data_start(&self) -> NonNull { - NonNull::new_unchecked(self.data_end().as_ptr().wrapping_sub(self.buckets())) - } - /// Return the information about memory allocated by the table. /// /// `RawTable` allocates single memory block to store both data and metadata. @@ -3531,33 +3524,17 @@ impl Clone for RawTable { } } -/// Specialization of `clone_from` for `Copy` types +// NOTE (Privasys fork): newer nightly `min_specialization` forbids specializing +// on `Copy`, so the bulk-memcpy specialization for `Copy` element types was +// removed. All clones go through the generic per-element `clone_from_impl` path; +// correctness is identical and table-clone is not an enclave hot path. trait RawTableClone { unsafe fn clone_from_spec(&mut self, source: &Self); } impl RawTableClone for RawTable { - default_fn! { - #[cfg_attr(feature = "inline-more", inline)] - unsafe fn clone_from_spec(&mut self, source: &Self) { - self.clone_from_impl(source); - } - } -} -#[cfg(feature = "nightly")] -impl RawTableClone for RawTable { #[cfg_attr(feature = "inline-more", inline)] unsafe fn clone_from_spec(&mut self, source: &Self) { - source - .table - .ctrl(0) - .copy_to_nonoverlapping(self.table.ctrl(0), self.table.num_ctrl_bytes()); - source - .data_start() - .as_ptr() - .copy_to_nonoverlapping(self.data_start().as_ptr(), self.table.buckets()); - - self.table.items = source.table.items; - self.table.growth_left = source.table.growth_left; + self.clone_from_impl(source); } } diff --git a/sgx_tstd/src/ffi/mod.rs b/sgx_tstd/src/ffi/mod.rs index 9b75d5e66..5178f76b7 100644 --- a/sgx_tstd/src/ffi/mod.rs +++ b/sgx_tstd/src/ffi/mod.rs @@ -182,6 +182,6 @@ pub use core::ffi::{ pub use core::ffi::c_void; -pub use core::ffi::{VaList, VaListImpl}; +pub use core::ffi::{VaList}; mod os_str; diff --git a/sgx_tstd/src/fs.rs b/sgx_tstd/src/fs.rs index cf6859916..c8b3d3336 100644 --- a/sgx_tstd/src/fs.rs +++ b/sgx_tstd/src/fs.rs @@ -740,7 +740,7 @@ impl Read for &File { } #[inline] - fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { self.inner.read_buf(cursor) } @@ -796,7 +796,7 @@ impl Read for File { fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { (&*self).read_vectored(bufs) } - fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { (&*self).read_buf(cursor) } #[inline] @@ -842,7 +842,7 @@ impl Read for Arc { fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { (&**self).read_vectored(bufs) } - fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { (&**self).read_buf(cursor) } #[inline] diff --git a/sgx_tstd/src/io/buffered/bufreader.rs b/sgx_tstd/src/io/buffered/bufreader.rs index ced201271..bfc1484ef 100644 --- a/sgx_tstd/src/io/buffered/bufreader.rs +++ b/sgx_tstd/src/io/buffered/bufreader.rs @@ -300,7 +300,7 @@ impl Read for BufReader { Ok(nread) } - fn read_buf(&mut self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, mut cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { // If we don't have any buffered data and we're doing a massive read // (larger than our internal buffer), bypass our internal buffer // entirely. diff --git a/sgx_tstd/src/io/buffered/bufreader/buffer.rs b/sgx_tstd/src/io/buffered/bufreader/buffer.rs index 774f02805..5cfb744ff 100644 --- a/sgx_tstd/src/io/buffered/bufreader/buffer.rs +++ b/sgx_tstd/src/io/buffered/bufreader/buffer.rs @@ -42,14 +42,14 @@ pub struct Buffer { // defensive initialization as possible. Note that while this often the same as `filled`, it // doesn't need to be. Calls to `fill_buf` are not required to actually fill the buffer, and // omitting this is a huge perf regression for `Read` impls that do not. - initialized: usize, + initialized: bool, } impl Buffer { #[inline] pub fn with_capacity(capacity: usize) -> Self { let buf = Box::new_uninit_slice(capacity); - Self { buf, pos: 0, filled: 0, initialized: 0 } + Self { buf, pos: 0, filled: 0, initialized: false } } #[inline] @@ -76,7 +76,7 @@ impl Buffer { // This is only used by a test which asserts that the initialization-tracking is correct. #[cfg(feature = "unit_test")] - pub fn initialized(&self) -> usize { + pub fn initialized(&self) -> bool { self.initialized } @@ -124,15 +124,16 @@ impl Buffer { let mut buf = BorrowedBuf::from(&mut *self.buf); // SAFETY: `self.filled` bytes will always have been initialized. - unsafe { - buf.set_init(self.initialized); + if self.initialized { + // SAFETY: only set after buf was fully initialized. + unsafe { buf.set_init() }; } reader.read_buf(buf.unfilled())?; self.pos = 0; self.filled = buf.len(); - self.initialized = buf.init_len(); + self.initialized = buf.is_init(); } Ok(self.buffer()) } diff --git a/sgx_tstd/src/io/buffered/tests.rs b/sgx_tstd/src/io/buffered/tests.rs index 5c72f0eef..eb1d3a1c5 100644 --- a/sgx_tstd/src/io/buffered/tests.rs +++ b/sgx_tstd/src/io/buffered/tests.rs @@ -84,7 +84,7 @@ fn test_buffered_reader_read_buf() { let mut reader = BufReader::with_capacity(2, inner); let buf: &mut [_] = &mut [MaybeUninit::uninit(); 3]; - let mut buf: BorrowedBuf<'_> = buf.into(); + let mut buf: BorrowedBuf<'_, u8> = buf.into(); reader.read_buf(buf.unfilled()).unwrap(); @@ -92,7 +92,7 @@ fn test_buffered_reader_read_buf() { assert_eq!(reader.buffer(), []); let buf: &mut [_] = &mut [MaybeUninit::uninit(); 2]; - let mut buf: BorrowedBuf<'_> = buf.into(); + let mut buf: BorrowedBuf<'_, u8> = buf.into(); reader.read_buf(buf.unfilled()).unwrap(); @@ -100,7 +100,7 @@ fn test_buffered_reader_read_buf() { assert_eq!(reader.buffer(), []); let buf: &mut [_] = &mut [MaybeUninit::uninit(); 1]; - let mut buf: BorrowedBuf<'_> = buf.into(); + let mut buf: BorrowedBuf<'_, u8> = buf.into(); reader.read_buf(buf.unfilled()).unwrap(); @@ -108,7 +108,7 @@ fn test_buffered_reader_read_buf() { assert_eq!(reader.buffer(), [3]); let buf: &mut [_] = &mut [MaybeUninit::uninit(); 3]; - let mut buf: BorrowedBuf<'_> = buf.into(); + let mut buf: BorrowedBuf<'_, u8> = buf.into(); reader.read_buf(buf.unfilled()).unwrap(); diff --git a/sgx_tstd/src/io/copy.rs b/sgx_tstd/src/io/copy.rs index 6f30fde27..a4f2444ce 100644 --- a/sgx_tstd/src/io/copy.rs +++ b/sgx_tstd/src/io/copy.rs @@ -225,16 +225,10 @@ impl BufferedWriterSpec for BufWriter { } let mut len = 0; - let mut init = 0; loop { let buf = self.buffer_mut(); - let mut read_buf: BorrowedBuf<'_> = buf.spare_capacity_mut().into(); - - unsafe { - // SAFETY: init is either 0 or the init_len from the previous iteration. - read_buf.set_init(init); - } + let mut read_buf: BorrowedBuf<'_, u8> = buf.spare_capacity_mut().into(); if read_buf.capacity() >= DEFAULT_BUF_SIZE { let mut cursor = read_buf.unfilled(); @@ -246,7 +240,6 @@ impl BufferedWriterSpec for BufWriter { return Ok(len); } - init = read_buf.init_len() - bytes_read; len += bytes_read as u64; // SAFETY: BorrowedBuf guarantees all of its filled bytes are init @@ -260,7 +253,6 @@ impl BufferedWriterSpec for BufWriter { } } else { self.flush_buf()?; - init = 0; } } } @@ -290,16 +282,11 @@ impl BufferedWriterSpec for Vec { loop { self.reserve(DEFAULT_BUF_SIZE); - let mut initialized_spare_capacity = 0; loop { let buf = self.spare_capacity_mut(); let read_size = min(max_read_size, buf.len()); let mut buf = BorrowedBuf::from(&mut buf[..read_size]); - // SAFETY: init is either 0 or the init_len from the previous iteration. - unsafe { - buf.set_init(initialized_spare_capacity); - } match reader.read_buf(buf.unfilled()) { Ok(()) => { let bytes_read = buf.len(); @@ -310,7 +297,7 @@ impl BufferedWriterSpec for Vec { } // the reader is returning short reads but it doesn't call ensure_init() - if buf.init_len() < buf.capacity() { + if !buf.is_init() { max_read_size = usize::MAX; } // the reader hasn't returned short reads so far @@ -318,7 +305,6 @@ impl BufferedWriterSpec for Vec { max_read_size *= 2; } - initialized_spare_capacity = buf.init_len() - bytes_read; bytes += bytes_read as u64; // SAFETY: BorrowedBuf guarantees all of its filled bytes are init // and the number of read bytes can't exceed the spare capacity since @@ -343,7 +329,7 @@ fn stack_buffer_copy( writer: &mut W, ) -> Result { let buf: &mut [_] = &mut [MaybeUninit::uninit(); DEFAULT_BUF_SIZE]; - let mut buf: BorrowedBuf<'_> = buf.into(); + let mut buf: BorrowedBuf<'_, u8> = buf.into(); let mut len = 0; diff --git a/sgx_tstd/src/io/cursor.rs b/sgx_tstd/src/io/cursor.rs index 9f8da589d..a5ba58b2b 100644 --- a/sgx_tstd/src/io/cursor.rs +++ b/sgx_tstd/src/io/cursor.rs @@ -325,7 +325,7 @@ where Ok(n) } - fn read_buf(&mut self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, mut cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { let prev_written = cursor.written(); Read::read_buf(&mut self.fill_buf()?, cursor.reborrow())?; diff --git a/sgx_tstd/src/io/impls.rs b/sgx_tstd/src/io/impls.rs index 8e7f61a1f..a421001ad 100644 --- a/sgx_tstd/src/io/impls.rs +++ b/sgx_tstd/src/io/impls.rs @@ -38,7 +38,7 @@ impl Read for &mut R { } #[inline] - fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { (**self).read_buf(cursor) } @@ -141,7 +141,7 @@ impl Read for Box { } #[inline] - fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { (**self).read_buf(cursor) } @@ -264,7 +264,7 @@ impl Read for &[u8] { } #[inline] - fn read_buf(&mut self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, mut cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { let amt = cmp::min(cursor.capacity(), self.len()); let (a, b) = self.split_at(amt); @@ -450,7 +450,7 @@ impl Read for VecDeque { } #[inline] - fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { let (ref mut front, _) = self.as_slices(); let n = cmp::min(cursor.capacity(), front.len()); Read::read_buf(front, cursor)?; @@ -538,7 +538,7 @@ impl Write for VecDeque { } } -impl<'a> io::Write for core::io::BorrowedCursor<'a> { +impl<'a> io::Write for core::io::BorrowedCursor<'a, u8> { fn write(&mut self, buf: &[u8]) -> io::Result { let amt = cmp::min(buf.len(), self.capacity()); self.append(&buf[..amt]); diff --git a/sgx_tstd/src/io/mod.rs b/sgx_tstd/src/io/mod.rs index b8fbb380e..da6426f55 100644 --- a/sgx_tstd/src/io/mod.rs +++ b/sgx_tstd/src/io/mod.rs @@ -420,64 +420,104 @@ pub(crate) fn default_read_to_end( let start_cap = buf.capacity(); // Optionally limit the maximum bytes read on each iteration. // This adds an arbitrary fiddle factor to allow for more data than we expect. - let max_read_size = - size_hint.and_then(|s| s.checked_add(1024)?.checked_next_multiple_of(DEFAULT_BUF_SIZE)); - - let mut initialized = 0; // Extra initialized bytes from previous loop iteration - loop { - if buf.len() == buf.capacity() { - buf.reserve(32); // buf is full, need more space + let mut max_read_size = size_hint + .and_then(|s| s.checked_add(1024)?.checked_next_multiple_of(DEFAULT_BUF_SIZE)) + .unwrap_or(DEFAULT_BUF_SIZE); + + const PROBE_SIZE: usize = 32; + + fn small_probe_read(r: &mut R, buf: &mut Vec) -> Result { + let mut probe = [0u8; PROBE_SIZE]; + + loop { + match r.read(&mut probe) { + Ok(n) => { + // there is no way to recover from allocation failure here + // because the data has already been read. + buf.extend_from_slice(&probe[..n]); + return Ok(n); + } + Err(ref e) if e.is_interrupted() => continue, + Err(e) => return Err(e), + } } + } - let mut spare = buf.spare_capacity_mut(); - if let Some(size) = max_read_size { - let len = cmp::min(spare.len(), size); - spare = &mut spare[..len] - } - let mut read_buf: BorrowedBuf<'_> = spare.into(); + // avoid inflating empty/small vecs before we have determined that there's anything to read + if (size_hint.is_none() || size_hint == Some(0)) && buf.capacity() - buf.len() < PROBE_SIZE { + let read = small_probe_read(r, buf)?; - // SAFETY: These bytes were initialized but not filled in the previous loop - unsafe { - read_buf.set_init(initialized); + if read == 0 { + return Ok(0); } + } - let mut cursor = read_buf.unfilled(); - match r.read_buf(cursor.reborrow()) { - Ok(()) => {} - Err(e) if e.is_interrupted() => continue, - Err(e) => return Err(e), + loop { + if buf.len() == buf.capacity() && buf.capacity() == start_cap { + // The buffer might be an exact fit. Let's read into a probe buffer + // and see if it returns `Ok(0)`. If so, we've avoided an + // unnecessary doubling of the capacity. But if not, append the + // probe buffer to the primary buffer and let its capacity grow. + let read = small_probe_read(r, buf)?; + + if read == 0 { + return Ok(buf.len() - start_len); + } } - if cursor.written() == 0 { - return Ok(buf.len() - start_len); + if buf.len() == buf.capacity() { + // buf is full, need more space + buf.try_reserve(PROBE_SIZE).map_err(|_| crate::io::ErrorKind::OutOfMemory)?; } - // store how much was initialized but not filled - initialized = cursor.init_mut().len(); + let mut spare = buf.spare_capacity_mut(); + let buf_len = cmp::min(spare.len(), max_read_size); + spare = &mut spare[..buf_len]; + let mut read_buf: BorrowedBuf<'_, u8> = spare.into(); + + // Note that we don't track already initialized bytes here, but this is fine + // because we explicitly limit the read size + let mut cursor = read_buf.unfilled(); + let result = loop { + match r.read_buf(cursor.reborrow()) { + Err(e) if e.is_interrupted() => continue, + // Do not stop now in case of error: we might have received both data + // and an error + res => break res, + } + }; + + let bytes_read = cursor.written(); + let is_init = read_buf.is_init(); // SAFETY: BorrowedBuf's invariants mean this much memory is initialized. unsafe { - let new_len = read_buf.filled().len() + buf.len(); + let new_len = bytes_read + buf.len(); buf.set_len(new_len); } - if buf.len() == buf.capacity() && buf.capacity() == start_cap { - // The buffer might be an exact fit. Let's read into a probe buffer - // and see if it returns `Ok(0)`. If so, we've avoided an - // unnecessary doubling of the capacity. But if not, append the - // probe buffer to the primary buffer and let its capacity grow. - let mut probe = [0u8; 32]; - - loop { - match r.read(&mut probe) { - Ok(0) => return Ok(buf.len() - start_len), - Ok(n) => { - buf.extend_from_slice(&probe[..n]); - break; - } - Err(ref e) if e.is_interrupted() => continue, - Err(e) => return Err(e), - } + // Now that all data is pushed to the vector, we can fail without data loss + result?; + + if bytes_read == 0 { + return Ok(buf.len() - start_len); + } + + // Use heuristics to determine the max read size if no initial size hint was provided + if size_hint.is_none() { + // The reader is returning short reads but it doesn't call ensure_init(). + // In that case we no longer need to restrict read sizes to avoid + // initialization costs. + // When reading from disk we usually don't get any short reads except at EOF. + // So we wait for at least 2 short reads before uncapping the read buffer; + // this helps with the Windows issue. + if !is_init { + max_read_size = usize::MAX; + } + // we have passed a larger buffer than previously and the + // reader still hasn't returned a short read + else if buf_len >= max_read_size && bytes_read == buf_len { + max_read_size = max_read_size.saturating_mul(2); } } } @@ -534,12 +574,12 @@ pub(crate) fn default_read_exact(this: &mut R, mut buf: &mut [ } } -pub(crate) fn default_read_buf(read: F, mut cursor: BorrowedCursor<'_>) -> Result<()> +pub(crate) fn default_read_buf(read: F, mut cursor: BorrowedCursor<'_, u8>) -> Result<()> where F: FnOnce(&mut [u8]) -> Result, { - let n = read(cursor.ensure_init().init_mut())?; - cursor.advance(n); + let n = read(cursor.ensure_init())?; + unsafe { cursor.advance(n) }; Ok(()) } @@ -873,7 +913,7 @@ pub trait Read { /// with uninitialized buffers. The new data will be appended to any existing contents of `buf`. /// /// The default implementation delegates to `read`. - fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<()> { + fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<()> { default_read_buf(|b| self.read(b), buf) } @@ -895,7 +935,7 @@ pub trait Read { /// returns. /// /// If this function returns an error, all bytes read will be appended to `cursor`. - fn read_buf_exact(&mut self, mut cursor: BorrowedCursor<'_>) -> Result<()> { + fn read_buf_exact(&mut self, mut cursor: BorrowedCursor<'_, u8>) -> Result<()> { while cursor.capacity() > 0 { let prev_written = cursor.written(); match self.read_buf(cursor.reborrow()) { @@ -2611,51 +2651,61 @@ impl Read for Take { Ok(n) } - fn read_buf(&mut self, mut buf: BorrowedCursor<'_>) -> Result<()> { + fn read_buf(&mut self, mut buf: BorrowedCursor<'_, u8>) -> Result<()> { // Don't call into inner reader at all at EOF because it may still block if self.limit == 0 { return Ok(()); } - if self.limit <= buf.capacity() as u64 { - // if we just use an as cast to convert, limit may wrap around on a 32 bit target - let limit = cmp::min(self.limit, usize::MAX as u64) as usize; + if self.limit < buf.capacity() as u64 { + // The condition above guarantees that `self.limit` fits in `usize`. + let limit = self.limit as usize; - let extra_init = cmp::min(limit as usize, buf.init_mut().len()); + let is_init = buf.is_init(); // SAFETY: no uninit data is written to ibuf - let ibuf = unsafe { &mut buf.as_mut()[..limit] }; + let mut sliced_buf = BorrowedBuf::from(unsafe { &mut buf.as_mut()[..limit] }); - let mut sliced_buf: BorrowedBuf<'_> = ibuf.into(); - - // SAFETY: extra_init bytes of ibuf are known to be initialized - unsafe { - sliced_buf.set_init(extra_init); + if is_init { + // SAFETY: `sliced_buf` is a subslice of `buf`, so if `buf` was initialized then + // `sliced_buf` is. + unsafe { sliced_buf.set_init() }; } - let mut cursor = sliced_buf.unfilled(); - self.inner.read_buf(cursor.reborrow())?; + let result = self.inner.read_buf(sliced_buf.unfilled()); - let new_init = cursor.init_mut().len(); + let did_init_up_to_limit = sliced_buf.is_init(); let filled = sliced_buf.len(); - // cursor / sliced_buf / ibuf must drop here + // sliced_buf must drop here + + // Avoid accidentally quadratic behaviour by initializing the whole + // cursor if only part of it was initialized. + if did_init_up_to_limit && !is_init { + // SAFETY: No uninit data will be written. + let unfilled_before_advance = unsafe { buf.as_mut() }; + + unfilled_before_advance[limit..].write_filled(0); + + // SAFETY: `unfilled_before_advance[..limit]` was initialized by `T::read_buf`, and + // `unfilled_before_advance[limit..]` was just initialized. + unsafe { buf.set_init() }; + } unsafe { - // SAFETY: filled bytes have been filled and therefore initialized + // SAFETY: filled bytes have been filled buf.advance(filled); - // SAFETY: new_init bytes of buf's unfilled buffer have been initialized - buf.set_init(new_init); } self.limit -= filled as u64; + + result } else { let written = buf.written(); - self.inner.read_buf(buf.reborrow())?; + let result = self.inner.read_buf(buf.reborrow()); self.limit -= (buf.written() - written) as u64; + result } - - Ok(()) } } diff --git a/sgx_tstd/src/io/stdio.rs b/sgx_tstd/src/io/stdio.rs index 8a02e6145..62b73db03 100644 --- a/sgx_tstd/src/io/stdio.rs +++ b/sgx_tstd/src/io/stdio.rs @@ -109,7 +109,7 @@ impl Read for StdinRaw { handle_ebadf(self.0.read(buf), 0) } - fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> io::Result<()> { handle_ebadf(self.0.read_buf(buf), ()) } @@ -426,7 +426,7 @@ impl Read for Stdin { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.lock().read(buf) } - fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> io::Result<()> { self.lock().read_buf(buf) } fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { @@ -459,7 +459,7 @@ impl Read for StdinLock<'_> { self.inner.read(buf) } - fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> io::Result<()> { self.inner.read_buf(buf) } diff --git a/sgx_tstd/src/io/tests.rs b/sgx_tstd/src/io/tests.rs index edaa5ee6c..8d6d9e4a7 100644 --- a/sgx_tstd/src/io/tests.rs +++ b/sgx_tstd/src/io/tests.rs @@ -179,7 +179,7 @@ fn read_exact_slice() { #[test_case] fn read_buf_exact() { let buf: &mut [_] = &mut [0; 4]; - let mut buf: BorrowedBuf<'_> = buf.into(); + let mut buf: BorrowedBuf<'_, u8> = buf.into(); let mut c = Cursor::new(&b""[..]); assert_eq!(c.read_buf_exact(buf.unfilled()).unwrap_err().kind(), io::ErrorKind::UnexpectedEof); @@ -624,7 +624,7 @@ fn bench_take_read_buf(b: &mut Bencher) { b.iter(|| { let buf: &mut [_] = &mut [MaybeUninit::uninit(); 64]; - let mut buf: BorrowedBuf<'_> = buf.into(); + let mut buf: BorrowedBuf<'_, u8> = buf.into(); [255; 128].take(64).read_buf(buf.unfilled()).unwrap(); }); diff --git a/sgx_tstd/src/io/util.rs b/sgx_tstd/src/io/util.rs index 0bc7a7470..f13a0170f 100644 --- a/sgx_tstd/src/io/util.rs +++ b/sgx_tstd/src/io/util.rs @@ -77,7 +77,7 @@ impl Read for Empty { } #[inline] - fn read_buf(&mut self, _cursor: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, _cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { Ok(()) } } @@ -194,7 +194,7 @@ impl Read for Repeat { Ok(buf.len()) } - fn read_buf(&mut self, mut buf: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, mut buf: BorrowedCursor<'_, u8>) -> io::Result<()> { // SAFETY: No uninit bytes are being written for slot in unsafe { buf.as_mut() } { slot.write(self.byte); @@ -202,7 +202,7 @@ impl Read for Repeat { let remaining = buf.capacity(); - buf.advance(remaining); + unsafe { buf.advance(remaining) }; Ok(()) } diff --git a/sgx_tstd/src/io/util/tests.rs b/sgx_tstd/src/io/util/tests.rs index 279f6f85c..cb5e8d6d6 100644 --- a/sgx_tstd/src/io/util/tests.rs +++ b/sgx_tstd/src/io/util/tests.rs @@ -40,25 +40,25 @@ fn empty_reads() { assert_eq!(Read::by_ref(&mut e).read(&mut [0; 1024]).unwrap(), 0); let buf: &mut [MaybeUninit<_>] = &mut []; - let mut buf: BorrowedBuf<'_> = buf.into(); + let mut buf: BorrowedBuf<'_, u8> = buf.into(); e.read_buf(buf.unfilled()).unwrap(); assert_eq!(buf.len(), 0); assert_eq!(buf.init_len(), 0); let buf: &mut [_] = &mut [MaybeUninit::uninit()]; - let mut buf: BorrowedBuf<'_> = buf.into(); + let mut buf: BorrowedBuf<'_, u8> = buf.into(); e.read_buf(buf.unfilled()).unwrap(); assert_eq!(buf.len(), 0); assert_eq!(buf.init_len(), 0); let buf: &mut [_] = &mut [MaybeUninit::uninit(); 1024]; - let mut buf: BorrowedBuf<'_> = buf.into(); + let mut buf: BorrowedBuf<'_, u8> = buf.into(); e.read_buf(buf.unfilled()).unwrap(); assert_eq!(buf.len(), 0); assert_eq!(buf.init_len(), 0); let buf: &mut [_] = &mut [MaybeUninit::uninit(); 1024]; - let mut buf: BorrowedBuf<'_> = buf.into(); + let mut buf: BorrowedBuf<'_, u8> = buf.into(); Read::by_ref(&mut e).read_buf(buf.unfilled()).unwrap(); assert_eq!(buf.len(), 0); assert_eq!(buf.init_len(), 0); diff --git a/sgx_tstd/src/lib.rs b/sgx_tstd/src/lib.rs index 301271ddd..a9ba6eac4 100644 --- a/sgx_tstd/src/lib.rs +++ b/sgx_tstd/src/lib.rs @@ -66,7 +66,6 @@ #![feature(const_trait_impl)] #![feature(decl_macro)] #![feature(dropck_eyepatch)] -#![feature(if_let_guard)] #![feature(lang_items)] #![feature(min_specialization)] #![feature(must_not_suspend)] @@ -86,6 +85,9 @@ #![feature(char_internals)] #![feature(core_intrinsics)] #![feature(core_io_borrowed_buf)] +#![feature(borrowed_buf_init)] +#![feature(core_io)] +#![feature(core_io_internals)] #![feature(duration_constants)] #![feature(error_generic_member_access)] #![feature(error_iter)] @@ -97,7 +99,7 @@ #![feature(hasher_prefixfree_extras)] #![feature(hashmap_internals)] #![feature(ip)] -#![feature(maybe_uninit_slice)] +#![feature(maybe_uninit_fill)] #![feature(panic_can_unwind)] #![feature(panic_internals)] #![feature(ptr_as_uninit)] @@ -123,7 +125,6 @@ // // Only for re-exporting: // tidy-alphabetical-start -#![feature(assert_matches)] #![feature(async_iterator)] #![feature(c_variadic)] #![feature(cfg_accessible)] diff --git a/sgx_tstd/src/net/tcp.rs b/sgx_tstd/src/net/tcp.rs index 4d60a3163..494c6e9fb 100644 --- a/sgx_tstd/src/net/tcp.rs +++ b/sgx_tstd/src/net/tcp.rs @@ -610,7 +610,7 @@ impl Read for TcpStream { self.0.read(buf) } - fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> io::Result<()> { self.0.read_buf(buf) } @@ -648,7 +648,7 @@ impl Read for &TcpStream { self.0.read(buf) } - fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> io::Result<()> { self.0.read_buf(buf) } diff --git a/sgx_tstd/src/os/fd/owned.rs b/sgx_tstd/src/os/fd/owned.rs index 052bd9a3f..095fbfa5f 100644 --- a/sgx_tstd/src/os/fd/owned.rs +++ b/sgx_tstd/src/os/fd/owned.rs @@ -43,11 +43,9 @@ use crate::sys_common::{AsInner, FromInner, IntoInner}; /// descriptor, which is then borrowed under the same lifetime. #[derive(Copy, Clone)] #[repr(transparent)] -#[rustc_layout_scalar_valid_range_start(0)] // libstd/os/raw/mod.rs assures me that every libstd-supported platform has a // 32-bit c_int. Below is -2, in two's complement, but that only works out // because c_int is 32 bits. -#[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)] pub struct BorrowedFd<'fd> { fd: RawFd, _phantom: PhantomData<&'fd OwnedFd>, @@ -63,11 +61,9 @@ pub struct BorrowedFd<'fd> { /// passed as a consumed argument or returned as an owned value, and it never /// has the value `-1`. #[repr(transparent)] -#[rustc_layout_scalar_valid_range_start(0)] // libstd/os/raw/mod.rs assures me that every libstd-supported platform has a // 32-bit c_int. Below is -2, in two's complement, but that only works out // because c_int is 32 bits. -#[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)] pub struct OwnedFd { fd: RawFd, } @@ -83,7 +79,7 @@ impl BorrowedFd<'_> { pub const unsafe fn borrow_raw(fd: RawFd) -> Self { assert!(fd != u32::MAX as RawFd); // SAFETY: we just asserted that the value is in the valid range and isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned) - unsafe { Self { fd, _phantom: PhantomData } } + Self { fd, _phantom: PhantomData } } } @@ -146,7 +142,7 @@ impl FromRawFd for OwnedFd { unsafe fn from_raw_fd(fd: RawFd) -> Self { assert_ne!(fd, u32::MAX as RawFd); // SAFETY: we just asserted that the value is in the valid range and isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned) - unsafe { Self { fd } } + Self { fd } } } diff --git a/sgx_tstd/src/panicking.rs b/sgx_tstd/src/panicking.rs index 038d9cc17..e8b529d2f 100644 --- a/sgx_tstd/src/panicking.rs +++ b/sgx_tstd/src/panicking.rs @@ -478,7 +478,7 @@ pub unsafe fn r#try R>(f: F) -> Result> // - `do_catch`, the second argument, can be called with the `data_ptr` as well. // See their safety preconditions for more information unsafe { - return if intrinsics::catch_unwind(do_call::, data_ptr, do_catch::) == 0 { + return if !intrinsics::catch_unwind(do_call::, data_ptr, do_catch::) { Ok(ManuallyDrop::into_inner(data.r)) } else { Err(ManuallyDrop::into_inner(data.p)) diff --git a/sgx_tstd/src/prelude/v1.rs b/sgx_tstd/src/prelude/v1.rs index 305c11fb7..89316bae6 100644 --- a/sgx_tstd/src/prelude/v1.rs +++ b/sgx_tstd/src/prelude/v1.rs @@ -46,7 +46,7 @@ pub use crate::result::Result::{self, Err, Ok}; #[doc(no_inline)] pub use core::prelude::v1::{ assert, cfg, column, compile_error, concat, env, file, format_args, - format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env, + include, include_bytes, include_str, line, log_syntax, module_path, option_env, stringify, trace_macros, Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, }; diff --git a/sgx_tstd/src/process.rs b/sgx_tstd/src/process.rs index a4ce47308..c9c9a3140 100644 --- a/sgx_tstd/src/process.rs +++ b/sgx_tstd/src/process.rs @@ -360,7 +360,7 @@ impl Read for ChildStdout { self.inner.read(buf) } - fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> io::Result<()> { self.inner.read_buf(buf) } @@ -428,7 +428,7 @@ impl Read for ChildStderr { self.inner.read(buf) } - fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> io::Result<()> { self.inner.read_buf(buf) } diff --git a/sgx_tstd/src/sync/mod.rs b/sgx_tstd/src/sync/mod.rs index 3496aa75a..085289a2f 100644 --- a/sgx_tstd/src/sync/mod.rs +++ b/sgx_tstd/src/sync/mod.rs @@ -171,7 +171,6 @@ pub use alloc_crate::sync::{Arc, Weak}; pub use core::sync::atomic; -pub use core::sync::Exclusive; pub use self::barrier::{Barrier, BarrierWaitResult}; pub use self::condvar::{Condvar, WaitTimeoutResult}; diff --git a/sgx_tstd/src/sys/common/thread_local/fast_local.rs b/sgx_tstd/src/sys/common/thread_local/fast_local.rs index 3b15fa3fe..674861221 100644 --- a/sgx_tstd/src/sys/common/thread_local/fast_local.rs +++ b/sgx_tstd/src/sys/common/thread_local/fast_local.rs @@ -23,7 +23,7 @@ use crate::{fmt, mem, panic}; #[allow_internal_unstable(thread_local_internals, cfg_target_thread_local, thread_local)] #[allow_internal_unsafe] -#[rustc_macro_transparency = "semitransparent"] +#[rustc_macro_transparency = "semiopaque"] pub macro thread_local_inner { // used to generate the `LocalKey` value for const-initialized thread locals (@key $t:ty, const $init:expr) => {{ diff --git a/sgx_tstd/src/sys/common/thread_local/os_local.rs b/sgx_tstd/src/sys/common/thread_local/os_local.rs index 22f0224fd..35e30b69a 100644 --- a/sgx_tstd/src/sys/common/thread_local/os_local.rs +++ b/sgx_tstd/src/sys/common/thread_local/os_local.rs @@ -23,7 +23,7 @@ use crate::{fmt, marker, panic, ptr}; #[allow_internal_unstable(thread_local_internals)] #[allow_internal_unsafe] -#[rustc_macro_transparency = "semitransparent"] +#[rustc_macro_transparency = "semiopaque"] pub macro thread_local_inner { // used to generate the `LocalKey` value for const-initialized thread locals (@key $t:ty, const $init:expr) => {{ diff --git a/sgx_tstd/src/sys/fd.rs b/sgx_tstd/src/sys/fd.rs index 080d5fca5..f151a5690 100644 --- a/sgx_tstd/src/sys/fd.rs +++ b/sgx_tstd/src/sys/fd.rs @@ -60,12 +60,12 @@ impl FileDesc { cvt_ocall(unsafe { libc::pread64(self.as_raw_fd(), buf, offset as _) }) } - pub fn read_buf(&self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> { + pub fn read_buf(&self, mut cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { let ret = cvt_ocall(unsafe { libc::read(self.as_raw_fd(), cursor.as_mut().assume_init_mut()) })?; - cursor.advance(ret); + unsafe { cursor.advance(ret) }; Ok(()) } @@ -147,7 +147,7 @@ impl<'a> Read for &'a FileDesc { (**self).read(buf) } - fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { (**self).read_buf(cursor) } diff --git a/sgx_tstd/src/sys/fs.rs b/sgx_tstd/src/sys/fs.rs index 206bd86e1..2c5e86435 100644 --- a/sgx_tstd/src/sys/fs.rs +++ b/sgx_tstd/src/sys/fs.rs @@ -455,7 +455,7 @@ impl File { self.0.read_at(buf, offset) } - pub fn read_buf(&self, cursor: BorrowedCursor<'_>) -> io::Result<()> { + pub fn read_buf(&self, cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { self.0.read_buf(cursor) } diff --git a/sgx_tstd/src/sys/net.rs b/sgx_tstd/src/sys/net.rs index 36173f253..28f2062f5 100644 --- a/sgx_tstd/src/sys/net.rs +++ b/sgx_tstd/src/sys/net.rs @@ -186,7 +186,7 @@ impl Socket { self.0.duplicate().map(Socket) } - fn recv_with_flags(&self, mut buf: BorrowedCursor<'_>, flags: c_int) -> io::Result<()> { + fn recv_with_flags(&self, mut buf: BorrowedCursor<'_, u8>, flags: c_int) -> io::Result<()> { let ret = cvt_ocall(unsafe { libc::recv( self.as_raw_fd(), @@ -195,7 +195,7 @@ impl Socket { ) })?; - buf.advance(ret as usize); + unsafe { buf.advance(ret as usize) }; Ok(()) } @@ -212,7 +212,7 @@ impl Socket { Ok(buf.len()) } - pub fn read_buf(&self, buf: BorrowedCursor<'_>) -> io::Result<()> { + pub fn read_buf(&self, buf: BorrowedCursor<'_, u8>) -> io::Result<()> { self.recv_with_flags(buf, 0) } diff --git a/sgx_tstd/src/sys/pipe.rs b/sgx_tstd/src/sys/pipe.rs index fa0fae426..32f38794c 100644 --- a/sgx_tstd/src/sys/pipe.rs +++ b/sgx_tstd/src/sys/pipe.rs @@ -42,7 +42,7 @@ impl AnonPipe { self.0.read(buf) } - pub fn read_buf(&self, buf: BorrowedCursor<'_>) -> io::Result<()> { + pub fn read_buf(&self, buf: BorrowedCursor<'_, u8>) -> io::Result<()> { self.0.read_buf(buf) } diff --git a/sgx_tstd/src/sys/stdio.rs b/sgx_tstd/src/sys/stdio.rs index 88cff4771..ba90614e2 100644 --- a/sgx_tstd/src/sys/stdio.rs +++ b/sgx_tstd/src/sys/stdio.rs @@ -37,7 +37,7 @@ impl io::Read for Stdin { unsafe { ManuallyDrop::new(FileDesc::from_raw_fd(libc::STDIN_FILENO)).read(buf) } } - fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> { + fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> io::Result<()> { unsafe { ManuallyDrop::new(FileDesc::from_raw_fd(libc::STDIN_FILENO)).read_buf(buf) } } diff --git a/sgx_tstd/src/sys/time.rs b/sgx_tstd/src/sys/time.rs index bd6c6a38f..6663e4bea 100644 --- a/sgx_tstd/src/sys/time.rs +++ b/sgx_tstd/src/sys/time.rs @@ -26,8 +26,6 @@ pub const UNIX_EPOCH: SystemTime = SystemTime { t: Timespec::zero() }; #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] -#[rustc_layout_scalar_valid_range_start(0)] -#[rustc_layout_scalar_valid_range_end(999_999_999)] struct Nanoseconds(u32); #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -86,7 +84,7 @@ impl Timespec { const fn new(tv_sec: i64, tv_nsec: i64) -> Timespec { assert!(tv_nsec >= 0 && tv_nsec < NSEC_PER_SEC as i64); // SAFETY: The assert above checks tv_nsec is within the valid range - Timespec { tv_sec, tv_nsec: unsafe { Nanoseconds(tv_nsec as u32) } } + Timespec { tv_sec, tv_nsec: Nanoseconds(tv_nsec as u32) } } pub fn now(clock: libc::clockid_t) -> Timespec { diff --git a/sgx_tstd/src/sys/unsupported/pipe.rs b/sgx_tstd/src/sys/unsupported/pipe.rs index eda55a4d6..b75352414 100644 --- a/sgx_tstd/src/sys/unsupported/pipe.rs +++ b/sgx_tstd/src/sys/unsupported/pipe.rs @@ -32,7 +32,7 @@ impl AnonPipe { unsupported() } - pub fn read_buf(&self, _buf: BorrowedCursor<'_>) -> io::Result<()> { + pub fn read_buf(&self, _buf: BorrowedCursor<'_, u8>) -> io::Result<()> { unsupported() } diff --git a/sgx_tstd/src/sys_common/net.rs b/sgx_tstd/src/sys_common/net.rs index d4142b116..5d7b60b34 100644 --- a/sgx_tstd/src/sys_common/net.rs +++ b/sgx_tstd/src/sys_common/net.rs @@ -226,7 +226,7 @@ impl TcpStream { self.inner.read(buf) } - pub fn read_buf(&self, buf: BorrowedCursor<'_>) -> io::Result<()> { + pub fn read_buf(&self, buf: BorrowedCursor<'_, u8>) -> io::Result<()> { self.inner.read_buf(buf) } diff --git a/sgx_tstd/src/thread/mod.rs b/sgx_tstd/src/thread/mod.rs index bc4da3027..54620c9cb 100644 --- a/sgx_tstd/src/thread/mod.rs +++ b/sgx_tstd/src/thread/mod.rs @@ -534,7 +534,12 @@ impl Builder { let main = Box::new(main); // SAFETY: dynamic size and alignment of the Box remain the same. See below for why the // lifetime change is justified. - let main = unsafe { Box::from_raw(Box::into_raw(main) as *mut (dyn FnOnce() + 'static)) }; + // raw-pointer `as` casts can no longer extend trait-object lifetimes (rust#141402); + // unsize with the natural lifetime, then transmute the lifetime to 'static. + let main: *mut (dyn FnOnce() + '_) = Box::into_raw(main); + let main = unsafe { + Box::from_raw(crate::mem::transmute::<_, *mut (dyn FnOnce() + 'static)>(main)) + }; Ok(JoinInner { // SAFETY: From b34920bd4cf40aad94ac1c0b94d4c50a015e563b Mon Sep 17 00:00:00 2001 From: bfoing <40759640+bfoing@users.noreply.github.com> Date: Mon, 22 Jun 2026 12:30:32 +0100 Subject: [PATCH 32/34] fix(sgx_tstd): sync prelude macro re-exports with nightly-2026-06-21 std The new std prelude re-exports an expanded macro set; sgx_tstd was missing assert_eq/assert_ne/debug_assert{,_eq,_ne}/matches/todo/try/unimplemented/ unreachable/write/writeln. Downstream crates built with the `std` feature (e.g. minimal-lexical via nom) failed with "cannot find macro debug_assert". Surfaced by the enclave-os-mini integration build; sysroot-only builds did not exercise it. --- sgx_tstd/src/prelude/v1.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sgx_tstd/src/prelude/v1.rs b/sgx_tstd/src/prelude/v1.rs index 89316bae6..279e5de6d 100644 --- a/sgx_tstd/src/prelude/v1.rs +++ b/sgx_tstd/src/prelude/v1.rs @@ -45,9 +45,11 @@ pub use crate::result::Result::{self, Err, Ok}; #[allow(deprecated)] #[doc(no_inline)] pub use core::prelude::v1::{ - assert, cfg, column, compile_error, concat, env, file, format_args, - include, include_bytes, include_str, line, log_syntax, module_path, option_env, - stringify, trace_macros, Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, + assert, assert_eq, assert_ne, cfg, column, compile_error, concat, debug_assert, + debug_assert_eq, debug_assert_ne, env, file, format_args, include, include_bytes, + include_str, line, log_syntax, matches, module_path, option_env, stringify, todo, + r#try, trace_macros, unimplemented, unreachable, write, writeln, + Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, }; #[doc(no_inline)] From c328dad91701863c68973d598f8d8796cff85150 Mon Sep 17 00:00:00 2001 From: bfoing <40759640+bfoing@users.noreply.github.com> Date: Mon, 22 Jun 2026 12:36:19 +0100 Subject: [PATCH 33/34] fix(sgx_tstd): export std-defined macros (panic/vec/format/print/...) in prelude The prelude never re-exported std's own macros, so downstream crates built with the `std` feature could not resolve `panic!` (reached via `debug_assert!`), `vec!`, `format!`, etc. unqualified. Add them, using std's `ambiguous_macros_only` shadowing trick for `panic`/`vec` (which collide with the modules of the same name). Surfaced by minimal-lexical/num-traits in the enclave-os-mini build. --- sgx_tstd/src/prelude/v1.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sgx_tstd/src/prelude/v1.rs b/sgx_tstd/src/prelude/v1.rs index 279e5de6d..74cb45dd6 100644 --- a/sgx_tstd/src/prelude/v1.rs +++ b/sgx_tstd/src/prelude/v1.rs @@ -81,3 +81,22 @@ pub use crate::boxed::Box; pub use crate::string::{String, ToString}; #[doc(no_inline)] pub use crate::vec::Vec; + +// Std-defined macros that belong in the prelude (matching std::prelude::v1). +// Without these, downstream crates built with the `std` feature cannot resolve +// `panic!` (e.g. via `debug_assert!`), `vec!`, `format!`, etc. unqualified. +#[doc(no_inline)] +pub use crate::{dbg, eprint, eprintln, format, print, println, thread_local}; + +// `vec` and `panic` would be ambiguous with the modules of the same name, so +// shadow those modules with private empty modules and glob-export only the +// macros (this mirrors std's own prelude mechanism). +mod ambiguous_macros_only { + #[allow(hidden_glob_reexports)] + mod vec {} + #[allow(hidden_glob_reexports)] + mod panic {} + pub use crate::*; +} +#[doc(no_inline)] +pub use self::ambiguous_macros_only::{panic, vec}; From 2330b2a5aa8404d3c0a38e9d3a760144549f4943 Mon Sep 17 00:00:00 2001 From: bfoing <40759640+bfoing@users.noreply.github.com> Date: Mon, 22 Jun 2026 13:08:31 +0100 Subject: [PATCH 34/34] feat: support Intel SGX SDK 2.29 + remove EPID (sgx_key_exchange) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sgx_trts: bump MINOR_VERSION 27 -> 29 so the SDK 2.29 `sgx_sign` accepts the enclave ("SDK version is not correct" otherwise — the signer enforces a match between the trts-embedded version and the signing SDK). - Remove the EPID-based `sgx_key_exchange` crate (tkey/ukey_exchange): EPID remote attestation was removed from the Intel SGX SDK in 2.28, so it no longer links. DCAP/ECDSA attestation (sgx_dcap) is unaffected. --- sgx_key_exchange/message/Cargo.toml | 47 -- sgx_key_exchange/message/src/lib.rs | 47 -- sgx_key_exchange/message/src/message.rs | 513 ------------------ sgx_key_exchange/tkey_exchange/Cargo.toml | 44 -- sgx_key_exchange/tkey_exchange/src/capi.rs | 151 ------ sgx_key_exchange/tkey_exchange/src/lib.rs | 37 -- .../tkey_exchange/src/session/ecall.rs | 131 ----- .../tkey_exchange/src/session/initiator.rs | 276 ---------- .../tkey_exchange/src/session/manager.rs | 247 --------- .../tkey_exchange/src/session/mod.rs | 23 - sgx_key_exchange/ukey_exchange/Cargo.toml | 41 -- sgx_key_exchange/ukey_exchange/build.rs | 36 -- sgx_key_exchange/ukey_exchange/src/capi.rs | 199 ------- sgx_key_exchange/ukey_exchange/src/lib.rs | 34 -- sgx_key_exchange/ukey_exchange/src/session.rs | 254 --------- sgx_trts/src/version.rs | 2 +- 16 files changed, 1 insertion(+), 2081 deletions(-) delete mode 100644 sgx_key_exchange/message/Cargo.toml delete mode 100644 sgx_key_exchange/message/src/lib.rs delete mode 100644 sgx_key_exchange/message/src/message.rs delete mode 100644 sgx_key_exchange/tkey_exchange/Cargo.toml delete mode 100644 sgx_key_exchange/tkey_exchange/src/capi.rs delete mode 100644 sgx_key_exchange/tkey_exchange/src/lib.rs delete mode 100644 sgx_key_exchange/tkey_exchange/src/session/ecall.rs delete mode 100644 sgx_key_exchange/tkey_exchange/src/session/initiator.rs delete mode 100644 sgx_key_exchange/tkey_exchange/src/session/manager.rs delete mode 100644 sgx_key_exchange/tkey_exchange/src/session/mod.rs delete mode 100644 sgx_key_exchange/ukey_exchange/Cargo.toml delete mode 100644 sgx_key_exchange/ukey_exchange/build.rs delete mode 100644 sgx_key_exchange/ukey_exchange/src/capi.rs delete mode 100644 sgx_key_exchange/ukey_exchange/src/lib.rs delete mode 100644 sgx_key_exchange/ukey_exchange/src/session.rs diff --git a/sgx_key_exchange/message/Cargo.toml b/sgx_key_exchange/message/Cargo.toml deleted file mode 100644 index 0ef0bc0ce..000000000 --- a/sgx_key_exchange/message/Cargo.toml +++ /dev/null @@ -1,47 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -[package] -name = "sgx_ra_msg" -version = "2.0.0" -authors = ["The Teaclave Authors"] -repository = "https://github.com/apache/teaclave-sgx-sdk" -license-file = "LICENSE" -documentation = "https://teaclave.apache.org/sgx-sdk-docs/" -description = "Rust SGX SDK provides the ability to write Intel SGX applications in Rust Programming Language." -edition = "2021" - -[lib] -name = "sgx_ra_msg" -crate-type = ["rlib"] - -[features] -default = ["tmsg"] -tmsg = ["sgx_trts", "sgx_tcrypto"] -umsg = ["sgx_ucrypto"] -tserialize = ["tmsg", "sgx_tserialize", "sgx_tcrypto/tserialize"] -userialize = ["umsg", "sgx_userialize", "sgx_ucrypto/userialize"] - -[target.'cfg(not(target_vendor = "teaclave"))'.dependencies] -sgx_types = { path = "../../sgx_types" } -sgx_trts = { path = "../../sgx_trts", optional = true } - -[dependencies] -sgx_tcrypto = { path = "../../sgx_crypto", default-features = false, features = ["tcrypto"], package = 'sgx_crypto', optional = true } -sgx_ucrypto = { path = "../../sgx_crypto", default-features = false, features = ["ucrypto"], package = 'sgx_crypto', optional = true } -sgx_tserialize = { path = "../../sgx_serialize", default-features = false, features = ["tserialize", "derive"], package = 'sgx_serialize', optional = true } -sgx_userialize = { path = "../../sgx_serialize", default-features = false, features = ["userialize", "derive"], package = 'sgx_serialize', optional = true } diff --git a/sgx_key_exchange/message/src/lib.rs b/sgx_key_exchange/message/src/lib.rs deleted file mode 100644 index d61a73c16..000000000 --- a/sgx_key_exchange/message/src/lib.rs +++ /dev/null @@ -1,47 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#![no_std] -#![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] -#![feature(allocator_api)] - -#[cfg(all(feature = "tmsg", feature = "umsg"))] -compile_error!("feature \"tmsg\" and feature \"umsg\" cannot be enabled at the same time"); - -#[cfg(not(any(feature = "tmsg", feature = "umsg")))] -compile_error!("need to enable feature \"tmsg\" or feature \"umsg\""); - -#[macro_use] -extern crate alloc; - -#[macro_use] -extern crate sgx_types; - -#[cfg(feature = "tmsg")] -extern crate sgx_tcrypto as sgx_crypto; -#[cfg(feature = "tmsg")] -extern crate sgx_trts; -#[cfg(feature = "umsg")] -extern crate sgx_ucrypto as sgx_crypto; - -#[cfg(feature = "tserialize")] -extern crate sgx_tserialize as sgx_serialize; -#[cfg(feature = "userialize")] -extern crate sgx_userialize as sgx_serialize; - -mod message; -pub use message::*; diff --git a/sgx_key_exchange/message/src/message.rs b/sgx_key_exchange/message/src/message.rs deleted file mode 100644 index 8adb091b2..000000000 --- a/sgx_key_exchange/message/src/message.rs +++ /dev/null @@ -1,513 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 alloc::alloc::Global; -use alloc::boxed::Box; -use alloc::vec::{self, Vec}; -use core::alloc::Allocator; -use core::mem; -#[cfg(feature = "tmsg")] -use core::ptr; -use core::slice; -use sgx_crypto::ecc::{EcPrivateKey, EcPublicKey, EcSignature}; -use sgx_crypto::mac::AesCMac; -#[cfg(feature = "tmsg")] -use sgx_trts::trts::{is_within_enclave, is_within_host, EnclaveRange}; -use sgx_types::error::{SgxResult, SgxStatus}; -use sgx_types::memeq::ConstTimeEq; -use sgx_types::types::{ - AlignKey128bit, CRaMsg1, CRaMsg2, CRaMsg3, Ec256PublicKey, EpidGroupId, Mac, PsSecPropDesc, - Quote, QuoteSignType, Spid, -}; - -#[cfg(any(feature = "tserialize", feature = "userialize"))] -use sgx_serialize::{Deserialize, Serialize}; - -#[derive(Clone, Copy, Debug, Default)] -#[cfg_attr( - any(feature = "tserialize", feature = "userialize"), - derive(Deserialize, Serialize) -)] -pub struct RaMsg1 { - pub pub_key_a: EcPublicKey, - pub gid: EpidGroupId, -} - -impl_struct_ContiguousMemory! { - RaMsg1; -} -impl_asref_array! { - RaMsg1; -} - -#[derive(Clone, Debug, Default)] -#[cfg_attr( - any(feature = "tserialize", feature = "userialize"), - derive(Deserialize, Serialize) -)] -pub struct RaMsg2 { - pub pub_key_b: EcPublicKey, - pub spid: Spid, - pub quote_type: QuoteSignType, - pub kdf_id: u16, - pub sign_gb_ga: EcSignature, - pub mac: Mac, - pub sig_rl: Option>, -} - -#[derive(Clone, Debug, Default)] -#[cfg_attr( - any(feature = "tserialize", feature = "userialize"), - derive(Deserialize, Serialize) -)] -pub struct RaMsg3 { - pub mac: Mac, - pub pub_key_a: EcPublicKey, - pub ps_sec_prop: PsSecPropDesc, - pub quote: Box<[u8]>, -} - -impl RaMsg1 { - #[inline] - pub fn into_bytes(self) -> SgxResult> { - self.to_bytes() - } - - #[inline] - pub fn to_bytes(&self) -> SgxResult> { - self.to_bytes_in(Global) - } - - #[inline] - pub fn into_bytes_in(self, alloc: A) -> SgxResult> { - self.to_bytes_in(alloc) - } - - pub fn to_bytes_in(&self, alloc: A) -> SgxResult> { - let raw_msg: CRaMsg1 = self.into(); - Ok(raw_msg.as_ref().to_vec_in(alloc)) - } - - pub fn copy_to_slice(&self, bytes: &mut [u8]) -> SgxResult { - ensure!( - bytes.len() == mem::size_of::(), - SgxStatus::InvalidParameter - ); - - let raw_msg = unsafe { &mut *(bytes.as_mut_ptr() as *mut CRaMsg1) }; - raw_msg.g_a = self.pub_key_a.into(); - raw_msg.gid = self.gid; - Ok(()) - } - - #[inline] - pub fn from_bytes(bytes: Vec) -> SgxResult { - Self::from_slice(bytes.as_slice()) - } - - pub fn from_slice(bytes: &[u8]) -> SgxResult { - let raw_msg = unsafe { &*(bytes.as_ptr() as *const CRaMsg1) }; - Ok(raw_msg.into()) - } -} - -impl RaMsg2 { - pub fn gen_sign_and_cmac( - &mut self, - pub_key_a: &EcPublicKey, - sign_priv_key: &EcPrivateKey, - cmac_key: &AlignKey128bit, - ) -> SgxResult { - let keys: [Ec256PublicKey; 2] = [self.pub_key_b.into(), pub_key_a.into()]; - let sign_gb_ga = sign_priv_key.sign(&keys)?; - - let mut cmac = AesCMac::new(&cmac_key.key)?; - cmac.update(&self.pub_key_b)?; - cmac.update(&self.spid)?; - cmac.update(&(self.quote_type as u16))?; - cmac.update(&self.kdf_id)?; - cmac.update(&sign_gb_ga)?; - let mac = cmac.finalize()?; - - self.sign_gb_ga = sign_gb_ga; - self.mac = mac; - - Ok(()) - } - - pub fn verify_sign_and_cmac( - &self, - pub_key_a: &EcPublicKey, - verify_pub_key: &EcPublicKey, - cmac_key: &AlignKey128bit, - ) -> SgxResult { - let keys: [Ec256PublicKey; 2] = [self.pub_key_b.into(), pub_key_a.into()]; - let is_valid = verify_pub_key.verify(&keys, &self.sign_gb_ga)?; - ensure!(is_valid, SgxStatus::InvalidSignature); - - let mut cmac = AesCMac::new(&cmac_key.key)?; - cmac.update(&self.pub_key_b)?; - cmac.update(&self.spid)?; - cmac.update(&(self.quote_type as u16))?; - cmac.update(&self.kdf_id)?; - cmac.update(&self.sign_gb_ga)?; - let mac = cmac.finalize()?; - - ensure!(mac.ct_eq(&self.mac), SgxStatus::MacMismatch); - Ok(()) - } - - #[inline] - pub fn into_bytes(self) -> SgxResult> { - self.to_bytes() - } - - #[inline] - pub fn to_bytes(&self) -> SgxResult> { - self.to_bytes_in(Global) - } - - #[inline] - pub fn into_bytes_in(self, alloc: A) -> SgxResult> { - self.to_bytes_in(alloc) - } - - pub fn to_bytes_in(&self, alloc: A) -> SgxResult> { - let raw_len = self.get_raw_ize().ok_or(SgxStatus::InvalidParameter)?; - - let mut bytes = vec::from_elem_in(0_u8, raw_len as usize, alloc); - let header_len = mem::size_of::() as u32; - - let raw_msg = unsafe { &mut *(bytes.as_mut_ptr() as *mut CRaMsg2) }; - raw_msg.g_b = self.pub_key_b.into(); - raw_msg.spid = self.spid; - raw_msg.quote_type = self.quote_type as u16; - raw_msg.kdf_id = self.kdf_id; - raw_msg.sign_gb_ga = self.sign_gb_ga.into(); - raw_msg.mac = self.mac; - raw_msg.sig_rl_size = raw_len - header_len; - if let Some(sig_rl) = self.sig_rl.as_ref() { - bytes[header_len as usize..].copy_from_slice(sig_rl); - } - Ok(bytes) - } - - pub fn copy_to_slice(&self, bytes: &mut [u8]) -> SgxResult { - let raw_len = self.get_raw_ize().ok_or(SgxStatus::InvalidParameter)?; - ensure!(bytes.len() == raw_len as usize, SgxStatus::InvalidParameter); - - let header_len = mem::size_of::() as u32; - let raw_msg = unsafe { &mut *(bytes.as_mut_ptr() as *mut CRaMsg2) }; - - raw_msg.g_b = self.pub_key_b.into(); - raw_msg.spid = self.spid; - raw_msg.quote_type = self.quote_type as u16; - raw_msg.kdf_id = self.kdf_id; - raw_msg.sign_gb_ga = self.sign_gb_ga.into(); - raw_msg.mac = self.mac; - raw_msg.sig_rl_size = raw_len - header_len; - if let Some(sig_rl) = self.sig_rl.as_ref() { - bytes[header_len as usize..].copy_from_slice(sig_rl); - } - Ok(()) - } - - #[inline] - pub fn from_bytes(bytes: Vec) -> SgxResult { - Self::from_slice(bytes.as_slice()) - } - - pub fn from_slice(bytes: &[u8]) -> SgxResult { - ensure!( - bytes.len() >= mem::size_of::(), - SgxStatus::InvalidParameter - ); - - let header_len = mem::size_of::() as u32; - let raw_msg = unsafe { &*(bytes.as_ptr() as *const CRaMsg2) }; - - ensure!( - (raw_msg.sig_rl_size <= u32::MAX - header_len) - && (bytes.len() == (header_len + raw_msg.sig_rl_size) as usize), - SgxStatus::InvalidParameter - ); - - let sig_rl_len = raw_msg.sig_rl_size as usize; - let sig_rl = if sig_rl_len > 0 { - let mut sig_rl = vec![0_u8; sig_rl_len]; - sig_rl.as_mut_slice().copy_from_slice(unsafe { - slice::from_raw_parts(&raw_msg.sig_rl as *const _ as *const u8, sig_rl_len) - }); - Some(sig_rl.into_boxed_slice()) - } else { - None - }; - - let quote_type = if raw_msg.quote_type == 0 { - QuoteSignType::Unlinkable - } else { - QuoteSignType::Linkable - }; - - Ok(RaMsg2 { - pub_key_b: raw_msg.g_b.into(), - spid: raw_msg.spid, - quote_type, - kdf_id: raw_msg.kdf_id, - sign_gb_ga: raw_msg.sign_gb_ga.into(), - mac: raw_msg.mac, - sig_rl, - }) - } - - pub fn get_raw_ize(&self) -> Option { - let sig_rl_len = self.sig_rl.as_ref().map_or(0, |sig_rl| sig_rl.len()); - - if Self::check_sig_rl_len(sig_rl_len) { - Some((mem::size_of::() + sig_rl_len) as u32) - } else { - None - } - } - - #[inline] - pub fn check_sig_rl_len(sig_rl_len: usize) -> bool { - sig_rl_len <= (u32::MAX as usize) - mem::size_of::() - } -} - -impl RaMsg3 { - pub fn gen_cmac(&mut self, cmac_key: &AlignKey128bit) -> SgxResult { - let mut cmac = AesCMac::new(&cmac_key.key)?; - cmac.update(&self.pub_key_a)?; - cmac.update(&self.ps_sec_prop)?; - cmac.update(&self.quote[..])?; - self.mac = cmac.finalize()?; - - Ok(()) - } - - pub fn verify_cmac(&self, cmac_key: &AlignKey128bit) -> SgxResult { - let mut cmac = AesCMac::new(&cmac_key.key)?; - cmac.update(&self.pub_key_a)?; - cmac.update(&self.ps_sec_prop)?; - cmac.update(&self.quote[..])?; - let mac = cmac.finalize()?; - - ensure!(mac.ct_eq(&self.mac), SgxStatus::MacMismatch); - Ok(()) - } - - #[inline] - pub fn into_bytes(self) -> SgxResult> { - self.to_bytes() - } - - #[inline] - pub fn to_bytes(&self) -> SgxResult> { - self.to_bytes_in(Global) - } - - #[inline] - pub fn into_bytes_in(self, alloc: A) -> SgxResult> { - self.to_bytes_in(alloc) - } - - pub fn to_bytes_in(&self, alloc: A) -> SgxResult> { - ensure!(!self.quote.is_empty(), SgxStatus::InvalidParameter); - let raw_len = self.get_raw_ize().ok_or(SgxStatus::InvalidParameter)?; - - let mut bytes = vec::from_elem_in(0_u8, raw_len as usize, alloc); - let header_len = mem::size_of::(); - - let raw_msg = unsafe { &mut *(bytes.as_mut_ptr() as *mut CRaMsg3) }; - raw_msg.mac = self.mac; - raw_msg.g_a = self.pub_key_a.into(); - raw_msg.ps_sec_prop = self.ps_sec_prop; - bytes[header_len..].copy_from_slice(&self.quote); - - Ok(bytes) - } - - pub fn copy_to_slice(&self, bytes: &mut [u8]) -> SgxResult { - ensure!(!self.quote.is_empty(), SgxStatus::InvalidParameter); - let raw_len = self.get_raw_ize().ok_or(SgxStatus::InvalidParameter)?; - ensure!(bytes.len() == raw_len as usize, SgxStatus::InvalidParameter); - - let header_len = mem::size_of::(); - let raw_msg = unsafe { &mut *(bytes.as_mut_ptr() as *mut CRaMsg3) }; - - raw_msg.mac = self.mac; - raw_msg.g_a = self.pub_key_a.into(); - raw_msg.ps_sec_prop = self.ps_sec_prop; - bytes[header_len..].copy_from_slice(&self.quote); - - Ok(()) - } - - #[inline] - pub fn from_bytes(bytes: Vec) -> SgxResult { - Self::from_slice(bytes.as_slice()) - } - - pub fn from_slice(bytes: &[u8]) -> SgxResult { - let raw_msg_len = bytes.len(); - ensure!( - raw_msg_len > mem::size_of::(), - SgxStatus::InvalidParameter - ); - - let header_len = mem::size_of::(); - let raw_msg = unsafe { &*(bytes.as_ptr() as *const CRaMsg3) }; - - let quote_len = raw_msg_len - header_len; - ensure!( - Self::check_quote_len(quote_len), - SgxStatus::InvalidParameter - ); - - let mut quote = vec![0_u8; quote_len]; - quote.as_mut_slice().copy_from_slice(unsafe { - slice::from_raw_parts(&raw_msg.quote as *const _ as *const u8, quote_len) - }); - - Ok(RaMsg3 { - mac: raw_msg.mac, - pub_key_a: raw_msg.g_a.into(), - ps_sec_prop: raw_msg.ps_sec_prop, - quote: quote.into_boxed_slice(), - }) - } - - pub fn get_raw_ize(&self) -> Option { - let quote_len = self.quote.len(); - - if Self::check_quote_len(quote_len) { - Some((mem::size_of::() + quote_len) as u32) - } else { - None - } - } - - #[inline] - pub fn check_quote_len(quote_len: usize) -> bool { - quote_len <= (u32::MAX as usize) - mem::size_of::() - && quote_len > mem::size_of::() - } -} - -impl From for CRaMsg1 { - fn from(msg: RaMsg1) -> CRaMsg1 { - CRaMsg1 { - g_a: msg.pub_key_a.into(), - gid: msg.gid, - } - } -} - -impl From<&RaMsg1> for CRaMsg1 { - fn from(msg: &RaMsg1) -> CRaMsg1 { - CRaMsg1 { - g_a: msg.pub_key_a.into(), - gid: msg.gid, - } - } -} - -impl From for RaMsg1 { - fn from(msg: CRaMsg1) -> RaMsg1 { - RaMsg1 { - pub_key_a: msg.g_a.into(), - gid: msg.gid, - } - } -} - -impl From<&CRaMsg1> for RaMsg1 { - fn from(msg: &CRaMsg1) -> RaMsg1 { - RaMsg1 { - pub_key_a: msg.g_a.into(), - gid: msg.gid, - } - } -} - -#[cfg(feature = "tmsg")] -impl EnclaveRange for RaMsg2 { - fn is_enclave_range(&self) -> bool { - if !is_within_enclave(self as *const _ as *const u8, mem::size_of::()) { - return false; - } - - let sig_rl = self.sig_rl.as_ref(); - let (ptr, len) = sig_rl.map_or((ptr::null(), 0), |sig_rl| { - if !sig_rl.is_empty() { - (sig_rl.as_ptr(), sig_rl.len()) - } else { - (ptr::null(), 0) - } - }); - if len > 0 && !is_within_enclave(ptr, len) { - return false; - } - - true - } - - fn is_host_range(&self) -> bool { - if !is_within_host(self as *const _ as *const u8, mem::size_of::()) { - return false; - } - - let sig_rl = self.sig_rl.as_ref(); - let (ptr, len) = sig_rl.map_or((ptr::null(), 0), |sig_rl| { - if !sig_rl.is_empty() { - (sig_rl.as_ptr(), sig_rl.len()) - } else { - (ptr::null(), 0) - } - }); - if len > 0 && !is_within_host(ptr, len) { - return false; - } - - true - } -} - -#[cfg(feature = "tmsg")] -impl EnclaveRange for RaMsg3 { - fn is_enclave_range(&self) -> bool { - if !is_within_enclave(self as *const _ as *const u8, mem::size_of::()) { - return false; - } - if self.quote.len() > 0 && !is_within_enclave(self.quote.as_ptr(), self.quote.len()) { - return false; - } - true - } - - fn is_host_range(&self) -> bool { - if !is_within_host(self as *const _ as *const u8, mem::size_of::()) { - return false; - } - if self.quote.len() > 0 && !is_within_host(self.quote.as_ptr(), self.quote.len()) { - return false; - } - true - } -} diff --git a/sgx_key_exchange/tkey_exchange/Cargo.toml b/sgx_key_exchange/tkey_exchange/Cargo.toml deleted file mode 100644 index 1290ab1e2..000000000 --- a/sgx_key_exchange/tkey_exchange/Cargo.toml +++ /dev/null @@ -1,44 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -[package] -name = "sgx_tkey_exchange" -version = "2.0.0" -authors = ["The Teaclave Authors"] -repository = "https://github.com/apache/teaclave-sgx-sdk" -license-file = "LICENSE" -documentation = "https://teaclave.apache.org/sgx-sdk-docs/" -description = "Rust SGX SDK provides the ability to write Intel SGX applications in Rust Programming Language." -edition = "2021" - -[lib] -name = "sgx_tkey_exchange" -crate-type = ["rlib"] - -[features] -default = [] -capi = [] - -[target.'cfg(not(target_vendor = "teaclave"))'.dependencies] -sgx_trts = { path = "../../sgx_trts" } -sgx_types = { path = "../../sgx_types" } -sgx_sync = { path = "../../sgx_sync" } - -[dependencies] -sgx_crypto = { path = "../../sgx_crypto" } -sgx_tse = { path = "../../sgx_tse" } -sgx_ra_msg = { path = "../message" } diff --git a/sgx_key_exchange/tkey_exchange/src/capi.rs b/sgx_key_exchange/tkey_exchange/src/capi.rs deleted file mode 100644 index 479294048..000000000 --- a/sgx_key_exchange/tkey_exchange/src/capi.rs +++ /dev/null @@ -1,151 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 crate::session::Initiator; -use core::mem::{self, ManuallyDrop}; -use sgx_trts::trts::is_within_enclave; -use sgx_types::error::{SgxResult, SgxStatus}; -use sgx_types::types::{ - AlignKey128bit, Ec256PublicKey, Key128bit, RaContext, RaDriveSecretKeyFn, RaKeyType, -}; - -/// # Safety -#[no_mangle] -pub unsafe extern "C" fn sgx_ra_init( - sp_pub_key: *const Ec256PublicKey, - _pse: i32, - context: *mut RaContext, -) -> SgxStatus { - if sp_pub_key.is_null() || context.is_null() { - return SgxStatus::InvalidParameter; - } - - if !is_within_enclave(sp_pub_key as *const u8, mem::size_of::()) { - return SgxStatus::InvalidParameter; - } - - let pub_key = &*sp_pub_key; - let initiator = match Initiator::new(&pub_key.into()) { - Ok(initiator) => initiator, - Err(e) => return e, - }; - - *context = initiator.into_raw(); - SgxStatus::Success -} - -/// # Safety -#[no_mangle] -pub unsafe extern "C" fn sgx_ra_init_ex( - sp_pub_key: *const Ec256PublicKey, - _pse: i32, - derive_key_cb: RaDriveSecretKeyFn, - context: *mut RaContext, -) -> SgxStatus { - if sp_pub_key.is_null() || context.is_null() { - return SgxStatus::InvalidParameter; - } - - if !is_within_enclave(sp_pub_key as *const u8, mem::size_of::()) { - return SgxStatus::InvalidParameter; - } - if !is_within_enclave(derive_key_cb as *const u8, 0) { - return SgxStatus::InvalidParameter; - } - - let pub_key = &*sp_pub_key; - let initiator = match Initiator::new_with_derive_key( - &pub_key.into(), - move |share_key, - kdf_id| - -> SgxResult<( - AlignKey128bit, - AlignKey128bit, - AlignKey128bit, - AlignKey128bit, - )> { - let mut smk_key = Key128bit::default(); - let mut sk_key = Key128bit::default(); - let mut mk_key = Key128bit::default(); - let mut vk_key = Key128bit::default(); - - let status = derive_key_cb( - share_key, - kdf_id, - &mut smk_key, - &mut sk_key, - &mut mk_key, - &mut vk_key, - ); - let result = if status.is_success() { - let smk = smk_key.into(); - let sk = sk_key.into(); - let mk = mk_key.into(); - let vk = vk_key.into(); - - Ok((smk, sk, mk, vk)) - } else { - Err(status) - }; - - smk_key.fill(0); - sk_key.fill(0); - mk_key.fill(0); - vk_key.fill(0); - result - }, - ) { - Ok(initiator) => initiator, - Err(e) => return e, - }; - - *context = initiator.into_raw(); - SgxStatus::Success -} - -/// # Safety -#[no_mangle] -pub unsafe extern "C" fn sgx_ra_get_keys( - context: RaContext, - key_type: RaKeyType, - key: *mut Key128bit, -) -> SgxStatus { - if key.is_null() { - return SgxStatus::InvalidParameter; - } - - if !is_within_enclave(key as *const u8, mem::size_of::()) { - return SgxStatus::InvalidParameter; - } - - let initiator = ManuallyDrop::new(Initiator::from_raw(context)); - let ra_key = match initiator.get_keys(key_type) { - Ok(key) => key.key, - Err(e) => return e, - }; - - *key = ra_key; - SgxStatus::Success -} - -/// # Safety -#[no_mangle] -pub unsafe extern "C" fn sgx_ra_close(context: RaContext) -> SgxStatus { - let initiator = Initiator::from_raw(context); - drop(initiator); - SgxStatus::Success -} diff --git a/sgx_key_exchange/tkey_exchange/src/lib.rs b/sgx_key_exchange/tkey_exchange/src/lib.rs deleted file mode 100644 index 1a408b860..000000000 --- a/sgx_key_exchange/tkey_exchange/src/lib.rs +++ /dev/null @@ -1,37 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#![no_std] -#![cfg_attr(target_vendor = "teaclave", feature(rustc_private))] -#![feature(extract_if)] -#![allow(clippy::missing_safety_doc)] - -extern crate alloc; - -extern crate sgx_crypto; -extern crate sgx_ra_msg; -extern crate sgx_sync; -extern crate sgx_trts; -extern crate sgx_tse; -#[macro_use] -extern crate sgx_types; - -mod session; -pub use session::*; - -#[cfg(feature = "capi")] -pub mod capi; diff --git a/sgx_key_exchange/tkey_exchange/src/session/ecall.rs b/sgx_key_exchange/tkey_exchange/src/session/ecall.rs deleted file mode 100644 index a66c688a5..000000000 --- a/sgx_key_exchange/tkey_exchange/src/session/ecall.rs +++ /dev/null @@ -1,131 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 super::Initiator; -use core::mem::{self, ManuallyDrop}; -use core::slice; -use sgx_ra_msg::RaMsg2; -use sgx_trts::fence; -use sgx_trts::trts::is_within_host; -use sgx_types::error::SgxStatus; -use sgx_types::types::{ - CRaMsg2, CRaMsg3, Ec256PublicKey, QuoteNonce, QuoteSignType, RaContext, Report, TargetInfo, -}; - -/// # Safety -#[no_mangle] -pub unsafe extern "C" fn sgx_ra_get_ga( - context: RaContext, - pub_key_a: *mut Ec256PublicKey, -) -> SgxStatus { - if pub_key_a.is_null() { - return SgxStatus::InvalidParameter; - } - - let initiator = ManuallyDrop::new(Initiator::from_raw(context)); - let key = match initiator.get_ga() { - Ok(key) => key, - Err(e) => return e, - }; - - *pub_key_a = key.into(); - SgxStatus::Success -} - -/// # Safety -#[no_mangle] -pub unsafe extern "C" fn sgx_ra_proc_msg2_trusted( - context: RaContext, - msg2: *const CRaMsg2, - qe_target: *const TargetInfo, - report: *mut Report, - nonce: *mut QuoteNonce, -) -> SgxStatus { - if msg2.is_null() || qe_target.is_null() || report.is_null() || nonce.is_null() { - return SgxStatus::InvalidParameter; - } - - let qe_target = &*qe_target; - let c_msg2 = &*msg2; - let quote_type = if c_msg2.quote_type == 0 { - QuoteSignType::Unlinkable - } else { - QuoteSignType::Linkable - }; - - let msg2 = RaMsg2 { - pub_key_b: c_msg2.g_b.into(), - spid: c_msg2.spid, - quote_type, - kdf_id: c_msg2.kdf_id, - sign_gb_ga: c_msg2.sign_gb_ga.into(), - mac: c_msg2.mac, - sig_rl: None, - }; - - let initiator = ManuallyDrop::new(Initiator::from_raw(context)); - let (rpt, rand) = match initiator.process_msg2(&msg2, qe_target) { - Ok(r) => r, - Err(e) => return e, - }; - - *report = rpt; - *nonce = rand; - SgxStatus::Success -} - -/// # Safety -#[no_mangle] -pub unsafe extern "C" fn sgx_ra_get_msg3_trusted( - context: RaContext, - quote_size: u32, - qe_report: *const Report, - msg3: *mut CRaMsg3, - msg3_size: u32, -) -> SgxStatus { - if qe_report.is_null() || msg3.is_null() { - return SgxStatus::InvalidParameter; - } - - if usize::MAX - (msg3 as usize) < msg3_size as usize - || u32::MAX - quote_size < mem::size_of::() as u32 - || mem::size_of::() as u32 + quote_size != msg3_size - { - return SgxStatus::InvalidParameter; - } - - if !is_within_host(msg3 as *const u8, msg3_size as usize) { - return SgxStatus::InvalidParameter; - } - - fence::lfence(); - - let qe_report = &*qe_report; - let c_msg3 = &mut *msg3; - let quote = slice::from_raw_parts(&c_msg3.quote as *const _ as *const u8, quote_size as usize); - - let initiator = ManuallyDrop::new(Initiator::from_raw(context)); - let msg3 = match initiator.generate_msg3(qe_report, quote) { - Ok(msg) => msg, - Err(e) => return e, - }; - - c_msg3.mac = msg3.mac; - c_msg3.g_a = msg3.pub_key_a.into(); - c_msg3.ps_sec_prop = msg3.ps_sec_prop; - SgxStatus::Success -} diff --git a/sgx_key_exchange/tkey_exchange/src/session/initiator.rs b/sgx_key_exchange/tkey_exchange/src/session/initiator.rs deleted file mode 100644 index 84e4ba531..000000000 --- a/sgx_key_exchange/tkey_exchange/src/session/initiator.rs +++ /dev/null @@ -1,276 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 super::manager::SESSION_MAGAGER; -use super::manager::{Context, Session, State}; -use super::manager::{DropKey, DropPrivateKey, DropShareKey}; -use alloc::boxed::Box; -use core::mem; -use sgx_crypto::ecc::{EcKeyPair, EcPublicKey}; -use sgx_crypto::sha::Sha256; -use sgx_ra_msg::{RaMsg2, RaMsg3}; -use sgx_trts::fence; -use sgx_trts::rand::Rng; -use sgx_trts::trts::EnclaveRange; -use sgx_tse::EnclaveReport; -use sgx_types::error::{SgxResult, SgxStatus}; -use sgx_types::types::SHA256_HASH_SIZE; -use sgx_types::types::{ - AlignKey128bit, Ec256SharedKey, QuoteNonce, RaContext, RaKeyType, Report, ReportData, - TargetInfo, -}; - -#[derive(Debug)] -pub struct Initiator { - rctx: RaContext, -} - -impl Initiator { - pub fn new(sp_pub_key: &EcPublicKey) -> SgxResult { - ensure!(sp_pub_key.is_enclave_range(), SgxStatus::InvalidParameter); - - let is_valid = sp_pub_key.check_point()?; - ensure!(is_valid, SgxStatus::InvalidParameter); - - let mut context = Context::new(); - context.sp_pub_key = *sp_pub_key; - let session = Session::new_with_context(context).set_derive_key(None); - - let rctx = SESSION_MAGAGER.write().push(session); - Ok(Self { rctx }) - } - - pub fn new_with_derive_key(sp_pub_key: &EcPublicKey, derive_key: F) -> SgxResult - where - F: Fn( - &Ec256SharedKey, - u16, - ) -> SgxResult<( - AlignKey128bit, - AlignKey128bit, - AlignKey128bit, - AlignKey128bit, - )> + Sync - + Send - + 'static, - { - ensure!(sp_pub_key.is_enclave_range(), SgxStatus::InvalidParameter); - - let is_valid = sp_pub_key.check_point()?; - ensure!(is_valid, SgxStatus::InvalidParameter); - - let mut context = Context::new(); - context.sp_pub_key = *sp_pub_key; - let session = Session::new_with_context(context).set_derive_key(Some(Box::new(derive_key))); - - let rctx = SESSION_MAGAGER.write().push(session); - Ok(Self { rctx }) - } - - pub fn get_ga(&self) -> SgxResult { - let session = SESSION_MAGAGER - .read() - .find(self.rctx) - .ok_or(SgxStatus::InvalidParameter)?; - - let mut key_pair = EcKeyPair::create()?; - let (mut priv_key, pub_key) = key_pair.into(); - - let mut context = session.context.lock(); - context.priv_key = priv_key; - context.pub_key_a = pub_key; - context.state = State::GaGened; - drop(context); - - key_pair.clear(); - priv_key.clear(); - - Ok(pub_key) - } - - pub fn process_msg2( - &self, - msg2: &RaMsg2, - qe_target: &TargetInfo, - ) -> SgxResult<(Report, QuoteNonce)> { - ensure!(msg2.is_enclave_range(), SgxStatus::InvalidParameter); - ensure!(qe_target.is_enclave_range(), SgxStatus::InvalidParameter); - - let session = SESSION_MAGAGER - .read() - .find(self.rctx) - .ok_or(SgxStatus::InvalidParameter)?; - - fence::lfence(); - - let context = session.context.lock(); - ensure!(context.state == State::GaGened, SgxStatus::InvalidState); - let mut priv_key = context.priv_key; - let pub_key_a = context.pub_key_a; - let sp_pub_key = context.sp_pub_key; - drop(context); - - let priv_key = DropPrivateKey::new(&mut priv_key); - - let mut dh_key = priv_key.shared_key(&msg2.pub_key_b)?; - let dh_key = DropShareKey::new(&mut dh_key); - - let (ref mut smk_key, ref mut sk_key, ref mut mk_key, ref mut vk_key) = - if let Some(driver_key) = &session.derive_key { - driver_key(&(&*dh_key).into(), msg2.kdf_id)? - } else { - ensure!(msg2.kdf_id == 0x0001, SgxStatus::KdfMismatch); - let smk_key = dh_key.derive_key("SMK".as_bytes())?; - let sk_key = dh_key.derive_key("SK".as_bytes())?; - let mk_key = dh_key.derive_key("MK".as_bytes())?; - let vk_key = dh_key.derive_key("VK".as_bytes())?; - (smk_key, sk_key, mk_key, vk_key) - }; - - let smk_key = DropKey::new(smk_key); - let sk_key = DropKey::new(sk_key); - let mk_key = DropKey::new(mk_key); - let vk_key = DropKey::new(vk_key); - - msg2.verify_sign_and_cmac(&pub_key_a, &sp_pub_key, &smk_key)?; - - let mut nonce = QuoteNonce::default(); - Rng::new().fill_bytes(&mut nonce.rand); - - let mut report_data = ReportData::default(); - let mut sha = Sha256::new()?; - sha.update(&pub_key_a)?; - sha.update(&msg2.pub_key_b)?; - sha.update(&*vk_key)?; - let hash = sha.finalize()?; - report_data.d[..SHA256_HASH_SIZE].copy_from_slice(&hash); - let report = Report::for_target(qe_target, &report_data)?; - - let mut context = session.context.lock(); - ensure!(context.state == State::GaGened, SgxStatus::InvalidState); - context.pub_key_b = msg2.pub_key_b; - context.smk_key = *smk_key; - context.sk_key = *sk_key; - context.mk_key = *mk_key; - context.vk_key = *vk_key; - context.qe_target = *qe_target; - context.quote_nonce = nonce; - context.state = State::Msg2Proced; - drop(context); - - Ok((report, nonce)) - } - - pub fn generate_msg3(&self, qe_report: &Report, quote: &[u8]) -> SgxResult { - ensure!(qe_report.is_enclave_range(), SgxStatus::InvalidParameter); - ensure!(!quote.is_empty(), SgxStatus::InvalidParameter); - ensure!( - quote.is_enclave_range() || quote.is_host_range(), - SgxStatus::InvalidParameter - ); - ensure!( - RaMsg3::check_quote_len(quote.len()), - SgxStatus::InvalidParameter - ); - - let session = SESSION_MAGAGER - .read() - .find(self.rctx) - .ok_or(SgxStatus::InvalidParameter)?; - - fence::lfence(); - - qe_report.verify()?; - - let context = session.context.lock(); - ensure!(context.state == State::Msg2Proced, SgxStatus::InvalidState); - let attributes = context.qe_target.attributes; - let mr_enclave = context.qe_target.mr_enclave; - let pub_key_a = context.pub_key_a; - let ps_sec_prop = context.ps_sec_prop; - let mut smk_key = context.smk_key; - let nonce = context.quote_nonce; - drop(context); - - let smk_key = DropKey::new(&mut smk_key); - - ensure!( - attributes.eq(&qe_report.body.attributes), - SgxStatus::InvalidParameter - ); - ensure!( - mr_enclave.eq(&qe_report.body.mr_enclave), - SgxStatus::InvalidParameter - ); - - let mut sha = Sha256::new()?; - sha.update(&nonce)?; - sha.update(quote)?; - let hash = sha.finalize()?; - ensure!( - hash.eq(&qe_report.body.report_data.d[..SHA256_HASH_SIZE]), - SgxStatus::Unexpected - ); - - let mut msg3 = RaMsg3 { - mac: Default::default(), - pub_key_a, - ps_sec_prop, - quote: quote.into(), - }; - msg3.gen_cmac(&smk_key)?; - - Ok(msg3) - } - - pub fn get_keys(&self, key_type: RaKeyType) -> SgxResult { - let session = SESSION_MAGAGER - .read() - .find(self.rctx) - .ok_or(SgxStatus::InvalidParameter)?; - - let context = session.context.lock(); - ensure!(context.state == State::Msg2Proced, SgxStatus::InvalidState); - - let key = match key_type { - RaKeyType::SK => context.sk_key, - RaKeyType::MK => context.mk_key, - }; - - Ok(key) - } - - #[inline] - pub fn into_raw(self) -> RaContext { - let rctx = self.rctx; - mem::forget(self); - rctx - } - - #[inline] - pub unsafe fn from_raw(rctx: RaContext) -> Initiator { - Self { rctx } - } -} - -impl Drop for Initiator { - fn drop(&mut self) { - if let Some(session) = SESSION_MAGAGER.write().remove(self.rctx) { - drop(session) - } - } -} diff --git a/sgx_key_exchange/tkey_exchange/src/session/manager.rs b/sgx_key_exchange/tkey_exchange/src/session/manager.rs deleted file mode 100644 index d5f55c5f2..000000000 --- a/sgx_key_exchange/tkey_exchange/src/session/manager.rs +++ /dev/null @@ -1,247 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 alloc::boxed::Box; -use alloc::collections::LinkedList; -use alloc::sync::Arc; -use core::mem; -use core::ops::Deref; -use core::ptr; -use core::sync::atomic::{AtomicU32, Ordering}; -use sgx_crypto::ecc::{EcPrivateKey, EcPublicKey, EcShareKey}; -use sgx_sync::{LazyLock, SpinMutex, SpinRwLock}; -use sgx_types::error::SgxResult; -use sgx_types::types::{AlignKey128bit, Ec256SharedKey, PsSecPropDesc, QuoteNonce, TargetInfo}; - -#[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[repr(u32)] -pub enum State { - Inited, - GaGened, - Msg2Proced, -} - -impl Default for State { - #[inline] - fn default() -> State { - State::Inited - } -} - -type DeriveKeyFn = dyn Fn( - &Ec256SharedKey, - u16, - ) -> SgxResult<( - AlignKey128bit, - AlignKey128bit, - AlignKey128bit, - AlignKey128bit, - )> + Sync - + Send - + 'static; - -#[derive(Default)] -pub struct Context { - pub sp_pub_key: EcPublicKey, - pub pub_key_a: EcPublicKey, - pub pub_key_b: EcPublicKey, - pub priv_key: EcPrivateKey, - pub ps_sec_prop: PsSecPropDesc, - pub smk_key: AlignKey128bit, - pub sk_key: AlignKey128bit, - pub mk_key: AlignKey128bit, - pub vk_key: AlignKey128bit, - pub quote_nonce: QuoteNonce, - pub qe_target: TargetInfo, - pub state: State, -} - -impl Context { - pub fn new() -> Context { - Self::default() - } - - #[inline] - fn clear(&mut self) { - unsafe { ptr::write_bytes(self as *mut _ as *mut u8, 0, mem::size_of::()) } - } -} - -impl Drop for Context { - fn drop(&mut self) { - self.clear() - } -} - -pub struct Session { - pub context: SpinMutex, - pub derive_key: Option>, -} - -impl Default for Session { - fn default() -> Session { - Self::new() - } -} - -impl Session { - pub fn new() -> Session { - Session { - context: SpinMutex::new(Context::new()), - derive_key: None, - } - } - - pub fn new_with_context(context: Context) -> Session { - Session { - context: SpinMutex::new(context), - derive_key: None, - } - } - - pub fn set_derive_key(mut self, derive_key: Option>) -> Session { - self.derive_key = derive_key; - self - } -} - -pub static SESSION_MAGAGER: LazyLock> = - LazyLock::new(|| SpinRwLock::new(SessionManager::new())); - -struct Node { - sid: u32, - session: Arc, -} - -pub struct SessionManager { - seed: AtomicU32, - list: LinkedList, -} - -impl Default for SessionManager { - fn default() -> SessionManager { - SessionManager::new() - } -} - -impl SessionManager { - pub const fn new() -> SessionManager { - SessionManager { - seed: AtomicU32::new(1), - list: LinkedList::new(), - } - } - - pub fn find(&self, sid: u32) -> Option> { - self.list - .iter() - .find(|&node| node.sid == sid) - .map(|node| node.session.clone()) - } - - pub fn push(&mut self, session: Session) -> u32 { - let sid = self.seed.fetch_add(1, Ordering::SeqCst); - let session = Arc::new(session); - self.list.push_back(Node { sid, session }); - sid - } - - pub fn remove(&mut self, sid: u32) -> Option> { - self.list - .extract_if(|node| node.sid == sid) - .next() - .map(|node| node.session) - } -} - -pub(crate) struct DropKey<'a> { - key: &'a mut AlignKey128bit, -} - -impl<'a> DropKey<'a> { - #[inline] - pub(crate) fn new(key: &'a mut AlignKey128bit) -> Self { - DropKey { key } - } -} - -impl Drop for DropKey<'_> { - #[inline] - fn drop(&mut self) { - self.key.key.fill(0); - } -} - -impl Deref for DropKey<'_> { - type Target = AlignKey128bit; - - fn deref(&self) -> &Self::Target { - self.key - } -} - -pub(crate) struct DropShareKey<'a> { - key: &'a mut EcShareKey, -} - -impl<'a> DropShareKey<'a> { - #[inline] - pub(crate) fn new(key: &'a mut EcShareKey) -> Self { - DropShareKey { key } - } -} - -impl Drop for DropShareKey<'_> { - #[inline] - fn drop(&mut self) { - self.key.clear(); - } -} - -impl Deref for DropShareKey<'_> { - type Target = EcShareKey; - - fn deref(&self) -> &Self::Target { - self.key - } -} - -pub(crate) struct DropPrivateKey<'a> { - key: &'a mut EcPrivateKey, -} - -impl<'a> DropPrivateKey<'a> { - #[inline] - pub(crate) fn new(key: &'a mut EcPrivateKey) -> Self { - DropPrivateKey { key } - } -} - -impl Drop for DropPrivateKey<'_> { - #[inline] - fn drop(&mut self) { - self.key.clear(); - } -} - -impl Deref for DropPrivateKey<'_> { - type Target = EcPrivateKey; - - fn deref(&self) -> &Self::Target { - self.key - } -} diff --git a/sgx_key_exchange/tkey_exchange/src/session/mod.rs b/sgx_key_exchange/tkey_exchange/src/session/mod.rs deleted file mode 100644 index c9d5d261b..000000000 --- a/sgx_key_exchange/tkey_exchange/src/session/mod.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -mod ecall; -mod initiator; -mod manager; - -pub use ecall::*; -pub use initiator::*; diff --git a/sgx_key_exchange/ukey_exchange/Cargo.toml b/sgx_key_exchange/ukey_exchange/Cargo.toml deleted file mode 100644 index 0fb986336..000000000 --- a/sgx_key_exchange/ukey_exchange/Cargo.toml +++ /dev/null @@ -1,41 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -[package] -name = "sgx_ukey_exchange" -version = "2.0.0" -authors = ["The Teaclave Authors"] -repository = "https://github.com/apache/teaclave-sgx-sdk" -license-file = "LICENSE" -documentation = "https://teaclave.apache.org/sgx-sdk-docs/" -description = "Rust SGX SDK provides the ability to write Intel SGX applications in Rust Programming Language." -edition = "2021" - -[lib] -name = "sgx_ukey_exchange" -crate-type = ["rlib"] - -[features] -default = [] -sim = ["sgx_types/sim"] -hyper = ["sgx_types/hyper", "sgx_urts/hyper"] -capi = [] - -[dependencies] -sgx_types = { path = "../../sgx_types" } -sgx_ra_msg = { path = "../message", default-features = false, features = ["umsg"] } -sgx_urts = { path = "../../sgx_urts", optional = true } diff --git a/sgx_key_exchange/ukey_exchange/build.rs b/sgx_key_exchange/ukey_exchange/build.rs deleted file mode 100644 index f32117995..000000000 --- a/sgx_key_exchange/ukey_exchange/build.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 std::env; - -fn main() -> Result<(), &'static str> { - println!("cargo:rerun-if-env-changed=SGX_MODE"); - println!("cargo:rerun-if-changed=build.rs"); - - if cfg!(all(feature = "sim", feature = "hyper")) { - println!("cargo:warning=feature \"sim\" and feature \"hyper\", only one or neither of them can be enabled."); - return Err("Defined feature is illegal."); - } - - let mode = env::var("SGX_MODE").unwrap_or_else(|_| "HW".to_string()); - match mode.as_ref() { - "SIM" | "SW" => println!("cargo:rustc-cfg=feature=\"sim\""), - "HYPER" => println!("cargo:rustc-cfg=feature=\"hyper\""), - _ => (), - } - Ok(()) -} diff --git a/sgx_key_exchange/ukey_exchange/src/capi.rs b/sgx_key_exchange/ukey_exchange/src/capi.rs deleted file mode 100644 index 0bf9fe747..000000000 --- a/sgx_key_exchange/ukey_exchange/src/capi.rs +++ /dev/null @@ -1,199 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT 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 crate::Initiator; -use sgx_ra_msg::RaMsg2; -use sgx_types::error::SgxStatus; -use sgx_types::types::{ - AttKeyId, CRaMsg1, CRaMsg2, CRaMsg3, ECallGetGaFn, ECallGetMsg3Fn, ECallProcessMsg2Fn, - EnclaveId, RaContext, -}; -use std::mem::ManuallyDrop; -use std::slice; -use std::sync::LazyLock; -use std::sync::Mutex; - -static INITIATOR: LazyLock> = LazyLock::new(|| Mutex::new(Initiator::new(0, 0))); - -/// # Safety -#[no_mangle] -pub unsafe extern "C" fn sgx_ra_get_msg1( - rctx: RaContext, - eid: EnclaveId, - get_ga_fn: ECallGetGaFn, - msg1: *mut CRaMsg1, -) -> SgxStatus { - if msg1.is_null() { - return SgxStatus::InvalidParameter; - } - - let mut initiator = Initiator::new(eid, rctx); - let ra_msg1 = match initiator.generate_msg1(None, get_ga_fn) { - Ok(msg) => msg, - Err(e) => return e, - }; - - let mut guard = INITIATOR.lock().unwrap(); - guard.set_attkey_id(None); - guard.set_qe_target(initiator.get_qe_target()); - drop(guard); - - *msg1 = ra_msg1.into(); - - SgxStatus::Success -} - -/// # Safety -#[no_mangle] -pub unsafe extern "C" fn sgx_ra_proc_msg2( - rctx: RaContext, - eid: EnclaveId, - process_msg2_fn: ECallProcessMsg2Fn, - get_msg3_fn: ECallGetMsg3Fn, - msg2: *const CRaMsg2, - msg2_size: u32, - msg3: *mut *mut CRaMsg3, - msg3_size: *mut u32, -) -> SgxStatus { - if msg2.is_null() || msg3.is_null() || msg3_size.is_null() { - return SgxStatus::InvalidParameter; - } - - let guard = INITIATOR.lock().unwrap(); - if guard.get_attkey_id().is_some() { - return SgxStatus::InvalidState; - } - let qe_target = guard.get_qe_target(); - drop(guard); - - let mut initiator = Initiator::new(eid, rctx); - initiator.set_attkey_id(None); - initiator.set_qe_target(qe_target); - - let msg2_slice = slice::from_raw_parts(msg2 as *const u8, msg2_size as usize); - let ra_msg2 = match RaMsg2::from_slice(msg2_slice) { - Ok(msg) => msg, - Err(e) => return e, - }; - - let ra_msg3 = match initiator.process_msg2(&ra_msg2, process_msg2_fn, get_msg3_fn) { - Ok(msg) => msg, - Err(e) => return e, - }; - - let raw_msg3_size = match ra_msg3.get_raw_ize() { - Some(size) => size, - None => return SgxStatus::Unexpected, - }; - - let mut raw_msg3 = ManuallyDrop::new(vec![0_u8; raw_msg3_size as usize]); - match ra_msg3.copy_to_slice(raw_msg3.as_mut_slice()) { - Ok(_) => (), - Err(e) => return e, - }; - - *msg3 = raw_msg3.as_mut_ptr() as *mut CRaMsg3; - *msg3_size = raw_msg3_size; - - SgxStatus::Success -} - -/// # Safety -#[no_mangle] -pub unsafe extern "C" fn sgx_ra_get_msg1_ex( - att_key_id: *const AttKeyId, - rctx: RaContext, - eid: EnclaveId, - get_ga_fn: ECallGetGaFn, - msg1: *mut CRaMsg1, -) -> SgxStatus { - if att_key_id.is_null() || msg1.is_null() { - return SgxStatus::InvalidParameter; - } - - let mut initiator = Initiator::new(eid, rctx); - let ra_msg1 = match initiator.generate_msg1(Some(*att_key_id), get_ga_fn) { - Ok(msg) => msg, - Err(e) => return e, - }; - - let mut guard = INITIATOR.lock().unwrap(); - guard.set_attkey_id(initiator.get_attkey_id()); - guard.set_qe_target(initiator.get_qe_target()); - drop(guard); - - *msg1 = ra_msg1.into(); - - SgxStatus::Success -} - -/// # Safety -#[no_mangle] -pub unsafe extern "C" fn sgx_ra_proc_msg2_ex( - att_key_id: *const AttKeyId, - rctx: RaContext, - eid: EnclaveId, - process_msg2_fn: ECallProcessMsg2Fn, - get_msg3_fn: ECallGetMsg3Fn, - msg2: *const CRaMsg2, - msg2_size: u32, - msg3: *mut *mut CRaMsg3, - msg3_size: *mut u32, -) -> SgxStatus { - if att_key_id.is_null() || msg2.is_null() || msg3.is_null() || msg3_size.is_null() { - return SgxStatus::InvalidParameter; - } - - let att_key_id = Some(*att_key_id); - let guard = INITIATOR.lock().unwrap(); - if guard.get_attkey_id() != att_key_id { - return SgxStatus::InvalidState; - } - let qe_target = guard.get_qe_target(); - drop(guard); - - let mut initiator = Initiator::new(eid, rctx); - initiator.set_attkey_id(att_key_id); - initiator.set_qe_target(qe_target); - - let msg2_slice = slice::from_raw_parts(msg2 as *const u8, msg2_size as usize); - let ra_msg2 = match RaMsg2::from_slice(msg2_slice) { - Ok(msg) => msg, - Err(e) => return e, - }; - - let ra_msg3 = match initiator.process_msg2(&ra_msg2, process_msg2_fn, get_msg3_fn) { - Ok(msg) => msg, - Err(e) => return e, - }; - - let raw_msg3_size = match ra_msg3.get_raw_ize() { - Some(size) => size, - None => return SgxStatus::Unexpected, - }; - - let mut raw_msg3 = ManuallyDrop::new(vec![0_u8; raw_msg3_size as usize]); - match ra_msg3.copy_to_slice(raw_msg3.as_mut_slice()) { - Ok(_) => (), - Err(e) => return e, - }; - - *msg3 = raw_msg3.as_mut_ptr() as *mut CRaMsg3; - *msg3_size = raw_msg3_size; - - SgxStatus::Success -} diff --git a/sgx_key_exchange/ukey_exchange/src/lib.rs b/sgx_key_exchange/ukey_exchange/src/lib.rs deleted file mode 100644 index f0248add1..000000000 --- a/sgx_key_exchange/ukey_exchange/src/lib.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#![feature(allocator_api)] -#![feature(lazy_cell)] - -#[cfg(all(feature = "sim", feature = "hyper"))] -compile_error!("feature \"sim\" and feature \"hyper\" cannot be enabled at the same time"); - -#[macro_use] -extern crate sgx_types; -extern crate sgx_ra_msg; -#[cfg(feature = "hyper")] -extern crate sgx_urts; - -mod session; -pub use session::*; - -#[cfg(feature = "capi")] -pub mod capi; diff --git a/sgx_key_exchange/ukey_exchange/src/session.rs b/sgx_key_exchange/ukey_exchange/src/session.rs deleted file mode 100644 index a0917b475..000000000 --- a/sgx_key_exchange/ukey_exchange/src/session.rs +++ /dev/null @@ -1,254 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#![allow(dead_code)] - -use sgx_ra_msg::{RaMsg1, RaMsg2, RaMsg3}; -use sgx_types::error::{SgxResult, SgxStatus}; -use sgx_types::function::{ - sgx_calc_quote_size, sgx_get_quote, sgx_get_quote_ex, sgx_get_quote_size_ex, sgx_init_quote, - sgx_init_quote_ex, -}; -use sgx_types::types::{ - AttKeyId, CRaMsg3, Ec256PublicKey, EnclaveId, EpidGroupId, QeReportInfo, QuoteNonce, RaContext, - Report, TargetInfo, -}; -use sgx_types::types::{ECallGetGaFn, ECallGetMsg3Fn, ECallProcessMsg2Fn}; -use std::mem; -use std::ptr; -use std::vec; - -#[derive(Debug)] -pub struct Initiator { - rctx: RaContext, - eid: EnclaveId, - att_key_id: Option, - qe_target: TargetInfo, -} - -impl Initiator { - #[inline] - pub fn new(eid: EnclaveId, rctx: RaContext) -> Initiator { - Initiator { - rctx, - eid, - att_key_id: None, - qe_target: TargetInfo::default(), - } - } - - pub fn generate_msg1( - &mut self, - att_key_id: Option, - get_ga_fn: ECallGetGaFn, - ) -> SgxResult { - let mut gid = EpidGroupId::default(); - let mut qe_target = TargetInfo::default(); - - let status = unsafe { - if let Some(ref att_key_id) = att_key_id { - let mut pub_key_id_size = 0_usize; - let status = sgx_init_quote_ex( - att_key_id as *const _, - &mut qe_target as *mut _, - &mut pub_key_id_size as *mut _, - ptr::null_mut(), - ); - ensure!(status.is_success(), status); - - let mut pub_key_id = vec![0_u8; pub_key_id_size]; - sgx_init_quote_ex( - att_key_id as *const _, - &mut qe_target as *mut _, - &mut pub_key_id_size as *mut _, - pub_key_id.as_mut_ptr(), - ) - } else { - sgx_init_quote(&mut qe_target as *mut _, &mut gid as *mut _) - } - }; - ensure!(status.is_success(), status); - - self.att_key_id = att_key_id; - self.qe_target = qe_target; - - let mut retval = SgxStatus::Success; - let mut pub_key_a = Ec256PublicKey::default(); - let status = unsafe { - get_ga_fn( - self.eid, - &mut retval as *mut _, - self.rctx, - &mut pub_key_a as *mut _, - ) - }; - ensure!(status.is_success(), status); - ensure!(retval.is_success(), retval); - - Ok(RaMsg1 { - pub_key_a: pub_key_a.into(), - gid, - }) - } - - pub fn process_msg2( - &self, - msg2: &RaMsg2, - process_msg2_fn: ECallProcessMsg2Fn, - get_msg3_fn: ECallGetMsg3Fn, - ) -> SgxResult { - let raw_msg2 = msg2.to_bytes()?; - - let (sig_rl, sig_rl_len) = msg2 - .sig_rl - .as_ref() - .map(|sig_rl| { - if !sig_rl.is_empty() { - (sig_rl.as_ptr(), sig_rl.len() as u32) - } else { - (ptr::null(), 0) - } - }) - .unwrap_or((ptr::null(), 0)); - - if self.att_key_id.is_some() { - ensure!(sig_rl_len == 0, SgxStatus::InvalidParameter); - } - - let raw_msg3 = unsafe { - let mut report = Report::default(); - let mut nonce = QuoteNonce::default(); - - let mut retval = SgxStatus::Success; - let status = process_msg2_fn( - self.eid, - &mut retval as *mut _, - self.rctx, - raw_msg2.as_ptr().cast(), - &self.qe_target as *const _, - &mut report as *mut _, - &mut nonce as *mut _, - ); - ensure!(status.is_success(), status); - ensure!(retval.is_success(), retval); - - let mut quote_size = 0_u32; - let status = if let Some(ref att_key_id) = self.att_key_id { - sgx_get_quote_size_ex(att_key_id as *const _, &mut quote_size as *mut _) - } else { - sgx_calc_quote_size(sig_rl, sig_rl_len, &mut quote_size as *mut _) - }; - ensure!(status.is_success(), status); - - ensure!( - RaMsg3::check_quote_len(quote_size as usize), - SgxStatus::Unexpected - ); - - let raw_msg3_len = mem::size_of::() + quote_size as usize; - - cfg_if! { - if #[cfg(feature = "hyper")] { - use sgx_urts::msbuf::MsBufAlloc; - let alloc = MsBufAlloc::new(self.eid); - - let remain_size = alloc.remain_size(); - ensure!(raw_msg3_len < remain_size, SgxStatus::OutOfMemory); - } else { - use std::alloc::Global; - let alloc = Global; - } - } - - let mut raw_msg3 = vec::from_elem_in(0_u8, raw_msg3_len, alloc); - let c_msg3 = &mut *(raw_msg3.as_mut_ptr() as *mut CRaMsg3); - - let qe_report = &(if let Some(ref att_key_id) = self.att_key_id { - let mut qe_report_info = QeReportInfo { - nonce, - app_enclave_target_info: report.into(), - qe_report: Report::default(), - }; - let status = sgx_get_quote_ex( - &report as *const _, - att_key_id as *const _, - &mut qe_report_info as *mut _, - (c_msg3.quote).as_mut_ptr().cast(), - quote_size, - ); - ensure!(status.is_success(), status); - - qe_report_info.qe_report - } else { - let mut qe_report = Report::default(); - let status = sgx_get_quote( - &report as *const _, - msg2.quote_type, - &msg2.spid as *const _, - &nonce as *const _, - sig_rl, - sig_rl_len, - &mut qe_report as *mut _, - (c_msg3.quote).as_mut_ptr().cast(), - quote_size, - ); - ensure!(status.is_success(), status); - - qe_report - }); - - let mut retval = SgxStatus::Success; - let status = get_msg3_fn( - self.eid, - &mut retval as *mut _, - self.rctx, - quote_size, - qe_report as *const _, - c_msg3 as *mut _, - raw_msg3_len as u32, - ); - ensure!(status.is_success(), status); - ensure!(retval.is_success(), retval); - - raw_msg3 - }; - - RaMsg3::from_bytes(raw_msg3) - } -} - -impl Initiator { - #[inline] - pub(crate) fn set_attkey_id(&mut self, att_key_id: Option) { - self.att_key_id = att_key_id; - } - - #[inline] - pub(crate) fn set_qe_target(&mut self, qe_target: TargetInfo) { - self.qe_target = qe_target; - } - - #[inline] - pub(crate) fn get_attkey_id(&self) -> Option { - self.att_key_id - } - - #[inline] - pub(crate) fn get_qe_target(&self) -> TargetInfo { - self.qe_target - } -} diff --git a/sgx_trts/src/version.rs b/sgx_trts/src/version.rs index 5b911094b..6a5466776 100644 --- a/sgx_trts/src/version.rs +++ b/sgx_trts/src/version.rs @@ -16,6 +16,6 @@ // under the License. pub const MAJOR_VERSION: usize = 2; -pub const MINOR_VERSION: usize = 27; +pub const MINOR_VERSION: usize = 29; pub const REVISION_VERSION: usize = 100; pub const VERSION_UINT: usize = (MAJOR_VERSION << 32) | (MINOR_VERSION << 16) | REVISION_VERSION;