added signature support (doesn't work yet)

This commit is contained in:
git@daemon.de
2013-11-08 09:40:51 +01:00
parent a2c55c96b4
commit e6733e5e56
15 changed files with 497 additions and 39 deletions

View File

@@ -25,6 +25,6 @@ lib_LTLIBRARIES = libpcp1.la
libpcp1_la_SOURCES = mac.c mem.c pad.c version.c \
z85.c zmq_z85.c key.c randomart.c \
vault.c fatal.c jenhash.c digital_crc32.c \
crypto.c
crypto.c ed.c
include_HEADERS = ../include/pcp.h

View File

@@ -99,7 +99,7 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
libpcp1_la_LIBADD =
am_libpcp1_la_OBJECTS = mac.lo mem.lo pad.lo version.lo z85.lo \
zmq_z85.lo key.lo randomart.lo vault.lo fatal.lo jenhash.lo \
digital_crc32.lo crypto.lo
digital_crc32.lo crypto.lo ed.lo
libpcp1_la_OBJECTS = $(am_libpcp1_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
@@ -264,7 +264,7 @@ lib_LTLIBRARIES = libpcp1.la
libpcp1_la_SOURCES = mac.c mem.c pad.c version.c \
z85.c zmq_z85.c key.c randomart.c \
vault.c fatal.c jenhash.c digital_crc32.c \
crypto.c
crypto.c ed.c
include_HEADERS = ../include/pcp.h
all: config.h
@@ -362,6 +362,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/crypto.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/digital_crc32.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ed.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fatal.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/jenhash.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/key.Plo@am__quote@

86
libpcp/ed.c Normal file
View File

@@ -0,0 +1,86 @@
/*
This file is part of Pretty Curved Privacy (pcp1).
Copyright (C) 2013 T.Linden.
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 <http://www.gnu.org/licenses/>.
You can contact me by mail: <tlinden AT cpan DOT org>.
*/
#include "ed.h"
int pcp_ed_verify(unsigned char *input, size_t inputlen, pcp_sig_t *sig, pcp_pubkey_t *p) {
unsigned char *hash = ucmalloc(crypto_hash_sha256_BYTES + crypto_sign_BYTES); // from sig
unsigned char *check = ucmalloc(crypto_hash_sha256_BYTES); // from file
size_t mlen = 0;
if(crypto_sign_open(hash, &mlen, sig->edsig, crypto_hash_sha256_BYTES + crypto_sign_BYTES, p->public) != 0) {
fatal("Failed to open the signature using the public key 0x%s!\n", p->id);
goto errve1;
}
crypto_hash_sha256(check, input, inputlen);
if(memcmp(check, hash, crypto_hash_sha256_BYTES) != 0) {
fatal("Failed to verify the signature, hashes differ!\n");
goto errve1;
}
free(hash);
free(check);
return 0;
errve1:
free(hash);
free(check);
return 1;
}
pcp_sig_t *pcp_ed_sign(unsigned char *message, size_t messagesize, pcp_key_t *s) {
unsigned char *hash = ucmalloc(crypto_hash_sha256_BYTES);
size_t slen = crypto_hash_sha256_BYTES + crypto_sign_BYTES;
unsigned char *signature = ucmalloc(slen);
crypto_hash_sha256(hash, message, messagesize);
crypto_sign(signature, &slen, hash, crypto_hash_sha256_BYTES, s->secret);
pcp_sig_t *sig = pcp_ed_newsig(signature, s->id);
return sig;
}
pcp_sig_t *pcp_ed_newsig(unsigned char *hash, char *id) {
pcp_sig_t *sig = ucmalloc(sizeof(pcp_sig_t));
sig->version = PCP_SIG_VERSION;
sig->ctime = (long)time(0);
memcpy(sig->edsig, hash, crypto_hash_sha256_BYTES + crypto_sign_BYTES);
memcpy(sig->id, id, 17);
return sig;
}
pcp_sig_t *sig2native(pcp_sig_t *s) {
s->version = be32toh(s->version);
s->ctime = be64toh(s->ctime);
return s;
}
pcp_sig_t *sig2be(pcp_sig_t *s) {
s->version = htobe32(s->version);
s->ctime = htobe64(s->ctime);
return s;
}