home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / crypl200.zip / KEYMGMT / PGP_IDEA.H < prev    next >
Text File  |  1996-09-22  |  2KB  |  74 lines

  1. /* This code was scanned from the book "PGP - Source Code and Internals",
  2.    Phil Zimmermann, MIT Press 1995, ISBN 0-262-24039-4, p.367-368 using
  3.    OmniPage Pro v6 and then cleaned up (removed page numbers, fixed a few
  4.    mis-recognised characters, etc) with an editor.  It was not exported
  5.    from the US in electronic form */
  6.  
  7. #ifndef IDEA_H
  8. #define IDEA_H
  9.  
  10. /*
  11.  *    idea.h - header file for idea.c
  12.  */
  13.  
  14. #if defined( INC_CHILD )
  15.   #include "../crypt.h"
  16. #else
  17.   #include "crypt.h"
  18. #endif /* Compiler-specific includes */
  19.  
  20. /* Convert the usual cryptlib defines to the PGP equivalent */
  21.  
  22. #define word32        LONG
  23. #define word16        WORD
  24. #define boolean        BOOLEAN
  25. #define byte        BYTE
  26. #define byteptr        BYTE *
  27.  
  28. #define IDEAKEYSIZE 16
  29. #define IDEABLOCKSIZE 8
  30.  
  31. #define IDEAROUNDS 8
  32. #define IDEAKEYLEN (6*IDEAROUNDS+4)
  33.  
  34. /*
  35.  * iv[] is used as a circular buffer.  bufleft is the number of
  36.  * bytes at the end which have to be filled in before we crank
  37.  * the block cipher again.  We do the block cipher operation
  38.  * lazily: bufleft may be 0.  When we need one more byte, we
  39.  * crank the block cipher and set bufleft to 7.
  40.  *
  41.  * oldcipher[] holds the previous 8 bytes of ciphertext, for use
  42.  * by ideaCfbSync() and Phil's, ahem, unique (not insecure, just
  43.  * unusual) way of doing CFB encryption.
  44.  */
  45. struct IdeaCfbContext {
  46.     byte oldcipher[8];
  47.     byte iv[8];
  48.     word16 key[IDEAKEYLEN];
  49.     int bufleft;
  50. };
  51.  
  52. struct IdeaRandContext {
  53.     byte outbuf[8];
  54.     word16 key[IDEAKEYLEN];
  55.     int bufleft;
  56.     byte internalbuf[8];
  57. };
  58.  
  59. void ideaCfbReinit(struct IdeaCfbContext *context, byte const *iv);
  60. void ideaCfbInit(struct IdeaCfbContext *context, byte const (key[16]));
  61. void ideaCfbSync(struct IdeaCfbContext *context);
  62. void ideaCfbDestroy(struct IdeaCfbContext *context);
  63. void ideaCfbEncrypt(struct IdeaCfbContext *context,
  64.             byte const *src, byte *dest, int count);
  65. void ideaCfbDecrypt(struct IdeaCfbContext *context,
  66.             byte const *src, byte *dest, int count);
  67. void ideaRandInit(struct IdeaRandContext *context, byte const (key[16]),
  68.           byte const (seed[8]));
  69. byte ideaRandByte(struct IdeaRandContext *c);
  70. void ideaRandWash(struct IdeaRandContext *c, struct IdeaCfbContext *cfb);
  71. void ideaRandState(struct IdeaRandContext *c, byte key[16], byte seed[8]);
  72.  
  73. #endif /* !IDEA_H */
  74.