예제 #1
0
int _start(void) {
    crash_handler_word[0] = crash_handler;
    int max = 1000;
    cursor_pos = INITIAL_CURSOR_POS;
    clear_screen_with_border(BACKGROUND, FOREGROUND, border_size);
    banner();
    uint32_t number = (getrand()%max)+1;
    int remaining = 1337;

    while(1) {
        char buffer[32] = {0};
        char *episode_name = NULL;
        int season = getrand()%7;;
        int episode_number;
        if(season == 0) {
            episode_number = getrand()%12;
        }
        else {
            episode_number = getrand()%22;
        }
        episode_name = episodes[season][episode_number];
        episode_number++;
        season++;
        //format the question
        question[29] = (episode_number >= 10) ? ('0' + (episode_number/10)) : ' ';
        question[30] = '0' + (episode_number%10);
        question[42] = '0' + season;

        //ask the question
        process_string(question);

        process_text(buffer);
        if(0 == strcasecmp(buffer,episode_name)) {
            if(remaining == 0) {
                print_secret();
                break;
            }
            else {
                process_string("Correct! get ");
                print_number(remaining--);
                process_string(" more correct to learn the password\r\r");
            }
        }
        else {
            process_string("Wrong! The answer is \"");
            process_string(episode_name);
            process_string("\"\r\r");
        }
    }
    //infinite loop
    while(1) {
        wait_for_interrupt();
    }
}
예제 #2
0
static int check_prime(ENGINE *engine, struct prime *pr)
{
    DH *dh1, *dh2;
    BIGNUM *p, *g;
    unsigned char *sec1, *sec2;
    size_t size;
    int ret;

    if (verbose)
	printf("Testing %s\n", pr->name);

    p = BN_new();
    g = BN_new();
    dh1 = DH_new_method(engine);
    dh2 = DH_new_method(engine);

    /* 1. set shared parameter */
    set_prime(p, pr->value);
    set_generator(g);
    dh1->p = BN_dup(p);
    dh1->g = BN_dup(g);
    dh2->p = BN_dup(p);
    dh2->g = BN_dup(g);

    /* 2. set keys */
    ret = DH_generate_key(dh1);
    if (ret == 0) {
	fprintf(stderr, "DH_generate_key\n");
	exit(EXIT_FAILURE);
    }
    ret = DH_generate_key(dh2);
    if (ret == 0) {
	fprintf(stderr, "DH_generate_key\n");
	exit(EXIT_FAILURE);
    }

    /* 3. compute shared secret */
    size = DH_size(dh1);
    if (size != DH_size(dh2)) {
	fprintf(stderr, "size does not match!\n");
	exit(EXIT_FAILURE);
    }
    sec1 = malloc(size);
    sec2 = malloc(size);
    if (!sec1 || !sec2) {
	perror("malloc");
	exit(EXIT_FAILURE);
    }
    ret = DH_compute_key(sec1, dh2->pub_key, dh1);
    if (ret == -1) {
	fprintf(stderr, "DH_compute_key");
	exit(EXIT_FAILURE);
    }
    ret = DH_compute_key(sec2, dh1->pub_key, dh2);
    if (ret == -1) {
	fprintf(stderr, "DH_compute_key");
	exit(EXIT_FAILURE);
    }

    /* 4. compare shared secret */
    if (verbose) {
	printf("shared secret 1\n");
	print_secret(sec1, size);
	printf("shared secret 2\n");
	print_secret(sec2, size);
    }

    if (memcmp(sec1, sec2, size) == 0)
	ret = 1;
    else
	ret = 0;

    free(sec2);
    free(sec1);
    DH_free(dh2);
    DH_free(dh1);
    BN_free(g);
    BN_free(p);

    return ret;
}