Skip to content

Commit

Permalink
fix: edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyTubongbanua committed Aug 12, 2023
1 parent 56396c1 commit 1b46d67
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/atchops/src/aes_ctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "atchops/aes_ctr.h"
#include "atchops/base64.h"

#define BUFFER_SIZE 65536

int atchops_aes_ctr_encrypt(
const char *keybase64,
const unsigned long keybase64len,
Expand Down Expand Up @@ -65,7 +67,7 @@ int atchops_aes_ctr_encrypt(
ret = mbedtls_aes_setkey_enc(&aes, key, keybits);
// printf("mbedtls_aes_setkey_enc: %d\n", ret);

unsigned long ciphertextlen = 5000;
unsigned long ciphertextlen = BUFFER_SIZE;
unsigned char *ciphertext = malloc(sizeof(unsigned char) * ciphertextlen);
unsigned long ciphertextolen = 0;

Expand Down Expand Up @@ -131,7 +133,7 @@ int atchops_aes_ctr_decrypt(
// printf("\n\n");

// 2. decode the ciphertextbase64 into ciphertext
unsigned long ciphertextlen = 5000;
unsigned long ciphertextlen = BUFFER_SIZE;
unsigned char *ciphertext = malloc(sizeof(unsigned char) * ciphertextlen);
memset(ciphertext, 0, ciphertextlen);
unsigned long ciphertextolen = 0;
Expand Down Expand Up @@ -162,7 +164,7 @@ int atchops_aes_ctr_decrypt(
unsigned char *stream_block = malloc(sizeof(unsigned char) * 16);
memset(stream_block, 0, 16);

unsigned long plaintextpaddedlen = 1000;
unsigned long plaintextpaddedlen = plaintextlen;
unsigned char *plaintextpadded = malloc(sizeof(unsigned char) * plaintextpaddedlen);
memset(plaintextpadded, 0, plaintextpaddedlen);
unsigned long plaintextpaddedolen = 0;
Expand Down
2 changes: 2 additions & 0 deletions packages/repl/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ int main()

const size_t pkamprivatekeylen = 10000;
unsigned char *pkamprivatekey = malloc(sizeof(unsigned char) * pkamprivatekeylen);
memset(pkamprivatekey, 0, pkamprivatekeylen);
size_t pkamprivatekeyolen = 0;

printf("self encryption key: \"%s\"\n", atkeysfile.self_encryption_key->key);
Expand Down Expand Up @@ -134,6 +135,7 @@ int main()
size_t pkamcommandlen = 32768;
unsigned char *pkamcommand = malloc(sizeof(unsigned char) * pkamcommandlen);
memset(pkamcommand, 0, pkamcommandlen);
memset(pkamcommand, 0, pkamcommandlen);

strcat(pkamcommand, "pkam:");
strncat(pkamcommand, signature, signaturelen);
Expand Down

0 comments on commit 1b46d67

Please sign in to comment.