|
|
1.1 ! root 1: /* basslib.h - include file for BassOmatic encipherment functions. ! 2: ! 3: (c) Copyright 1988 by Philip Zimmermann. All rights reserved. ! 4: This software may not be copied without the written permission of ! 5: Philip Zimmermann. The author assumes no liability for damages ! 6: resulting from the use of this software, even if the damage results ! 7: from defects in this software. No warranty is expressed or implied. ! 8: */ ! 9: ! 10: /* Elaborate protection mechanisms to assure no redefinitions of types...*/ ! 11: #ifndef BOOLSTUFF ! 12: #define BOOLSTUFF ! 13: #ifndef TRUE ! 14: #define FALSE 0 ! 15: #define TRUE (!FALSE) ! 16: #endif /* if TRUE not already defined */ ! 17: typedef unsigned char boolean; /* values are TRUE or FALSE */ ! 18: #endif /* if BOOLSTUFF not already defined */ ! 19: #ifndef BYTESTUFF ! 20: #define BYTESTUFF ! 21: typedef unsigned char byte; /* values are 0-255 */ ! 22: typedef byte *byteptr; /* pointer to byte */ ! 23: typedef char *string; /* pointer to ASCII character string */ ! 24: #endif /* if BYTESTUFF not already defined */ ! 25: #ifndef WORDSTUFF ! 26: #define WORDSTUFF ! 27: typedef unsigned short word16; /* values are 0-65536 */ ! 28: typedef unsigned long word32; /* values are 0-4294967296 */ ! 29: #endif /* if WORDSTUFF not already defined */ ! 30: #ifndef min /* if min macro not already defined */ ! 31: #define min(a,b) ( (a)<(b) ? (a) : (b) ) ! 32: #define max(a,b) ( (a)>(b) ? (a) : (b) ) ! 33: #endif /* if min macro not already defined */ ! 34: ! 35: ! 36: #define MAXKEYLEN 254 /* max byte length of BassOmatic key */ ! 37: ! 38: #define NTABLES 8 /* number of random permutation vectors */ ! 39: ! 40: typedef struct { ! 41: boolean initialized; /* determines whether key context is defined */ ! 42: byteptr tlist[NTABLES]; /* list of permutation table pointers */ ! 43: byte bitmasks[NTABLES]; /* bitshredder bitmasks with 50% bits set */ ! 44: byteptr iv; /* CFB Initialization Vector used by initcfb and basscfb */ ! 45: boolean cfbuncryp; /* TRUE means decrypting (in CFB mode) */ ! 46: boolean uncryp; /* TRUE means decrypting (in ECB mode) */ ! 47: /* The following parameters are computed from the key control byte...*/ ! 48: char nrounds; /* specifies number of rounds thru BassOmatic */ ! 49: boolean hardrand; /* means regenerate tables with BassOmatic */ ! 50: boolean shred8ways; /* means use 8-way bit shredding */ ! 51: boolean rerand; /* means replenish tables with every block */ ! 52: byteptr lfsr; /* Linear Feedback Shift Register */ ! 53: byte rtail; /* rtail is an index into LFSR buffer */ ! 54: } KEYCONTEXT; ! 55: ! 56: ! 57: /* ! 58: ** initbassrand - initialize bassrand, BassOmatic random number generator. ! 59: ** Must close via closebass(). ! 60: */ ! 61: void initbassrand(byteptr key, short keylen, byteptr seed, short seedlen); ! 62: ! 63: ! 64: /* ! 65: ** bassrand - BassOmatic pseudo-random number generator. ! 66: */ ! 67: byte bassrand(void); ! 68: ! 69: ! 70: /* ! 71: ** bass_save - saves BassOmatic key context in context structure. ! 72: */ ! 73: void bass_save(KEYCONTEXT *context); ! 74: ! 75: ! 76: /* ! 77: ** bass_restore - restore BassOmatic key context from context structure. ! 78: */ ! 79: void bass_restore(KEYCONTEXT *context); ! 80: ! 81: ! 82: /* ! 83: ** closebass - end the current BassOmatic key context, freeing its buffers. ! 84: */ ! 85: void closebass(void); ! 86: ! 87: int initkey(byteptr key, short keylen, boolean decryp); ! 88: /* Sets up key schedule for BassOmatic. */ ! 89: ! 90: void bassomatic(byteptr in, byteptr out); ! 91: /* Encipher 1 block with the BassOmatic ECB mode. */ ! 92: ! 93: /* ! 94: ** initcfb - Initializes the BassOmatic key schedule tables via key, ! 95: ** and initializes the Cipher Feedback mode IV. ! 96: */ ! 97: int initcfb(byteptr iv0, byteptr key, short keylen, boolean decryp); ! 98: ! 99: ! 100: /* ! 101: ** basscfb - encipher 1 block with BassOmatic enciphering algorithm, ! 102: ** using Cipher Feedback (CFB) mode. ! 103: ** ! 104: ** Assumes initcfb has already been called. References global iv byteptr. ! 105: */ ! 106: void basscfb(byteptr buf, int count); ! 107: ! 108: ! 109: /* ! 110: ** fillbuf(dst,count,c) - fill byte buffer dst with byte c ! 111: */ ! 112: void fillbuf(register byteptr dst, register short count, register byte c); ! 113: ! 114: ! 115: /* ! 116: ** crc() - compute CRC-16 of buffer ! 117: */ ! 118: word16 crc(register byteptr buf, int count); ! 119: ! 120:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.