123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #include "Openssl_crypto.h"
- class SymmetricEncryptionBox {
- uint8_t iv[12];
- uint8_t symmetric_key[32]; // SHA256 used with ECDHE -> or AES whatever symmetric_key.
- // increments last 4 bytes (in big-endian order)
- uint32_t aes_gcm_increment_iv_internal_call(uint8_t* iv) {
- uint32_t counter;
- for(counter=11;counter>7;counter--)
- {
- if(iv[counter] == 0xff)
- {
- if(counter - 1 == 7)
- return 0xff;
- iv[counter-1] = 0x01;
- iv[counter] = 0x0;
- }
- else
- iv[counter] += 1;
- }
- return 0;
- }
- public:
- SymmetricEncryptionBox();
- uint32_t set_symmetric_key(uint8_t* given_key);
- uint32_t encrypt_decrypt(int enc, uint8_t* plaintext, uint32_t plaintext_length, uint8_t* ciphertext, uint32_t* ciphertext_length, uint8_t* tag);
- uint32_t set_symmetric_key(uint8_t* given_key)
- {
- uint32_t counter;
- for(counter=0; counter<32; counter++)
- symmetric_key[counter] = given_key[counter];
- }
- // TODO: IMPORTANT - CHECK IF WE NEED TO DO THIS FOR DECRYPTION TOO.
- uint32_t encrypt_decrypt(int enc, uint8_t* plaintext, uint32_t plaintext_length, uint8_t* ciphertext, uint32_t* ciphertext_length, uint8_t* tag)
- {
- uint32_t return_status = aes_gcm(enc, symmetric_key, iv, plaintext, plaintext_length, ciphertext, ciphertext_length, tag);
- if(return_status == 0)
- aes_gcm_increment_iv_internal_call(iv);
- }
- }
|