I am trying to encrypt/decrypt file using source code directly. The issue is how to properly do it after reading the file.
int crypto_aead_encrypt(
unsigned char *c, unsigned long long *clen,
const unsigned char *m, unsigned long long mlen,
const unsigned char *ad, unsigned long long adlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k
)
Working code: (plaintext is char *)
for (start = 0; start < fileLength; start += 32)
{
int end = (start + 32);
end = end > fileLength ? fileLength : end;
strncpy(msg, plaintext + start, end - start);
// encrypt
crypto_aead_encrypt(ct, &clen, msg, mlen, ad, adlen, NULL, nonce, key);
// decryption
crypto_aead_decrypt(msg2, &mlen2, NULL, ct, clen, ad, adlen, nonce, key);
}
This is the function, and the max limit of the message m is 32 bits, which would make encrypting/decrypt very long for large files (ex. 1GB). Is there a way to perform the encrypting as fast as if it were from the library. Neglecting the code above, ex. how does OpenSSL do it when -in is provided?
The way I have it is to read the file, save it to an char * and then take 32 bits and enc each one. So I am wondering if there is a proper more correct way to do it.
Edit: reference implementation like ascon or photon-beetle