コード例 #1
0
ファイル: block.c プロジェクト: amaloz/libgarble
inline block
garble_random_block(void)
{
    block out;
    uint64_t *val;
    int i;

    out = garble_zero_block();
    val = (uint64_t *) &out;
    val[0] = current_rand_index++;
    out = _mm_xor_si128(out, rand_aes_key.rd_key[0]);
    for (i = 1; i < 10; ++i)
        out = _mm_aesenc_si128(out, rand_aes_key.rd_key[i]);
    return _mm_aesenclast_si128(out, rand_aes_key.rd_key[i]);
}
コード例 #2
0
ファイル: block.c プロジェクト: amaloz/libgarble
block
garble_seed(block *seed)
{
    block cur_seed;
    current_rand_index = 0;
    if (seed) {
        cur_seed = *seed;
    } else {
        if (RAND_bytes((unsigned char *) &cur_seed, 16) == 0) {
            fprintf(stderr, "** unable to seed securely\n");
            return garble_zero_block();
        }
    }
    AES_set_encrypt_key(cur_seed, &rand_aes_key);
    return cur_seed;
}
コード例 #3
0
ファイル: 2pc_evaluator.c プロジェクト: aled1027/CompGC
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;
}