dm crypt: properly handle extra key string in initialization
authorMilan Broz <gmazyland@gmail.com>
Mon, 28 Oct 2013 22:21:03 +0000 (23:21 +0100)
committerAlex Shi <alex.shi@linaro.org>
Tue, 23 Jun 2015 07:28:33 +0000 (15:28 +0800)
commit797cd96ddf07f958b9f4786e03003e96a49c8d9a
tree63ab61273b1f95efeb8f19f7f1fd535d5e5e41fb
parent3cd53f7be1bb2cdc2d47e96a81084de15b4172db
dm crypt: properly handle extra key string in initialization

Some encryption modes use extra keys (e.g. loopAES has IV seed) which
are not used in block cipher initialization but are part of key string
in table constructor.

This patch adds an additional field which describes the length of the
extra key(s) and substracts it before real key encryption setting.

The key_size always includes the size, in bytes, of the key provided
in mapping table.

The key_parts describes how many parts (usually keys) are contained in
the whole key buffer.  And key_extra_size contains size in bytes of
additional keys part (this number of bytes must be subtracted because it
is processed by the IV generator).

| K1 | K2 | .... | K64 |      Kiv       |
|----------- key_size ----------------- |
|                      |-key_extra_size-|
|     [64 keys]        |  [1 key]       | => key_parts = 65

Example where key string contains main key K, whitening key
Kw and IV seed Kiv:

|     K       |   Kiv   |       Kw      |
|--------------- key_size --------------|
|             |-----key_extra_size------|
|  [1 key]    | [1 key] |     [1 key]   | => key_parts = 3

Because key_extra_size is calculated during IV mode setting, key
initialization is moved after this step.

For now, this change has no effect to supported modes (thanks to ilog2
rounding) but it is required by the following patch.

Also, fix a sparse warning in crypt_iv_lmk_one().

Signed-off-by: Milan Broz <gmazyland@gmail.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
(cherry picked from commit da31a0787a2ac92dd219ce0d33322160b66d6a01)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
drivers/md/dm-crypt.c