#ifndef HEADER_MSCRYPTO_INT_H
#define HEADER_MSCRYPTO_INT_H
/* $Id: mscrypto_int.h,v 1.2 2005/01/30 18:32:17 rumen Exp $ */


#if defined(__MINGW32__)
#  include <wincrypt.h>
#endif


#ifdef  __cplusplus
extern "C" {
#endif


#define UNUSED(a)       (void)a


#define MSCRYPTO_ENCODING_TYPE  (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)


#ifndef ALG_SID_SSL3SHAMD5
#  define ALG_SID_SSL3SHAMD5              8
#endif

#ifndef CALG_SSL3_SHAMD5
#ifdef ALG_SID_SSL3SHAMD5
#  define CALG_SSL3_SHAMD5	(ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)
#endif
#endif

#ifndef CALG_RIPEMD160
#  define CALG_RIPEMD160	(ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_RIPEMD160)
#endif

#ifndef CALG_RIPEMD
#  define CALG_RIPEMD		(ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_RIPEMD)
#endif

#ifndef CALG_MDC2
#ifdef ALG_SID_MDC2
#  define CALG_MDC2		(ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MDC2)
#endif
#endif


struct MSCRYPTO_CTX_s {
    HCERTSTORE hStoreHandle;
};

typedef struct MSCRYPTO_CTX_s MSCRYPTO_CTX;


struct MSCRYPTO_KEYCTX_s {
    PCCERT_CONTEXT pCert;

    HCRYPTPROV hCryptProv;

    DWORD dwKeySpec;

    BOOL fCallerFreeProv;

    HCRYPTKEY hKey;
    HCRYPTKEY hPubKey;
};

typedef struct MSCRYPTO_KEYCTX_s MSCRYPTO_KEYCTX;


extern EVP_PKEY* mscrypto_load_privkey(
    ENGINE *e,
    const char *key_id,
    UI_METHOD *ui_method,
    void *callback_data
);


extern HCRYPTKEY mscrypto_get_hKey(const RSA *rsa, int pubkey);

extern HCRYPTHASH mscrypto_create_hash(
    HCRYPTPROV hProv,
    int dtype,
    const unsigned char *m,
    unsigned int m_length
);


extern HCRYPTKEY mscrypto_RSA_private_to_hKey(const RSA *key, HCRYPTPROV hProv);
extern HCRYPTKEY mscrypto_RSA_public_to_hKey(const RSA *key, HCRYPTPROV hProv);


/* RSA functions */
extern int
mscrypto_rsa_decrypt(
    int len,
    const unsigned char *from,
    unsigned char *to,
    RSA *rsa,
    int padding,
    int pubkey
);

extern int
mscrypto_rsa_encrypt(
    int len,
    const unsigned char *from,
    unsigned char *to,
    RSA *rsa,
    int padding,
    int pubkey
);

extern int/*bool*/
mscrypto_rsa_sign(
    int dtype,
    const unsigned char *m,
    unsigned int m_length,
    unsigned char *sigret,
    unsigned int *siglen,
    const RSA *rsa
);


extern int/*bool*/
mscrypto_rsa_verify(
    int dtype,
    const unsigned char *m,
    unsigned int m_length,
    unsigned char *sigbuf,
    unsigned int siglen,
    const RSA *rsa
);


/* other functions */
extern void* memcpy_rev(void *dest, const void *src, size_t n);

extern int/*bool*/ check_padding(int padding, const char* msg);

extern void MSCRYPTOw32err(const char *msg);

extern BIO *logstream;


/*TO REMOVE:*/
/* use OPENSSL malloc */
#define malloc OPENSSL_malloc
#define free OPENSSL_free


/*TO REMOVE^*/


#if 1
#  define MSCRYPTO_TRACE
#endif


#ifdef  __cplusplus
}
#endif


#endif /*ndef HEADER_MSCRYPTO_INT_H*/
