]> de.git.xonotic.org Git - xonotic/d0_blind_id.git/blobdiff - main.c
main.c: missing va_end(ap).
[xonotic/d0_blind_id.git] / main.c
diff --git a/main.c b/main.c
index d52a8bf6ce6a1bbabf11a6ef5faf81f0283ddb87..9995fd5ece643d1563a08d75048f3eaaa593f06b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,21 +1,37 @@
 /*
-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"
 
@@ -38,7 +54,7 @@ void bench(double *b)
 #ifndef WIN32
 #include <sys/signal.h>
 #endif
-volatile BOOL quit = 0;
+volatile D0_BOOL quit = 0;
 void mysignal(int signo)
 {
        (void) signo;
@@ -52,6 +68,7 @@ static void errx(int status, const char *format, ...)
        va_list ap;
        va_start(ap, format);
        vfprintf(stderr, format, ap);
+       va_end(ap);
        fputs("\n", stderr);
        exit(status);
 }
@@ -67,7 +84,7 @@ int main(int argc, char **argv)
        ctx_other = d0_blind_id_new();
 
        printf("keygen RSA...\n");
-       if(!d0_blind_id_generate_private_key(ctx_self, 256))
+       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))
@@ -103,9 +120,9 @@ int main(int argc, char **argv)
                buf2size = sizeof(buf2) - 1; if(!d0_blind_id_fingerprint64_public_id(ctx_other, buf2, &buf2size))
                        errx(4, "fp64 fail");
                bench(&bench_stop);
+               ++n;
                if(n % 1024 == 0)
                        printf("gen=%f fp=%f\n", n/bench_gen, n/bench_fp);
-               ++n;
        }
        while(!(quit || argc != 2 || (buf2size > strlen(argv[1]) && !memcmp(buf2, argv[1], strlen(argv[1])))));
 
@@ -125,10 +142,21 @@ int main(int argc, char **argv)
                errx(8, "readpub2 fail");
 
        n = 0;
-       double bench_auth = 0, bench_chall = 0, bench_resp = 0, bench_verify = 0, bench_dhkey1 = 0, bench_dhkey2 = 0;
-       BOOL status;
+       double bench_auth = 0, bench_chall = 0, bench_resp = 0, bench_verify = 0, bench_dhkey1 = 0, bench_dhkey2 = 0, bench_sign = 0, bench_signverify = 0;
+       D0_BOOL status;
        while(!quit)
        {
+               bench(&bench_sign);
+               bufsize = sizeof(buf); if(!d0_blind_id_sign_with_private_id_sign(ctx_other, 1, 1, "hello world", 11, buf, &bufsize))
+                       errx(9, "sign fail");
+               bench(&bench_signverify);
+               buf2size = sizeof(buf2); if(!d0_blind_id_sign_with_private_id_verify(ctx_self, 1, 1, buf, bufsize, buf2, &buf2size, &status))
+                       errx(9, "signverify fail");
+               bench(&bench_stop);
+               if(buf2size != 11 || memcmp(buf2, "hello world", 11))
+                       errx(13, "signhello fail");
+               if(!status)
+                       errx(14, "signsignature fail");
                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");
@@ -158,7 +186,7 @@ int main(int argc, char **argv)
                        errx(17, "dhkey match fail");
                ++n;
                if(n % 1024 == 0)
-                       printf("auth=%f chall=%f resp=%f verify=%f dh1=%f dh2=%f\n", n/bench_auth, n/bench_chall, n/bench_resp, n/bench_verify, n/bench_dhkey1, n/bench_dhkey2);
+                       printf("sign=%f signverify=%f auth=%f chall=%f resp=%f verify=%f dh1=%f dh2=%f\n", n/bench_sign, n/bench_signverify, n/bench_auth, n/bench_chall, n/bench_resp, n/bench_verify, n/bench_dhkey1, n/bench_dhkey2);
        }
 
        return 0;