481{
482 uint32_t a,b,c;
483 union { const void *ptr; size_t i; } u;
484
485
486 a = b = c = 0xdeadbeef + ((uint32_t)length) + *pc;
487 c += *pb;
488
489 u.ptr = key;
491 const uint32_t *k = (const uint32_t *)key;
492
493
494
495 while (length > 12)
496 {
497 a += k[0];
498 b += k[1];
499 c += k[2];
501 length -= 12;
502 k += 3;
503 }
504
505
506
507
508
509
510
511
512
513
514
515#ifndef VALGRIND
516
517 switch(length)
518 {
519 case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
520 case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break;
521 case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break;
522 case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break;
523 case 8 : b+=k[1]; a+=k[0]; break;
524 case 7 : b+=k[1]&0xffffff; a+=k[0]; break;
525 case 6 : b+=k[1]&0xffff; a+=k[0]; break;
526 case 5 : b+=k[1]&0xff; a+=k[0]; break;
527 case 4 : a+=k[0]; break;
528 case 3 : a+=k[0]&0xffffff; break;
529 case 2 : a+=k[0]&0xffff; break;
530 case 1 : a+=k[0]&0xff; break;
531 case 0 : *pc=c; *pb=b; return;
532 }
533
534#else
535
536 k8 = (const uint8_t *)k;
537 switch(length)
538 {
539 case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
540 case 11: c+=((uint32_t)k8[10])<<16;
541 case 10: c+=((uint32_t)k8[9])<<8;
542 case 9 : c+=k8[8];
543 case 8 : b+=k[1]; a+=k[0]; break;
544 case 7 : b+=((uint32_t)k8[6])<<16;
545 case 6 : b+=((uint32_t)k8[5])<<8;
546 case 5 : b+=k8[4];
547 case 4 : a+=k[0]; break;
548 case 3 : a+=((uint32_t)k8[2])<<16;
549 case 2 : a+=((uint32_t)k8[1])<<8;
550 case 1 : a+=k8[0]; break;
551 case 0 : *pc=c; *pb=b; return;
552 }
553
554#endif
555
557 const uint16_t *k = (const uint16_t *)key;
558 const uint8_t *k8;
559
560
561 while (length > 12)
562 {
563 a += k[0] + (((uint32_t)k[1])<<16);
564 b += k[2] + (((uint32_t)k[3])<<16);
565 c += k[4] + (((uint32_t)k[5])<<16);
567 length -= 12;
568 k += 6;
569 }
570
571
572 k8 = (const uint8_t *)k;
573 switch(length)
574 {
575 case 12: c+=k[4]+(((uint32_t)k[5])<<16);
576 b+=k[2]+(((uint32_t)k[3])<<16);
577 a+=k[0]+(((uint32_t)k[1])<<16);
578 break;
579 case 11: c+=((uint32_t)k8[10])<<16;
580 case 10: c+=k[4];
581 b+=k[2]+(((uint32_t)k[3])<<16);
582 a+=k[0]+(((uint32_t)k[1])<<16);
583 break;
584 case 9 : c+=k8[8];
585 case 8 : b+=k[2]+(((uint32_t)k[3])<<16);
586 a+=k[0]+(((uint32_t)k[1])<<16);
587 break;
588 case 7 : b+=((uint32_t)k8[6])<<16;
589 case 6 : b+=k[2];
590 a+=k[0]+(((uint32_t)k[1])<<16);
591 break;
592 case 5 : b+=k8[4];
593 case 4 : a+=k[0]+(((uint32_t)k[1])<<16);
594 break;
595 case 3 : a+=((uint32_t)k8[2])<<16;
596 case 2 : a+=k[0];
597 break;
598 case 1 : a+=k8[0];
599 break;
600 case 0 : *pc=c; *pb=b; return;
601 }
602
603 } else {
604 const uint8_t *k = (const uint8_t *)key;
605
606
607 while (length > 12)
608 {
609 a += k[0];
610 a += ((uint32_t)k[1])<<8;
611 a += ((uint32_t)k[2])<<16;
612 a += ((uint32_t)k[3])<<24;
613 b += k[4];
614 b += ((uint32_t)k[5])<<8;
615 b += ((uint32_t)k[6])<<16;
616 b += ((uint32_t)k[7])<<24;
617 c += k[8];
618 c += ((uint32_t)k[9])<<8;
619 c += ((uint32_t)k[10])<<16;
620 c += ((uint32_t)k[11])<<24;
622 length -= 12;
623 k += 12;
624 }
625
626
627 switch(length)
628 {
629 case 12: c+=((uint32_t)k[11])<<24;
630 case 11: c+=((uint32_t)k[10])<<16;
631 case 10: c+=((uint32_t)k[9])<<8;
632 case 9 : c+=k[8];
633 case 8 : b+=((uint32_t)k[7])<<24;
634 case 7 : b+=((uint32_t)k[6])<<16;
635 case 6 : b+=((uint32_t)k[5])<<8;
636 case 5 : b+=k[4];
637 case 4 : a+=((uint32_t)k[3])<<24;
638 case 3 : a+=((uint32_t)k[2])<<16;
639 case 2 : a+=((uint32_t)k[1])<<8;
640 case 1 : a+=k[0];
641 break;
642 case 0 : *pc=c; *pb=b; return;
643 }
644 }
645
646 final(a,b,c);
647 *pc=c; *pb=b;
648}
#define HASH_LITTLE_ENDIAN