<!-- $Id$ -->

<!DOCTYPE ARTICLE PUBLIC "-//OASIS//DTD DocBook V3.1//EN" [
<!--ArborText, Inc., 1988-1995, v.4001-->
<!NOTATION drw SYSTEM "DRW">
<!ENTITY gpg "<application>gpg</application>">
<!ENTITY gnupg "GnuPG">
<!ENTITY Gnupg "GnuPG">
<!ENTITY pgp "PGP 2.x">
<!ENTITY Gnupg "GnuPG">
<!ENTITY eg "e.g.">
<!ENTITY ie "i.e.">
<!ENTITY license SYSTEM "license.sgml">
]> 

<article>
<artheader>
<title>Replacing &pgp; with &gnupg;</title>
<!--
<authorgroup>
<author><firstname>Kyle</><surname>Hasselbacher</>
<affiliation>
<address><email>kyle@toehold.com</email></address>
</affiliation>
</author>
<author><firstname>Michael</><surname>Fischer v. Mollard</>
<affiliation>
<address><email>mfvm@gmx.de</email></address> 
</affiliation>
</author>
<author><firstname>Mike</><surname>Ashley</>
<affiliation>
<address><email>jashley@acm.org</email></address>
</affiliation> 
</author>
</authorgroup>
-->
<copyright>
<year>1999</year>
<holder>Kyle Hasselbacher</holder>
</copyright>
</artheader>

<abstract>
<para>
This article is based on an earlier
<ulink url="http://www.toehold.com/~kyle/pgp-compat.html">&pgp;/&gnupg; 
compatability guide</ulink> written by Kyle Hasselbacher 
(<email>kyle@toehold.com</email>).
Mike Ashley (<email>jashley@acm.org</email>) edited and expanded it.
Michael Fischer v. Mollard (<email>mfvm@gmx.de</email>) transformed the 
HTML source to DocBook SGML and also expanded it further.
Some of the details described here came from the 
<literal>gnupg-devel</literal> and <literal>gnupg-user</literal> mailing lists.
The workaround for both signing with and encrypting to an RSA key were
taken from 
<ulink
url="http://muppet.faveve.uni-stuttgart.de/~gero/gpg-2comp/changes.html">Gero 
Treuner's compatability script</ulink>.
Please direct questions, bug reports, or suggesstions to
the maintainer, Mike Ashley.
</para>

<para>
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled "GNU
Free Documentation License".
</para>
</abstract>

<sect1>
<title>
Introduction
</title>

<para>
This document describes how to communicate with people still using
old versions of &pgp;
&gnupg; can be used as a nearly complete replacement for
&pgp;.
You may encrypt and decrypt &pgp; messages using imported
old keys, but you cannot generate &pgp; keys.
This document demonstrates how to extend the standard distribution of
&gnupg; to support &pgp; keys as well as what options must be used to
ensure inter-operation with &pgp; users.  
It also warns of anomalies
with the interoperation of &pgp; and &gnupg;.  
</para>
	  
<para>
<emphasis>Note:</emphasis> Using the extension modules
<filename>idea.c</filename> and <filename>rsa.c</filename> without
licensing the patented algorithms they implement may be illegal.
I do not recommend you use these modules.  
If you have &pgp; keys, I suggest you revoke them in favor of new keys and
encourage correspondents who use &pgp; keys to do the same.
</para>
</sect1>

<sect1>
<title>
Extending &gnupg; to support &pgp; keys
</title>

<para>
The standard distribution of &gnupg; does not support &pgp; keys since
&pgp; uses IDEA as its symmetric cipher and RSA for its public key
cipher. 
These algorithms are patented<footnote><para>
The RSA patent expires in September 2000.
The IDEA patent expires in 2011.
</para></footnote>
and may only be used under certain restrictions. 
It is a GNU policy not to use patented algorithms, since patents on
algorithms are a contradiction to the spirit of free software.
Employing these algorithms limits your freedom to use &gnupg; as you wish.
</para>

<para>
It may or may not be legal to use RSA and IDEA without licensing
these algorithms.
RSA is only patented in the United States, so it is legal to build RSA
versions outside of the United States. 
The extension module for &gnupg; is such a version and it may be 
legally used outside the United States, but it is illegal to use it 
in the United States.  
In the United States there exists a reference implementation for RSA 
called RSAREF, available at
<ulink url="tp://ftp.funet.fi/pub/crypt/cryptography/asymmetric/rsa/rsaref2.tar.gz">ftp.funet.fi</ulink> or at 
<ulink url=" ftp://non-us.debian.org/debian-non-US/dists/stable/non-US/source/rsaref_19930105.orig.tar.gz">debian.org</ulink>, 
that may be used legally without a charge in the USA for non commercial 
use.
Due to export restrictions this code cannot be exported, so there
are two ways to integrate RSA into &gnupg;: one for the USA and Canada, and
one for the rest of the world.
</para>

<para>
The situation for IDEA is simpler.
IDEA is patented in Europe and in the USA, and a patent for Japan is 
pending. 
The patent holder, Ascom, grants a non-commerical
<ulink url="http://www.ascom.ch/infosec/idea/licensing.html">license</ulink>
for no charge, but the definition of non-commercial use is rather strict
You need to buy a license from Ascom if you want to use IDEA commercially.
</para>

<!--
<para>
Looking at this situation one might conclude that patents on software
are not a good idea, and this is true. 
Let me say it again: Revoke
your old &pgp; keys and try to convince your communication partners to
use newer OpenPGP ones, and you will not have any problems with
patents.
</para>
-->

<para>
To use the extension modules first obtain their source code,
<filename>idea.c</filename> and <filename>rsa.c</filename> or
<filename>rsaref.c</filename> from the directory of code 
<ulink url="ftp://ftp.gnupg.org/pub/gcrypt/contrib/">contributed</ulink>
to &gnupg;. 
Once you have the code, it must be compiled.
If you use <application>gcc</application>, you would compile it as follows: 
</para>

<screen width=80>
<prompt>alice%</prompt> <userinput>gcc -Wall -O2 -shared -fPIC -o idea idea.c</userinput>  
[...]  
<prompt>alice%</prompt> <userinput>gcc -Wall -O2 -shared -fPIC -o rsa rsa.c</userinput>  
[...] # or
<prompt>alice%</prompt> <userinput>gcc -Wall -O2 -shared -fPIC -o rsa rsaref.c /usr/lib/rsaref.a</userinput>
 </screen>

<para>
The last argument <filename>/usr/lib/rsaref.a</filename> must be
replaced with the real location of the RSAREF library on your local machine.
</para>

<para>
Once compiled, &gnupg; must be instructed to load it. 
This may be done using the option <option>load-extension</option>, 
either on the command line or in the options file although typically it
is done in the options file.
For example, if you have put <filename>idea</filename>
and <filename>rsa</filename> in your <filename>~/.gnupg</filename>
directory, in the options file you may add
</para>

<screen width=80>
load-extension ~/.gnupg/idea  
load-extension ~/.gnupg/rsa      
</screen>

<para>
If you do not specify an explicit path, &gnupg; searches the
extension modules in the default &gnupg; module directory, which is
<filename>/usr/local/lib/gnupg</filename>. 
If you compiled &gnupg; with a different install prefix using
<option>--prefix PREFIX</option> when you configured
your &gnupg; source, then the module directory is 
<filename>PREFIX/lib/gnupg</filename>.
Copy the two files `rsa' and `idea' into the module directory described
above.
Make sure everyone can read these files.
You do not have to make these files executable as these files are not
programs but shared modules.
</para>
</sect1>

<sect1>
<title>
Importing &pgp; keys
</title>

<para>
Once the extensions are loaded it is straightforward to import a &pgp;
key pair using the option <option>import</option>. 
There are two caveats, however.
</para>

<para>
<itemizedlist>
<listitem>
<para>
You must not export a private key from &pgp; as an ASCII-armored file.  
Because &pgp; predates the OpenPGP specification,
the armored message header &pgp; uses is not compliant with OpenPGP.
Because private key export is rare, &gnupg; does not check for the
case when the ASCII-armored message is a private key.
</para>
</listitem>

<listitem> 
<para>
&Gnupg; expects imported public keys to be self-signed
by the corresponding private key.
This is a prudent  precaution, and
both &gnupg; and newer versions of PGP self-sign public keys when they
are first created.  
This is not done by &pgp;, however.
To solve this, you can first self-sign the public key before exporting
it from &pgp;.  
Alternatively, you can use the option
<option>allow-non-selfsigned-uid</option> to force &gnupg; to take the
key anyway.
It is recommended that you self-sign the key either
before exporting it or after you have imported it, though, since using
a non-self-signed key is a security risk.
</para>
</listitem>
</itemizedlist>
</para>

<screen width=80>
<prompt>alice%</prompt><userinput> pgp -kx alice public.pgp</userinput> 
Pretty Good Privacy(tm) 2.6.2 - Public-key encryption for the masses. 
[...]
Extracting from key ring: '/u/alice/.pgp/pubring.pgp', userid "alice". 
Key for user ID: Alice &lt;alice@cyb.org> 
1024-bit key, Key ID 24E2C409, created 1999/09/18

Key extracted to file 'public.pgp'. 

<prompt>alice%</prompt> <userinput>pgp -kx alice private.pgp .pgp/secring.pgp</userinput>
Pretty Good Privacy(tm) 2.6.2 - Public-key encryption for the masses.
[...] 

Extracting from key ring: '.pgp/secring.pgp', userid "alice".
Key for user ID: Alice &lt;alice@cyb.org> 
1024-bit key, Key ID 24E2C409, created 1999/09/18 

Key extracted to file 'private.pgp'.

<prompt>alice%</prompt> <userinput>&gpg; --import public.pgp</userinput>
gpg: key 24E2C409: public key imported 
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1) 

<prompt>alice%</prompt><userinput>&gpg; --import private.pgp</userinput> 
gpg: key 24E2C409: secret key imported 
gpg: Total number processed: 1 
gpg:       secret keys read: 1 
gpg:   secret keys imported: 1
</screen>
</sect1>

<sect1>
<title>
Using &pgp; keys
</title>

<para>
An imported public key can be used to encrypt documents to a &pgp;
private key holder and check signatures made using a &pgp; private
key. 
<emphasis>
It is important to realize that it is impossible to use a new OpenPGP
key to communicate with an &pgp; user, so you must import an old style
key if you want to communicate with a &pgp; user.
</emphasis> 
</para>

<sect2>
<title>
Encrypting a document to a &pgp; user
</title>
	  
<para>
Encrypting a document uses several command-line options, and the
document to be encrypted must be specified as a file. 
</para>

<screen width=80>
<prompt>alice%</prompt> <userinput>&gpg; --rfc1991 --cipher-algo idea --compress-algo 1 --encrypt --recipient alice secret</userinput> 
gpg:
RSA keys are deprecated; please consider creating a new key and use this key in the future 
gpg: this cipher algorithm is depreciated; please use a more standard one!
</screen>

<para>
Each of the command-line options are necessary.
</para>

<itemizedlist>
<listitem>
<para>
The option <option>rfc1991</option> is used to force
&gnupg; to be more compliant with RFC 1991, which is the old PGP
specification implemented by &pgp;. 
If it is omitted, the output from &gnupg; will be malformed and unusable 
by &pgp;.
</para>
</listitem>

<listitem>
<para>
The option <option>cipher-algo</option> specifies the
symmetric cipher with which the document is to be encrypted. 
In the special case of encrypting to a &pgp; public key, the cipher specified
must be IDEA. 
If it is omitted, the document will usually be encrypted
using 3DES, an algorithm unsupported by &pgp;.
</para>
</listitem>

<listitem> 
<para>
&pgp;'s compression algorithm motivates how the rest of
the command is formed. 
The option <option>compress-algo</option>
specifies that &gnupg; must use the old zlib compression algorithm
used by &pgp;. 
Despite this, &gnupg; uses partial length headers when
encrypting a stream of unknown size, and this is unsupported by &pgp;.
The document to be encrypted must therefore be in a file so that
&gnupg; knows the total size of the document to be encrypted before
starting. 
So unfortunately, you cannot use pipes when using &pgp; keys.
</para>
</listitem>
</itemizedlist>
</sect2>

<sect2>
<title>
Signing a document for a &pgp; user
</title>

<para>
Signing a document is no different than when any other key is used.
</para>

<!-- sign from gpg to pgp -->
<screen width=80>
<prompt>alice%</prompt> <userinput>&gpg; --local-user 0x24E2C409 --sign document</userinput> 
You need a passphrase to unlock the secret key for 
user: "Alice &lt;alice@cyb.com>" 
1024-bit RSA key, ID 24E2C409, created 1999-09-18 

gpg: RSA keys are deprecated; please consider creating a new key and use this 
key in the future 
</screen>

<para>
In this example, the option <option>local-user</option> is used to
specify which private key to use for signing. 
Also, the output file is <filename>document.gpg</filename>. 
If the signature is to be verified
using &pgp;, it must be renamed to a filename with a
<filename>.pgp</filename> extension.
</para>
</sect2>

<sect2>
<title>
Signing and encrypting a document for a &pgp; user
</title>

<para>
&Gnupg; does not have native support for both signing a document with
an RSA key and encrypting it to an RSA key.
&Gnupg; can be used in a workaround, however, that requires a few steps
to implement.
The process involves creating a detached signature and then using it
to build an encrypted file that can be decrypted and verified using
&pgp;.
</para>

<para>
There are four steps.
The first creates a detached signature
</para>

