Skip to content

fix: avoid resetting method.hashUpdate #95

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

This is a list of notable changes to Intel® Cryptography Primitives Library, in reverse chronological order.

## Intel(R) Cryptography Primitives Library 1.1.1
- Fixed setting the `method.hashUpdate` variable twice in `ippsHashMethod_SHA256_TT` implementation. In a multithreaded environment this destroyed memory caches. Note that to make the code cleaner I used an early return in the special `sha256_ni_hashUpdate` case. Fixes intel/linux-sgx#1073

## Intel(R) Cryptography Primitives Library 1.1.0

- Added single buffer SM4 (former SMS4) algorithm with the new SM4 instructions for Lunar Lake and Arrow Lake S CPUs.
Expand Down
40 changes: 18 additions & 22 deletions sources/ippcp/hash/sha1/pcphashmethod_sha1_tt.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,25 @@
//
*F*/

IPPFUN( const IppsHashMethod*, ippsHashMethod_SHA1_TT, (void) )
IPPFUN(const IppsHashMethod*, ippsHashMethod_SHA1_TT, (void))
{
static IppsHashMethod method = {
ippHashAlg_SHA1,
IPP_SHA1_DIGEST_BITSIZE/8,
MBS_SHA1,
MLR_SHA1,
NULL,
NULL,
NULL,
NULL,
};
static IppsHashMethod method = {
ippHashAlg_SHA1, IPP_SHA1_DIGEST_BITSIZE / 8, MBS_SHA1, MLR_SHA1, NULL, NULL, NULL, NULL,
};

// don't merge `method` initialization with function pointers assignment
// to prevent relocations (indirect calls) to be generated in the binary
method.hashInit = sha1_hashInit;
method.hashUpdate = sha1_hashUpdate;
method.hashOctStr = sha1_hashOctString;
method.msgLenRep = sha1_msgRep;
// don't merge `method` initialization with function pointers assignment
// to prevent relocations (indirect calls) to be generated in the binary
method.hashInit = sha1_hashInit;
method.hashOctStr = sha1_hashOctString;
method.msgLenRep = sha1_msgRep;

#if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_==_FEATURE_ON_)
if(IsFeatureEnabled(ippCPUID_SHA))
method.hashUpdate = sha1_ni_hashUpdate;
#endif
return &method;
#if (_SHA_NI_ENABLING_ == _FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_ == _FEATURE_ON_)
if (IsFeatureEnabled(ippCPUID_SHA)) {
method.hashUpdate = sha1_ni_hashUpdate;
return &method;
}
#endif

method.hashUpdate = sha1_hashUpdate;
return &method;
}
32 changes: 17 additions & 15 deletions sources/ippcp/hash/sha1/pcphashmethodset_sha1_tt.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,26 @@
//
*F*/

IPPFUN( IppStatus, ippsHashMethodSet_SHA1_TT, (IppsHashMethod* pMethod) )
IPPFUN(IppStatus, ippsHashMethodSet_SHA1_TT, (IppsHashMethod * pMethod))
{
/* test pointers */
IPP_BAD_PTR1_RET(pMethod);
/* test pointers */
IPP_BAD_PTR1_RET(pMethod);

pMethod->hashAlgId = ippHashAlg_SHA1;
pMethod->hashLen = IPP_SHA1_DIGEST_BITSIZE/8;
pMethod->msgBlkSize = MBS_SHA1;
pMethod->msgLenRepSize = MLR_SHA1;
pMethod->hashInit = sha1_hashInit;
pMethod->hashUpdate = sha1_hashUpdate;
pMethod->hashOctStr = sha1_hashOctString;
pMethod->msgLenRep = sha1_msgRep;
pMethod->hashAlgId = ippHashAlg_SHA1;
pMethod->hashLen = IPP_SHA1_DIGEST_BITSIZE / 8;
pMethod->msgBlkSize = MBS_SHA1;
pMethod->msgLenRepSize = MLR_SHA1;
pMethod->hashInit = sha1_hashInit;
pMethod->hashOctStr = sha1_hashOctString;
pMethod->msgLenRep = sha1_msgRep;

#if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_==_FEATURE_ON_)
if(IsFeatureEnabled(ippCPUID_SHA))
pMethod->hashUpdate = sha1_ni_hashUpdate;
#if (_SHA_NI_ENABLING_ == _FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_ == _FEATURE_ON_)
if (IsFeatureEnabled(ippCPUID_SHA)) {
pMethod->hashUpdate = sha1_ni_hashUpdate;
return ippStsNoErr;
}
#endif

return ippStsNoErr;
pMethod->hashUpdate = sha1_hashUpdate;
return ippStsNoErr;
}
47 changes: 25 additions & 22 deletions sources/ippcp/hash/sha224/pcphashmethod_sha224_tt.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,32 @@
//
*F*/

