--- pgp/src/crypto.c 2018/04/24 16:43:50 1.1.1.7 +++ pgp/src/crypto.c 2018/04/24 16:44:47 1.1.1.8 @@ -352,7 +352,7 @@ for this file.\n")); int version_byte_error(int val) { - if (val != VERSION_BYTE_OLD && val != VERSION_BYTE_KLUDGE) { + if (val != VERSION_BYTE_OLD && val != VERSION_BYTE_NEW) { fprintf (pgpout, LANG("\n\007Unsupported packet format - you need a newer version of PGP \ for this file.\n")); @@ -390,19 +390,21 @@ static int make_random_ideakey(byte key[ int skip) { int count; + struct IdeaCfbContext cfb; + byte buf[10]; + + ideaCfbInit(&cfb, md5buf); + burn(md5buf); - if (cryptRandOpen() < 0) { + if (cryptRandOpen(&cfb) < 0) { fprintf(pgpout,LANG("Preparing random session key...")); /* get some random key bits */ trueRandAccum((IDEAKEYSIZE+RAND_PREFIX_LENGTH)*8); - cryptRandCreate(); + cryptRandInit(&cfb); } - /* Mix in the MD5 of the current file */ - cryptRandWash(md5buf); - /* * Generate a good random IDEA key and initial vector. If we have * no random bytes, the trueRandByte() part will be useless @@ -419,7 +421,17 @@ static int make_random_ideakey(byte key[ * try to figure out what the key was by examining the entrails * of the random number generator state in randseed.bin. */ - cryptRandSave(key, key+IDEAKEYSIZE); + ideaCfbInit(&cfb, key); + memcpy(buf, key, 8); + buf[8] = buf[6]; + buf[9] = buf[7]; + ideaCfbEncrypt(&cfb, buf, buf, 10); + ideaCfbSync(&cfb); + + /* Save out the washed session key */ + cryptRandSave(&cfb); + + ideaCfbDestroy(&cfb); return IDEAKEYSIZE; } @@ -1065,6 +1077,8 @@ int compromise(byte *keyID, char *keyfil /* Copy the remainder from file f to file g */ copyfile (f, g, -1L); + + fclose(f); if (write_error(g)) { fclose(g); @@ -1189,6 +1203,7 @@ the\nabove user ID (y/N)? ")); assumption */ if ((g = fopen(keyfile,FOPRBIN)) == NULL) { + fclose(f); fprintf(pgpout, LANG("\n\007Can't open key ring file '%s'\n"),keyfile); return -1; @@ -1231,9 +1246,11 @@ the\nabove user ID (y/N)? ")); make_signature_certificate(certificate, &MD, K0_SIGNATURE_BYTE, e, d, p, q, u, n); - if (certificate_length < 0) + if (certificate_length < 0) { + fclose(f); return -1; /* error return from make_signature_certificate() */ + } } /* end of scope for some buffers */ @@ -1286,10 +1303,8 @@ int check_signaturefile(char *infile, ch char keyfile[MAX_PATH]; /* for getpublickey */ char sigfile[MAX_PATH]; /* .sig file if strip_signature */ char plainfile[MAX_PATH]; /* buffer for getstring() */ -#ifndef CANONICAL_TEXT char *tempFileName; /* Name for temporary uncanonicalized file */ FILE *tempFile; -#endif /* !CANONICAL_TEXT */ long fp; FILE *f; FILE *g; @@ -1653,7 +1668,6 @@ This may be caused either by corrupted d /* now compare computed MD with claimed MD */ /* Assume MSB external byte ordering */ if (!equal_buffers(digest, outbuf+outbufoffset, 16)) { -#ifndef CANONICAL_TEXT /* 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 @@ -1673,16 +1687,11 @@ This may be caused either by corrupted d if (verbose) fprintf(stderr, "signature checking failed, trying in canonical mode\n"); - if( ( tempFile = fopen( tempFileName, FOPWPBIN ) ) + make_canonical(outfile,tempFileName); + if( ( tempFile = fopen( tempFileName, FOPRBIN ) ) != NULL ) - { /* We've opened a temporary work file, - copy the text to it - with canonicalization */ - copyfile_to_canon( f, tempFile, -1L ); - - /* Move back to the start of the file - and recalculate the MD */ - rewind( tempFile ); + { + /* Now check the signature */ MDfile0_len(&MD, tempFile, -1L ); MD_addbuffer(&MD, mdextras, mdlensave, digest); @@ -1699,7 +1708,6 @@ This may be caused either by corrupted d goto goodsig; } } -#endif /* !CANONICAL_TEXT */ fprintf(pgpout, LANG("\007\nWARNING: Bad signature, doesn't match file contents!\007\n"));