コード例 #1
0
ファイル: serialization.c プロジェクト: amintimany/verifast
int serialize_to_public_message(char** dest, struct item* item)
  /*@ requires [?f0]world(?pub, ?key_clsfy) &*&
               [?f1]item(item, ?i, pub) &*& pointer(dest, _) &*&
               [_]pub(i); @*/
  /*@ ensures  [f0]world(pub, key_clsfy) &*&
               [f1]item(item, i, pub) &*& pointer(dest, ?d) &*&
               malloc_block(d, result) &*& result > 1 &*&
               chars(d, result, ?cs) &*&
               [_]item_constraints(i, cs, pub); @*/
{
  int size;
  char* temp;
  //@ open [f1]item(item, i, pub);
  //@ assert [f1]item->content |-> ?cont;
  size = item->size;
  //@ assert [f1]crypto_chars(secret, cont, size, ?cs);

  temp = malloc_wrapper(size);
  memcpy(temp, item->content, (unsigned int) size);
  *dest = temp;

  //@ open [f0]world(pub, key_clsfy);
  //@ close [f0]world(pub, key_clsfy);
  //@ retreive_proof_obligations();
  //@ assert [_]item_constraints(i, cs, pub);
  //@ serialize_item(i);
  //@ public_crypto_chars(temp, size);
  //@ leak proof_obligations(pub);
  //@ close [f1]item(item, i, pub);

  return size;
}
コード例 #2
0
struct item* deserialize(char* buffer, int size)
  /*@ requires [?f0]world(?pub, ?key_clsfy) &*&
               [?f1]chars(buffer, size, ?cs); @*/
  /*@ ensures  [f0]world(pub, key_clsfy) &*&
               [f1]chars(buffer, size, cs) &*&
               item(result, ?i, pub) &*& [_]pub(i); @*/
{
  if (size <= MINIMAL_STRING_SIZE)
    abort_crypto_lib("Found corrupted item during deserialization");

  struct item* item = malloc(sizeof(struct item));
  if (item == 0){abort_crypto_lib("malloc of item failed");}

  //@ open [f0]world(pub, key_clsfy);
  //@ public_chars(buffer, size);
  //@ close [f0]world(pub, key_clsfy);
  item->size = size;
  item->content = malloc_wrapper(item->size);
  //@ assert item->content |-> ?cont;
  //@ chars_to_crypto_chars(buffer, size);
  //@ assert [f1]crypto_chars(normal, buffer, size, ?ccs);
  memcpy(item->content, buffer, (unsigned int) size);
  //@ get_forall_t<char>();
  //@ get_forall_t<list<char> >();
  parse_item(buffer, size);
  //@ retreive_proof_obligations();
  //@ deserialize_item(ccs);
  //@ leak proof_obligations(pub);
  //@ assert [_]item_constraints(?i, ccs, pub) &*& [_]pub(i);
  //@ cs_to_ccs_crypto_chars(cont, cs);
  //@ cs_to_ccs_crypto_chars(buffer, cs);
  //@ chars_to_secret_crypto_chars(cont, size);
  //@ close item(item, i, pub);
  return item;
}
コード例 #3
0
ファイル: hash_item.c プロジェクト: amintimany/verifast
struct item *create_hash(struct item *payload)
  /*@ requires [?f0]world(?pub, ?key_clsfy) &*&
               [?f1]item(payload, ?pay, pub); @*/
  /*@ ensures  [f0]world(pub, key_clsfy) &*&
               [f1]item(payload, pay, pub) &*& item(result, ?hash, pub) &*& 
               col || hash == hash_item(some(pay)); @*/
{
  //@ open [f1]item(payload, pay, pub);
  //@ open [_]item_constraints(pay, ?pay_cs, pub);
  //@ assert [f1]payload->content |-> ?p_cont &*& [f1]payload->size |-> ?p_size;
  struct item* hash = malloc(sizeof(struct item));
  if (hash == 0){abort_crypto_lib("malloc of item failed");}
  
  hash->size = TAG_LENGTH + HASH_SIZE;
  hash->content = malloc_wrapper(hash->size);
  write_tag(hash->content, TAG_HASH);
  
  if (payload->size < MINIMAL_STRING_SIZE)
    {abort_crypto_lib("Payload of hash was to small");}
  sha512(payload->content, (unsigned int) payload->size, hash->content + TAG_LENGTH, 0);
  
  //@ open [f0]world(pub, key_clsfy);  
  //@ assert hash->content |-> ?cont &*& hash->size |-> ?size;
  //@ public_chars(cont, TAG_LENGTH);
  //@ assert chars(cont, TAG_LENGTH, ?cs_tag);
  //@ assert cs_tag == full_tag(TAG_HASH);
  //@ open cryptogram(cont + TAG_LENGTH, HASH_SIZE, ?cs_cont, ?h_cg);
  //@ assert h_cg == cg_hash(pay_cs);
  //@ item h = hash_item(some(pay));
  //@ close ic_cg(h)(cs_cont, h_cg);
  //@ list<char> cs = append(cs_tag, cs_cont);
  //@ if (col) public_chars(cont + TAG_LENGTH, HASH_SIZE);
  //@ if (col) public_generated_join(polarssl_pub(pub), cs_tag, cs_cont);  
  //@ if (col) chars_to_secret_crypto_chars(cont + TAG_LENGTH, HASH_SIZE);
  //@ chars_to_secret_crypto_chars(cont, TAG_LENGTH);
  //@ crypto_chars_join(cont);
  //@ close [f0]world(pub, key_clsfy);
  //@ close ic_parts(h)(cs_tag, cs_cont);
  //@ WELL_FORMED(cs_tag, cs_cont, TAG_HASH)
  //@ close well_formed_item_chars(h)(pay_cs);
  //@ leak well_formed_item_chars(h)(pay_cs);
  //@ close item_constraints(h, cs, pub);
  //@ leak item_constraints(h, cs, pub);
  //@ close item(hash, h, pub);
  
  return hash;
  //@ close [f1]item(payload, pay, pub);
}
コード例 #4
0
ファイル: item.c プロジェクト: amintimany/verifast
struct item* item_clone(struct item* item)
  //@ requires [?f]item(item, ?i, ?pub);
  /*@ ensures  [f]item(item, i, pub) &*& 
               item(result, i, pub) &*& result != 0; @*/
{
  //@ open [f]item(item, i, pub);
  struct item* clone = malloc(sizeof(struct item));
  if (clone == 0){abort_crypto_lib("malloc of item failed");}
  clone->size = item->size;
  clone->content = malloc_wrapper(clone->size);
  memcpy(clone->content, item->content, (unsigned int) clone->size);

  return clone;
  //@ close [f]item(item, i, pub);
  //@ close item(clone, i, pub);
}
コード例 #5
0
ファイル: memory.c プロジェクト: akonecki/CodingProjects
treenode_t * insert(treenode_t ** root_ptr, const int value) {
    if (*root_ptr == NULL) {
        // tree is empty
        malloc_wrapper((void *)(root_ptr), sizeof(treenode_t));
        (*root_ptr)->value = value;
        return *root_ptr;
    }
    else {
        if ((*root_ptr)->value >= value) {
            // go left
            (*root_ptr)->left = insert(&(*root_ptr)->left, value);
            //((*root_ptr)->left) = insert(&(*root_ptr)->left, value);
        } 
        else {
            (*root_ptr)->right = insert(&(*root_ptr)->right, value);
        }    
        return *root_ptr;
    }
}
コード例 #6
0
ファイル: memory.c プロジェクト: akonecki/CodingProjects
int main(int argc, char * argv[]) {
    int * intPtr = NULL;
    volatile int number = 0;
    treenode_t * root = NULL;

    printf("intPtr is at address %p\n", &intPtr);
    malloc_wrapper((void *)&intPtr, 4);
    if (intPtr == NULL) {
        printf("could not malloc\n");
        return -1;
    }

    printf("intPtr is at address %p\n", &intPtr);
    printf("intPtr is pointing to %p\n", intPtr);

    free (intPtr);

    printf("is big endian result : %08x\n", isBigEndian());

    insert(&root, 1);
    printf("root is %p\n", root);
    traversal(root);
    insert(&root, 2);
    traversal(root);
    insert(&root, 3);
    traversal(root);
    insert(&root, 1);
    traversal(root);
    insert(&root, 2);
    traversal(root);
    insert(&root, 3);
    traversal(root);
    insert(&root, -1);
    traversal(root);
    insert(&root, 0);
    traversal(root);

    printf("\n");
    deleteTree(&root);

    return 0;
}
コード例 #7
0
ファイル: memory.c プロジェクト: donshanil/schoolwork
bool first_fit(Scheduler *s)
{
	//given the runnable list, fit the memory chunk in.
	//operation complete
	MemoryChunk* current_chunk;
	ProcessList* current_list;
	current_list = s->running;
	current_chunk = s->memory;
	while (current_chunk != NULL)
	{
		if (current_chunk->pid == -1)
		{
			if(current_chunk->size >= current_list->proc.mem_size)
			{
				//space found!
				MemoryChunk* new_chunk = malloc_wrapper(sizeof(MemoryChunk));
				current_chunk->size = current_chunk->size - (current_list->proc.mem_size);
				new_chunk->size = current_list->proc.mem_size;
				new_chunk->time = s->clock_time;
				new_chunk->pid = current_list->proc.pid;
				if(current_chunk->next != NULL)
				{	
					new_chunk->next = current_chunk->next;
				}
				else
				{
					new_chunk->next = NULL;
				}
				current_chunk->next = new_chunk;

				return true;
			}
		}
		current_chunk = current_chunk->next;
	}
	
	return false; //no space found.
}
コード例 #8
0
ファイル: pair_item.c プロジェクト: amintimany/verifast
struct item *create_pair(struct item *first, struct item *second)
  /*@ requires [?f0]world(?pub, ?key_clsfy) &*&
               [?f1]item(first, ?f, pub) &*& [?f2]item(second, ?s, pub); @*/
  /*@ ensures  [f0]world(pub, key_clsfy) &*&
               [f1]item(first, f, pub) &*& [f2]item(second, s, pub) &*&
               item(result, pair_item(f, s), pub); @*/
{
  //@ open [f0]world(pub, key_clsfy);
  struct item* pair = malloc(sizeof(struct item));
  if (pair == 0){abort_crypto_lib("malloc of item failed");}

  //@ open [f1]item(first, f, pub);
  //@ assert [f1]first->content |-> ?cont_f &*& [f1]first->size |-> ?size_f;
  //@ assert [f1]crypto_chars(secret, cont_f, size_f, ?cs_f);
  //@ assert [_]item_constraints(f, cs_f, pub);
  //@ well_formed_item_constraints(f, f);
  //@ open [_]well_formed_item_chars(f)(cs_f);
  //@ open [f2]item(second, s, pub);
  //@ assert [f2]second->content |-> ?cont_s &*& [f2]second->size |-> ?size_s;
  //@ assert [f2]crypto_chars(secret, cont_s, size_s, ?cs_s);
  //@ well_formed_item_constraints(s, s);
  //@ open [_]well_formed_item_chars(s)(cs_s);
  //@ assert [_]item_constraints(s, cs_s, pub);
  if (INT_MAX - TAG_LENGTH - (int) sizeof(int) - first->size < second->size)
    abort_crypto_lib("Requested pair item was to big");
  pair->size = TAG_LENGTH + (int) sizeof(int) + first->size + second->size;
  pair->content = malloc_wrapper(pair->size);
  //@ assert pair->content |-> ?cont &*& pair->size |-> ?size;
  write_tag(pair->content, TAG_PAIR);
  {
    //@ assert chars(cont, TAG_LENGTH, full_tag(TAG_PAIR));
    //@ public_chars(cont, TAG_LENGTH);
    //@ chars_to_secret_crypto_chars(cont, TAG_LENGTH);
    char* temp = pair->content + TAG_LENGTH;
    //@ chars_split(cont + TAG_LENGTH, sizeof(int));
    //@ assert [f1]integer(&first->size, ?flen);
    //@ integer_to_chars(&first->size);
    //@ open chars((void*) &first->size, sizeof(int), chars_of_int(flen));
    //@ character_limits((void*) &first->size);
    //@ close [f1]chars((void*) &first->size, sizeof(int), chars_of_int(flen));
    //@ public_chars((void*) &first->size, sizeof(int));
    //@ public_chars((void*) &first->size, sizeof(int));
    //@ chars_to_crypto_chars((void*) &first->size, sizeof(int));
    write_buffer(&temp, (void*) &(first->size), (int) sizeof(int));
    //@ crypto_chars_to_chars((void*) &first->size, sizeof(int));
    //@ chars_to_secret_crypto_chars(temp - sizeof(int), sizeof(int));
    //@ chars_to_integer(&first->size);
    //@ chars_split(cont + TAG_LENGTH + sizeof(int), first->size);
    write_buffer(&temp, first->content, first->size);
    write_buffer(&temp, second->content, second->size);
    //@ crypto_chars_join(cont + TAG_LENGTH + sizeof(int));
    //@ crypto_chars_join(cont + TAG_LENGTH);
    //@ crypto_chars_join(cont);
  }
  //@ list<char> size_f_cs = chars_of_int(size_f);
  //@ list<char> cs0 = append(size_f_cs, append(cs_f, cs_s));
  //@ list<char> cs = append(full_tag(TAG_PAIR), cs0);
  //@ take_append(TAG_LENGTH, full_tag(TAG_PAIR), cs0);
  //@ drop_append(TAG_LENGTH, full_tag(TAG_PAIR), cs0);
  //@ assert length(size_f_cs) == sizeof(int);
  //@ take_append(sizeof(int), size_f_cs, append(cs_f, cs_s));
  //@ drop_append(sizeof(int), size_f_cs, append(cs_f, cs_s));
  //@ take_append(size_f, cs_f, cs_s);
  //@ drop_append(size_f, cs_f, cs_s);
  //@ assert drop(sizeof(int), cs0) == append(cs_f, cs_s);
  //@ assert size_f_cs == chars_of_unbounded_int(length(cs_f));
  //@ append_assoc(size_f_cs, cs_f, cs_s);
  //@ assert crypto_chars(secret, cont, size, cs);
  //@ item p = pair_item(f, s);
  //@ close ic_pair(p)(cs_f, cs_s);
  //@ length_equals_nat_length(cs);
  //@ length_equals_nat_length(cs0);
  //@ drop_drop(sizeof(int), TAG_LENGTH, cs);
  //@ head_append(full_tag(TAG_PAIR), cs0);
  /*@ switch(nat_length(cs))
      {
        case succ(n):
          well_formed_upper_bound(cs_f, nat_length(cs_f), n);
          well_formed_upper_bound(cs_s, nat_length(cs_s), n);
        case zero:
          assert false;
      }
  @*/
  /*@ if(col)
      {
        public_chars(cont, size);
        public_generated_split(polarssl_pub(pub), cs, TAG_LENGTH);
      }
  @*/
  //@ close ic_parts(p)(full_tag(TAG_PAIR), cs0);
  //@ close item_constraints(p, cs, pub);
  //@ leak item_constraints(p, cs, pub);
  //@ close item(pair, p, pub);

  //@ close [f1]item(first, f, pub);
  //@ close [f2]item(second, s, pub);
  return pair;
  //@ close [f0]world(pub, key_clsfy);
}
コード例 #9
0
ファイル: pair_item.c プロジェクト: amintimany/verifast
void pair_get_components(struct item* pair,
                         struct item** firstp, struct item** secondp)
  /*@ requires [?f]world(?pub, ?key_clsfy) &*& item(pair, ?p, pub) &*&
               p == pair_item(?f0, ?s0) &*&
               pointer(firstp, _) &*& pointer(secondp, _); @*/
  /*@ ensures  [f]world(pub, key_clsfy) &*& item(pair, p, pub) &*&
               pointer(firstp, ?fp) &*& pointer(secondp, ?sp) &*&
                item(fp, ?f1, pub) &*& item(sp, ?s1, pub) &*&
               col ? true : f0 == f1 && s0 == s1; @*/
{
  char* temp;

  check_is_pair(pair);
  //@ open item(pair, p, pub);
  //@ assert pair->content |-> ?cont &*& pair->size |-> ?size;
  //@ assert crypto_chars(secret, cont, size, ?cs);
  //@ open [_]item_constraints(p, cs, pub);
  //@ assert [_]ic_parts(p)(?cs_tag, ?cs_cont);
  //@ take_append(TAG_LENGTH, cs_tag, cs_cont);
  //@ drop_append(TAG_LENGTH, cs_tag, cs_cont);
  //@ assert [_]ic_pair(p)(?cs_f, ?cs_s);
  
  struct item *first  = malloc(sizeof(struct item));
  struct item *second = malloc(sizeof(struct item));
  if (first == 0 || second == 0){abort_crypto_lib("malloc of item failed");}

  temp = pair->content;
  //@ crypto_chars_split(cont, TAG_LENGTH);
  //@ if (col) public_generated_split(polarssl_pub(pub), cs, TAG_LENGTH);
  //@ assert crypto_chars(secret, temp, TAG_LENGTH, cs_tag);
  //@ assert crypto_chars(secret, temp + TAG_LENGTH, size - TAG_LENGTH, cs_cont);
  //@ assert cs_tag == full_tag(TAG_PAIR);
  //@ assert cs == append(cs_tag, cs_cont);
  //@ switch(cs_tag) {case cons(c0, cs0): case nil: assert false;}
  //@ assert cs_tag == cons(TAG_PAIR, _);
  

  temp = temp + TAG_LENGTH;
  if (pair->size <= TAG_LENGTH + (int) sizeof(int))
    abort_crypto_lib("Found corrupted pair item 1");

  //@ open [f]world(pub, key_clsfy);
  //@ crypto_chars_split(temp, sizeof(int));
  //@ if (col) public_generated_split(polarssl_pub(pub), cs_cont, sizeof(int));
  //@ assert crypto_chars(secret, temp, sizeof(int), ?cs_size_f);
  //@ assert crypto_chars(secret, temp + sizeof(int), size - TAG_LENGTH - sizeof(int), ?cs_p);
  //@ take_append(sizeof(int), cs_size_f, cs_p);
  //@ drop_append(sizeof(int), cs_size_f, cs_p);
  //@ public_crypto_chars(temp, sizeof(int));
  //@ chars_to_integer(temp);
  first->size = *((int*) (void*) temp);
  second->size = pair->size - TAG_LENGTH - (int) sizeof(int) - first->size;
  //@ assert first->size |-> ?size_f &*& second->size |-> ?size_s;
  if (first->size <= TAG_LENGTH ||
      pair->size - TAG_LENGTH - (int) sizeof(int) <= first->size)
    abort_crypto_lib("Found corrupted pair item 2");
  //@ integer_to_chars(temp);
  temp = temp + (int) sizeof(int);
  //@ assert cs_cont == append(cs_size_f, cs_p);
  //@ append_assoc(cs_cont, cs_size_f, cs_p);
  //@ crypto_chars_split(temp, first->size);
  //@ if (col) public_generated_split(polarssl_pub(pub), cs_p, first->size);
  //@ take_append(size_f, cs_f, cs_s);
  //@ drop_append(size_f, cs_f, cs_s);
  //@ assert crypto_chars(secret, temp, size_f, cs_f);
  //@ assert crypto_chars(secret, temp + size_f, size_s, cs_s);
  //@ assert cs_p == append(cs_f, cs_s);
  first->content = malloc_wrapper(first->size);
  if (first->size <= MINIMAL_STRING_SIZE)
    abort_crypto_lib("Found corrupted pair item 3");
  memcpy(first->content, temp, (unsigned int) first->size);
  temp = temp + first->size;
  if (second->size <= MINIMAL_STRING_SIZE)
    abort_crypto_lib("Found corrupted pair item 4");
  second->content = malloc_wrapper(second->size);
  memcpy(second->content, temp, (unsigned int) second->size);
  //@ crypto_chars_join(cont + TAG_LENGTH + sizeof(int));
  //@ chars_to_secret_crypto_chars(cont + TAG_LENGTH, sizeof(int));
  //@ crypto_chars_join(cont + TAG_LENGTH);
  //@ assert first->content |-> ?cont_f &*& second->content |-> ?cont_s;
  //@ assert crypto_chars(secret, cont_f, size_f, cs_f);
  //@ assert crypto_chars(secret, cont_s, size_s, cs_s);
  //@ assert size_f == int_of_chars(cs_size_f);
  //@ assert chars_of_unbounded_int(size_f) == cs_size_f;
  //@ assert length(cs_f) == size_f;
  //@ assert [_]item_constraints(f0, ?cs_f0, pub);
  //@ assert [_]item_constraints(s0, ?cs_s0, pub);
  /*@ drop_append(sizeof(int), chars_of_int(length(cs_f0)),
                  append(cs_f0, cs_s0)); @*/
  /*@ take_append(sizeof(int), chars_of_int(length(cs_f0)),
                  append(cs_f0, cs_s0)); @*/
  //@ drop_append(length(cs_f0), cs_f0, cs_s0);
  //@ take_append(length(cs_f0), cs_f0, cs_s0);
  //@ close item(first, f0, pub);
  //@ close item(second, s0, pub);
  //@ close item(pair, pair_item(f0, s0), pub);

  *firstp = first;
  *secondp = second;
  //@ close [f]world(pub, key_clsfy);
}