Make BN_num_bits_word constant-time.
[openssl.git] / crypto / ppccpuid.pl
1 #!/usr/bin/env perl
2
3 $flavour = shift;
4
5 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
6 ( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
7 ( $xlate="${dir}perlasm/ppc-xlate.pl" and -f $xlate) or
8 die "can't locate ppc-xlate.pl";
9
10 open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
11
12 if ($flavour=~/64/) {
13     $CMPLI="cmpldi";
14     $SHRLI="srdi";
15     $SIGNX="extsw";
16 } else {
17     $CMPLI="cmplwi";
18     $SHRLI="srwi";
19     $SIGNX="mr";
20 }
21
22 $code=<<___;
23 .machine        "any"
24 .text
25
26 .globl  .OPENSSL_ppc64_probe
27 .align  4
28 .OPENSSL_ppc64_probe:
29         fcfid   f1,f1
30         extrdi  r0,r0,32,0
31         blr
32         .long   0
33         .byte   0,12,0x14,0,0,0,0,0
34 .size   .OPENSSL_ppc64_probe,.-.OPENSSL_ppc64_probe
35
36 .globl  .OPENSSL_altivec_probe
37 .align  4
38 .OPENSSL_altivec_probe:
39         .long   0x10000484      # vor   v0,v0,v0
40         blr
41         .long   0
42         .byte   0,12,0x14,0,0,0,0,0
43 .size   .OPENSSL_altivec_probe,.-..OPENSSL_altivec_probe
44
45 .globl  .OPENSSL_crypto207_probe
46 .align  4
47 .OPENSSL_crypto207_probe:
48         lvx_u   v0,0,r1
49         vcipher v0,v0,v0
50         blr
51         .long   0
52         .byte   0,12,0x14,0,0,0,0,0
53 .size   .OPENSSL_crypto207_probe,.-.OPENSSL_crypto207_probe
54
55 .globl  .OPENSSL_wipe_cpu
56 .align  4
57 .OPENSSL_wipe_cpu:
58         xor     r0,r0,r0
59         fmr     f0,f31
60         fmr     f1,f31
61         fmr     f2,f31
62         mr      r3,r1
63         fmr     f3,f31
64         xor     r4,r4,r4
65         fmr     f4,f31
66         xor     r5,r5,r5
67         fmr     f5,f31
68         xor     r6,r6,r6
69         fmr     f6,f31
70         xor     r7,r7,r7
71         fmr     f7,f31
72         xor     r8,r8,r8
73         fmr     f8,f31
74         xor     r9,r9,r9
75         fmr     f9,f31
76         xor     r10,r10,r10
77         fmr     f10,f31
78         xor     r11,r11,r11
79         fmr     f11,f31
80         xor     r12,r12,r12
81         fmr     f12,f31
82         fmr     f13,f31
83         blr
84         .long   0
85         .byte   0,12,0x14,0,0,0,0,0
86 .size   .OPENSSL_wipe_cpu,.-.OPENSSL_wipe_cpu
87
88 .globl  .OPENSSL_atomic_add
89 .align  4
90 .OPENSSL_atomic_add:
91 Ladd:   lwarx   r5,0,r3
92         add     r0,r4,r5
93         stwcx.  r0,0,r3
94         bne-    Ladd
95         $SIGNX  r3,r0
96         blr
97         .long   0
98         .byte   0,12,0x14,0,0,0,2,0
99         .long   0
100 .size   .OPENSSL_atomic_add,.-.OPENSSL_atomic_add
101
102 .globl  .OPENSSL_rdtsc
103 .align  4
104 .OPENSSL_rdtsc:
105         mftb    r3
106         mftbu   r4
107         blr
108         .long   0
109         .byte   0,12,0x14,0,0,0,0,0
110 .size   .OPENSSL_rdtsc,.-.OPENSSL_rdtsc
111
112 .globl  .OPENSSL_cleanse
113 .align  4
114 .OPENSSL_cleanse:
115         $CMPLI  r4,7
116         li      r0,0
117         bge     Lot
118         $CMPLI  r4,0
119         beqlr-
120 Little: mtctr   r4
121         stb     r0,0(r3)
122         addi    r3,r3,1
123         bdnz    \$-8
124         blr
125 Lot:    andi.   r5,r3,3
126         beq     Laligned
127         stb     r0,0(r3)
128         subi    r4,r4,1
129         addi    r3,r3,1
130         b       Lot
131 Laligned:
132         $SHRLI  r5,r4,2
133         mtctr   r5
134         stw     r0,0(r3)
135         addi    r3,r3,4
136         bdnz    \$-8
137         andi.   r4,r4,3
138         bne     Little
139         blr
140         .long   0
141         .byte   0,12,0x14,0,0,0,2,0
142         .long   0
143 .size   .OPENSSL_cleanse,.-.OPENSSL_cleanse
144 ___
145
146 $code =~ s/\`([^\`]*)\`/eval $1/gem;
147 print $code;
148 close STDOUT;