示例#1
0
文件: cube2.c 项目: yonghuhaige/cube
static int print_cube(cube_t *cube){
  int i;
  int j;
  int k;

  for(i = 0; i < CUBE_ORDER; ++i){
    for(j = 0; j < CUBE_ORDER; ++j){
      print_block(&cube->face[UUU].block[i][j]);
    }
    printf("%x", i);
    printf("\n");
  }
  printf("0 1 2 3 4 5 6 7 8 9 a  a 9 8 7 6 5 4 3 2 1 0  a 9 8 7 6 5 4 3 2 1 0  0 1 2 3 4 5 6 7 8 9 a\n");
  for(i = 0; i < CUBE_ORDER; ++i){
    for(k = FFF; k <= LLL; ++k){
      for(j = 0; j < CUBE_ORDER; ++j){
	print_block(&cube->face[k].block[i][j]);
      }
      printf("%x", CUBE_ORDER - 1 - i);
    }
    printf("\n");
  }
  printf("0 1 2 3 4 5 6 7 8 9 a  a 9 8 7 6 5 4 3 2 1 0  a 9 8 7 6 5 4 3 2 1 0  0 1 2 3 4 5 6 7 8 9 a\n");
  for(i = 0; i < CUBE_ORDER; ++i){
    for(j = 0; j < CUBE_ORDER; ++j){
      print_block(&cube->face[DDD].block[i][j]);
    }
    printf("%x", CUBE_ORDER - 1 - i);
    printf("\n");
  }
  printf("0 1 2 3 4 5 6 7 8 9 a\n");
  return 0;
}
示例#2
0
文件: test.c 项目: justinethier/aes
  /*(Key (128): E8E9EAEBEDEEEFF0F2F3F4F5F7F8F9FA 
Plaintext: 014BAF2278A69D331D5180103643E99A 
Ciphertext: 6743C3D1519AB4F2CD9A78AB09A511BD */
void test_encryption(){
  unsigned char 
  /* TODO: old values taht seem to be invalid:
     key[] = {0xE8, 0xE9, 0xEA, 0xEB, 0xED, 0xEE, 0xEF, 0xF0, 0xF2, 0xF3, 0xF4, 0xF5, 0xF7, 0xF8, 0xF9, 0xFA},
     plain[] = {0x01, 0x4B, 0xAF, 0x22, 0x78, 0xA6, 0x9D, 0x33, 0x1D, 0x51, 0x80, 0x10, 0x36, 0x43, 0xE9, 0x9A},
     cipher[] = {0x67, 0x43, 0xC3, 0xD1, 0x51, 0x9A, 0xB4, 0xF2, 0xCD, 0x9A, 0x78, 0xAB, 0x09, 0xA5, 0x11, 0xBD};
*/

/* TODO: test w/these values instead. if they work, investigate why the other ones don't:
    data = [0x68, 0x65, 0x6c, 0x6c,

                0x6f, 0x2c, 0x20, 0x77,
                0x6f, 0x72, 0x6c, 0x64,
                0x21, 0x21, 0x21, 0x21]
    key = [0x0f, 0x15, 0x71, 0xc9,
              0x47, 0xd9, 0xe8, 0x59,
              0x0c, 0xb7, 0xad, 0xd6,
              0xaf, 0x7f, 0x67, 0x98]
    result = @aes.encrypt(data, key)

    assert_equal([0x56, 0xdd, 0x68, 0x15, 0x44, 0x65, 0x7b, 0x76, 0xe5, 0x93, 0x51, 0xf5, 0x7d, 0x95, 0xa4, 0xb3], 
                      result)
    */
  unsigned char *c = encrypt(plain, key, 16);
  print_block(c, 16);
  print_block(cipher, 16);
  assert( bytencmp(c, cipher, 16) == 0 );
  //unsigned char *p = decrypt(c, key, 16);
  //assert( bytencmp(p, plain, 16) == 0 );

  free(c);
//  free(p);

}
示例#3
0
void print_disk_tree (int block_nr)
{
    struct buffer_head * bh;

    bh = bread (g_sb.s_dev, block_nr, g_sb.s_blocksize);
    if (B_IS_KEYS_LEVEL (bh)) {
	int i;
	struct disk_child * dc;

	g_stat_info.nr_internals ++;
	print_block (bh, print_mode (), -1, -1);
      
	dc = B_N_CHILD (bh, 0);
	for (i = 0; i <= B_NR_ITEMS (bh); i ++, dc ++)
	    print_disk_tree (dc->dc_block_number);

    } else if (B_IS_ITEMS_LEVEL (bh)) {
	g_stat_info.nr_leaves ++;
	print_block (bh, print_mode (), -1, -1);
    } else {
	print_block (bh, print_mode (), -1, -1);
	die ("print_disk_tree: bad block type");
    }
    brelse (bh);
}
示例#4
0
void print_block(value v, int m)
{
    int size, i;

    margin(m);
    if (Is_long(v))
    {
        printf("immediate value (%ld)\n", Long_val(v));
        return;
    }
    printf("memory block: size=%d - ", size=Wosize_val(v));

    switch(Tag_val(v))
    {
        case Closure_tag:
            printf("closure with %d free variables\n", size-1);
            margin(m+4);
            printf("code pointer: %p\n", Code_val(v));
            for (i=1; i<size; i++)
                print_block(Field(v,i),m+4);
            break;

        case String_tag:
            printf("string: %s (%s)\n", String_val(v), (char *) v);
            break;

        case Double_tag:
            printf("float: %g\n", Double_val(v));
            break;

        case Double_array_tag:
            printf("float array: ");
            for (i=0; i<size/Double_wosize; i++)
                printf(" %g", Double_field(v,i));
            printf("\n");
            break;

        case Abstract_tag:
            printf("abstract type\n");
            break;

        case Custom_tag:
            printf("abstract finalized type\n");
            break;

        default:
            if (Tag_val(v) >= No_scan_tag)
            {
                printf("unknown tag");
                break;
            };
            printf("structured block (tag=%d):\n", Tag_val(v));
            for (i=0; i<size; i++)
                print_block(Field(v,i), m+4);
    }
    return;
}
示例#5
0
/*
 * Set up the indentation for a list item; used from pre_it().
 */
