ABL-{32,*}-AES
Subsystems (2)
Hello list,
I'm working on an ABL-32-AES (and a more general ABL-*-AES) implementation for the Linux kernel as proposed by John Viega and David McGrew in
http://grouper.ieee.org/groups/1619/email/rtf00000.rtf (October 28, 2004) and
http://grouper.ieee.org/groups/1619/email/pdf00005.pdf (April 15, 2004). The spec is not sufficiently reviewed and the two documents seem to contradict eachother in a few places. Therefore the implementation of the ABL blockcipher mode itself is preliminary.
ABL allows to turn a blockcipher with a blocksize of 16 bytes into a blockcipher of arbitrary block size (for example 512 (dm sector size) and 4k (x86 page size)). The mode is (according to it's creators) unencumbered by patents (other well known modes, CMC, EME, EME* and XCB, are).
To get ABL-32-AES to work, a new IV is needed: 'bewbi' ('big-endian' wide block count'). It counts the number of wide blocks in bigendian format starting at 1. The first patch adds this IV mode.
For 4k blocks (cipherblocksize equal to PAGE_SIZE and ext3fs max blocksize on x86) another change is needed to dm-crypt, it adds an optional argument to dm-crypt (the extra shift, eg extra_shift=1 gives cipherblocks of 1k). It works for me, but I don't know if my implementation is correct.
For completeness I include the patch that introduces the ABL blockcipher mode itself.
The patches are against the current cryptodev-2.6 tree, and if no-one objects the dm-crypt patches will probably go there.
Greetings,
Rik.
PATCH 1/1 crypto: bewbi IV, big endian wide block count for ABL-32-AES
From: Rik Snel <[email protected]>
ABL-32-AES needs a certain IV. This IV should be provided dm-crypt. The block cipher mode could, in principle, generate the correct IV from the plain IV, but I think that it is cleaner to supply the right IV directly.
The sector -> wide block calculation is currently just a conversion to bigendian and an increment, but if dm-crypt will support cypher blocksizes larger than 512 bytes (which would be interesting for wide blocks) the conversion will include a shift also.
--- drivers/md/dm-crypt.c | 20 +++++++++++++++++++- 1 files changed, 19 insertions(+), 1 deletions(-)
drivers/md/dm-crypt.c +19 -1
@@ -117,6 +117,9 @@ static kmem_cache_t *_crypt_io_pool;* benbi: the 64-bit "big-endian 'narrow block'-count", starting at 1 * (needed for LRW-32-AES and possible other narrow block modes) * +* bewbi: the 64-bit "big-endian 'wide block'-count", starting at 1 +* (needed for ABL-32-AES and possible other wide block modes) +* * plumb: unimplemented, see: * http://article.gmane.org/gmane.linux.kernel.device-mapper.dm-crypt/454 */
@@ -251,6 +254,14 @@ static int crypt_iv_benbi_gen(struct crypt_config *cc, u8 *iv, sector_t sector)return 0 ; } +static int crypt_iv_bewbi_gen (struct crypt_config *cc,u8 *iv,sector_t sector) +{ +memset (iv,0 , cc->iv_size -sizeof (u32)); + *((u32 *)iv +3 ) =cpu_to_be32 ((sector &0xffffffff ) +1 ); + +return 0 ; +} +static struct crypt_iv_operations crypt_iv_plain_ops = { .generator = crypt_iv_plain_gen };
@@ -267,6 +278,10 @@ static struct crypt_iv_operations crypt_iv_benbi_ops = { .generator = crypt_iv_benbi_gen }; +static struct crypt_iv_operations crypt_iv_bewbi_ops = { + .generator = crypt_iv_bewbi_gen +}; + static int crypt_convert_scatterlist(struct crypt_config *cc, struct scatterlist *out, struct scatterlist *in, unsigned int length,
@@ -815,7 +830,8 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) cc->tfm = tfm;/* -* Choose ivmode. Valid modes: "plain", "essiv:<esshash>", "benbi". +* Choose ivmode. Valid modes: "plain", "essiv:<esshash>", "benbi", +* "bewbi". * See comments at iv code */
@@ -827,6 +843,8 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) cc->iv_gen_ops = &crypt_iv_essiv_ops; else if (strcmp(ivmode, "benbi") == 0) cc->iv_gen_ops = &crypt_iv_benbi_ops; + else if (strcmp(ivmode, "bewbi") == 0) + cc->iv_gen_ops = &crypt_iv_bewbi_ops; else { ti->error ="Invalid IV mode" ; goto bad2;
Signature · 1 line
1.4.4.1
PATCH 1/1 dm-crypt: add support for very wide (>512 bytes) block modes
From: Rik Snel <[email protected]>
By default dm-crypt sends and receives chunks of 512 bytes to and from the crypto layer. For implementing deniable harddisk encryption it is useful to make these chunks larger; i.e. equal to the filesystem block size. If a wide block cipher mode (like ABL) is used, then a single bit modification of the filesystem block will result in a total change of the corresponding cipher block.
This patch adds an optional argument to dm-crypt, the 'extra sector size shift'. The blocksize for communicating with the crypto layer will be 512<<'extra sector size shift'. The resulting size may not be larger than PAGE_SIZE. Care is taken to also enlarge the hardsector_size as needed.
--- drivers/md/dm-crypt.c | 50 ++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 45 insertions(+), 5 deletions(-)
drivers/md/dm-crypt.c +45 -5
@@ -95,6 +95,7 @@ struct crypt_config {struct crypto_blkcipher *tfm;unsigned long flags;unsigned int key_size; +int extra_shift;u8 key[0 ]; };
@@ -257,7 +258,8 @@ static int crypt_iv_benbi_gen(struct crypt_config *cc, u8 *iv, sector_t sector)static int crypt_iv_bewbi_gen (struct crypt_config *cc,u8 *iv,sector_t sector) {memset (iv,0 , cc->iv_size -sizeof (u32)); - *((u32 *)iv +3 ) =cpu_to_be32 ((sector &0xffffffff ) +1 ); + *((u32 *)iv +3 ) = +cpu_to_be32 ((sector >> cc->extra_shift &0xffffffff ) +1 );return 0 ; }
@@ -344,12 +346,12 @@ static int crypt_convert(struct crypt_config *cc,struct scatterlist sg_in = { .page = bv_in->bv_page, .offset = bv_in->bv_offset + ctx->offset_in, - .length =1 <<SECTOR_SHIFT + .length = (1 <<SECTOR_SHIFT ) << cc->extra_shift };struct scatterlist sg_out = { .page = bv_out->bv_page, .offset = bv_out->bv_offset + ctx->offset_out, - .length =1 <<SECTOR_SHIFT + .length = (1 <<SECTOR_SHIFT ) << cc->extra_shift }; ctx->offset_in += sg_in.length;
@@ -760,7 +762,7 @@ static int crypt_wipe_key(struct crypt_config *cc)/* * Construct an encryption mapping: -* <cipher> <key> <iv_offset> <dev_path> <start> +* <cipher> <key> <iv_offset> <dev_path> <start> [<extra_shift>] */ static int crypt_ctr (struct dm_target *ti,unsigned int argc,char **argv) {
@@ -774,11 +776,16 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)unsigned int key_size;unsigned long long tmpll; -if (argc !=5 ) { +if (argc <5 ) { ti->error ="Not enough arguments" ;return -EINVAL ; } +if (argc >6 ) { + ti->error ="Too many arguments" ; +return -EINVAL ; + } + tmp = argv[0 ]; cipher =strsep (&tmp,"-" ); chainmode =strsep (&tmp,"-" );
@@ -903,12 +910,42 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) } cc->start = tmpll; +if (argc >5 ) { +if (sscanf (argv[5 ],"%llu" , &tmpll) !=1 ) { + ti->error ="Invalid extra sector size shift" ; + goto bad5; + } +if (tmpll <1 ) { + ti->error ="Invalid extra sector size shift, " +"must be positive" ; + goto bad5; + } +if (tmpll >PAGE_SHIFT -SECTOR_SHIFT ) { + ti->error ="Invalid extra sector size shift, " +"must be <= PAGE_SHIFT - SECTOR_SHIFT" ; + goto bad5; + } + cc->extra_shift = tmpll; + }else cc->extra_shift =0 ; +if (dm_get_device (ti, argv[3 ], cc->start, ti->len,dm_table_get_mode (ti->table), &cc->dev)) { ti->error ="Device lookup failed" ; goto bad5; } +if (cc->extra_shift) { +/* update hardsector_size */ +if (ti->limits.hardsect_size%(1 <<SECTOR_SHIFT )) { + ti->error ="Weird sector size, too small or " +"not a power of 2" ; + goto bad5; + } +while (ti->limits.hardsect_size < + (1 <<SECTOR_SHIFT ) << cc->extra_shift) + ti->limits.hardsect_size <<=1 ; + } +if (ivmode && cc->iv_gen_ops) {if (ivopts) *(ivopts -1 ) =':' ;
@@ -1010,6 +1047,9 @@ static int crypt_status(struct dm_target *ti, status_type_t type,DMEMIT (" %llu %s %llu" , (unsigned long long )cc->iv_offset, cc->dev->name, (unsigned long long )cc->start); +if (cc->extra_shift) +DMEMIT (" %llu" , (unsigned long long )cc->extra_shift); +break ; }return 0 ;
Signature · 1 line
1.4.4.1
PATCH 1/1 ABL, Arbitrary Block Length, a tweakable wide block cipher mode
From: Rik Snel <[email protected]>
This is a preliminary implementation of ABL as specified by David McGrew and John Viega in:
- http://grouper.ieee.org/groups/1619/email/rtf00000.rtf (October 28, 2004)
- http://grouper.ieee.org/groups/1619/email/pdf00005.pdf (April 15, 2004)
Preliminary, because the specification has not been sufficiently reviewed and is subject to change because the two contradict eachother in a few places (see the comments at the top of abl.c).
Currently I have no official test vectors. This implementation is only checked against an "independent" and minimal userspace implementation I wrote, which is available at: http://cube.dyndns.org/~rsnel/abl/
I added a self-generated test vector to tcrypt.h and also an ABL specific speed_test_template because this implementation cannot handle input shorter than two blocks. The spec allows it, but I chose not to implement it because it is not needed for harddisk encryption. This implementation also does not handle partial blocks, while the spec allows it.
Please do not use this mode for anything serious yet.
--- crypto/Kconfig | 14 ++ crypto/Makefile | 1 + crypto/abl.c | 406 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ crypto/tcrypt.c | 12 ++ crypto/tcrypt.h | 300 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 733 insertions(+), 0 deletions(-)
crypto/Kconfig +14 -0
@@ -181,6 +181,20 @@ config CRYPTO_LRW The first 128, 192 or 256 bits in the key are used for AES and the rest is used to tie each cipher block to its logical position. +config CRYPTO_ABL + tristate "ABL support (EXPERIMENTAL)" + depends on EXPERIMENTAL + select CRYPTO_BLKCIPHER + select CRYPTO_GF128MUL + default n + help + ABL: Arbitrary Block Length, a tweakable, non malleable, non movable + wide block cipher mode. Use it with cipher specification string + aes-lrw-bewbi, the key must be 128, 192 or 256 bits. + + WARNING: The ABL spec is not finalized and still has to be reviewed. + Do not use this mode for anything serious yet. + config CRYPTO_DES tristate "DES and Triple DES EDE cipher algorithms" select CRYPTO_ALGAPI
crypto/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_CRYPTO_GF128MUL) += gf128mul.o obj-$(CONFIG_CRYPTO_ECB) += ecb.o obj-$(CONFIG_CRYPTO_CBC) += cbc.o obj-$(CONFIG_CRYPTO_LRW) += lrw.o +obj-$(CONFIG_CRYPTO_ABL) += abl.o obj-$(CONFIG_CRYPTO_DES) += des.o obj-$(CONFIG_CRYPTO_BLOWFISH) += blowfish.o obj-$(CONFIG_CRYPTO_TWOFISH) += twofish.o
crypto/abl.c new file +406 -0
406 lines not on this page · raw message
crypto/tcrypt.c +12 -0
@@ -911,6 +911,10 @@ static void do_test(void) AES_LRW_ENC_TEST_VECTORS);test_cipher ("lrw(aes)" ,DECRYPT , aes_lrw_dec_tv_template,AES_LRW_DEC_TEST_VECTORS ); +test_cipher ("abl(aes)" ,ENCRYPT , aes_abl_enc_tv_template, +AES_ABL_ENC_TEST_VECTORS ); +test_cipher ("abl(aes)" ,DECRYPT , aes_abl_dec_tv_template, +AES_ABL_DEC_TEST_VECTORS );//CAST5 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
@@ -1078,6 +1082,10 @@ static void do_test(void) AES_LRW_ENC_TEST_VECTORS);test_cipher ("lrw(aes)" ,DECRYPT , aes_lrw_dec_tv_template,AES_LRW_DEC_TEST_VECTORS ); +test_cipher ("abl(aes)" ,ENCRYPT , aes_abl_enc_tv_template, +AES_ABL_ENC_TEST_VECTORS ); +test_cipher ("abl(aes)" ,DECRYPT , aes_abl_dec_tv_template, +AES_ABL_DEC_TEST_VECTORS );break ;case 11 :
@@ -1236,6 +1244,10 @@ static void do_test(void) aes_lrw_speed_template);test_cipher_speed ("lrw(aes)" ,DECRYPT , sec,NULL ,0 , aes_lrw_speed_template); +test_cipher_speed ("abl(aes)" ,ENCRYPT , sec,NULL ,0 , + aes_abl_speed_template); +test_cipher_speed ("abl(aes)" ,DECRYPT , sec,NULL ,0 , + aes_abl_speed_template);break ;case 201 :
crypto/tcrypt.h +300 -0
318 lines not on this page · raw message
Signature · 1 line
1.4.4.1