masterkey_trusted.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2010 IBM Corporation
  4. * Copyright (C) 2010 Politecnico di Torino, Italy
  5. * TORSEC group -- https://security.polito.it
  6. *
  7. * Authors:
  8. * Mimi Zohar <[email protected]>
  9. * Roberto Sassu <[email protected]>
  10. *
  11. * See Documentation/security/keys/trusted-encrypted.rst
  12. */
  13. #include <linux/uaccess.h>
  14. #include <linux/err.h>
  15. #include <keys/trusted-type.h>
  16. #include <keys/encrypted-type.h>
  17. #include "encrypted.h"
  18. /*
  19. * request_trusted_key - request the trusted key
  20. *
  21. * Trusted keys are sealed to PCRs and other metadata. Although userspace
  22. * manages both trusted/encrypted key-types, like the encrypted key type
  23. * data, trusted key type data is not visible decrypted from userspace.
  24. */
  25. struct key *request_trusted_key(const char *trusted_desc,
  26. const u8 **master_key, size_t *master_keylen)
  27. {
  28. struct trusted_key_payload *tpayload;
  29. struct key *tkey;
  30. tkey = request_key(&key_type_trusted, trusted_desc, NULL);
  31. if (IS_ERR(tkey))
  32. goto error;
  33. down_read(&tkey->sem);
  34. tpayload = tkey->payload.data[0];
  35. *master_key = tpayload->key;
  36. *master_keylen = tpayload->key_len;
  37. error:
  38. return tkey;
  39. }