Vendor custom mechanisms

2/27/2011 7:41:15 PM
Gravatar
Total Posts 2

Vendor custom mechanisms

C++ code:

#define MY_KEY_TYPE 0x80000001
#define MY_MECHANIZM 0x80000002

CK_MECHANISM MechanismData;
CK_KEY_TYPE KeyType = MY_KEY_TYPE;


CK_ATTRIBUTE template[] =
 {
  ...
  {CKA_KEY_TYPE, &KeyType, sizeof(CK_KEY_TYPE)},
  ....
 };


memset(&MechanismData, 0, sizeof(CK_MECHANISM));
MechanismData.mechanism = MY_MECHANIZM;
C_GenerateKey(hSession,&MechanismData,template,ulAttrCount,&hKey);
 

 

How to create a Cryptware.NCryptoki.Mechanizm.MY_MECHANIZM?

2/27/2011 8:15:57 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: Vendor custom mechanisms

It's very simple:
First of all you define your custom mechanism and key type as:

int myMechanismType = 0x80000002;
int myKeyType = 0x80000001;

Then create a template:

CryptokiCollection template = new CryptokiCollection();
template.Add(new ObjectAttribute(ObjectAttribute.CKA_KEY_TYPE, myKeyType));

Then create the mechanism:

Mechanism myMechanism = new Mechanism(myMechanismType, null);

and finally call GenereteKey

Key key = session.GenerateKey(myMechanism, template);

and that's all.

2/28/2011 4:32:37 AM
Gravatar
Total Posts 2

Vendor custom mechanisms

Ok, it works, thanks.
Another question.

typedef struct CK_MY_PARAMS {
   CK_V_TYPE vSrc;
   CK_BYTE vDst [8];
} CK_MY_PARAMS;
....

CK_MY_PARAMS MechanizmParameter;
.....
MechanismData.pParameter = & MechanizmParameter;

How to implement it in NCryptok?
 

2/28/2011 11:55:34 AM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: Vendor custom mechanisms

In the current version (1.4.5.7) of NCryptoki you should marshall the parameter as byte[] by yourself.
In your case you should prepare a byte[] containing in sequence the values of your struct.

For example if you have:

typedef struct CK_MY_PARAMS {
   CK_ULONG vSrc;
   CK_BYTE vDst [8];
} CK_MY_PARAMS;

with

vSrc = 0x10
vDst = {1,2,3,4,5,6,7,8}

you should create a byte[] as follows:

byte[] param = new byte[] {0x10, 0x00, 0x00, 0x00, 1,2,3,4,5,6,7,8}

 

Currently I'm working on the new version 1.4.6.x that should make this work for you. but I need some days more to finish development and testing.