~ubuntu-branches/ubuntu/oneiric/libgcrypt11/oneiric-proposed

« back to all changes in this revision

Viewing changes to cipher/tiger.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2011-01-15 15:02:27 UTC
  • mfrom: (1.1.8 upstream) (2.2.10 experimental)
  • Revision ID: james.westby@ubuntu.com-20110115150227-f9n5b3f5dgr1g9kz
Tags: 1.4.6-4
* Stricter version requirement (>> 1.10-0.1 instead of >= 1.4) on the
  libgpg-error-dev build-dependency, to get correct dependencies in the
  udeb.
* Use debhelper compatibility level 7.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* tiger.c  -  The TIGER hash function
2
 
 *      Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
 
2
 * Copyright (C) 1998, 2001, 2002, 2003, 2010 Free Software Foundation, Inc.
3
3
 *
4
4
 * This file is part of Libgcrypt.
5
5
 *
14
14
 * GNU Lesser General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU Lesser General Public
17
 
 * License along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
17
 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
19
18
 */
20
19
 
 
20
/* See http://www.cs.technion.ac.il/~biham/Reports/Tiger/  */
 
21
 
21
22
#include <config.h>
22
23
#include <stdio.h>
23
24
#include <stdlib.h>
37
38
    byte buf[64];
38
39
    int  count;
39
40
    u32  nblocks;
 
41
    int  variant;  /* 0 = old code, 1 = fixed code, 2 - TIGER2.  */
40
42
} TIGER_CONTEXT;
41
43
 
42
44
 
588
590
};
589
591
 
590
592
static void
591
 
tiger_init( void *context )
 
593
do_init (void *context, int variant)
592
594
{
593
595
  TIGER_CONTEXT *hd = context;
594
596
 
597
599
  hd->c = 0xf096a5b4c3b2e187LL;
598
600
  hd->nblocks = 0;
599
601
  hd->count = 0;
 
602
  hd->variant = variant;
 
603
}
 
604
 
 
605
static void
 
606
tiger_init( void *context )
 
607
{
 
608
  do_init (context, 0);
 
609
}
 
610
 
 
611
static void
 
612
tiger1_init( void *context )
 
613
{
 
614
  do_init (context, 1);
 
615
}
 
616
 
 
617
static void
 
618
tiger2_init( void *context )
 
619
{
 
620
  do_init (context, 2);
600
621
}
601
622
 
602
623
static void
763
784
  TIGER_CONTEXT *hd = context;
764
785
  u32 t, msb, lsb;
765
786
  byte *p;
 
787
  byte pad = hd->variant == 2? 0x80 : 0x01;
766
788
 
767
789
  tiger_write(hd, NULL, 0); /* flush */;
768
790
 
782
804
 
783
805
  if( hd->count < 56 )  /* enough room */
784
806
    {
785
 
      hd->buf[hd->count++] = 0x01; /* pad */
 
807
      hd->buf[hd->count++] = pad;
786
808
      while( hd->count < 56 )
787
809
        hd->buf[hd->count++] = 0;  /* pad */
788
810
    }
789
811
  else  /* need one extra block */
790
812
    {
791
 
      hd->buf[hd->count++] = 0x01; /* pad character */
 
813
      hd->buf[hd->count++] = pad;
792
814
      while( hd->count < 64 )
793
815
        hd->buf[hd->count++] = 0;
794
816
      tiger_write(hd, NULL, 0);  /* flush */;
815
837
                  *p++ = hd->a >> 24; *p++ = hd->a >> 16; \
816
838
                  *p++ = hd->a >>  8; *p++ = hd->a;       } while(0)
817
839
#endif
818
 
  X(a);
819
 
  X(b);
820
 
  X(c);
 
840
#define Y(a) do { *p++ = hd->a      ; *p++ = hd->a >> 8;  \
 
841
                  *p++ = hd->a >> 16; *p++ = hd->a >> 24; \
 
842
                  *p++ = hd->a >> 32; *p++ = hd->a >> 40; \
 
843
                  *p++ = hd->a >> 48; *p++ = hd->a >> 56; } while(0)
 
844
  if (hd->variant == 0)
 
845
    {
 
846
      X(a);
 
847
      X(b);
 
848
      X(c);
 
849
    }
 
850
  else
 
851
    {
 
852
      Y(a);
 
853
      Y(b);
 
854
      Y(c);
 
855
    }
821
856
#undef X
 
857
#undef Y
822
858
}
823
859
 
824
860
static byte *
829
865
  return hd->buf;
830
866
}
831
867
 
832
 
static byte asn[19] = /* Object ID is 1.3.6.1.4.1.11591.12.2 */
 
868
 
 
869
/* This is the old TIGER variant based on the unfixed reference
 
870
   implementation.  It was used in GnuPG up to 1.3.2.  We don't provide
 
871
   an OID anymore because that would not be correct.  */
 
872
gcry_md_spec_t _gcry_digest_spec_tiger =
 
873
  {
 
874
    "TIGER192", NULL, 0, NULL, 24,
 
875
    tiger_init, tiger_write, tiger_final, tiger_read,
 
876
    sizeof (TIGER_CONTEXT)
 
877
  };
 
878
 
 
879
 
 
880
 
 
881
/* This is the fixed TIGER implementation.  */
 
882
static byte asn1[19] = /* Object ID is 1.3.6.1.4.1.11591.12.2 */
833
883
  { 0x30, 0x29, 0x30, 0x0d, 0x06, 0x09, 0x2b, 0x06,
834
884
    0x01, 0x04, 0x01, 0xda, 0x47, 0x0c, 0x02,
835
885
    0x05, 0x00, 0x04, 0x18 };
836
886
 
837
 
static gcry_md_oid_spec_t oid_spec_tiger[] =
 
887
static gcry_md_oid_spec_t oid_spec_tiger1[] =
838
888
  {
839
889
    /* GNU.digestAlgorithm TIGER */
840
890
    { "1.3.6.1.4.1.11591.12.2" },
841
891
    { NULL }
842
892
  };
843
893
 
844
 
gcry_md_spec_t _gcry_digest_spec_tiger =
845
 
  {
846
 
    "TIGER192", asn, DIM (asn), oid_spec_tiger, 24,
847
 
    tiger_init, tiger_write, tiger_final, tiger_read,
848
 
    sizeof (TIGER_CONTEXT)
849
 
  };
 
894
gcry_md_spec_t _gcry_digest_spec_tiger1 =
 
895
  {
 
896
    "TIGER", asn1, DIM (asn1), oid_spec_tiger1, 24,
 
897
    tiger1_init, tiger_write, tiger_final, tiger_read,
 
898
    sizeof (TIGER_CONTEXT)
 
899
  };
 
900
 
 
901
 
 
902
 
 
903
/* This is TIGER2 which uses a changed padding algorithm.  */
 
904
gcry_md_spec_t _gcry_digest_spec_tiger2 =
 
905
  {
 
906
    "TIGER2", NULL, 0, NULL, 24,
 
907
    tiger2_init, tiger_write, tiger_final, tiger_read,
 
908
    sizeof (TIGER_CONTEXT)
 
909
  };
 
910
 
 
911
 
850
912
 
851
913
#endif /* HAVE_U64_TYPEDEF */