Return-Path: Received: from mail.saout.de ([127.0.0.1]) by localhost (mail.saout.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ccmqF2JrkF06 for ; Wed, 26 Sep 2012 17:17:33 +0200 (CEST) Received: from mail.ramses-pyramidenbau.de (ramses-pyramidenbau.de [78.47.114.252]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.saout.de (Postfix) with ESMTPS for ; Wed, 26 Sep 2012 17:17:33 +0200 (CEST) Message-ID: <50631C9E.8030903@ramses-pyramidenbau.de> Date: Wed, 26 Sep 2012 17:17:50 +0200 From: Ralf Ramsauer MIME-Version: 1.0 References: <50630077.6000204@ramses-pyramidenbau.de> <50630996.1080803@gmail.com> In-Reply-To: <50630996.1080803@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig25140D0831CBB3123C6DDF04" Subject: Re: [dm-crypt] Initialization Vector using plain aes-cbc List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Milan Broz Cc: dm-crypt@saout.de This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig25140D0831CBB3123C6DDF04 Content-Type: multipart/alternative; boundary="------------040007030907000901090904" This is a multi-part message in MIME format. --------------040007030907000901090904 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 09/26/12 15:56, Milan Broz wrote: > On 09/26/2012 03:17 PM, Ralf Ramsauer wrote: >> cryptsetup create asd ./foobar --cipher=3Daes-cbc-essiv:sha256 --key-f= ile key >> or >> cryptsetup create asd ./foobar --cipher=3Daes-cbc >> Enter Passphrase: .......... > # cryptsetup create asd ./foobar --cipher=3Daes-cbc > Enter passphrase:=20 > device-mapper: reload ioctl on failed: Invalid argument > device-mapper: table ioctl on failed: No such device or address > >> work fine. > nope :) > Which version you are using? I'm using 1.4.3 and i double checked it. You are right, the second command fails, sorry, i probably mixed something up. cryptsetup create asd ./foobar --cipher=3Daes-cbc-plain works fine. > First, for historic reasons, there are some shortcuts: > "aes" and "aes-plain" will translate to "aes-cbc-plain" > > but "aes-cbc" is not valid shortcut > (and cbc mode require IV specification ) > > If you are not sure, just run > cryptsetup status > and it will print full mode spec. of active device. > > FO scripts, please always use full specification, the above is just > to provide compatibility with old cryptsetup. > > Format is > -- Ah ok, now things are getting clearer. > plain/plain64 IV is just sector number, so no dependence > on passphrase/key. (If used with CBC mode, it is not secure.) > > For more info about available IV modes see > http://code.google.com/p/cryptsetup/wiki/DMCrypt#IV_generators > > Milan Ah I see. Let's have a closer look at the mapping table example on that page: 0 417792 crypt aes-xts-plain64 e8cfa3dbfe373b536be43c5637387786c01be00ba5= f730aacb039e86f3eb72f3 0 8:16 0 | | | | | | | = | | |=20 start| | | mode IV | = | | offset size | cipher | = | device target 256bit-key = IV offset In this case=20 In this case, the start sector is 0 and the IV offset is 0 as well. Let's assume our IV generator is plain64 and we use a 256bit Key, AES blocksize is 128Bit, so our IV has to be 16Bytes. IV offset is defined as: *iv_offset*: The IV offset is a sector count that is added to the sector number before creating the IV. It can be used to create a map that starts after the first encrypted sect= or. Usually you'll set it to zero except your device is only partially available or you need to configure some mode compatible with other encryption system. Plain64 is defined as: *plain64*: the initial vector is the 64-bit little-endian version of the sector number, padded with zeros if necessary. As I understand it, the first encrypted block and the IV would overlap? I'm sure that is a misunderstanding, but I don't get it.... The IV is just needed for decrypting the first Block. How is it exactly generated? The IV has not to be kept secret and is just used for decrypting the first Block. So why not filling up the IV with zeroes or wasting the first block by filling it with random data? Example: if i generate a crypt-loopback device of 1MiB using aes-cbc-plain and a 32Byte Keyfile then blockdev returns #cryptsetup -d ./key -s 128 -c aes-cbc-plain create asd ./foo #blockdev --getsz /dev/mapper/asd 2048 2048 Blocks are exactly 1MiB. Ok, that's fine, no space is wastes, but how did we generate the IV? Sorry, i'm stucking a bit ;-) Thanks a lot! Ralf --------------040007030907000901090904 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 09/26/12 15:56, Milan Broz wrote:
On 09/26/2012 03:17 PM, Ralf Ramsauer wrote:
cryptsetup create asd ./foobar --cipher=3Daes-cbc-=
essiv:sha256 --key-file key
or
cryptsetup create asd ./foobar --cipher=3Daes-cbc
Enter Passphrase: ..........
# cryptsetup create asd ./foobar --cipher=3Daes-cbc
Enter passphrase:=20
device-mapper: reload ioctl on  failed: Invalid argument
device-mapper: table ioctl on  failed: No such device or address

work fine.
nope :)
Which version you are using?
I'm using 1.4.3 and i double checked it. You are right, the second command fails,
sorry, i probably mixed something up.

cryptsetup create asd ./foobar --cipher=3Daes-cbc-plain
works fine.
First, for historic reasons, there are some shortcuts:
"aes" and "aes-plain"  will translate to "aes-cbc-plain"

but "aes-cbc" is not valid shortcut
(and cbc mode require IV specification )

If you are not sure, just run
cryptsetup status <active device>
and it will print full mode spec. of active device.

FO scripts, please always use full specification, the above is just
to provide compatibility with old cryptsetup.

Format is
<cipher>-<mode>-<IV/params>
Ah ok, now things are getting clearer.
plain/plain64 IV is just sector number, so no dependence
on passphrase/key. (If used with CBC mode, it is not secure.)

For more info about available IV modes see
http://code.google.com/p/cryptsetup/wik=
i/DMCrypt#IV_generators

Milan
Ah I see.

Let's have a closer look at the mapping table example on that page:
0 417792 crypt=
 aes-xts-plain64 e8cfa3dbfe373b536be43=
c5637387786c01be00ba5f730aacb039e86f3eb72f3 0<=
/span> 8:16 0
|    |     =
|    |   |     |            =
                     |      =
;                     &=
nbsp;       |  | &=
nbsp; |=20
start|    =
; |    |  mode   I=
V                     &=
nbsp;          |               &=
nbsp;                   |  |   offset
     size  |  cipher             &nbs=
p;                     =
     |                     =
              |  device
         target         &nbs=
p;                     =
         256bit-key      =
                    IV =
offset

In this case=20
In this case, the start sector is 0 and the IV offset is 0 as well.
Let's assume our IV generator is plain64 and we use a 256bit Key, AES blocksize is 128Bit, so our IV has to be 16Bytes.

IV offset is defined as:
iv_offset: The IV offset is a sector count that is added to the sector number before creating the IV.
It can be used to create a map that starts after the first encrypted sector.
Usually you'll set it to zero except your device is only partially available or you need to configure some mode compatible with other encryption system.

Plain64 is defined as:
plain64: the initial vector is the 64-bit little-endian version of the sector number, padded with zeros if necessary.

As I understand it, the first encrypted block and the IV would overlap? I'm sure that is a misunderstanding, but I don't get it....<= br>
The IV is just needed for decrypting the first Block. How is it exactly generated?

The IV has not to be kept secret and is just used for decrypting the first Block.
So why not filling up the IV with zeroes or wasting the first block by filling it with random data?

Example:
if i generate a crypt-loopback device of 1MiB using aes-cbc-plain and a 32Byte Keyfile
then blockdev returns
#cryptsetup -d ./key -s 128 -c aes-cbc-plain create asd ./foo
#blockdev --getsz /dev/mapper/asd
    2048

2048 Blocks are exactly 1MiB. Ok, that's fine, no space is wastes, but how did we generate the IV?
Sorry, i'm stucking a bit ;-)

Thanks a lot!

Ralf
--------------040007030907000901090904-- --------------enig25140D0831CBB3123C6DDF04 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iQIcBAEBAgAGBQJQYxyeAAoJEL+V5p9n2n1j0iYP/RLh0S/aOS2M9cujaLYjAff0 T13RerKq1Nr4FV40V3WSER/TTZeqFjty7UYR5ECoG+O34v33iIk9fqVFtbmimx8l rSAc8ytx8SESCb3JhwMGl2x1jKt4Kz7iSnPrMw4syK9ypBSvnn2ihcZXUEEuxfpN HgoWHB6jIyAAI1bLsL4aeMJje44nXozwZ/DIZGTFz2Q7iGlCIHw3glxhDm/KndBf s352lHDIwNoNucWSEW4gfcdxa/HINVUcSitAfwPy1jQ/3I9aRl6HQyz9+zStvAjq d5BwecG5OZl5ppd20jdnNIklCmsZp1a9WyzWsvLVZ8QBVJvF/J1JBiM1nM11aR1l 50wFLIHX6m1GVpNYKoDmx3XstGm58uT4mklafOzvEDE/dD/YOVCPIc15s6o09szX nDr/z0PfvuFReE0c6LCQjWUg+NbjCHbvNC0D6EIGy1PuWUceG37cQ8Hh3kY6ofia oKhzhrNVS/WNjsEeOwOtYNc59Jisyrg2QvrOcczLnfQbwXCNTP/SSdBGLvyNHsZz KJY+hNyZeE7KhfwrllWh6ireEH5eT6zr9lO+C017K5984HcBp6Bjm11goHudM5wA XnJJ8/LsthCYfpe5wh5VZS13pgPyQN3LQa3XmD7WWr3oho2X2Ti7Ub0vyZfiIt4v TL09dFUYkZ1H0MaNozWp =ZVDq -----END PGP SIGNATURE----- --------------enig25140D0831CBB3123C6DDF04--