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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 #error Must define HAS_AES 1
24 __xdata uint8_t ao_aes_mutex;
25 __xdata uint8_t ao_aes_done;
26 __xdata uint8_t ao_aes_dma_in, ao_aes_dma_out;
27 __xdata uint8_t ao_aes_dma_in_done, ao_aes_dma_out_done;
28 __pdata enum ao_aes_mode ao_aes_current_mode;
31 ao_aes_isr(void) __interrupt 4
34 if (ENCCCS & ENCCCS_RDY) {
36 ao_wakeup(&ao_aes_done);
41 ao_aes_set_mode(enum ao_aes_mode mode)
43 ao_aes_current_mode = mode;
47 ao_aes_set_key(__xdata uint8_t *in)
49 ao_dma_set_transfer(ao_aes_dma_in,
54 DMA_CFG0_TMODE_SINGLE |
55 DMA_CFG0_TRIGGER_ENC_DW,
58 DMA_CFG1_PRIORITY_LOW);
59 ao_dma_start(ao_aes_dma_in);
61 ENCCCS = ENCCCS_MODE_CBC_MAC |
63 ENCCCS |= ENCCCS_START;
64 __critical while (!ao_aes_done)
65 ao_sleep(&ao_aes_done);
73 ENCCCS = ENCCCS_MODE_CBC_MAC | ENCCCS_CMD_LOAD_IV | ENCCCS_START;
74 for (b = 0; b < AO_AES_LEN; b++)
79 ao_aes_run(__xdata uint8_t *in,
84 ao_dma_set_transfer(ao_aes_dma_in,
89 DMA_CFG0_TMODE_SINGLE |
90 DMA_CFG0_TRIGGER_ENC_DW,
93 DMA_CFG1_PRIORITY_LOW);
96 ao_dma_set_transfer(ao_aes_dma_out,
100 DMA_CFG0_WORDSIZE_8 |
101 DMA_CFG0_TMODE_SINGLE |
102 DMA_CFG0_TRIGGER_ENC_UP,
105 DMA_CFG1_PRIORITY_LOW);
107 switch (ao_aes_current_mode) {
108 case ao_aes_mode_cbc_mac:
110 b = (ENCCCS_MODE_CBC |
113 b = (ENCCCS_MODE_CBC_MAC |
121 ao_dma_start(ao_aes_dma_in);
123 ao_dma_start(ao_aes_dma_out);
125 ENCCCS |= ENCCCS_START;
127 __critical while (!ao_aes_dma_out_done)
128 ao_sleep(&ao_aes_dma_out_done);
130 __critical while (!ao_aes_done)
131 ao_sleep(&ao_aes_done);
138 ao_aes_dma_in = ao_dma_alloc(&ao_aes_dma_in_done);
139 ao_aes_dma_out = ao_dma_alloc(&ao_aes_dma_out_done);