digsig.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (C) 2011 Intel Corporation
  3. *
  4. * Author:
  5. * Dmitry Kasatkin <dmitry.kasatkin@intel.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, version 2 of the License.
  10. *
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/err.h>
  14. #include <linux/rbtree.h>
  15. #include <linux/key-type.h>
  16. #include <linux/digsig.h>
  17. #include "integrity.h"
  18. static struct key *keyring[INTEGRITY_KEYRING_MAX];
  19. static const char *keyring_name[INTEGRITY_KEYRING_MAX] = {
  20. "_evm",
  21. "_module",
  22. "_ima",
  23. };
  24. int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,
  25. const char *digest, int digestlen)
  26. {
  27. if (id >= INTEGRITY_KEYRING_MAX)
  28. return -EINVAL;
  29. if (!keyring[id]) {
  30. keyring[id] =
  31. request_key(&key_type_keyring, keyring_name[id], NULL);
  32. if (IS_ERR(keyring[id])) {
  33. int err = PTR_ERR(keyring[id]);
  34. pr_err("no %s keyring: %d\n", keyring_name[id], err);
  35. keyring[id] = NULL;
  36. return err;
  37. }
  38. }
  39. return digsig_verify(keyring[id], sig, siglen, digest, digestlen);
  40. }