Contiki-NG
crypto.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013, ADVANSEE - http://www.advansee.com/
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * 3. Neither the name of the copyright holder nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31/**
32 * \addtogroup cc2538-crypto
33 * @{
34 *
35 * \file
36 * Implementation of the cc2538 AES/SHA cryptoprocessor driver
37 */
38#include "contiki.h"
39#include "dev/sys-ctrl.h"
40#include "dev/nvic.h"
41#include "dev/crypto.h"
42#include "dev/aes.h"
43#include "reg.h"
44#include "lpm.h"
45
46#include <stdbool.h>
47/*---------------------------------------------------------------------------*/
48static volatile struct process *notification_process = NULL;
49/*---------------------------------------------------------------------------*/
50/** \brief The AES/SHA cryptoprocessor ISR
51 *
52 * This is the interrupt service routine for the AES/SHA
53 * cryptoprocessor.
54 *
55 * This ISR is called at worst from PM0, so lpm_exit() does not need
56 * to be called.
57 */
58void
60{
61 NVIC_ClearPendingIRQ(AES_IRQn);
62 NVIC_DisableIRQ(AES_IRQn);
63
64 if(notification_process != NULL) {
65 process_poll((struct process *)notification_process);
66 notification_process = NULL;
67 }
68}
69/*---------------------------------------------------------------------------*/
70static bool
71permit_pm1(void)
72{
73 return REG(AES_CTRL_ALG_SEL) == 0;
74}
75/*---------------------------------------------------------------------------*/
76void
78{
79 volatile int i;
80
81 lpm_register_peripheral(permit_pm1);
82
84
85 /* Reset the AES/SHA cryptoprocessor */
87 for(i = 0; i < 16; i++);
88 REG(SYS_CTRL_SRSEC) &= ~SYS_CTRL_SRSEC_AES;
89}
90/*---------------------------------------------------------------------------*/
91void
93{
94 /* Enable the clock for the AES/SHA cryptoprocessor */
98}
99/*---------------------------------------------------------------------------*/
100void
102{
103 /* Gate the clock for the AES/SHA cryptoprocessor */
104 REG(SYS_CTRL_RCGCSEC) &= ~SYS_CTRL_RCGCSEC_AES;
105 REG(SYS_CTRL_SCGCSEC) &= ~SYS_CTRL_SCGCSEC_AES;
106 REG(SYS_CTRL_DCGCSEC) &= ~SYS_CTRL_DCGCSEC_AES;
107}
108/*---------------------------------------------------------------------------*/
109void
111{
112 notification_process = p;
113}
114
115/** @} */
Header file for the cc2538 AES driver.
Header file for the cc2538 AES/SHA cryptoprocessor driver.
@ AES_IRQn
AES Interrupt.
Definition: cc2538_cm3.h:111
#define AES_CTRL_ALG_SEL
Algorithm select.
Definition: aes.h:130
void crypto_init(void)
Enables and resets the AES/SHA cryptoprocessor.
Definition: crypto.c:77
void crypto_enable(void)
Enables the AES/SHA cryptoprocessor.
Definition: crypto.c:92
void crypto_register_process_notification(struct process *p)
Registers a process to be notified of the completion of a crypto operation.
Definition: crypto.c:110
void crypto_disable(void)
Disables the AES/SHA cryptoprocessor.
Definition: crypto.c:101
void crypto_isr(void)
The AES/SHA cryptoprocessor ISR.
Definition: crypto.c:59
#define SYS_CTRL_SCGCSEC_AES
AES clock enable, CPU IDLE.
Definition: sys-ctrl.h:179
#define SYS_CTRL_SRSEC
Sec Mod reset control.
Definition: sys-ctrl.h:86
#define SYS_CTRL_DCGCSEC_AES
AES clock enable, PM0.
Definition: sys-ctrl.h:186
#define SYS_CTRL_RCGCSEC_AES
AES clock enable, CPU running.
Definition: sys-ctrl.h:172
#define SYS_CTRL_RCGCSEC
Sec Mod clocks - active mode.
Definition: sys-ctrl.h:83
#define SYS_CTRL_SCGCSEC
Sec Mod clocks - sleep mode.
Definition: sys-ctrl.h:84
#define SYS_CTRL_DCGCSEC
Sec Mod clocks - PM0.
Definition: sys-ctrl.h:85
#define SYS_CTRL_SRSEC_AES
AES is reset.
Definition: sys-ctrl.h:193
void process_poll(struct process *p)
Request a process to be polled.
Definition: process.c:371
Header file for the ARM Nested Vectored Interrupt Controller.
Header file with register manipulation macro definitions.
Header file for the cc2538 System Control driver.