コード例 #1
0
ファイル: ibetest.c プロジェクト: argp/ibe-win32
int
main(void)
{
 char *id = "argp at domain cs.tcd.ie";
 params_t params;
 byte_string_t U;
 byte_string_t secret;
 byte_string_t key;
 byte_string_t master;

 IBE_init();

 IBE_setup(params, master, 512, 160, "test");
 printf("system parameters generated!\n");

 printf("IBE test program\n");
 printf("Test ID: %s\n", id);

 printf("generating key...\n");
 IBE_KEM_encrypt(secret, U, id, params);

 printf("U =");
 byte_string_printf(U, " %02X");
 printf("\n");

 printf("secret =");
 byte_string_printf(secret, " %02X");
 printf("\n");
 byte_string_clear(secret);

 printf("extracting...\n");
 IBE_extract(key, master, id, params);

 printf("recovering secret...\n");
 IBE_KEM_decrypt(secret, U, key, params);

 /* hopefully it will be the same as above */
 printf("secret =");
 byte_string_printf(secret, " %02X");
 printf("\n");

 params_clear(params);
 IBE_clear();
 byte_string_clear(U);
 byte_string_clear(key);
 byte_string_clear(secret);
 byte_string_clear(master);
 
 return(0);
}
コード例 #2
0
int main()
{
    params_t params;
    byte_string_t priv, pub;
    byte_string_t priv2, pub2;
    byte_string_t sig;
    byte_string_t message;
    byte_string_t master;

    IBE_init();

    IBE_setup(params, master, 512, 160, "test");

    //generate a BLS private/public key pair
    BLS_keygen(priv, pub, params);

    BLS_keygen(priv2, pub2, params);

    byte_string_set(message, "Hello, World");

    BLS_sign(sig, message, priv, params);
    printf("Sig: ");
    byte_string_fprintf(stdout, sig, " %02X");
    printf("\n");

    if (BLS_verify(sig, message, pub, params)) {
        printf("signature verifies\n");
    } else {
        printf("bug: signature does not verify\n");
    }

    if (BLS_verify(sig, message, pub2, params)) {
        printf("bug: signature verifies with wrong public key\n");
    }

    params_clear(params);

    IBE_clear();

    return 0;
}
コード例 #3
0
ファイル: gen.c プロジェクト: hyxer/AndroidAppIBE
int main(int argc, char **argv)
{
    char defaultcnffile[] = "gen.cnf";
    char *cnffile;
    CONF_CTX *cnfctx;
    int t, n;
    int bits, qbits;
    char *systemid;
    char *paramsfile;
    char **sharefile;

    char *dfltlist[3];
    char dl0[] = "share";
    char dl1[] = "share2";

    int i;

    byte_string_t master;

    params_t params;

    if (argc < 2) {
	cnffile = defaultcnffile;
    } else {
	cnffile = argv[1];
    }

    cnfctx = LoadConfig(cnffile);

    if (!cnfctx) {
	fprintf(stderr, "error opening %s\n", cnffile);
	fprintf(stderr, "using default values\n");
	cnfctx = constructCTX();
	//exit(1);
    }

    t = GetIntParam(cnfctx, "threshold", 0, 2);
    n = GetIntParam(cnfctx, "shares", 0, 2);
    bits = GetIntParam(cnfctx, "pbits", 0, 1024);
    qbits = GetIntParam(cnfctx, "qbits", 0, 160);
    systemid = GetStringParam(cnfctx, "system", 0, "noname");
    paramsfile = GetPathParam(cnfctx, "params", 0, "params.txt");
    dfltlist[0] = dl0;
    dfltlist[1] = dl1;
    sharefile = GetListParam(cnfctx, "sharefiles", 0, dfltlist);

    printf("Generating IBE public parameters and secret...\n");
    printf("Parameters:\n");
    printf("system name: %s\n", systemid);
    printf("params file: %s\n", paramsfile);
    printf("%d-out-of-%d sharing\n", t, n);
    printf("%d-bit prime\n", bits);
    printf("%d-bit subgroup\n", qbits);
    printf("share files:\n");
    for (i=0; i<n; i++) {
	if (sharefile[i] == NULL) {
	    fprintf(stderr, "not enough filenames given\n");
	    exit(1);
	}
	printf("   %s\n", sharefile[i]);
    }

    IBE_init();
    IBE_setup(params, master, bits, qbits, systemid);

    FMT_split_master(sharefile, master, t, n, params);

    FMT_save_params(paramsfile, params);

    // test it works
    if (0) {
	byte_string_t key;
	//FMT_construct_master(key, sharefile, t);
	IBE_extract(key, master, "*****@*****.**", params);
	byte_string_clear(key);
    }

    byte_string_clear(master);

    params_clear(params);

    IBE_clear();

    return 0;
}
コード例 #4
0
ファイル: infect.c プロジェクト: hyxer/AndroidAppIBE
int main(int argc, char **argv)
{
    char *field;
    char *ampptr;
    char *query;
    char *token;
    int status;
    char defaultcnffile[] = "infect.cnf";
    char *cnffile, *paramsfile;
    CONF_CTX *cnfctx;
    char *unencfile;
    char *email, *subject;
    char *id;

    if (argc < 2) {
	printf("Usage: infect id=<email address>\n");
	return 0;
    }
    if (argc > 2) {
	cnffile = argv[1];
	query = argv[2];
    } else {
	cnffile = defaultcnffile;
	query = argv[1];
    }

    cnfctx = LoadConfig(cnffile);

    if (!cnfctx) {
	fprintf(stderr, "error opening %s\n", cnffile);
	fprintf(stderr, "using default values\n");
	cnfctx = constructCTX();
    }

    paramsfile = GetPathParam(cnfctx, "params", 0, "params.txt");
    mailprog = GetPathParam(cnfctx, "mail", 0, "/usr/bin/mail");
    encfile = GetPathParam(cnfctx, "messagefile", 0, "firstmessage.txt");
    unencfile = GetPathParam(cnfctx, "helpfile", 0, "instructions.txt");

    printf("Infecting %s\n", query);
    /*
    cout << "params file: " << paramsfile << endl;
    cout << "mailer: " << mailprog << endl;
    cout << "instructions: " << unencfile << endl;
    cout << "message: " << encfile << endl;
    */

    status = FMT_load_raw_byte_string(plainmessage, unencfile);
    if (status != 1) {
	fprintf(stderr, "error opening instructions\n");
    }

    IBE_init();
    status = FMT_load_params(params, paramsfile);
    if (status != 1) {
	fprintf(stderr, "Error loading params file %s\n", paramsfile);
	return(1);
    }

    email = NULL;
    subject = NULL;

    token = (char *) malloc(strlen(query) + 1);

    ampptr = query;
    ampptr = get_token(token, ampptr, '&');
    while(ampptr) {
	if (!(field = index(token, '='))) {
	    fprintf(stderr, "Malformed query\n");
	    return 1;
	}
	field[0] = 0;
	field++;
	if (!strcmp(token, "id")) {
	    email = (char *) malloc(strlen(field));
	    strcpy(email, field);
	    translate(email);
	} else if (!strcmp(token, "subject")) {
	    subject = (char *) malloc(strlen(field));
	    strcpy(subject, field);
	    translate(subject);
	}
	ampptr = get_token(token, ampptr, '&');
    }

    if (!email) {
	//char errmsg[] = "Must supply email address and password.";
	fprintf(stderr, "bad ID\n");
	return 1;
    }
    id = FMT_make_id(email, subject, params);
    infect(email, id);

    free(id);
    free(email);
    free(subject);
    free(token);

    params_clear(params);
    IBE_clear();

    return 0;
}