[Mono-list] to wrapp mono with C

pa-alran at tele2.fr pa-alran at tele2.fr
Thu Sep 29 08:39:19 EDT 2005


hello, congratulation for Mono.

I'm french, so my english is very poor... sorry.
I want to use the hash function of openssl with my code in 
mono.

The file .h in C is :

#define SHA_BLOCK	16

typedef struct SHAstate_st
{
	unsigned long h0,h1,h2,h3,h4;
	unsigned long Nl,Nh;
	unsigned long data[SHA_LBLOCK];
	int num;
} SHA_CTX;

void SHA1_Init(SHA_CTX *c);

void SHA1_Update(SHA_CTX *c, unsigned char *data, unsigned 
long len);

void SHA1_Final(unsigned char *md, SHA_CTX *c);

---------------------------

I have write my wrapper like this :

protected int SHA_BLOCK = 16;

[StructLayout(LayoutKind.Sequential, 
CharSet=CharSet.Ansi)]
public struct SHA_CTX
{
     public uint h0;
     public uint h1;
     public uint h2;
     public uint h3;
     public uint h4;
     public uint Nl;
     public uint Nh;
     [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
     public uint [] data ;
     public int num;
} 
		
//chargement de la dll SHA1.so "C"
[DllImport("SHA1")]
public static extern void SHA1_Init(ref SHA_CTX c);
//public static extern void SHA1_Init(IntPtr c);

//chargement de la dll SHA1.dll "C"
[DllImport("SHA1")]
public static extern void SHA1_Update(ref SHA_CTX c, ref 
byte [] data, uint len);
//public static extern void SHA1_Update(ref SHA_CTX c, 
IntPtr data, uint len);
//public static extern void SHA1_Update(ref SHA_CTX c, 
byte * data, uint len);
		
//chargement de la dll SHA1.dll "C"
[DllImport("SHA1")]
public static extern void  SHA1_Final(ref byte [] md, ref 
SHA_CTX c);
//public static extern void  SHA1_Final(IntPtr md, ref 
SHA_CTX c);
//public static extern void  SHA1_Final(byte* md, ref 
SHA_CTX c);
		
-----------------------

With the structure, i can acces to the array data ?

And i don't know how to wrapp " unsigned char * " ? my 
solutions don't work.


Can you help me please ?

Thank you very much.

Pierre alain.


More information about the Mono-list mailing list