]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Add reference counts to key identifiers, so that they can have multiple owners
authorGreg Hudson <ghudson@mit.edu>
Sun, 18 Oct 2009 17:17:42 +0000 (17:17 +0000)
committerGreg Hudson <ghudson@mit.edu>
Sun, 18 Oct 2009 17:17:42 +0000 (17:17 +0000)
without having to create multiple underlying PKCS#11 objects (or similar).

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/enc-perf@22918 dc483132-0cff-0310-8789-dd5450dbe970

src/include/k5-int.h
src/include/krb5/krb5.hin
src/lib/crypto/krb/key.c

index 22824c156c5b42041ad938840590a80e103b47e7..34ce10d92182eda6622dcc897cb62b1e22b2b373 100644 (file)
@@ -638,6 +638,7 @@ krb5int_locate_server (krb5_context, const krb5_data *realm,
 /* Internal structure of an opaque key identifier */
 struct krb5_key_st {
     krb5_keyblock keyblock;
+    int refcount;
 };
 
 /* new encryption provider api */
index 271386f6a8c1986f56580292c4e414b130668afa..b5294a458d40ebff719998a530fdf338f1b1a3fa 100644 (file)
@@ -715,13 +715,18 @@ krb5_error_code KRB5_CALLCONV
 
 /*
  * krb5_k_* functions use opaque key identifiers and should perform
- * better for repeated operations with the same key usage.
+ * better for repeated operations with the same key usage.  krb5_keys
+ * are immutable once created.
  */
 
 krb5_error_code KRB5_CALLCONV
 krb5_k_create_key(krb5_context context, const krb5_keyblock *key_data,
                  krb5_key *out);
 
+/* Since keys are immutable, they can be "copied" by reference count. */
+void KRB5_CALLCONV krb5_k_reference_key(krb5_context context, krb5_key key);
+
+/* Decrement the reference count on a key and free it if it hits zero. */
 void KRB5_CALLCONV krb5_k_free_key(krb5_context context, krb5_key key);
 
 krb5_error_code KRB5_CALLCONV
index 8b842abddcfa003fd5e955bd3083bd0dcd1112ba..1fb9bcc83757197f4026cf173dcba27eab7aafae 100644 (file)
@@ -49,6 +49,7 @@ krb5_k_create_key(krb5_context context, const krb5_keyblock *key_data,
     if (code)
        goto cleanup;
 
+    key->refcount = 1;
     *out = key;
     return 0;
 
@@ -57,11 +58,17 @@ cleanup:
     return code;
 }
 
+void KRB5_CALLCONV
+krb5_k_reference_key(krb5_context context, krb5_key key)
+{
+    key->refcount++;
+}
+
 /* Free the memory used by a krb5_key. */
 void KRB5_CALLCONV
 krb5_k_free_key(krb5_context context, krb5_key key)
 {
-    if (key == NULL)
+    if (key == NULL || --key->refcount > 0)
        return;
     krb5int_c_free_keyblock_contents(context, &key->keyblock);
 }