<screen width=80>
<prompt>alice%</prompt> <userinput>gpg --detach-signature --recipient alice --local-user 0x24E2C409 document</userinput> 

You need a passphrase to unlock the secret key for
user: "Alice &lt;alice@cyb.com>"
1024-bit RSA key, ID 24E2C409, created 1999-09-18

gpg: RSA keys are deprecated; please consider creating a new key and use this
key in the future
</screen>

<para>
The second step converts the document to an internal, literal format that is
unencrupted.
</para>

<screen width=80>
<prompt>alice%</prompt> <userinput>gpg --store -z 0 --output document.lit document</userinput> 
</screen>

<para>
The third step combines the detached signature with the literal document.
This is what &pgp; uses to verify the signature after decryption.
</para>

<screen width=80>
<prompt>alice%</prompt> <userinput>cat Notes.sig Notes.lit | gpg --no-options --no-literal --store --compress-algo 1 --output document.z</userinput> 
gpg: NOTE: --no-literal is not for normal use!
</screen>

<para>
The fourth and final step is to use &gnupg; to encrypt the combined
signature and plaintext to yield an signed and encrypted document
that can be decrypted and verified using &pgp;.
</para>

<screen width=80>
<prompt>alice%</prompt> <userinput>gpg --rfc1991 --cipher-algo idea --no-literal --encrypt --recipient alice --output document.pgp document.z</userinput> 
gpg: NOTE: --no-literal is not for normal use!
gpg: RSA keys are deprecated; please consider creating a new key and use this
key in the future
gpg: this cipher algorithm is depreciated; please use a more standard one!
</screen>

<para>
The signed and encrypted document can also be ASCII-armored using the usual
options.
</para>

<screen width=80>
<prompt>alice%</prompt> <userinput>gpg --rfc1991 --cipher-algo idea --no-literal --encrypt --recipient alice --output document.asc --armor document.z</userinput> 
gpg: NOTE: --no-literal is not for normal use!
gpg: RSA keys are deprecated; please consider creating a new key and use this
key in the future
gpg: this cipher algorithm is depreciated; please use a more standard one!
</screen>
</sect2>

<sect2>
<title>
Decrypting a &pgp; document
</title>

<para>
An imported private key may be used to decrypt documents encrypted to
the key as well as make signatures using the key. Decrypting a message
is no more difficult than when any other key is used.
</para>

<!-- decrypt from pgp to gpg -->
<screen width=80>
<prompt>alice%</prompt> <userinput>&gpg; secret.pgp</userinput> 

You need a passphrase to unlock the secret key for 
user: "Alice &lt;alice@cyb.org>" 
1024-bit RSA key, ID 24E2C409, created 1999-09-18

gpg: NOTE: cipher algorithm 1 not found in preferences 
gpg: secret.pgp: unknown suffix 
Enter new filename [secret]: 
</screen>

<para>
Again, the file renaming dialog can be avoided by renaming the input
file with a <filename>.gpg</filename> extension. 
The note emitted by &gnupg; regarding cipher algorithm 1 not found in
the preferences may be safely ignored if seen.
</para>
</sect2>

<sect2>
<title>
Verifying a &pgp; signature
</title>

<para>
Verifying a signature made using a &pgp; key is straightforward.
</para>

<screen width=80>
<prompt>alice%</prompt> <userinput>&gpg; document.pgp</userinput> 
gpg: document.pgp: unknown suffix
Enter new filename [document]:  
File `document' exists. Overwrite (y/N)? y 
gpg: old style (PGP 2.x) signature
gpg: Signature made Sat Sep 18 17:55:30 1999 EST using RSA key ID 24E2C409 
gpg: Good signature from "Alice &lt;alice@cyb.org>"
</screen>

<para>
The file renaming dialog can be avoided if the document being
verified is renamed with a <filename>.gpg</filename> extension before
invoking &gpg;.
</para>

</sect2>
</sect1>

<sect1 id="clearText">
<title>
Working with clear-text signatures
</title>

<para>
As of &gnupg; release 1.0, there are outstanding issues with respect
to passing clear-text signed documents between &gnupg; and all versions
of PGP.
The difficulties appear to be due to implementation deviations from the
OpenPGP specification.
With respect to &pgp;, signatures made by &pgp; can be  verified using
&gnupg; and signatures made with &gnupg; can be verified using &pgp;.
The document output from the verification will in both cases differ,
however, from the original document.
These differences are limited to whitespace, so it should not affect
human readability of signed documents.
If it is important to maintain complete integrity of the document,
you should avoid clear-text signatures.
</para>
</sect1>

&license
</article>