IPPFUN( const IppsHashMethod*, ippsHashMethod_SHA224_TT, (void) )
IPPFUN(const IppsHashMethod*, ippsHashMethod_SHA224_TT, (void))
{
static IppsHashMethod method = {
ippHashAlg_SHA224,
IPP_SHA224_DIGEST_BITSIZE/8,
MBS_SHA256,
MLR_SHA256,
NULL,
NULL,
NULL,
NULL,
};
static IppsHashMethod method = {
ippHashAlg_SHA224,
IPP_SHA224_DIGEST_BITSIZE / 8,
MBS_SHA256,
MLR_SHA256,
NULL,
NULL,
NULL,
NULL,
};

// don't merge `method` initialization with function pointers assignment
// to prevent relocations (indirect calls) to be generated in the binary
method.hashInit = sha224_hashInit;
method.hashUpdate = sha256_hashUpdate;
method.hashOctStr = sha224_hashOctString;
method.msgLenRep = sha256_msgRep;
// don't merge `method` initialization with function pointers assignment
// to prevent relocations (indirect calls) to be generated in the binary
method.hashInit = sha224_hashInit;
method.hashOctStr = sha224_hashOctString;
method.msgLenRep = sha256_msgRep;

#if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_==_FEATURE_ON_)
if(IsFeatureEnabled(ippCPUID_SHA))
method.hashUpdate = sha256_ni_hashUpdate;
#endif
return &method;
#if (_SHA_NI_ENABLING_ == _FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_ == _FEATURE_ON_)
if (IsFeatureEnabled(ippCPUID_SHA)) {
method.hashUpdate = sha256_ni_hashUpdate;
return &method;
}
#endif

method.hashUpdate = sha256_hashUpdate;
return &method;
}
32 changes: 17 additions & 15 deletions sources/ippcp/hash/sha224/pcphashmethodset_sha224_tt.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,26 @@
//
*F*/

IPPFUN( IppStatus, ippsHashMethodSet_SHA224_TT, (IppsHashMethod* pMethod) )
IPPFUN(IppStatus, ippsHashMethodSet_SHA224_TT, (IppsHashMethod * pMethod))
{
/* test pointers */
IPP_BAD_PTR1_RET(pMethod);
/* test pointers */
IPP_BAD_PTR1_RET(pMethod);

pMethod->hashAlgId = ippHashAlg_SHA224;
pMethod->hashLen = IPP_SHA224_DIGEST_BITSIZE/8;
pMethod->msgBlkSize = MBS_SHA256;
pMethod->msgLenRepSize = MLR_SHA256;
pMethod->hashInit = sha224_hashInit;
pMethod->hashUpdate = sha256_hashUpdate;
pMethod->hashOctStr = sha224_hashOctString;
pMethod->msgLenRep = sha256_msgRep;
pMethod->hashAlgId = ippHashAlg_SHA224;
pMethod->hashLen = IPP_SHA224_DIGEST_BITSIZE / 8;
pMethod->msgBlkSize = MBS_SHA256;
pMethod->msgLenRepSize = MLR_SHA256;
pMethod->hashInit = sha224_hashInit;
pMethod->hashOctStr = sha224_hashOctString;
pMethod->msgLenRep = sha256_msgRep;

#if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_==_FEATURE_ON_)
if(IsFeatureEnabled(ippCPUID_SHA))
pMethod->hashUpdate = sha256_ni_hashUpdate;
#if (_SHA_NI_ENABLING_ == _FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_ == _FEATURE_ON_)
if (IsFeatureEnabled(ippCPUID_SHA)) {
pMethod->hashUpdate = sha256_ni_hashUpdate;
return ippStsNoErr;
}
#endif

return ippStsNoErr;
pMethod->hashUpdate = sha256_hashUpdate;
return ippStsNoErr;
}
36 changes: 20 additions & 16 deletions sources/ippcp/hash/sha224/pcphashstatemethodset_sha224_tt.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,30 @@
//
*F*/

