char comment[COMMENT_MAX];
};
-struct pakfire_key_public_key {
+typedef struct pakfire_key_public_key {
unsigned char sig_algo[2];
pakfire_key_id id;
unsigned char pubkey[32];
-};
+} pakfire_key_public_key;
-struct pakfire_key_private_key {
+typedef struct pakfire_key_private_key {
unsigned char sig_algo[2];
- unsigned char kdf_algo[2];
+ unsigned char kdf_algo[2];
uint32_t kdf_rounds;
- unsigned char kdf_salt[16];
+ unsigned char kdf_salt[16];
unsigned char checksum[8];
pakfire_key_id id;
struct {
unsigned char secret[32];
unsigned char public[32];
} keys;
-};
+} pakfire_key_private_key;
-struct pakfire_key_signature {
+typedef struct pakfire_key_signature {
unsigned char sig_algo[2];
pakfire_key_id key_id;
unsigned char signature[64];
-};
+} 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));
}
-static int pakfire_key_create(struct pakfire_key** key, pakfire_ctx* ctx,
+static int pakfire_key_create(pakfire_key** key, pakfire_ctx* ctx,
const pakfire_key_algo_t algo, const pakfire_key_id id, EVP_PKEY* pkey, const char* comment) {
- struct pakfire_key* k = NULL;
+ pakfire_key* k = NULL;
int r = 0;
if (!pkey)
return r;
}
-static void pakfire_key_free(struct pakfire_key* key) {
+static void pakfire_key_free(pakfire_key* key) {
// Free the key
if (key->pkey)
EVP_PKEY_free(key->pkey);
free(key);
}
-struct pakfire_key* pakfire_key_ref(struct pakfire_key* key) {
+pakfire_key* pakfire_key_ref(pakfire_key* key) {
++key->nrefs;
return key;
}
-struct pakfire_key* pakfire_key_unref(struct pakfire_key* key) {
+pakfire_key* pakfire_key_unref(pakfire_key* key) {
if (--key->nrefs > 0)
return key;
return NULL;
}
-pakfire_key_id* pakfire_key_get_id(struct pakfire_key* key) {
+pakfire_key_id* pakfire_key_get_id(pakfire_key* key) {
return &key->id;
}
-const char* pakfire_key_get_algo(struct pakfire_key* key) {
+const char* pakfire_key_get_algo(pakfire_key* key) {
switch (key->algo) {
case PAKFIRE_KEY_ALGO_ED25519:
return "Ed255919";
return NULL;
}
-const char* pakfire_key_get_comment(struct pakfire_key* key) {
+const char* pakfire_key_get_comment(pakfire_key* key) {
return key->comment;
}
-int pakfire_key_generate(struct pakfire_key** key, pakfire_ctx* ctx,
+int pakfire_key_generate(pakfire_key** key, pakfire_ctx* ctx,
const pakfire_key_algo_t algo, const char* comment) {
EVP_PKEY* pkey = NULL;
EVP_PKEY_CTX* pctx = NULL;
Import
*/
-static int pakfire_key_import_secret_key(struct pakfire_key** key,
+static int pakfire_key_import_secret_key(pakfire_key** key,
pakfire_ctx* ctx, const char* comment,
- const struct pakfire_key_private_key* buffer) {
+ const pakfire_key_private_key* buffer) {
const pakfire_key_algo_t algo = PAKFIRE_KEY_ALGO_ED25519;
EVP_PKEY* pkey = NULL;
char error[ERROR_MAX];
return r;
}
-static int pakfire_key_import_public_key(struct pakfire_key** key,
+static int pakfire_key_import_public_key(pakfire_key** key,
pakfire_ctx* ctx, const char* comment,
- const struct pakfire_key_public_key* buffer) {
+ const pakfire_key_public_key* buffer) {
const pakfire_key_algo_t algo = PAKFIRE_KEY_ALGO_ED25519;
EVP_PKEY* pkey = NULL;
char error[ERROR_MAX];
return r;
}
-int pakfire_key_import(struct pakfire_key** key,
+int pakfire_key_import(pakfire_key** key,
pakfire_ctx* ctx, FILE* f) {
unsigned char* buffer = NULL;
size_t buffer_length = 0;
// What kind of key do we have?
switch (buffer_length) {
// Public Key
- case sizeof(struct pakfire_key_public_key):
+ case sizeof(pakfire_key_public_key):
r = pakfire_key_import_public_key(key, ctx, comment,
- (struct pakfire_key_public_key*)buffer);
+ (pakfire_key_public_key*)buffer);
if (r < 0)
goto ERROR;
break;
// Private Key
- case sizeof(struct pakfire_key_private_key):
+ case sizeof(pakfire_key_private_key):
r = pakfire_key_import_secret_key(key, ctx, comment,
- (struct pakfire_key_private_key*)buffer);
+ (pakfire_key_private_key*)buffer);
if (r < 0)
goto ERROR;
break;
return r;
}
-int pakfire_key_import_from_string(struct pakfire_key** key,
+int pakfire_key_import_from_string(pakfire_key** key,
pakfire_ctx* ctx, const char* data, const size_t length) {
FILE* f = NULL;
int r;
return r;
}
-static int pakfire_key_get_public_key(struct pakfire_key* key,
+static int pakfire_key_get_public_key(pakfire_key* key,
unsigned char* buffer, const size_t length) {
char error[ERROR_MAX];
int r;
return 0;
}
-static int pakfire_key_get_secret_key(struct pakfire_key* key,
+static int pakfire_key_get_secret_key(pakfire_key* key,
unsigned char* buffer, const size_t length) {
char error[ERROR_MAX];
int r;
Export
*/
-static int pakfire_key_export_private_key(struct pakfire_key* key,
- struct pakfire_key_private_key* buffer) {
+static int pakfire_key_export_private_key(pakfire_key* key,
+ pakfire_key_private_key* buffer) {
unsigned char checksum[64];
unsigned int length = sizeof(checksum);
int r;
return 0;
}
-static int pakfire_key_export_public_key(struct pakfire_key* key,
- struct pakfire_key_public_key* buffer) {
+static int pakfire_key_export_public_key(pakfire_key* key,
+ pakfire_key_public_key* buffer) {
int r;
// Write the algorithm
return 0;
}
-int pakfire_key_export(struct pakfire_key* key, FILE* f,
+int pakfire_key_export(pakfire_key* key, FILE* f,
const pakfire_key_export_mode_t mode) {
- struct pakfire_key_public_key public_key = { 0 };
- struct pakfire_key_private_key private_key = { 0 };
+ pakfire_key_public_key public_key = { 0 };
+ pakfire_key_private_key private_key = { 0 };
int r;
BIO* bio = NULL;
return r;
}
-int pakfire_key_export_string(struct pakfire_key* self, char** buffer, size_t* length) {
+int pakfire_key_export_string(pakfire_key* self, char** buffer, size_t* length) {
FILE* f = NULL;
int r;
Sign
*/
-static int __pakfire_key_sign(struct pakfire_key* key,
- struct pakfire_key_signature* signature, const void* data, const size_t length) {
+static int __pakfire_key_sign(pakfire_key* key,
+ pakfire_key_signature* signature, const void* data, const size_t length) {
EVP_MD_CTX* mdctx = NULL;
char error[ERROR_MAX];
int r;
return r;
}
-int pakfire_key_sign_string(struct pakfire_key* key,
+int pakfire_key_sign_string(pakfire_key* key,
FILE* f, const void* data, const size_t length, const char* comment) {
- struct pakfire_key_signature signature = { 0 };
+ pakfire_key_signature signature = { 0 };
char* buffer = NULL;
int r;
return r;
}
-int pakfire_key_sign(struct pakfire_key* key, FILE* s, FILE* f, const char* comment) {
+int pakfire_key_sign(pakfire_key* key, FILE* s, FILE* f, const char* comment) {
char* buffer = NULL;
size_t length = 0;
int r;
return r;
}
-static int pakfire_key_read_signature(struct pakfire_key* key,
- struct pakfire_key_signature* signature, FILE* f) {
+static int pakfire_key_read_signature(pakfire_key* key,
+ pakfire_key_signature* signature, FILE* f) {
unsigned char* buffer = NULL;
size_t buffer_length = 0;
int r;
return r;
}
-static int pakfire_key_verify_signature(struct pakfire_key* key,
- const struct pakfire_key_signature* signature, const void* data, const size_t length) {
+static int pakfire_key_verify_signature(pakfire_key* key,
+ const pakfire_key_signature* signature, const void* data, const size_t length) {
EVP_MD_CTX* mdctx = NULL;
int r;
return r;
}
-int pakfire_key_verify(struct pakfire_key* key, FILE* f,
+int pakfire_key_verify(pakfire_key* key, FILE* f,
const void* data, const size_t length) {
- struct pakfire_key_signature signature = { 0 };
+ pakfire_key_signature signature = { 0 };
int r;
// Read the signature
#include <time.h>
-struct pakfire_key;
+typedef struct pakfire_key pakfire_key;
#include <pakfire/ctx.h>
typedef unsigned char pakfire_key_id[8];
-struct pakfire_key* pakfire_key_ref(struct pakfire_key* key);
-struct pakfire_key* pakfire_key_unref(struct pakfire_key* key);
+pakfire_key* pakfire_key_ref(pakfire_key* key);
+pakfire_key* pakfire_key_unref(pakfire_key* key);
// Access key properties
-pakfire_key_id* pakfire_key_get_id(struct pakfire_key* key);
-const char* pakfire_key_get_algo(struct pakfire_key* key);
-const char* pakfire_key_get_comment(struct pakfire_key* key);
+pakfire_key_id* pakfire_key_get_id(pakfire_key* key);
+const char* pakfire_key_get_algo(pakfire_key* key);
+const char* pakfire_key_get_comment(pakfire_key* key);
-int pakfire_key_generate(struct pakfire_key** key, pakfire_ctx* ctx,
+int pakfire_key_generate(pakfire_key** key, pakfire_ctx* ctx,
const pakfire_key_algo_t algo, const char* comment);
-int pakfire_key_export(struct pakfire_key* key, FILE* f, const pakfire_key_export_mode_t mode);
-int pakfire_key_export_string(struct pakfire_key* self, char** buffer, size_t* length);
-int pakfire_key_import(struct pakfire_key** key, pakfire_ctx* ctx, FILE* f);
+int pakfire_key_export(pakfire_key* key, FILE* f, const pakfire_key_export_mode_t mode);
+int pakfire_key_export_string(pakfire_key* self, char** buffer, size_t* length);
+int pakfire_key_import(pakfire_key** key, pakfire_ctx* ctx, FILE* f);
// Sign
-int pakfire_key_sign(struct pakfire_key* key, FILE* s, FILE* f, const char* comment);
-int pakfire_key_sign_string(struct pakfire_key* key,
+int pakfire_key_sign(pakfire_key* key, FILE* s, FILE* f, const char* comment);
+int pakfire_key_sign_string(pakfire_key* key,
FILE* s, const void* data, const size_t length, const char* comment);
-int pakfire_key_verify(struct pakfire_key* key,
+int pakfire_key_verify(pakfire_key* key,
FILE* f, const void* data, const size_t length);
-int pakfire_key_import_from_string(struct pakfire_key** key,
+int pakfire_key_import_from_string(pakfire_key** key,
pakfire_ctx* ctx, const char* data, const size_t length);
#endif /* PAKFIRE_KEY_H */