masterkey_trusted.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (C) 2010 IBM Corporation
  3. * Copyright (C) 2010 Politecnico di Torino, Italy
  4. * TORSEC group -- http://security.polito.it
  5. *
  6. * Authors:
  7. * Mimi Zohar <zohar@us.ibm.com>
  8. * Roberto Sassu <roberto.sassu@polito.it>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, version 2 of the License.
  13. *
  14. * See Documentation/security/keys-trusted-encrypted.txt
  15. */
  16. #include <linux/uaccess.h>
  17. #include <linux/module.h>
  18. #include <linux/err.h>
  19. #include <keys/trusted-type.h>
  20. /*
  21. * request_trusted_key - request the trusted key
  22. *
  23. * Trusted keys are sealed to PCRs and other metadata. Although userspace
  24. * manages both trusted/encrypted key-types, like the encrypted key type
  25. * data, trusted key type data is not visible decrypted from userspace.
  26. */
  27. struct key *request_trusted_key(const char *trusted_desc,
  28. u8 **master_key, size_t *master_keylen)
  29. {
  30. struct trusted_key_payload *tpayload;
  31. struct key *tkey;
  32. tkey = request_key(&key_type_trusted, trusted_desc, NULL);
  33. if (IS_ERR(tkey))
  34. goto error;
  35. down_read(&tkey->sem);
  36. tpayload = rcu_dereference(tkey->payload.data);
  37. *master_key = tpayload->key;
  38. *master_keylen = tpayload->key_len;
  39. error:
  40. return tkey;
  41. }