Yep, that solved it! That makes sense. Thankyou so much!
On Wed, Nov 2, 2011 at 12:08 AM, re.est <re.est1...@gmail.com> wrote: > Hello, > > I added *8 in length for both encrypt/decrypt call to make it bit length. > AES_cfb1_encrypt(data, ciphertext, length*8, &key, iv, &num, > AES_ENCRYPT); > > As you can see, cfb128_1 has uses bit as length in API > void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out, > size_t bits, const void *key, ....... > > unlike other cfb APIs. > > > > > > On 11/01/2011 09:48 PM, Ananthasayanan Kandiah wrote: > > Hi, > > I would be grateful if you could expand on this. I've tried simply placing > the bit length for the AES_set_encrypt_key call and it still produces the > same result. > > > Thanks, > Anantha > > On Tue, Nov 1, 2011 at 8:10 PM, re est <re.est1...@gmail.com> wrote: > >> Hi, >> >> I have tried your code and replaced the length param with bit length >> (*8) instead. >> It worked. It seems that there are inconsistent with the usage of API. >> >> - re.est >> >> On Sun, Oct 30, 2011 at 4:55 PM, Ananthasayanan Kandiah >> <ananthasaya...@obtino.com> wrote: >> > Hi, >> > >> > I'm trying to use AES-CFB1 through the "low-level" calls. Here's the >> example >> > program I have come up with: >> > >> > #include <stdio.h> >> > #include <string.h> >> > #include <openssl/aes.h> >> > #include <openssl/bio.h> >> > >> > #define KEY_SIZE 16 >> > >> > int main(void) >> > { >> > int i; >> > AES_KEY key; >> > BIO* bio_out; >> > >> > unsigned char key_data[KEY_SIZE] = { >> > 0xfe, 0xec, 0x82, 0x17, 0xb5, 0x1, 0x98, 0x6b, >> > 0x5e, 0xf1, 0xb8, 0x6, 0x52, 0x74, 0x2e, 0x52 >> > }; >> > >> > unsigned char iv[AES_BLOCK_SIZE]; >> > >> > unsigned char const iv_data[AES_BLOCK_SIZE] = { >> > 0x10, 0x8a, 0xc9, 0x30, 0xb7, 0xf2, 0x35, 0x21, >> > 0xfb, 0xac, 0x6b, 0xdf, 0x80, 0x95, 0xeb, 0x1e >> > }; >> > >> > char* data = "Internet is a wonderful mechanism for making a >> fool " >> > "of yourself in front of a very large audience"; >> > >> > >> > int length = (int) strlen(data); >> > >> > int num = 0; >> > >> > /* Allocate some space for the ciphertext and plaintext */ >> > char* ciphertext = (char*) malloc(sizeof(char) * length); >> > char* plaintext = (char*) malloc(sizeof(char) * length); >> > >> > /* Copy the IV data to the IV array */ >> > memcpy(iv, iv_data, AES_BLOCK_SIZE); >> > >> > /* Set the encrypt key structure using the predefined key */ >> > AES_set_encrypt_key(key_data, KEY_SIZE * 8, &key); >> > >> > /* Carry out the encryption */ >> > AES_cfb1_encrypt(data, ciphertext, length, &key, iv, &num, >> AES_ENCRYPT); >> > >> > /* Setup output */ >> > bio_out = BIO_new_fp(stdout, BIO_NOCLOSE); >> > >> > BIO_printf(bio_out, "Original plaintext: %s\n\n", data); >> > >> > BIO_printf(bio_out, "Ciphertext: "); >> > >> > /* Print out the ciphertext */ >> > for (i = 0; i < length; i++) >> > BIO_printf(bio_out, "%02x", ((unsigned char*)ciphertext)[i]); >> > >> > BIO_printf(bio_out, "\n\n"); >> > >> > /* Start the decryption process */ >> > >> > /* First, copy the original IV data back to the IV array - as it was >> > overwritten >> > * during the encryption process >> > */ >> > memcpy(iv, iv_data, AES_BLOCK_SIZE); >> > >> > /* Reset how far we've gone through the IV */ >> > num = 0; >> > >> > /* Carry out the decryption */ >> > AES_cfb1_encrypt(ciphertext, plaintext, length, &key, iv, &num, >> > AES_DECRYPT); >> > >> > BIO_printf(bio_out, "Recovered plaintext: "); >> > >> > /* print out the plaintext */ >> > for (i = 0; i < length; i++) >> > BIO_printf(bio_out, "%c", ((unsigned char*)plaintext)[i]); >> > >> > BIO_printf(bio_out, "\n\n"); >> > >> > BIO_free(bio_out); >> > >> > free(ciphertext); >> > free(plaintext); >> > >> > >> > return 0; >> > } >> > >> > When I run it, the output which I receive is: >> > >> > Original plaintext: Internet is a wonderful mechanism for making a >> foolof >> > yourself in front of a very large audience >> > >> > Ciphertext: >> > >> 92c0883c54eb8df072b43278000000000000000000000000000000000000000000000000000000000000000000000000000000000000 >> > >> 000000000000000000000000000000000000000000000000000000000000000000000000000000000000 >> > >> > Recovered plaintext: Internet is >> > >> > >> > >> d:\ananthasayanan\stuff\projects\programming\openssl\openssl-1.0.0d\demos\crypto\low_level\ciphers\symmetric\aes\aes_cfb >> > 1_128\x64\Release>aes_cfb1_128.exe >> > Original plaintext: Internet is a wonderful mechanism for making a fool >> of >> > yourself in front of a very large audience >> > >> > Ciphertext: >> > >> 92c0883c54eb8df072b43278000000000000000000000000000000000000000000000000000000000000000000000000000000000000 >> > >> 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000 >> > >> > Recovered plaintext: Internet is >> > >> > As you can see, the ciphertext that is produced is only 12 bytes in >> length. >> > Hence, the recovered plaintext has only 12 characters. I have had a >> look at >> > the source-code for AES_cfb1_encrypt and the comment says that the input >> > should be "packed". What does this mean? Am I doing something wrong or >> is >> > there a bug with AES-CFB1? >> > >> > >> > Thanks, >> > Anantha >> > >> > >> ______________________________________________________________________ >> OpenSSL Project http://www.openssl.org >> User Support Mailing List openssl-users@openssl.org >> Automated List Manager majord...@openssl.org >> > > >