Does Crypto++ support TOFB-I? - c++

I'm developing a C++ application to decrypt the data encrypted by someone else with TOFB-I (TDEA Output Feedback - Interleaved).
To do this I'm using the Crypto++ library.
Unfortunately, the result of the decryption doesn't seem to work: the first byte is decrypted correctly, the rest is just meaningless data.
I've double checked with the Linux command line tool OpenSSL and get exactly the same result.
So I'm inclined to believe that I'm applying a decryption algorithm with wrong feedback, so that the first IV works fine but something goes wrong with the feedbacks.
My question is: how do I apply the interleaved variant of the DES_OFB mode?
Couldn't find anything about this either in the Crypto++ or in the OpenSSL documentation.

Apparently Crypto++ (and also OpenSSL) doesn't support TOFB-I operation mode:
http://csrc.nist.gov/groups/STM/cavp/documents/des/tripledesval.html
Actually, according to the above link no implementation has been validated yet as conforming to TOFB-I!
So I guess I'll need to implement my own TOFB-I algo.

Related

Encrypting text file with AES-256 CBC

I've been trying to pick up C++ and computer security in my own free time and I've been attempting some CTF challenges.
The challenge was about finding out the number of words (N) in a text file (x.txt), and using N as a key to encrypt the text file (x.txt) using AES-256 CBC and outputting a new text file (y.txt) with the encrypted contents.
I have no problems getting the number of words from the text file, but I was just wondering if anyone knows how to perform the encryption stated?
I've been reading up on OpenSSL for this but I can't proceed further. I assume the IV would be zero in this case?
Thanks in advance.
I assume the IV would be zero in this case?
An IV or Initialization Vector, is the "seed" for encryption. It is needed so that plaintexts that are similar don't look similar when encrypted. It is meant to never repeat between different encryption runs and is not secret. A zero IV (or any other fixed IV) would thus defeat the purpose.
A typical approach with AES-CBC is during encryption to generate a random IV and store it together with the ciphertext. Then during decryption read it in and use it to initialize the decryptor.
To know more about the OpenSSL API's to use, refer to OpenSSL Wiki - Symmetric Encryption.
I'm currently learning about AES too. Here are some resources I found useful:
How to perform AES encryption:
It boils down to 4 steps per round:
Substitute bytes (using the S-box)
Shifting the rows
Mixing the columns
Adding the round key
There's a really good video about how to perform each AES round by Professor Paar. Here is a link to his AES video. His whole channel is really a gold mine with regards to learning crypto. Note: You will need to hard code the S-box or include it somehow.
One thing Prof. Paar doesn't explain in the video is key expansion (aka how to get each round key). You can find a java implementation of key expansion on Professor Wagner's page here. It should be relatively straight forward to refactor into C++. Just remember to include the round constant table.

Simple text-file encryption in C++

So I was looking at ways to lock file folders with a password in windows, and this type of security is not really supported.
Given I know C++ I was wondering if I could simply do this myself.
It would be simple enough, in the case of a text file, to copy the entire contents of the file into a C-string. I could then use basic logic to prompt for a password, if it matches, use an fstream overload and insert the whole string into a text file.
Then, simply wipe the file when I'm done using it.
I basically know how to do this, and the result would be a string containing the document compiled into a .exe which I assume would be unreadable. The thing is, I've never really studied encryption or computer security so I'm wondering how secure this would be, or if there is a better way to do this?
Could it be done on photo or video files as well, if so, how?
How hard would it be to reverse (decompile) the process?
What types of things could I do to make reversal more difficult, ie. using multiple strings, or mixing in random characters?
I'm not looking to hide super-sensitive files, I'm just curious about encryption basics.
Never implement crypto yourself - it is destined to fail. Use well reviewed libraries such as OpenSSL. A good example of using AES for file encryption: Encrypting and decrypting a small file using openssl
Using such simple approach will let you encrypt any file. And it will be secure. Why settle for weak encryption if you can have strong encryption?
If you don't want to write a program, just get, for example, OpenSSL and use the terminal: openssl des3 -salt -in file.txt -out file.des3

Parse encrypted file with openssl

I have encrypted a file with openssl, now I would like to read the encrypted file (actually parse that file) without decrypting it. Basically I want to see if the encrypted file contains a certain word. How can I do that? I searched different blogs and posts and the only solution I could come up with is to decrypt the file (which creates a new READABLE file), search the word in the decrypted file and then remove it. Since I don't like having to create a decrypted copy of the file and then remove it, is there any way that I can parse/read the file without decrypting it? I should probably mention that I am using c++, but I don't think it really matters, am I correct?
Thanks in advance for all the help you can give me.
There is no way to parse a file that is encrypted (at least if you are using a reasonable, not trivially breakable - pretty much everything beyond a Ceasar cipher or a XOR cipher counts as "not trivially breakable" in this context).
In other words, you will need to find a way to decrypt the content - one solution is of course to decrypt to memory, or to stdout and use a pipe to read from the file.
An example (written here as a general idea, the exact code may need some adjusting):
FILE* p = popen("openssl des3 -d -in myfile.encrypted", "r");
int ch;
while((ch = fgetc(p)) != EOF)
{
... process a character at a time ...
}
pclose(p);
I have encrypted a file with openssl, now I would like to read the encrypted file (actually parse that file) without decrypting it... to see if the encrypted file contains a certain word.
To preserve semantic security, you need to use a homomorphic encryption scheme. OpenSSL does not support those cryptosystems, so its probably not possible using OpenSSL.
If you don't care about semantic security, then you can probably use any number of schemes. Mats gave you a couple of them. But they will leak information like a sieve and are probably trivial to break with simple techniques like frequency analysis.
You might want to read up on Fully Homomorphic Encryption and Somewhat Homomorphic Encryption schemes. If the scheme is built on a lattice, then the NTRU library might offer the scheme or a useful primitive. Shoup's NTL library might also offer the scheme or primitives. (I don't know because I don't use FHE or SHE schemes).
You should also talk to the folks on security.stackexchange.com or crypto.stackexchange.com.

is there any library support RSASSA-PSS with EMSA-PSS encoding technique and certificate validation..?

i need to sign the data using RSASSA-PSS with EMSA-PSS encoding .. openssl does not support this algorithm .can any tell me is there any other open source libraries available to do this..?
Crypto++ mentiones PSS and EMSA.
OpenSSL supports RSA-PSS (http://www.openssl.org/docs/apps/pkeyutl.html#RSA_ALGORITHM), as well as other libraries (BouncyCastle should do that as well).
Have look here:
http://fixunix.com/openssl/526614-signing-verifying-messages-rsassa-pss.html
I haven't try this implementation, but I have one of my own that looks like this one, and it's perfectly working

How to sign XML document or verify XML document signature with C++?

Subj. I need to sign/verify under Windows in native C++ (no .NET), using private key for signing, public key for verification.
I saw few examples on MSDN (http://msdn.microsoft.com/en-us/library/ms761363(VS.85).aspx) that demonstrate how to sign the document with CSP (I don't know what this means).
For my case I need to use a "key" from the binary data array (using DSA encryption algorithm)... can somebody help me with that?
Thank you in advance.
I recommand libxml2 and xmlsec which are perfect for this purpose.
The API can seem hard to read at first, but it works well. xmlsec uses OpenSSL to achieve the cryptographic part.
Providing a "short" example here is probably hard because the three libraries require some initialization and a lot of C calls.
Google's keyczar lib is also very easy to use
There's also Crypto++