crypto: loop-AES support
Subsystems (4)
RFC PATCH 1/1 crypto: loop-AES support
This set adds an implementation of the Loop-AES block encryption modes for dm-crypt.
It consists of two main parts:
(1) blkcipher implementation of the Loop-AES block chaining modes (lmk2, lmk3)
(2) Support for alternating keys in dm-crypt.
The patches are based on cryptodev-2.6.
Together they can be used to access encrypted images created with loop-AES.
Loop-AES v2.x multi-key-v2 mode corresponds to the dm-crypt cipher spec "aes-lmk2-plain64-multi:64", v2.x corresponds to "aes-lmk3-plain64-multi:64".
Tested on mips32 and x86_64.
To actually use this with Loop-AES encrypted images you will need a key derivator which converts Loop-AES format keyfiles into a hexstring for dm-crypt.
I'm putting some rough code for testing up on
http://hinterhof.net/~max/keyderive-0.1.tar.gz
Please note that this is not intended to be used with any valuable keys yet. I'll work on a robust derivator once the kernel side is done.
Looking forward to comments and review,
Max
PATCH 1/4 dm-crypt: clarify cipher vs. cipher mode
The original code used cc->cipher for two things:
(a) It starts out containing the cipher mode string ("xts(aes)") used to get the ablkcipher.
(b) Then it gets overwritten to contain just the plain cipher string ("aes") used to allocate the plain cipher for essiv and for display by dm status.
So change it to be used only for the latter and put cipher mode string on the stack.
--- drivers/md/dm-crypt.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/md/dm-crypt.c +3 -2
@@ -1014,6 +1014,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)char *ivopts;unsigned int key_size;unsigned long long tmpll; +char ciphermode[CRYPTO_MAX_ALG_NAME ];if (argc !=5 ) { ti->error ="Not enough arguments" ;
@@ -1049,13 +1050,13 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) goto bad_cipher; } -if (snprintf (cc->cipher,CRYPTO_MAX_ALG_NAME ,"%s(%s)" , +if (snprintf (ciphermode,CRYPTO_MAX_ALG_NAME ,"%s(%s)" , chainmode, cipher) >=CRYPTO_MAX_ALG_NAME ) { ti->error ="Chain mode + cipher name is too long" ; goto bad_cipher; } - tfm =crypto_alloc_ablkcipher (cc->cipher,0 ,0 ); + tfm =crypto_alloc_ablkcipher (ciphermode,0 ,0 );if (IS_ERR (tfm)) { ti->error ="Error allocating crypto tfm" ; goto bad_cipher;
Signature · 1 line
1.6.5.4
Re: [PATCH 1/4] dm-crypt: clarify cipher vs. cipher mode
drivers/md/dm-crypt.c static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) · line 1017
Quoted 7 lines · Max Vozeler
The original code used
cc->cipherfor two things:drivers/md/dm-crypt.c +1
-0@@ -1014,6 +1014,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)char *ivopts;unsigned int key_size;unsigned long long tmpll; +char ciphermode[CRYPTO_MAX_ALG_NAME ];
Today is CRYPTO_MAX_ALG_NAME 64 bytes but it can increase in future. This should not be allocated on the stack.
But anyway, I see that the reason for this is to introduce multikey feature (compatible with loop-AES mode). That's interesting idea.
But please can you add more explanation into documentation about this mode? Is there any paper which analyses that mode - if so can you add link to description?
(and yes, I know loop-AES documentation:-)
Milan
--
[email protected]
Re: [PATCH 1/4] dm-crypt: clarify cipher vs. cipher mode
Quoted 11 lines · Milan Broz
drivers/md/dm-crypt.c static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) · line 1017
Quoted 7 lines · Max Vozeler
The original code used
cc->cipherfor two things:drivers/md/dm-crypt.c +1
-0@@ -1014,6 +1014,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)char *ivopts;unsigned int key_size;unsigned long long tmpll; +char ciphermode[CRYPTO_MAX_ALG_NAME ];Today is
CRYPTO_MAX_ALG_NAME64 bytes but it can increase in future. This should not be allocated on the stack.
OK. The mode string is only ever used within crypt_ctr(). It does not seem worth to move it into struct crypt_config or have it dynamically allocated, so I'll drop this cleanup.
Quoted 4 lines
But anyway, I see that the reason for this is to introduce multikey feature (compatible with loop-AES mode). That's interesting idea.
But please can you add more explanation into documentation about this mode?
Sure, let me see what I can do.
The most detailed description I know of is [1]. Besides the description in the Loop-AES documentation there are also some notes I took while doing the reimplementation.
I'll see if I can put all these bits together into a document to have one mode and format specification.
Quoted 3 lines
Is there any paper which analyses that mode - if so can you add link to description?
(and yes, I know loop-AES documentation:-)
I'm not aware of any papers which analyze these modes.
The 2004 paper by Saarinen[2] I think is what prompted the creation of these modes, specifically do protect against the weaknesses pointed out therein.
The resulting v2 and v3 modes have not been independently analyzed as far as I'm aware. Anyone know better?
Thanks for your comments,
Max
Signature · 2 lines
[1] http://mail.nl.linux.org/linux-crypto/2006-01/msg00006.html [2] http://mareichelt.de/pub/notmine/diskenc.pdf
Re: [PATCH 1/4] dm-crypt: clarify cipher vs. cipher mode
Quoted 6 lines · Max Vozeler
Quoted 4 lines · Milan Broz
But anyway, I see that the reason for this is to introduce multikey feature (compatible with loop-AES mode). That's interesting idea.
But please can you add more explanation into documentation about this mode?
Quoted 8 lines
Sure, let me see what I can do.
The most detailed description I know of is [1]. Besides the description in the Loop-AES documentation there are also some notes I took while doing the reimplementation.
I'll see if I can put all these bits together into a document to have one mode and format specification.
This adds a short document detailing the two multi-key modes. I think it covers all important points.
Review much appreciated. Thanks,
Max
Documentation/crypto/lmk.txt new file +72 -0
@@ -0,0 +1,72 @@ +Loop-AES compatible cipher block chaining modes +----------------------------------------------- + +There are three modes supported by loop-AES at the time of this +writing: + + Loop-AES v1.x single-key cbc-plain + Loop-AES v2.x multi-key-v2 lmk2-plain64-multi:64 + Loop-AES v3.x multi-key-v3 lmk3-plain64-multi:64 + +This text describes the multi-key-v2 and multi-key-v3 modes and +their implementation in the Linux kernel. + +These modes have two main characteristics compared to regular CBC +with sector IV. The first is implemented in dm-crypt, the second +is implemented in the lmk2 and lmk3 blkciphers. + +1) Use of 64 independent keys which are alternatingly applied to +different sectors. + + key = keys[sectornum % 64] + +2) IV derivation from an MD5 digest of the sector number, parts +of the plaintext data and a mode specific format constant. The +multi-key-v3 mode additionally uses a 128-bit IV seed. + + v2IV = MD5(plaintext[16..511] || + truncated-sector-number || + format-magic) + + v3IV = MD5(ivseed || + plaintext[16..511] || + truncated-sector-number || + format-magic) + +The sector number is obtained from the plain64 dm-crypt IV +generator. It is converted to 64-bit little endian and then +truncated to 56 bits: + + truncated-sector-number = + (sectornum & 0x00ffffffffffffff) | 0x8000000000000000 + +The format-magic for both modes is fixed at the value 4024 +encoded as 32-bit little endian. + +Encryption: + + IV = IVFUNC(optional-ivseed, + plaintext[16..511], + truncated-sector-number, + format-magic) + + ciphertext[0..511] = CBC-ENCRYPT(key, IV, plaintext[0..511]) + +Decryption: + + IV1 = ciphertext[0..15] + + plaintext[16..511] = CBC-DECRYPT(key, IV1, ciphertext[16..511]) + + IV2 = IVFUNC(optional-ivseed, + plaintext[16..511], + truncated-sector-number, + format-magic) + + plaintext[0..15] = DECRYPT(key, IV2, ciphertext[0..15]) + +References: + + Mode description by the author of Loop-AES, Jari Ruusu: + http://mail.nl.linux.org/linux-crypto/2006-01/msg00006.html +
Re: [PATCH 1/4] dm-crypt: clarify cipher vs. cipher mode
Documentation/crypto/lmk.txt line 16
Quoted 4 lines · Max Vozeler
Documentation/crypto/lmk.txt new file +4
-0+ +These modes have two main characteristics compared to regular CBC +with sector IV. The first is implemented in dm-crypt, the second +is implemented in the lmk2 and lmk3 blkciphers.
the formulation is not very clear. Possibly better wording -
+ There are two main differences distinguishing the lmk2 and lmk3 modes
+ from the blok cipher implemented in dm-crypt:
Documentation/crypto/lmk.txt line 21
Quoted 4 lines
+1) Use of 64 independent keys which are alternatingly applied to
Documentation/crypto/lmk.txt new file +3
-0+different sectors. + + key = keys[sectornum % 64]
not really "alternating" when there is more than 2, my try "different sectors are encrypted with 64 independent keys selected by the following rule"
+ key = keys[sectornum % 64]
Documentation/crypto/lmk.txt line 25
Quoted 3 lines
+2) IV derivation from an MD5 digest of the sector number, parts
Documentation/crypto/lmk.txt new file +2
-0+of the plaintext data and a mode specific format constant. The +multi-key-v3 mode additionally uses a 128-bit IV seed.
slightly rephrased:
+2) IVs are derived from an MD5 digest of the sector number, parts +of the plaintext data and a mode specific format constant. The +multi-key-v3 mode additionally uses a 128-bit IV seed.
Documentation/crypto/lmk.txt line 34
Quoted 8 lines
Documentation/crypto/lmk.txt new file +8
-0+ v2IV = MD5(plaintext[16..511] || + truncated-sector-number || + format-magic) + + v3IV = MD5(ivseed || + plaintext[16..511] || + truncated-sector-number || + format-magic)
that seems different than what is described here -
http://mail.nl.linux.org/linux-crypto/2006-01/msg00006.html
so is it compatible after all? Or where is format-magic' equivalent hidden in Jari's description?
Documentation/crypto/lmk.txt line 44
Quoted 2 lines
Documentation/crypto/lmk.txt new file +2
-0+The format-magic for both modes is fixed at the value 4024 +encoded as 32-bit little endian.
I am not familiar with this detail and the description does not make it completely clear, it appears to refer to some magic value of the on disk representation?
Documentation/crypto/lmk.txt line 51
Quoted 6 lines
Documentation/crypto/lmk.txt new file +6
-0+Encryption: + + IV = IVFUNC(optional-ivseed, + plaintext[16..511], + truncated-sector-number, + format-magic)
optional first argument in formalism makes it hard to relate to above decriptions. So maybe introduce IVFUNC where you describe them above, including ivseed which is simply unused in one variant.
Quoted 1 line
+ ciphertext[0..511] = CBC-ENCRYPT(key, IV, plaintext[0..511])
I know that key=key_table[sector_number & 63] is mentioned further above but might be "too far back" for many readers as it is one of the things that are special about this encryption modes.
Richard
Re: [PATCH 1/4] dm-crypt: clarify cipher vs. cipher mode
Hi Richard,
Quoted 10 lines · Richard Zidlicky
Review
Quoted 4 lines · Max Vozeler
(quoted diff) +4
-0+ +These modes have two main characteristics compared to regular CBC +with sector IV. The first is implemented in dm-crypt, the second +is implemented in the lmk2 and lmk3 blkciphers.the formulation is not very clear. Possibly better wording -
+ There are two main differences distinguishing the lmk2 and lmk3 modes
+ from the blok cipher implemented in dm-crypt:
I reworked this part in the new version below.
Quoted 9 lines
Review
Quoted 4 lines
+1) Use of 64 independent keys which are alternatingly applied to
(quoted diff) +3
-0+different sectors. + + key = keys[sectornum % 64]not really "alternating" when there is more than 2, my try "different sectors are encrypted with 64 independent keys selected by the following rule"
+ key = keys[sectornum % 64]
Good point, thanks.
Review
Quoted 9 lines
Review
Quoted 3 lines
+2) IV derivation from an MD5 digest of the sector number, parts
(quoted diff) +2
-0+of the plaintext data and a mode specific format constant. The +multi-key-v3 mode additionally uses a 128-bit IV seed.slightly rephrased:
+2) IVs are derived from an MD5 digest of the sector number, parts
(quoted diff) +2
-0+of the plaintext data and a mode specific format constant. The +multi-key-v3 mode additionally uses a 128-bit IV seed.
Agreed. I included your rephrasing.
Quoted 12 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ v2IV = MD5(plaintext[16..511] || + truncated-sector-number || + format-magic) + + v3IV = MD5(ivseed || + plaintext[16..511] || + truncated-sector-number || + format-magic)that seems different than what is described here -
http://mail.nl.linux.org/linux-crypto/2006-01/msg00006.html
Quoted 2 lines
so is it compatible after all? Or where is format-magic' equivalent hidden in Jari's description?
The format-magic is not mentioned in Jari's description, but is indeed used by Loop-AES.
Compare loop-AES-v3.2h/glue.c:402:
/* 4024 bits == 31 * 128 bit plaintext blocks + 56 bits of sector number */ /* For version 3 on-disk format this really should be 4536 bits, but can't be */ /* changed without breaking compatibility. V3 uses MD5-with-wrong-length IV */ buf[14] = 4024;
buf[15] = 0;
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+The format-magic for both modes is fixed at the value 4024 +encoded as 32-bit little endian.I am not familiar with this detail and the description does not make it completely clear, it appears to refer to some magic value of the on disk representation?
The magic is only used as an additional input to the MD5 digest as part of the IV derivation.
Changed the description to hopefully clarify this.
Quoted 11 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+Encryption: + + IV = IVFUNC(optional-ivseed, + plaintext[16..511], + truncated-sector-number, + format-magic)optional first argument in formalism makes it hard to relate to above decriptions. So maybe introduce IVFUNC where you describe them above, including ivseed which is simply unused in one variant.
Quoted 5 lines
Quoted 1 line
+ ciphertext[0..511] = CBC-ENCRYPT(key, IV, plaintext[0..511])
I know that key=key_table[sector_number & 63] is mentioned further above but might be "too far back" for many readers as it is one of the things that are special about this encryption modes.
Agreed on both points. Could you have a look and see if you find it clearer now in the new version?
Thanks a lot for your comments,
Max
Documentation/crypto/lmk.txt new file +102 -0
@@ -0,0 +1,102 @@ +Loop-AES compatible cipher block chaining modes +----------------------------------------------- + +The following table shows the Loop-AES name of the mode, the +Loop-AES version first supporting it, and the equivalent cipher +specification string for dm-crypt: + + single-key Loop-AES v1.x cbc-plain + multi-key-v2 Loop-AES v2.x lmk2-plain64-multi:64 + multi-key-v3 Loop-AES v3.x lmk3-plain64-multi:64 + +This text describes the multi-key-v2 and multi-key-v3 modes and +their implementation in the Linux kernel. + +The multi-key modes describe a combination of CBC using a +specific IV derivation function with the use of multiple +independent encryption keys. + +The IV derivation and block chaining are implemented as +blkciphers named "lmk2" and "lmk3". The support for multiple +encryption keys is implemented in dm-crypt. + +Multiple keys: + + Each sector is encrypted/decrypted with one of 64 independent + keys selected by the following rule: + + key = keys[sectornum % 64] + +IV derivation: + + IVs are derived from an MD5 digest of the sector number, parts + of the plaintext data and a mode specific format constant. The + multi-key-v3 mode additionally uses a 128-bit IV seed. + + v2IV = MD5(plaintext[16..511] || + le64(truncated-sector-number) || + le32(format-magic)) + + v3IV = MD5(ivseed || + plaintext[16..511] || + le64(truncated-sector-number) || + le32(format-magic)) + + The format-magic is a constant value (4024). + + The input IV supplied to lmk2 or lmk3 is expected to be the + sector number in 64-bit little endian as supplied by the + plain64 dm-crypt IV generator. It gets truncated to 56 bits + with the most significant byte set to 0x80: + + truncated-sector-number = + (sectornum & 0x00ffffffffffffff) | 0x8000000000000000 + +Mode multi-key-v2 (lmk2-plain64-multi:64): + + key = keys[sectornum % 64] + + encrypt: + IV = MD5(plaintext[16..511] || + le64(truncated-sector-number) || + le32(format-magic)) + + ciphertext[0..511] = CBC-ENCRYPT(key, IV, plaintext[0..511]) + + decrypt: + IV1 = ciphertext[0..15] + plaintext[16..511] = CBC-DECRYPT(key, IV1, ciphertext[16..511]) + + IV2 = MD5(plaintext[16..511] || + le64(truncated-sector-number) || + le32(format-magic)) + + plaintext[0..15] = DECRYPT(key, IV2, ciphertext[0..15]) + +Mode multi-key-v3 (lmk3-plain64-multi:64): + + key = keys[sectornum % 64] + + encrypt: + IV = MD5(ivseed, + plaintext[16..511], + le64(truncated-sector-number), + le32(format-magic)) + + ciphertext[0..511] = CBC-ENCRYPT(key, IV, plaintext[0..511]) + + decrypt: + IV1 = ciphertext[0..15] + plaintext[16..511] = CBC-DECRYPT(key, IV1, ciphertext[16..511]) + + IV2 = MD5(ivseed, + plaintext[16..511], + le64(truncated-sector-number), + le32(format-magic)) + + plaintext[0..15] = DECRYPT(key, IV2, ciphertext[0..15]) + +References: + +Mode description by the author of Loop-AES, Jari Ruusu: +http://mail.nl.linux.org/linux-crypto/2006-01/msg00006.html
Re: [PATCH 1/4] dm-crypt: clarify cipher vs. cipher mode
Hi,
Quoted 30 lines
The format-magic is not mentioned in Jari's description, but is indeed used by Loop-AES.
Compare
loop-AES-v3.2h/glue.c:402:/* 4024 bits == 31 * 128 bit plaintext blocks + 56 bits of sector number */ /* For version 3 on-disk format this really should be 4536 bits, but can't be */ /* changed without breaking compatibility. V3 uses MD5-with-wrong-length IV */ buf[14] = 4024;
buf[15] = 0;Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+The format-magic for both modes is fixed at the value 4024 +encoded as 32-bit little endian.I am not familiar with this detail and the description does not make it completely clear, it appears to refer to some magic value of the on disk representation?
The magic is only used as an additional input to the MD5 digest as part of the IV derivation.
Documentation/crypto/lmk.txt new file +3
-0@@ -0,0 +1,102 @@ +Loop-AES compatible cipher block chaining modes +----------------------------------------------- +
Documentation/crypto/lmk.txt line 13
Quoted 10 lines
Documentation/crypto/lmk.txt new file +10
-0+The following table shows the Loop-AES name of the mode, the +Loop-AES version first supporting it, and the equivalent cipher +specification string for dm-crypt: + + single-key Loop-AES v1.x cbc-plain + multi-key-v2 Loop-AES v2.x lmk2-plain64-multi:64 + multi-key-v3 Loop-AES v3.x lmk3-plain64-multi:64 + +This text describes the multi-key-v2 and multi-key-v3 modes and +their implementation in the Linux kernel.
pointer to alternative implementation with loop-AES?
Quoted 19 lines
Documentation/crypto/lmk.txt new file +19
-0+The multi-key modes describe a combination of CBC using a +specific IV derivation function with the use of multiple +independent encryption keys. + +The IV derivation and block chaining are implemented as +blkciphers named "lmk2" and "lmk3". The support for multiple +encryption keys is implemented in dm-crypt. + +Multiple keys: + + Each sector is encrypted/decrypted with one of 64 independent + keys selected by the following rule: + + key = keys[sectornum % 64] + +IV derivation: + + IVs are derived from an MD5 digest of the sector number, parts + of the plaintext data and a mode specific format constant. The
Documentation/crypto/lmk.txt line 43
Quoted 10 lines
Documentation/crypto/lmk.txt new file +10
-0+ multi-key-v3 mode additionally uses a 128-bit IV seed. + + v2IV = MD5(plaintext[16..511] || + le64(truncated-sector-number) || + le32(format-magic)) + + v3IV = MD5(ivseed || + plaintext[16..511] || + le64(truncated-sector-number) || + le32(format-magic))
ivseed = key_table[64] is nowhere declared. Also "||" should be explained, it is probably conatenation like in Jari's description? Hard to think of a really intuitive notation.."o" or "<<" might be intuitive for many but does not look too good in this case, especially in ASCII.
Documentation/crypto/lmk.txt line 50
Quoted 4 lines
Documentation/crypto/lmk.txt new file +4
-0+ The input IV supplied to lmk2 or lmk3 is expected to be the + sector number in 64-bit little endian as supplied by the + plain64 dm-crypt IV generator. It gets truncated to 56 bits + with the most significant byte set to 0x80:
I believe preceding paragraoh can be completely omitted, is not easier to understand than the pseudocode.
Documentation/crypto/lmk.txt line 53
Quoted 2 lines
Documentation/crypto/lmk.txt new file +2
-0+ truncated-sector-number = + (sectornum & 0x00ffffffffffffff) | 0x8000000000000000
would be better above the IV derivation descriptions.
Documentation/crypto/lmk.txt line 62
Quoted 8 lines
Documentation/crypto/lmk.txt new file +8
-0+Mode multi-key-v2 (lmk2-plain64-multi:64): + + key = keys[sectornum % 64] + + encrypt: + IV = MD5(plaintext[16..511] || + le64(truncated-sector-number) || + le32(format-magic))
no need to repeat the IV description here, could use the v2/v3IV in the pseudocode bellow. For the decryption IVs it would be then better to use some more distinct names because eg IV2 is fairly close to v2IV.
Btw did you send the other parts of the patch to the list? I did only ever receive the description part so feel free to email me the other parts.
Richard
Re: [PATCH 1/4] dm-crypt: clarify cipher vs. cipher mode
Hello Richard,
Quoted 13 lines · Richard Zidlicky
Quoted 13 lines
Documentation/crypto/lmk.txt new file +7
-0@@ -0,0 +1,102 @@ +Loop-AES compatible cipher block chaining modes +----------------------------------------------- + +The following table shows the Loop-AES name of the mode, the +Loop-AES version first supporting it, and the equivalent cipher +specification string for dm-crypt: +
Quoted 8 lines
Documentation/crypto/lmk.txt line 13
Quoted 6 lines
Documentation/crypto/lmk.txt new file +6
-0+ single-key Loop-AES v1.x cbc-plain + multi-key-v2 Loop-AES v2.x lmk2-plain64-multi:64 + multi-key-v3 Loop-AES v3.x lmk3-plain64-multi:64 + +This text describes the multi-key-v2 and multi-key-v3 modes and +their implementation in the Linux kernel.pointer to alternative implementation with loop-AES?
OK, I will point to Loop-AES itself.
Quoted 23 lines
Quoted 23 lines
Documentation/crypto/lmk.txt new file +23
-0+The multi-key modes describe a combination of CBC using a +specific IV derivation function with the use of multiple +independent encryption keys. + +The IV derivation and block chaining are implemented as +blkciphers named "lmk2" and "lmk3". The support for multiple +encryption keys is implemented in dm-crypt. + +Multiple keys: + + Each sector is encrypted/decrypted with one of 64 independent + keys selected by the following rule: + + key = keys[sectornum % 64] + +IV derivation: + + IVs are derived from an MD5 digest of the sector number, parts + of the plaintext data and a mode specific format constant. The + multi-key-v3 mode additionally uses a 128-bit IV seed. + + v2IV = MD5(plaintext[16..511] || + le64(truncated-sector-number) ||
Quoted 8 lines
Documentation/crypto/lmk.txt line 43
Quoted 6 lines
Documentation/crypto/lmk.txt new file +6
-0+ le32(format-magic)) + + v3IV = MD5(ivseed || + plaintext[16..511] || + le64(truncated-sector-number) || + le32(format-magic))ivseed = key_table[64] is nowhere declared.
This is an implementation detail of Loop-AES, so I don't consider it belonging to the description of the modes here. Loop-AES v3 keyfiles contain 65 keys of which the last key is used as IV seed.
Quoted 4 lines
Also "||" should be explained, it is probably conatenation like in Jari's description? Hard to think of a really intuitive notation.."o" or "<<" might be intuitive for many but does not look too good in this case, especially in ASCII.
OK, I agree this needs pointing out. The "||" for concatenation is what I'm familiar with, I don't think I would understand "o" or "<<" as well. I will explain what it does.
Quoted 7 lines
Documentation/crypto/lmk.txt line 50
Quoted 4 lines
Documentation/crypto/lmk.txt new file +4
-0+ The input IV supplied to lmk2 or lmk3 is expected to be the + sector number in 64-bit little endian as supplied by the + plain64 dm-crypt IV generator. It gets truncated to 56 bits + with the most significant byte set to 0x80:I believe preceding paragraoh can be completely omitted, is not easier to understand than the pseudocode.
OK. I'll drop the last sentence, the first one describing where the IV is expected to come from seems relevant.
Quoted 4 lines
Documentation/crypto/lmk.txt line 53
Quoted 2 lines
Documentation/crypto/lmk.txt new file +2
-0+ truncated-sector-number = + (sectornum & 0x00ffffffffffffff) | 0x8000000000000000would be better above the IV derivation descriptions.
Noted.
Quoted 11 lines
Documentation/crypto/lmk.txt line 62
Quoted 8 lines
Documentation/crypto/lmk.txt new file +8
-0+Mode multi-key-v2 (lmk2-plain64-multi:64): + + key = keys[sectornum % 64] + + encrypt: + IV = MD5(plaintext[16..511] || + le64(truncated-sector-number) || + le32(format-magic))no need to repeat the IV description here, could use the v2/v3IV in the pseudocode bellow.
I think repeating it makes it clearer which parts happen at which time, so I'd leave this as is.
Quoted 2 lines
For the decryption IVs it would be then better to use some more distinct names because eg IV2 is fairly close to v2IV.
Good point, thanks. Will change.
Quoted 3 lines
Btw did you send the other parts of the patch to the list? I did only ever receive the description part so feel free to email me the other parts.
I did send them all to linux-crypto@vger. I'm not sure why you didn't receive them. I'll send you the missing parts and CC you on the next submission.
Thanks again for your comments,
Max
Re: [PATCH 1/4] dm-crypt: clarify cipher vs. cipher mode
Hi,
Quoted 4 lines
Quoted 1 line
ivseed = key_table[64] is nowhere declared.
This is an implementation detail of Loop-AES, so I don't consider it belonging to the description of the modes here.
difficult to draw the line, but as it is something supplied as "external parameter" to the dm-crypt layer I think it is certainly worth mentioning where it comes from.
Quoted 10 lines
Quoted 7 lines
Documentation/crypto/lmk.txt line 50
Quoted 4 lines
Documentation/crypto/lmk.txt new file +4
-0+ The input IV supplied to lmk2 or lmk3 is expected to be the + sector number in 64-bit little endian as supplied by the + plain64 dm-crypt IV generator. It gets truncated to 56 bits + with the most significant byte set to 0x80:I believe preceding paragraoh can be completely omitted, is not easier to understand than the pseudocode.
OK. I'll drop the last sentence, the first one describing where the IV is expected to come from seems relevant.
actually the first sentence does not make any sense to me as it is now.
Quoted 12 lines
Quoted 11 lines
Documentation/crypto/lmk.txt line 62
Quoted 8 lines
Documentation/crypto/lmk.txt new file +8
-0+Mode multi-key-v2 (lmk2-plain64-multi:64): + + key = keys[sectornum % 64] + + encrypt: + IV = MD5(plaintext[16..511] || + le64(truncated-sector-number) || + le32(format-magic))no need to repeat the IV description here, could use the v2/v3IV in the pseudocode bellow.
Quoted 2 lines
I think repeating it makes it clearer which parts happen at which time, so I'd leave this as is.
at the very least I would use v2IV etc like in the earlier description. But I think the duplication can be avoided.
Richard
Re: [PATCH 1/4] dm-crypt: clarify cipher vs. cipher mode
In reply to Milan BrozOn Mon, Dec 28, 2009 at 08:37:43PM +0100, Milan Broz wrote:
Hi,
Quoted 5 lines
But please can you add more explanation into documentation about this mode? Is there any paper which analyses that mode - if so can you add link to description?
(and yes, I know loop-AES documentation:-)
I have some archived mail messages from Jari explaining the details of the encryption pretty exhaustively if that helps.
While we are at it - are you aware of any documentation of the "mainline" dm-crypt implementation? I have not seen anything, much less any explanation if it has improved any since the ancient watermarking attack.
http://luks.endorphin.org/ is down, http://www.saout.de/misc/dm-crypt/ has plenty of information but I am not sure if it is up to date.. well if it is than it seems default dm-crypt still has more or less snake oil quality encryption.
Richard
Re: [PATCH 1/4] dm-crypt: clarify cipher vs. cipher mode
Quoted 9 lines · Richard Zidlicky
On Mon, Dec 28, 2009 at 08:37:43PM +0100, Milan Broz wrote:
While we are at it - are you aware of any documentation of the "mainline" dm-crypt implementation? I have not seen anything, much less any explanation if it has improved any since the ancient watermarking attack.
http://luks.endorphin.org/ is down, http://www.saout.de/misc/dm-crypt/ has plenty of information but I am not sure if it is up to date.. well if it is than it seems default dm-crypt still has more or less snake oil quality encryption.
ok, I should probably add some info, probably to new cryptsetup pages
http://code.google.com/p/cryptsetup/ and kernel to documentation, if needed.
- the watermarking attack is not possible with introducing ESSIV long time ago (essiv default for LUKS formatted devices by cryptsetup - for several years)
- I prefer using XTS mode, but user can use whatever is supported in kernel
- AFAIK there is no known problem with dm-crypt (stability or security) when properly configured (you can of course use old vulnerable IV mode if you want). (And many distributions and uses dm-crypt/LUKS based full disk encryption currently, also Truecrypt uses dm-crypt as backend on Linux for new containers.)
(If you think about coldboot or something similar - dm-crypt provides functions to temporarily freeze device and empty keys and I also added support for this to cryptsetup. So the controlled suspend/resume to RAM can ask for LUKS passphrase and unlock master key, preventing active encryption keys in RAM.
Of course this do not apply to if the shutdown is not controlled, but that's common problem of all these implementations.)
If you know about some problem in dm-crypt, just let me know (or write to dm-crypt mailing list).
Milan
--
[email protected]
Re: [PATCH 1/4] dm-crypt: clarify cipher vs. cipher mode
Hi,
many thanks for the clarifications. Fedora has a very nice and unobstrusive crypto setup but finding out the technical details involves looking into quite a few places. The http://code.google.com/p/cryptsetup/ pages seems to have plenty of information for a start.
Quoted 4 lines
(If you think about coldboot or something similar - dm-crypt provides functions to temporarily freeze device and empty keys and I also added support for this to cryptsetup. So the controlled suspend/resume to RAM can ask for LUKS passphrase and unlock master key, preventing active encryption keys in RAM.
that is a really godd idea - is there a howto somewhere? Coldboot is not my main worry but it is certainly good to take reasonable precautions.
Quoted 1 line
If you know about some problem in dm-crypt, just let me know (or write to dm-crypt mailing list).
I have some problems with hibernation which look like it might be related to the dm layer but am not totally sure. Unfortunately it is rare enough that I could not catch it with any of the remote debugging methods. I could only email a picture of a stack trace.
Richard
PATCH 2/4 dm-crypt: multi tfm mode
In reply to Max VozelerIntroduces a mode for dm-crypt which uses multiple encryption keys (and thus tfms) alternating based on the sector number and the number of keys.
This change is needed to support loop-AES compatible block chaining modes, which use "multi:64".
--- Documentation/device-mapper/dm-crypt.txt | 3 +- drivers/md/dm-crypt.c | 138 +++++++++++++++++++++++++---- 2 files changed, 121 insertions(+), 20 deletions(-)
Documentation/device-mapper/dm-crypt.txt +2 -1
@@ -8,11 +8,12 @@ Parameters: <cipher> <key> <iv_offset> <device path> <offset> <cipher> Encryption cipher and an optional IV generation mode. - (In format cipher-chainmode-ivopts:ivmode). + (In format cipher-chainmode-ivopts:ivmode-multi:nkeys). Examples: des aes-cbc-essiv:sha256 twofish-ecb + aes-lmk3-plain64-multi:64 /proc/crypto contains supported crypto modes
drivers/md/dm-crypt.c +119 -19
257 lines not on this page · raw message
Signature · 1 line
1.6.5.4
PATCH 3/4 crypto: md5 - Add export support
In reply to Max VozelerThis patch adds export support to md5. The exported type is defined by struct md5_state.
This is modeled after the equivalent change to sha1_generic, except only export is added for now.
--- crypto/md5.c | 31 +++++++++++++++---------------- include/crypto/md5.h | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 include/crypto/md5.h
crypto/md5.c +15 -16
@@ -16,17 +16,13 @@* */ #include <crypto/internal/hash.h> +#include <crypto/md5.h> #include <linux/init.h> #include <linux/module.h> #include <linux/string.h> #include <linux/types.h> #include <asm/byteorder.h> -#define MD5_DIGEST_SIZE 16 -#define MD5_HMAC_BLOCK_SIZE 64 -#define MD5_BLOCK_WORDS 16 -#define MD5_HASH_WORDS 4 -#define F1 (x, y, z) (z ^ (x & (y ^ z)))#define F2 (x, y, z) F1(z, x, y)#define F3 (x, y, z) (x ^ y ^ z)
@@ -35,12 +31,6 @@#define MD5STEP (f, w, x, y, z, in, s) \ (w += f(x, y, z) + in, w = (w<<s | w>>(32-s)) + x) -struct md5_ctx { -u32 hash[MD5_HASH_WORDS ]; -u32 block[MD5_BLOCK_WORDS ]; -u64 byte_count; -}; -static void md5_transform (u32 *hash,u32 const *in) {u32 a, b, c, d;
@@ -141,7 +131,7 @@ static inline void cpu_to_le32_array(u32 *buf, unsigned int words) } } -static inline void md5_transform_helper (struct md5_ctx *ctx) +static inline void md5_transform_helper (struct md5_state *ctx) {le32_to_cpu_array (ctx->block,sizeof (ctx->block) /sizeof (u32));md5_transform (ctx->hash, ctx->block);
@@ -149,7 +139,7 @@ static inline void md5_transform_helper(struct md5_ctx *ctx)static int md5_init (struct shash_desc *desc) { -struct md5_ctx *mctx =shash_desc_ctx (desc); +struct md5_state *mctx =shash_desc_ctx (desc); mctx->hash[0 ] =0x67452301 ; mctx->hash[1 ] =0xefcdab89 ;
@@ -162,7 +152,7 @@ static int md5_init(struct shash_desc *desc)static int md5_update (struct shash_desc *desc,const u8 *data,unsigned int len) { -struct md5_ctx *mctx =shash_desc_ctx (desc); +struct md5_state *mctx =shash_desc_ctx (desc);const u32 avail =sizeof (mctx->block) - (mctx->byte_count &0x3f ); mctx->byte_count += len;
@@ -194,7 +184,7 @@ static int md5_update(struct shash_desc *desc, const u8 *data, unsigned int len)static int md5_final (struct shash_desc *desc,u8 *out) { -struct md5_ctx *mctx =shash_desc_ctx (desc); +struct md5_state *mctx =shash_desc_ctx (desc);const unsigned int offset = mctx->byte_count &0x3f ;char *p = (char *)mctx->block + offset;int padding =56 - (offset +1 );
@@ -220,12 +210,21 @@ static int md5_final(struct shash_desc *desc, u8 *out)return 0 ; } +static int md5_export (struct shash_desc *desc,void *out) +{ +struct md5_state *ctx =shash_desc_ctx (desc); + +memcpy (out, ctx,sizeof (*ctx)); +return 0 ; +} +static struct shash_alg alg = { .digestsize =MD5_DIGEST_SIZE , .init = md5_init, .update = md5_update, .final = md5_final, - .descsize =sizeof (struct md5_ctx ), + .export = md5_export, + .descsize =sizeof (struct md5_state ), .base = { .cra_name ="md5" , .cra_flags =CRYPTO_ALG_TYPE_SHASH ,
include/crypto/md5.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef _CRYPTO_MD5_H +#define _CRYPTO_MD5_H + +#include <linux/types.h> + +#define MD5_DIGEST_SIZE 16 +#define MD5_HMAC_BLOCK_SIZE 64 +#define MD5_BLOCK_WORDS 16 +#define MD5_HASH_WORDS 4 + +struct md5_state { +u32 hash[MD5_HASH_WORDS ]; +u32 block[MD5_BLOCK_WORDS ]; +u64 byte_count; +}; + +#endif
Signature · 1 line
1.6.5.4
Herbert Xu
maintainerRe: [PATCH 3/4] crypto: md5 - Add export support
Quoted 8 lines · Max Vozeler
This patch adds export support to md5. The exported type is defined by struct
md5_state.This is modeled after the equivalent change to
sha1_generic, except only export is added for now.Signed-off-by Max Vozeler <[email protected]>Cc Jari Ruusu <[email protected]>
Please add an import function as the shash API requires import to be present if export is present.
Thanks,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtRe: [PATCH 3/4] crypto: md5 - Add export support
Quoted 4 lines · Herbert Xu
Quoted 3 lines · Max Vozeler
This patch adds export support to md5. The exported type is defined by struct
md5_state.
Quoted 8 lines
Quoted 5 lines
This is modeled after the equivalent change to
sha1_generic, except only export is added for now.Signed-off-by Max Vozeler <[email protected]>Cc Jari Ruusu <[email protected]>Please add an import function as the shash API requires import to be present if export is present.
Thanks for pointing this out, I was not aware of the requirement. Changed to add import as well as export.
Max
This patch adds export/import support to md5. The exported type is defined by struct md5_state.
This is modeled after the equivalent change to sha1_generic.
--- crypto/md5.c | 40 ++++++++++++++++++++++++---------------- include/crypto/md5.h | 17 +++++++++++++++++ 2 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 include/crypto/md5.h
v2: Also add import as required by shash API.
crypto/md5.c +24 -16
@@ -16,17 +16,13 @@* */ #include <crypto/internal/hash.h> +#include <crypto/md5.h> #include <linux/init.h> #include <linux/module.h> #include <linux/string.h> #include <linux/types.h> #include <asm/byteorder.h> -#define MD5_DIGEST_SIZE 16 -#define MD5_HMAC_BLOCK_SIZE 64 -#define MD5_BLOCK_WORDS 16 -#define MD5_HASH_WORDS 4 -#define F1 (x, y, z) (z ^ (x & (y ^ z)))#define F2 (x, y, z) F1(z, x, y)#define F3 (x, y, z) (x ^ y ^ z)
@@ -35,12 +31,6 @@#define MD5STEP (f, w, x, y, z, in, s) \ (w += f(x, y, z) + in, w = (w<<s | w>>(32-s)) + x) -struct md5_ctx { -u32 hash[MD5_HASH_WORDS ]; -u32 block[MD5_BLOCK_WORDS ]; -u64 byte_count; -}; -static void md5_transform (u32 *hash,u32 const *in) {u32 a, b, c, d;
@@ -141,7 +131,7 @@ static inline void cpu_to_le32_array(u32 *buf, unsigned int words) } } -static inline void md5_transform_helper (struct md5_ctx *ctx) +static inline void md5_transform_helper (struct md5_state *ctx) {le32_to_cpu_array (ctx->block,sizeof (ctx->block) /sizeof (u32));md5_transform (ctx->hash, ctx->block);
@@ -149,7 +139,7 @@ static inline void md5_transform_helper(struct md5_ctx *ctx)static int md5_init (struct shash_desc *desc) { -struct md5_ctx *mctx =shash_desc_ctx (desc); +struct md5_state *mctx =shash_desc_ctx (desc); mctx->hash[0 ] =0x67452301 ; mctx->hash[1 ] =0xefcdab89 ;
@@ -162,7 +152,7 @@ static int md5_init(struct shash_desc *desc)static int md5_update (struct shash_desc *desc,const u8 *data,unsigned int len) { -struct md5_ctx *mctx =shash_desc_ctx (desc); +struct md5_state *mctx =shash_desc_ctx (desc);const u32 avail =sizeof (mctx->block) - (mctx->byte_count &0x3f ); mctx->byte_count += len;
@@ -194,7 +184,7 @@ static int md5_update(struct shash_desc *desc, const u8 *data, unsigned int len)static int md5_final (struct shash_desc *desc,u8 *out) { -struct md5_ctx *mctx =shash_desc_ctx (desc); +struct md5_state *mctx =shash_desc_ctx (desc);const unsigned int offset = mctx->byte_count &0x3f ;char *p = (char *)mctx->block + offset;int padding =56 - (offset +1 );
@@ -220,12 +210,30 @@ static int md5_final(struct shash_desc *desc, u8 *out)return 0 ; } +static int md5_export (struct shash_desc *desc,void *out) +{ +struct md5_state *ctx =shash_desc_ctx (desc); + +memcpy (out, ctx,sizeof (*ctx)); +return 0 ; +} + +static int md5_import (struct shash_desc *desc,const void *in) +{ +struct md5_state *ctx =shash_desc_ctx (desc); + +memcpy (ctx, in,sizeof (*ctx)); +return 0 ; +} +static struct shash_alg alg = { .digestsize =MD5_DIGEST_SIZE , .init = md5_init, .update = md5_update, .final = md5_final, - .descsize =sizeof (struct md5_ctx ), + .export = md5_export, + .import = md5_import, + .descsize =sizeof (struct md5_state ), .base = { .cra_name ="md5" , .cra_flags =CRYPTO_ALG_TYPE_SHASH ,
include/crypto/md5.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef _CRYPTO_MD5_H +#define _CRYPTO_MD5_H + +#include <linux/types.h> + +#define MD5_DIGEST_SIZE 16 +#define MD5_HMAC_BLOCK_SIZE 64 +#define MD5_BLOCK_WORDS 16 +#define MD5_HASH_WORDS 4 + +struct md5_state { +u32 hash[MD5_HASH_WORDS ]; +u32 block[MD5_BLOCK_WORDS ]; +u64 byte_count; +}; + +#endif
Signature · 1 line
1.6.5.4
Re: [PATCH 3/4] crypto: md5 - Add export support
Quoted 5 lines · Max Vozeler
This patch adds export/import support to md5. The exported type is defined by struct
md5_state.This is modeled after the equivalent change to
sha1_generic.
Applied to cryptodev.
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtPATCH 4/4 crypto: lmk2/lmk3 cipher block modes
In reply to Max VozelerThis is a compatible implementation of the block chaining modes used by the Loop-AES block device encryption system
(http://loop-aes.sf.net/).
It implements two modes: lmk2 and lmk3. They correspond to the modes used in Loop-AES v2.x and Loop-AES v3.x and are intended to be full compatible.
Both modes operate on full 512 byte sectors. They use CBC with an IV derived from the sector number, the data and (for lmk3 only) an extra 128-bit IV seed.
--- MAINTAINERS | 6 + crypto/Kconfig | 17 ++ crypto/Makefile | 1 + crypto/lmk.c | 434 +++++++++++++++++++++++++++++++++++++++++ crypto/testmgr.c | 30 +++ crypto/testmgr.h | 564 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1052 insertions(+), 0 deletions(-) create mode 100644 crypto/lmk.c
MAINTAINERS +6 -0
@@ -4611,6 +4611,12 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.g S: Maintained F: drivers/net/wireless/rtl818x/rtl8187* +LMK BLOCK CHAINING MODE +P: Max Vozeler +M: [email protected] +S: Maintained +F: crypto/lmk.c + S3 SAVAGE FRAMEBUFFER DRIVER M: Antonino Daplas <[email protected]> L: [email protected]
crypto/Kconfig +17 -0
@@ -243,6 +243,23 @@ config CRYPTO_XTS key size 256, 384 or 512 bits. This implementation currently can't handle a sectorsize which is not a multiple of 16 bytes. +config CRYPTO_LMK + tristate "LMK support (EXPERIMENTAL)" + depends on EXPERIMENTAL + select CRYPTO_BLKCIPHER + select CRYPTO_MANAGER + select CRYPTO_MD5 + help + LMK block cipher modes (lmk2/lmk3). + + These modes are compatible with Loop-AES. Use them with a + dm-crypt cipher string aes-lmk2-plain64-multi:64 (for Loop-AES + v2.x) or aes-lmk2-plain64-multi:64 (for Loop-AES v3.x). + + The key for lmk3 must be 256, 320 or 384 bits. The first 128, + 192 or 256 bits in the key are used for the cipher, the rest + is used as an extra input to the IV calculation. + config CRYPTO_FPU tristate select CRYPTO_BLKCIPHER
crypto/Makefile +1 -0
@@ -53,6 +53,7 @@ obj-$(CONFIG_CRYPTO_PCBC) += pcbc.o obj-$(CONFIG_CRYPTO_CTS) += cts.o obj-$(CONFIG_CRYPTO_LRW) += lrw.o obj-$(CONFIG_CRYPTO_XTS) += xts.o +obj-$(CONFIG_CRYPTO_LMK) += lmk.o obj-$(CONFIG_CRYPTO_CTR) += ctr.o obj-$(CONFIG_CRYPTO_GCM) += gcm.o obj-$(CONFIG_CRYPTO_CCM) += ccm.o
crypto/lmk.c new file +434 -0
434 lines not on this page · raw message
crypto/testmgr.c +30 -0
@@ -2113,6 +2113,36 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { + .alg = "lmk2(aes)", + .test = alg_test_skcipher, + .suite = { + .cipher = { + .enc = { + .vecs = aes_lmk2_enc_tv_template, + .count = AES_LMK2_ENC_TEST_VECTORS + }, + .dec = { + .vecs = aes_lmk2_dec_tv_template, + .count = AES_LMK2_DEC_TEST_VECTORS + } + } + } + }, { + .alg = "lmk3(aes)", + .test = alg_test_skcipher, + .suite = { + .cipher = { + .enc = { + .vecs = aes_lmk3_enc_tv_template, + .count =AES_LMK3_ENC_TEST_VECTORS + }, + .dec = { + .vecs = aes_lmk3_dec_tv_template, + .count =AES_LMK3_DEC_TEST_VECTORS + } + } + } + }, { .alg = "lrw(aes)", .test = alg_test_skcipher, .suite = {
crypto/testmgr.h +564 -0
570 lines not on this page · raw message
Signature · 1 line
1.6.5.4
Re: [PATCH 4/4] crypto: lmk2/lmk3 cipher block modes
crypto/Kconfig config CRYPTO_XTS · line 257
Quoted 6 lines · Max Vozeler
crypto/Kconfig +6
-0+ help + LMK block cipher modes (lmk2/lmk3). + + These modes are compatible with Loop-AES. Use them with a + dm-crypt cipher string aes-lmk2-plain64-multi:64 (for Loop-AES + v2.x) or aes-lmk2-plain64-multi:64 (for Loop-AES v3.x).
^^^^
should that be lmk3 ?
Too tired to look further..
Richard
Re: [PATCH 4/4] crypto: lmk2/lmk3 cipher block modes
Quoted 10 lines · Richard Zidlicky
crypto/Kconfig config CRYPTO_XTS · line 257
Quoted 6 lines · Max Vozeler
crypto/Kconfig +6
-0+ help + LMK block cipher modes (lmk2/lmk3). + + These modes are compatible with Loop-AES. Use them with a + dm-crypt cipher string aes-lmk2-plain64-multi:64 (for Loop-AES + v2.x) or aes-lmk2-plain64-multi:64 (for Loop-AES v3.x).^^^^should that be lmk3 ?
Yes, you are right. Thanks for catching it,
Max
Herbert Xu
maintainerRe: [PATCH 4/4] crypto: lmk2/lmk3 cipher block modes
In reply to Max VozelerQuoted 8 lines · Max Vozeler
This is a compatible implementation of the block chaining modes used by the Loop-AES block device encryption system
(http://loop-aes.sf.net/).It implements two modes: lmk2 and lmk3. They correspond to the modes used in Loop-AES v2.x and Loop-AES v3.x and are intended to be full compatible.
Quoted 6 lines
Both modes operate on full 512 byte sectors. They use CBC with an IV derived from the sector number, the data and (for lmk3 only) an extra 128-bit IV seed.
Signed-off-by Max Vozeler <[email protected]>Cc Jari Ruusu <[email protected]>
So this is just CBC with a modified IV? If so it should not be implemented as another mode. Doing it as a mode means that you will not benefit from any hardware implementations of CBC.
You should instead implement it as an IV generator. Currently they're done in dm-crypt. But we could move them into crypto at some point if there are multiple users in the kernel.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtRe: [PATCH 4/4] crypto: lmk2/lmk3 cipher block modes
Hello Herbert,
Quoted 6 lines · Herbert Xu
Quoted 3 lines · Max Vozeler
Both modes operate on full 512 byte sectors. They use CBC with an IV derived from the sector number, the data and (for lmk3 only) an extra 128-bit IV seed.
So this is just CBC with a modified IV?
Is is almost CBC, but not exactly.
The difference is that the IV is derived from the cleartext and so is not known before decrypt.
So decrypt could be described using CBC as, I think:
1) CBC decrypt with null IV
2) Derive IV based on cleartext of blocks 1..31
3) XOR block 0 with IV
Quoted 3 lines
If so it should not be implemented as another mode. Doing it as a mode means that you will not benefit from any hardware implementations of CBC.
If there is some way to implement it cleanly without making it another mode I would prefer doing that.
Quoted 2 lines
You should instead implement it as an IV generator. Currently they're done in dm-crypt.
I'd agree that dm-crypt would be the more suitable place.
But I'm not sure how to implement it given the difference described above. It might look something like this:
- Add IV generators "lmk2", "lmk3"
- Treat them as "cbc" with null IV internally, then after decrypt derive IV and xor block 0 with it.
The second part is why I built this as a mode originally. It seemed like it was not belonging in dm-crypt.
Max
Herbert Xu
maintainerRe: [PATCH 4/4] crypto: lmk2/lmk3 cipher block modes
Quoted 9 lines · Max Vozeler
The difference is that the IV is derived from the cleartext and so is not known before decrypt.
So decrypt could be described using CBC as, I think:
1) CBC decrypt with null IV
2) Derive IV based on cleartext of blocks 1..31
3) XOR block 0 with IV
Yep, this sounds like the way it should be implemented.
Quoted 10 lines
But I'm not sure how to implement it given the difference described above. It might look something like this:
- Add IV generators "lmk2", "lmk3"
- Treat them as "cbc" with null IV internally, then after decrypt derive IV and xor block 0 with it.
The second part is why I built this as a mode originally. It seemed like it was not belonging in dm-crypt.
OK, I see what you mean.
Let's keep lmk2/lmk3 as separate modes, but implement it as a wrapper around cbc. That is, instead of allocating the cipher, you'd allocate "cbc(cipher)" (as an ablkcipher) and use it to perform the actual encryption/decryption.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtRe: [PATCH 4/4] crypto: lmk2/lmk3 cipher block modes
Hi Herbert,
Quoted 4 lines · Herbert Xu
Let's keep lmk2/lmk3 as separate modes, but implement it as a wrapper around cbc. That is, instead of allocating the cipher, you'd allocate "cbc(cipher)" (as an ablkcipher) and use it to perform the actual encryption/decryption.
I started looking at this today.
I'm wondering if I'm heading in the right direction since this is stretching my understanding of the API:
Would it look something like ccm, in that
alloc does
- crypto_grab_skcipher(spawn, "cbc(aes)"
- crypto_skcipher_spawn_alg()
then my alg.cra_init does
- crypto_spawn_skcipher ?
Any advice appreciated. In the meantime I'll read the code to get a better understanding of how this fits together.
Max
Herbert Xu
maintainerRe: [PATCH 4/4] crypto: lmk2/lmk3 cipher block modes
Quoted 5 lines · Max Vozeler
I'm wondering if I'm heading in the right direction since this is stretching my understanding of the API:
Would it look something like ccm, in that
Not quite.
Quoted 6 lines
alloc does
- crypto_grab_skcipher(spawn, "cbc(aes)"
-crypto_skcipher_spawn_alg()then my alg.cra_init does
-crypto_spawn_skcipher?
The skcipher interface is synchronous only. It's OK for CCM and GCM as we don't currently have an async CTR implementation.
For CBC however you really need the ablkcipher interface so that all hardware implementations are available, notably the Intel AES implementation is only available through the async interface.
The authenc/chainiv/seqiv drivers should serve as an example as to how the ablkcipher interface can be used.
The other place where it differs from ccm is that ccm is an AEAD algorithm, thus presenting itself through the crypto_aead interface. You will on the other hand present an ablkcipher interface.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt