~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to grub-core/lib/xzembed/xz_dec_stream.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-09-13 18:02:04 UTC
  • mfrom: (1.17.15 upstream)
  • mto: (17.6.27 experimental)
  • mto: This revision was merged to the branch mainline in revision 145.
  • Revision ID: package-import@ubuntu.com-20120913180204-mojnmocbimlom4im
Tags: upstream-2.00
ImportĀ upstreamĀ versionĀ 2.00

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
        vli_type unpadded;
33
33
        vli_type uncompressed;
34
34
#ifndef GRUB_EMBED_DECOMPRESSOR
35
 
        uint8_t *crc32_context;
 
35
        uint64_t *hash_context;
36
36
#endif
37
37
};
38
38
 
 
39
/* Enough for up to 512 bits.  */
 
40
#define MAX_HASH_SIZE 64
 
41
 
39
42
struct xz_dec {
40
43
        /* Position in dec_main() */
41
44
        enum {
62
65
        size_t out_start;
63
66
 
64
67
        /* CRC32 value in Block or Index */
65
 
        uint32_t crc32_temp; /* need for crc32_validate*/
66
 
        uint8_t *crc32_context;
 
68
#ifndef GRUB_EMBED_DECOMPRESSOR
 
69
        uint8_t hash_value[MAX_HASH_SIZE]; /* need for crc32_validate*/
 
70
#endif
 
71
        int have_hash_value;
 
72
#ifndef GRUB_EMBED_DECOMPRESSOR
 
73
        uint64_t *hash_context;
 
74
        uint64_t *crc32_context;
 
75
#endif
67
76
 
68
 
        /* True if CRC32 is calculated from uncompressed data */
69
 
        bool has_crc32;
 
77
        /* Hash function calculated from uncompressed data */
 
78
#ifndef GRUB_EMBED_DECOMPRESSOR
 
79
        const gcry_md_spec_t *hash;
 
80
        const gcry_md_spec_t *crc32;
 
81
        grub_uint8_t hash_id;
 
82
#endif
 
83
        grub_size_t hash_size;
70
84
 
71
85
        /* True if we are operating in single-call mode. */
72
86
        bool single_call;
250
264
                return XZ_DATA_ERROR;
251
265
 
252
266
#ifndef GRUB_EMBED_DECOMPRESSOR
253
 
        if (s->has_crc32)
254
 
          GRUB_MD_CRC32->write(s->crc32_context,b->out + s->out_start,
255
 
                                b->out_pos - s->out_start);
 
267
        if (s->hash)
 
268
          s->hash->write(s->hash_context,b->out + s->out_start,
 
269
                         b->out_pos - s->out_start);
 
270
        if (s->crc32)
 
271
          s->crc32->write(s->crc32_context,b->out + s->out_start,
 
272
                          b->out_pos - s->out_start);
256
273
#endif
257
274
 
258
275
        if (ret == XZ_STREAM_END) {
268
285
 
269
286
                s->block.hash.unpadded += s->block_header.size
270
287
                                + s->block.compressed;
271
 
                if (s->has_crc32)
272
 
                        s->block.hash.unpadded += 4;
 
288
                s->block.hash.unpadded += s->hash_size;
273
289
 
274
290
                s->block.hash.uncompressed += s->block.uncompressed;
275
291
 
276
292
#ifndef GRUB_EMBED_DECOMPRESSOR
277
 
                GRUB_MD_CRC32->write(s->block.hash.crc32_context,
278
 
                                (const uint8_t *)&s->block.hash, 2 * sizeof(vli_type));
 
293
                if (s->hash)
 
294
                        s->hash->write(s->block.hash.hash_context,
 
295
                                       (const uint8_t *)&s->block.hash,
 
296
                                       2 * sizeof(vli_type));
279
297
#endif
280
298
 
281
299
                ++s->block.count;
290
308
        size_t in_used = b->in_pos - s->in_start;
291
309
        s->index.size += in_used;
292
310
#ifndef GRUB_EMBED_DECOMPRESSOR
293
 
        GRUB_MD_CRC32->write(s->crc32_context,b->in + s->in_start, in_used);
 
311
        if (s->hash)
 
312
                s->hash->write(s->hash_context,b->in + s->in_start, in_used);
 
313
        if (s->crc32)
 
314
                s->crc32->write(s->crc32_context,b->in + s->in_start, in_used);
294
315
#endif
295
316
}
296
317
 
337
358
                        s->index.hash.uncompressed += s->vli;
338
359
 
339
360
#ifndef GRUB_EMBED_DECOMPRESSOR
340
 
                        GRUB_MD_CRC32->write(s->index.hash.crc32_context,
341
 
                                        (const uint8_t *)&s->index.hash, 2 * sizeof(vli_type));
 
361
                        if (s->hash)
 
362
                                s->hash->write(s->index.hash.hash_context,
 
363
                                               (const uint8_t *)&s->index.hash, 2 * sizeof(vli_type));
342
364
#endif
343
365
 
344
366
                        --s->index.count;
354
376
 * Validate that the next four input bytes match the value of s->crc32.
355
377
 * s->pos must be zero when starting to validate the first byte.
356
378
 */
357
 
static enum xz_ret crc32_validate(struct xz_dec *s, struct xz_buf *b)
 
379
static enum xz_ret hash_validate(struct xz_dec *s, struct xz_buf *b,
 
380
        int crc32)
358
381
{
359
382
#ifndef GRUB_EMBED_DECOMPRESSOR
360
 
        if(s->crc32_temp == 0)
 
383
        const gcry_md_spec_t *hash = crc32 ? s->crc32 : s->hash;
 
384
        void *hash_context = crc32 ? s->crc32_context 
 
385
                : s->hash_context;
 
386
        if(!s->have_hash_value && hash
 
387
                && sizeof (s->hash_value) >= hash->mdlen)
361
388
        {
362
 
          GRUB_MD_CRC32->final(s->crc32_context);
363
 
                s->crc32_temp = get_unaligned_be32(GRUB_MD_CRC32->read(s->crc32_context));
 
389
                hash->final(hash_context);
 
390
                grub_memcpy (s->hash_value, hash->read(hash_context),
 
391
                             hash->mdlen);
 
392
                s->have_hash_value = 1;
 
393
                if (s->hash_id == 1 || crc32)
 
394
                {
 
395
                        grub_uint8_t t;
 
396
                        t = s->hash_value[0];
 
397
                        s->hash_value[0] = s->hash_value[3];
 
398
                        s->hash_value[3] = t;
 
399
                        t = s->hash_value[1];
 
400
                        s->hash_value[1] = s->hash_value[2];
 
401
                        s->hash_value[2] = t;
 
402
                }
364
403
        }
365
404
#endif
366
405
 
369
408
                        return XZ_OK;
370
409
 
371
410
#ifndef GRUB_EMBED_DECOMPRESSOR
372
 
                if (((s->crc32_temp >> s->pos) & 0xFF) != b->in[b->in_pos++])
 
411
                if (hash && s->hash_value[s->pos / 8] != b->in[b->in_pos++])
373
412
                        return XZ_DATA_ERROR;
374
413
#endif
375
414
 
376
415
                s->pos += 8;
377
416
 
378
 
        } while (s->pos < 32);
 
417
        } while (s->pos < (crc32 ? 32 : s->hash_size * 8));
379
418
 
380
419
#ifndef GRUB_EMBED_DECOMPRESSOR
381
 
        GRUB_MD_CRC32->init(s->crc32_context);
 
420
        if (s->hash)
 
421
                s->hash->init(s->hash_context);
 
422
        if (s->crc32)
 
423
                s->crc32->init(s->crc32_context);
382
424
#endif
383
 
        s->crc32_temp = 0;
 
425
        s->have_hash_value = 0;
384
426
        s->pos = 0;
385
427
 
386
428
        return XZ_STREAM_END;
387
429
}
388
430
 
 
431
static const struct
 
432
{
 
433
        const char *name;
 
434
        grub_size_t size;
 
435
} hashes[] = {
 
436
        [0x01] = { "CRC32", 4},
 
437
        [0x04] = { "CRC64", 8},
 
438
        [0x0A] = { "SHA256", 32},
 
439
};
 
440
 
