diff -c pgp_262/crypto.c pgp_sha1/crypto.c
*** pgp_262/crypto.c Fri Jun 21 23:31:01 1996
--- pgp_sha1/crypto.c Sat Jun 22 00:02:32 1996
***************
*** 63,69 ****
--- 63,75 ----
/* This variable stores the md5 hash of the current file, if it is
available. It is used in make_random_ideakey. */
+ #ifdef SHA1
+ #include "sha1.h"
+ static boolean local_sha1_flag = FALSE;
+ static unsigned char md5buf[20];
+ #else
static unsigned char md5buf[16];
+ #endif
/* This flag is set if the buffer above has been filled. */
static char already_have_md5 = 0;
***************
*** 697,702 ****
--- 703,715 ----
complete message digest packet in a single RSA block. */
blocksize = countbytes(n)-1; /* size of a plaintext block */
+ #ifdef SHA1
+ if ((blocksize < 32) && local_sha1_flag) {
+ fprintf(pgpout,
+ "\n\007Error: RSA key length must be at least 264 bits.\n");
+ return -1;
+ } else
+ #endif
if (blocksize < 31) {
fprintf(pgpout,
"\n\007Error: RSA key length must be at least 256 bits.\n");
***************
*** 714,721 ****
--- 727,744 ----
convert_byteorder(timestamp,4); /* convert to external form */
/* Finish off message digest calculation with this information */
+ #ifdef SHA1
+ if (local_sha1_flag) {
+ SHA1_addbuffer ((struct SHA1Context *)MD, &class, 1, 0);
+ SHA1_addbuffer ((struct SHA1Context *)MD, timestamp, 4, md5buf)
;
+ } else {
+ MD_addbuffer (MD, &class, 1, 0);
+ MD_addbuffer (MD, timestamp, 4, md5buf);
+ }
+ #else
MD_addbuffer (MD, &class, 1, 0);
MD_addbuffer (MD, timestamp, 4, md5buf);
+ #endif
/* We wrote the digest to a static variable because we want to keep it around
for random number generation later. Also make a note of that fact. */
already_have_md5 = 1;
***************
*** 727,734 ****
--- 750,766 ----
}
/* do RSA signature calculation: */
+ #ifdef SHA1
+ if (local_sha1_flag)
+ i = rsa_private_encrypt((unitptr)outbuf, md5buf, 20,
+ e, d, p, q, u, n);
+ else
+ i = rsa_private_encrypt((unitptr)outbuf, md5buf, 16,
+ e, d, p, q, u, n);
+ #else
i = rsa_private_encrypt((unitptr)outbuf, md5buf, sizeof(md5buf),
e, d, p, q, u, n);
+ #endif
if (i < 0) {
if (i == -4) {
fprintf(pgpout,
***************
*** 786,791 ****
--- 818,828 ----
certificate[certificate_length++] = keyID[i];
/* now compare computed MD with claimed MD */
/* Assume MSB external byte ordering */
+ #ifdef SHA1
+ if (!equal_buffers(digest, outbuf+outbufoffset, local_sha1_flag ? 20 :
16)) {
+ #else
if (!equal_buffers(digest, outbuf+outbufoffset, 16)) {
+ #endif
/* IF the signature is bad, AND this machine does not use
MSDOS-stype canonical text as its native text format, AND
this is a detached signature certificate, AND this file
***************
*** 1692,1698 ****
--- 1798,1815 ----
!= NULL )
{
/* Now check the signature */
+ #ifdef SHA1
+ if (local_sha1_flag)
+ SHA1file0_len(&SH, tempFile, -1L );
+ else
+ #endif
MDfile0_len(&MD, tempFile, -1L );
+ #ifdef SHA1
+ if (local_sha1_flag)
+ SHA1_addbuffer(&SH, mdextras, mdlensave,
+ digest);
+ else
+ #endif
MD_addbuffer(&MD, mdextras, mdlensave,
digest);
***************
*** 1703,1714 ****
--- 1820,1839 ----
/* Check if the signature is OK this time
round */
/* Assume MSB external byte ordering */
+ #ifdef SHA1
if(equal_buffers(digest, outbuf+outbufoffset,
+ local_sha1_flag ? 20 : 16))
+ #else
+ if(equal_buffers(digest, outbuf+outbufoffset,
16))
+ #endif
goto goodsig;
}
}
+ #ifdef SHA1
+ local_sha1_flag = FALSE;
+ #endif
fprintf(pgpout,
LANG("\007\nWARNING: Bad signature, doesn't match file contents!\007\n"));
fprintf(pgpout,LANG("\nBad signature from user \"%s\".\n"),
***************
*** 1730,1735 ****
--- 1855,1866 ----
LOCAL_CHARSET((char *)userid));
fprintf(pgpout,
LANG("Signature made %s\n"),ctdate((word32 *)timestamp));
+ #ifdef SHA1
+ if (local_sha1_flag)
+ fprintf(pgpout,
+ LANG("Signature made using the SHA1 message digest algorithm.\n"));
+ local_sha1_flag = FALSE;
+ #endif
warnsig:
/* warn only, don't ask if user wants to use the key */
diff -c pgp_262/pgp.c pgp_sha1/pgp.c
*** pgp_262/pgp.c Fri Jun 21 23:31:16 1996
--- pgp_sha1/pgp.c Sat Jun 22 07:16:22 1996
***************
*** 131,136 ****
--- 131,141 ----
#include "keymaint.h"
#include "keyadd.h"
#include "rsaglue.h"
+
+ #ifdef SHA1
+ #include "sha1.h"
+ #endif
+
#ifdef M_XENIX
char *strstr();
long time();
***************
*** 661,666 ****
--- 666,674 ----
case 'w':
wipeflag = TRUE;
break;
+ case 'x':
+ mdalg_flag = SHA1_ALGORITHM_BYTE;
+ break;
case 'z':
break;
/* '+' special option: does not require - */
diff -c pgp_262/rsaglue1.c pgp_sha1/rsaglue1.c
*** pgp_262/rsaglue1.c Fri Jun 21 23:31:17 1996
--- pgp_sha1/rsaglue1.c Sat Jun 22 07:22:07 1996
***************
*** 53,58 ****
--- 53,99 ----
static byte asn_array[] = { /* PKCS 01 block type 01 data */
0x30,0x20,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,
0x02,0x05,0x05,0x00,0x04,0x10 };
+ #ifdef SHA1
+ static byte sha1_asn_array[] = {
+ 0x30,0x21,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1a,
+ 0x05,0x00,0x04,0x14 };
+ /*
+ Taken from Internet Draft draft-ietf-cat-spkmgss-06,
+ "The Simple Public-Key GSS-API Mechanism (SPKM)", by
+ C. Adams, Bell-Northern Research, Jan. 19, 1996. See
+ also "Working Implementation Agreements for Open Systems
+ Interconnection Protocols: Part 12 - OS Security, Output
+ from the December 1994 Open Systems Environment
+ Implementors' Workshop (OIW)"
+
+ SHA1 OBJECT IDENTIFIER ::= {
+ iso(1) identified-organization(3) oiw(14) secsig(3)
+ algorithm(2) 26
+ }
+
+ ASN.1 encoding:
+ 0x30, / * Universal, Constructed, Sequence * /
+ 0x21, / * Length 33 (bytes following) * /
+ 0x30, / * Universal, Constructed, Sequence * /
+ 0x09, / * Length 9 * /
+ 0x06, / * Universal, Primitive, object-identifier * /
+ 0x05, / * Length 5 * /
+ 43, / * 43 = ISO(1)*40 + 3 * /
+ 14,
+ 3,
+ 2,
+ 26,
+ 0x05, / * Universal, Primitive, NULL * /
+ 0x00, / * Length 0 * /
+ 0x04, / * Universal, Primitive, Octet string * /
+ 0x14 / * Length 20 * /
+ / * 20 SHA.1 digest bytes go here * /
+
+ Cf. "A Layman's Guide to a Subset of ASN.1, BER, and DER --
+ An RSA Laboratories Technical Note" by Burton S. Kaliski Jr.
+ Revised November 1, 1993
+ */
+ #endif /* SHA1 */
/* This many bytes from the end, there's a zero byte */
#define ASN_ZERO_END 3