Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
273 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
6
//    This file is part of emBIOS.
7
//
8
//    emBIOS 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
//    emBIOS 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 emBIOS.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "hwkeyaes.h"
26
#include "s5l8702.h"
27
#include "thread.h"
28
 
29
 
387 theseven 30
struct mutex hwkeyaes_mutex;
31
 
32
 
273 theseven 33
void hwkeyaes(enum hwkeyaes_direction direction, uint32_t keyidx, void* data, uint32_t size)
34
{
35
    int i;
387 theseven 36
    mutex_lock(&hwkeyaes_mutex, TIMEOUT_BLOCK);
275 theseven 37
    clockgate_enable(10, true);
273 theseven 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 ? 9 : 8;
47
    AESOUTSIZE = size;
48
    AESOUTADDR = data;
49
    AESINSIZE = size;
50
    AESINADDR = data;
51
    AESAUXSIZE = size;
52
    AESAUXADDR = data;
53
    AESSIZE3 = size;
54
	clean_dcache();
55
    AESGO = 1;
56
	invalidate_dcache();
57
    while (!(AESSTATUS & 0xf)) sleep(100);
275 theseven 58
    clockgate_enable(10, false);
387 theseven 59
    mutex_unlock(&hwkeyaes_mutex);
273 theseven 60
}