Пример #1
0
void CipherText::compute_node(element_t& v, Node* node){//v amounts to s
  if(node->getType() == LEAF){
    Leaf* leaf = (Leaf*)node;
    leaf->compute(&v, this->pub, this->p);
  //  printf("leaf: %d, %d, computed\n", leaf->getK(), leaf->getNum());

  } else if (node->getType() == INTERNAL_NODE){

    InternalNode* internalNode = (InternalNode*)node;
    int num = internalNode->getNum();
    int k = internalNode->getK();
    Node** sons = internalNode->getSons();//??

  //  printf("internal Node: %d, %d\n", k, num);

    element_t* ys = (element_t*)malloc(sizeof(element_t) *  (num + 1));      
    element_init_Zr(ys[0], *(this->p));
    element_set(ys[0], v);                          //set ys[0] to v
    computePoints(ys, k, num);       //compute other num point, 
    int i = 1;
    for (i = 1; i <= num; i++){
      compute_node(ys[i], sons[i - 1]);
    }
  }
}
Пример #2
0
Policy::Policy(unsigned char* buf, pairing_t* p) {
  //get nodeNum
  int pos = 0;
  int numberOfNode = Utility::str2int(buf);
  pos += 4;

//  printf("node num is %d\n", numberOfNode);
  this->nodeNum = numberOfNode;

  //reconstruct access tree form bytes
  Node** nodes = (Node**)malloc(sizeof(Node*) * this->nodeNum);  //store all nodes
  int index = 0;
  Node* node = NULL;
  int nodeSize = 0;
  for(index = 0; index < numberOfNode; index++){
    printf("index: %d\n", index);
    //get father position
    int father = Utility::str2int(buf + pos);
    
    pos += 4;
    printf("father is %d\t", father);
    //get node size to indentify node type
    nodeSize = Utility::str2int(buf + pos);
    pos += 4;
    //printf("node size is %d\t", nodeSize);
    

    if(nodeSize == -1){
      nodeSize = INTERNAL_NODE_SIZE;
      node = new InternalNode(buf + pos);
      printf("internal node\t");
      InternalNode* t = (InternalNode*)node;
      printf("%d, %d\t", t->getK(), t->getNum());
    } else if(nodeSize == -2){
      nodeSize = LEAF_SIZE;
      node = new Leaf(buf + pos, p);
     // printf("leaf\t");
    } else {
      node = new ExLeaf((char*)(buf + pos), nodeSize);
    //  printf("ex leaf\t");
    }
    pos += nodeSize;
    nodes[index] = node;

    if(father == -1){
      this->root = node;
    } else {
      this->addSon(nodes[father],node);
    }
   // printf("add son to node %d\n", father);
  }

//  printf("reconstruct node ok\n");
  free(nodes);
}