CKM XOR BASE AND DATA,

3/15/2011 8:14:27 PM
Gravatar
Total Posts 8

CKM XOR BASE AND DATA,

Hi, i need a help, i trying to create a Master key that receive 3 key Values, for example, i insert the value of the first key, then i receive the value of the second key and for last i receive the value of the third key, so with this values i can make the Master key, i found the mechanism CKM_XOR_BASE_AND_DATA, but i don't know how to use it, i'm using C# right now,  if you can show me a example how to use it i will be grateful.

 

Tks

3/16/2011 12:34:10 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: CKM XOR BASE AND DATA,

In the current version you should work a little with unsafe segment.

First of all you should declare your param structure:

[StructLayout(LayoutKind.Sequential)]
public struct CK_KEY_DERIVATION_STRING_DATA
{
    public int len;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
    public byte[] data;
}

Note that I specified SizeCont=8, considering for example a DES key. If your key has different length you should specify the exact length.

Then, you should convert your structure to a byte array:

CK_KEY_DERIVATION_STRING_DATA param = new CK_KEY_DERIVATION_STRING_DATA();
param.data = new byte[]{0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
param.len = 8;

int len = Marshal.SizeOf(param);
IntPtr pointer = Marshal.AllocCoTaskMem(len);

Marshal.StructureToPtr(param, pointer, false);

unsafe
{
    byte* p = (byte*)pointer.ToPointer();
    byte[] b = new byte[len];
    for (int i = 0; i < len; i++)
    {
        b[i] = p[i];
    }

    Mechanism m = new Mechanism(Mechanism.CKM_XOR_BASE_AND_DATA, b);

}

5/15/2013 4:56:28 PM
Gravatar
Total Posts 5

Re: CKM XOR BASE AND DATA,

Hi Ugo,

I need the same that magodalespaul, do you have a complete working example? 

I need to create a master double des key that receive 3 components (16 bytes each one).

Thanks for your support,

Best Regards,