/*
 *-----------------------------------------------------------------------------
 *   Copyright 1994 DeltaLink bv
 *-----------------------------------------------------------------------------
 * Module Name : encrypt.h
 * Version/Rev : 1.00
 * Author/Date : Leon Westervoort
 * Description : Encryption Header File.
 *
 *-----------------------------------------------------------------------------
 */

#ifndef ENCRYPT_INCLUDED
#define ENCRYPT_INCLUDED

#ifdef WIN
#define DL_ENTRY		_pascal
#else
#define DL_ENTRY
#endif

#define MAX_MODULE_NAME     8
#define KEY_LEN             4
#define SERIAL_LEN          8

/*
 * the length of the readable encrypted string is:
 *
 */
#define CRYPTREC_LEN         4


/* error codes returned by the PRO_TECT library */

#define  OK                  0          /* operation executed OK */
#define  FAULT              -1          /* will be returned if access denied to key */

#define  E_MODE             -2          /* wrong mode opening file */
#define  E_MEMORY           -3          /* not enough system memory */
#define  E_PLATFORM         -4          /* key for other platform */
#define  E_CORRUPTED        -5          /* the key file is corrupted */
#define  E_FILE             -6          /* cannot open file */

/* modes for opening the option file */

#define OP_CREATE           0    
#define OP_APPEND           1
#define OP_READ             2

/*
 * module options
 */
#define OPT_LITE            1             /* running mode lite */ 

/*
 * information of a module
 */

typedef struct _op_module {

	/* parameters which will be passed by the user */

  char    name[ MAX_MODULE_NAME +2];          /* name of the module */ 
  char    id;                                 /* unique module id */
  char    version;                            /* major version number of the module */
  char    options;                            /* options of the module */

	/* parameters which will be returned by the protection functions */

  char   dl_serial[ SERIAL_LEN];              /* protection serial number */
  char   dl_version[ 2];                      /* version of the module in ASCII*/

} OP_MODULE;

/*
 *  module before the encription, the length of this structure must always be even
 */

typedef struct _to_enctrypt {

  char   version[ 2];                        /* version of the module in ASCII*/
  char   serial[ SERIAL_LEN];                /* serial number */
  char   id[ 2];                             /* unique module id in ASCII */
  char   options[ 2];                        /* options for the module */

} TO_ENCRYPT;

#define CRYPT_LEN            sizeof( TO_ENCRYPT)

/*
 *  part of the encription string in the option file
 */

typedef struct _op_cryptrec {

  char    space;                              /* one space */
  char    data[ CRYPTREC_LEN];

} CRYPTREC;

/*
 *  module record in option file
 */

typedef struct _op_modrec {

  char         name[ MAX_MODULE_NAME];                  /* name of the module */

  CRYPTREC     key[ (KEY_LEN * 2) /CRYPTREC_LEN];       /* number of key records */
  CRYPTREC     crypt[ (CRYPT_LEN * 2) /CRYPTREC_LEN];   /* number of encrypted records */

#ifdef UNIX
  char         lf;                                      /* linefeed */
#else
  short        crlf;                                    /* carriage return and linefeed */
#endif

} OP_MODREC;


/*
 * programming routines for generating option files and option entries
 */

int DL_ENTRY init_option	 ( char *, short, char *);
int DL_ENTRY add_option 	 ( OP_MODULE *);
int DL_ENTRY calc_option	 ( OP_MODULE *, OP_MODREC *, char *);
int DL_ENTRY delete_option ( OP_MODULE *);
int DL_ENTRY clear_option  ( void);
int DL_ENTRY search_option ( OP_MODULE *);
int DL_ENTRY exit_option	 ( void);


/*
 * initialization routine for DeltaLink modules
 */
int         pro_optfile( OP_MODULE *);

/*
 *-----------------------------------------------------------------------------
 *  END OF FILE
 *-----------------------------------------------------------------------------
 */
#endif
