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 iCXeD6ln0oAv for ; Wed, 26 Sep 2012 19:02:06 +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 19:02:06 +0200 (CEST) Message-ID: <5063351E.5090501@ramses-pyramidenbau.de> Date: Wed, 26 Sep 2012 19:02:22 +0200 From: Ralf Ramsauer MIME-Version: 1.0 References: <50630077.6000204@ramses-pyramidenbau.de> <50630996.1080803@gmail.com> <50631C9E.8030903@ramses-pyramidenbau.de> <5063265F.6000206@gmail.com> In-Reply-To: <5063265F.6000206@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig76412FC08457706FF3E4D992" 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) --------------enig76412FC08457706FF3E4D992 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 09/26/12 17:59, Milan Broz wrote: > On 09/26/2012 05:17 PM, Ralf Ramsauer wrote: >> Plain64 is defined as: >> *plain64*: the initial vector is the 64-bit little-endian version of t= he 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.... > Read how CBC mode works > http://en.wikipedia.org/wiki/Cipher_block_chaining#Cipher-block_chainin= g_.28CBC.29 > > For full disk encryption, every sector (512 Bytes) is encrypted indepen= dently. > > Inside that sector block cipher mode applies (size of cipher block is t= ypically > 16 bytes, so you have 512/16 chained blocks inside sector for the CBC m= ode. > If it helps, I tried to describe it here http://mbroz.fedorapeople.org/= talks/DevConf2012/ Now it's clear :-) So each sector uses it's own IV (in case of plain mode, the sector number which padded up with zeroes). Otherwise parts inside the block device couldn't be exchanged without reencrypting the whole content beginning from that point. Now it makes sense, didn't think about that. > >> The IV is just needed for decrypting the first Block. How is it exactl= y generated? > plain64 =3D=3D just sector number. IOW offset from the device start in = sectors. Ok, i got it :-) > =20 >> The IV has not to be kept secret and is just used for decrypting the f= irst Block. > No. For CBC you should use ESSIV and not predictable IV. > (And you need separate IV for every sector, not one per device.) > (For other encryption modes, like XTS, predictable IV is ok.) > >> So why not filling up the IV with zeroes or wasting the first block by= filling it with random data? > I think you missed the point. dmcrypt is transparent sector based devic= e encryption, > size of plaintext =3D size of ciphertext, you have no extra space. > > IV is generated, not stored anywhere. > For plain64 IV, it is just > iv =3D cpu_to_le64(sector_offset); (see dmcrypt code) > >> 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 > dmcrypt always uses 512 Bytes sized sectors, logical block is irrelevan= t here. > (block size is inherited from underlying device but encryption always r= un over 512 sectors. > No need to worry, dmcrypt handles this for you) > > Please, if you are not sure how it works, use default mode, see cryptse= tup --help. > (Which is currently aes-cbc-essiv:sha256, in next version we will switc= h to XTS mode though.) > > Milan Milan, thanks a lot for your explanations, you really helped me! Ralf --------------enig76412FC08457706FF3E4D992 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/ iQIcBAEBAgAGBQJQYzUeAAoJEL+V5p9n2n1jAu4QALmOB8r9JiTg9drkFgwm2jlB 479jYSjkjZAJ4ct0vFI0Mz0D9wunr+ybNl8Hg7Hpgj7cLkZRPYmcvPDKpHNX8Zr/ faEZiBxEt1AwR9LyzNqiee9mT1Lc0uIhU4Idx1IN1Brs0QDpTwzisq70xUGNKbRl RQ0DEamlqTFNkC1YvjXVYsgXRhSlb5CKFwZDa8ApQ7ba6coudWqV2LLqH8Z/bSqT WfmjpTCIsuCJXqxBPK9h8MtdoJYMwqw0QyBv9uW+BAC0CGOtX0FqcfBXmaIDHpp3 wt/6Zx4WPSJYHuqtmrHpCDF9bpwr2EdgWZiHSWDRqShBeO807kSuwVTnWoYf8rvv /8hwN/zq4YdS35KXUW44hRNWd8TTJAGlmQzMsGhytYDg9QLM7vpeyIta+qQxMJcv PPqVLVMzLGljtmvZGin14X7WaZ5vzoTk2VId6zyjp1ObLNoij88DfhF5zSs7cMiC pfP2kQQHufd1uWq9mCnl004HKpPg6I/fbZ5HH/gKdU6Wb17gzS7w0M8IahHpj5NX IU6qBQPkqCcCH6rA8N6FRB9KCF61ZReQlVPSt64aCFHHczFkHKRTIgC3UyqWvYnY tnJTgV35gUBrhna2VQ+Fp8RaccQVr4T9xl2JiK5Gjmq521U4oebSEC/iduyt4NK2 Zcqt6eLpfnXYp+3jp/Cz =ortu -----END PGP SIGNATURE----- --------------enig76412FC08457706FF3E4D992--