int main(int argc, char *argv[]) { int status = -1; dhuser_t alice, bob; s_memclr(&alice, sizeof(dhuser_t)); s_memclr(&bob, sizeof(dhuser_t)); if(argc != 2) goto err; int ac = dh_init(&alice, SERVER); int bc = dh_init(&bob, CLIENT); if(ac != 0 || bc != 0) goto err; int mod_len = check_size(atoi(argv[1]),0); if(mod_len < 0) goto err; if(dh_generateParameters(&alice, mod_len, mod_len, mod_len) < 0) goto err; if(dh_setParameters(&bob, mod_len, mod_len, mod_len, alice.P, alice.G) < 0) goto err; if(dh_generatePrivateKey(&alice) < 0 || dh_generatePrivateKey(&bob) < 0) goto err; dh_generateSharedKey(&alice); dh_generateSharedKey(&bob); if(dh_computeSecret(&alice, bob.Shared_E) < 0 || dh_computeSecret(&bob, alice.Shared_F) < 0) goto err; char* alice_hash = dh_computePublicHash(&alice); char* bob_hash = dh_computePublicHash(&bob); if(!alice_hash || !bob_hash) goto err; byte sig_buf[2048]; s_memclr(sig_buf, 2048); unsigned int sig_len = sizeof(sig_buf); sign(alice_hash, sig_buf, &sig_len); printf("%u\n",sig_len); if(verify(bob_hash, sig_buf, sig_len) != 1) printf("Authentication failed\n"); else printf("Secret sharing successful\n"); status = 0; err: if(alice_hash) delete(alice_hash, strlen(alice_hash)); if(bob_hash) delete(bob_hash, strlen(bob_hash)); dh_destroy(&alice); dh_destroy(&bob); return status; }
// ----------------------------------------------------------------------- int main(int argc, char **argv) { int ret = 1; int res; FILE *outf; res = parse_args(argc, argv); if (res) { printf("\n"); usage(); goto cleanup; } if (kw_init() < 0) { printf("Internal dictionary initialization failed.\n"); goto cleanup; } sym = dh_create(16000, 1); if (!sym) { printf("Failed to create symbol table.\n"); goto cleanup; } if (input_file) { yyin = fopen(input_file, "r"); loc_push(input_file); } else { yyin = stdin; loc_push("(stdin)"); } if (!yyin) { printf("Cannot open source file: '%s'\n", input_file); goto cleanup; } inc_path_add("."); AADEBUG("==== Parse ================================"); if (yyparse()) { if (yyin) fclose(yyin); goto cleanup; } if (yyin) fclose(yyin); if (!program) { // shouldn't happen - parser should always produce program (even empty one) printf("Parse produced empty tree.\n"); goto cleanup; } res = assemble(program, 1); if (res < 0) { printf("%s\n", aerr); goto cleanup; } else if (res > 0) { if (otype == O_EMELF) { if (assemble(program, 1) < 0) { printf("%s\n", aerr); goto cleanup; } } else { if (assemble(program, 0)) { printf("%s\n", aerr); goto cleanup; } } } if (otype != O_DEBUG) { if (!output_file) { output_file = strdup("a.out"); } outf = fopen(output_file, "w"); } else { if (!output_file) { output_file = strdup("(stdout)"); } outf = stdout; } if (!outf) { printf("Cannot open output file '%s' for writing\n", output_file); goto cleanup; } switch (otype) { case O_RAW: res = writer_raw(program, outf); break; case O_DEBUG: res = writer_debug(program, outf); break; case O_EMELF: res = writer_emelf(program, sym, outf); break; default: printf("Unknown output type.\n"); fclose(outf); goto cleanup; } fclose(outf); if (res) { printf("%s\n", aerr); goto cleanup; } ret = 0; cleanup: yylex_destroy(); st_drop(inc_paths); st_drop(filenames); st_drop(program); dh_destroy(sym); st_drop(entry); kw_destroy(); free(output_file); return ret; }