aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcryptobox/keypair.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-06 14:09:21 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-06 14:09:21 +0000
commit524b67ba88ffd3c00160ad0b6cd3f8bffefb7263 (patch)
tree2212653f6feadc42a6ac3c71d7a7727668b46259 /src/libcryptobox/keypair.c
parentab780d6f7531cb8277609aedffbb4376d821f6ff (diff)
downloadrspamd-524b67ba88ffd3c00160ad0b6cd3f8bffefb7263.tar.gz
rspamd-524b67ba88ffd3c00160ad0b6cd3f8bffefb7263.zip
Add routines to print pubkey components
Diffstat (limited to 'src/libcryptobox/keypair.c')
-rw-r--r--src/libcryptobox/keypair.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/libcryptobox/keypair.c b/src/libcryptobox/keypair.c
index 8f0e8e8f6..e645ef3e0 100644
--- a/src/libcryptobox/keypair.c
+++ b/src/libcryptobox/keypair.c
@@ -146,6 +146,8 @@ rspamd_cryptobox_keypair_alloc (enum rspamd_cryptobox_keypair_type type,
abort ();
}
+ memset (kp, 0, size);
+
return kp;
}
@@ -153,7 +155,7 @@ static struct rspamd_cryptobox_pubkey *
rspamd_cryptobox_pubkey_alloc (enum rspamd_cryptobox_keypair_type type,
enum rspamd_cryptobox_mode alg)
{
- struct rspamd_cryptobox_pubkey *kp;
+ struct rspamd_cryptobox_pubkey *pk;
guint size = 0;
if (alg == RSPAMD_CRYPTOBOX_MODE_25519) {
@@ -173,13 +175,15 @@ rspamd_cryptobox_pubkey_alloc (enum rspamd_cryptobox_keypair_type type,
}
}
- g_assert (size >= sizeof (*kp));
+ g_assert (size >= sizeof (*pk));
- if (posix_memalign ((void **)&kp, 32, size) != 0) {
+ if (posix_memalign ((void **)&pk, 32, size) != 0) {
abort ();
}
- return kp;
+ memset (pk, 0, size);
+
+ return pk;
}
@@ -553,7 +557,8 @@ rspamd_keypair_print (struct rspamd_cryptobox_keypair *kp, guint how)
rspamd_keypair_print_component (p, len, res, how, "Private key");
}
if ((how & RSPAMD_KEYPAIR_ID_SHORT)) {
- rspamd_keypair_print_component (kp->id, 5, res, how, "Short key ID");
+ rspamd_keypair_print_component (kp->id, RSPAMD_KEYPAIR_SHORT_ID_LEN,
+ res, how, "Short key ID");
}
if ((how & RSPAMD_KEYPAIR_ID)) {
rspamd_keypair_print_component (kp->id, sizeof (kp->id), res, how, "Key ID");
@@ -562,6 +567,33 @@ rspamd_keypair_print (struct rspamd_cryptobox_keypair *kp, guint how)
return res;
}
+GString *
+rspamd_pubkey_print (struct rspamd_cryptobox_pubkey *pk, guint how)
+{
+ GString *res;
+ guint len;
+ gpointer p;
+
+ g_assert (pk != NULL);
+
+ res = g_string_sized_new (63);
+
+ if ((how & RSPAMD_KEYPAIR_PUBKEY)) {
+ p = rspamd_cryptobox_pubkey_pk (pk, &len);
+ rspamd_keypair_print_component (p, len, res, how, "Public key");
+ }
+ if ((how & RSPAMD_KEYPAIR_ID_SHORT)) {
+ rspamd_keypair_print_component (pk->id, RSPAMD_KEYPAIR_SHORT_ID_LEN,
+ res, how, "Short key ID");
+ }
+ if ((how & RSPAMD_KEYPAIR_ID)) {
+ rspamd_keypair_print_component (pk->id, sizeof (pk->id), res, how,
+ "Key ID");
+ }
+
+ return res;
+}
+
const guchar *
rspamd_keypair_component (struct rspamd_cryptobox_keypair *kp,
guint ncomp, guint *len)