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

KMAC implementation using EVP_MAC #7597

Closed
wants to merge 1 commit into from
Closed

Conversation

slontis
Copy link
Member

@slontis slontis commented Nov 9, 2018

Checklist
  • documentation is added or updated
  • tests are added or updated

crypto/kmac/kmac.c Outdated Show resolved Hide resolved
Copy link
Contributor

@paulidale paulidale left a comment

Choose a reason for hiding this comment

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

A few minor comments, but looking good for the most part.

crypto/evp/m_sha3.c Outdated Show resolved Hide resolved
crypto/kmac/kmac.c Show resolved Hide resolved
if (kctx->custom_len == 0)
(void)kmac_ctrl_str(kctx, "custom", "");

return bytepad(out, &out_len, kmac_string, sizeof(kmac_string),
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we support a sequence like:

init()
init()
update()
final()

where the effects of the first init are ignored?

I don't see why we should and if that assumption is correct, the code is here if fine.

Copy link
Member Author

@slontis slontis Nov 12, 2018

Choose a reason for hiding this comment

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

Hmm this should probably be made to work.. So I will cache md and not do the digestInit to the kmac_init().

crypto/kmac/kmac.c Show resolved Hide resolved
crypto/kmac/kmac.c Show resolved Hide resolved
@slontis slontis force-pushed the new-kmac branch 2 times, most recently from a458bad to 2beca10 Compare November 12, 2018 02:21
@slontis slontis force-pushed the new-kmac branch 2 times, most recently from b2ea98f to b369a18 Compare November 12, 2018 03:59
crypto/kmac/kmac.c Show resolved Hide resolved

switch (cmd) {
case EVP_MAC_CTRL_SET_XOF:
kctx->xof_mode = va_arg(args, size_t);
Copy link
Contributor

Choose a reason for hiding this comment

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

The documentation claims the type should be unsigned long not size_t.


EVP_MAC_ctrl_str() type string: "xof"

The value string is expected to be an unsigned long. Use 1 to enable XOF mode.
Copy link
Contributor

Choose a reason for hiding this comment

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

This type doesn't match the code (in two different ways). How about using an int?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@paulidale paulidale added approval: review pending This pull request needs review by a committer branch: master Merge to master branch labels Nov 12, 2018
* right_encoded(requested output length).

* All other Ctrl functions should be set before init().
* EVP_MAC_CTRL_SET_MD must be set before EVP_MAC_CTRL_SET_KEY.
Copy link
Member

Choose a reason for hiding this comment

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

This line should be removed

/*
* The following Ctrl functions can be set any time before final():
* - EVP_MAC_CTRL_SET_SIZE: The requested output length.
* - EVP_MAC_CTRL_SET_XOF_MODE: If set, this indicates that
Copy link
Member

Choose a reason for hiding this comment

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

Lose _MODE

@@ -1027,6 +1030,9 @@ void EVP_MAC_do_all_sorted(void (*fn)
# define EVP_MAC_CTRL_SET_CIPHER 0x05 /* EVP_CIPHER * */
# define EVP_MAC_CTRL_SET_SIZE 0x06 /* size_t */
# define EVP_MAC_CTRL_SET_IV 0x07 /* unsigned char *, size_t */
# define EVP_MAC_CTRL_SET_CUSTOM 0x08 /* unsigned char *, size_t */
# define EVP_MAC_CTRL_SET_XOF 0x09 /* unsigned long */

Copy link
Member

Choose a reason for hiding this comment

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

Lose the extra blank line


=item B<EVP_MAC_CTRL_SET_KEY>

This can only be used after B<EVP_MAC_CTRL_SET_MD> has been set.
Copy link
Member

Choose a reason for hiding this comment

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

Lose this line

Copy link
Member

Choose a reason for hiding this comment

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

Also, you should probably specify that this can't be called after EVP_MAC_init


=back

=item B<EVP_MAC_CTRL_SET_CUSTOM>
Copy link
Member

Choose a reason for hiding this comment

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

You should probably specify that this can't be called after EVP_MAC_init

EVP_MAC_ctrl_str() type string: "outlen"

The value string is expected to contain a decimal number. This can be used to
override the default value that is specified by the digest.
Copy link
Member

Choose a reason for hiding this comment

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

This probably needs to be rephrased, since you don't set the MD any more.


=item B<EVP_MAC_CTRL_SET_XOF>

This control expects one argument: C<unsigned long flags>
Copy link
Member

Choose a reason for hiding this comment

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

s/unsigned long/int/

@@ -1027,6 +1030,9 @@ void EVP_MAC_do_all_sorted(void (*fn)
# define EVP_MAC_CTRL_SET_CIPHER 0x05 /* EVP_CIPHER * */
# define EVP_MAC_CTRL_SET_SIZE 0x06 /* size_t */
# define EVP_MAC_CTRL_SET_IV 0x07 /* unsigned char *, size_t */
# define EVP_MAC_CTRL_SET_CUSTOM 0x08 /* unsigned char *, size_t */
# define EVP_MAC_CTRL_SET_XOF 0x09 /* unsigned long */
Copy link
Member

Choose a reason for hiding this comment

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

s/unsigned long/int/

Copy link
Member Author

Choose a reason for hiding this comment

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

should all be updated now.

@paulidale
Copy link
Contributor

Could a test case with xof = 0 explicitly listed be added? This should catch the varargs type change.
Just amend an existing case with this, no need to create a new one.

Copy link
Contributor

@paulidale paulidale left a comment

Choose a reason for hiding this comment

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

Still looks good.

@levitte levitte added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Nov 13, 2018
@paulidale
Copy link
Contributor

Merged to master. Thanks for the patience everyone.

@paulidale paulidale closed this Nov 13, 2018
levitte pushed a commit that referenced this pull request Nov 13, 2018
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #7597)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: done This pull request has the required number of approvals branch: master Merge to master branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants