How do i do hardware protected HMAC'ing from dotnet?

How do i do hardware protected HMAC'ing from dotnet?

Post by Helge Jens » Sun, 20 May 2007 03:04:33


I have a hardware token that supports HMAC'ing with a key generated and
protected on that token.

For RSA operations I can use keys in the box by stuff like:

CspParameters cp = new CspParameters(
PROV_RSA_FULL, provider, container);
cp.Flags = CspProviderFlags.UseExistingKey;
RSACryptoServiceProvider csp = new RSACryptoServiceProvider(cp);
byte[] data = { 0, 1, 2, 3, 4, 5 };
byte[] x = csp.SignData(data, new SHA1());
Assert(csp.VerifyData(data, new SHA1(), x));
data[0] = (byte)~data[0];
Assert(!csp.VerifyData(data, new SHA1(), x));

The box supports HMAC'ing with either (3)DES or AES (Rinjdael) keys.
How do I go about doing something similar with HMAC'ing, while still
leaving the key *only* in the box.

The DESCryptoServiceProvider and TripleDESCryptoServiceProvider accepts
no parameters which would allow access to hardware tokens and there is
no RinjdaelCryptoServiceProvider.

--
Helge
 
 
 

How do i do hardware protected HMAC'ing from dotnet?

Post by Helge Jens » Thu, 24 May 2007 21:12:30

Helge Jensen skrev:


For the record: I ended up doing P/Invoke to CAPI.

I can use CryptGenKey to generate a key in the box, letting
CRYPT_ARCHIVABLE protect the key from export expect while i still hold
the original handle returned by CryptGenKey.

Next i can export the key in an OPAQUEBLOB, and use the CryptImportKey,
and CryptCreateHash/... to implement KeyedHashAlgoritm.

The .NET crypto-design borrows some concepts from CAPI, and is clearly
implemented in CAPI-terms (dwType,...) but stops oddly short, for
example the RSACryptoServiceProvider does not expose GenKey, ImportKey,
ExportKey and friends as I would expect.

--
Helge