Category : C Source Code
Archive   : PGP20SRC.ZIP
Filename : MPIIO.H

 
Output of file : MPIIO.H contained in archive : PGP20SRC.ZIP
/* C include file for MPI library I/O routines

(c) Copyright 1986 by Philip Zimmermann. All rights reserved.
The author assumes no liability for damages resulting from the use
of this software, even if the damage results from defects in this
software. No warranty is expressed or implied.

These routines are for multiprecision arithmetic I/O functions for
number-theoretic cryptographic algorithms such as ElGamal,
Diffie-Hellman, Rabin, or factoring studies for large composite
numbers, as well as Rivest-Shamir-Adleman (RSA) public key
cryptography.

The external data representation for RSA messages and keys that
some of these library routines assume is outlined in a paper by
Philip Zimmermann, "A Proposed Standard Format for RSA Cryptosystems",
IEEE Computer, September 1986, Vol. 19 No. 9, pages 21-34.
Some revisions to this data format have occurred since the paper
was published.

NOTE: This assumes previous inclusion of "mpilib.h"
*/

/*--------------------- Byte ordering stuff -------------------*/

#ifdef NEEDSWAP
#undef NEEDSWAP /* make sure NEEDSWAP is initially undefined */
#endif

#ifdef XLOWFIRST
#ifdef HIGHFIRST
#define NEEDSWAP /* External/internal byteorder differs, need byte swap */
#endif
#endif

#ifndef XLOWFIRST
#ifndef HIGHFIRST
#define NEEDSWAP /* External/internal byteorder differs, need byte swap */
#endif
#endif


word16 fetch_word16(byte *buf);
/* Fetches a 16-bit word from where byte pointer is pointing.
buf points to external-format byteorder array. */

byte *put_word16(word16 w, byte *buf);
/* Puts a 16-bit word to where byte pointer is pointing, and
returns updated byte pointer.
buf points to external-format byteorder array. */

word32 fetch_word32(byte *buf);
/* Fetches a 32-bit word from where byte pointer is pointing.
buf points to external-format byteorder array. */

byte *put_word32(word32 w, byte *buf);
/* Puts a 32-bit word to where byte pointer is pointing, and
returns updated byte pointer.
buf points to external-format byteorder array. */

/* Note that convert_byteorder does nothing if internal native
byteorder is already the same as external byteorder. */

#ifdef NEEDSWAP /* External/internal byteorder differs, need byte swap */
#define convert_byteorder(buf,bytecount) hiloswap(buf,bytecount)
#define mp_convert_order(r) hiloswap(r,units2bytes(global_precision))
#else
#define convert_byteorder(buf,bytecount) /* nil statement */
#define mp_convert_order(r) /* nil statement */
#endif /* not NEEDSWAP */

/*------------------ End byte ordering stuff -------------------*/

#include

#define fill0(buffer,count) memset( buffer, 0, count )
/* Zero-fill the byte buffer. */

#ifdef EMBEDDED
int putchar(int c); /* standard C library function from */
#endif /* EMBEDDED */

int string_length(char *s);
/* Returns string length */

int str2reg(unitptr reg,string digitstr);
/* Converts a possibly-signed digit string into a large binary number.
Returns assumed radix, derived from suffix 'h','o',b','.' */

void putstr(string s); /* Put out null-terminated ASCII string via putchar. */
void puthexbyte(byte b); /* Put out byte in ASCII hex via putchar. */
void puthexw16(word16 w); /* Put out 16-bit word in hex, high byte first. */

int display_in_base(string s,unitptr n,short radix);
/* Display n in any base, such as base 10. Returns number of digits. */

void mp_display(string s,unitptr r);
/* Display register r in hex, with prefix string s. */

word16 checksum(register byteptr buf, register word16 count);
/* Returns checksum of buffer. */

void cbc_xor(register unitptr dst, register unitptr src, word16 bytecount);
/* Performs the XOR necessary for RSA Cipher Block Chaining. */

void hiloswap(byteptr r1,short numbytes);
/* Reverses the order of bytes in an array of bytes. */

short mpi2reg(register unitptr r, register byteptr buf);
/* Converts to unit array from byte array with bit length prefix word. */

short reg2mpi(register byteptr buf, register unitptr r);
/* Converts from unit array to byte array with bit length prefix word. */

short preblock(unitptr outreg, byteptr inbuf, short bytecount,
unitptr modulus, byteptr randompad);
/* Converts plaintext block into form suitable for RSA encryption. */

short postunblock(byteptr outbuf, unitptr inreg, unitptr modulus);
/* Converts a just-decrypted RSA block back
into unblocked plaintext form. */


/****************** end of MPI I/O library ************************/



  3 Responses to “Category : C Source Code
Archive   : PGP20SRC.ZIP
Filename : MPIIO.H

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/