IPPFUN( IppStatus, ippsHashStateMethodSet_SHA224_TT, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) )
IPPFUN(IppStatus,
ippsHashStateMethodSet_SHA224_TT,
(IppsHashState_rmf * pState, IppsHashMethod* pMethod))
{
/* test pointers */
IPP_BAD_PTR2_RET(pState, pMethod);
/* test pointers */
IPP_BAD_PTR2_RET(pState, pMethod);

HASH_METHOD(pState) = pMethod;
HASH_METHOD(pState) = pMethod;

pMethod->hashAlgId = ippHashAlg_SHA224;
pMethod->hashLen = IPP_SHA224_DIGEST_BITSIZE/8;
pMethod->msgBlkSize = MBS_SHA256;
pMethod->msgLenRepSize = MLR_SHA256;
pMethod->hashInit = sha224_hashInit;
pMethod->hashUpdate = sha256_hashUpdate;
pMethod->hashOctStr = sha224_hashOctString;
pMethod->msgLenRep = sha256_msgRep;
pMethod->hashAlgId = ippHashAlg_SHA224;
pMethod->hashLen = IPP_SHA224_DIGEST_BITSIZE / 8;
pMethod->msgBlkSize = MBS_SHA256;
pMethod->msgLenRepSize = MLR_SHA256;
pMethod->hashInit = sha224_hashInit;
pMethod->hashOctStr = sha224_hashOctString;
pMethod->msgLenRep = sha256_msgRep;

#if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_==_FEATURE_ON_)
if(IsFeatureEnabled(ippCPUID_SHA))
pMethod->hashUpdate = sha256_ni_hashUpdate;
#if (_SHA_NI_ENABLING_ == _FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_ == _FEATURE_ON_)
if (IsFeatureEnabled(ippCPUID_SHA)) {
pMethod->hashUpdate = sha256_ni_hashUpdate;
return ippStsNoErr;
}
#endif

return ippStsNoErr;
pMethod->hashUpdate = sha256_hashUpdate;
return ippStsNoErr;
}
44 changes: 23 additions & 21 deletions sources/ippcp/hash/sha256/pcphashmethod_sha256_tt.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,32 @@
//
*F*/

IPPFUN( const IppsHashMethod*, ippsHashMethod_SHA256_TT, (void) )
IPPFUN(const IppsHashMethod*, ippsHashMethod_SHA256_TT, (void))
{
static IppsHashMethod method = {
ippHashAlg_SHA256,
IPP_SHA256_DIGEST_BITSIZE/8,
MBS_SHA256,
MLR_SHA256,
NULL,
NULL,
NULL,
NULL,
};
static IppsHashMethod method = {
ippHashAlg_SHA256,
IPP_SHA256_DIGEST_BITSIZE / 8,
MBS_SHA256,
MLR_SHA256,
NULL,
NULL,
NULL,
NULL,
};

// don't merge `method` initialization with function pointers assignment
// to prevent relocations (indirect calls) to be generated in the binary
method.hashInit = sha256_hashInit;
method.hashUpdate = sha256_hashUpdate;
method.hashOctStr = sha256_hashOctString;
method.msgLenRep = sha256_msgRep;
// don't merge `method` initialization with function pointers assignment
// to prevent relocations (indirect calls) to be generated in the binary
method.hashInit = sha256_hashInit;
method.hashOctStr = sha256_hashOctString;
method.msgLenRep = sha256_msgRep;

#if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_==_FEATURE_ON_)
if(IsFeatureEnabled(ippCPUID_SHA))
method.hashUpdate = sha256_ni_hashUpdate;
#if (_SHA_NI_ENABLING_ == _FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_ == _FEATURE_ON_)
if (IsFeatureEnabled(ippCPUID_SHA)) {
method.hashUpdate = sha256_ni_hashUpdate;
return &method;
}
#endif

return &method;
method.hashUpdate = sha256_hashUpdate;
return &method;
}
32 changes: 17 additions & 15 deletions sources/ippcp/hash/sha256/pcphashmethodset_sha256_tt.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,26 @@
//
*F*/

