1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62#include <crypto/algapi.h>
63
64#ifndef __HAVE_ARCH_CRYPTO_MEMNEQ
65
66
67static inline unsigned long
68__crypto_memneq_generic(const void *a, const void *b, size_t size)
69{
70 unsigned long neq = 0;
71
72#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
73 while (size >= sizeof(unsigned long)) {
74 neq |= *(unsigned long *)a ^ *(unsigned long *)b;
75 OPTIMIZER_HIDE_VAR(neq);
76 a += sizeof(unsigned long);
77 b += sizeof(unsigned long);
78 size -= sizeof(unsigned long);
79 }
80#endif
81 while (size > 0) {
82 neq |= *(unsigned char *)a ^ *(unsigned char *)b;
83 OPTIMIZER_HIDE_VAR(neq);
84 a += 1;
85 b += 1;
86 size -= 1;
87 }
88 return neq;
89}
90
91
92static inline unsigned long __crypto_memneq_16(const void *a, const void *b)
93{
94 unsigned long neq = 0;
95
96#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
97 if (sizeof(unsigned long) == 8) {
98 neq |= *(unsigned long *)(a) ^ *(unsigned long *)(b);
99 OPTIMIZER_HIDE_VAR(neq);
100 neq |= *(unsigned long *)(a+8) ^ *(unsigned long *)(b+8);
101 OPTIMIZER_HIDE_VAR(neq);
102 } else if (sizeof(unsigned int) == 4) {
103 neq |= *(unsigned int *)(a) ^ *(unsigned int *)(b);
104 OPTIMIZER_HIDE_VAR(neq);
105 neq |= *(unsigned int *)(a+4) ^ *(unsigned int *)(b+4);
106 OPTIMIZER_HIDE_VAR(neq);
107 neq |= *(unsigned int *)(a+8) ^ *(unsigned int *)(b+8);
108 OPTIMIZER_HIDE_VAR(neq);
109 neq |= *(unsigned int *)(a+12) ^ *(unsigned int *)(b+12);
110 OPTIMIZER_HIDE_VAR(neq);
111 } else
112#endif
113 {
114 neq |= *(unsigned char *)(a) ^ *(unsigned char *)(b);
115 OPTIMIZER_HIDE_VAR(neq);
116 neq |= *(unsigned char *)(a+1) ^ *(unsigned char *)(b+1);
117 OPTIMIZER_HIDE_VAR(neq);
118 neq |= *(unsigned char *)(a+2) ^ *(unsigned char *)(b+2);
119 OPTIMIZER_HIDE_VAR(neq);
120 neq |= *(unsigned char *)(a+3) ^ *(unsigned char *)(b+3);
121 OPTIMIZER_HIDE_VAR(neq);
122 neq |= *(unsigned char *)(a+4) ^ *(unsigned char *)(b+4);
123 OPTIMIZER_HIDE_VAR(neq);
124 neq |= *(unsigned char *)(a+5) ^ *(unsigned char *)(b+5);
125 OPTIMIZER_HIDE_VAR(neq);
126 neq |= *(unsigned char *)(a+6) ^ *(unsigned char *)(b+6);
127 OPTIMIZER_HIDE_VAR(neq);
128 neq |= *(unsigned char *)(a+7) ^ *(unsigned char *)(b+7);
129 OPTIMIZER_HIDE_VAR(neq);
130 neq |= *(unsigned char *)(a+8) ^ *(unsigned char *)(b+8);
131 OPTIMIZER_HIDE_VAR(neq);
132 neq |= *(unsigned char *)(a+9) ^ *(unsigned char *)(b+9);
133 OPTIMIZER_HIDE_VAR(neq);
134 neq |= *(unsigned char *)(a+10) ^ *(unsigned char *)(b+10);
135 OPTIMIZER_HIDE_VAR(neq);
136 neq |= *(unsigned char *)(a+11) ^ *(unsigned char *)(b+11);
137 OPTIMIZER_HIDE_VAR(neq);
138 neq |= *(unsigned char *)(a+12) ^ *(unsigned char *)(b+12);
139 OPTIMIZER_HIDE_VAR(neq);
140 neq |= *(unsigned char *)(a+13) ^ *(unsigned char *)(b+13);
141 OPTIMIZER_HIDE_VAR(neq);
142 neq |= *(unsigned char *)(a+14) ^ *(unsigned char *)(b+14);
143 OPTIMIZER_HIDE_VAR(neq);
144 neq |= *(unsigned char *)(a+15) ^ *(unsigned char *)(b+15);
145 OPTIMIZER_HIDE_VAR(neq);
146 }
147
148 return neq;
149}
150
151
152
153
154
155
156noinline unsigned long __crypto_memneq(const void *a, const void *b,
157 size_t size)
158{
159 switch (size) {
160 case 16:
161 return __crypto_memneq_16(a, b);
162 default:
163 return __crypto_memneq_generic(a, b, size);
164 }
165}
166EXPORT_SYMBOL(__crypto_memneq);
167
168#endif
169