static void
print_width(const struct mdoc_bl *bl, const struct roff_node *child)
{
	char		  buf[24];
	struct roffsu	  su;
	const char	 *end;
	int		  numeric, remain, sz, chsz;

	numeric = 1;
	remain = 0;

	/* Convert the width into a number (of characters). */
	if (bl->width == NULL)
		sz = (bl->type == LIST_hang) ? 6 : 0;
	else {
		end = a2roffsu(bl->width, &su, SCALE_MAX);
		if (end == NULL || *end != '\0')
			sz = man_strlen(bl->width);
		else if (SCALE_EN == su.unit)
			sz = su.scale;
		else {
			sz = 0;
			numeric = 0;
		}
	}

	/* XXX Rough estimation, might have multiple parts. */
	if (bl->type == LIST_enum)
		chsz = (bl->count > 8) + 1;
	else if (child != NULL && child->type == ROFFT_TEXT)
		chsz = man_strlen(child->string);
	else
		chsz = 0;

	/* Maybe we are inside an enclosing list? */
	mid_it();

	/*
	 * Save our own indentation,
	 * such that child lists can use it.
	 */
	Bl_stack[Bl_stack_len++] = sz + 2;

	/* Set up the current list. */
	if (chsz > sz && bl->type != LIST_tag)
		print_block(".HP", 0);
	else {
		print_block(".TP", 0);
		remain = sz + 2;
	}
	if (numeric) {
		(void)snprintf(buf, sizeof(buf), "%dn", sz + 2);
		print_word(buf);
	} else
		print_word(bl->width);
	TPremain = remain;
}
示例#6
0
/*
 * Set up the indentation for a list item; used from pre_it().
 */
