RE: Question about OffloadModExpo() Function

From: lelteto (lelteto_at_discussions.microsoft.com)
Date: 10/21/05

  • Next message: smveloso_at_gmail.com: "Extracting a timestamp from a PKCS#7"
    Date: Fri, 21 Oct 2005 09:32:01 -0700
    
    

    In debugger do you see at all your function called from CAPI? If not, than
    maybe dll signing is the issue. Capi won't load unsigned CSPs so it's
    possible that it won't load unsigned OffLoadModExpo dlls either. For testing
    try to load a KERNEL debugger (because than CAPI allow to load any unsigned
    dlls). If that solves your problem than it's the dll signature...

    Laszlo Elteto
    SafeNet, Inc.

    "JohnShen" wrote:

    > Hi everyone,
    >
    > MSDN tells that OffloadModExpo() function can offload modular exponentiation
    > from a CSP to a hardware accelerator.
    > But these days I've been nearly crazy about this function.
    >
    > I implement my own OffloadModExpo() function, which calling the ModExpo
    > implementation of RSAREF library. And building to a windows DLL.
    >
    > Directly calling my OffloadModExpo(), encrypting & decrypting runs OK.
    > But When use Crypto API, which will indirectly call OffloadModExpo(),
    > encrypting & decrypting fails.
    >
    > My implementation is like this:
    >
    > ///////////////
    > // .h
    > _declspec (dllexport)
    > BOOL /* WINAPI */ OffloadModExpo( // NOTICE: no 'WINAPI' here, if used can't
    > be called by Crypto API
    > BYTE *pbBase, // in
    > BYTE *pbExpo, // in
    > DWORD cbExpo, // in
    > BYTE *pbMod, // in
    > DWORD cbMod, // in
    > BYTE *pbResult, // out
    > void *pReserved, // reserved
    > DWORD dwFlags // in
    > );
    >
    > // .c
    > BOOL /* WINAPI */ OffloadModExpo(
    > BYTE *pbBase, // in
    > BYTE *pbExpo, // in
    > DWORD cbExpo, // in
    > BYTE *pbMod, // in
    > DWORD cbMod, // in
    > BYTE *pbResult, // out
    > void *pReserved, // reserved
    > DWORD dwFlags // in
    > )
    > {
    > // here is my implementation, calling RSAREF's NN_ModExp()
    > ...
    >
    > return TRUE;
    > }
    > /////////////////
    >
    > I use two test programs, one is encrypting & decrypting using RSA, another
    > is signing & verifying. Not calling my OffloadModExpo DLL, the two test
    > programs both run OK. But when using OffloadModExpo, error occurs. One error
    > come out when calling CryptDecrypt(), another is from CryptVerifySignature().
    > The error code are both: ERROR_INVALID_PARAMETER.
    >
    >
    > Then I write a program directly calling OffloadModExpo, not by Crypto API.
    > This time encrypting & decrypting using RSA is OK.
    > The test program is:
    > //////////////////////
    > #define BYTE_LEN 8
    > int main(int argc, char *argv[])
    > {
    > // all are little endian
    > BYTE enc[BYTE_LEN], decr[BYTE_LEN];
    > BYTE base[BYTE_LEN] = {0x11, 0x22, 0x33, 0x44, 0x55, 0xaa, 0x1}; // BASE
    > BYTE pub_expo[BYTE_LEN] = {0x01, 0, 0x01, 0}; // PUBLIC EXPO: 65537
    > BYTE mod[BYTE_LEN] = {0x29, 0x5D, 0x3C, 0x33, 0x6F, 0xD2, 0x2}; //MODULAR:
    > 2D26F333C5D29
    > BYTE priv_expo[BYTE_LEN] = {0xE1, 0xF1, 0x85, 0xC2, 0x7A, 0x63, 0x1}; //
    > PRIVATE EXPO: 1637AC285F1E1
    >
    >
    > printf("----text %x %x %x %x %x %x %x %x\n", base[0], base[1], base[2],
    > base[3], base[4], base[5], base[6], base[7]);
    >
    > OffloadModExpo(base, pub_expo, 3, mod, 7, enc, NULL, 0);
    > printf("----encr %x %x %x %x %x %x %x %x\n", enc[0], enc[1], enc[2],
    > enc[3], enc[4], enc[5], enc[6], enc[7]);
    >
    > OffloadModExpo(enc, priv_expo, 7, mod, 7, decr, NULL, 0);
    > printf("----decr %x %x %x %x %x %x %x %x\n", decr[0], decr[1], decr[2],
    > decr[3], decr[4], decr[5], decr[6], decr[7]);
    >
    > return 0;
    > }
    > ////////////////////
    >
    >
    > So I think my ModExpo implementation is not wrong.
    >
    > But what's the problem in?
    > I'm using VC++ 6.0, runing on Windows2k.
    >
    > If anyone could give me some information, I'll be very grateful.
    >
    > Thanks for your reading and your time.
    >
    > --
    > John
    >


  • Next message: smveloso_at_gmail.com: "Extracting a timestamp from a PKCS#7"

    Relevant Pages

    • Re: The Lib debate
      ... >>Calling Functions in a DLL is a comletely different thing. ... For shared object libraries you have to call ... I have been told that zip comes with a Lib only. ...
      (alt.lang.asm)
    • Re: using the CWegPage.dll
      ... It is using the WINAPI (_stdcall) calling ... > The source code for the DLL is on that page and is in this link to the zip ... >> change the calling convention to that which VB can handle. ... >>> The goal is to put an internet explorer web browswer on my form. ...
      (microsoft.public.vc.language)
    • Re: using the CWegPage.dll
      ... It is using the WINAPI (_stdcall) calling ... > The source code for the DLL is on that page and is in this link to the zip ... >> change the calling convention to that which VB can handle. ... >>> The goal is to put an internet explorer web browswer on my form. ...
      (microsoft.public.vb.winapi)
    • Re: moving data from one place to another in a text file
      ... """Calling DLL's under Windows ... the Pascal convention. ... used by a DLL just try one. ... that we're calling 'routine1' which expects a number as its first ...
      (comp.lang.cobol)
    • Re: How to debug load-time DLL exception?
      ... It is safe to call other functions in Kernel32.dll, ... Calling imported functions other than those located in Kernel32.dll may ... User, Shell, and COM functions can cause access violation errors, because ... here is the better stack trace:> ...
      (microsoft.public.win32.programmer.kernel)