-
Notifications
You must be signed in to change notification settings - Fork 177
Add support for CMAC #891
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
base: master
Are you sure you want to change the base?
Add support for CMAC #891
Conversation
Thanks for working on this series. The base class Regarding the method naming, is there particular reason for choosing The Also, we need docs. |
@@ -0,0 +1,174 @@ | |||
#include "ossl.h" | |||
|
|||
#if OSSL_OPENSSL_PREREQ(3, 0, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe LibreSSL and AWS-LC will eventually implement the EVP_MAC
API too. Please use an extconf.rb
check instead of relying on the version number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does any of the following approaches align with what you're suggesting?
OpenSSL::MAC
should be defined if all necessary OpenSSL functions are available.OpenSSL::MAC
should be defined if a preselected OpenSSL function is available.- Each
OpenSSL::MAC
method should raise an exception unless all OpenSSL functions it needs are available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can assume the type EVP_MAC{,_CTX}
and the related functions will be added in the same release, so checking any one of them should be sufficient.
def hexmac | ||
mac.unpack1('H*') | ||
end | ||
alias inspect hexmac |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think people would expect #inspect
to show the class name or the algorithm rather than the calculated MAC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This aims to align OpenSSL::MAC
subclasses with OpenSSL::HMAC
to facilitate future migrations to OpenSSL::MAC::HMAC
.
OpenSSL::HMAC
has inspect
as an alias for hexdigest
, though it's unlikely that anyone would depend on that alias in production code.
If OpenSSL::HMAC
didn't exist, I'd prefer OpenSSL::MAC::CMAC#inspect
to behave exactly like Object#inspect
.
Considering this, should we remove OpenSSL::MAC#inspect
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point it's in OpenSSL::HMAC
. IMHO OpenSSL::MAC
doesn't have to follow it.
The digest
library (and thus OpenSSL::Digest
)'s #inspect
seems to return an Object#inspect
-style string.
return false unless self.mac.bytesize == other.mac.bytesize | ||
|
||
OpenSSL.fixed_length_secure_compare(self.mac, other.mac) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comparing MACs generated by different algorithms or parameters would be pointless, but this doesn't prevent it and it's probably not possible unless we store parameters or sensitive keys ourselves, which would be a bad idea.
Honestly, I'm not sure if this should be provided by this library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, too, aims to align OpenSSL::MAC
subclasses with OpenSSL::HMAC
to facilitate future migrations to OpenSSL::MAC::HMAC
.
OpenSSL::HMAC
has an ==
method similar to this one, thereby comparing its objects as calculated values.
That said, objects of these classes are essentially calculators.
There seems little need to compare them as such, and as you indicate, no appropriate way to implement such a comparison.
If OpenSSL::HMAC
didn't exist, I'd prefer to treat OpenSSL::MAC::CMAC
objects only as calculators and avoid adding this ==
method.
Considering this, should we remove OpenSSL::MAC#==
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've forgotten it was in OpenSSL::HMAC
. It seems to have the same issue.
IMO we should not add it to OpenSSL::MAC
, though we can't remove the existing method from OpenSSL::HMAC
.
Thanks for the second review.
I think we can do it the way you suggest.
I chose the method names like "mac" because OpenSSL refers to MACs as "MACs," distinguishing them from "digests." |
I leaning towards sticking with the Digging through the history, it appears |
FWIW, in #906, I've been working on exposing
I'm hoping they can have a consistent behavior. |
Follow-up to #806.
Implements #802 by adding the
OpenSSL::MAC
andOpenSSL::MAC::CMAC
classes.The classes are defined if compiled against OpenSSL 3.