Skip to contentSkip to conversation

Security: Keys: Big keys stored encrypted

PATCH Superseded Kirill Marinushkin 2 participants 2 messages Mar 30, 2016 – Apr 1, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Security: Keys: Big keys stored encrypted

Solved TODO task: big keys saved to shmem file are now stored encrypted. The encryption key is randomly generated and saved to payload[big_key_data].

---
 security/keys/Kconfig   |   4 ++
 security/keys/big_key.c | 187 +++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 173 insertions(+), 18 deletions(-)
security/keys/Kconfig +4 -0
index fe4d74e..4582809 100644
@@ -41,6 +41,10 @@ config BIG_KEYS
 	bool "Large payload keys"
 	depends on KEYS
 	depends on TMPFS
+	select CRYPTO
+	select CRYPTO_AES
+	select CRYPTO_ECB
+	select CRYPTO_RNG
 	help
 	  This option provides support for holding large keys within the kernel
 	  (for example Kerberos ticket caches).  The data may be stored out to
security/keys/big_key.c +169 -18

278 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#1 lore raw

security/keys/big_key.c enum { · line 38

Quoted 4 lines · Kirill Marinushkin
security/keys/big_key.c +4 -0
+enum {
+	ENC,
+	DEC,
+};

"enum big_key_mode" and use it as a parameter type to big_key_crypt().

Also BIG_KEY_ENC, BIG_KEY_DEC. Please use prefixes consistently.

security/keys/big_key.c enum { · line 70

Quoted 6 lines
security/keys/big_key.c +6 -0
+static const char *rng_name = "stdrng";
+
+/*
+ * Algorithm name for big_key data encryption
+ */
+static const char *alg_name = "ecb(aes)";

Use const char arrays not const char pointers as that saves on a pointer storage.

security/keys/big_key.c enum { · line 60

Quoted 4 lines
security/keys/big_key.c +4 -0
+/*
+ * Aligned data length of big_key encryption
+ */
+#define ALIGNED_LEN(l)	(l + ENC_BLOCK_SIZE - l % ENC_BLOCK_SIZE)

Surely there's a crypto thing for this? The block size and key size ought to be functions of the algorithm you select rather than being hardcoded.

Quoted 1 line

+static int gen_enckey(u8 *key)

big_key_gen_enckey().

Quoted 4 lines
security/keys/big_key.c +4 -0
+{
+	int ret = -EINVAL;
+	struct crypto_rng *rng = NULL;
+

security/keys/big_key.c struct key_type key_type_big_key = { · line 104

Quoted 10 lines
security/keys/big_key.c +10 -0
+	rng = crypto_alloc_rng(rng_name, 0, 0);
+	if (IS_ERR(rng))
+		return -EFAULT;
+
+	ret = crypto_rng_reset(rng, NULL, crypto_rng_seedsize(rng));
+
+	if (!ret)
+		ret = crypto_rng_get_bytes(rng, key, ENC_KEY_SIZE);
+
+	if (rng)

rng can be NULL here?!

Quoted 1 line

+static int big_crypt(u8 op, u8 *data, size_t datalen, u8 *key)

big_key_crypt().