Вопрос

I need help in Kocher's blowfish algorythm to implement in C. Its url is(http://www.schneier.com/code/bfsh-koc.zip). I could do the basics (initialize), but decryption isn't well. I know I should work with longs, but please help me to write a char * function what needs (char *encrypted_text) and returns the decrypted text. THANKS

Это было полезно?

Решение 2

here are the basics of encryption, how it works in code depends on the implementation:

do some sort of initialization of state, include the encryption key up to 56 bytes, set up the mode (cbc, ecb, etc)

feed into your machine (Block Size) byte chunks of data until you are out of data... be sure to pad the end of the data stream somehow to get to 8 bytes...

now that your have completed you can extract the hash from the state...

see doesn't that sound easy...

now an openSSL example:

void *source = "12345678";
size_t len = strlen(source);
assert(len % BF_BLOCK == 0);
void *dest = malloc(len);
BF_KEY key;
BF_set_key(&key, 5, "12345"); // make a key

while(len > 0) {
    BF_ecb_encrypt(source, dest, key, 1);// or other BF function see docs.
    source += BF_BLOCK;
    dest += BF_BLOCK;
    len -= BF_BLOCK;
}

Другие советы

Blowfish is already implemented in C all over the place. There's no need to write it yourself.

The PolarSSL library has a C implementation, which can be found here.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top