1 /**
2 *
3 * \file
4 *
5 * \brief SAM Advanced Encryption Standard driver.
6 *
7 * This file defines a useful set of functions for the AES on SAM devices.
8 *
9 * Copyright (c) 2014-2016 Atmel Corporation. All rights reserved.
10 *
11 * \asf_license_start
12 *
13 * \page License
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions are met:
17 *
18 * 1. Redistributions of source code must retain the above copyright notice,
19 * this list of conditions and the following disclaimer.
20 *
21 * 2. Redistributions in binary form must reproduce the above copyright notice,
22 * this list of conditions and the following disclaimer in the documentation
23 * and/or other materials provided with the distribution.
24 *
25 * 3. The name of Atmel may not be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * 4. This software may only be redistributed and used in connection with an
29 * Atmel microcontroller product.
30 *
31 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
32 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
34 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
35 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
40 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGE.
42 *
43 * \asf_license_stop
44 *
45 */
46 /*
47 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
48 */
49
50 #include "aes.h"
51 #include "aes_callback.h"
52
53 /** \internal Max number of callback type. */
54 #define AES_CALLBACK_TYPE_NUM 2
55
56 /**
57 * \internal
58 * \brief AES callback function pointer
59 */
60 aes_callback_t aes_callback_pointer[AES_CALLBACK_TYPE_NUM]={NULL,NULL};
61
62
aes_register_callback(const aes_callback_t callback,const enum aes_callback_type type)63 enum status_code aes_register_callback(
64 const aes_callback_t callback,
65 const enum aes_callback_type type)
66 {
67 if (type >= AES_CALLBACK_TYPE_NUM){
68 Assert(false);
69 return STATUS_ERR_INVALID_ARG;
70 }
71
72 aes_callback_pointer[type] = callback;
73 return STATUS_OK;
74 }
75
aes_unregister_callback(const aes_callback_t callback,const enum aes_callback_type type)76 enum status_code aes_unregister_callback(
77 const aes_callback_t callback,
78 const enum aes_callback_type type)
79 {
80 if (type >= AES_CALLBACK_TYPE_NUM){
81 Assert(false);
82 return STATUS_ERR_INVALID_ARG;
83 }
84
85 aes_callback_pointer[type] = NULL;
86 return STATUS_OK;
87 }
88
89
90
91 /**
92 * \internal The AES interrupt handler.
93 */
AES_Handler(void)94 void AES_Handler(void)
95 {
96 uint32_t status = AES->INTFLAG.reg;
97
98 if (status & AES_INTFLAG_ENCCMP) {
99 if (aes_callback_pointer[AES_CALLBACK_ENCRYPTION_COMPLETE]) {
100 AES->INTFLAG.reg = AES_INTFLAG_ENCCMP;
101 aes_callback_pointer[AES_CALLBACK_ENCRYPTION_COMPLETE]();
102 }
103 }
104
105 if (status & AES_INTFLAG_GFMCMP) {
106 if (aes_callback_pointer[AES_CALLBACK_ENCRYPTION_COMPLETE]) {
107 AES->INTFLAG.reg = AES_INTFLAG_GFMCMP;
108 aes_callback_pointer[AES_CALLBACK_ENCRYPTION_COMPLETE]();
109 }
110 }
111 }
112