コード例 #1
0
ファイル: bce.c プロジェクト: loiluu/weshare
void Decrypt_BC_KEM_using_indicies(global_broadcast_params_t gbp, 
				   priv_key_t mykey, element_t key,
				   ct_t myct, int *in_recip, int num_recip)
{
  if(!mykey) {
    printf("\nyou didn't give me a valid key.  I die\n");
    return;
  } 
  Gen_decr_prod_from_indicies(gbp, mykey->index,in_recip, num_recip, mykey);
  DecryptKEM_using_product(gbp, mykey, key, myct);  
}
コード例 #2
0
ファイル: bcejni.c プロジェクト: YingquanYuan/bce-suite
int BCEDecrypt(byte *global_params_path, byte *priv_key_block, byte *CT_C0, byte *CT_C1, byte *symmetric_key_out)
{
    global_broadcast_params_t gbs;
    priv_key_t priv_key;
    ct_t shared_CT;
    element_t symmetric_key;
    int suffix = 0, retlen;

    if (global_params_path == NULL)
        return 1;
    if (priv_key_block == NULL)
        return 2;
    if (CT_C0 == NULL)
        return 3;
    if (CT_C1 == NULL)
        return 4;
    if (symmetric_key_out == NULL)
        return 5;

    LoadGlobalParams((char *) global_params_path, &gbs);

    priv_key = (priv_key_t) pbc_malloc(sizeof(struct single_priv_key_s));
    // restore index
    priv_key->index = bytes_to_int(priv_key_block);
    suffix += PRK_INDEX_LENGTH;

    // restore g_i_gamma
    element_init(priv_key->g_i_gamma, gbs->pairing->G1);
    retlen = element_from_bytes(priv_key->g_i_gamma, priv_key_block + suffix);
    if (retlen != PRK_G_I_GAMMA_LENGTH)
        return 6;
    suffix += PRK_G_I_GAMMA_LENGTH;

    // restore g_i
    element_init(priv_key->g_i, gbs->pairing->G1);
    retlen = element_from_bytes(priv_key->g_i, priv_key_block + suffix);
    if (retlen != PRK_G_I_LENGTH)
        return 7;
    suffix += PRK_G_I_LENGTH;

    // restore h_i
    element_init(priv_key->h_i, gbs->pairing->G2);
    retlen = element_from_bytes(priv_key->h_i, priv_key_block + suffix);
    if (retlen != PRK_H_I_LENGTH)
        return 8;
    suffix += PRK_H_I_LENGTH;

    // restore decr_prod
    element_init(priv_key->decr_prod, gbs->pairing->G1);
    retlen = element_from_bytes(priv_key->decr_prod, priv_key_block + suffix);
    if (retlen != PRK_DECR_PROD_LENGTH)
        return 9;

    shared_CT = (ct_t) pbc_malloc(sizeof(struct ciphertext_s));
    element_init(shared_CT->C0, gbs->pairing->G2);
    element_init(shared_CT->C1, gbs->pairing->G1);
    element_from_bytes(shared_CT->C0, CT_C0);
    element_from_bytes(shared_CT->C1, CT_C1);

    DecryptKEM_using_product(gbs, priv_key, symmetric_key, shared_CT);

    retlen = element_to_bytes(symmetric_key_out, symmetric_key);
    if (retlen != SYMMETRIC_KEY_LENGTH)
        return 10;

    element_random(symmetric_key);
    element_clear(symmetric_key);
    FreeCT(shared_CT);
    pbc_free(shared_CT);
    FreePK(priv_key);
    pbc_free(priv_key);
    FreeGBP(gbs);
    pbc_free(gbs);

    return 0;
}