siphash_ameth.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2007-2017 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include "internal/cryptlib.h"
  11. #include <openssl/evp.h>
  12. #include "internal/asn1_int.h"
  13. #include "internal/siphash.h"
  14. #include "siphash_local.h"
  15. /*
  16. * SIPHASH "ASN1" method. This is just here to indicate the maximum
  17. * SIPHASH output length and to free up a SIPHASH key.
  18. */
  19. static int siphash_size(const EVP_PKEY *pkey)
  20. {
  21. return SIPHASH_MAX_DIGEST_SIZE;
  22. }
  23. static void siphash_key_free(EVP_PKEY *pkey)
  24. {
  25. ASN1_OCTET_STRING *os = EVP_PKEY_get0(pkey);
  26. if (os != NULL) {
  27. if (os->data != NULL)
  28. OPENSSL_cleanse(os->data, os->length);
  29. ASN1_OCTET_STRING_free(os);
  30. }
  31. }
  32. static int siphash_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
  33. {
  34. /* nothing (including ASN1_PKEY_CTRL_DEFAULT_MD_NID), is supported */
  35. return -2;
  36. }
  37. static int siphash_pkey_public_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
  38. {
  39. return ASN1_OCTET_STRING_cmp(EVP_PKEY_get0(a), EVP_PKEY_get0(b));
  40. }
  41. const EVP_PKEY_ASN1_METHOD siphash_asn1_meth = {
  42. EVP_PKEY_SIPHASH,
  43. EVP_PKEY_SIPHASH,
  44. 0,
  45. "SIPHASH",
  46. "OpenSSL SIPHASH method",
  47. 0, 0, siphash_pkey_public_cmp, 0,
  48. 0, 0, 0,
  49. siphash_size,
  50. 0, 0,
  51. 0, 0, 0, 0, 0, 0, 0,
  52. siphash_key_free,
  53. siphash_pkey_ctrl,
  54. 0, 0
  55. };