From mboxrd@z Thu Jan 1 00:00:00 1970 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 OnDNqbjb-zQU for ; Sun, 7 Oct 2012 21:50:50 +0200 (CEST) Received: from mail-wg0-f44.google.com (mail-wg0-f44.google.com [74.125.82.44]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mail.saout.de (Postfix) with ESMTPS for ; Sun, 7 Oct 2012 21:50:49 +0200 (CEST) Received: by mail-wg0-f44.google.com with SMTP id dr13so3129767wgb.1 for ; Sun, 07 Oct 2012 12:50:49 -0700 (PDT) Message-ID: <5071DD16.8030301@gmail.com> Date: Sun, 07 Oct 2012 21:50:46 +0200 From: Milan Broz MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [dm-crypt] Query on validating cryptsetup List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Abhishek Tiwari Cc: dm-crypt@saout.de On 10/03/2012 07:28 PM, Abhishek Tiwari wrote: > I am trying to use cryptsetup for an SD card. I create the crypto > mapper device and write a file to it. For the purpose of validation, > I am using a fixed key "11111111" as passphrase. Then I tried to see > the contents of this SD card using a reader and WinHex. Unfortunately > these contents do not match with an encrypted copy of same file that > was encrypted using this online DES encryption tool: > http://www.tools4noobs.com/online_tools/encrypt/ I specified > algorithm as DES and mode as CBC. Well, if it is real use, never use DES, it is no longer secure enough. But for learning crypto this can be nice exercise. First, note difference in CBC encryption for the whole file and with dm-crypt. For dmcrypt, it uses CBC per sector, restarting for every sector with defined IV. (Sectors are encrypted independently.) So you cannot compare more than one sector of ciphertext - 512 bytes with tool above. Whatever: - in that PHP tool, I entered "11111111" as key (note it is string, so it translates to 0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31) - plaintext "test1234test5678" (2x DES 8-bytes blocks to see CBC for second block) - encryption is DES, mode CBC, output hexa - note php mcrypt_encrypt uses zeroed IV if not specified So, this will get ciphertext: b43b364065cdf4571a92ba2daecaf2ff Now, the same with cryptsetup: - prepare keyfile # echo -n "11111111">keyfile - configure cryptsetup, null is zeroed IV. Note that for keyfile there is no hashing (exactly what we need - directly use key form file). # cryptsetup -c des-cbc-null --key-size=64 --key-file=keyfile create test /dev/sdb - you can verify what key is really used (key is 5th parameter in hexa) # dmsetup table --showkeys test 0 417792 crypt des-cbc-null 3131313131313131 0 8:16 0 - write plaintext # echo -n "test1234test5678" >/dev/mapper/test - flush underlying device cache to be sure we read new data (or remove dmcrypt mapping) # blockdev --flushbufs /dev/sdb - and check ciphertext # hexdump -C -n 16 /dev/sdb 00000000 b4 3b 36 40 65 cd f4 57 1a 92 ba 2d ae ca f2 ff |.;6@e..W...-....| For me, it looks like it is the same ;-) Milan