fscrypt-crypt-util: add HKDF context constants
authorEric Biggers <ebiggers@google.com>
Mon, 2 Dec 2019 23:01:52 +0000 (15:01 -0800)
committerEryu Guan <guaneryu@gmail.com>
Fri, 3 Jan 2020 07:57:37 +0000 (15:57 +0800)
Use #defines rather than hard-coded numbers + comments.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
src/fscrypt-crypt-util.c

index bafc15e0660405451622b885047a3e72fdfa3988..30f5e5851eb8e35837891f193f7b7e3cc51cf0a1 100644 (file)
@@ -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;