1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/cal/ed25519.h>
#include <aws/common/ref_count.h>
struct aws_ed25519_key_pair_impl;
#ifndef BYO_CRYPTO
extern struct aws_ed25519_key_pair_impl *aws_ed25519_key_pair_new_generate_impl(struct aws_allocator *allocator);
extern void aws_ed25519_key_pair_destroy_impl(struct aws_ed25519_key_pair_impl *key_pair_impl);
extern int aws_ed25519_key_pair_get_public_key_impl(
const struct aws_ed25519_key_pair_impl *key_pair,
enum aws_ed25519_key_export_format format,
struct aws_byte_buf *out);
extern size_t aws_ed25519_key_pair_get_public_key_size_impl(enum aws_ed25519_key_export_format format);
extern int aws_ed25519_key_pair_get_private_key_impl(
const struct aws_ed25519_key_pair_impl *key_pair,
enum aws_ed25519_key_export_format format,
struct aws_byte_buf *out);
extern size_t aws_ed25519_key_pair_get_private_key_size_impl(enum aws_ed25519_key_export_format format);
#else /* BYO_CRYPTO */
struct aws_ed25519_key_pair_impl *aws_ed25519_key_pair_new_generate_impl(struct aws_allocator *allocator) {
(void)allocator;
abort();
}
void aws_ed25519_key_pair_destroy_impl(struct aws_ed25519_key_pair_impl *key_pair_impl) {
(void)key_pair_impl;
abort();
}
int aws_ed25519_key_pair_get_public_key_impl(
const struct aws_ed25519_key_pair_impl *key_pair,
enum aws_ed25519_key_export_format format,
struct aws_byte_buf *out) {
(void)key_pair;
(void)format;
(void)out;
abort();
}
size_t aws_ed25519_key_pair_get_public_key_size_impl(enum aws_ed25519_key_export_format format) {
(void)format;
abort();
}
int aws_ed25519_key_pair_get_private_key_impl(
const struct aws_ed25519_key_pair_impl *key_pair,
enum aws_ed25519_key_export_format format,
struct aws_byte_buf *out) {
(void)key_pair;
(void)format;
(void)out;
abort();
}
size_t aws_ed25519_key_pair_get_private_key_size_impl(enum aws_ed25519_key_export_format format) {
(void)format;
abort();
}
#endif /* BYO_CRYPTO */
struct aws_ed25519_key_pair {
struct aws_allocator *allocator;
struct aws_ref_count ref_count;
struct aws_ed25519_key_pair_impl *key;
};
static void s_ed25519_destroy_key(void *key_pair) {
if (key_pair == NULL) {
return;
}
struct aws_ed25519_key_pair *ed25519_key_pair = (struct aws_ed25519_key_pair *)(key_pair);
if (ed25519_key_pair->key != NULL) {
aws_ed25519_key_pair_destroy_impl(ed25519_key_pair->key);
}
aws_mem_release(ed25519_key_pair->allocator, ed25519_key_pair);
}
struct aws_ed25519_key_pair *aws_ed25519_key_pair_new_generate(struct aws_allocator *allocator) {
struct aws_ed25519_key_pair_impl *key_impl = aws_ed25519_key_pair_new_generate_impl(allocator);
if (key_impl == NULL) {
return NULL;
}
struct aws_ed25519_key_pair *key_pair = aws_mem_calloc(allocator, 1, sizeof(struct aws_ed25519_key_pair));
aws_ref_count_init(&key_pair->ref_count, key_pair, s_ed25519_destroy_key);
key_pair->allocator = allocator;
key_pair->key = key_impl;
return key_pair;
}
struct aws_ed25519_key_pair *aws_ed25519_key_pair_acquire(struct aws_ed25519_key_pair *key_pair) {
if (key_pair != NULL) {
aws_ref_count_acquire(&key_pair->ref_count);
}
return key_pair;
}
struct aws_ed25519_key_pair *aws_ed25519_key_pair_release(struct aws_ed25519_key_pair *key_pair) {
if (key_pair != NULL) {
aws_ref_count_release(&key_pair->ref_count);
}
return NULL;
}
int aws_ed25519_key_pair_get_public_key(
const struct aws_ed25519_key_pair *key_pair,
enum aws_ed25519_key_export_format format,
struct aws_byte_buf *out) {
return aws_ed25519_key_pair_get_public_key_impl(key_pair->key, format, out);
}
size_t aws_ed25519_key_pair_get_public_key_size(enum aws_ed25519_key_export_format format) {
return aws_ed25519_key_pair_get_public_key_size_impl(format);
}
int aws_ed25519_key_pair_get_private_key(
const struct aws_ed25519_key_pair *key_pair,
enum aws_ed25519_key_export_format format,
struct aws_byte_buf *out) {
return aws_ed25519_key_pair_get_private_key_impl(key_pair->key, format, out);
}
size_t aws_ed25519_key_pair_get_private_key_size(enum aws_ed25519_key_export_format format) {
return aws_ed25519_key_pair_get_private_key_size_impl(format);
}
|