X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=main.c;h=9506c1ef4b67df45131f5037bdca78a7a24a999a;hb=a0b5239a7c040e5694b62993ee09d3bfbc589b03;hp=249e60471c51b0bebe2297be1a2496985a677c62;hpb=eb8ff0931f00304b0ad437961a9c3003c3bcc1ed;p=xonotic%2Fd0_blind_id.git diff --git a/main.c b/main.c index 249e604..9506c1e 100644 --- a/main.c +++ b/main.c @@ -1,48 +1,77 @@ /* -Blind-ID library for user identification using RSA blind signatures -Copyright (C) 2010 Rudolf Polzer - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library 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 -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + * FILE: d0_iobuf.c + * AUTHOR: Rudolf Polzer - divVerent@xonotic.org + * + * Copyright (c) 2010, Rudolf Polzer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Format:commit %H$ + * $Id$ + */ #include "d0_blind_id.h" #include #include #include +#include void bench(double *b) { - static struct timespec thistime, lasttime; + static struct timeval thistime, lasttime; static double x = 0; static double *lastclock = &x; lasttime = thistime; - clock_gettime(CLOCK_MONOTONIC, &thistime); - *lastclock += (thistime.tv_sec - lasttime.tv_sec) + 0.000000001 * (thistime.tv_nsec - lasttime.tv_nsec); + gettimeofday(&thistime, NULL); + *lastclock += (thistime.tv_sec - lasttime.tv_sec) + 0.000001 * (thistime.tv_usec - lasttime.tv_usec); lastclock = b; } +#ifndef WIN32 #include -volatile BOOL quit = 0; +#endif +volatile D0_BOOL quit = 0; void mysignal(int signo) { (void) signo; quit = 1; } -#include +#include +#include +static void errx(int status, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + vfprintf(stderr, format, ap); + fputs("\n", stderr); + exit(status); +} + int main(int argc, char **argv) { char buf[65536]; size_t bufsize; @@ -56,6 +85,10 @@ int main(int argc, char **argv) printf("keygen RSA...\n"); if(!d0_blind_id_generate_private_key(ctx_self, 1024)) errx(1, "keygen fail"); + buf2size = sizeof(buf2) - 1; + if(!d0_blind_id_fingerprint64_public_key(ctx_self, buf2, &buf2size)) + errx(2, "fp64 fail"); + printf("key has fingerprint %s\n", buf2); bufsize = sizeof(buf); if(!d0_blind_id_write_public_key(ctx_self, buf, &bufsize)) errx(2, "writepub fail"); if(!d0_blind_id_read_public_key(ctx_other, buf, bufsize)) @@ -71,7 +104,9 @@ int main(int argc, char **argv) errx(3, "readpub fail"); */ +#ifndef WIN32 signal(SIGINT, mysignal); +#endif int n = 0; double bench_gen = 0, bench_fp = 0, bench_stop = 0; @@ -107,17 +142,19 @@ int main(int argc, char **argv) n = 0; double bench_auth = 0, bench_chall = 0, bench_resp = 0, bench_verify = 0, bench_dhkey1 = 0, bench_dhkey2 = 0; - BOOL status; + D0_BOOL status; while(!quit) { bench(&bench_auth); bufsize = sizeof(buf); if(!d0_blind_id_authenticate_with_private_id_start(ctx_other, 1, 1, "hello world", 11, buf, &bufsize)) errx(9, "start fail"); bench(&bench_chall); - buf2size = sizeof(buf2); if(!d0_blind_id_authenticate_with_private_id_challenge(ctx_self, 1, 1, buf, bufsize, buf2, &buf2size, NULL)) + buf2size = sizeof(buf2); if(!d0_blind_id_authenticate_with_private_id_challenge(ctx_self, 1, 1, buf, bufsize, buf2, &buf2size, &status)) errx(10, "challenge fail"); + if(!status) + errx(14, "signature prefail"); bench(&bench_resp); - bufsize = sizeof(buf); if(!d0_blind_id_authenticate_with_private_id_response(ctx_other, 1, buf2, buf2size, buf, &bufsize)) + bufsize = sizeof(buf); if(!d0_blind_id_authenticate_with_private_id_response(ctx_other, buf2, buf2size, buf, &bufsize)) errx(11, "response fail"); bench(&bench_verify); buf2size = sizeof(buf2); if(!d0_blind_id_authenticate_with_private_id_verify(ctx_self, buf, bufsize, buf2, &buf2size, &status)) @@ -127,10 +164,10 @@ int main(int argc, char **argv) if(!status) errx(14, "signature fail"); bench(&bench_dhkey1); - bufsize = sizeof(buf); if(!d0_blind_id_sessionkey_public_id(ctx_self, buf, &bufsize)) + bufsize = 20; if(!d0_blind_id_sessionkey_public_id(ctx_self, buf, &bufsize)) errx(15, "dhkey1 fail"); bench(&bench_dhkey2); - buf2size = sizeof(buf2); if(!d0_blind_id_sessionkey_public_id(ctx_other, buf2, &buf2size)) + buf2size = 20; if(!d0_blind_id_sessionkey_public_id(ctx_other, buf2, &buf2size)) errx(16, "dhkey2 fail"); bench(&bench_stop); if(bufsize != buf2size || memcmp(buf, buf2, bufsize))