Initialize Tizen 2.3
[external/nettle.git] / x86 / aes.m4
1 dnl AES_LOAD(a, b, c, d, src, key)
2 dnl Loads the next block of data from src, and add the subkey pointed
3 dnl to by key.
4 dnl Note that x86 allows unaligned accesses.
5 dnl Would it be preferable to interleave the loads and stores?
6 define(<AES_LOAD>, <
7         movl    ($5),$1
8         movl    4($5),$2
9         movl    8($5),$3
10         movl    12($5),$4
11         
12         xorl    ($6),$1
13         xorl    4($6),$2
14         xorl    8($6),$3
15         xorl    12($6),$4>)dnl
16
17 dnl AES_STORE(a, b, c, d, key, dst)
18 dnl Adds the subkey to a, b, c, d,
19 dnl and stores the result in the area pointed to by dst.
20 dnl Note that x86 allows unaligned accesses.
21 dnl Would it be preferable to interleave the loads and stores?
22 define(<AES_STORE>, <
23         xorl    ($5),$1
24         xorl    4($5),$2
25         xorl    8($5),$3
26         xorl    12($5),$4
27
28         movl    $1,($6)
29         movl    $2,4($6)
30         movl    $3,8($6)
31         movl    $4,12($6)>)dnl
32
33 dnl AES_ROUND(table,a,b,c,d,out,ptr)
34 dnl Computes one word of the AES round. Leaves result in $6.
35 define(<AES_ROUND>, <
36         movzbl  LREG($2), $7
37         movl    AES_TABLE0 ($1, $7, 4),$6
38         movzbl  HREG($3), $7
39         xorl    AES_TABLE1 ($1, $7, 4),$6
40         movl    $4,$7
41         shrl    <$>16,$7
42         andl    <$>0xff,$7
43         xorl    AES_TABLE2 ($1, $7, 4),$6
44         movl    $5,$7
45         shrl    <$>24,$7
46         xorl    AES_TABLE3 ($1, $7, 4),$6>)dnl
47
48 dnl AES_FINAL_ROUND(a, b, c, d, table, out, tmp)
49 dnl Computes one word of the final round.
50 dnl Note that we have to quote $ in constants.
51 define(<AES_FINAL_ROUND>, <
52         movzbl  LREG($1),$6
53         movzbl  ($5, $6), $6
54         movl    $2,$7
55         andl    <$>0x0000ff00,$7
56         orl     $7, $6
57         movl    $3,$7
58         andl    <$>0x00ff0000,$7
59         orl     $7, $6
60         movl    $4,$7
61         andl    <$>0xff000000,$7
62         orl     $7, $6
63         roll    <$>8, $6>)dnl
64
65 dnl AES_SUBST_BYTE(A, B, C, D, table, ptr)
66 dnl Substitutes the least significant byte of
67 dnl each of eax, ebx, ecx and edx, and also rotates
68 dnl the words one byte to the left.
69 dnl Uses that AES_SBOX == 0
70 define(<AES_SUBST_BYTE>, <
71         movzbl  LREG($1),$6
72         movb    ($5, $6),LREG($1)
73         roll    <$>8,$1
74
75         movzbl  LREG($2),$6
76         movb    ($5, $6),LREG($2)
77         roll    <$>8,$2
78
79         movzbl  LREG($3),$6
80         movb    ($5, $6),LREG($3)
81         roll    <$>8,$3
82
83         movzbl  LREG($4),$6
84         movb    ($5, $6),LREG($4)
85         roll    <$>8,$4>)dnl