diff options
author | Stef Walter <stef@memberwebs.com> | 2008-12-09 03:47:01 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2008-12-09 03:47:01 +0000 |
commit | 94c63a237d77654bab2ea34146b06fd4b0acfc99 (patch) | |
tree | e726b7d285dd9f188ba92830355f64b8cba644ab /ckcapi-key.c | |
parent | a71df0e849b4e286f29ae6e26973961d3412cd83 (diff) |
Use better and faster hashing of objects.
Diffstat (limited to 'ckcapi-key.c')
-rw-r--r-- | ckcapi-key.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/ckcapi-key.c b/ckcapi-key.c index 7618e1e..5cf60ba 100644 --- a/ckcapi-key.c +++ b/ckcapi-key.c @@ -80,10 +80,7 @@ typedef struct _KeyObject /* The raw key identifier */ CRYPT_HASH_BLOB key_identifier; - - /* Together these form the unique key. Must be contiguous */ CK_OBJECT_CLASS object_class; - BYTE tail_data[1]; } KeyObject; @@ -733,6 +730,24 @@ key_load_data(CkCapiSession* sess, CkCapiObject* obj, CkCapiObjectData** objdata return CKR_OK; } +static unsigned int +key_hash_func(CkCapiObject* obj) +{ + KeyObject* kobj = (KeyObject*)obj; + return ckcapi_hash_data(kobj->key_identifier.pbData, kobj->key_identifier.cbData) ^ + ckcapi_hash_integer((int)kobj->object_class); +} + +static int +key_equal_func(CkCapiObject* a, CkCapiObject* b) +{ + KeyObject* ka = (KeyObject*)a; + KeyObject* kb = (KeyObject*)b; + return ka->object_class == kb->object_class && + ka->key_identifier.cbData == kb->key_identifier.cbData && + memcmp(ka->key_identifier.pbData, kb->key_identifier.pbData, ka->key_identifier.cbData) == 0; +} + static void key_object_release(void* data) { @@ -743,6 +758,8 @@ key_object_release(void* data) static const CkCapiObjectVtable key_object_vtable = { key_load_data, + key_hash_func, + key_equal_func, key_object_release, }; @@ -763,12 +780,9 @@ register_key_object(CkCapiSession* sess, CK_OBJECT_CLASS cls, kobj->obj.id = 0; kobj->obj.obj_funcs = &key_object_vtable; - kobj->obj.unique_key = UNIQUE_KEY_AT(kobj, object_class); - kobj->obj.unique_len = UNIQUE_KEY_VAR_LEN(kobj, object_class, tail_data, - key_identifier->cbData); kobj->object_class = cls; - kobj->key_identifier.pbData = kobj->tail_data; + kobj->key_identifier.pbData = (BYTE*)(kobj + 1); kobj->key_identifier.cbData = key_identifier->cbData; memcpy(kobj->key_identifier.pbData, key_identifier->pbData, kobj->key_identifier.cbData); |