signature.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Signature verification with an asymmetric key
  2. *
  3. * See Documentation/security/asymmetric-keys.txt
  4. *
  5. * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
  6. * Written by David Howells (dhowells@redhat.com)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public Licence
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the Licence, or (at your option) any later version.
  12. */
  13. #include <keys/asymmetric-subtype.h>
  14. #include <linux/module.h>
  15. #include <linux/err.h>
  16. #include <crypto/public_key.h>
  17. #include "asymmetric_keys.h"
  18. /**
  19. * verify_signature - Initiate the use of an asymmetric key to verify a signature
  20. * @key: The asymmetric key to verify against
  21. * @sig: The signature to check
  22. *
  23. * Returns 0 if successful or else an error.
  24. */
  25. int verify_signature(const struct key *key,
  26. const struct public_key_signature *sig)
  27. {
  28. const struct asymmetric_key_subtype *subtype;
  29. int ret;
  30. pr_devel("==>%s()\n", __func__);
  31. if (key->type != &key_type_asymmetric)
  32. return -EINVAL;
  33. subtype = asymmetric_key_subtype(key);
  34. if (!subtype ||
  35. !key->payload.data)
  36. return -EINVAL;
  37. if (!subtype->verify_signature)
  38. return -ENOTSUPP;
  39. ret = subtype->verify_signature(key, sig);
  40. pr_devel("<==%s() = %d\n", __func__, ret);
  41. return ret;
  42. }
  43. EXPORT_SYMBOL_GPL(verify_signature);