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

_gcry_md_hash_buffers_extract can be used instead of _gcry_md_open&write&extract&close. #37

Closed
Tracked by #24
falko-strenzke opened this issue Oct 17, 2023 · 1 comment
Labels
invalid This doesn't seem right

Comments

@falko-strenzke
Copy link

falko-strenzke commented Oct 17, 2023

from Jussi's review

mlkem-common.c: _gcry_mlkem_mlkem_shake256_rkprf:
gcry_md_hash_buffers_extract can be used here instead of _gcry_md_open&write&extract&close.

mlkem-symmetric.c: _gcry_mlkem_shake256_prf:
_gcry_md_hash_buffers_extract can be used here instead of _gcry_md_open&write&extract&close. Temporary buffer > usage can be avoided by passing input buffers through two IOV to _gcry_md_hash_buffers_extract.

@falko-strenzke
Copy link
Author

falko-strenzke commented Oct 17, 2023

in the code of _gcry_md_hash_buffers_extract it says:

The only supported flag in FLAGS is GCRY_MD_FLAG_HMAC which turns this function into a HMAC function; the first item in IOV is then used as the key."

The flag GCRY_MD_FLAG_SECURE that we need is thus not supported. Also I don't see much saving in code lines, as also the buffer object would have to be initialized.

This is the code I used to test it which gave a runtime error (Invalid Argument):

static gcry_err_code_t
_gcry_mlkem_mlkem_shake256_rkprf (uint8_t out[GCRY_MLKEM_SSBYTES],
                                  const uint8_t key[GCRY_MLKEM_SYMBYTES],
                                  const uint8_t *input,
                                  size_t input_length)
{
    gcry_buffer_t buf;
    buf.data = (void*) input;
    buf.off = 0;
    buf.len = input_length;
    buf.size = input_length;
return _gcry_md_hash_buffers_extract(GCRY_MD_SHAKE256, GCRY_MD_FLAG_SECURE, out, GCRY_MLKEM_SSBYTES, &buf, 1);
}

@falko-strenzke falko-strenzke added the invalid This doesn't seem right label Oct 17, 2023
@falko-strenzke falko-strenzke changed the title _gcry_md_hash_buffers_extract can be used here instead of _gcry_md_open&write&extract&close. _gcry_md_hash_buffers_extract can be used instead of _gcry_md_open&write&extract&close. Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant