Hello everyone and it's nice to be here!
I have a rather complex task (for me) and I'm new to C. I worked with the language the past month but lets just say C is not trivial (for me). What I have to do is the following: four functions and they all deal with a byte file that contains several information. I started programming and I was able to achieve some parts but now I'm running into some problems and I need some help from more experienced programmer.
The function takes a random file n and does more or less this:
- Apply encoding on n and save n'
- Create random numbers and a key and encrypt all of it and append it to n'
- Create a mac of the current file and append it to the rest
Right now I'm appending the bytes by just using fwrite. BUT how will I be able to retrieve the information again in a different function without knowing the size of the parts? Is there a convenient way to write a struct and parse it easily back?
Further, I'm using libgcrypt (GnuPG) for generating values, hashing, and encryption. Besides the lack of real examples, I'm struggling with the debugging. I'm using notepad++ to view (or should I say explore) my created files. Is it possible to print char* in hex and view files in the same way? That would make it (hopefully) easier!
Last but not least: Like I said I'm new to C; therefore, the concept of memory management is new to me. Most of the time I have to use char* to point to the file content, keys, hashs etc.. I always allocate memory and stuff, but reading about the different register sizes and different platforms I'm scared that my code will not work on another machine. Are there guidelines or things I have to consider to make my code portable?
Thanks