|
|
1.1 ! root 1: /* C include file for RSA library I/O routines ! 2: ! 3: (c) Copyright 1986 by Philip Zimmermann. All rights reserved. ! 4: The author assumes no liability for damages resulting from the use ! 5: of this software, even if the damage results from defects in this ! 6: software. No warranty is expressed or implied. ! 7: ! 8: The external data representation for RSA messages and keys that ! 9: some of these library routines assume is outlined in a paper by ! 10: Philip Zimmermann, "A Proposed Standard Format for RSA Cryptosystems", ! 11: IEEE Computer, September 1986, Vol. 19 No. 9, pages 21-34. ! 12: Some revisions to this data format have occurred since the paper ! 13: was published. ! 14: ! 15: NOTE: This assumes previous inclusion of "rsalib.h" ! 16: */ ! 17: ! 18: /* #define XHIGHFIRST */ /* determines external integer byteorder for I/O */ ! 19: ! 20: /*--------------------- Byte ordering stuff -------------------*/ ! 21: #ifdef NEEDSWAP ! 22: #undef NEEDSWAP /* make sure NEEDSWAP is initially undefined */ ! 23: #endif ! 24: ! 25: #ifdef HIGHFIRST /* internal HIGHFIRST byte order */ ! 26: #ifndef XHIGHFIRST /* external LOWFIRST byte order */ ! 27: #define NEEDSWAP /* internal byteorder differs from external byteorder */ ! 28: #endif ! 29: #else /* internal LOWFIRST byte order */ ! 30: #ifdef XHIGHFIRST /* external HIGHFIRST byte order */ ! 31: #define NEEDSWAP /* internal byteorder differs from external byteorder */ ! 32: #endif ! 33: #endif /* internal LOWFIRST byte order */ ! 34: ! 35: #ifdef NEEDSWAP ! 36: #define hilo_swap(r1,numbytes) hiloswap(r1,numbytes) ! 37: #define convert_order(r) hiloswap(r,units2bytes(global_precision)) ! 38: #else ! 39: /* hilo_swap is nil because external representation is already the same */ ! 40: #define hilo_swap(r1,numbytes) /* nil statement */ ! 41: #define convert_order(r) /* nil statement */ ! 42: #endif /* not NEEDSWAP */ ! 43: ! 44: /*------------------ End byte ordering stuff -------------------*/ ! 45: ! 46: ! 47: #ifndef RSAIO /* not compiling RSAIO */ ! 48: /* Bug in DSP2101 C compiler -- no function protypes ! 49: allowed when compiling those same functions. */ ! 50: ! 51: #ifdef EMBEDDED ! 52: int putchar(int c); /* standard C library function from <stdio.h> */ ! 53: #endif /* EMBEDDED */ ! 54: ! 55: int string_length(char *s); ! 56: /* Returns string length */ ! 57: ! 58: int str2reg(unitptr reg,string digitstr); ! 59: /* Converts a possibly-signed digit string into a large binary number. ! 60: Returns assumed radix, derived from suffix 'h','o',b','.' */ ! 61: ! 62: void putstr(string s); /* Put out null-terminated ASCII string via putchar. */ ! 63: void puthexbyte(byte b); /* Put out byte in ASCII hex via putchar. */ ! 64: void puthexw16(word16 w); /* Put out 16-bit word in hex, high byte first. */ ! 65: ! 66: int display_in_base(string s,unitptr n,short radix); ! 67: /* Display n in any base, such as base 10. Returns number of digits. */ ! 68: ! 69: void mp_display(string s,unitptr r); ! 70: /* Display register r in hex, with prefix string s. */ ! 71: ! 72: word16 checksum(register byteptr buf, register word16 count); ! 73: /* Returns checksum of buffer. */ ! 74: ! 75: void fill0(byteptr buf,word16 bytecount); ! 76: /* Zero-fill the byte buffer. */ ! 77: ! 78: void cbc_xor(register unitptr dst, register unitptr src, word16 bytecount); ! 79: /* Performs the XOR necessary for RSA Cipher Block Chaining. */ ! 80: ! 81: void hiloswap(byteptr r1,short numbytes); ! 82: /* Reverses the order of bytes in an array of bytes. */ ! 83: ! 84: short mpi2reg(register unitptr r, register byteptr buf); ! 85: /* Converts to unit array from byte array with bit length prefix word. */ ! 86: ! 87: short reg2mpi(register byteptr buf, register unitptr r); ! 88: /* Converts from unit array to byte array with bit length prefix word. */ ! 89: ! 90: short preblock(unitptr outreg, byteptr inbuf, short bytecount, ! 91: unitptr modulus, boolean cksbit, byteptr randompad); ! 92: /* Converts plaintext block into form suitable for RSA encryption. */ ! 93: ! 94: short postunblock(byteptr outbuf, unitptr inreg, ! 95: unitptr modulus, boolean padded, boolean cksbit); ! 96: /* Converts a just-decrypted RSA block back ! 97: into unblocked plaintext form. */ ! 98: ! 99: #endif /* not compiling RSAIO */ ! 100: ! 101: /****************** end of RSA I/O library ************************/ ! 102:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.