⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d3des.h

📁 3des 算法 Richard Outerbridge 本人写的一个不错的版本
💻 H
字号:
/*This archive contains the following files, besides this one -        d3des.c - THINK C* source for DES        d3des.h - Header file for d3des.c        enkeys3.c - Simple UNIX-like DES calculatorPlease make sure that you read and understand the "OBLIGATORY IMPORTANTDISCLAIMERS, WARNINGS AND RESTRICTIONS" section at the end of this file.  D3DES.C, D3DES.H, D3DES68.C & ENKEYS3.C=======================================These files are useful for playing around with DES cryptography,especially if you neither need or love assembler."d3des" is an implementation of DES written in portable 'C'.  Whileoriginally written on the Macintosh, it has been run correctly, withoutchange, on the PC and on UNIX platforms.  It only assumes that "long"integers are at least 32 bits wide.  The reason it's called "d3"des is that it actually performs five (5)different forms of the DES: (1) Single key, single block; (2) Doublekey, single block; (3) Double key, double block; (4) Triple key, singleblock; and (5) Triple key, double block.  Some auxilliary support codeis included, for hashing keys out of passwords for instance."enkeys3" is a UNIX-like desktop DES ECB-mode calculator.  With somechanges to enkeys3.c (the header files to be #include'd and the end-of-linefiltering) the package compiles and runs (correctly) using Symantec THINK Con the Macintosh and Microsoft Quick C on the IBM PC.  It should also run(more or less correctly) on any version of UNIX.OBLIGATORY IMPORTANT DISCLAIMERS, WARNINGS AND RESTRICTIONS===========================================================[1] This software is provided "as is" without warranty of fitness for use orsuitability for any purpose, express or implied.  Use at your own risk or notat all.  It does, however, "do" DES.[2] This software (comprised of the files listed above) is "freeware".  It maybe freely used and distributed (but see [3], below).  The copyright in thissoftware has not been abandoned, and is hereby asserted.[3] ENCRYPTION SOFTWARE MAY ONLY BE EXPORTED FROM NORTH AMERICA UNDER THEAUTHORITY OF A VALID EXPORT LICENSE OR PERMIT.  CONSULT THE APPROPRIATEBRANCH(ES) OF YOUR FEDERAL GOVERNMENT FOR MORE INFORMATION.        Try asking them >why<, for starters.---------------------------------------------------------------Richard Outerbridge                GEnie: OUTER50 Walmer Road, #111        CompuServe: [71755,204]Toronto, Ontario                (416) 961-4757Canada   M5R 2X4                9210.06 / October 6th, 1992---------------------------------------------------------------This release of the code is dedicated to the memory of Michael AllenRidler (1954-1989), Visual Artist, exemplary friend, victim of AIDS.*//* d3des.h -** Headers and defines for d3des.c* Graven Imagery, 1992.** THIS SOFTWARE PLACED IN THE PUBLIC DOMAIN BY THE AUTHOUR* 920825 19:42 EDST** Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge*        (GEnie : OUTER; CIS : [71755,204])*/#define D2_DES                /* include double-length support */#define D3_DES                /* include triple-length support */#ifdef D3_DES#ifndef D2_DES#define D2_DES                /* D2_DES is needed for D3_DES */#endif#endif       #define EN0        0                /* MODE == encrypt */#define DE1        1                /* MODE == decrypt *//* Useful on 68000-ish machines, but NOT USED here. */typedef union {        unsigned long blok[2];        unsigned short word[4];        unsigned char byte[8];        } M68K;typedef union {        unsigned long dblok[4];        unsigned short dword[8];        unsigned char dbyte[16];        } M68K2;extern void deskey(unsigned char *, short);/*                      hexkey[8]     MODE* Sets the internal key register according to the hexadecimal* key contained in the 8 bytes of hexkey, according to the DES,* for encryption or decryption according to MODE.*/extern void usekey(unsigned long *);/*                    cookedkey[32]* Loads the internal key register with the data in cookedkey.*/extern void cpkey(unsigned long *);/*                   cookedkey[32]* Copies the contents of the internal key register into the storage* located at &cookedkey[0].*/extern void des(unsigned char *, unsigned char *);/*                    from[8]              to[8]* Encrypts/Decrypts (according to the key currently loaded in the* internal key register) one block of eight bytes at address 'from'* into the block at address 'to'.  They can be the same.*/#ifdef D2_DES#define desDkey(a,b)        des2key((a),(b))extern void des2key(unsigned char *, short);/*                      hexkey[16]     MODE* Sets the internal key registerS according to the hexadecimal* keyS contained in the 16 bytes of hexkey, according to the DES,* for DOUBLE encryption or decryption according to MODE.* NOTE: this clobbers all three key registers!*/extern void Ddes(unsigned char *, unsigned char *);/*                    from[8]              to[8]* Encrypts/Decrypts (according to the keyS currently loaded in the* internal key registerS) one block of eight bytes at address 'from'* into the block at address 'to'.  They can be the same.*/extern void D2des(unsigned char *, unsigned char *);/*                    from[16]              to[16]* Encrypts/Decrypts (according to the keyS currently loaded in the* internal key registerS) one block of SIXTEEN bytes at address 'from'* into the block at address 'to'.  They can be the same.*/extern void makekey(char *, unsigned char *);/*                *password,        single-length key[8]* With a double-length default key, this routine hashes a NULL-terminated* string into an eight-byte random-looking key, suitable for use with the* deskey() routine.*/#define makeDkey(a,b)        make2key((a),(b))extern void make2key(char *, unsigned char *);/*                *password,        double-length key[16]* With a double-length default key, this routine hashes a NULL-terminated* string into a sixteen-byte random-looking key, suitable for use with the* des2key() routine.*/#ifndef D3_DES        /* D2_DES only */#define useDkey(a)        use2key((a))#define cpDkey(a)        cp2key((a))extern void use2key(unsigned long *);/*                    cookedkey[64]* Loads the internal key registerS with the data in cookedkey.* NOTE: this clobbers all three key registers!*/extern void cp2key(unsigned long *);/*                   cookedkey[64]* Copies the contents of the internal key registerS into the storage* located at &cookedkey[0].*/#else        /* D3_DES too */#define useDkey(a)        use3key((a))#define cpDkey(a)        cp3key((a))extern void des3key(unsigned char *, short);/*                      hexkey[24]     MODE* Sets the internal key registerS according to the hexadecimal* keyS contained in the 24 bytes of hexkey, according to the DES,* for DOUBLE encryption or decryption according to MODE.*/extern void use3key(unsigned long *);/*                    cookedkey[96]* Loads the 3 internal key registerS with the data in cookedkey.*/extern void cp3key(unsigned long *);/*                   cookedkey[96]* Copies the contents of the 3 internal key registerS into the storage* located at &cookedkey[0].*/extern void make3key(char *, unsigned char *);/*                *password,        triple-length key[24]* With a triple-length default key, this routine hashes a NULL-terminated* string into a twenty-four-byte random-looking key, suitable for use with* the des3key() routine.*/#endif        /* D3_DES */#endif        /* D2_DES *//* d3des.h V5.09 rwo 9208.04 15:06 Graven Imagery********************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -