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

Incremental Keccak API #4259

Merged
merged 1 commit into from
Sep 4, 2018
Merged

Conversation

ph4r05
Copy link
Contributor

@ph4r05 ph4r05 commented Aug 14, 2018

  • needed for TREZOR integration

memcpy(md, ctx->hash, KECCAK_DIGESTSIZE);
}

memset(ctx, 0, sizeof(KECCAK_CTX));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could possibly do with a memwipe. Not sure if really necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would leave the call whether necessary or not to you, you know better

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably unneeded, since there's no free there, though the caller might. We can add it later if it's found to be needed.

}
while (inlen >= KECCAK_BLOCKLEN) {
uint64_t* aligned_message_block;
if (IS_ALIGNED_64(in)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

KECCAK_BLOCKLEN is a multiple of 8, so this calc is only needed once. In fact, if not aligned, a prefix can be memcpy'd, then an aligned loop can follow. Might end up more complicated, not sure. It'd also allow the round function to xor a uint64_t at a time in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the uint64_t xor and computation of IS_ALIGNED_64 only once.

But I don't see how to make unaligned input data aligned as in this state the leftover message buffer is empty and one Keccak round needs 17*8=136 bytes at a time.

}

void keccak_update(KECCAK_CTX * ctx, const uint8_t *in, size_t inlen){
size_t idx = (size_t)ctx->rest;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe make rest size_t, it'd avoid needless word size conversions.

// 1600 bits algorithm hashing state
uint64_t hash[25];
// 1536-bit buffer for leftovers
uint64_t message[24];
Copy link
Collaborator

Choose a reason for hiding this comment

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

That seems too large. Looks like it needs 136 bytes, so 17 uint64_t. Is this wrong ?

void keccak_update(KECCAK_CTX * ctx, const uint8_t *in, size_t inlen){
size_t idx = (size_t)ctx->rest;

if (ctx->rest & KECCAK_FINALIZED) return; // too late for additional input
Copy link
Collaborator

Choose a reason for hiding this comment

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

That might be worth a hard error, it's a programming error.

if (IS_ALIGNED_64(in)) {
// the most common case is processing of an already aligned message
// without copying it
aligned_message_block = (uint64_t*)(void*)in;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The double cast seems unneeded.

inlen -= left;
}
while (inlen >= KECCAK_BLOCKLEN) {
uint64_t* aligned_message_block;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be const, it's input.

@ph4r05
Copy link
Contributor Author

ph4r05 commented Aug 14, 2018

Thanks for review. I will squash eventually.

- needed for TREZOR integration
@ph4r05
Copy link
Contributor Author

ph4r05 commented Aug 15, 2018

Done

@moneromooo-monero
Copy link
Collaborator

FYI: #4275

@ph4r05
Copy link
Contributor Author

ph4r05 commented Aug 17, 2018 via email

@prusnak
Copy link

prusnak commented Aug 31, 2018

Can we have this merged if there is no opposition and tests are ready too?

@luigi1111 luigi1111 merged commit 4e08100 into monero-project:master Sep 4, 2018
luigi1111 added a commit that referenced this pull request Sep 4, 2018
4e08100 Incremental Keccak API added (pr4r05)
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.

4 participants