hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/fs/crypto/hkdf.c
....@@ -16,9 +16,14 @@
1616
1717 /*
1818 * HKDF supports any unkeyed cryptographic hash algorithm, but fscrypt uses
19
- * SHA-512 because it is reasonably secure and efficient; and since it produces
20
- * a 64-byte digest, deriving an AES-256-XTS key preserves all 64 bytes of
21
- * entropy from the master key and requires only one iteration of HKDF-Expand.
19
+ * SHA-512 because it is well-established, secure, and reasonably efficient.
20
+ *
21
+ * HKDF-SHA256 was also considered, as its 256-bit security strength would be
22
+ * sufficient here. A 512-bit security strength is "nice to have", though.
23
+ * Also, on 64-bit CPUs, SHA-512 is usually just as fast as SHA-256. In the
24
+ * common case of deriving an AES-256-XTS key (512 bits), that can result in
25
+ * HKDF-SHA512 being much faster than HKDF-SHA256, as the longer digest size of
26
+ * SHA-512 causes HKDF-Expand to only need to do one iteration rather than two.
2227 */
2328 #define HKDF_HMAC_ALG "hmac(sha512)"
2429 #define HKDF_HASHLEN SHA512_DIGEST_SIZE
....@@ -44,18 +49,13 @@
4449 unsigned int ikmlen, u8 prk[HKDF_HASHLEN])
4550 {
4651 static const u8 default_salt[HKDF_HASHLEN];
47
- SHASH_DESC_ON_STACK(desc, hmac_tfm);
4852 int err;
4953
5054 err = crypto_shash_setkey(hmac_tfm, default_salt, HKDF_HASHLEN);
5155 if (err)
5256 return err;
5357
54
- desc->tfm = hmac_tfm;
55
- desc->flags = 0;
56
- err = crypto_shash_digest(desc, ikm, ikmlen, prk);
57
- shash_desc_zero(desc);
58
- return err;
58
+ return crypto_shash_tfm_digest(hmac_tfm, ikm, ikmlen, prk);
5959 }
6060
6161 /*
....@@ -129,7 +129,6 @@
129129 return -EINVAL;
130130
131131 desc->tfm = hkdf->hmac_tfm;
132
- desc->flags = 0;
133132
134133 memcpy(prefix, "fscrypt\0", 8);
135134 prefix[8] = context;