encrypt:
while(!feof(fp)){
memset(plain_text, 0, sizeof(plain_text));
retval = fread(plain_text, 1, 16, fp);
if(!retval) break;
for(i=0; i<16; i++){
if(plain_text[i] == 0){
for(j=i; j<16; j++){
plain_text[j] = 0x0i;
}
break;
}
}
gcry_cipher_encrypt(hd, encBuffer, txtLenght, plain_text, txtLenght);
fwrite(encBuffer, 1, 16, fpout);
}
decrypt:
while(!feof(fp)){
memset(plain_text, 0, sizeof(plain_text));
retval = fread(plain_text, 1, 16, fp);
if(!retval) break;
gcry_cipher_decrypt(hd, encBuffer, txtLenght, plain_text, txtLenght);
for(i=0; i<16; i++){
if(encBuffer[i] == 0x0i){
j = 0;
j += i;
if(encBuffer[++i] == 0x0j){
last = 1;
i--;
j=i;
printf("found a %d\n", i);
break;
}
else i--;
}
}
//printf("%d\n", j);
if(last == 1) fwrite(encBuffer, 1, j, fpout);
else fwrite(encBuffer, 1, 16, fpout);
}
i'm trying to add the removable padding from the pkcs#7 standard but i have a problem.
If i work with txt files my program work perfectly but if i try to decrypt some tar.gz or pdf file the decrypt program stop at half of file size!
For example let's take a tar.gz archive which size is 28272 bytes (prova is the original file, out is the encrypted file and origdec is the decrypted file):
28272 prova
28272 out
12147 origdec
i'm using libgcrypt on gnu/linux!