diff options
author | 2015-09-04 09:25:34 +0200 | |
---|---|---|
committer | 2015-09-04 09:25:34 +0200 | |
commit | 3baeb11a8fbcfcdbc31976d421f17b85503b3ecd (patch) | |
tree | 04891d88c1127148f1b390b5a24414e85b270aee /moon-abe/pbc-0.5.14/gen | |
parent | 67c5b73910f5fc437429c356978081b252a59480 (diff) |
init attribute-based encryption
Change-Id: Iba1a3d722110abf747a0fba366f3ebc911d25b25
Diffstat (limited to 'moon-abe/pbc-0.5.14/gen')
-rw-r--r-- | moon-abe/pbc-0.5.14/gen/Makefile.am | 18 | ||||
-rw-r--r-- | moon-abe/pbc-0.5.14/gen/gena1param.c | 27 | ||||
-rw-r--r-- | moon-abe/pbc-0.5.14/gen/genalldparams | 15 | ||||
-rw-r--r-- | moon-abe/pbc-0.5.14/gen/genaparam.c | 21 | ||||
-rw-r--r-- | moon-abe/pbc-0.5.14/gen/gendparam.c | 35 | ||||
-rw-r--r-- | moon-abe/pbc-0.5.14/gen/geneparam.c | 21 | ||||
-rw-r--r-- | moon-abe/pbc-0.5.14/gen/genfparam.c | 24 | ||||
-rw-r--r-- | moon-abe/pbc-0.5.14/gen/gengparam.c | 33 | ||||
-rw-r--r-- | moon-abe/pbc-0.5.14/gen/hilbertpoly.c | 57 | ||||
-rw-r--r-- | moon-abe/pbc-0.5.14/gen/listfreeman.c | 38 | ||||
-rw-r--r-- | moon-abe/pbc-0.5.14/gen/listmnt.c | 41 |
11 files changed, 330 insertions, 0 deletions
diff --git a/moon-abe/pbc-0.5.14/gen/Makefile.am b/moon-abe/pbc-0.5.14/gen/Makefile.am new file mode 100644 index 00000000..773d31d9 --- /dev/null +++ b/moon-abe/pbc-0.5.14/gen/Makefile.am @@ -0,0 +1,18 @@ +CLEANFILES = *~ +maintainer-clean-local: + -rm -rf Makefile.in + +AM_CPPFLAGS = -I../include +LDADD = ../libpbc.la -lgmp + +noinst_PROGRAMS = gena1param genaparam gendparam geneparam genfparam gengparam hilbertpoly listmnt listfreeman + +gena1param_SOURCES = gena1param.c +genaparam_SOURCES = genaparam.c +gendparam_SOURCES = gendparam.c +geneparam_SOURCES = geneparam.c +genfparam_SOURCES = genfparam.c +gengparam_SOURCES = gengparam.c +hilbertpoly_SOURCES = hilbertpoly.c +listmnt_SOURCES = listmnt.c +listfreeman_SOURCES = listfreeman.c diff --git a/moon-abe/pbc-0.5.14/gen/gena1param.c b/moon-abe/pbc-0.5.14/gen/gena1param.c new file mode 100644 index 00000000..3472beac --- /dev/null +++ b/moon-abe/pbc-0.5.14/gen/gena1param.c @@ -0,0 +1,27 @@ +#include "pbc.h" + +int main(void) +{ + mpz_t p, q, N; + + mpz_init(p); + mpz_init(q); + mpz_init(N); + + // In a real application, p and q must be stored somewhere safe. + pbc_mpz_randomb(p, 512); + pbc_mpz_randomb(q, 512); + + mpz_nextprime(p, p); + mpz_nextprime(q, q); + mpz_mul(N, p, q); + + pbc_param_t param; + pbc_param_init_a1_gen(param, N); + pbc_param_out_str(stdout, param); + pbc_param_clear(param); + mpz_clear(p); + mpz_clear(q); + mpz_clear(N); + return 0; +} diff --git a/moon-abe/pbc-0.5.14/gen/genalldparams b/moon-abe/pbc-0.5.14/gen/genalldparams new file mode 100644 index 00000000..22cfa993 --- /dev/null +++ b/moon-abe/pbc-0.5.14/gen/genalldparams @@ -0,0 +1,15 @@ +#!/bin/bash +# Generates all type D curve parameters within certain limits +# +# Use with the output of listmnt + +function myfunc { + until [ -z "$1" ] + do + filename=d$1-$2-$3.param + gen/gendparam $1 > $filename + shift 3 + done +} + +myfunc `awk -F, '{ if (($2 >= 80) && ($2 <= 300) && ($3 >= 80)) { print $1 $2 $3; } }'` diff --git a/moon-abe/pbc-0.5.14/gen/genaparam.c b/moon-abe/pbc-0.5.14/gen/genaparam.c new file mode 100644 index 00000000..c589e5a3 --- /dev/null +++ b/moon-abe/pbc-0.5.14/gen/genaparam.c @@ -0,0 +1,21 @@ +// Generate type A pairings. +// Usage: +// genaparam [RBITS [QBITS]] +// +// RBITS +// The number of bits in r, the order of the subgroup G1. Default is 160. +// QBITS +// The number of bits in q, the order of the full group. Default is 512. + +#include "pbc.h" + +int main(int argc, char **argv) { + int rbits = argc > 1 ? atoi(argv[1]) : 160; + int qbits = argc > 2 ? atoi(argv[2]) : 512; + + pbc_param_t par; + pbc_param_init_a_gen(par, rbits, qbits); + pbc_param_out_str(stdout, par); + pbc_param_clear(par); + return 0; +} diff --git a/moon-abe/pbc-0.5.14/gen/gendparam.c b/moon-abe/pbc-0.5.14/gen/gendparam.c new file mode 100644 index 00000000..8506e52a --- /dev/null +++ b/moon-abe/pbc-0.5.14/gen/gendparam.c @@ -0,0 +1,35 @@ +// Generate MNT curve(s) for a given D. + +#include <stdint.h> // for intptr_t +#include "pbc.h" +#include "pbc_utils.h" // for UNUSED_VAR + +int generate(pbc_cm_t cm, void *data) { + UNUSED_VAR(data); + pbc_param_t param; + pbc_info("gendparam: computing Hilbert polynomial and finding roots..."); + pbc_param_init_d_gen(param, cm); + pbc_info("gendparam: bits in q = %zu\n", mpz_sizeinbase(cm->q, 2)); + pbc_param_out_str(stdout, param); + pbc_param_clear(param); + return 1; +} + +int main(int argc, char **argv) { + int D = 9563; + + if (argc > 1) { + int m; + D = atoi(argv[1]); + m = D % 4; + if (D <= 0 || m == 1 || m == 2) { + pbc_die("D must be 0 or 3 mod 4 and positive"); + } + } + pbc_info("Using D = %d\n", D); + + if (!pbc_cm_search_d(generate, NULL, D, 500)) { + pbc_die("no suitable curves for this D"); + } + return 0; +} diff --git a/moon-abe/pbc-0.5.14/gen/geneparam.c b/moon-abe/pbc-0.5.14/gen/geneparam.c new file mode 100644 index 00000000..a8109127 --- /dev/null +++ b/moon-abe/pbc-0.5.14/gen/geneparam.c @@ -0,0 +1,21 @@ +// Generate type E pairings. +// Usage: +// geneparam [RBITS [QBITS]] +// +// RBITS +// The number of bits in r, the order of the subgroup G1. Default is 160. +// QBITS +// The number of bits in q, the order of the full group. Default is 1024. + +#include "pbc.h" + +int main(int argc, char **argv) { + int rbits = argc > 1 ? atoi(argv[1]) : 160; + int qbits = argc > 2 ? atoi(argv[2]) : 1024; + + pbc_param_t par; + pbc_param_init_e_gen(par, rbits, qbits); + pbc_param_out_str(stdout, par); + pbc_param_clear(par); + return 0; +} diff --git a/moon-abe/pbc-0.5.14/gen/genfparam.c b/moon-abe/pbc-0.5.14/gen/genfparam.c new file mode 100644 index 00000000..d7118dad --- /dev/null +++ b/moon-abe/pbc-0.5.14/gen/genfparam.c @@ -0,0 +1,24 @@ +// Generate type F pairings. +// Usage: +// genaparam [BITS] +// +// BITS +// The number of bits in r, the order of the subgroup G1. Default is 160. + +#include "pbc.h" + +int main(int argc, char **argv) { + int bits = 160; + if (argc > 1) { + bits = atoi(argv[1]); + if (bits < 1) { + pbc_die("Usage: %s [BITS]", argv[0]); + } + } + pbc_param_t fp; + pbc_param_init_f_gen(fp, bits); + pbc_param_out_str(stdout, fp); + pbc_param_clear(fp); + + return 0; +} diff --git a/moon-abe/pbc-0.5.14/gen/gengparam.c b/moon-abe/pbc-0.5.14/gen/gengparam.c new file mode 100644 index 00000000..064f2b76 --- /dev/null +++ b/moon-abe/pbc-0.5.14/gen/gengparam.c @@ -0,0 +1,33 @@ +// Generate Freeman curves with a given discriminant. +#include "pbc.h" + +int generate(pbc_cm_t cm, void *data) { + UNUSED_VAR(data); + pbc_param_t param; + + pbc_info("gengparam: computing Hilbert polynomial and finding roots..."); + pbc_param_init_g_gen(param, cm); + pbc_info("gengparam: bits in q = %zu", mpz_sizeinbase(cm->q, 2)); + pbc_param_out_str(stdout, param); + pbc_param_clear(param); + return 1; +} + +int main(int argc, char **argv) { + int D = 35707; + + if (argc > 1) { + int m; + D = atoi(argv[1]); + m = D % 120; + if (D <= 0 || (m != 43 && m != 67)) { + pbc_die("D must be 43 or 67 mod 120 and positive"); + } + } + pbc_info("Using D = %d", D); + + if (!pbc_cm_search_g(generate, NULL, D, 500)) { + pbc_die("No suitable curves for this D"); + } + return 0; +} diff --git a/moon-abe/pbc-0.5.14/gen/hilbertpoly.c b/moon-abe/pbc-0.5.14/gen/hilbertpoly.c new file mode 100644 index 00000000..2e73af4e --- /dev/null +++ b/moon-abe/pbc-0.5.14/gen/hilbertpoly.c @@ -0,0 +1,57 @@ +// Prints Hilbert polynomials H_D(X) +// +// Usage: hilbertpoly [LOWER [UPPER]] +// +// LOWER: +// Lower limit of D. Defaults to 3. +// UPPER: +// Upper limit of D. Defaults to LOWER. +// +// e.g. $ hilbertpoly 3 1000000 +#include <stdarg.h> +#include <stdio.h> +#include <stdint.h> // for intptr_t +#include <stdlib.h> //for atoi, exit +#include <gmp.h> +#include "pbc_utils.h" +#include "pbc_hilbert.h" + +static void xpow(int degree) { + if (degree == 1) { + printf("X"); + } else if (degree) { + printf("X^%d", degree); + } +} + +int main(int argc, char **argv) { + int D = argc > 1 ? atoi(argv[1]) : 3; + if (D <= 0) pbc_die("D must be positive."); + + int Dlimit = argc > 2 ? atoi(argv[2]) : D; + + for(; D <= Dlimit; D++) { + mpz_t *coefflist; + int m = D % 4; + if (m == 1 || m == 2) continue; + printf("D = %d\n", D); + + int n = pbc_hilbert(&coefflist, D); + + printf(" "); + xpow(n - 1); + printf("\n"); + int i; + for (i = n - 2; i >= 0; i--) { + if (mpz_sgn(coefflist[i]) >= 0) { + printf("+"); + } + mpz_out_str(stdout, 0, coefflist[i]); + xpow(i); + printf("\n"); + } + pbc_hilbert_free(coefflist, n); + } + + return 0; +} diff --git a/moon-abe/pbc-0.5.14/gen/listfreeman.c b/moon-abe/pbc-0.5.14/gen/listfreeman.c new file mode 100644 index 00000000..f3f18cc4 --- /dev/null +++ b/moon-abe/pbc-0.5.14/gen/listfreeman.c @@ -0,0 +1,38 @@ +// List discriminant and bits in r and q for type G pairings that may be +// suitable for cryptography. + +#include "pbc.h" + +int show(pbc_cm_t cm, void *data) { + unsigned int D = * (unsigned *) data; + int qbits, rbits; + qbits = mpz_sizeinbase(cm->q, 2); + rbits = mpz_sizeinbase(cm->r, 2); + printf("%d, %d, %d\n", D, qbits, rbits); + fflush(stdout); + return 0; +} + +void try(int tryD) { + pbc_cm_search_g(show, &tryD, tryD, 500); +} + +int main(int argc, char **argv) { + unsigned int D = 0; + + if (argc > 1) { + D = atoi(argv[1]); + if (D % 120) { + pbc_die("D must be multiple of 120"); + } + } + + printf("D < %u, bits in q, bits in r\n", 1000000000); + while (D < 1000000000) { + try(D + 43); + try(D + 67); + D+=120; + } + + return 0; +} diff --git a/moon-abe/pbc-0.5.14/gen/listmnt.c b/moon-abe/pbc-0.5.14/gen/listmnt.c new file mode 100644 index 00000000..a9160eab --- /dev/null +++ b/moon-abe/pbc-0.5.14/gen/listmnt.c @@ -0,0 +1,41 @@ +// For different discriminants D, list group size and representation size +// of resulting MNT curves. + +#include "pbc.h" + +int consider(pbc_cm_t cm, void *data) { + unsigned int D = * (unsigned *) data; + int qbits, rbits; + qbits = mpz_sizeinbase(cm->q, 2); + rbits = mpz_sizeinbase(cm->r, 2); + printf("%d, %d, %d\n", D, qbits, rbits); + fflush(stdout); + return 0; +} + +void try(unsigned int D) { + pbc_cm_search_d(consider, &D, D, 500); +} + +int main(int argc, char **argv) +{ + unsigned int D = 7; + + if (argc > 1) { + D = atoi(argv[1]); + if (D < 7 || (D % 4) != 3) { + pbc_die("D must be 3 mod 4 and at least 7"); + } + } + + const unsigned int maxD = 1000000000; + printf("D < %u, bits in q, bits in r\n", maxD); + while (D < maxD) { + try(D); + D++; + try(D); + D+=3; + } + + return 0; +} |