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

  1. /****************************************************************************
  2. *                                                                            *
  3. *                ASN.1 Key Management Structures and Prototypes                 *
  4. *                        Copyright Peter Gutmann 1992-1996                    *
  5. *                                                                            *
  6. ****************************************************************************/
  7.  
  8. #ifndef _ASN1KEYS_DEFINED
  9.  
  10. #define _ASN1KEYS_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. /* Some routines are currently unused because the cryptlib key file format
  21.    may not be used after all if any of the various standardisation efforts
  22.    for key collections ever comes to fruition.  Define the following to
  23.    include the extra routines (some of these clash with routines in other
  24.    modules which postdate their removal from asn1keys.c */
  25.  
  26. /* #define FULL_KEYMGMT */
  27.  
  28. /* The default value for tagged types.  If this value is given the basic
  29.    type is used, otherwise the value is used as a context-specific tag */
  30.  
  31. #ifndef DEFAULT_TAG
  32.   #define DEFAULT_TAG            -1
  33. #endif /* DEFAULT_TAG */
  34.  
  35. /* The key record for a key.  This serves as a general algorithm-independant
  36.    container to hold the information related to a key */
  37.  
  38. typedef struct KI {
  39.     /* Key components */
  40.     CRYPT_ALGO algorithm;        /* PKC algorithm */
  41.     void *keyInfo;                /* PKC key information */
  42.     int keyInfoSize;            /* PKC key information size */
  43.  
  44.     /* Key ID information */
  45.     BYTE keyID[ CRYPT_MAX_KEYIDSIZE ];    /* The key ID */
  46.     int keyIDsize;                /* The key ID size */
  47.  
  48.     /* General information */
  49.     time_t validFrom;            /* Valid from date */
  50.     time_t validTo;                /* Valid to date */
  51.     } PKC_INFO;
  52.  
  53. /****************************************************************************
  54. *                                                                            *
  55. *                            ASN.1 Crypto Types Routines                        *
  56. *                                                                            *
  57. ****************************************************************************/
  58.  
  59. /* Read and write keys in the X.509 SubjectPublicKeyInfo format */
  60.  
  61. int readPublicKey( STREAM *stream, PKC_INFO *pkcInfo );
  62. int writePublicKey( STREAM *stream, const PKC_INFO *pkcInfo );
  63.  
  64. #ifdef FULL_KEYMGMT
  65.  
  66. /* Routines for reading and writing key collection header records.  These are
  67.    somewhat different from the usual ASN.1 routines in that they only handle
  68.    input and output of the header values, as there's no need to do anything
  69.    else */
  70.  
  71. int sizeofHeader( const int noRecords, const int maxVersion );
  72. int writeHeader( STREAM *stream, const int noRecords, const int maxVersion, \
  73.                  const char *description, const int tag );
  74. int _readHeader( STREAM *stream, int *noRecords, int *maxVersion, \
  75.                  char *description, const BOOLEAN readIdent );
  76.  
  77. #define readHeader( stream, noRecords, maxVersion, description ) \
  78.     _readHeader( stream, noRecords, maxVersion, description, TRUE );
  79. #define readHeaderData( stream, noRecords, maxVersion, description ) \
  80.     _readHeader( stream, noRecords, maxVersion, description, FALSE );
  81.  
  82. /* Routines for reading and writing public and private keys.  These are
  83.    somewhat different from the usual ASN.1 routines in that they only handle
  84.    input and output of the keys.  Anything beyond that is up to the user */
  85.  
  86. int sizeofKey( PKC_INFO *pkcInfo );
  87. int writeKey( STREAM *stream, PKC_INFO *pkcInfo, const int tag );
  88. int _readKey( STREAM *stream, PKC_INFO *pkcInfo, const BOOLEAN readIdent,
  89.               const BOOLEAN isPublicKey );
  90.  
  91. #define readPublicKey( stream, pkcInfo ) \
  92.         _readKey( stream, pkcInfo, TRUE, TRUE )
  93. #define readPublicKeyData( stream, pkcInfo ) \
  94.         _readKey( stream, pkcInfo, FALSE, TRUE )
  95.  
  96. #define readPrivateKey( stream, rsaPrivateKey ) \
  97.         _readKey( stream, rsaPrivateKey, TRUE, FALSE )
  98. #define readPrivateKeyData( stream, rsaPrivateKey ) \
  99.         _readKey( stream, rsaPrivateKey, FALSE, FALSE )
  100.  
  101. /* Routines for reading and writing key record headers */
  102.  
  103. int writeKeyRecordHeader( STREAM *stream, int length, const int tag );
  104. int _readKeyRecordHeader( STREAM *stream, int *length, const BOOLEAN readIdent );
  105.  
  106. #define readKeyRecordHeader( stream, length ) \
  107.     _readKeyRecordHeader( stream, length, TRUE )
  108. #define readKeyRecordHeaderData( stream, length ) \
  109.     _readKeyRecordHeader( stream, length, FALSE )
  110.  
  111. /* Routines for reading and writing key information and certificate headers.
  112.    Since these are functionally identical (both read/write a SET tag) we use
  113.    the same code for both */
  114.  
  115. int writeKeyInfoHeader( STREAM *stream, int length, const int tag );
  116. int _readKeyInfoHeader( STREAM *stream, int *length, const BOOLEAN readIdent );
  117.  
  118. #define readKeyInfoHeader( stream, length ) \
  119.     _readKeyInfoHeader( stream, length, TRUE )
  120. #define readKeyInfoHeaderData( stream, length ) \
  121.     _readKeyInfoHeader( stream, length, FALSE )
  122. #define writeKeyCertHeader( stream, length, tag ) \
  123.     writeKeyInfoHeader( stream, length, tag )
  124. #define readKeyCertHeader( stream, length ) \
  125.     _readKeyInfoHeader( stream, length, TRUE )
  126. #define readKeyCertHeaderData( stream, length ) \
  127.     _readKeyInfoHeader( stream, length, FALSE )
  128.  
  129. #endif /* FULL_KEYMGMT */
  130.  
  131. #endif /* _ASN1KEYS_DEFINED */
  132.