add? update

This commit is contained in:
Zheyuan Wu
2026-02-11 17:31:34 -06:00
parent a03f90a4ba
commit 6cc8ce61b3
5 changed files with 22 additions and 6 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -46,13 +46,19 @@ int stream_encrypt(unsigned char *plaintext, int plaintext_len, unsigned char *k
/* Initialise the encryption operation. */ /* 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 // 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 */ /* 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. */ /* 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 */ /* Clean up */
EVP_CIPHER_CTX_free(ctx); EVP_CIPHER_CTX_free(ctx);

View File

@@ -19,6 +19,10 @@ file bin/server bin/client || true
chmod a+x bin/server bin/client chmod a+x bin/server bin/client
# clean up existing containers and networks
docker compose down
# start the containers
docker compose up -d server docker compose up -d server
docker compose run --rm -it client docker compose run --rm -it client

View File

@@ -45,13 +45,19 @@ int stream_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char
ctx = EVP_CIPHER_CTX_new(); ctx = EVP_CIPHER_CTX_new();
/* Initialise the decryption operation. */ /* Initialise the decryption operation. */
EVP_DecryptInit_ex(ctx, EVP_aes_256_ctr(), NULL, key, iv); if (EVP_DecryptInit_ex(ctx, EVP_aes_256_ctr(), NULL, key, iv) != 1){
ERR_print_errors_fp(stderr);
}
/* Provide the message to be decrypted, and obtain the plaintext output. EVP_DecryptUpdate can be called multiple times if necessary */ /* Provide the message to be decrypted, and obtain the plaintext output. EVP_DecryptUpdate can be called multiple times if necessary */
EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len); if (EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len) != 1) {
ERR_print_errors_fp(stderr);
}
/* Finalize the decryption. Further plaintext bytes may be written at this stage. */ /* Finalize the decryption. Further plaintext bytes may be written at this stage. */
EVP_DecryptFinal_ex(ctx, plaintext + len, &plaintext_len); if (EVP_DecryptFinal_ex(ctx, plaintext + len, &plaintext_len) != 1) {
ERR_print_errors_fp(stderr);
}
/* Clean up */ /* Clean up */
EVP_CIPHER_CTX_free(ctx); EVP_CIPHER_CTX_free(ctx);