Using opaque data types in C

Suppose if we have to write a SDK and don’t want others to know the details of function parameters, we can use opaque data types in C. In most of the cases, you may not need these. But if you use them, it will be very difficult for hacker/crackers to know what is being stored in the datatype. I have made a sample library and a program which uses them. You can download them here. I have written this code just to demonstrate; it is not optimized.
test1.h and test1.c are used to generate libtest1.so file. test2.c is used to test the library. We give only test1.h and libtest1.so files to our customers. Lets assume test2.c is the program written by him. By seeing test1.h, customer does not know what is “opaque_type1“. But he uses it in his code [test2.c] and gets the result.

If we are using C structures for making opaque data types, we can’t use them directly as compiler does not know the size of it to allocate[In my code, I have implemented opaque data types using C structures. They are just declared not defined]. We always have to use them as pointers.

Advertisements

2 Comments

  1. Mustafa Hussain said,

    March 28, 2007 at 6:22 pm

    hello,
    i am studying the code of CFS in which opaque data type is being used.if anyone can give me an example (in code, ofcourse) with an explanation, i will be grateful to him/her.
    bye.

  2. test2 said,

    September 25, 2012 at 8:21 pm

    I relish, result in I found just what I used to be having a look for. You have ended my four day lengthy hunt! God Bless you man. Have a great day. Bye


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: