Exemple #1
0
inline int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
		AES_KEY *key) {
	AES_KEY temp_key;
	AES_set_encrypt_key(userKey, bits, &temp_key);
	AES_set_decrypt_key_fast(key, &temp_key);
	return 0;
}
Exemple #2
0
static int
computeOutputs(const OutputInstructions *ois, int *output,
               block **computed_outputmap)
{
    assert(output && "output's memory should be allocated");

    for (uint16_t i = 0; i < ois->size; ++i) {
        AES_KEY key;
        block out[2], b_zero, b_one;
        OutputInstruction *oi = &ois->output_instruction[i];

        // decrypt using comp_block as key
        block comp_block = computed_outputmap[oi->gc_id][oi->wire_id];

        /* XXX: huh?  why does calling AES_set_decrypt_key not work!? */
        /* AES_set_decrypt_key(comp_block, &key); */
        {
            AES_KEY temp_key;
            AES_set_encrypt_key(comp_block, &temp_key);
            AES_set_decrypt_key_fast(&key, &temp_key);
        }
        out[0] = oi->labels[0];
        out[1] = oi->labels[1];
        AES_ecb_decrypt_blks(out, 2, &key);

        b_zero = garble_zero_block();
        b_one = garble_make_block((uint64_t) 0, (uint64_t) 1); // 000...00001

        if (garble_equal(out[0], b_zero) || garble_equal(out[1], b_zero)) {
            output[i] = 0;
        } else if (garble_equal(out[0], b_one) || garble_equal(out[1], b_one)) {
            output[i] = 1;
        } else {
            fprintf(stderr, "Could not compute output[%d] from (gc_id: %d, wire_id: %d)\n",
                    i, oi->gc_id, oi->wire_id);
            /* assert(false); */
            return FAILURE;
        }
    }
    return SUCCESS;
}