Ejemplo n.º 1
0
void AES_CMAC_Update(AES_CMAC_CTX *ctx, const u_int8_t *data, u_int len)
{
	u_int mlen;
	unsigned char in[16];
	
	if (ctx->M_n > 0)
	{
		mlen = MIN(16 - ctx->M_n, len);
		memcpy1(ctx->M_last + ctx->M_n, data, mlen);
		ctx->M_n += mlen;
		if (ctx->M_n < 16 || len == mlen)
			return;
		XOR(ctx->M_last, ctx->X);
		// rijndael_encrypt(&ctx->rijndael, ctx->X, ctx->X);
		aes_encrypt( ctx->X, ctx->X, &ctx->rijndael);
		data += mlen;
		len -= mlen;
	}
	while (len > 16)
	{	/* not last block */
		XOR(data, ctx->X);
		// rijndael_encrypt(&ctx->rijndael, ctx->X, ctx->X);

		memcpy1(in, &ctx->X[0], 16); //Bestela ez du ondo iten
		aes_encrypt( in, in, &ctx->rijndael);
		memcpy1(&ctx->X[0], in, 16);

		data += 16;
		len -= 16;
	}

	/* potential last block, save it */
	memcpy1(ctx->M_last, data, len);
	ctx->M_n = len;
}
Ejemplo n.º 2
0
void f5(void)
{
  char buf[10];
  memset((void *)0x100000000ULL, 0, 0x1000);
  memcpy((char *)NULL + 0x10000, buf, 0x10);
  memcpy1((char *)NULL + 0x10000, buf, 0x10); // expected-error {{argument value 4 is outside the valid range [0, 3]}}
}
Ejemplo n.º 3
0
void AES_CMAC_Final(u_int8_t digest[AES_CMAC_DIGEST_LENGTH], AES_CMAC_CTX *ctx)
{
	u_int8_t K[16];
	unsigned char in[16];
	/* generate subkey K1 */
	memset1(K, '\0', 16);

	// rijndael_encrypt(&ctx->rijndael, K, K);

	aes_encrypt( K, K, &ctx->rijndael);

	if (K[0] & 0x80)
	{
		LSHIFT(K, K);
		K[15] ^= 0x87;
	} else
		LSHIFT(K, K);

	if (ctx->M_n == 16)
	{
		/* last block was a complete block */
		XOR(K, ctx->M_last);
	} else {
		/* generate subkey K2 */
		if (K[0] & 0x80)
		{
			LSHIFT(K, K);
			K[15] ^= 0x87;
		} else
			LSHIFT(K, K);

		/* padding(M_last) */
		ctx->M_last[ctx->M_n] = 0x80;
		while (++ctx->M_n < 16)
			ctx->M_last[ctx->M_n] = 0;

		XOR(K, ctx->M_last);
	}
	XOR(ctx->M_last, ctx->X);

	// rijndael_encrypt(&ctx->rijndael, ctx->X, digest);

	memcpy1(in, &ctx->X[0], 16); //Bestela ez du ondo iten
	aes_encrypt(in, digest, &ctx->rijndael);
	memset1(K, 0, sizeof K);
}
Ejemplo n.º 4
0
Archivo: fs.c Proyecto: jjhlzn/haribote
void mkfs()
{
	MESSAGE driver_msg;
	int i, j;

	int bits_per_sect = SECTOR_SIZE * 8; /* 8 bits per byte */
	
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	fsbuf = (u8 *)memman_alloc(memman,FSBUF_SIZE);

	/* get the geometry of ROOTDEV */
	struct part_info geo;
	//driver_msg.type		= DEV_IOCTL;
	//driver_msg.DEVICE	= MINOR(ROOT_DEV);
	//driver_msg.REQUEST	= DIOCTL_GET_GEO;
	//driver_msg.BUF		= &geo;
	//driver_msg.PROC_NR	= 0; //TASK_FS
	//hd_ioctl(&driver_msg);
	geo.size = 20097;
	
	debug("dev size: 0x%x sectors", geo.size);

	/************************/
	/*      super block     */
	/************************/
	struct super_block sb;
	sb.magic	  = MAGIC_V1;
	sb.nr_inodes	  = bits_per_sect;  //512 * 8 = 4096个i_node
	sb.nr_inode_sects = sb.nr_inodes * INODE_SIZE / SECTOR_SIZE;  //i_node所占用的扇区数=4096 * 32 / 512 = 32
	sb.nr_sects	  = geo.size; /* partition size in sector, 这个分区总共有多少个扇区 */
	sb.nr_imap_sects  = 1; //inode-map所占用的扇区数
	sb.nr_smap_sects  = sb.nr_sects / bits_per_sect + 1; //secotr-map所占用的扇区数
	sb.n_1st_sect	  = 1 + 1 +   /* boot sector & super block */
						sb.nr_imap_sects + sb.nr_smap_sects + sb.nr_inode_sects; //数据区的第一个扇区编号
	sb.root_inode	  = ROOT_INODE;  //root directory占用的inode编号
	sb.inode_size	  = INODE_SIZE; 
	struct inode x;
	sb.inode_isize_off= (int)&x.i_size - (int)&x; //i_size在i-node结构中的偏移
	sb.inode_start_off= (int)&x.i_start_sect - (int)&x; //start_sect在i-node结构中的偏移
	sb.dir_ent_size	  = DIR_ENTRY_SIZE; //DIR_ENTRY结构的大小
	struct dir_entry de;
	sb.dir_ent_inode_off = (int)&de.inode_nr - (int)&de; //inode_nr在dir_entry中的偏移
	sb.dir_ent_fname_off = (int)&de.name - (int)&de; //name在dir_entry中的偏移

	memset1(fsbuf, 0x90, SECTOR_SIZE);
	memcpy1(fsbuf, &sb,  SUPER_BLOCK_SIZE);
	
	debug("sb.n_1st_sect = %d",sb.n_1st_sect);
	
	/* write the super block */
	WR_SECT(ROOT_DEV, 1);

	/************************/
	/*       inode map      */
	/************************/
	memset1(fsbuf, 0, SECTOR_SIZE);
	for (i = 0; i < (NR_CONSOLES + 2); i++)
		fsbuf[0] |= 1 << i;

	assert(fsbuf[0] == 0x1F);/* 0001 1111 : 
	//			  *    | ||||
	//			  *    | |||`--- bit 0 : reserved
	//			  *    | ||`---- bit 1 : the first inode,
	//			  *    | ||              which indicates `/'
	//			  *    | |`----- bit 2 : /dev_tty0
	//			  *    | `------ bit 3 : /dev_tty1
	//			  *    `-------- bit 4 : /dev_tty2
	//			  */
	WR_SECT(ROOT_DEV, 2);

	/************************/
	/*      secter map      */
	/************************/
	memset1(fsbuf, 0, SECTOR_SIZE);
	int nr_sects = NR_DEFAULT_FILE_SECTS + 1;
	/*             ~~~~~~~~~~~~~~~~~~~|~   |
	 *                                |    `--- bit 0 is reserved
	 *                                `-------- for `/'
	 */
	for (i = 0; i < nr_sects / 8; i++)
		fsbuf[i] = 0xFF;

	for (j = 0; j < nr_sects % 8; j++)
		fsbuf[i] |= (1 << j);

	WR_SECT(ROOT_DEV, 2 + sb.nr_imap_sects);

	/* zeromemory the rest sector-map */
	memset1(fsbuf, 0, SECTOR_SIZE);
	for (i = 1; i < sb.nr_smap_sects; i++)
		WR_SECT(ROOT_DEV, 2 + sb.nr_imap_sects + i);

	/************************/
	/*       inodes         */
	/************************/
	/* inode of `/' */
	memset1(fsbuf, 0, SECTOR_SIZE);
	struct inode * pi = (struct inode*)fsbuf;
	pi->i_mode = I_DIRECTORY;
	pi->i_size = DIR_ENTRY_SIZE * 4; /* 4 files:
					  * `.',
					  * `dev_tty0', `dev_tty1', `dev_tty2',
					  */
	pi->i_start_sect = sb.n_1st_sect;
	pi->i_nr_sects = NR_DEFAULT_FILE_SECTS;
	/* inode of `/dev_tty0~2' */
	for (i = 0; i < NR_CONSOLES; i++) {
		pi = (struct inode*)(fsbuf + (INODE_SIZE * (i + 1)));
		pi->i_mode = I_CHAR_SPECIAL;
		pi->i_size = 0;
		pi->i_start_sect = MAKE_DEV(DEV_CHAR_TTY, i);
		debug("pi->i_start_sect = %d",MAKE_DEV(DEV_CHAR_TTY, i));
		pi->i_nr_sects = 0;
	}
	WR_SECT(ROOT_DEV, 2 + sb.nr_imap_sects + sb.nr_smap_sects);

	/************************/
	/*          `/'         */
	/************************/
	memset1(fsbuf, 0, SECTOR_SIZE);
	struct dir_entry * pde = (struct dir_entry *)fsbuf;

	pde->inode_nr = 1;
	strcpy(pde->name, ".");

	/* dir entries of `/dev_tty0~2' */
	for (i = 0; i < NR_CONSOLES; i++) {
		pde++;
		pde->inode_nr = i + 2; /* dev_tty0's inode_nr is 2 */
		
		sprintf(pde->name, "dev_tty%d", i);
		
		debug("pde->inode_nr = %d",pde->inode_nr);
		debug("pde->name = %s",pde->name);
	}
	WR_SECT(ROOT_DEV, sb.n_1st_sect);
}