static void
print_width(const char *v, const struct mdoc_node *child, size_t defsz)
{
	char		  buf[24];
	struct roffsu	  su;
	size_t		  sz, chsz;
	int		  numeric, remain;

	numeric = 1;
	remain = 0;

	/* Convert v into a number (of characters). */
	if (NULL == v)
		sz = defsz;
	else if (a2roffsu(v, &su, SCALE_MAX)) {
		if (SCALE_EN == su.unit)
			sz = su.scale;
		else {
			sz = 0;
			numeric = 0;
		}
	} else
		sz = strlen(v);

	/* XXX Rough estimation, might have multiple parts. */
	chsz = (NULL != child && MDOC_TEXT == child->type) ?
	    strlen(child->string) : 0;

	/* Maybe we are inside an enclosing list? */
	mid_it();

	/*
	 * Save our own indentation,
	 * such that child lists can use it.
	 */
	Bl_stack[Bl_stack_len++] = sz + 2;

	/* Set up the current list. */
	if (defsz && chsz > sz)
		print_block(".HP", 0);
	else {
		print_block(".TP", 0);
		remain = sz + 2;
	}
	if (numeric) {
		(void)snprintf(buf, sizeof(buf), "%zun", sz + 2);
		print_word(buf);
	} else
		print_word(v);
	TPremain = remain;
}
示例#7
0
void test_chacha(const uint8_t *key, const uint8_t *iv, uint8_t *expected, 
                uint8_t keylength, uint8_t rounds) {
    uint8_t cipher_data[64] =  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    uint8_t cipher_result[64] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    
    struct chacha_ctx cipher_ctx;

    uint8_t errors;
    
    chacha_set_key(&cipher_ctx, keylength, key);
    chacha_set_iv(&cipher_ctx, iv);
    chacha_crypt(&cipher_ctx, 64, rounds, &cipher_result[0], &cipher_data[0]);

    if (DEBUG) {
        printf("Result after encryption:\n");
        print_block(cipher_result);
      }

    errors = 0;
    for (uint8_t i = 0 ; i < 64 ; i++) {
      if (cipher_result[i] != expected[i]) {
        errors++;
      }
    }
    
    if (errors > 0) {
      printf("Error, expected:\n");
      print_block(&expected[0]);
      printf("Got:\n");
      print_block(cipher_result);
    }
    else {
      printf("Success, result matched expected.\n");
    }
}
示例#8
0
/* first calls search_by_key, then, if item is not found looks for the entry inside directory item indicated by
   search_by_key. (We assign a key to each directory item, and place multiple entries in a single directory item.)
   Fills the path to the entry, and to the entry position in the item */
int search_by_entry_key (struct super_block * sb, struct key * key, struct path * path, int * pos_in_item, int * repeat)
{
  /* search for a directory item using key of entry */
  if (search_by_key (sb, key, path, repeat, DISK_LEAF_NODE_LEVEL, READ_BLOCKS) == ITEM_FOUND) {
    *pos_in_item = 0;
    return POSITION_FOUND;
  }
#ifdef REISERFS_CHECK
  if (!PATH_LAST_POSITION (path))
    reiserfs_panic (sb, "vs-7000: search_by_entry_key: search_by_key returned item position == 0");
#endif /* REISERFS_CHECK */
  PATH_LAST_POSITION (path) --;

#ifdef REISERFS_CHECK
  {
    struct item_head * ih = B_N_PITEM_HEAD (PATH_PLAST_BUFFER (path), PATH_LAST_POSITION (path));

    if (!I_IS_DIRECTORY_ITEM (ih) || COMP_SHORT_KEYS (&(ih->ih_key), key)) {
      print_block (PATH_PLAST_BUFFER (path), 0, -1, -1);
      reiserfs_panic (sb, "vs-7005: search_by_entry_key: found item %h is not directory item or "
		      "does not belong to the same directory as key %k", ih, key);
    }
  }
#endif /* REISERFS_CHECK */

  /* binary search in directory item by third component of the key */
  return bin_search_in_dir_item (PATH_PITEM_HEAD (path), B_I_DEH (PATH_PLAST_BUFFER (path), PATH_PITEM_HEAD (path)), key, pos_in_item);
}
示例#9
0
void decrypt_key(unsigned char* decryptedSap, unsigned char* keyIn, unsigned char* iv, unsigned char* keyOut)
{
   unsigned char blockIn[16];
   uint32_t key_schedule[11][4];
   uint32_t mode_key_schedule[11][4];
   generate_key_schedule(&decryptedSap[8], key_schedule);
   printf("Generating mode key:\n");
   generate_key_schedule(initial_session_key, mode_key_schedule);
   z_xor(keyIn, blockIn, 1);
   print_block("Input to cycle is: ", blockIn);
   cycle(blockIn, key_schedule);
   for (int j = 0; j < 16; j++)
      keyOut[j] = blockIn[j] ^ iv[j];
   print_block("Output from cycle is: ", keyOut);
   x_xor(keyOut, keyOut, 1);
}
示例#10
0
文件: test.c 项目: justinethier/aes
void test_shift_rows(){
  char msg[] = "0123456789ABCDE";
  print_block(msg, 16);

printf("\n");
  shift_rows(msg, 16);
  print_block(msg, 16);

  printf("\n");
  inv_shift_rows(msg, 16);
  print_block(msg, 16);

// TODO: cannot use strcmp because it stops on 0!
// TODO: assert inv is equal to original
  assert( strcmp(msg, "0123456789ABCDE") == 0 );
}
示例#11
0
void permute_block_1(unsigned char* block)
{
   block[0] = table_s3[block[0]];
   block[4] = table_s3[0x400+block[4]];
   block[8] = table_s3[0x800+block[8]];
   block[12] = table_s3[0xc00+block[12]];
   
   unsigned char tmp = block[13];
   block[13] = table_s3[0x100+block[9]];
   block[9] = table_s3[0xd00+block[5]];
   block[5] = table_s3[0x900+block[1]];
   block[1] = table_s3[0x500+tmp];

   tmp = block[2];
   block[2] = table_s3[0xa00+block[10]];
   block[10] = table_s3[0x200+tmp];
   tmp = block[6];
   block[6] = table_s3[0xe00+block[14]];
   block[14] = table_s3[0x600+tmp];

   tmp = block[3];
   block[3] = table_s3[0xf00+block[7]];
   block[7] = table_s3[0x300+block[11]];
   block[11] = table_s3[0x700+block[15]];
   block[15] = table_s3[0xb00+tmp];
   print_block("Permutation complete. Final value of block: ", block); // This looks right to me, at least for decrypt_kernel
}
示例#12
0
bool block_check_invariants_print_result(Block* block, Value* out)
{
    circa::Value result;
    block_check_invariants(&result, block);

    if (list_length(&result) == 0)
        return true;

    string_append(out, list_length(&result));
    string_append(out, " errors found in block ");
    string_append_ptr(out, block);
    string_append(out, "\n");

    for (int i=0; i < list_length(&result); i++) {
        Value* error = list_get(&result,i);
        string_append(out, "[");
        string_append(out, as_int(list_get(error, 1)));
        string_append(out, "]");
        string_append(out, as_cstring(list_get(error, 2)));
        string_append(out, "\n");
    }

    string_append(out, "contents:\n");
    print_block(block, out);

    return false;
}
示例#13
0
void permute_block_2(unsigned char* block, int round)
{
   // round is 0..8?
   printf("Permuting via table2, round %d... (block[0] = %02X)\n", round, block[0]);
   block[0] = permute_table_2(round*16+0)[block[0]];
   block[4] = permute_table_2(round*16+4)[block[4]];
   block[8] = permute_table_2(round*16+8)[block[8]];
   block[12] = permute_table_2(round*16+12)[block[12]];
   
   unsigned char tmp = block[13];
   block[13] = permute_table_2(round*16+13)[block[9]];
   block[9] = permute_table_2(round*16+9)[block[5]];
   block[5] = permute_table_2(round*16+5)[block[1]];
   block[1] = permute_table_2(round*16+1)[tmp];

   tmp = block[2];
   block[2] = permute_table_2(round*16+2)[block[10]];
   block[10] = permute_table_2(round*16+10)[tmp];
   tmp = block[6];
   block[6] = permute_table_2(round*16+6)[block[14]];
   block[14] = permute_table_2(round*16+14)[tmp];

   tmp = block[3];
   block[3] = permute_table_2(round*16+3)[block[7]];
   block[7] = permute_table_2(round*16+7)[block[11]];
   block[11] = permute_table_2(round*16+11)[block[15]];
   block[15] = permute_table_2(round*16+15)[tmp];
   print_block("Permutation (2) complete. Final value of block: ", block); // This looks right to me, at least for decrypt_kernel
}
示例#14
0
static int
pre_nm(DECL_ARGS)
{
	char	*name;

	if (MDOC_BLOCK == n->type) {
		outflags |= MMAN_Bk;
		pre_syn(n);
	}
	if (MDOC_ELEM != n->type && MDOC_HEAD != n->type)
		return(1);
	name = n->child ? n->child->string : meta->name;
	if (NULL == name)
		return(0);
	if (MDOC_HEAD == n->type) {
		if (NULL == n->parent->prev)
			outflags |= MMAN_sp;
		print_block(".HP", 0);
		printf(" %zun", strlen(name) + 1);
		outflags |= MMAN_nl;
	}
	font_push('B');
	if (NULL == n->child)
		print_word(meta->name);
	return(1);
}
示例#15
0
static int
pre_fn(DECL_ARGS)
{

	pre_syn(n);

	n = n->child;
	if (NULL == n)
		return 0;

	if (NODE_SYNPRETTY & n->flags)
		print_block(".HP 4n", MMAN_nl);

	font_push('B');
	print_node(meta, n);
	font_pop();
	outflags &= ~MMAN_spc;
	print_word("(");
	outflags &= ~MMAN_spc;

	n = n->next;
	if (NULL != n)
		pre_fa(meta, n);
	return 0;
}
示例#16
0
static int
pre_nm(DECL_ARGS)
{
	char	*name;

	if (n->type == ROFFT_BLOCK) {
		outflags |= MMAN_Bk;
		pre_syn(n);
	}
	if (n->type != ROFFT_ELEM && n->type != ROFFT_HEAD)
		return 1;
	name = n->child ? n->child->string : meta->name;
	if (NULL == name)
		return 0;
	if (n->type == ROFFT_HEAD) {
		if (NULL == n->parent->prev)
			outflags |= MMAN_sp;
		print_block(".HP", 0);
		printf(" %zun", strlen(name) + 1);
		outflags |= MMAN_nl;
	}
	font_push('B');
	if (NULL == n->child)
		print_word(meta->name);
	return 1;
}
示例#17
0
文件: print.c 项目: chenggongtc/myls
static void
print_line(OBJ *obj)
{
	struct stat *st;
	FTSENT      *p;

	p = obj->obj_list;

	while (p != NULL) {
		if (p->fts_number == FTS_NO_PRINT) {
			p = p->fts_link;
			continue;
		}

		st = p->fts_statp;

		/* print inode */
		if (f_ino)
			printf("%*"PRIuMAX" ", obj->obj_ino_max,
				(uintmax_t)st->st_ino);

		/* print number of blocks */
		if (f_block) {	
			print_block(st->st_blocks * 512, obj->obj_block_max);
		}

		print_name(p, NO_LINK);

		putchar('\n');
		p = p->fts_link;
	}
}
示例#18
0
static int
pre_fo(DECL_ARGS)
{

	switch (n->type) {
	case ROFFT_BLOCK:
		pre_syn(n);
		break;
	case ROFFT_HEAD:
		if (n->child == NULL)
			return 0;
		if (NODE_SYNPRETTY & n->flags)
			print_block(".HP 4n", MMAN_nl);
		font_push('B');
		break;
	case ROFFT_BODY:
		outflags &= ~(MMAN_spc | MMAN_nl);
		print_word("(");
		outflags &= ~MMAN_spc;
		break;
	default:
		break;
	}
	return 1;
}
示例#19
0
文件: mm.c 项目: i-hossain/ece454
/**********************************************************
 * print_heap
 * Prints all the blocks in the heap till epilogue
 **********************************************************/
void print_heap()
{
    void *bp;
    for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp))
    {
        print_block(bp);
    }
}
示例#20
0
文件: print.c 项目: chenggongtc/myls
void
print_long(OBJ *obj)
{
	struct stat *st;
	FTSENT      *p;
	char        mode[MODE_BUFF_SIZE];

	p = obj->obj_list;

	if(!obj->obj_isroot)
		print_total(obj->obj_size_total);

	while (p != NULL) {
		if (p->fts_number == FTS_NO_PRINT) {
			p = p->fts_link;
			continue;
		}

		st = p->fts_statp;

		/* print inode */
		if (f_ino)
			printf("%*"PRIuMAX" ", obj->obj_ino_max,
				(uintmax_t)st->st_ino);

		/* print number of blocks */
		if (f_block) {	
			print_block((int64_t)st->st_blocks * DEFAULT_BSIZE, 
				    obj->obj_block_max);
		}
		
		/* print mode */
		strmode(st->st_mode, mode);
		printf("%11s ", mode);

		/* print number of links */
		printf("%*"PRIuMAX" ", obj->obj_link_max, 
			(uintmax_t)st->st_nlink);

		/* print owner and group */
		print_user_and_group(st->st_uid, st->st_gid, 
				      obj->obj_user_max, obj->obj_group_max);

		/* print size */
		if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
			print_device(st->st_rdev, obj->obj_major_max,
					obj->obj_minor_max);
		else
			print_size(st->st_size, obj->obj_size_max);

		print_date(st);
		print_name(p, WITH_LINK);

		putchar('\n');

		p = p->fts_link;
	}
}
示例#21
0
int main (int argc, char **argv)
{
    int res = 1;
    
    if (argc != 3) {
        printf("Usage: %s <desugar=0/1> <string>\n", (argc > 0 ? argv[0] : ""));
        goto fail0;
    }
    
    int desugar = atoi(argv[1]);
    char *text = argv[2];
    
    BLog_InitStdout();
    
    // parse
    NCDProgram prog;
    if (!NCDConfigParser_Parse(text, strlen(text), &prog)) {
        DEBUG("NCDConfigParser_Parse failed");
        goto fail1;
    }
    
    // desugar
    if (desugar) {
        if (!NCDSugar_Desugar(&prog)) {
            DEBUG("NCDSugar_Desugar failed");
            goto fail2;
        }
    }
    
    // print
    for (NCDProgramElem *elem = NCDProgram_FirstElem(&prog); elem; elem = NCDProgram_NextElem(&prog, elem)) {
        switch (NCDProgramElem_Type(elem)) {
            case NCDPROGRAMELEM_PROCESS: {
                NCDProcess *p = NCDProgramElem_Process(elem);
                printf("process name=%s is_template=%d\n", NCDProcess_Name(p), NCDProcess_IsTemplate(p));
                print_block(NCDProcess_Block(p), 2);
            } break;
            
            case NCDPROGRAMELEM_INCLUDE: {
                printf("include path=%s\n", NCDProgramElem_IncludePathData(elem));
            } break;
            
            case NCDPROGRAMELEM_INCLUDE_GUARD: {
                printf("include_guard id=%s\n", NCDProgramElem_IncludeGuardIdData(elem));
            } break;
            
            default: ASSERT(0);
        }
    }
    
    res = 0;
fail2:
    NCDProgram_Free(&prog);
fail1:
    BLog_Free();
fail0:
    return res;
}
示例#22
0
文件: mm.c 项目: i-hossain/ece454
/**********************************************************
 * print_list
 * Determines which bin to print from the segregated list
 * based on the index
 **********************************************************/
void print_list(int index)
{
    dlist *current = sep_list_head[index];
    
    while (current != NULL) {
        print_block((void*)current);
        current = current->next;
    }
}
示例#23
0
/* The function is NOT SCHEDULE-SAFE! */
int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
			struct treepath *path, struct reiserfs_dir_entry *de)
{
	int retval;

	retval = search_item(sb, key, path);
	switch (retval) {
	case ITEM_NOT_FOUND:
		if (!PATH_LAST_POSITION(path)) {
			reiserfs_error(sb, "vs-7000", "search_by_key "
				       "returned item position == 0");
			pathrelse(path);
			return IO_ERROR;
		}
		PATH_LAST_POSITION(path)--;

	case ITEM_FOUND:
		break;

	case IO_ERROR:
		return retval;

	default:
		pathrelse(path);
		reiserfs_error(sb, "vs-7002", "no path to here");
		return IO_ERROR;
	}

	set_de_item_location(de, path);

#ifdef CONFIG_REISERFS_CHECK
	if (!is_direntry_le_ih(de->de_ih) ||
	    COMP_SHORT_KEYS(&de->de_ih->ih_key, key)) {
		print_block(de->de_bh, 0, -1, -1);
		reiserfs_panic(sb, "vs-7005", "found item %h is not directory "
			       "item or does not belong to the same directory "
			       "as key %K", de->de_ih, key);
	}
#endif				/* CONFIG_REISERFS_CHECK */

	/*
	 * binary search in directory item by third component of the
	 * key. sets de->de_entry_num of de
	 */
	retval = bin_search_in_dir_item(de, cpu_key_k_offset(key));
	path->pos_in_item = de->de_entry_num;
	if (retval != NAME_NOT_FOUND) {
		/*
		 * ugly, but rename needs de_bh, de_deh, de_name,
		 * de_namelen, de_objectid set
		 */
		set_de_name_and_namelen(de);
		set_de_object_key(de);
	}
	return retval;
}
示例#24
0
static void print_all_blocks(tmp_block_t *block_list, unsigned r, unsigned c)
{
	tmp_block_t *current_block = block_list;

	while(current_block) {
		print_block(current_block, r, c);

		current_block = current_block->next;
	};
}
示例#25
0
void main()
{	struct block data,key,temp;
	//unsigned char c1[16]={0x32,0x88,0x31,0xe0,0x43,0x5a,0x31,0x37,0xf6,0x30,0x98,0x07,0xa8,0x8d,0xa2,0x34};
	//unsigned char c2[16]={0x2b,0x28,0xab,0x09,0x7e,0xae,0xf7,0xcf,0x15,0xd2,0x15,0x4f,0x16,0xa6,0x88,0x3c};
	unsigned char c1[16]="Hello World. 123";
	unsigned char c2[16]="My New Password.";	
	int i,j,c=0;
	struct block round_key[11];
	// Initializing Data and Key
	for(i=0;i<4;i++)
	{	for(j=0;j<4;j++)
		{	data.b[i][j]=c1[c];
			key.b[i][j]=c2[c];
			c++;	
		}
	}

	printf("Data and key before encryption:");
	printf("\n Data:\n");
	print_block(data);
	printf("\n Key:\n");
	print_block(key);

	printf("Generating All the round Keys:");
	round_key[0]=key;
	temp=key;	
	for(i=0;i<10;i++)
	{	temp=next_key(temp,i);
		round_key[i+1]=temp;
	}
	printf("All the keys generated.");

	data=encrypt(data,round_key);

	printf("Data after encryption:");
	printf("\n Data:\n");
	print_block(data);

	printf("\nData After Decryption\n");
	data=decrypt(data,round_key);
	print_block(data);
}
示例#26
0
 void DisassemblerContext::print_function(const ValuePtr<Function>& term) {
   print_function_type_term(term->function_type(), term);
   if (!term->blocks().empty()) {
     *m_output << " {\n";
     
     for (Function::BlockList::const_iterator ii = term->blocks().begin(), ie = term->blocks().end(); ii != ie; ++ii)
       print_block(*ii, m_local_definitions[*ii]);
     
     *m_output << "}";
   }
   *m_output << ";\n";
 }
示例#27
0
文件: test.c 项目: Fat-Zer/semestr-6
int main()
{
	unsigned char key[8]   = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
	unsigned char block[8] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7};
	unsigned char tmp_block[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
	unsigned char zero_block[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

	uint64_t k_arr[16]={
		0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0};
	des_ctx ctx={
		{	0, 0, 0, 0, 0, 0, 0, 0, 	0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 	0, 0, 0, 0, 0, 0, 0, 0},
		{	0, 0, 0, 0, 0, 0, 0, 0, 	0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 	0, 0, 0, 0, 0, 0, 0, 0}
	};
	uint64_t tmp;
	int i;
	
	des_key(&ctx, key);
	des_gen_ks(des_byte2key(key), k_arr);
	
//	print_block("k[0] my", k_arr);
//	print_block("k[0] work", ctx.ek);
/*	tmp = des_f(0,k_arr[0]);
	print_block32("des_f(0,k[1])", &tmp);
	tmp = des_ssl_f(0,ctx.ek);
	print_block32("ssl_f(0,k[1])", &tmp);
	
	tmp = des_work_f(0,ctx.ek);
	print_block32("work_f(0,k[1])", &tmp);
*/	
	des_enc(&ctx, block, 1);
	print_block("Encrypted", block);
	des_dec(&ctx, block, 1);
	print_block("Decrypted", block);

	puts("===============================================");
	print_block("Plain", block);

	//*(uint64_t*)block = des_byte2key(block);
	des_block_crypt((uint64_t*)block, k_arr, DES_ENCRYPT_ACT);
	print_block("Encrypted", block);

	reverse_bit_buff(tmp_block, block, 8);
	print_block("Mirrored", tmp_block);

	for(i=0; i<8; i++) tmp_block[i]=reverse_bit_byte(block[i]);
	print_block("ByBitMirrored", tmp_block);

	des_block_crypt((uint64_t*)block, k_arr, DES_DECRYPT_ACT);
	print_block("Decrypted", block);

	return 0;
}
示例#28
0
/*
 * Print before a section header.
 */
static int
pre_sect(DECL_ARGS)
{

	if (n->type == ROFFT_HEAD) {
		outflags |= MMAN_sp;
		print_block(manacts[n->tok].prefix, 0);
		print_word("");
		putchar('\"');
		outflags &= ~MMAN_spc;
	}
	return 1;
}
示例#29
0
/*
 * Print before a section header.
 */
static int
pre_sect(DECL_ARGS)
{

	if (MDOC_HEAD == n->type) {
		outflags |= MMAN_sp;
		print_block(manacts[n->tok].prefix, 0);
		print_word("");
		putchar('\"');
		outflags &= ~MMAN_spc;
	}
	return(1);
}
示例#30
0
void decrypt_sap(unsigned char* sapIn, unsigned char* sapOut)
{
   uint32_t key_schedule[11][4];
   unsigned char* iv;
   print_block("Base sap: ", &sapIn[0xf0]);
   z_xor(sapIn, sapOut, 16);
   generate_key_schedule(sap_key_material, key_schedule);
   print_block("lastSap before cycle: ", &sapOut[0xf0]);
   for (int i = 0xf0; i >= 0x00; i-=0x10)
   {
      printf("Ready to cycle %02X\n", i);
      cycle(&sapOut[i], key_schedule);
      print_block("After cycling, block is: ", &sapOut[i]);
      if (i > 0)
      { // xor with previous block
         iv = &sapOut[i-0x10];
      }
      else
      { // xor with sap IV
         iv = sap_iv;
      }
      for (int j = 0; j < 16; j++)
      {
         printf("%02X ^ %02X -> %02X\n", sapOut[i+j],  iv[j], sapOut[i+j] ^ iv[j]);
         sapOut[i+j] = sapOut[i+j] ^ iv[j];
      }
      printf("Decrypted SAP %02X-%02X:\n", i, i+0xf);
      print_block("", &sapOut[i]);
   }
   // Lastly grind the whole thing through x_key. This is the last time we modify sap
   x_xor(sapOut, sapOut, 16);
   printf("Sap is decrypted to\n");
   for (int i = 0xf0; i >= 0x00; i-=0x10)
   {
      printf("Final SAP %02X-%02X: ", i, i+0xf);
      print_block("", &sapOut[i]);
   }
}