389
441
/* Decode the Stream Header field (the first 12 bytes of the .xz Stream). */
390
442
static enum xz_ret dec_stream_header(struct xz_dec *s)
391
443
{
393
445
                return XZ_FORMAT_ERROR;
394
446
 
395
447
#ifndef GRUB_EMBED_DECOMPRESSOR
396
 
        uint8_t crc32_context[GRUB_MD_CRC32->contextsize];
397
 
 
398
 
        GRUB_MD_CRC32->init(crc32_context);
399
 
        GRUB_MD_CRC32->write(crc32_context,s->temp.buf + HEADER_MAGIC_SIZE, 2);
400
 
        GRUB_MD_CRC32->final(crc32_context);
401
 
 
402
 
        uint32_t resultcrc = get_unaligned_be32(GRUB_MD_CRC32->read(crc32_context));
403
 
        uint32_t readcrc = get_unaligned_le32(s->temp.buf + HEADER_MAGIC_SIZE + 2);
404
 
 
405
 
        if(resultcrc != readcrc)
406
 
                return XZ_DATA_ERROR;
 
448
        s->crc32 = grub_crypto_lookup_md_by_name ("CRC32");
 
449
 
 
450
        if (s->crc32)
 
451
        {
 
452
                uint64_t hash_context[(s->crc32->contextsize + 7) / 8];
 
453
                uint8_t resulthash[s->crc32->mdlen];
 
454
                uint8_t readhash[4];
 
455
 
 
456
                s->crc32->init(hash_context);
 
457
                s->crc32->write(hash_context,s->temp.buf + HEADER_MAGIC_SIZE, 2);
 
458
                s->crc32->final(hash_context);
 
459
 
 
460
                grub_memcpy (resulthash, s->crc32->read(hash_context),
 
461
                             s->crc32->mdlen);
 
462
                readhash[0] = s->temp.buf[HEADER_MAGIC_SIZE + 5];
 
463
                readhash[1] = s->temp.buf[HEADER_MAGIC_SIZE + 4];
 
464
                readhash[2] = s->temp.buf[HEADER_MAGIC_SIZE + 3];
 
465
                readhash[3] = s->temp.buf[HEADER_MAGIC_SIZE + 2];
 
466
 
 
467
                if(4 != s->crc32->mdlen
 
468
                   || grub_memcmp (readhash, resulthash, s->crc32->mdlen) != 0)
 
469
                        return XZ_DATA_ERROR;
 
470
        }
407
471
#endif
408
472
 
 
473
#ifndef GRUB_EMBED_DECOMPRESSOR
409
474
        /*
410
 
         * Decode the Stream Flags field. Of integrity checks, we support
411
 
         * only none (Check ID = 0) and CRC32 (Check ID = 1).
 
475
         * Decode the Stream Flags field.
412
476
         */
413
477
        if (s->temp.buf[HEADER_MAGIC_SIZE] != 0
414
 
                        || s->temp.buf[HEADER_MAGIC_SIZE + 1] > 1)
 
478
            || s->temp.buf[HEADER_MAGIC_SIZE + 1] >= ARRAY_SIZE (hashes)
 
479
            || (hashes[s->temp.buf[HEADER_MAGIC_SIZE + 1]].name == 0
 
480
                && s->temp.buf[HEADER_MAGIC_SIZE + 1] != 0))
415
481
                return XZ_OPTIONS_ERROR;
416
482
 
417
 
        s->has_crc32 = s->temp.buf[HEADER_MAGIC_SIZE + 1];
 
483
        s->hash_id = s->temp.buf[HEADER_MAGIC_SIZE + 1];
 
484
 
 
485
        if (s->crc32)
 
486
        {
 
487
                s->crc32_context = kmalloc(s->crc32->contextsize, GFP_KERNEL);
 
488
                if (s->crc32_context == NULL)
 
489
                        return XZ_MEMLIMIT_ERROR;
 
490
                s->crc32->init(s->crc32_context);
 
491
        }
 
492
#endif
 
493
 
 
494
        if (s->temp.buf[HEADER_MAGIC_SIZE + 1])
 
495
        {
 
496
                s->hash_size = hashes[s->temp.buf[HEADER_MAGIC_SIZE + 1]].size;
 
497
#ifndef GRUB_EMBED_DECOMPRESSOR
 
498
                s->hash = grub_crypto_lookup_md_by_name (hashes[s->temp.buf[HEADER_MAGIC_SIZE + 1]].name);
 
499
                if (s->hash)
 
500
                {
 
501
                        if (s->hash->mdlen != s->hash_size)
 
502
                                return XZ_OPTIONS_ERROR;
 
503
                        s->hash_context = kmalloc(s->hash->contextsize, GFP_KERNEL);
 
504
                        if (s->hash_context == NULL)
 
505
                        {
 
506
                                kfree(s->crc32_context);
 
507
                                return XZ_MEMLIMIT_ERROR;
 
508
                        }
 
509
                        
 
510
                        s->index.hash.hash_context = kmalloc(s->hash->contextsize,
 
511
                                                             GFP_KERNEL);
 
512
                        if (s->index.hash.hash_context == NULL)
 
513
                        {
 
514
                                kfree(s->hash_context);
 
515
                                kfree(s->crc32_context);
 
516
                                return XZ_MEMLIMIT_ERROR;
 
517
                        }
 
518
                        
 
519
                        s->block.hash.hash_context = kmalloc(s->hash->contextsize, GFP_KERNEL);
 
520
                        if (s->block.hash.hash_context == NULL)
 
521
                        {
 
522
                                kfree(s->index.hash.hash_context);
 
523
                                kfree(s->hash_context);
 
524
                                kfree(s->crc32_context);
 
525
                                return XZ_MEMLIMIT_ERROR;
 
526
                        }
 
527
 
 
528
                        s->hash->init(s->hash_context);
 
529
                        s->hash->init(s->index.hash.hash_context);
 
530
                        s->hash->init(s->block.hash.hash_context);
 
531
                }
 
532
                if (!s->hash)
 
533
                        return XZ_OPTIONS_ERROR;
 
534
#endif
 
535
        }
 
