]> git.ipfire.org Git - pakfire.git/commitdiff
keys: Change key id into uint64_t
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Jun 2023 17:01:18 +0000 (17:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Jun 2023 17:01:18 +0000 (17:01 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/key.h
src/libpakfire/key.c

index d965837ac24c3a2e2c2463ba7e12f70867e4f2f9..96a5352e3dfe14fb4bf099af157284d3de3b3e1f 100644 (file)
@@ -37,11 +37,13 @@ typedef enum pakfire_key_export_mode {
        PAKFIRE_KEY_EXPORT_MODE_PRIVATE,
 } pakfire_key_export_mode_t;
 
+typedef uint64_t pakfire_key_id;
+
 struct pakfire_key* pakfire_key_ref(struct pakfire_key* key);
 void pakfire_key_unref(struct pakfire_key* key);
 
 // Access key properties
-const char* pakfire_key_get_id(struct pakfire_key* key);
+pakfire_key_id pakfire_key_get_id(struct pakfire_key* key);
 const char* pakfire_key_get_algo(struct pakfire_key* key);
 
 int pakfire_key_generate(struct pakfire_key** key, struct pakfire* pakfire,
index d78b2ca36527ce315b43c6ee017b1a7ebcd30603..9d2ec1e05277887b429e22f09767c146ac01358e 100644 (file)
@@ -44,8 +44,6 @@
 // Size of the buffer to allocate for error messages
 #define ERROR_MAX              1024
 
-typedef unsigned char pakfire_key_id[8];
-
 struct pakfire_key {
        struct pakfire* pakfire;
        int nrefs;
@@ -86,7 +84,7 @@ struct pakfire_key_signature {
 };
 
 static int pakfire_key_id_equals(const pakfire_key_id* id1, const pakfire_key_id* id2) {
-       return !memcmp(*id1, *id2, sizeof(*id1));
+       return *id1 == *id2;
 }
 
 static int pakfire_key_create(struct pakfire_key** key, struct pakfire* pakfire,
@@ -118,7 +116,7 @@ static int pakfire_key_create(struct pakfire_key** key, struct pakfire* pakfire,
        }
 
        // Store the key ID
-       memcpy(k->id, id, sizeof(k->id));
+       k->id = id;
 
        // Keep a reference to this key
        EVP_PKEY_up_ref(pkey);
@@ -155,6 +153,10 @@ PAKFIRE_EXPORT void pakfire_key_unref(struct pakfire_key* key) {
        pakfire_key_free(key);
 }
 
+PAKFIRE_EXPORT pakfire_key_id pakfire_key_get_id(struct pakfire_key* key) {
+       return key->id;
+}
+
 PAKFIRE_EXPORT const char* pakfire_key_get_algo(struct pakfire_key* key) {
        switch (key->algo) {
                case PAKFIRE_KEY_ALGO_ED25519:
@@ -188,7 +190,7 @@ PAKFIRE_EXPORT int pakfire_key_generate(struct pakfire_key** key, struct pakfire
        }
 
        // Generate a random key ID
-       r = RAND_bytes(key_id, sizeof(key_id));
+       r = RAND_bytes((unsigned char*)&key_id, sizeof(key_id));
        if (r < 0) {
                ERROR(pakfire, "Could not generate the key ID\n");
                r = 1;
@@ -555,7 +557,7 @@ static int pakfire_key_export_private_key(struct pakfire_key* key,
        }
 
        // Copy the key ID
-       memcpy(buffer->id, key->id, sizeof(buffer->id));
+       buffer->id = key->id;
 
        // Write the public key
        r = pakfire_key_get_public_key(key, buffer->keys.public, sizeof(buffer->keys.public));
@@ -602,7 +604,7 @@ static int pakfire_key_export_public_key(struct pakfire_key* key,
        }
 
        // Copy the key ID
-       memcpy(buffer->id, key->id, sizeof(buffer->id));
+       buffer->id = key->id;
 
        // Write the public key
        r = pakfire_key_get_public_key(key, buffer->pubkey, sizeof(buffer->pubkey));
@@ -787,7 +789,7 @@ static int __pakfire_key_sign(struct pakfire_key* key,
        signature->sig_algo[1] = 'd';
 
        // Set the key ID
-       memcpy(signature->key_id, key->id, sizeof(signature->key_id));
+       signature->key_id = key->id;
 
        // Create a message digest context
        mdctx = EVP_MD_CTX_new();