int main() //@ : main_full(main_app) //@ requires module(main_app, true); //@ ensures true; { struct keypair *apair; struct keypair *pair; struct item *key; struct item *pub_key; struct item *priv_key; printf("\n\tExecuting \""); printf("auth secure_storage"); printf("protocol"); printf("\" ... \n\n"); //@ open_module(); //@ PACK_PROOF_OBLIGATIONS(ss_auth) init_crypto_lib(); int attacker = create_principal(&apair); //@ assume (bad(attacker)); int sender = create_principal(&pair); pub_key = keypair_get_public_key(pair); priv_key = keypair_get_private_key(pair); keypair_free(pair); void *null = (void *) 0; //@ leak world(ss_auth_pub); { pthread_t a_thread; struct ss_auth_args *args = malloc(sizeof(struct ss_auth_args)); if (args == 0) abort(); args->attacker = attacker; args->keypair = apair; //@ close pthread_run_pre(attacker_t)(args, _); pthread_create(&a_thread, NULL, &attacker_t, args); } int i = 0; #ifdef EXECUTE while (i++ < 10) #else while (true) #endif /*@ invariant [_]world(ss_auth_pub) &*& generated_values(_, _) &*& item(pub_key, public_key_item(sender, _), ss_auth_pub) &*& item(priv_key, private_key_item(sender, _), ss_auth_pub); @*/ { pthread_t s_thread, r_thread; struct ss_auth_args *args_s = malloc(sizeof(struct ss_auth_args)); if (args_s == 0) abort(); struct ss_auth_args *args_r = malloc(sizeof(struct ss_auth_args)); if (args_r == 0) abort(); args_s->key = priv_key; args_r->key = pub_key; { /*@ close pthread_run_pre(sender_t)(args_s, cons(pointer_value(priv_key), cons(int_value(sender), nil))); @*/ pthread_create(&s_thread, null, &sender_t, args_s); /*@ close pthread_run_pre(receiver_t)(args_r, cons(pointer_value(pub_key), cons(int_value(sender), nil))); @*/ pthread_create(&r_thread, null, &receiver_t, args_r); } { pthread_join(r_thread, null); //@ open pthread_run_post(receiver_t)(args_r, _); pthread_join(s_thread, null); //@ open pthread_run_post(sender_t)(args_s, _); } free(args_s); free(args_r); } //@ close_module(); //@ leak module(main_app, _); printf("Done\n"); }
int main(int argc, char* argv[]) { bool i = false, o = false, e = false, d = false, k = false; int c; char input_path[255]; char output_path[255]; char key_path[255]; FILE* input_file; FILE* output_file; FILE* key_file; mpz_t kn, ke, kd; keypair_t kp; while ((c = getopt(argc, argv, "i:o:edk:")) != -1) { switch (c) { case 'i': i = true; strcpy(input_path, optarg); break; case 'o': o = true; strcpy(output_path, optarg); break; case 'e': e = true; break; case 'd': d = true; break; case 'k': k = true; strcpy(key_path, optarg); break; default: abort(); } } if (i && o && k) { if (!e && !d || e && d) { fprintf(stderr, "You must select EITHER e or d.\n"); return 1; } input_file = fopen(input_path, "rb"); output_file = fopen(output_path, "wb"); key_file = fopen(key_path, "r"); if (!(input_file && output_file && key_file)) { printf("wtf?\n"); return 1; } else { mpz_inits(kn, ke, kd, NULL); gmp_fscanf(key_file, "%Zd %Zd %Zd", kn, ke, kd); fclose(key_file); kp = keypair_init_p(kn, ke, kd); if (e) { keypair_file_encrypt(kp, input_file, output_file); } else { keypair_file_decrypt(kp, input_file, output_file); } fclose(input_file); fclose(output_file); mpz_clears(kn, ke, kd, NULL); keypair_free(kp); return 0; } } else { fprintf(stderr, "\n### Usage:\n"); fprintf(stderr, "%s -i file1 -o file2 -k keyfile -{e,d}\n", argv[0]); fprintf(stderr, "-i\tinput file\n"); fprintf(stderr, "-o\toutput file\n"); fprintf(stderr, "-k\tkey file\n"); fprintf(stderr, "-e\tencrypt\n"); fprintf(stderr, "-d\tdecrypt\n\n"); return 1; } }