@@ -179,9 +179,9 @@ static unsigned long hash_key_type_and_desc(const struct keyring_index_key *inde
179
179
int n , desc_len = index_key -> desc_len ;
180
180
181
181
type = (unsigned long )index_key -> type ;
182
-
183
182
acc = mult_64x32_and_fold (type , desc_len + 13 );
184
183
acc = mult_64x32_and_fold (acc , 9207 );
184
+
185
185
for (;;) {
186
186
n = desc_len ;
187
187
if (n <= 0 )
@@ -215,57 +215,37 @@ static unsigned long hash_key_type_and_desc(const struct keyring_index_key *inde
215
215
/*
216
216
* Build the next index key chunk.
217
217
*
218
- * On 32-bit systems the index key is laid out as:
219
- *
220
- * 0 4 5 9...
221
- * hash desclen typeptr desc[]
222
- *
223
- * On 64-bit systems:
224
- *
225
- * 0 8 9 17...
226
- * hash desclen typeptr desc[]
227
- *
228
218
* We return it one word-sized chunk at a time.
229
219
*/
230
220
static unsigned long keyring_get_key_chunk (const void * data , int level )
231
221
{
232
222
const struct keyring_index_key * index_key = data ;
233
223
unsigned long chunk = 0 ;
234
- long offset = 0 ;
224
+ const u8 * d ;
235
225
int desc_len = index_key -> desc_len , n = sizeof (chunk );
236
226
237
227
level /= ASSOC_ARRAY_KEY_CHUNK_SIZE ;
238
228
switch (level ) {
239
229
case 0 :
240
230
return hash_key_type_and_desc (index_key );
241
231
case 1 :
242
- return (( unsigned long ) index_key -> type << 8 ) | desc_len ;
232
+ return index_key -> x ;
243
233
case 2 :
244
- if (desc_len == 0 )
245
- return (u8 )((unsigned long )index_key -> type >>
246
- (ASSOC_ARRAY_KEY_CHUNK_SIZE - 8 ));
247
- n -- ;
248
- offset = 1 ;
249
- /* fall through */
234
+ return (unsigned long )index_key -> type ;
250
235
default :
251
- offset += sizeof (chunk ) - 1 ;
252
- offset += (level - 3 ) * sizeof (chunk );
253
- if (offset >= desc_len )
236
+ level -= 3 ;
237
+ if (desc_len <= sizeof (index_key -> desc ))
254
238
return 0 ;
255
- desc_len -= offset ;
239
+
240
+ d = index_key -> description + sizeof (index_key -> desc );
241
+ d += level * sizeof (long );
242
+ desc_len -= sizeof (index_key -> desc );
256
243
if (desc_len > n )
257
244
desc_len = n ;
258
- offset += desc_len ;
259
245
do {
260
246
chunk <<= 8 ;
261
- chunk |= (( u8 * ) index_key -> description )[ -- offset ] ;
247
+ chunk |= * d ++ ;
262
248
} while (-- desc_len > 0 );
263
-
264
- if (level == 2 ) {
265
- chunk <<= 8 ;
266
- chunk |= (u8 )((unsigned long )index_key -> type >>
267
- (ASSOC_ARRAY_KEY_CHUNK_SIZE - 8 ));
268
- }
269
249
return chunk ;
270
250
}
271
251
}
@@ -304,39 +284,28 @@ static int keyring_diff_objects(const void *object, const void *data)
304
284
seg_b = hash_key_type_and_desc (b );
305
285
if ((seg_a ^ seg_b ) != 0 )
306
286
goto differ ;
287
+ level += ASSOC_ARRAY_KEY_CHUNK_SIZE / 8 ;
307
288
308
289
/* The number of bits contributed by the hash is controlled by a
309
290
* constant in the assoc_array headers. Everything else thereafter we
310
291
* can deal with as being machine word-size dependent.
311
292
*/
312
- level += ASSOC_ARRAY_KEY_CHUNK_SIZE / 8 ;
313
- seg_a = a -> desc_len ;
314
- seg_b = b -> desc_len ;
293
+ seg_a = a -> x ;
294
+ seg_b = b -> x ;
315
295
if ((seg_a ^ seg_b ) != 0 )
316
296
goto differ ;
297
+ level += sizeof (unsigned long );
317
298
318
299
/* The next bit may not work on big endian */
319
- level ++ ;
320
300
seg_a = (unsigned long )a -> type ;
321
301
seg_b = (unsigned long )b -> type ;
322
302
if ((seg_a ^ seg_b ) != 0 )
323
303
goto differ ;
324
-
325
304
level += sizeof (unsigned long );
326
- if (a -> desc_len == 0 )
327
- goto same ;
328
305
329
- i = 0 ;
330
- if (((unsigned long )a -> description | (unsigned long )b -> description ) &
331
- (sizeof (unsigned long ) - 1 )) {
332
- do {
333
- seg_a = * (unsigned long * )(a -> description + i );
334
- seg_b = * (unsigned long * )(b -> description + i );
335
- if ((seg_a ^ seg_b ) != 0 )
336
- goto differ_plus_i ;
337
- i += sizeof (unsigned long );
338
- } while (i < (a -> desc_len & (sizeof (unsigned long ) - 1 )));
339
- }
306
+ i = sizeof (a -> desc );
307
+ if (a -> desc_len <= i )
308
+ goto same ;
340
309
341
310
for (; i < a -> desc_len ; i ++ ) {
342
311
seg_a = * (unsigned char * )(a -> description + i );
@@ -662,6 +631,9 @@ static bool search_nested_keyrings(struct key *keyring,
662
631
BUG_ON ((ctx -> flags & STATE_CHECKS ) == 0 ||
663
632
(ctx -> flags & STATE_CHECKS ) == STATE_CHECKS );
664
633
634
+ if (ctx -> index_key .description )
635
+ key_set_index_key (& ctx -> index_key );
636
+
665
637
/* Check to see if this top-level keyring is what we are looking for
666
638
* and whether it is valid or not.
667
639
*/
0 commit comments