file/file_encrypt/crypto.h

/*
* EVALUATION AND USE OF THIS SOFTWARE IS SUBJECT TO THE TERMS AND
* CONDITIONS OF THE CONTROLLING LICENSE AGREEMENT FOUND AT LICENSE.md
* IN THIS SDK. IF YOU DO NOT AGREE TO THE LICENSE TERMS AND CONDITIONS,
* PLEASE RETURN ALL SOURCE FILES TO SILICON LABORATORIES.
* (c) Copyright 2018, Silicon Laboratories Inc. All rights reserved.
*/
#pragma once
#include "gos.h"
#define IV_SIZE (AES128_BLOCK_SIZE)
#define MAC_SIZE (AES128_BLOCK_SIZE)
typedef struct
{
mbedtls_aes_context aes;
} crypt_context_t;
gos_result_t encrypt_buffer_to_file(const uint8_t *key, uint8_t *buffer, uint32_t buffer_length, const char *encrypted_filename);
gos_result_t decrypt_file_to_buffer(const uint8_t *key, const char *filename, uint8_t *buffer, uint32_t buffer_length);
void calculate_mac(const uint8_t *key, const uint8_t *buffer, uint32_t buffer_length, uint8_t *mac);
void encrypt_block(crypt_context_t *context, uint8_t *ptr);
void encrypt_buffer(crypt_context_t *context, uint8_t *ptr, uint8_t size);
// NOTE: encrypt/decrypt in CTR mode is symmetric, so these function do the *exact* same thing
#define decrypt_block encrypt_block
#define decrypt_buffer encrypt_buffer