IPPFUN( IppStatus, ippsHashMethodSet_SHA256_TT, (IppsHashMethod* pMethod) )
IPPFUN(IppStatus, ippsHashMethodSet_SHA256_TT, (IppsHashMethod * pMethod))
{
/* test pointers */
IPP_BAD_PTR1_RET(pMethod);
/* test pointers */
IPP_BAD_PTR1_RET(pMethod);

pMethod->hashAlgId = ippHashAlg_SHA256;
pMethod->hashLen = IPP_SHA256_DIGEST_BITSIZE/8;
pMethod->msgBlkSize = MBS_SHA256;
pMethod->msgLenRepSize = MLR_SHA256;
pMethod->hashInit = sha256_hashInit;
pMethod->hashUpdate = sha256_hashUpdate;
pMethod->hashOctStr = sha256_hashOctString;
pMethod->msgLenRep = sha256_msgRep;
pMethod->hashAlgId = ippHashAlg_SHA256;
pMethod->hashLen = IPP_SHA256_DIGEST_BITSIZE / 8;
pMethod->msgBlkSize = MBS_SHA256;
pMethod->msgLenRepSize = MLR_SHA256;
pMethod->hashInit = sha256_hashInit;
pMethod->hashOctStr = sha256_hashOctString;
pMethod->msgLenRep = sha256_msgRep;

#if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_==_FEATURE_ON_)
if(IsFeatureEnabled(ippCPUID_SHA))
pMethod->hashUpdate = sha256_ni_hashUpdate;
#if (_SHA_NI_ENABLING_ == _FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_ == _FEATURE_ON_)
if (IsFeatureEnabled(ippCPUID_SHA)) {
pMethod->hashUpdate = sha256_ni_hashUpdate;
return ippStsNoErr;
}
#endif

return ippStsNoErr;
pMethod->hashUpdate = sha256_hashUpdate;
return ippStsNoErr;
}
36 changes: 20 additions & 16 deletions sources/ippcp/hash/sha256/pcphashstatemethodset_sha256_tt.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,30 @@
//
*F*/

IPPFUN( IppStatus, ippsHashStateMethodSet_SHA256_TT, (IppsHashState_rmf* pState, IppsHashMethod* pMethod) )
IPPFUN(IppStatus,
ippsHashStateMethodSet_SHA256_TT,
(IppsHashState_rmf * pState, IppsHashMethod* pMethod))
{
/* test pointers */
IPP_BAD_PTR2_RET(pState, pMethod);
/* test pointers */
IPP_BAD_PTR2_RET(pState, pMethod);

HASH_METHOD(pState) = pMethod;
HASH_METHOD(pState) = pMethod;

pMethod->hashAlgId = ippHashAlg_SHA256;
pMethod->hashLen = IPP_SHA256_DIGEST_BITSIZE/8;
pMethod->msgBlkSize = MBS_SHA256;
pMethod->msgLenRepSize = MLR_SHA256;
pMethod->hashInit = sha256_hashInit;
pMethod->hashUpdate = sha256_hashUpdate;
pMethod->hashOctStr = sha256_hashOctString;
pMethod->msgLenRep = sha256_msgRep;
pMethod->hashAlgId = ippHashAlg_SHA256;
pMethod->hashLen = IPP_SHA256_DIGEST_BITSIZE / 8;
pMethod->msgBlkSize = MBS_SHA256;
pMethod->msgLenRepSize = MLR_SHA256;
pMethod->hashInit = sha256_hashInit;
pMethod->hashOctStr = sha256_hashOctString;
pMethod->msgLenRep = sha256_msgRep;

#if (_SHA_NI_ENABLING_==_FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_==_FEATURE_ON_)
if(IsFeatureEnabled(ippCPUID_SHA))
pMethod->hashUpdate = sha256_ni_hashUpdate;
#if (_SHA_NI_ENABLING_ == _FEATURE_TICKTOCK_ || _SHA_NI_ENABLING_ == _FEATURE_ON_)
if (IsFeatureEnabled(ippCPUID_SHA)) {
pMethod->hashUpdate = sha256_ni_hashUpdate;
return ippStsNoErr;
}
#endif

return ippStsNoErr;
pMethod->hashUpdate = sha256_hashUpdate;
return ippStsNoErr;
}
Loading