コード例 #1
0
ファイル: drvinst.c プロジェクト: capturePointer/diskcryptor
int dc_update_driver()
{
	wchar_t      buff[MAX_PATH];
	dc_conf_data conf;
	int          resl;

	do
	{
		if ( (resl = dc_save_drv_file(drv_dc)) != ST_OK ) {
			break;
		}
		if ( (resl = dc_load_conf(&conf)) != ST_OK ) {
			break;
		}
		if (conf.build < 692) 
		{
			/* remove old file system filter driver */
			if (dc_remove_service(drv_fsf) == ST_OK)
			{
				dc_get_driver_path(buff, drv_fsf);
				DeleteFile(buff);
			}
			/* add Altitude */
			if ( (resl = dc_add_altitude()) != ST_OK ) {
				break;
			}
		}
		if (conf.build < 366)
		{
			/* add CDROM class filter */
			dc_add_filter(cdr_key, drv_dc, 1);
			/* set new default flags */
			conf.conf_flags |= CONF_HW_CRYPTO | CONF_AUTOMOUNT_BOOT;
		}
		if (conf.build < 642) {
			conf.conf_flags |= CONF_ENABLE_SSD_OPT;
		}
		resl = dc_save_conf(&conf);
	} while (0);

	if (resl == ST_OK) 
	{
		_snwprintf(
			buff, sizeof_w(buff), L"DC_UPD_%d", dc_get_version());

		GlobalAddAtom(buff);			
	}
	return resl;
}
コード例 #2
0
ファイル: cd_enc.c プロジェクト: dwalkes/RDXEncryption
int dc_encrypt_cd(
	  wchar_t *src_path, wchar_t *dst_path, dc_pass *pass, 
	  int      cipher, cd_callback callback, void *param
	  )
{
	dc_conf_data conf;
	HANDLE       h_src = NULL;
	HANDLE       h_dst = NULL;
	xts_key     *v_key = NULL;
	xts_key     *h_key = NULL;
	dc_header    head;
	int          resl;
	u64          iso_sz;
	u32          bytes;
	u8           salt[PKCS5_SALT_SIZE];
	u8           dk[DISKKEY_SIZE];
	
	if (alg_ok == 0) 
	{
		if (dc_load_conf(&conf) == ST_OK) {
			xts_init(conf.conf_flags & CONF_HW_CRYPTO);
		} else {
			xts_init(0);
		}
		alg_ok = 1;
	}

	do
	{
		if ( (resl = dc_lock_memory(dk, sizeof(dk))) != ST_OK ) {
			break;
		}
		if ( (resl = dc_lock_memory(&head, sizeof(head))) != ST_OK ) {
			break;
		}

		h_src = CreateFile(
			src_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0);

		if (h_src == INVALID_HANDLE_VALUE) {
			h_src = NULL; resl = ST_NO_OPEN_FILE; break;
		}

		h_dst = CreateFile(
			dst_path, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0);

		if (h_dst == INVALID_HANDLE_VALUE) {
			h_dst = NULL; resl = ST_NO_CREATE_FILE; break;
		}

		if (GetFileSizeEx(h_src, pv(&iso_sz)) == 0) {
			resl = ST_IO_ERROR; break;
		}

		v_key = VirtualAlloc(NULL, sizeof(xts_key), MEM_COMMIT+MEM_RESERVE, PAGE_EXECUTE_READWRITE);
		h_key = VirtualAlloc(NULL, sizeof(xts_key), MEM_COMMIT+MEM_RESERVE, PAGE_EXECUTE_READWRITE);
		
		if ( (v_key == NULL) || (h_key == NULL) ) {
			resl = ST_NOMEM; break;
		}

		/* lock keys in memory */
		if ( (resl = dc_lock_memory(v_key, sizeof(xts_key))) != ST_OK ) {
			break;
		}
		if ( (resl = dc_lock_memory(h_key, sizeof(xts_key))) != ST_OK ) {
			break;
		}

		/* create volume header */
		zeroauto(&head, sizeof(dc_header));

		dc_get_random(pv(salt),          PKCS5_SALT_SIZE);
		dc_get_random(pv(&head.disk_id), sizeof(u32));
		dc_get_random(pv(head.key_1),    DISKKEY_SIZE);

		head.sign     = DC_VOLM_SIGN;
		head.version  = DC_HDR_VERSION;
		head.flags    = VF_NO_REDIR;
		head.alg_1    = cipher;
		head.use_size = iso_sz;
		head.data_off = sizeof(dc_header);
		head.hdr_crc  = crc32(pv(&head.version), DC_CRC_AREA_SIZE);

		/* initialize volume key */
		xts_set_key(head.key_1, cipher, v_key);

		/* initialize header key */
		sha512_pkcs5_2(
			1000, pass->pass, 
			pass->size, salt, PKCS5_SALT_SIZE, dk, PKCS_DERIVE_MAX);

		xts_set_key(dk, cipher, h_key);

		/* encrypt volume header */
		xts_encrypt(pv(&head), pv(&head), sizeof(dc_header), 0, h_key);

		/* save salt */
		autocpy(head.salt, salt, PKCS5_SALT_SIZE);

		/* write volume header to file */
		if (WriteFile(h_dst, &head, sizeof(head), &bytes, NULL) == 0) {
			resl = ST_IO_ERROR; break;
		}

		resl = do_cd_encrypt(h_src, h_dst, iso_sz, v_key, callback, param);
	} while (0);

	/* prevent leaks */
	zeroauto(dk, sizeof(dk));
	zeroauto(&head, sizeof(head));
	dc_unlock_memory(dk);
	dc_unlock_memory(&head);

	if (v_key != NULL) {
		zeroauto(v_key, sizeof(xts_key));
		dc_unlock_memory(v_key);
		VirtualFree(v_key, 0, MEM_RELEASE);
	}

	if (h_key != NULL) {
		zeroauto(h_key, sizeof(xts_key));
		dc_unlock_memory(h_key);
		VirtualFree(h_key, 0, MEM_RELEASE);
	}

	if (h_src != NULL) {
		CloseHandle(h_src);
	}

	if (h_dst != NULL) 
	{
		CloseHandle(h_dst);

		if (resl != ST_OK) {
			DeleteFile(dst_path);
		}	
	}

	return resl;
}