00001
00059 #ifndef AES_DRIVER_H
00060 #define AES_DRIVER_H
00061
00062 #include "avr_compiler.h"
00063
00064
00065 #define AES_BLOCK_LENGTH 16
00066
00067
00068 typedef struct AES_interrupt_driver
00069 {
00071 uint8_t * input_ptr;
00073 uint8_t * key_ptr;
00075 uint8_t * init_ptr;
00077 uint8_t * output_ptr;
00079 uint8_t block_count;
00081 uint8_t blocks_left;
00083 bool decrypt;
00084 } AES_interrupt_driver_t;
00085
00086
00087
00088
00090 #define AES_encryption_mode_set() ( AES.CTRL = AES.CTRL & (~AES_DECRYPT_bm) )
00091
00093 #define AES_decryption_mode_set() ( AES.CTRL |= AES_DECRYPT_bm )
00094
00096 #define AES_auto_enable() ( AES.CTRL |= AES_AUTO_bm )
00097
00099 #define AES_auto_disable() ( AES.CTRL = AES.CTRL & (~AES_AUTO_bm) )
00100
00102 #define AES_xor_enable() ( AES.CTRL |= AES_XOR_bm )
00103
00105 #define AES_xor_disable() ( AES.CTRL = AES.CTRL & (~AES_XOR_bm) )
00106
00108 #define AES_software_reset() ( AES.CTRL = AES_RESET_bm )
00109
00111 #define AES_start() ( AES.CTRL |= AES_START_bm )
00112
00118 #define AES_state_ready_flag_check() ((AES.STATUS & AES_SRIF_bm) != 0)
00119
00125 #define AES_error_flag_check() ((AES.STATUS & AES_ERROR_bm) != 0)
00126
00127
00128
00129
00130 void AES_interrupt_driver_init(AES_interrupt_driver_t * interrupt_driver,
00131 uint8_t * input_ptr, uint8_t * output_ptr,
00132 uint8_t * AES_key, uint8_t * AES_init,
00133 uint8_t block_count, bool decrypt);
00134 bool AES_interrupt_driver_start(AES_interrupt_driver_t * interrupt_driver,
00135 AES_INTLVL_t int_lvl);
00136 void AES_interrupt_handler(AES_interrupt_driver_t * interrupt_driver);
00137 bool AES_interrupt_driver_finished(AES_interrupt_driver_t * interrupt_driver);
00138 void AES_interruptlevel_set(AES_INTLVL_t int_lvl);
00139
00140
00141 bool AES_encrypt(uint8_t * plaintext, uint8_t * ciphertext, uint8_t * key);
00142 bool AES_decrypt(uint8_t * ciphertext, uint8_t * plaintext, uint8_t * key);
00143 bool AES_encrypt_backtoback(uint8_t * plaintext, uint8_t * ciphertext);
00144 bool AES_decrypt_backtoback(uint8_t * ciphertext, uint8_t * plaintext);
00145 bool AES_lastsubkey_generate(uint8_t * key, uint8_t * decrypt_key);
00146 bool AES_CBC_encrypt(uint8_t * plaintext, uint8_t * ciphertext, uint8_t * keys,
00147 uint8_t * init, uint16_t block_count);
00148 bool AES_CBC_decrypt(uint8_t * ciphertext, uint8_t * plaintext, uint8_t * keys,
00149 uint8_t * init, uint16_t block_count);
00150
00151 #endif