mic...@gmail.com
unread,Feb 10, 2008, 9:18:09 AM2/10/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Crypto++ Users
Hello,
I have tried to use crypto++ to get the same result as mcrypt for a
simple CFB crypto. The reason is I am trying to write a new client for
an existing server that use mcrypt, and mcrypt is not "easily"
available for windows.
The result from mcrypt is:
0xa7, 0x8f, 0x88, 0x4e, ...
Where-as the result from crypto++ is:
0xa7, 0x44, 0x24, 0x6e, ...
As you can see the first byte is the same but the following ones are
not. I have seen another post on the list regarding a similar issue
but there was no solution. I am thinking it might be related to some
issues with block-size or some such but I am not an expert on
cryptography so I hope that someone here might be able to help me with
this. I have also tried this with DES/3DES with the exact same result
(ie. first char correct, the rest are not).
// Michael Medin
The code I use is:
#include <stdio.h>
#include <mcrypt.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <crypto++/cryptlib.h>
#include <crypto++/modes.h>
#include <crypto++/des.h>
#include <crypto++/aes.h>
#include <crypto++/filters.h>
#include <mcrypt.h>
unsigned char key[] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30,
0x31, 0x32}; // 12345678901234567890123456789012
unsigned char iv[] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36}; // 1234567890123456
unsigned char plain[] = {0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77,
0x6f, 0x72, 0x6c, 0x64}; // hello world
void print_it(char *title, unsigned char* buff, int len) {
int i;
printf("unsigned char %s[] = {", title);
for (i=0;i<len-1;i++) {
printf("0x%x, ", (unsigned char)buff[i]);
}
printf("0x%x", (unsigned char)buff[len-1]);
printf("} // %s\n", buff);
}
void testCryptoPP() {
CryptoPP::CFB_Mode< CryptoPP::AES >::Encryption encryptor(key,
sizeof(key), iv, sizeof(iv));
unsigned char ciphertext[100];
for(int x=0;x<sizeof(plain);x++) {
encryptor.ProcessData(&ciphertext[x], (unsigned char*)&plain[x], 1);
ciphertext[x+1] = 0;
}
print_it("plain", plain, sizeof(plain));
print_it("crypto", ciphertext, sizeof(plain));
}
void testMCrypt() {
MCRYPT td;
td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,NULL,"cfb",NULL);
int iv_size = mcrypt_enc_get_iv_size(td);
printf("iv size: %d (%d)\n", iv_size, sizeof(iv));
int key_size = mcrypt_enc_get_key_size(td);
printf("key size: %d (%d)\n", key_size, sizeof(key));
mcrypt_generic_init(td,key,key_size,iv);
print_it("plain", plain, sizeof(plain));
for(int x=0;x<sizeof(plain);x++)
mcrypt_generic(td,&plain[x],1);
print_it("mcrypt", plain, sizeof(plain));
}
int main(int argv, char *argc[]) {
testCryptoPP();
testMCrypt();
}