summaryrefslogtreecommitdiffstats
path: root/moon-abe/cpabe-0.11/benchmark.c.old
diff options
context:
space:
mode:
authorWuKong <rebirthmonkey@gmail.com>2015-09-04 09:25:34 +0200
committerWuKong <rebirthmonkey@gmail.com>2015-09-04 09:25:34 +0200
commit3baeb11a8fbcfcdbc31976d421f17b85503b3ecd (patch)
tree04891d88c1127148f1b390b5a24414e85b270aee /moon-abe/cpabe-0.11/benchmark.c.old
parent67c5b73910f5fc437429c356978081b252a59480 (diff)
init attribute-based encryption
Change-Id: Iba1a3d722110abf747a0fba366f3ebc911d25b25
Diffstat (limited to 'moon-abe/cpabe-0.11/benchmark.c.old')
-rw-r--r--moon-abe/cpabe-0.11/benchmark.c.old112
1 files changed, 112 insertions, 0 deletions
diff --git a/moon-abe/cpabe-0.11/benchmark.c.old b/moon-abe/cpabe-0.11/benchmark.c.old
new file mode 100644
index 00000000..e9f04630
--- /dev/null
+++ b/moon-abe/cpabe-0.11/benchmark.c.old
@@ -0,0 +1,112 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <glib.h>
+#include <pbc.h>
+#include <pbc_random.h>
+#include "bswabe.h"
+#include "common.h"
+#include <sys/time.h>
+#include <sys/resource.h>
+
+char* usage =
+"Usage: cpabe-setup [OPTION ...]\n"
+"\n"
+"Generate system parameters, a public key, and a master secret key\n"
+"for use with cpabe-keygen, cpabe-enc, and cpabe-dec.\n"
+"\n"
+"Output will be written to the files \"pub_key\" and \"master_key\"\n"
+"unless the --output-public-key or --output-master-key options are\n"
+"used.\n"
+"\n"
+"Mandatory arguments to long options are mandatory for short options too.\n\n"
+" -h, --help print this message\n\n"
+" -v, --version print version information\n\n"
+" -p, --output-public-key FILE write public key to FILE\n\n"
+" -m, --output-master-key FILE write master secret key to FILE\n\n"
+" -d, --deterministic use deterministic \"random\" numbers\n"
+" (only for debugging)\n\n"
+"";
+
+char* pub_file = "pub_key";
+char* msk_file = "master_key";
+
+void
+parse_args( int argc, char** argv )
+{
+ int i;
+
+ for( i = 1; i < argc; i++ )
+ if( !strcmp(argv[i], "-h") || !strcmp(argv[i], "--help") )
+ {
+ printf("%s", usage);
+ exit(0);
+ }
+ else if( !strcmp(argv[i], "-v") || !strcmp(argv[i], "--version") )
+ {
+ printf(CPABE_VERSION, "-setup");
+ exit(0);
+ }
+ else if( !strcmp(argv[i], "-p") || !strcmp(argv[i], "--output-public-key") )
+ {
+ if( ++i >= argc )
+ die(usage);
+ else
+ pub_file = argv[i];
+ }
+ else if( !strcmp(argv[i], "-m") || !strcmp(argv[i], "--output-master-key") )
+ {
+ if( ++i >= argc )
+ die(usage);
+ else
+ msk_file = argv[i];
+ }
+ else if( !strcmp(argv[i], "-d") || !strcmp(argv[i], "--deterministic") )
+ {
+ pbc_random_set_deterministic(0);
+ }
+ else
+ die(usage);
+}
+
+int
+main( int argc, char** argv )
+{
+ bswabe_pub_t* pub;
+ bswabe_msk_t* msk;
+
+ parse_args(argc, argv);
+
+ bswabe_setup(&pub, &msk);
+ spit_file(pub_file, bswabe_pub_serialize(pub), 1);
+ spit_file(msk_file, bswabe_msk_serialize(msk), 1);
+
+// Benchmark
+/*
+{
+ double get_time()
+ {
+ struct timeval t;
+ struct timezone tzp;
+ gettimeofday(&t, &tzp);
+ return t.tv_sec + t.tv_usec*1e-6;
+ }
+
+ int i;
+ int n = 100;
+ double ttotal = 0.0;
+ for (i = 0; i < n; i++) {
+
+ double t0 = get_time();
+ bswabe_setup(&pub, &msk);
+ double t1 = get_time();
+ ttotal += t1 - t0;
+ }
+
+ printf("average setup time (pub key and master key generation) = %f s\n", ttotal / n);
+
+}
+*/
+ return 0;
+}