2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 #error Must define HAS_AES 1
25 __xdata uint8_t ao_aes_mutex;
26 __xdata uint8_t ao_aes_done;
27 __xdata uint8_t ao_aes_dma_in, ao_aes_dma_out;
28 __xdata uint8_t ao_aes_dma_in_done, ao_aes_dma_out_done;
29 __pdata enum ao_aes_mode ao_aes_current_mode;
32 ao_aes_isr(void) __interrupt 4
35 if (ENCCCS & ENCCCS_RDY) {
37 ao_wakeup(&ao_aes_done);
42 ao_aes_set_mode(enum ao_aes_mode mode)
44 ao_aes_current_mode = mode;
48 ao_aes_set_key(__xdata uint8_t *in)
50 ao_dma_set_transfer(ao_aes_dma_in,
55 DMA_CFG0_TMODE_SINGLE |
56 DMA_CFG0_TRIGGER_ENC_DW,
59 DMA_CFG1_PRIORITY_LOW);
60 ao_dma_start(ao_aes_dma_in);
62 ENCCCS = ENCCCS_MODE_CBC_MAC |
64 ENCCCS |= ENCCCS_START;
65 __critical while (!ao_aes_done)
66 ao_sleep(&ao_aes_done);
74 ENCCCS = ENCCCS_MODE_CBC_MAC | ENCCCS_CMD_LOAD_IV | ENCCCS_START;
75 for (b = 0; b < AO_AES_LEN; b++)
80 ao_aes_run(__xdata uint8_t *in,
85 ao_dma_set_transfer(ao_aes_dma_in,
90 DMA_CFG0_TMODE_SINGLE |
91 DMA_CFG0_TRIGGER_ENC_DW,
94 DMA_CFG1_PRIORITY_LOW);
97 ao_dma_set_transfer(ao_aes_dma_out,
101 DMA_CFG0_WORDSIZE_8 |
102 DMA_CFG0_TMODE_SINGLE |
103 DMA_CFG0_TRIGGER_ENC_UP,
106 DMA_CFG1_PRIORITY_LOW);
108 switch (ao_aes_current_mode) {
109 case ao_aes_mode_cbc_mac:
111 b = (ENCCCS_MODE_CBC |
114 b = (ENCCCS_MODE_CBC_MAC |
122 ao_dma_start(ao_aes_dma_in);
124 ao_dma_start(ao_aes_dma_out);
126 ENCCCS |= ENCCCS_START;
128 __critical while (!ao_aes_dma_out_done)
129 ao_sleep(&ao_aes_dma_out_done);
131 __critical while (!ao_aes_done)
132 ao_sleep(&ao_aes_done);
139 #if DMA_SHARE_AES_RADIO
140 ao_aes_dma_in = ao_radio_dma;
142 ao_aes_dma_in = ao_dma_alloc(&ao_aes_dma_in_done);
144 ao_aes_dma_out = ao_dma_alloc(&ao_aes_dma_out_done);