Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
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
/*---------------------------------------------------------------------------*/
48
static
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
*/
58
void
59
crypto_isr
(
void
)
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
/*---------------------------------------------------------------------------*/
70
static
bool
71
permit_pm1
(
void
)
72
{
73
return
REG(
AES_CTRL_ALG_SEL
) == 0;
74
}
75
/*---------------------------------------------------------------------------*/
76
void
77
crypto_init
(
void
)
78
{
79
volatile
int
i;
80
81
lpm_register_peripheral(permit_pm1);
82
83
crypto_enable
();
84
85
/* Reset the AES/SHA cryptoprocessor */
86
REG(
SYS_CTRL_SRSEC
) |=
SYS_CTRL_SRSEC_AES
;
87
for
(i = 0; i < 16; i++);
88
REG(
SYS_CTRL_SRSEC
) &=
~SYS_CTRL_SRSEC_AES
;
89
}
90
/*---------------------------------------------------------------------------*/
91
void
92
crypto_enable
(
void
)
93
{
94
/* Enable the clock for the AES/SHA cryptoprocessor */
95
REG(
SYS_CTRL_RCGCSEC
) |=
SYS_CTRL_RCGCSEC_AES
;
96
REG(
SYS_CTRL_SCGCSEC
) |=
SYS_CTRL_SCGCSEC_AES
;
97
REG(
SYS_CTRL_DCGCSEC
) |=
SYS_CTRL_DCGCSEC_AES
;
98
}
99
/*---------------------------------------------------------------------------*/
100
void
101
crypto_disable
(
void
)
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
/*---------------------------------------------------------------------------*/
109
void
110
crypto_register_process_notification
(
struct
process *p)
111
{
112
notification_process = p;
113
}
114
115
/** @} */
aes.h
Header file for the cc2538 AES driver.
crypto.h
Header file for the cc2538 AES/SHA cryptoprocessor driver.
AES_IRQn
@ AES_IRQn
AES Interrupt.
Definition
cc2538_cm3.h:111
AES_CTRL_ALG_SEL
#define AES_CTRL_ALG_SEL
Algorithm select.
Definition
aes.h:130
crypto_init
void crypto_init(void)
Enables and resets the AES/SHA cryptoprocessor.
Definition
crypto.c:77
crypto_enable
void crypto_enable(void)
Enables the AES/SHA cryptoprocessor.
Definition
crypto.c:92
crypto_register_process_notification
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
crypto_disable
void crypto_disable(void)
Disables the AES/SHA cryptoprocessor.
Definition
crypto.c:101
crypto_isr
void crypto_isr(void)
The AES/SHA cryptoprocessor ISR.
Definition
crypto.c:59
SYS_CTRL_SCGCSEC_AES
#define SYS_CTRL_SCGCSEC_AES
AES clock enable, CPU IDLE.
Definition
sys-ctrl.h:179
SYS_CTRL_SRSEC
#define SYS_CTRL_SRSEC
Sec Mod reset control.
Definition
sys-ctrl.h:86
SYS_CTRL_DCGCSEC_AES
#define SYS_CTRL_DCGCSEC_AES
AES clock enable, PM0.
Definition
sys-ctrl.h:186
SYS_CTRL_RCGCSEC_AES
#define SYS_CTRL_RCGCSEC_AES
AES clock enable, CPU running.
Definition
sys-ctrl.h:172
SYS_CTRL_RCGCSEC
#define SYS_CTRL_RCGCSEC
Sec Mod clocks - active mode.
Definition
sys-ctrl.h:83
SYS_CTRL_SCGCSEC
#define SYS_CTRL_SCGCSEC
Sec Mod clocks - sleep mode.
Definition
sys-ctrl.h:84
SYS_CTRL_DCGCSEC
#define SYS_CTRL_DCGCSEC
Sec Mod clocks - PM0.
Definition
sys-ctrl.h:85
SYS_CTRL_SRSEC_AES
#define SYS_CTRL_SRSEC_AES
AES is reset.
Definition
sys-ctrl.h:193
permit_pm1
static bool permit_pm1(void)
Definition
usb-arch.c:333
process_poll
void process_poll(struct process *p)
Request a process to be polled.
Definition
process.c:366
nvic.h
Header file for the ARM Nested Vectored Interrupt Controller.
reg.h
Header file with register manipulation macro definitions.
sys-ctrl.h
Header file for the cc2538 System Control driver.
arch
cpu
cc2538
dev
crypto.c
Generated on
for Contiki-NG by
1.17.0