supriyav Posted January 21, 2006 Report Share Posted January 21, 2006 I’ve a C dll which I’m going to invoke in my vi. The C dll consists of 4 functions in that I’m going to use only 2 functions. AES_set_encrypt_key and AES_encrypt Prototypes of that 2 functions are int AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key); void AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key); userkey---pointer to an U8 array Key---- pointer to a structure AES_KEY Below is the structure: struct aes_key_st { #ifdef AES_LONG unsigned long rd_key[4 *(AES_MAXNR + 1)]; #else unsigned int rd_key[4 *(AES_MAXNR + 1)]; #endif int rounds; }; typedef struct aes_key_st AES_KEY; In the AES_set_encrypt_key function the first two arguments are input and the third is the output. The output (key) of this AES_set_encrypt_key function is going to used by the AES_encrypt_ function as input. In the AES_encrypt_ function the first and third arguments are input and the second is the output. I’ve created a vi set_encrypt.vi in which Parameter Type Data Type Format/Pass userkey Array Unsigned 8-bit Integer Array Data Pointer Bits Numeric signed 16-bit Integer Value Key Array Unsigned 32-bit Integer Array Data Pointer This vi actually crashes. I thought this is crashing since the Key is a pointer to a structure but I’ve configured that argument to Array Pointer. So I’ve created cluster2.vi using cluster for the third parameter and converting this to U32 Key Array Unsigned 32-bit Integer Array Data Pointer This also crashes. The calling Convention for the dll and for the Call Library function are the same. So I’ve created cluster3.vi using cluster for the third parameter and changed the type to Adapt To Type. Key Adapt to Type Pointers to handles But even this also crashes. The calling Convention for the dll and for the Call Library function is the same. Pls find the attached vis and dll. Pls guide me in this regard Thanks And Regards SupriyaV Download File:post-2648-1137846998.zip Download File:post-2648-1137847028.zip Quote Link to comment
Rolf Kalbermatter Posted January 21, 2006 Report Share Posted January 21, 2006 int AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key); void AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key); userkey---pointer to an U8 array Key---- pointer to a structure AES_KEY Below is the structure: struct aes_key_st { #ifdef AES_LONG unsigned long rd_key[4 *(AES_MAXNR + 1)]; #else unsigned int rd_key[4 *(AES_MAXNR + 1)]; #endif int rounds; }; typedef struct aes_key_st AES_KEY; In the AES_set_encrypt_key function the first two arguments are input and the third is the output. The output (key) of this AES_set_encrypt_key function is going to used by the AES_encrypt_ function as input. In the AES_encrypt_ function the first and third arguments are input and the second is the output. I?ve created a vi set_encrypt.vi in which Parameter Type Data Type Format/Pass userkey Array Unsigned 8-bit Integer Array Data Pointer Bits Numeric signed 16-bit Integer Value Key Array Unsigned 32-bit Integer Array Data Pointer This vi actually crashes. I thought this is crashing since the Key is a pointer to a structure but I?ve configured that argument to Array Pointer. So I?ve created cluster2.vi using cluster for the third parameter and converting this to U32 Key Array Unsigned 32-bit Integer Array Data Pointer This also crashes. The calling Convention for the dll and for the Call Library function are the same. So I?ve created cluster3.vi using cluster for the third parameter and changed the type to Adapt To Type. Key Adapt to Type Pointers to handles But even this also crashes. The calling Convention for the dll and for the Call Library function is the same. Pls find the attached vis and dll. Pls guide me in this regard Thanks And Regards SupriyaV First an int in modern Windows is always 32 bit and not 16 as you have assumed for the Bits parameter of the first function. This probably will neck you as well in the third parameter since you need to provide enough memory for the function to write into and if you assumed 16bit for the values in there your buffer is likely calculated to small. Second while you have this time properly documented the type of AES_KEY you still missed to provide important information. Without knowing the value of AES_MAXNR one can NOT calculate the size of the buffer you need to allocate in LabVIEW for this parameter. Basically the needed size is 4 * (AES_MAXNR + 1) + 4 bytes. A single byte to small can either crash your system immediately or after some time or when you try to close your LabVIEW app but most importantly could also corrupt some data that is vital to LabVIEW or your VI and when saved to disc might corrupt your VI to the point where you have to start over. My advice is still to go to www.visecurity.com and get the CryptoG toolkit that has a ready to use AES encryption and decryption routine out of the box. Rolf Kalbermatter Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.