Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
_Crypt - Creating A Hash Value
Message
From
24/11/2003 17:06:24
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00852090
Message ID:
00853090
Views:
18
If you want to use the CryptoAPI functions for creating a hash then _CRYPT.VCX::_CryptAPI will do pretty little for you. It will declare some of the DLL functions you need (but not all, CryptGetHashParam() is missing for example), and it will obtain a csp handle but the handle will be leaked because _CryptAPI fails to release it. Also, #including the WinCrypt.h header file pulls a whole lot macros into your code, including FoxPro.h.

In other words, if you only want to do a little hashing on the side and you don't need the performance provided by FoxCrypto.FLL then you'd be better off just coding your own class. Using _CRYPT.VCX would save only very few lines of code but it has its drawbacks.

I don't know how FoxCrypto.FLL has factored the calls but in my experience the incremental mode of operation (initialize context, hand several pieces to the hasher one after the other, then finalize and obtain hash) is only rarely needed in an environment like Fox, if at all. In many cases a simple function that takes a string and returns a hash is the most useful interface.

I managed to find an old benchmark and here are some figures for calling CryptoAPI functions (wrapped in a class similar to _CryptAPI) and an FLL function of mine that calls an optimized implementation of MD5:
>> 11/25/03 01:44:46 AM PROCEDURE SERIES_ D:\DEV\SUB\ZRBJ\TEST\BENCH_CRYPTOAPI_MD5_VS_MD5.FXP

Visual FoxPro 03.00.00.0711 für Windows 
# loops: 10000, data size: 1
   0.080 seconds,   0.12 MByte/s for MD5(m.cData)
   0.781 seconds,   0.01 MByte/s for o.Hash(@m.cData)
# loops: 10000, data size: 10
   0.080 seconds,   1.19 MByte/s for MD5(m.cData)
   0.772 seconds,   0.12 MByte/s for o.Hash(@m.cData)
# loops: 10000, data size: 100
   0.090 seconds,  10.60 MByte/s for MD5(m.cData)
   0.811 seconds,   1.18 MByte/s for o.Hash(@m.cData)
# loops: 10000, data size: 1000
   0.130 seconds,  73.36 MByte/s for MD5(m.cData)
   0.821 seconds,  11.62 MByte/s for o.Hash(@m.cData)
# loops: 10000, data size: 10000
   0.581 seconds, 164.14 MByte/s for MD5(m.cData)
   1.212 seconds,  78.69 MByte/s for o.Hash(@m.cData)
# loops: 10000, data size: 100000
   5.338 seconds, 178.66 MByte/s for MD5(m.cData)
   8.091 seconds, 117.87 MByte/s for o.Hash(@m.cData)

<< 11/25/03 01:45:05 AM PROCEDURE SERIES_ D:\DEV\SUB\ZRBJ\TEST\BENCH_CRYPTOAPI_MD5_VS_MD5.FXP
The numbers for newer Foxen are similar, though slightly slower. It is clear to see that the call overhead dominates for small strings (up to 1000 chars) and later the processing time of the MD5 code begins to show. For comparison: on this machine my MD5 code runs at about 275 MBytes/s, so the overhead of copying the data string (or flattening, or whatever) shows even for data size 100000.
Previous
Reply
Map
View

Click here to load this message in the networking platform