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

  1. /****************************************************************************
  2. *                                                                            *
  3. *                                ASN.1 Object Types                             *
  4. *                        Copyright Peter Gutmann 1992-1996                    *
  5. *                                                                            *
  6. ****************************************************************************/
  7.  
  8. #ifndef _ASN1OBJS_DEFINED
  9.  
  10. #define _ASN1OBJS_DEFINED
  11.  
  12. #ifndef _STREAM_DEFINED
  13.   #if defined( INC_ALL ) ||  defined( INC_CHILD )
  14.     #include "stream.h"
  15.   #else
  16.     #include "keymgmt/stream.h"
  17.   #endif /* Compiler-specific includes */
  18. #endif /* _STREAM_DEFINED */
  19.  
  20. /* The default value for tagged types.  If this value is given the basic
  21.    type is used, otherwise the value is used as a context-specific tag */
  22.  
  23. #ifndef DEFAULT_TAG
  24.   #define DEFAULT_TAG            -1
  25. #endif /* DEFAULT_TAG */
  26.  
  27. /* The ASN.1 MessageDigest type.  The isSHA1 algorithm-specific information
  28.    field is a kludge which works for now since SHA-1 is the only algorithm
  29.    with optional parameters, but will need to be changed if the MD types are
  30.    ever extended to include keyed MAC's or similar algorithms */
  31.  
  32. typedef struct {
  33.     CRYPT_ALGO type;                /* Message digest algorithm */
  34.     BOOLEAN isSHA;                    /* Set to TRUE for SHA rather than SHA1
  35.                                        if type is CRYPT_ALGO_SHA */
  36.     BYTE data[ CRYPT_MAX_HASHSIZE ];/* Message digest */
  37.     int length;                        /* Length of MD data */
  38.     } MESSAGE_DIGEST;
  39.  
  40. /****************************************************************************
  41. *                                                                            *
  42. *                            ASN.1 Object Types Routines                        *
  43. *                                                                            *
  44. ****************************************************************************/
  45.  
  46. /* Routines for handling message digests */
  47.  
  48. int newMessageDigest( MESSAGE_DIGEST *messageDigest, const CRYPT_ALGO mdAlgo,
  49.                       const BYTE *md, const int length );
  50. int deleteMessageDigest( MESSAGE_DIGEST *messageDigest );
  51. int sizeofMessageDigest( const MESSAGE_DIGEST *messageDigest );
  52. int writeMessageDigest( STREAM *stream, const MESSAGE_DIGEST *messageDigest,
  53.                         const int tag );
  54. int _readMessageDigest( STREAM *stream, MESSAGE_DIGEST *messageDigest,
  55.                         const BOOLEAN readIdent );
  56.  
  57. #define readMessageDigest( stream, messageDigest ) \
  58.         _readMessageDigest( stream, messageDigest, TRUE )
  59. #define readMessageDigestData( stream, messageDigest ) \
  60.         _readMessageDigest( stream, messageDigest, FALSE )
  61.  
  62. /* Routines for reading and writing message digest information for creating
  63.    generating signatures.  These add a nonce to the MD record to make sure
  64.    we never end up signing the same information twice */
  65.  
  66. int sizeofMessageDigestInfo( const MESSAGE_DIGEST *messageDigest );
  67. int writeMessageDigestInfo( STREAM *stream, const MESSAGE_DIGEST *messageDigest );
  68. int readMessageDigestInfo( STREAM *stream, MESSAGE_DIGEST *messageDigest );
  69.  
  70. /* Routines for reading and writing session key information for
  71.    encapsulation inside a conventional or PKC-encrypted data block.  The
  72.    first function writes only the header information (but not the key
  73.    itself) for use in various locations which need to process encryption key
  74.    information formatted in a standardised manner) */
  75.  
  76. int writeKeyInfoHeader( STREAM *stream, const CRYPT_INFO *cryptInfo,
  77.                         int keyLength );
  78. int sizeofKeyInfo( const CRYPT_INFO *cryptInfo, const BOOLEAN addPadding );
  79. int writeKeyInfo( STREAM *stream, const CRYPT_INFO *cryptInfo,
  80.                   int *keyOffset, const BOOLEAN addPadding );
  81. int readKeyInfo( STREAM *stream, CRYPT_CONTEXT *cryptContext );
  82.  
  83. /* Routines for reading and writing encrypted and PKC-encrypted session keys */
  84.  
  85. int writeEncryptedKey( STREAM *stream, const CRYPT_INFO *cryptInfo,
  86.                        const CRYPT_INFO *sessionKeyInfo,
  87.                        const BYTE *buffer, const int length );
  88. int readEncryptedKey( STREAM *stream, const CRYPT_INFO *cryptInfo,
  89.                       CRYPT_OBJECT_INFO *cryptObjectInfo, int *keyInfoLength );
  90. int writePKCEncryptedKey( STREAM *stream, const CRYPT_INFO *pkcInfo,
  91.                           const CRYPT_INFO *sessionKeyInfo,
  92.                           const BYTE *buffer, const int length );
  93. int readPKCEncryptedKey( STREAM *stream, CRYPT_INFO *pkcInfo,
  94.                          CRYPT_CONTEXT *sessionKeyContext,
  95.                          CRYPT_OBJECT_INFO *cryptObjectInfo );
  96.  
  97. /* Routines for reading and writing signatures */
  98.  
  99. int writeSignature( STREAM *stream, const CRYPT_INFO *pkcInfo,
  100.                     const BYTE *buffer, const int length );
  101. int readSignature( STREAM *stream, CRYPT_INFO *pkcInfo );
  102.  
  103. /* Routines for writing data objects */
  104.  
  105. int writeBasicObject( STREAM *stream, const BOOLEAN isContinued,
  106.                       const long dataLength, const BOOLEAN isDataObject );
  107. int readBasicObject( STREAM *stream, BOOLEAN *isContinued,
  108.                      long *dataLength );
  109. int writeEncryptedObject( STREAM *stream, const BOOLEAN isContinued,
  110.                           const long dataLength,
  111.                           const CRYPT_INFO *cryptInfoPtr );
  112. int readEncryptedObject( STREAM *stream, BOOLEAN *isContinued,
  113.                          long *dataLength,
  114.                          CRYPT_OBJECT_INFO *cryptObjectInfo );
  115. int writeSignedObject( STREAM *stream, const BOOLEAN isContinued,
  116.                        const CRYPT_INFO *cryptInfoPtr, const long dataLength );
  117. int readSignedObject( STREAM *stream, BOOLEAN *isContinued,
  118.                       CRYPT_OBJECT_INFO *cryptObjectInfo );
  119.  
  120. /* Routines for getting information on cryptlib objects */
  121.  
  122. int readObjectWrapper( STREAM *stream, CRYPT_OBJECT_TYPE *objectType,
  123.                        long *length );
  124. int readCKObject( STREAM *stream, CRYPT_OBJECT_INFO *cryptObjectInfo );
  125. int readPKObject( STREAM *stream, BYTE *keyID, int *keyIDsize,
  126.                   CRYPT_ALGO *cryptAlgo );
  127. int readPKKeyObject( STREAM *stream, CRYPT_ALGO cryptAlgo,
  128.                      CRYPT_CONTEXT *cryptContext,
  129.                      CRYPT_OBJECT_INFO *cryptObjectInfo );
  130.  
  131. #endif /* _ASN1OBJS_DEFINED */
  132.