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

EVP_PKEY_cmp() fails for HMAC EVP_PKEYs #1236

Closed
npmccallum opened this issue Jun 20, 2016 · 1 comment
Closed

EVP_PKEY_cmp() fails for HMAC EVP_PKEYs #1236

npmccallum opened this issue Jun 20, 2016 · 1 comment

Comments

@npmccallum
Copy link
Contributor

  #include <openssl/evp.h>
  #include <assert.h>

  int
  main()
  {
      EVP_PKEY *a = NULL;
      EVP_PKEY *b = NULL;

      a = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, "foo", 3);
      b = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, "foo", 3);
      assert(a);
      assert(b);

      assert(EVP_PKEY_cmp(a, b) == 0);
      return 0;
  }
test: test.c:15: main: Assertion `EVP_PKEY_cmp(a, b) == 0' failed.
@mattcaswell
Copy link
Member

If you check the return value from EVP_PKEY_cmp() you will find that it is -2 in the above code. The documentation for EVP_PKEY_cmp() has this to say on its return values:

The function EVP_PKEY_cmp_parameters() and EVP_PKEY_cmp() return 1 if the
keys match, 0 if they don't match, -1 if the key types are different and
-2 if the operation is not supported.

So this means "operation is not supported" in your context. That's because we don't currently support comparison of HMAC keys.

This isn't a bug as such, its a missing feature. Perhaps the documentation could be more explicit about which EVP_PKEY types actually support comparison.

@mattcaswell mattcaswell added this to the 1.1.0 milestone Jun 20, 2016
npmccallum added a commit to npmccallum/openssl that referenced this issue Jun 22, 2016
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

No branches or pull requests

2 participants