Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) 2010 IBM Corporation
0004  * Copyright (C) 2010 Politecnico di Torino, Italy
0005  *                    TORSEC group -- https://security.polito.it
0006  *
0007  * Authors:
0008  * Mimi Zohar <zohar@us.ibm.com>
0009  * Roberto Sassu <roberto.sassu@polito.it>
0010  *
0011  * See Documentation/security/keys/trusted-encrypted.rst
0012  */
0013 
0014 #include <linux/uaccess.h>
0015 #include <linux/err.h>
0016 #include <keys/trusted-type.h>
0017 #include <keys/encrypted-type.h>
0018 #include "encrypted.h"
0019 
0020 /*
0021  * request_trusted_key - request the trusted key
0022  *
0023  * Trusted keys are sealed to PCRs and other metadata. Although userspace
0024  * manages both trusted/encrypted key-types, like the encrypted key type
0025  * data, trusted key type data is not visible decrypted from userspace.
0026  */
0027 struct key *request_trusted_key(const char *trusted_desc,
0028                 const u8 **master_key, size_t *master_keylen)
0029 {
0030     struct trusted_key_payload *tpayload;
0031     struct key *tkey;
0032 
0033     tkey = request_key(&key_type_trusted, trusted_desc, NULL);
0034     if (IS_ERR(tkey))
0035         goto error;
0036 
0037     down_read(&tkey->sem);
0038     tpayload = tkey->payload.data[0];
0039     *master_key = tpayload->key;
0040     *master_keylen = tpayload->key_len;
0041 error:
0042     return tkey;
0043 }