NEWS: More news for 5.7.2
[strongswan.git] / scripts / pubkey_speed.c
index 255f650..83ab4e4 100644 (file)
@@ -1,8 +1,22 @@
+/*
+ * Copyright (C) 2009 Martin Willi
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * 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 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
 
 #include <stdio.h>
 #include <time.h>
 #include <library.h>
-#include <debug.h>
+#include <utils/debug.h>
 #include <credentials/keys/private_key.h>
 
 void start_timing(struct timespec *start)
@@ -21,7 +35,7 @@ double end_timing(struct timespec *start)
 
 static void usage()
 {
-       printf("usage: pubkey_speed plugins rsa|ecdsa rounds\n");
+       printf("usage: pubkey_speed plugins rsa|ecdsa rounds < key\n");
        exit(1);
 }
 
@@ -57,8 +71,8 @@ int main(int argc, char *argv[])
                usage();
        }
 
-       library_init(NULL);
-       lib->plugins->load(lib->plugins, NULL, argv[1]);
+       library_init(NULL, "pubkey_speed");
+       lib->plugins->load(lib->plugins, argv[1]);
        atexit(library_deinit);
 
        keydata = chunk_create(buf, 0);
@@ -79,23 +93,23 @@ int main(int argc, char *argv[])
        {
                switch (private->get_keysize(private))
                {
-                       case 32:
+                       case 256:
                                scheme = SIGN_ECDSA_256;
                                break;
-                       case 48:
+                       case 384:
                                scheme = SIGN_ECDSA_384;
                                break;
-                       case 66:
+                       case 521:
                                scheme = SIGN_ECDSA_521;
                                break;
                        default:
                                printf("%d bit ECDSA private key size not supported",
-                                               private->get_keysize(private) * 8);
+                                               private->get_keysize(private));
                                exit(1);
                }
        }
 
-       printf("%4d bit %N: ", private->get_keysize(private)*8,
+       printf("%4d bit %N: ", private->get_keysize(private),
                key_type_names, type);
 
        sigs = malloc(sizeof(chunk_t) * rounds);
@@ -104,7 +118,7 @@ int main(int argc, char *argv[])
        start_timing(&timing);
        for (round = 0; round < rounds; round++)
        {
-               if (!private->sign(private, scheme, data, &sigs[round]))
+               if (!private->sign(private, scheme, NULL, data, &sigs[round]))
                {
                        printf("creating signature failed\n");
                        exit(1);
@@ -121,7 +135,7 @@ int main(int argc, char *argv[])
        start_timing(&timing);
        for (round = 0; round < rounds; round++)
        {
-               if (!public->verify(public, scheme, data, sigs[round]))
+               if (!public->verify(public, scheme, NULL, data, sigs[round]))
                {
                        printf("signature verification failed\n");
                        exit(1);
@@ -138,4 +152,3 @@ int main(int argc, char *argv[])
        free(sigs);
        return 0;
 }
-