2016-04-03 3 views
0

Ich habe diesen CodeC++ EVP_EncriptUpdate Rewriting Stack?

..... 

const EVP_CIPHER * cipher = EVP_des_ecb(); 
uint8_t ot_byte,st_byte; 
EVP_CIPHER_CTX ctx; 
int trash; 
EVP_EncryptInit(&ctx,cipher, key, iv); 
cout << size - offset << endl; 
int i=0; 
for (; i < size - offset ;i++){ 
    check = read(input_fd,&ot_byte,1); 
    cout << (i < size - offset) << " " << i << endl; 
     EVP_EncryptUpdate(&ctx, &st_byte, &trash, &ot_byte, 1); 
     check = write(output_fd,&st_byte,1); 
} 
cout << (i < size - offset) << " " << i << endl; 
close(output_fd); 
close(output_fd); 

die Ausgabe

702000 
1 0 
1 1 
1 2 
1 3 
1 4 
1 5 
1 6 
1 7 
0 5019693 

Als ich "Kommentar off" der EVP-Funktion aktualisieren, geht die Schleife durch alle 702.000 Iterationen. Wo ist der Fehler? Gibt es eine Möglichkeit, dass die EVP irgendwie hinter ihren Puffer tritt und die Stack-Daten korrumpiert?

Antwort

1

Uint8_t Typ wird klein sein, diese Funktionen geben mindestens 8 Bytes zurück