From faf3abfe3f16e13e321b5a60613db8c8df88201d Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Mon, 2 Dec 2019 15:01:52 -0800 Subject: [PATCH] fscrypt-crypt-util: add HKDF context constants Use #defines rather than hard-coded numbers + comments. Signed-off-by: Eric Biggers Reviewed-by: Eryu Guan Signed-off-by: Eryu Guan --- src/fscrypt-crypt-util.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fscrypt-crypt-util.c b/src/fscrypt-crypt-util.c index bafc15e0..30f5e585 100644 --- a/src/fscrypt-crypt-util.c +++ b/src/fscrypt-crypt-util.c @@ -1703,6 +1703,10 @@ struct key_and_iv_params { bool file_nonce_specified; }; +#define HKDF_CONTEXT_KEY_IDENTIFIER 1 +#define HKDF_CONTEXT_PER_FILE_KEY 2 +#define HKDF_CONTEXT_PER_MODE_KEY 3 + /* * Get the key and starting IV with which the encryption will actually be done. * If a KDF was specified, a subkey is derived from the master key and the mode @@ -1743,11 +1747,11 @@ static void get_key_and_iv(const struct key_and_iv_params *params, break; case KDF_HKDF_SHA512: if (params->mode_num != 0) { - info[infolen++] = 3; /* HKDF_CONTEXT_PER_MODE_KEY */ + info[infolen++] = HKDF_CONTEXT_PER_MODE_KEY; info[infolen++] = params->mode_num; file_nonce_in_iv = true; } else if (params->file_nonce_specified) { - info[infolen++] = 2; /* HKDF_CONTEXT_PER_FILE_KEY */ + info[infolen++] = HKDF_CONTEXT_PER_FILE_KEY; memcpy(&info[infolen], params->file_nonce, FILE_NONCE_SIZE); infolen += FILE_NONCE_SIZE; -- 2.30.2