提交 100129a4 编写于 作者: D Dave Jiang 提交者: Caspar Zhang

keys-encrypted: add nvdimm key format type to encrypted keys

to #27305291

commit 9db67581b91d9e9e05c35570ac3f93872e6c84ca upstream.

Adding nvdimm key format type to encrypted keys in order to limit the size
of the key to 32bytes.
Signed-off-by: NDave Jiang <dave.jiang@intel.com>
Acked-by: NMimi Zohar <zohar@linux.ibm.com>
Signed-off-by: NDan Williams <dan.j.williams@intel.com>
Signed-off-by: NShile Zhang <shile.zhang@linux.alibaba.com>
Reviewed-by: NYang Shi <yang.shi@linux.alibaba.com>
上级 12aad331
...@@ -76,7 +76,7 @@ Usage:: ...@@ -76,7 +76,7 @@ Usage::
Where:: Where::
format:= 'default | ecryptfs' format:= 'default | ecryptfs | enc32'
key-type:= 'trusted' | 'user' key-type:= 'trusted' | 'user'
...@@ -173,3 +173,7 @@ are anticipated. In particular the new format 'ecryptfs' has been defined in ...@@ -173,3 +173,7 @@ are anticipated. In particular the new format 'ecryptfs' has been defined in
in order to use encrypted keys to mount an eCryptfs filesystem. More details in order to use encrypted keys to mount an eCryptfs filesystem. More details
about the usage can be found in the file about the usage can be found in the file
``Documentation/security/keys/ecryptfs.rst``. ``Documentation/security/keys/ecryptfs.rst``.
Another new format 'enc32' has been defined in order to support encrypted keys
with payload size of 32 bytes. This will initially be used for nvdimm security
but may expand to other usages that require 32 bytes payload.
...@@ -45,6 +45,7 @@ static const char hmac_alg[] = "hmac(sha256)"; ...@@ -45,6 +45,7 @@ static const char hmac_alg[] = "hmac(sha256)";
static const char blkcipher_alg[] = "cbc(aes)"; static const char blkcipher_alg[] = "cbc(aes)";
static const char key_format_default[] = "default"; static const char key_format_default[] = "default";
static const char key_format_ecryptfs[] = "ecryptfs"; static const char key_format_ecryptfs[] = "ecryptfs";
static const char key_format_enc32[] = "enc32";
static unsigned int ivsize; static unsigned int ivsize;
static int blksize; static int blksize;
...@@ -54,6 +55,7 @@ static int blksize; ...@@ -54,6 +55,7 @@ static int blksize;
#define HASH_SIZE SHA256_DIGEST_SIZE #define HASH_SIZE SHA256_DIGEST_SIZE
#define MAX_DATA_SIZE 4096 #define MAX_DATA_SIZE 4096
#define MIN_DATA_SIZE 20 #define MIN_DATA_SIZE 20
#define KEY_ENC32_PAYLOAD_LEN 32
static struct crypto_shash *hash_tfm; static struct crypto_shash *hash_tfm;
...@@ -62,12 +64,13 @@ enum { ...@@ -62,12 +64,13 @@ enum {
}; };
enum { enum {
Opt_error = -1, Opt_default, Opt_ecryptfs Opt_error = -1, Opt_default, Opt_ecryptfs, Opt_enc32
}; };
static const match_table_t key_format_tokens = { static const match_table_t key_format_tokens = {
{Opt_default, "default"}, {Opt_default, "default"},
{Opt_ecryptfs, "ecryptfs"}, {Opt_ecryptfs, "ecryptfs"},
{Opt_enc32, "enc32"},
{Opt_error, NULL} {Opt_error, NULL}
}; };
...@@ -195,6 +198,7 @@ static int datablob_parse(char *datablob, const char **format, ...@@ -195,6 +198,7 @@ static int datablob_parse(char *datablob, const char **format,
key_format = match_token(p, key_format_tokens, args); key_format = match_token(p, key_format_tokens, args);
switch (key_format) { switch (key_format) {
case Opt_ecryptfs: case Opt_ecryptfs:
case Opt_enc32:
case Opt_default: case Opt_default:
*format = p; *format = p;
*master_desc = strsep(&datablob, " \t"); *master_desc = strsep(&datablob, " \t");
...@@ -625,15 +629,22 @@ static struct encrypted_key_payload *encrypted_key_alloc(struct key *key, ...@@ -625,15 +629,22 @@ static struct encrypted_key_payload *encrypted_key_alloc(struct key *key,
format_len = (!format) ? strlen(key_format_default) : strlen(format); format_len = (!format) ? strlen(key_format_default) : strlen(format);
decrypted_datalen = dlen; decrypted_datalen = dlen;
payload_datalen = decrypted_datalen; payload_datalen = decrypted_datalen;
if (format && !strcmp(format, key_format_ecryptfs)) { if (format) {
if (dlen != ECRYPTFS_MAX_KEY_BYTES) { if (!strcmp(format, key_format_ecryptfs)) {
pr_err("encrypted_key: keylen for the ecryptfs format " if (dlen != ECRYPTFS_MAX_KEY_BYTES) {
"must be equal to %d bytes\n", pr_err("encrypted_key: keylen for the ecryptfs format must be equal to %d bytes\n",
ECRYPTFS_MAX_KEY_BYTES); ECRYPTFS_MAX_KEY_BYTES);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
}
decrypted_datalen = ECRYPTFS_MAX_KEY_BYTES;
payload_datalen = sizeof(struct ecryptfs_auth_tok);
} else if (!strcmp(format, key_format_enc32)) {
if (decrypted_datalen != KEY_ENC32_PAYLOAD_LEN) {
pr_err("encrypted_key: enc32 key payload incorrect length: %d\n",
decrypted_datalen);
return ERR_PTR(-EINVAL);
}
} }
decrypted_datalen = ECRYPTFS_MAX_KEY_BYTES;
payload_datalen = sizeof(struct ecryptfs_auth_tok);
} }
encrypted_datalen = roundup(decrypted_datalen, blksize); encrypted_datalen = roundup(decrypted_datalen, blksize);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册