home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Security / Security.zip / idea-v11.zip / idea.h < prev    next >
C/C++ Source or Header  |  1993-11-17  |  5KB  |  80 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /* I N T E R N A T I O N A L  D A T A  E N C R Y P T I O N  A L G O R I T H M */
  4. /*                                                                            */
  5. /******************************************************************************/
  6. /* Author:       Richard De Moliner (demoliner@isi.ee.ethz.ch)                */
  7. /*               Signal and Information Processing Laboratory                 */
  8. /*               Swiss Federal Institute of Technology                        */
  9. /*               CH-8092 Zuerich, Switzerland                                 */
  10. /* Created:      April 23, 1992                                               */
  11. /* Changes:      November 16, 1993 (support of ANSI-C and C++)                */
  12. /* System:       SUN SPARCstation, SUN acc ANSI-C-Compiler, SUN-OS 4.1.3      */
  13. /******************************************************************************/
  14. /* Change this type definitions to the representations in your computer.      */
  15.  
  16. typedef long                     int32; /* signed 32-bit integer (or larger)  */
  17. typedef unsigned long          u_int32; /* unsigned 32-bit integer (or larger)*/
  18. typedef unsigned short         u_int16; /* unsigned 16-bit integer (or larger)*/
  19. typedef unsigned char           u_int8; /* unsigned 8-bit integer             */
  20.  
  21. #define ANSI_C                   /* If 'ANSI_C' is defined the preprocessed   */
  22.                                  /* source code is ANSI-C or C++ code, other- */
  23.                                  /* wise it is Kerninghan & Ritchie C code.   */
  24.  
  25. /******************************************************************************/
  26. /* It is possible to change this values.                                      */
  27.  
  28. #define Idea_nofRound                 8 /* number of rounds                   */
  29. #define Idea_userKeyLen               8 /* user key length (8 or larger)      */
  30.  
  31. /******************************************************************************/
  32. /* Do not change the lines below.                                             */
  33.  
  34. #define Idea_dataLen                       4 /* plain-/ciphertext block length*/
  35. #define Idea_keyLen    (Idea_nofRound * 6 + 4) /* en-/decryption key length   */
  36.  
  37. #define Idea_dataSize       (Idea_dataLen * 2) /* 8 bytes = 64 bits           */
  38. #define Idea_userKeySize (Idea_userKeyLen * 2) /* 16 bytes = 128 bits         */
  39. #define Idea_keySize         (Idea_keyLen * 2) /* 104 bytes = 832 bits        */
  40.  
  41. typedef u_int16 Idea_Data[Idea_dataLen];
  42. typedef u_int16 Idea_UserKey[Idea_userKeyLen];
  43. typedef u_int16 Idea_Key[Idea_keyLen];
  44.  
  45. /******************************************************************************/
  46. /* void Idea_Crypt (Idea_Data dataIn, Idea_Data dataOut, Idea_Key key)        */
  47. /*                                                                            */
  48. /* Encryption and decryption algorithm IDEA. Depending on the value of 'key'  */
  49. /* 'Idea_Crypt' either encrypts or decrypts 'dataIn'. The result is stored    */
  50. /* in 'dataOut'.                                                              */
  51. /* pre:  'dataIn'  contains the plain/cipher-text block.                      */
  52. /*       'key'     contains the encryption/decryption key.                    */
  53. /* post: 'dataOut' contains the cipher/plain-text block.                      */
  54. /*                                                                            */
  55. /******************************************************************************/
  56. /* void Idea_InvertKey (Idea_Key key, Idea_Key invKey)                        */
  57. /*                                                                            */
  58. /* Inverts a decryption/encrytion key to a encrytion/decryption key.          */
  59. /* pre:  'key'    contains the encryption/decryption key.                     */
  60. /* post: 'invKey' contains the decryption/encryption key.                     */
  61. /*                                                                            */
  62. /******************************************************************************/
  63. /* void Idea_ExpandUserKey (Idea_UserKey userKey, Idea_Key key)               */
  64. /*                                                                            */
  65. /* Expands a user key of 128 bits to a full encryption key                    */
  66. /* pre:  'userKey' contains the 128 bit user key                              */
  67. /* post: 'key'     contains the encryption key                                */
  68. /*                                                                            */
  69. /******************************************************************************/
  70.  
  71. #ifdef ANSI_C
  72.   void Idea_Crypt (Idea_Data dataIn, Idea_Data dataOut, Idea_Key key);
  73.   void Idea_InvertKey (Idea_Key key, Idea_Key invKey);
  74.   void Idea_ExpandUserKey (Idea_UserKey userKey, Idea_Key key);
  75. #else
  76.   Idea_Crypt ();
  77.   Idea_InvertKey ();
  78.   Idea_ExpandUserKey ();
  79. #endif
  80.