536
        else
 
537
        {
 
538
#ifndef GRUB_EMBED_DECOMPRESSOR
 
539
                s->hash = 0;
 
540
#endif
 
541
                s->hash_size = 0;
 
542
        }
 
543
 
 
544
        s->have_hash_value = 0;
 
545
 
418
546
 
419
547
        return XZ_OK;
420
548
}
426
554
                return XZ_DATA_ERROR;
427
555
 
428
556
#ifndef GRUB_EMBED_DECOMPRESSOR
429
 
        uint8_t crc32_context[GRUB_MD_CRC32->contextsize];
430
 
 
431
 
        GRUB_MD_CRC32->init(crc32_context);
432
 
        GRUB_MD_CRC32->write(crc32_context, s->temp.buf + 4, 6);
433
 
        GRUB_MD_CRC32->final(crc32_context);
434
 
 
435
 
        uint32_t resultcrc = get_unaligned_be32(GRUB_MD_CRC32->read(crc32_context));
436
 
        uint32_t readcrc = get_unaligned_le32(s->temp.buf);
437
 
 
438
 
        if(resultcrc != readcrc)
439
 
                return XZ_DATA_ERROR;
 
557
        if (s->crc32)
 
558
        {
 
559
                uint64_t hash_context[(s->crc32->contextsize + 7) / 8];
 
560
                uint8_t resulthash[s->crc32->mdlen];
 
561
                uint8_t readhash[4];
 
562
 
 
563
                s->crc32->init(hash_context);
 
564
                s->crc32->write(hash_context,s->temp.buf + 4, 6);
 
565
                s->crc32->final(hash_context);
 
566
 
 
567
                grub_memcpy (resulthash, s->crc32->read(hash_context),
 
568
                             s->crc32->mdlen);
 
569
                readhash[0] = s->temp.buf[3];
 
570
                readhash[1] = s->temp.buf[2];
 
571
                readhash[2] = s->temp.buf[1];
 
572
                readhash[3] = s->temp.buf[0];
 
573
 
 
574
                if(4 != s->crc32->mdlen
 
575
                   || grub_memcmp (readhash, resulthash, s->crc32->mdlen) != 0)
 
576
                        return XZ_DATA_ERROR;
 
577
        }
440
578
#endif
441
579
 
 
580
 
442
581
        /*
443
582
         * Validate Backward Size. Note that we never added the size of the
444
583
         * Index CRC32 field to s->index.size, thus we use s->index.size / 4
447
586
        if ((s->index.size >> 2) != get_le32(s->temp.buf + 4))
448
587
                return XZ_DATA_ERROR;
449
588
 
450
 
        if (s->temp.buf[8] != 0 || s->temp.buf[9] != s->has_crc32)
 
589
#ifndef GRUB_EMBED_DECOMPRESSOR
 
590
        if (s->temp.buf[8] != 0 || s->temp.buf[9] != s->hash_id)
451
591
                return XZ_DATA_ERROR;
 
592
#endif
452
593
 
453
594
        /*
454
595
         * Use XZ_STREAM_END instead of XZ_OK to be more convenient
468
609
         */
469
610
        s->temp.size -= 4;
470
611
#ifndef GRUB_EMBED_DECOMPRESSOR
471
 
        uint8_t crc32_context[GRUB_MD_CRC32->contextsize];
472
 
 
473
 
        GRUB_MD_CRC32->init(crc32_context);
474
 
        GRUB_MD_CRC32->write(crc32_context, s->temp.buf, s->temp.size);
475
 
        GRUB_MD_CRC32->final(crc32_context);
476
 
 
477
 
        uint32_t resultcrc = get_unaligned_be32(GRUB_MD_CRC32->read(crc32_context));
478
 
        uint32_t readcrc = get_unaligned_le32(s->temp.buf + s->temp.size);
479
 
 
480
 
        if (resultcrc != readcrc)
481
 
                return XZ_DATA_ERROR;
 
612
        if (s->crc32)
 
613
        {
 
614
                uint64_t hash_context[(s->crc32->contextsize + 7) / 8];
 
615
                uint8_t resulthash[s->crc32->mdlen];
 
616
                uint8_t readhash[4];
 
617
 
 
618
                s->crc32->init(hash_context);
 
619
                s->crc32->write(hash_context,s->temp.buf, s->temp.size);
 
620
                s->crc32->final(hash_context);
 
621
 
 
622
                grub_memcpy (resulthash, s->crc32->read(hash_context),
 
623
                             s->crc32->mdlen);
 
624
                readhash[3] = s->temp.buf[s->temp.size];
 
625
                readhash[2] = s->temp.buf[s->temp.size + 1];
 
626
                readhash[1] = s->temp.buf[s->temp.size + 2];
 
627
                readhash[0] = s->temp.buf[s->temp.size + 3];
 
628
 
 
629
                if(4 != s->crc32->mdlen
 
630
                   || grub_memcmp (readhash, resulthash, s->crc32->mdlen) != 0)
 
631
                        return XZ_DATA_ERROR;
 
632
        }
482
633
#endif
483
634
 
484
635
        s->temp.pos = 2;
659
810
                        s->sequence = SEQ_BLOCK_CHECK;
660
811
 
661
812
                case SEQ_BLOCK_CHECK:
662
 
                        if (s->has_crc32) {
663
 
                                ret = crc32_validate(s, b);
664
 
                                if (ret != XZ_STREAM_END)
665
 
                                        return ret;
666
 
                        }
 
813
                        ret = hash_validate(s, b, 0);
 
814
                        if (ret != XZ_STREAM_END)
 
815
                                return ret;
667
816
 
668
817
                        s->sequence = SEQ_BLOCK_START;
669
818
                        break;
691
840
                        index_update(s, b);
692
841
 
693
842
#ifndef GRUB_EMBED_DECOMPRESSOR
694
 
                        /* Compare the hashes to validate the Index field. */
695
 
                        GRUB_MD_CRC32->final(s->block.hash.crc32_context);
696
 
                        GRUB_MD_CRC32->final(s->index.hash.crc32_context);
697
 
                        uint32_t block_crc = *(uint32_t*)GRUB_MD_CRC32->read(s->block.hash.crc32_context);
698
 
                        uint32_t index_crc = *(uint32_t*)GRUB_MD_CRC32->read(s->index.hash.crc32_context);
699
 
 
700
 
                        if (s->block.hash.unpadded != s->index.hash.unpadded
701
 
                            || s->block.hash.uncompressed != s->index.hash.uncompressed
702
 
                            || block_crc != index_crc)
 
843
                        if (s->hash)
703
844
                        {
704
 
                                return XZ_DATA_ERROR;
 
845
                                uint8_t block_hash[s->hash->mdlen];
 
846
                                uint8_t index_hash[s->hash->mdlen];
 
847
                                /* Compare the hashes to validate the Index field. */
 
848
                                s->hash->final(s->block.hash.hash_context);
 
849
                                s->hash->final(s->index.hash.hash_context);
 
850
                                grub_memcpy (block_hash,
 
851
                                             s->hash->read(s->block.hash.hash_context),
 
852
                                        s->hash->mdlen);
 
853
                                grub_memcpy (index_hash,
 
854
                                             s->hash->read(s->index.hash.hash_context),
 
855
                                        s->hash->mdlen);
 
856
 
 
857
                                if (s->block.hash.unpadded != s->index.hash.unpadded
 
858
                                    || s->block.hash.uncompressed != s->index.hash.uncompressed
 
859
                                    || grub_memcmp (block_hash, index_hash, s->hash->mdlen) != 0)
 
860
                                        return XZ_DATA_ERROR;
705
861
                        }
706
862
#endif
707
863
 
708
864
                        s->sequence = SEQ_INDEX_CRC32;
709
865
 
710
866
                case SEQ_INDEX_CRC32:
711
 
                        ret = crc32_validate(s, b);
 
867
                        ret = hash_validate(s, b, 1);
712
868
                        if (ret != XZ_STREAM_END)
713
869
                                return ret;
714
870
 
802
958
                return NULL;
803
959
#endif
804
960
 
805
 
#ifndef GRUB_EMBED_DECOMPRESSOR
806
 
        /* prepare CRC32 calculators */
807
 
        if(GRUB_MD_CRC32 == NULL)
808
 
        {
809
 
                kfree(s);
810
 
                return NULL;
811
 
        }
812
 
 
813
 
        s->crc32_context = kmalloc(GRUB_MD_CRC32->contextsize, GFP_KERNEL);
814
 
        if (s->crc32_context == NULL)
815
 
        {
816
 
                kfree(s);
817
 
                return NULL;
818
 
        }
819
 
 
820
 
        s->index.hash.crc32_context = kmalloc(GRUB_MD_CRC32->contextsize, GFP_KERNEL);
821
 
        if (s->index.hash.crc32_context == NULL)
822
 
        {
823
 
                kfree(s->crc32_context);
824
 
                kfree(s);
825
 
                return NULL;
826
 
        }
827
 
 
828
 
        s->block.hash.crc32_context = kmalloc(GRUB_MD_CRC32->contextsize, GFP_KERNEL);
829
 
        if (s->block.hash.crc32_context == NULL)
830
 
        {
831
 
                kfree(s->index.hash.crc32_context);
832
 
                kfree(s->crc32_context);
833
 
                kfree(s);
834
 
                return NULL;
835
 
        }
836
 
 
837
 
 
838
 
        GRUB_MD_CRC32->init(s->crc32_context);
839
 
        GRUB_MD_CRC32->init(s->index.hash.crc32_context);
840
 
        GRUB_MD_CRC32->init(s->block.hash.crc32_context);
841
 
#endif
842
 
 
843
 
        s->crc32_temp = 0;
 
961
        memset (s, 0, sizeof (*s));
844
962
 
845
963
        s->single_call = dict_max == 0;
846
964
 
876
994
 
877
995
        {
878
996
#ifndef GRUB_EMBED_DECOMPRESSOR
879
 
                uint8_t *t;
880
 
                t = s->block.hash.crc32_context;
 
997
                uint64_t *t;
 
998
                t = s->block.hash.hash_context;
881
999
#endif
882
1000
                memzero(&s->block, sizeof(s->block));
883
1001
#ifndef GRUB_EMBED_DECOMPRESSOR
884
 
                s->block.hash.crc32_context = t;
885
 
                t = s->index.hash.crc32_context;
 
1002
                s->block.hash.hash_context = t;
 
1003
                t = s->index.hash.hash_context;
886
1004
#endif
887
1005
                memzero(&s->index, sizeof(s->index));
888
1006
#ifndef GRUB_EMBED_DECOMPRESSOR
889
 
                s->index.hash.crc32_context = t;
 
1007
                s->index.hash.hash_context = t;
890
1008
#endif
891
1009
        }
892
1010
        s->temp.pos = 0;
893
1011
        s->temp.size = STREAM_HEADER_SIZE;
894
1012
 
895
1013
#ifndef GRUB_EMBED_DECOMPRESSOR
896
 
        GRUB_MD_CRC32->init(s->crc32_context);
897
 
        GRUB_MD_CRC32->init(s->index.hash.crc32_context);
898
 
        GRUB_MD_CRC32->init(s->block.hash.crc32_context);
 
1014
        if (s->hash)
 
1015
        {
 
1016
                s->hash->init(s->hash_context);
 
1017
                s->hash->init(s->index.hash.hash_context);
 
1018
                s->hash->init(s->block.hash.hash_context);
 
1019
        }
899
1020
#endif
900
 
        s->crc32_temp = 0;
 
1021
        s->have_hash_value = 0;
901
1022
}
902
1023
 
903
1024
void xz_dec_end(struct xz_dec *s)
905
1026
        if (s != NULL) {
906
1027
                xz_dec_lzma2_end(s->lzma2);
907
1028
#ifndef GRUB_EMBED_DECOMPRESSOR
908
 
                kfree(s->index.hash.crc32_context);
909
 
                kfree(s->block.hash.crc32_context);
 
1029
                kfree(s->index.hash.hash_context);
 
1030
                kfree(s->block.hash.hash_context);
 
1031
                kfree(s->hash_context);
910
1032
                kfree(s->crc32_context);
911
1033
#endif
912
1034
#ifdef XZ_DEC_BCJ