Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Added crypto callback for SHA3. #7670

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

aidangarske
Copy link
Contributor

Description

Added crypto callback for SHA3 and extended the test.c tests for it in cryptocb_test.

Testing

./configure --enable-cryptocb --enable-sha3 CFLAGS="-DDEBUG_CRYPTOCB" --enable-debug
make 
./wolfcrypt/test/testwolfcrypt

@aidangarske aidangarske self-assigned this Jun 20, 2024
@dgarske
Copy link
Contributor

dgarske commented Jun 21, 2024

Retest this please

@JacobBarthelmeh JacobBarthelmeh merged commit 0303a82 into wolfSSL:master Jun 21, 2024
120 checks passed
Copy link
Contributor

@billphipps billphipps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok, but I'd like to see the existing pattern of using the p (block count) and len to determine the type instead of modifying and adding a member to track it. Also, there's a bug in InitSha3 that clears the devId, so the end of Final should either invoke the wc_InitSha3(..., sha3->devId) or InitSha3 should be updated to remember the devId.

(void)devId;
#elif defined(WOLF_CRYPTO_CB)
sha3->devId = devId;
sha3->type = type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the other cases (async, sw), the p parameter passed into SHA3_Update and SHA3_Final controls which type (256, 384, 512) of SHA3 is being used. Consider letting the the processing functions determine the info->hash->type based on that and remove the type parameter/member here. Comments below.

if (sha3->devId != INVALID_DEVID)
#endif
{
ret = wc_CryptoCb_Sha3Hash(sha3, sha3->type, NULL, 0, hash);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider:
int type = 0;
switch(len) {
case WC_SHA3_224_DIGEST_SIZE: type = WC_HASH_TYPE_SHA3_224; break;
case WC_SHA3_256_DIGEST_SIZE: type = WC_HASH_TYPE_SHA3_256; break;
case WC_SHA3_384_DIGEST_SIZE: type = WC_HASH_TYPE_SHA3_384; break;
case WC_SHA3_512_DIGEST_SIZE: type = WC_HASH_TYPE_SHA3_512; break;
default: return WC_ERROR_BAD_ARG;
}
ret = wc_CryptoCb_Sha3Hash(sha, type, NULL, 0, hash);

if (sha3->devId != INVALID_DEVID)
#endif
{
ret = wc_CryptoCb_Sha3Hash(sha3, sha3->type, data, len, NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider:
int type = 0;
switch(p) {
case WC_SHA3_224_COUNT: type = WC_HASH_TYPE_SHA3_224; break;
case WC_SHA3_256_COUNT: type = WC_HASH_TYPE_SHA3_256; break;
case WC_SHA3_384_COUNT: type = WC_HASH_TYPE_SHA3_384; break;
case WC_SHA3_512_COUNT: type = WC_HASH_TYPE_SHA3_512; break;
default: return WC_ERROR_BAD_ARG;
}
ret = wc_CryptoCb_Sha3Hash(sha, type, NULL, 0, hash);

wolfcrypt/src/sha3.c Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants