Exemplo n.º 1
0
static vod_status_t
mp4_encrypt_video_snpf_build_auxiliary_data(mp4_encrypt_video_state_t* state)
{
	u_char iv[MP4_AES_CTR_IV_SIZE];
	uint32_t bytes_of_encrypted_data;
	uint16_t bytes_of_clear_data;
	bool_t init_track;
	u_char* p;

	state->default_auxiliary_sample_size = sizeof(cenc_sample_auxiliary_data_t) + sizeof(cenc_sample_auxiliary_data_subsample_t);
	state->saiz_sample_count = state->base.sequence->total_frame_count;

	p = vod_alloc(
		state->base.request_context->pool, 
		state->default_auxiliary_sample_size * state->base.sequence->total_frame_count);
	if (p == NULL)
	{
		vod_log_debug0(VOD_LOG_DEBUG_LEVEL, state->base.request_context->log, 0,
			"mp4_encrypt_video_snpf_build_auxiliary_data: vod_alloc failed");
		return VOD_ALLOC_FAILED;
	}

	state->auxiliary_data.start = p;

	bytes_of_clear_data = state->base.cur_clip->first_track->media_info.u.video.nal_packet_size_length + 1;
	vod_memcpy(iv, state->base.iv, sizeof(iv));

	for (;;)
	{
		if (!mp4_encrypt_move_to_next_frame(&state->base, &init_track))
		{
			break;
		}

		if (init_track)
		{
			bytes_of_clear_data = state->base.cur_clip->first_track->media_info.u.video.nal_packet_size_length + 1;
		}

		// cenc_sample_auxiliary_data_t
		p = vod_copy(p, iv, sizeof(iv));
		mp4_aes_ctr_increment_be64(iv);
		write_be16(p, 1);		// subsample count

		// cenc_sample_auxiliary_data_subsample_t
		bytes_of_encrypted_data = state->base.cur_frame->size - bytes_of_clear_data;
		write_be16(p, bytes_of_clear_data);
		write_be32(p, bytes_of_encrypted_data);

		state->base.cur_frame++;
	}

	state->auxiliary_data.pos = p;

	// reset the state
	state->base.cur_clip = state->base.sequence->filtered_clips;
	mp4_encrypt_init_track(&state->base, state->base.cur_clip->first_track);

	return VOD_OK;
}
Exemplo n.º 2
0
int mb_ct_req_write(mb_msg *buf, uint16_t addr, uint16_t val)
{
	int e;
	if(!buf) return(MB_ENOBUF);
	if((e=mb_setbuflen(buf, 8))) return(e);
	buf->data[0]=MB_SLAVEADDR;
	buf->data[1]=MB_FN_WRITE;
	if((e=write_be16(buf->data+2, addr))) return(e);
	if((e=write_be16(buf->data+4, val))) return(e);
	if((e=mb_apply_crc16(buf))) return(e);
	return(MB_EOK);
}
Exemplo n.º 3
0
// Request constructors (mb_ct_req_*) build a request datagram
//	First arg is always mb_msg *buf, whence the result
int mb_ct_req_readn(mb_msg *buf, uint16_t addr, size_t words)
{
	int e;
	if(!buf) return(MB_ENOBUF);
	if(words>80) return(MB_EDLONG);
	if((e=mb_setbuflen(buf, 8))) return(e);
	buf->data[0]=MB_SLAVEADDR;
	buf->data[1]=MB_FN_READN;
	if((e=write_be16(buf->data+2, addr))) return(e);
	if((e=write_be16(buf->data+4, words))) return(e);
	if((e=mb_apply_crc16(buf))) return(e);
	return(MB_EOK);
}
Exemplo n.º 4
0
int mb_apply_crc16(mb_msg *buf)
{
	int e;
	uint16_t crc;
	if((e=mb_crc16(buf, &crc))) return(e);
	if((e=write_be16(buf->data+buf->len-2, crc))) return(e);
	return(MB_EOK);
}
Exemplo n.º 5
0
int mb_ct_req_writen(mb_msg *buf, uint16_t addr, size_t words, uint16_t *vals)
{
	int e;
	if(!buf) return(MB_ENOBUF);
	if(!vals) return(MB_EINVAL);
	if(words>80) return(MB_EDLONG);
	if((e=mb_setbuflen(buf, 9+(words<<1)))) return(e);
	buf->data[0]=MB_SLAVEADDR;
	buf->data[1]=MB_FN_WRITEN;
	if((e=write_be16(buf->data+2, addr))) return(e);
	if((e=write_be16(buf->data+4, words))) return(e);
	buf->data[6]=words<<1; // won't overflow since words<=80
	for(size_t i=0;i<words;i++)
	{
		if((e=write_be16(buf->data+7+(i<<1), vals[i]))) return(e);
	}
	if((e=mb_apply_crc16(buf))) return(e);
	return(MB_EOK);
}
Exemplo n.º 6
0
static vod_status_t
mp4_encrypt_video_end_frame(mp4_encrypt_video_state_t* state)
{
	size_t sample_size;
	u_char* p;

	// add the sample size to saiz
	sample_size = sizeof(cenc_sample_auxiliary_data_t)+
		state->subsample_count * sizeof(cenc_sample_auxiliary_data_subsample_t);
	*(state->auxiliary_sample_sizes_pos)++ = sample_size;

	// update subsample count in auxiliary_data
	p = state->auxiliary_data.pos - sample_size + offsetof(cenc_sample_auxiliary_data_t, subsample_count);
	write_be16(p, state->subsample_count);

	return VOD_OK;
}
Exemplo n.º 7
0
static vod_status_t
mp4_encrypt_video_add_subsample(mp4_encrypt_video_state_t* state, uint16_t bytes_of_clear_data, uint32_t bytes_of_encrypted_data)
{
	vod_status_t rc;

	rc = vod_dynamic_buf_reserve(&state->auxiliary_data, sizeof(cenc_sample_auxiliary_data_subsample_t));
	if (rc != VOD_OK)
	{
		vod_log_debug1(VOD_LOG_DEBUG_LEVEL, state->base.request_context->log, 0,
			"mp4_encrypt_video_add_subsample: vod_dynamic_buf_reserve failed %i", rc);
		return rc;
	}
	write_be16(state->auxiliary_data.pos, bytes_of_clear_data);
	write_be32(state->auxiliary_data.pos, bytes_of_encrypted_data);
	state->subsample_count++;

	return VOD_OK;
}
Exemplo n.º 8
0
static int boot_mips_write(FILE *outfile)
{
	struct directory_entry	*boot_file;	/* Boot file we need to search for */
    unsigned long length = 0;
    unsigned long extent = 0;
	int i;
	struct volume_header vh;
    unsigned long long iso_size = 0;
    char *filename = NULL;

	memset(&vh, 0, sizeof(vh));

    iso_size = last_extent * 2048;

    write_be32(VHMAGIC, (unsigned char *)&vh.vh_magic);

	/* Values from an IRIX cd */
    write_be16(BYTES_PER_SECTOR, (unsigned char *)&vh.vh_dp.dp_secbytes);
    write_be16(SECTORS_PER_TRACK, (unsigned char *)&vh.vh_dp.dp_secs);
    write_be32(DP_RESEEK|DP_IGNOREERRORS|DP_TRKFWD, (unsigned char *)&vh.vh_dp.dp_flags);
    write_be16(1, (unsigned char *)&vh.vh_dp.dp_trks0);

    write_be16((iso_size + BYTES_PER_SECTOR - 1) / (SECTORS_PER_TRACK * BYTES_PER_SECTOR),
               (unsigned char *)&vh.vh_dp.dp_cyls);

	for(i = 0; i < boot_mips_num_files; i++)
    {
        boot_file = search_tree_file(root, boot_mips_filename[i]);
        
        if (!boot_file) {
#ifdef	USE_LIBSCHILY
            comerrno(EX_BAD, "Uh oh, I cant find the MIPS boot file '%s'!\n",
                     boot_mips_filename[i]);
#else
            fprintf(stderr, "Uh oh, I cant find the MIPS boot file '%s'!\n",
                    boot_mips_filename[i]);
            exit(1);
#endif
        }

        extent = get_733(boot_file->isorec.extent) * 4;
        length = ((get_733(boot_file->isorec.size) + 2047) / 2048) * 2048;
        filename = file_base_name(boot_mips_filename[i]);

        strncpy((char *)vh.vh_vd[i].vd_name, filename, MIN(VDNAMESIZE, strlen(filename)));
        write_be32(extent, (unsigned char *)&vh.vh_vd[i].vd_lbn);
        write_be32(length, (unsigned char *)&vh.vh_vd[i].vd_nbytes);
        
        fprintf(stderr, "Found mips boot image %s, using extent %lu (0x%lX), #blocks %lu (0x%lX)\n",
                filename, extent, extent, length, length);
	}

	/* Create volume partition on whole cd iso */
    write_be32((iso_size + (BYTES_PER_SECTOR - 1))/ BYTES_PER_SECTOR, (unsigned char *)&vh.vh_pt[10].pt_nblks);
    write_be32(0, (unsigned char *)&vh.vh_pt[10].pt_firstlbn);
    write_be32(PTYPE_VOLUME, (unsigned char *)&vh.vh_pt[10].pt_type);

	/* Create volume header partition, also on WHOLE cd iso */
    write_be32((iso_size + (BYTES_PER_SECTOR - 1))/ BYTES_PER_SECTOR, (unsigned char *)&vh.vh_pt[8].pt_nblks);
    write_be32(0, (unsigned char *)&vh.vh_pt[8].pt_firstlbn);
    write_be32(PTYPE_VOLHDR, (unsigned char *)&vh.vh_pt[8].pt_type);

	/* Create checksum */
	vh_calc_checksum(&vh);

    jtwrite(&vh, sizeof(vh), 1, 0, FALSE);
    xfwrite(&vh, sizeof(vh), 1, outfile, 0, FALSE);
    last_extent_written++;

	return 0;
}