| 723 |
theseven |
1 |
//
|
|
|
2 |
//
|
|
|
3 |
// Copyright 2010 TheSeven
|
|
|
4 |
//
|
|
|
5 |
//
|
|
|
6 |
// This file is part of emCORE.
|
|
|
7 |
//
|
|
|
8 |
// emCORE is free software: you can redistribute it and/or
|
|
|
9 |
// modify it under the terms of the GNU General Public License as
|
|
|
10 |
// published by the Free Software Foundation, either version 2 of the
|
|
|
11 |
// License, or (at your option) any later version.
|
|
|
12 |
//
|
|
|
13 |
// emCORE is distributed in the hope that it will be useful,
|
|
|
14 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
16 |
// See the GNU General Public License for more details.
|
|
|
17 |
//
|
|
|
18 |
// You should have received a copy of the GNU General Public License along
|
|
|
19 |
// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
//
|
|
|
21 |
//
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
#include "global.h"
|
|
|
25 |
#include "hwkeyaes.h"
|
|
|
26 |
#include "s5l8720.h"
|
|
|
27 |
#include "thread.h"
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
struct mutex hwkeyaes_mutex;
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
void hwkeyaes(enum hwkeyaes_direction direction, uint32_t keyidx, void* data, uint32_t size)
|
|
|
34 |
{
|
|
|
35 |
int i;
|
|
|
36 |
mutex_lock(&hwkeyaes_mutex, TIMEOUT_BLOCK);
|
|
|
37 |
clockgate_enable(7, true);
|
|
|
38 |
for (i = 0; i < 4; i++) AESIV[i] = 0;
|
|
|
39 |
AESUNKREG0 = 1;
|
|
|
40 |
AESUNKREG0 = 0;
|
|
|
41 |
AESCONTROL = 1;
|
|
|
42 |
AESUNKREG1 = 0;
|
|
|
43 |
AESTYPE = keyidx;
|
|
|
44 |
AESTYPE2 = ~AESTYPE;
|
|
|
45 |
AESUNKREG2 = 0;
|
|
|
46 |
AESKEYLEN = direction == HWKEYAES_ENCRYPT ? 0xf : 0xe;
|
|
|
47 |
AESOUTSIZE = size;
|
|
|
48 |
AESOUTADDR = data;
|
|
|
49 |
AESINSIZE = size;
|
|
|
50 |
AESINADDR = data;
|
|
|
51 |
AESAUXSIZE = size;
|
|
|
52 |
AESAUXADDR = data;
|
|
|
53 |
AESSIZE3 = size;
|
|
|
54 |
invalidate_dcache();
|
|
|
55 |
AESGO = 1;
|
|
|
56 |
while (!(AESSTATUS & 0xf)) sleep(MIN(10000, size >> 4));
|
|
|
57 |
clockgate_enable(7, false);
|
|
|
58 |
mutex_unlock(&hwkeyaes_mutex);
|
|
|
59 |
}
|