]> git.cryptolib.org Git - arm-crypto-lib.git/blob - bmw/gen_f0_arm.rb
forgotten bmw stuff
[arm-crypto-lib.git] / bmw / gen_f0_arm.rb
1 # gen_f0_arm.rb 
2 =begin
3     This file is part of the ARM-Crypto-Lib.
4     Copyright (C) 2006-2010  Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 =end
19 =begin
20 #define S32_1(x) ( (SHR32((x),   1)) ^ \
21                  (SHL32((x),   2)) ^ \
22                  (ROTL32((x),  8)) ^ \
23                  (ROTR32((x),  9)) )
24
25 #define S32_2(x) ( (SHR32((x),   2)) ^ \
26                  (SHL32((x),   1)) ^ \
27                  (ROTL32((x), 12)) ^ \
28                  (ROTR32((x),  7)) )
29
30 #define S32_3(x) ( (SHR32((x),   2)) ^ \
31                  (SHL32((x),   2)) ^ \
32                  (ROTL32((x), 15)) ^ \
33                  (ROTR32((x),  3)) )
34
35 #define S32_4(x) ( (SHR32((x),   1)) ^ (x))
36
37 #define S32_5(x) ( (SHR32((x),   2)) ^ (x))
38
39 =end
40 $s32_0_lut = [ 1,  3,  4, 13]
41 $s32_1_lut = [ 1,  2,  8,  9]
42 $s32_2_lut = [ 2,  1, 12,  7]
43 $s32_3_lut = [ 2,  2, 15,  3]
44
45 $s32_lut = [$s32_0_lut, $s32_1_lut, $s32_2_lut, $s32_3_lut]
46
47 def s32_0(fout, select, reg0, reg1)
48   if select<=3
49     fout.puts("\tmov %s, %s", reg1, reg0)
50     fout.puts("\tlsrs %s, %s, #%d", reg0, reg0, $s32_lut[select][0])
51     fout.puts("\teor %s, %s, %s, lsl #%d", reg0, reg0, reg1, $s32_lut[select][1])
52     fout.puts("\teor %s, %s, %s, ror #%d", reg0, reg0, reg1, 32-$s32_lut[select][2])
53     fout.puts("\teor %s, %s, %s, ror #%d", reg0, reg0, reg1, $s32_lut[select][3])
54   else
55     fout.puts("\teor %s, %s, %s, ror #%d", reg0, reg0, reg0, 1) if select==4
56     fout.puts("\teor %s, %s, %s, ror #%d", reg0, reg0, reg0, 2) if select==5
57   end
58 end
59