Re: V3 secret keys

Ben Laurie <ben@algroup.co.uk> Tue, 07 February 2006 09:59 UTC

Received: from odin.ietf.org ([132.151.1.176] helo=ietf.org) by megatron.ietf.org with esmtp (Exim 4.32) id 1F6Pco-0002Lz-8Z for openpgp-archive@megatron.ietf.org; Tue, 07 Feb 2006 04:59:06 -0500
Received: from above.proper.com (above.proper.com [208.184.76.39]) by ietf.org (8.9.1a/8.9.1a) with ESMTP id EAA08625 for <openpgp-archive@lists.ietf.org>; Tue, 7 Feb 2006 04:57:23 -0500 (EST)
Received: from above.proper.com (localhost.vpnc.org [127.0.0.1]) by above.proper.com (8.12.11/8.12.9) with ESMTP id k179cB9f008170; Tue, 7 Feb 2006 01:38:11 -0800 (PST) (envelope-from owner-ietf-openpgp@mail.imc.org)
Received: (from majordom@localhost) by above.proper.com (8.12.11/8.12.9/Submit) id k179cBmg008169; Tue, 7 Feb 2006 01:38:11 -0800 (PST)
X-Authentication-Warning: above.proper.com: majordom set sender to owner-ietf-openpgp@mail.imc.org using -f
Received: from mail.links.org (mail.links.org [217.155.92.109]) by above.proper.com (8.12.11/8.12.9) with ESMTP id k179c73E008160 for <ietf-openpgp@imc.org>; Tue, 7 Feb 2006 01:38:08 -0800 (PST) (envelope-from ben@algroup.co.uk)
Received: from [193.133.15.218] (localhost [127.0.0.1]) by mail.links.org (Postfix) with ESMTP id C287F33C1C; Tue, 7 Feb 2006 09:38:06 +0000 (GMT)
Message-ID: <43E86A06.8070402@algroup.co.uk>
Date: Tue, 07 Feb 2006 09:36:06 +0000
From: Ben Laurie <ben@algroup.co.uk>
User-Agent: Thunderbird 1.5 (Windows/20051201)
MIME-Version: 1.0
To: Hal Finney <hal@finney.org>
CC: ietf-openpgp@imc.org
Subject: Re: V3 secret keys
References: <20060206223801.7087157FAE@finney.org>
In-Reply-To: <20060206223801.7087157FAE@finney.org>
X-Enigmail-Version: 0.93.0.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 7bit
Sender: owner-ietf-openpgp@mail.imc.org
Precedence: bulk
List-Archive: <http://www.imc.org/ietf-openpgp/mail-archive/>
List-Unsubscribe: <mailto:ietf-openpgp-request@imc.org?body=unsubscribe>
List-ID: <ietf-openpgp.imc.org>
Content-Transfer-Encoding: 7bit

Hal Finney wrote:
> Ben Laurie writes:
>> OK, I had to resort to reading the PGP 2 source to find out what was
>> going on here.
>>
>> In essence its fairly simple, but is _definitely_ no explained by the I-D.
>>
>> Firstly, v3 CFB does not use the IV in a standard way. Instead, what it
>> does instead is set the IV to all zeroes and then decrypt the IV and
>> throw away the result.
> 
> This is not correct. The IV is used in the standard way.  You may be
> thinking of symmetrically encrypted data packets, which work as you
> say here.  V3 private keys are standard.

Experiment and code reading/running says it is correct.

>> Secondly, as I think was correctly explained by someone here (but I
>> didn't get it, sorry), when "resynchronisation" occurs it means "set the
>> IV to the last 8 bytes of ciphertext".
> 
> Right.
> 
>> Note that for any standard-sized key resynchronisation does _not_ occur,
>> so people who think they've implemented it from AC are in for a surprise
>> one day.
> 
> This will usually be the case; p and q will be forced to be a multiple
> of 8 bytes (64 bits) for keys of usual sizes.  But d, which is e inverse
> mod lambda(n) would be shorter sometimes.  lambda(n) is lcm(p-1,q-1) so
> lambda will be at least 1 bit shorter (since p-1 and q-1 are both even)
> and perhaps 2 bits shorter with probability about 1/2 (in case p-1 and
> q-1 have other small common factors).  Independently, d may be shorter
> than lambda.  Put it all together and maybe one key in 70 or so would
> have a d value which is 1 byte shorter, requiring resynchronization.

OK, well, I haven't see one yet. As I mentioned before, test
vectors/packets in the I-D would be _really_ nice.

>> Obviously the I-D should be updated to reflect this (and clearly no-one
>> has ever implemented v3 keys from it).
> 
> The current text is not inaccurate, but does rely on knowing what
> "resynchronized" means.  Since this is a non-standard term we should
> explain it better.  Here is the current text:
> 
>     Encryption/decryption of the secret data is done in CFB mode using
>     the key created from the passphrase and the Initial Vector from the
>     packet. A different mode is used with V3 keys (which are only RSA)
>     than with other key formats. With V3 keys, the MPI bit count prefix
>     (i.e., the first two octets) is not encrypted.  Only the MPI
>     non-prefix data is encrypted.  Furthermore, the CFB state is
>     resynchronized at the beginning of each new MPI value, so that the
>     CFB block boundary is aligned with the start of the MPI data.
> 
> The last sentence is the one which is problematic.  What if we changed
> it to:
> 
>    Furthermore, at the beginning of each MPI value after the first,
>    the CFB state is re-synchronized to its initial state, with the IV
>    for that MPI taken as the last 8 octets of the ciphertext of the
>    previous MPI value.
> 
> Note that V3 keys only support ciphers with a block size of 8 bytes, so
> I think it is OK to explicitly say "8 octets" here.

"re-synchronised to its initial state" is perhaps not entirely clear -
wouldn't it better to just say the IV is set to the last 8 octets of the
previous ciphertext and not mention initial state?

Cheers,

Ben.

-- 
http://www.apache-ssl.org/ben.html       http://www.thebunker.net/

"There is no limit to what a man can do or how far he can go if he
doesn't mind who gets the credit." - Robert Woodruff