add? update
This commit is contained in:
12
client.cpp
12
client.cpp
@@ -46,13 +46,19 @@ int stream_encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *k
|
||||
|
||||
/* Initialise the encryption operation. */
|
||||
// choice for aes_256 ref: https://stackoverflow.com/questions/1220751/how-to-choose-an-aes-encryption-mode-cbc-ecb-ctr-ocb-cfb
|
||||
EVP_EncryptInit_ex(ctx, EVP_aes_256_ctr(), NULL, key, iv);
|
||||
if (EVP_EncryptInit_ex(ctx, EVP_aes_256_ctr(), NULL, key, iv) != 1){
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
/* Provide the message to be encrypted, and obtain the encrypted output. EVP_EncryptUpdate can be called multiple times if necessary */
|
||||
EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len);
|
||||
if (EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len) != 1) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
/* Finalize the encryption. Further cipher text bytes may be written at this stage. */
|
||||
EVP_EncryptFinal_ex(ctx, ciphertext + len, &ciphertext_len);
|
||||
if (EVP_EncryptFinal_ex(ctx, ciphertext + len, &ciphertext_len) != 1) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
|
||||
Reference in New Issue
Block a user