LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 03-17-2017, 04:36 AM   #1
AccumPlus
LQ Newbie
 
Registered: Feb 2017
Posts: 5

Rep: Reputation: Disabled
Decrypt device driver


I got a task to make a small image, encrypt it with the simpliest method and write a decrypt driver.

Making an image:

Code:
dd if=/dev/zero of=myFS bs=1024 count=60
mkfs.ext2 myFS
Encrypting with XOR:

Code:
int main()
{
    std::fstream streamIn;
    std::fstream streamOut;

    const char key = 0b00001111;

    streamIn.open("myFS", std::ios_base::binary | std::ios_base::in);
    streamOut.open("newFS", std::ios_base::binary | std::ios_base::trunc | std::ios_base::out);

    char b;
    while (streamIn.read(&b, 1))
    {
        b ^= key;
        streamOut.write(&b, 1);
    }

    streamIn.close();
    streamOut.close();

    return 0;
}
Then writing driver. It is based on device-mapper target and the main working function has this prototype:

Code:
static int sddm_target_map(struct dm_target *ti, struct bio *bio);
You see, I have a bio structure, and I think, that I should decrypt every byte it contains. What I have now:

Code:
struct bio_vec vec;
struct bvec_iter it;
unsigned int len;
char *addr;
unsigned int i;

bio_for_each_segment(vec, bio, it)
{
    len = vec.bv_len;
    addr = (char*)(page_address(vec.bv_page) + vec.bv_offset);

    for (i = 0; i != len; ++i)
    {
        *(addr+i) ^= 0b00001111;
    }
}
Of course, it doesn't work. Attempts to mount it finished with error:

Code:
mount: wrong fs type, bad option, bad superblock on /dev/mapper/mydevice
Also saw another algorithm:

Code:
bio_for_each_segment(vec, bio, it)
{
    len = vec.bv_len;
    addr = kmap_atomic(vec.bv_page);
    pointer = (char *)(addr + vec.bv_offset);

    for (i = 0; i != len; ++i)
    {
        *(pointer+i) ^= 0b00001111;
    }

    kunmap_atomic(addr);
}
But it goes with the same error.

How can I implement my plan? Thanks in advance!
 
  


Reply

Tags
device driver, driver



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Driver core binding device to driver and Udev loading driver module-difference? ayyasprings Linux - Embedded & Single-board computer 0 01-23-2016 01:44 PM
Bind only 1 device to vfio driver that have same vendor/device id's Eusaphious Linux - General 1 05-19-2015 09:41 PM
[SOLVED] USB device is not claimed by any active driver for every device in Linux 2.4 jacquesdirac Linux - Hardware 3 11-12-2010 08:35 AM
Question about usb storage device and device driver balteo Linux - Hardware 2 11-21-2009 09:37 AM
Multiple Device driver from single device driver???? rickhg12hs Linux - Kernel 3 05-25-2008 12:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 11:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration