Re: Using CryptoAPI to do a DH key exchange with OpenSSL



capi to capi works fine. But how can I tell what the difference is.
It's just a 128 byte array. And it is different on each client (as it
should be). I've already tried reversing the endian-ness. But still
it doesn't work. I'm at a loss for why this is so difficult. I must
be missing something. I've been able to get 3 different crypto libs to
inter-operate with each other fine. But so far, CryptoAPI has gotten
the better of me.

lelteto wrote:
Did you try first between two CAPI computers? Once that succeeds you can
start to figure out what's the data difference between CAPI and OpenSSL
export blob format.

Laszlo Elteto
SafeNet, Inc.

"edchan" wrote:

So I figured out the format. And the first 16 bytes is header info.
The remaining 128 bytes is the portion that should be sent to the other
party. But I still can't get it to work. Both sides seemingly agree
on a key (at least the CryptExportKey and CryptImportKey calls succeed
on the CryptoAPI side - and the corresponding DH calls in OpenSSL also
succeed). However, what's encrypted by one end is not properly
decrypted on the other.

There is the issue of endianness, but I tried converting from little to
big but still doesn't seem to work. Anybody have any ideas?

I should point out that the 128 bytes I get from openssl that is sent
to cryptoapi obviously doesn't include the blob header info. So I
added the same blob header info that I got from the blob that I got
when I called CryptoExportKey, to the 128 bytes from openssl and called
CryptImportKey on that. All the calls succeed, but as I said, the
encryption/decryption doesn't work properly. I encrypt with the key,
but when I decrypt on the other end, I get back garbage.

Ed


lelteto wrote:
PUBLICKEYBLOB is defined in the Platform SDK. However, I am not familiar with
the DH public key format in CAPI. (I can help with RSA public key format)
And right now it seems Microsoft screwed up its MSND Web pages - nothing can
be found :( hope they will fix it. soon...

The PUBLICKEYSTRUC is here:

typedef struct _PUBLICKEYSTRUC {
BYTE bType;
BYTE bVersion;
WORD reserved;
ALG_ID aiKeyAlg;
} BLOBHEADER, PUBLICKEYSTRUC;

typedef struct _PUBKEY {
DWORD magic;
DWORD bitlen;
} DHPUBKEY;

magic
This must always be set to DH1 (0x31484400) when used for public-key BLOBs

typedef struct _PUBKEYVER3 {
DWORD magic;
DWORD bitlenP;
DWORD bitlenQ;
DWORD bitlenJ;
DSSSEED DSSSeed;
} DHPUBKEY_VER3;

magic
This must always be set to 0x33484400, the ASCII encoding of "DH3".

Maybe this helps...

Laszlo Elteto
SafeNet, Inc.

"edchan" wrote:

Endianness aside, what about the blob header, etc.? After calling
CryptExportKey() I get 144 bytes. I'm expecting 128. I tried
discarding the first 16 bytes. But what do I do with the 128 bytes
returned from the other side. Calling CryptImportKey likely won't work
because it is expecting a blob in MS CryptoAPI format (whatever that
is). I saw some docs regarding PUBLICKEYBLOB, but not sure what to
enter for the headers. Then I started wondering how WinInet is able to
do a DH key exchange when doing an SSL connection to an OpenSSL server,
for example.

Ed

lelteto wrote:
The public key (blob) format in MS CAPI is completely different than in other
crypt libs. Moreover ENDIANNESS is different, too: CAPI uses little endian
byte order, other libs (Cryptoki, OpenSSL, etc) are using the big endian =
network byte order. You would need to convert between the two formats.

Laszlo Elteto
SafeNet, Inc.

"edchan" wrote:

Hi there,

I'm trying to perform a DH key exchange between 2 parties. I can do it
if both ends are using the same crypto lib. But if one end is MS
CryptoAPI and the other is say OpenSSL, then I have problems. OpenSSL
<-> RSA BSAFE is ok, as is any other combination of OpenSSL, RSA,
Certicom. It's only CryptoAPI that I am having problems. The problem
seems to lie in that when I export the public key using
CryptExportKey(), i am getting a PUBLICKEYBLOB of 16 bytes more than
the other end's public key. I figured this 16 bytes might be some blob
header, so I strip that out. But when I get the 128 byte public key
from the end and try to import that, I think the CryptImportKey is
expecting a blob with a header? Is that correct? So I tried setting
the same header from my public key blob to see what would happen. Of
course that didn't work.

Can anybody give me some info or point me to some docs about how to get
CryptoAPI to play nice with other libs for DH? Since the 3 other libs
I've tried seem to be inter-operable, I assume there is something
non-standard that CryptoAPI is doing? Or there is an additional step I
am missing?

Thanks,
Ed







.



Relevant Pages

  • Re: Using CryptoAPI to do a DH key exchange with OpenSSL
    ... a struct for the OpenSSL DH key blob format? ... But so far, CryptoAPI has gotten ... start to figure out what's the data difference between CAPI and OpenSSL ... the DH public key format in CAPI. ...
    (microsoft.public.platformsdk.security)
  • Re: Using CryptoAPI to do a DH key exchange with OpenSSL
    ... a struct for the OpenSSL DH key blob format? ... But so far, CryptoAPI has gotten ... start to figure out what's the data difference between CAPI and OpenSSL ... the DH public key format in CAPI. ...
    (microsoft.public.platformsdk.security)
  • Re: Using CryptoAPI to do a DH key exchange with OpenSSL
    ... start to figure out what's the data difference between CAPI and OpenSSL ... to cryptoapi obviously doesn't include the blob header info. So I ... the DH public key format in CAPI. ...
    (microsoft.public.platformsdk.security)
  • Re: Using CryptoAPI to do a DH key exchange with OpenSSL
    ... I was just trying to see what's available in the DH key blob and in the DH ... That's all in the wincrypt.h header files. ... Maybe somebody from MS can give more info on the DH public key. ... But so far, CryptoAPI has gotten ...
    (microsoft.public.platformsdk.security)
  • Re: Using CryptoAPI to do a DH key exchange with OpenSSL
    ... Can you tell me what MS CryptoAPI provider you are using, ... I am trying to pass the public key to the other party so the other ... a struct for the OpenSSL DH key blob format? ... start to figure out what's the data difference between CAPI and OpenSSL ...
    (microsoft.public.platformsdk.security)