From f849f506cce2cd53063f6657ca78726e78dac440 Mon Sep 17 00:00:00 2001 From: "git@daemon.de" Date: Wed, 12 Feb 2014 16:46:11 +0100 Subject: [PATCH] put keysig stuff into extra source --- include/Makefile.am | 3 +- include/pcp/keysig.h | 59 ++++++++++++++++++++++++++++++++++ libpcp/Makefile.am | 2 +- libpcp/keysig.c | 76 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 include/pcp/keysig.h create mode 100644 libpcp/keysig.c diff --git a/include/Makefile.am b/include/Makefile.am index c70bb0c..dc1e040 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -20,6 +20,7 @@ PCPEXPORT = pcp.h \ pcp/ed.h \ pcp/base85.h \ pcp/buffer.h \ - pcp/mgmt.h + pcp/mgmt.h \ + pcp/keysig.h nobase_include_HEADERS = $(PCPEXPORT) diff --git a/include/pcp/keysig.h b/include/pcp/keysig.h new file mode 100644 index 0000000..525c6b9 --- /dev/null +++ b/include/pcp/keysig.h @@ -0,0 +1,59 @@ +/* + This file is part of Pretty Curved Privacy (pcp1). + + Copyright (C) 2013-2014 T.v.Dein. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + You can contact me by mail: . +*/ + + +#ifndef _HAVE_PCP_KEYSIG_H +#define _HAVE_PCP_KEYSIG_H + +#include +#include + +#include "defines.h" +#include "platform.h" +#include "mem.h" +#include "buffer.h" +#include "key.h" + +#define PCP_RAW_KEYSIGSIZE sizeof(pcp_keysig_t) - sizeof(UT_hash_handle) + +/* holds a public key signature */ +struct _pcp_keysig_t { + uint8_t type; + uint32_t size; + char belongs[17]; + byte checksum[32]; + byte *blob; + UT_hash_handle hh; +}; + +typedef struct _pcp_keysig_t pcp_keysig_t; + +pcp_keysig_t *keysig2be(pcp_keysig_t *s); +pcp_keysig_t *keysig2native(pcp_keysig_t *s); + +/* put a keysig into a buffer, convert to big endian while at it */ +Buffer *pcp_keysig2blob(pcp_keysig_t *s); + +/* fetch a keysig from a buffer, usually loaded from vault */ +pcp_keysig_t *pcp_keysig_new(Buffer *blob); + + +#endif /* _HAVE_PCP_KEYSIG_H */ diff --git a/libpcp/Makefile.am b/libpcp/Makefile.am index fbaeefc..2a687f6 100644 --- a/libpcp/Makefile.am +++ b/libpcp/Makefile.am @@ -30,6 +30,6 @@ libpcp1_la_SOURCES = mac.c mem.c pad.c version.c \ vault.c fatal.c jenhash.c digital_crc32.c \ crypto.c ed.c keyhash.c scrypt.c \ scrypt/crypto/sha256.c scrypt/crypto/crypto_scrypt-nosse.c \ - base85.c util.c buffer.c mgmt.c + base85.c util.c buffer.c mgmt.c keysig.c include_HEADERS = ../include/pcp.h diff --git a/libpcp/keysig.c b/libpcp/keysig.c new file mode 100644 index 0000000..489e349 --- /dev/null +++ b/libpcp/keysig.c @@ -0,0 +1,76 @@ +/* + This file is part of Pretty Curved Privacy (pcp1). + + Copyright (C) 2013-2014 T.v.Dein. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + You can contact me by mail: . +*/ + + +#include "keysig.h" + +pcp_keysig_t * keysig2be(pcp_keysig_t *s) { +#ifdef __CPU_IS_BIG_ENDIAN + return s; +#else + uint32_t size = s->size; + unsigned char* p = (unsigned char*)&size; + if(p[0] != 0) { + s->size = htobe32(s->size); + } + return s; +#endif +} + +pcp_keysig_t *keysig2native(pcp_keysig_t *s) { +#ifdef __CPU_IS_BIG_ENDIAN + return s; +#else + s->size = be32toh(s->size); + return s; +#endif +} + +Buffer *pcp_keysig2blob(pcp_keysig_t *s) { + Buffer *b = buffer_new(256, "keysig2blob"); + buffer_add8(b, s->type); + buffer_add32be(b, s->size); + buffer_add(b, s->belongs, 17); + buffer_add(b, s->checksum, 32); + buffer_add(b, s->blob, s->size); + return b; +} + +pcp_keysig_t *pcp_keysig_new(Buffer *blob) { + pcp_keysig_t *sk = ucmalloc(sizeof(pcp_keysig_t)); + + uint8_t type = buffer_get8(blob); + uint32_t size = buffer_get32na(blob); + + byte *checksum = ucmalloc(32); + buffer_get_chunk(blob, checksum, 32); + + sk->blob = ucmalloc(size); + buffer_get_chunk(blob, sk->blob, size); + + sk->size = size; + sk->type = type; + memcpy(sk->checksum, checksum, 32); + + ucfree(checksum, 32); + + return sk; +}