//------------------------------------------------------------------------------
// File:          encryption.h
// Function:      Firmware encryption
// Supported chip(s):
//    - AT91SAM7XC128
//    - AT91SAM7XC256
// Supported toolchain(s):
//    - IAR Embedded Workbench
// Date created:  06 June 2006
// Created by:    JJo
//------------------------------------------------------------------------------
// Notes:
//
// This file must include the header of every encryption module implemented for
// the bootloader. It is also responsible for defining mock functions if no
// encryption module is selected, as well as checking that parameters are
// correctly set.
//
// An encryption module must define the following functions:
//  -> void encryption_init(void);
//  -> void encryption_cleanup(void);
//  -> int encryption_decrypt(const unsigned char *, unsigned char *, unsigned int)
//------------------------------------------------------------------------------

#ifndef BOOTLOADER_ENCRYPTION_H
#define BOOTLOADER_ENCRYPTION_H

//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------

#include "security/encryption/libtomcrypt.h"
#include "security/encryption/aes_reference.h"
#include "security/encryption/aes_hardware.h"
#include "security/encryption/des_hardware.h"

//------------------------------------------------------------------------------
// Check configuration
//------------------------------------------------------------------------------

#if !defined(encryption_init) && !defined(USE_ENCRYPTION)
  #define encryption_init();
  #define encryption_cleanup();
  #define encryption_decrypt(...) 0

#elif !defined(encryption_init) && defined(USE_ENCRYPTION)
  #error USE_ENCRYPTION defined but no encryption method selected.

#elif !defined(ENCRYPTION_AES_LTC) && \
      !defined(ENCRYPTION_AES_REF) && \
      !defined(ENCRYPTION_AES_HARD) && \
      !defined(ENCRYPTION_3DES_LTC) && \
      !defined(ENCRYPTION_3DES_HARD)
  #error No algorithm selected.

#elif !defined(ENCRYPTION_ECB) && \
      !defined(ENCRYPTION_CBC) && \
      !defined(ENCRYPTION_CTR)
  #error No encryption mode selected.

#elif !defined(ENCRYPTION_KEY)
  #error No key defined.

#elif !defined(ENCRYPTION_KEY_LENGTH)
  #error No key length selected.

#elif !defined(ENCRYPTION_IV)
  #error No initialization vector defined.

#elif !defined(ENCRYPTION_BLOCK_LENGTH)
  #error No block length selected.

#endif

#endif // BOOTLOADER_ENCRYPTION_H
