Changeset 18 for trunk/src


Ignore:
Timestamp:
Jan 28, 2006, 9:07:52 PM (19 years ago)
Author:
rainer
Message:

Optimized version of tiger algorithm, and basic ingredients for unit testing (part 2)

Location:
trunk/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/samhain.c

    r1 r18  
    10751075 *
    10761076 *******************************************************/
     1077#if !defined(SH_CUTEST)
    10771078int main(int argc, char * argv[])
     1079#else
     1080int undef_main(int argc, char * argv[])
     1081#endif
    10781082{
    10791083#if defined(INET_SYSLOG)
  • trunk/src/sh_database.c

    r13 r18  
    10641064        }
    10651065
     1066      /* Read in defaults from /etc/my.cnf and associated files,
     1067       * suggested by arjones at simultan dyndns org
     1068       * see: - http://dev.mysql.com/doc/refman/5.0/en/option-files.html
     1069       *        for the my.cnf format,
     1070       *      - http://dev.mysql.com/doc/refman/5.0/en/mysql-options.html
     1071       *        for possible options
     1072       * We don't check the return value because it's useless (failure due
     1073       * to lack of access permission is not reported).
     1074       */
     1075      mysql_options(db_conn, MYSQL_READ_DEFAULT_GROUP, _("samhain"));
     1076
    10661077      status = 0;
    10671078 
  • trunk/src/sh_hash.c

    r10 r18  
    396396static int hashfunc(char *s)
    397397{
    398   unsigned n = 0;
     398  unsigned int n = 0;
    399399
    400400  for ( ; *s; s++)
    401401    n = 31 * n + *s;
    402   return n & 0xFFFF;/* % TABSIZE*/;
     402
     403  return n & (TABSIZE - 1); /* % TABSIZE */;
    403404}
    404405
  • trunk/src/sh_tiger0.c

    r11 r18  
    2525#include "sh_utils.h"
    2626
    27 #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64)
     27#define PRIV_MAX  32768
     28
     29#if defined(TIGER_64_BIT)
    2830#if defined(HAVE_LONG_64)
    2931typedef unsigned long int word64;
     32#elif defined(HAVE_LONG_LONG_64)
     33typedef unsigned long long int word64;
    3034#else
    31 typedef unsigned long long int word64;
     35#error No 64 bit type found !
    3236#endif
    3337#endif
     
    4650#define GPGFORMAT (_("%08X %08X %08X  %08X %08X %08X"))
    4751#else
    48 #error No 32 byte type found !
     52#error No 32 bit type found !
    4953#endif
    5054
     
    5458#define FIL__  _("sh_tiger0.c")
    5559
    56 #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64)
    57 /* #ifdef HAVE_LONG_64 */
     60#if defined(TIGER_64_BIT)
     61
    5862void tiger_t(word64 *str, word64 length, word64 * res);
    5963void tiger(word64 *str, word64 length, word64 * res);
     
    97101static sh_byte buffer[PRIV_MAX + 72];
    98102
    99 #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64)
    100 /* #ifdef HAVE_LONG_64 */
     103#if defined(TIGER_64_BIT)
    101104static
    102105word64 * sh_tiger_hash_val (char * filename, TigerType what,
     
    114117  char    * tmp;
    115118  sh_byte * bptr;
    116   /* sh_byte buffer[PRIV_MAX + 72]; */
    117119  sh_byte bbuf[64];
    118120
     
    131133#endif
    132134
    133 #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64)
    134   /* #ifdef HAVE_LONG_64 */
     135#if defined(TIGER_64_BIT)
    135136#define TIGER_CAST (word64*)
    136137  static word64 res[3];
     
    254255          }
    255256       
    256         if (blk < 64) /* this must be (PRIV_MAX / 64) */
     257        if (blk < (PRIV_MAX / 64)) /* this must be (PRIV_MAX / 64) */
    257258          break;
    258259
     
    359360    bptr = buffer;
    360361
    361     memcpy(bptr, bbuf,    64); bptr +=   64;
    362     memcpy(bptr, bbuf,    64); bptr +=   64;
    363     memcpy(bptr, buffer, 128); bptr +=  128;
    364     memcpy(bptr, buffer, 256); bptr +=  256;
    365     memcpy(bptr, buffer, 512); bptr +=  512;
    366     memcpy(bptr, buffer,1024); bptr += 1024;
    367     memcpy(bptr, buffer,2048);
     362    memcpy(bptr, bbuf,     64); bptr +=    64;
     363    memcpy(bptr, bbuf,     64); bptr +=    64;
     364    memcpy(bptr, buffer,  128); bptr +=   128;
     365    memcpy(bptr, buffer,  256); bptr +=   256;
     366    memcpy(bptr, buffer,  512); bptr +=   512;
     367    memcpy(bptr, buffer, 1024); bptr +=  1024;
     368    memcpy(bptr, buffer, 2048); bptr +=  2048;
     369    memcpy(bptr, buffer, 4096); bptr +=  4096;
     370    memcpy(bptr, buffer, 8192); bptr +=  8192;
     371    memcpy(bptr, buffer,16384);
    368372
    369373    if (what == TIGER_FILE)
     
    814818                       MSG_E_SUBGEN, _("Not TIGER_FD"),
    815819                       _("sh_tiger_md5_hash"));
     820      out[0] = '\0';
    816821      return out;
    817822    }
     
    13281333                       MSG_E_SUBGEN, _("Not TIGER_FD"),
    13291334                       _("sh_tiger_sha1_hash"));
     1335      out[0] = '\0';
    13301336      return out;
    13311337    }
     
    14101416                                      unsigned long Length, int timeout)
    14111417{
    1412 #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64)
    1413   /* #ifdef HAVE_LONG_64 */
     1418#if defined(TIGER_64_BIT)
    14141419  word64 * res;
    14151420#else
     
    14251430    {
    14261431      /*@-bufferoverflowhigh -formatconst@*/
    1427 #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64)
    1428       /* #ifdef HAVE_LONG_64 */
     1432#if defined(TIGER_64_BIT)
    14291433      sprintf(out,                                   /* known to fit  */
    14301434              MYFORMAT,
     
    14611465  char * out;
    14621466  char   outhash[48+6+1];
    1463 #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64)
    1464   /* #ifdef HAVE_LONG_64 */
     1467#if defined(TIGER_64_BIT)
    14651468  word64 * res;
    14661469#else
     
    14741477    {
    14751478      /*@-bufferoverflowhigh -formatconst@*/
    1476 #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64)
    1477       /* #ifdef HAVE_LONG_64 */
     1479#if defined(TIGER_64_BIT)
    14781480      sprintf(outhash,                               /* known to fit  */
    14791481              GPGFORMAT,
     
    15301532                               unsigned long Length)
    15311533{
    1532 #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64)
    1533   /* #ifdef HAVE_LONG_64 */
     1534#if defined(TIGER_64_BIT)
    15341535  word64 * res;
    15351536#else
     
    15481549  if (res != NULL)
    15491550    {
    1550 #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64)
    1551       /* #ifdef HAVE_LONG_64 */
     1551#if defined(TIGER_64_BIT)
    15521552        out[0] =  (UINT32)(res[0]>>32);
    15531553        out[1] =  (UINT32)(res[0]);
  • trunk/src/sh_tiger1.c

    r1 r18  
    55#include "config_xor.h"
    66
    7 
    8 #if !defined(HAVE_LONG_64) && !defined(HAVE_LONG_LONG_64)
     7/* we already inline in the function used for file checksums */
     8/* #define UNROLL_COMPRESS */
     9#undef UNROLL_COMPRESS
     10
     11#if !defined(TIGER_64_BIT)
    912
    1013/* Tiger: A Fast New Hash Function
     
    3740typedef unsigned short sh_word32;
    3841#else
    39 #error No 32 byte type found !
     42#error No 32 bit type found !
    4043#endif
    4144
     
    4649#define BIG_ENDIAN
    4750#endif
    48 
    49 /* NOTE that this code is NOT FULLY OPTIMIZED for any  */
    50 /* machine. Assembly code might be much faster on some */
    51 /* machines, especially if the code is compiled with   */
    52 /* gcc.                                                */
    5351
    5452/* The number of passes of the hash function.          */
     
    6563#define t4 (tiger_table+256*3)
    6664
    67 #define sh_sub64(s0, s1, p0, p1) \
     65#define sub64(s0, s1, p0, p1) \
    6866      temps0 = (p0); \
    6967      tcarry = s0 < temps0; \
     
    7169      s1 -= (p1) + tcarry;
    7270
    73 #define sh_add64(s0, s1, p0, p1) \
     71#define add64(s0, s1, p0, p1) \
    7472      temps0 = (p0); \
    7573      s0 += temps0; \
     
    7775      s1 += (p1) + tcarry;
    7876
    79 #define sh_xor64(s0, s1, p0, p1) \
     77#define xor64(s0, s1, p0, p1) \
    8078      s0 ^= (p0); \
    8179      s1 ^= (p1);
    8280
    83 #define sh_mul5(s0, s1) \
     81#define mul5(s0, s1) \
    8482      tempt0 = s0<<2; \
    8583      tempt1 = (s1<<2)|(s0>>30); \
    86       sh_add64(s0, s1, tempt0, tempt1);
    87 
    88 #define sh_mul7(s0, s1) \
     84      add64(s0, s1, tempt0, tempt1);
     85
     86#define mul7(s0, s1) \
    8987      tempt0 = s0<<3; \
    9088      tempt1 = (s1<<3)|(s0>>29); \
    91       sh_sub64(tempt0, tempt1, s0, s1); \
     89      sub64(tempt0, tempt1, s0, s1); \
    9290      s0 = tempt0; \
    9391      s1 = tempt1;
    9492
    95 #define sh_mul9(s0, s1) \
     93#define mul9(s0, s1) \
    9694      tempt0 = s0<<3; \
    9795      tempt1 = (s1<<3)|(s0>>29); \
    98       sh_add64(s0, s1, tempt0, tempt1);
    99 
    100 #define sh_save_abc \
     96      add64(s0, s1, tempt0, tempt1);
     97
     98#define save_abc \
    10199      aa0 = a0; \
    102100      aa1 = a1; \
     
    106104      cc1 = c1;
    107105
    108 #define sh_round(a0,a1,b0,b1,c0,c1,x0,x1,mul) \
    109       sh_xor64(c0, c1, x0, x1); \
     106#define roundX(a0,a1,b0,b1,c0,c1,x0,x1) \
     107      xor64(c0, c1, x0, x1); \
    110108      temp0  = t1[((c0)>>(0*8))&0xFF][0] ; \
    111109      temp1  = t1[((c0)>>(0*8))&0xFF][1] ; \
     
    116114      temp0 ^= t4[((c1)>>(2*8))&0xFF][0] ; \
    117115      temp1 ^= t4[((c1)>>(2*8))&0xFF][1] ; \
    118       sh_sub64(a0, a1, temp0, temp1); \
     116      sub64(a0, a1, temp0, temp1); \
    119117      temp0  = t4[((c0)>>(1*8))&0xFF][0] ; \
    120118      temp1  = t4[((c0)>>(1*8))&0xFF][1] ; \
     
    125123      temp0 ^= t1[((c1)>>(3*8))&0xFF][0] ; \
    126124      temp1 ^= t1[((c1)>>(3*8))&0xFF][1] ; \
    127       sh_add64(b0, b1, temp0, temp1); \
    128       if((mul)==5) \
    129         {sh_mul5(b0, b1);} \
    130       else \
    131         if((mul)==7) \
    132           {sh_mul7(b0, b1);} \
    133         else \
    134           {sh_mul9(b0, b1)};
    135 
    136 #define sh_pass(a0,a1,b0,b1,c0,c1,mul) \
    137       sh_round(a0,a1,b0,b1,c0,c1,x00,x01,mul); \
    138       sh_round(b0,b1,c0,c1,a0,a1,x10,x11,mul); \
    139       sh_round(c0,c1,a0,a1,b0,b1,x20,x21,mul); \
    140       sh_round(a0,a1,b0,b1,c0,c1,x30,x31,mul); \
    141       sh_round(b0,b1,c0,c1,a0,a1,x40,x41,mul); \
    142       sh_round(c0,c1,a0,a1,b0,b1,x50,x51,mul); \
    143       sh_round(a0,a1,b0,b1,c0,c1,x60,x61,mul); \
    144       sh_round(b0,b1,c0,c1,a0,a1,x70,x71,mul);
    145 
    146 #define sh_key_schedule \
    147       sh_sub64(x00, x01, x70^0xA5A5A5A5, x71^0xA5A5A5A5); \
    148       sh_xor64(x10, x11, x00, x01); \
    149       sh_add64(x20, x21, x10, x11); \
    150       sh_sub64(x30, x31, x20^((~x10)<<19), ~x21^(((x11)<<19)|((x10)>>13))); \
    151       sh_xor64(x40, x41, x30, x31); \
    152       sh_add64(x50, x51, x40, x41); \
    153       sh_sub64(x60, x61, ~x50^(((x40)>>23)|((x41)<<9)), x51^((~x41)>>23)); \
    154       sh_xor64(x70, x71, x60, x61); \
    155       sh_add64(x00, x01, x70, x71); \
    156       sh_sub64(x10, x11, x00^((~x70)<<19), ~x01^(((x71)<<19)|((x70)>>13))); \
    157       sh_xor64(x20, x21, x10, x11); \
    158       sh_add64(x30, x31, x20, x21); \
    159       sh_sub64(x40, x41, ~x30^(((x20)>>23)|((x21)<<9)), x31^((~x21)>>23)); \
    160       sh_xor64(x50, x51, x40, x41); \
    161       sh_add64(x60, x61, x50, x51); \
    162       sh_sub64(x70, x71, x60^0x89ABCDEF, x61^0x01234567);
    163 
    164 #define sh_feedforward \
    165       sh_xor64(a0, a1, aa0, aa1); \
    166       sh_sub64(b0, b1, bb0, bb1); \
    167       sh_add64(c0, c1, cc0, cc1);
    168 
    169 #ifdef UNROLL_COMPRESS
    170 #define sh_compress \
    171       sh_save_abc \
    172       sh_pass(a0,a1,b0,b1,c0,c1,5); \
    173       sh_key_schedule; \
    174       sh_pass(c0,c1,a0,a1,b0,b1,7); \
    175       sh_key_schedule; \
    176       sh_pass(b0,b1,c0,c1,a0,a1,9); \
    177       for(pass_no=3; pass_no<PASSES; pass_no++) { \
    178         sh_key_schedule \
    179         sh_pass(a0,a1,b0,b1,c0,c1,9); \
    180         tmpa=a0; a0=c0; c0=b0; b0=tmpa; \
    181         tmpa=a1; a1=c1; c1=b1; b1=tmpa;} \
    182       sh_feedforward
    183 #else
    184 #define sh_compress \
    185       sh_save_abc \
    186       for(pass_no=0; pass_no<PASSES; pass_no++) { \
    187         if(pass_no != 0) {sh_key_schedule} \
    188         sh_pass(a0,a1,b0,b1,c0,c1,(pass_no==0?5:pass_no==1?7:9)) \
    189         tmpa=a0; a0=c0; c0=b0; b0=tmpa; \
    190         tmpa=a1; a1=c1; c1=b1; b1=tmpa;} \
    191       sh_feedforward
    192 #endif
     125      add64(b0, b1, temp0, temp1);
     126
     127
     128#define round5(a0,a1,b0,b1,c0,c1,x0,x1) \
     129      roundX(a0,a1,b0,b1,c0,c1,x0,x1); \
     130      mul5(b0, b1);
     131
     132#define round7(a0,a1,b0,b1,c0,c1,x0,x1) \
     133      roundX(a0,a1,b0,b1,c0,c1,x0,x1); \
     134      mul7(b0, b1);
     135
     136#define round9(a0,a1,b0,b1,c0,c1,x0,x1) \
     137      roundX(a0,a1,b0,b1,c0,c1,x0,x1); \
     138      mul9(b0, b1);
     139
     140
     141/* mixed with key_schedule
     142 */
     143#define pass5(a0,a1,b0,b1,c0,c1) \
     144      round5(a0,a1,b0,b1,c0,c1,x00,x01); \
     145      sub64(x00, x01, x70^0xA5A5A5A5, x71^0xA5A5A5A5); \
     146      round5(b0,b1,c0,c1,a0,a1,x10,x11); \
     147      xor64(x10, x11, x00, x01); \
     148      round5(c0,c1,a0,a1,b0,b1,x20,x21); \
     149      add64(x20, x21, x10, x11); \
     150      round5(a0,a1,b0,b1,c0,c1,x30,x31); \
     151      sub64(x30, x31, x20^((~x10)<<19), ~x21^(((x11)<<19)|((x10)>>13))); \
     152      round5(b0,b1,c0,c1,a0,a1,x40,x41); \
     153      xor64(x40, x41, x30, x31); \
     154      round5(c0,c1,a0,a1,b0,b1,x50,x51); \
     155      add64(x50, x51, x40, x41); \
     156      round5(a0,a1,b0,b1,c0,c1,x60,x61); \
     157      sub64(x60, x61, ~x50^(((x40)>>23)|((x41)<<9)), x51^((~x41)>>23)); \
     158      round5(b0,b1,c0,c1,a0,a1,x70,x71);
     159
     160/* mixed with key_schedule
     161 */
     162#define pass7(a0,a1,b0,b1,c0,c1) \
     163      round7(a0,a1,b0,b1,c0,c1,x00,x01); \
     164      sub64(x00, x01, x70^0xA5A5A5A5, x71^0xA5A5A5A5); \
     165      round7(b0,b1,c0,c1,a0,a1,x10,x11); \
     166      xor64(x10, x11, x00, x01); \
     167      round7(c0,c1,a0,a1,b0,b1,x20,x21); \
     168      add64(x20, x21, x10, x11); \
     169      round7(a0,a1,b0,b1,c0,c1,x30,x31); \
     170      sub64(x30, x31, x20^((~x10)<<19), ~x21^(((x11)<<19)|((x10)>>13))); \
     171      round7(b0,b1,c0,c1,a0,a1,x40,x41); \
     172      xor64(x40, x41, x30, x31); \
     173      round7(c0,c1,a0,a1,b0,b1,x50,x51); \
     174      add64(x50, x51, x40, x41); \
     175      round7(a0,a1,b0,b1,c0,c1,x60,x61); \
     176      sub64(x60, x61, ~x50^(((x40)>>23)|((x41)<<9)), x51^((~x41)>>23)); \
     177      round7(b0,b1,c0,c1,a0,a1,x70,x71);
     178
     179/* mixed with key_schedule
     180 */
     181#define pass9(a0,a1,b0,b1,c0,c1) \
     182      round9(a0,a1,b0,b1,c0,c1,x00,x01); \
     183      sub64(x00, x01, x70^0xA5A5A5A5, x71^0xA5A5A5A5); \
     184      round9(b0,b1,c0,c1,a0,a1,x10,x11); \
     185      xor64(x10, x11, x00, x01); \
     186      round9(c0,c1,a0,a1,b0,b1,x20,x21); \
     187      add64(x20, x21, x10, x11); \
     188      round9(a0,a1,b0,b1,c0,c1,x30,x31); \
     189      sub64(x30, x31, x20^((~x10)<<19), ~x21^(((x11)<<19)|((x10)>>13))); \
     190      round9(b0,b1,c0,c1,a0,a1,x40,x41); \
     191      xor64(x40, x41, x30, x31); \
     192      round9(c0,c1,a0,a1,b0,b1,x50,x51); \
     193      add64(x50, x51, x40, x41); \
     194      round9(a0,a1,b0,b1,c0,c1,x60,x61); \
     195      sub64(x60, x61, ~x50^(((x40)>>23)|((x41)<<9)), x51^((~x41)>>23)); \
     196      round9(b0,b1,c0,c1,a0,a1,x70,x71);
     197
     198#define key_schedule \
     199      xor64(x70, x71, x60, x61); \
     200      add64(x00, x01, x70, x71); \
     201      sub64(x10, x11, x00^((~x70)<<19), ~x01^(((x71)<<19)|((x70)>>13))); \
     202      xor64(x20, x21, x10, x11); \
     203      add64(x30, x31, x20, x21); \
     204      sub64(x40, x41, ~x30^(((x20)>>23)|((x21)<<9)), x31^((~x21)>>23)); \
     205      xor64(x50, x51, x40, x41); \
     206      add64(x60, x61, x50, x51); \
     207      sub64(x70, x71, x60^0x89ABCDEF, x61^0x01234567);
     208
     209#define feedforward \
     210      xor64(a0, a1, aa0, aa1); \
     211      sub64(b0, b1, bb0, bb1); \
     212      add64(c0, c1, cc0, cc1);
     213
     214#define compress \
     215      pass5(a0,a1,b0,b1,c0,c1); \
     216      key_schedule; \
     217      pass7(c0,c1,a0,a1,b0,b1); \
     218      key_schedule; \
     219      pass9(b0,b1,c0,c1,a0,a1); \
     220      feedforward
    193221
    194222#define tiger_compress_macro(str, state) \
    195223{ \
    196   register sh_word32 a0, a1, b0, b1, c0, c1, tmpa; \
     224  register sh_word32 a0, a1, b0, b1, c0, c1; \
    197225  sh_word32 aa0, aa1, bb0, bb1, cc0, cc1; \
    198226  sh_word32 x00, x01, x10, x11, x20, x21, x30, x31, \
    199          x40, x41, x50, x51, x60, x61, x70, x71; \
    200   register sh_word32 temp0, temp1, tempt0, tempt1, temps0, tcarry; \
    201   int pass_no; \
     227                  x40, x41, x50, x51, x60, x61, x70, x71; \
     228  sh_word32 temp0, temp1, tempt0, tempt1, temps0, tcarry; \
    202229\
    203230  a0 = state[0]; \
     
    208235  c1 = state[5]; \
    209236\
     237      save_abc \
     238\
    210239  x00=str[0*2]; x01=str[0*2+1]; x10=str[1*2]; x11=str[1*2+1]; \
    211240  x20=str[2*2]; x21=str[2*2+1]; x30=str[3*2]; x31=str[3*2+1]; \
     
    213242  x60=str[6*2]; x61=str[6*2+1]; x70=str[7*2]; x71=str[7*2+1]; \
    214243\
    215   sh_compress; \
     244  compress; \
    216245\
    217246  state[0] = a0; \
     
    223252}
    224253
    225 #ifdef UNROLL_COMPRESS
     254#if defined(UNROLL_COMPRESS)
    226255/* The compress function is inlined */
    227256#define tiger_compress(str, state) \
    228257  tiger_compress_macro(((sh_word32*)str), ((sh_word32*)state))
    229 #else
    230 /* The compress function is a function */
     258
     259#else
     260
    231261void
    232262tiger_compress(sh_word32 *str, sh_word32 state[6])
     
    249279#ifdef BIG_ENDIAN
    250280      for(j=0; j<64; j++)
    251         temp[j^3] = ((sh_byte*)str)[j];
    252       tiger_compress(((sh_word32*)temp), res);
    253 #else
    254       tiger_compress(str, res);
     281        temp[j^3] = ((sh_byte*)str)[j];
     282      tiger_compress_macro(((sh_word32*)temp), res);
     283#else
     284      tiger_compress_macro(str, res);
    255285#endif
    256286      str += 16;
     
    258288}
    259289
    260 void
    261 tiger(sh_word32 *str, sh_word32 length, sh_word32 res[6])
     290
     291void tiger(sh_word32 *str, sh_word32 length, sh_word32 res[6])
    262292{
    263293  register sh_word32 i, j;
    264294  sh_byte temp[64];
     295
     296  /*
     297   * res[0]=0x89ABCDEF;
     298   * res[1]=0x01234567;
     299   * res[2]=0x76543210;
     300   * res[3]=0xFEDCBA98;
     301   * res[4]=0xC3B2E187;
     302   * res[5]=0xF096A5B4;
     303   */
    265304
    266305  for(i=length; i>=64; i-=64)
     
    307346}
    308347
    309 #else
    310 void dummy_1 (int a)
    311 {
    312   (void) a;
    313   return;
    314 }
    315 #endif
    316 
    317 
    318 
    319 
    320 
    321 
    322 
    323 
    324 
     348#endif
     349
  • trunk/src/sh_tiger1_64.c

    r1 r18  
    55#include "config_xor.h"
    66
    7 #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64)
    8 
    9 /*@-incondefs -macroparens -macroassign -macroparams -macrostmt @*/
    10 /*@-fixedformalarray +charindex -type -paramuse -predboolint -exportlocal@*/
     7#if defined(TIGER_64_BIT)
     8
     9/* #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64) */
     10
     11#undef USE_MEMSET
     12
    1113/* Big endian:                                         */
    1214#ifdef WORDS_BIGENDIAN
    1315#define BIG_ENDIAN
    1416#endif
    15 
    1617
    1718/* Tiger: A Fast New Hash Function
     
    3839#if defined(HAVE_LONG_64)
    3940typedef unsigned long int word64;
    40 #else
     41#elif defined(HAVE_LONG_LONG_64)
    4142typedef unsigned long long int word64;
     43#else
     44#error No 64 bit type found !
    4245#endif
    4346
     
    4952typedef unsigned short sh_word32;
    5053#else
    51 #error No 32 byte type found !
     54#error No 32 bit type found !
    5255#endif
    5356
    5457typedef unsigned char sh_byte;
    5558
    56 /* Big endian:                                         
    57    #if !(defined(__alpha)||defined(__i386__)||defined(__vax__))
    58    #define BIG_ENDIAN
    59    #endif
    60 */
    61 
    62 /* The following macro denotes that an optimization    */
    63 /* for Alpha is required. It is used only for          */
    64 /* optimization of time. Otherwise it does nothing.    */
    65 #ifdef __alpha
    66 #define OPTIMIZE_FOR_ALPHA
    67 #endif
    68 
    69 /* NOTE that this code is NOT FULLY OPTIMIZED for any  */
    70 /* machine. Assembly code might be much faster on some */
    71 /* machines, especially if the code is compiled with   */
    72 /* gcc.                                                */
    73 
    74 /* The number of passes of the hash function.          */
    75 /* Three passes are recommended.                       */
    76 /* Use four passes when you need extra security.       */
    77 /* Must be at least three.                             */
     59#if defined(TIGER_OPT_ASM)
     60#define TIGER_ASM64_2 1
     61#else
     62#define TIGER_C 1
     63#endif
     64
     65/* The number of passes of the hash function.              */
     66/* Three passes are recommended.                           */
     67/* Use four passes when you need extra security.           */
     68/* Must be at least three.                                 */
    7869#define PASSES 3
    7970
    8071extern word64 tiger_table[4*256];
     72
     73/* Volatile can help if compiler is smart enough to use memory operand */
     74static /*volatile*/ const word64 XOR_CONST1=0xA5A5A5A5A5A5A5A5LL;
     75static /*volatile*/ const word64 XOR_CONST2=0x0123456789ABCDEFLL;
    8176
    8277#define t1 (tiger_table)
     
    8580#define t4 (tiger_table+256*3)
    8681
     82#define pass_start
     83#define pass_end
     84
     85
     86
    8787#define save_abc \
    88       aa = a; \
    89       bb = b; \
    90       cc = c;
    91 
    92 #ifdef OPTIMIZE_FOR_ALPHA
    93 /* This is the official definition of round */
    94 #define round(a,b,c,x,mul) \
    95       c ^= x; \
    96       a -= t1[((c)>>(0*8))&0xFF] ^ t2[((c)>>(2*8))&0xFF] ^ \
    97            t3[((c)>>(4*8))&0xFF] ^ t4[((c)>>(6*8))&0xFF] ; \
    98       b += t4[((c)>>(1*8))&0xFF] ^ t3[((c)>>(3*8))&0xFF] ^ \
    99            t2[((c)>>(5*8))&0xFF] ^ t1[((c)>>(7*8))&0xFF] ; \
    100       b *= mul;
    101 #else
    102 /* This code works faster when compiled on 32-bit machines */
    103 /* (but works slower on Alpha) */
    104 #define round(a,b,c,x,mul) \
    105       c ^= x; \
    106       a -= t1[(sh_byte)(c)] ^ \
    107            t2[(sh_byte)(((sh_word32)(c))>>(2*8))] ^ \
    108            t3[(sh_byte)((c)>>(4*8))] ^ \
    109            t4[(sh_byte)(((sh_word32)((c)>>(4*8)))>>(2*8))] ; \
    110       b += t4[(sh_byte)(((sh_word32)(c))>>(1*8))] ^ \
    111            t3[(sh_byte)(((sh_word32)(c))>>(3*8))] ^ \
    112            t2[(sh_byte)(((sh_word32)((c)>>(4*8)))>>(1*8))] ^ \
    113            t1[(sh_byte)(((sh_word32)((c)>>(4*8)))>>(3*8))]; \
    114       b *= mul;
    115 #endif
    116 
    117 #define pass(a,b,c,mul) \
    118       round(a,b,c,x0,mul) \
    119       round(b,c,a,x1,mul) \
    120       round(c,a,b,x2,mul) \
    121       round(a,b,c,x3,mul) \
    122       round(b,c,a,x4,mul) \
    123       round(c,a,b,x5,mul) \
    124       round(a,b,c,x6,mul) \
    125       round(b,c,a,x7,mul)
     88          aa = a; \
     89          bb = b; \
     90          cc = c;
     91
     92#ifdef TIGER_C
     93
     94#define BN(x,n) (((x)>>((n)*8))&0xFF)
     95
     96
     97/* Depending on outer code one of these two can be better*/
     98#define roundX(a,b,c,x) \
     99        c ^= x; \
     100        a -= t1[BN(c,0)] ^ t2[BN(c,2)] ^ \
     101             t3[BN(c,4)] ^ t4[BN(c,6)] ; \
     102        b += t4[BN(c,1)] ^ t3[BN(c,3)] ^ \
     103             t2[BN(c,5)] ^ t1[BN(c,7)] ;
     104
     105#define round5(a,b,c,x) roundX(a,b,c,x) b = b+b*4;
     106#define round7(a,b,c,x) roundX(a,b,c,x) b = b*8-b;
     107#define round9(a,b,c,x) roundX(a,b,c,x) b = b+b*8;
     108
     109#endif
     110
     111
     112#ifdef TIGER_OPT_ASM
     113
     114#define MASK0           0xFFL
     115#define MASK8           0xFF00L
     116#define MASK16          0xFF0000L
     117#define MASK32          0xFF00000000LL
     118#define MASK40          0xFF0000000000LL
     119#define MASK48          0xFF000000000000LL
     120
     121#define roundstart      __asm__ (
     122
     123/* a will be moved into different reg each round
     124 * using register substitution feature of  GCC asm
     125 * b will be moved in 2-nd pass rounds only
     126 */
     127
     128
     129#define roundend(a,b,c,x) \
     130 : "+r" (a), "+r" (b), "+r" (c) \
     131 : "0" (a), "1" (b), "2" (c), "m" (x), "r" (&tiger_table),\
     132  "i" (MASK0), "i" (MASK8), "i" (MASK16), "r" (MASK32), "r" (MASK40), "r" (MASK48) \
     133 : "3", "%rax","%rbx","%rcx","%rdx","%rsi", "%edi", "%r8"  );
     134
     135
     136/*      c ^= x;
     137        a -= t1[BN(c,0)] ^ t2[BN(c,2)] ^
     138        t3[BN(c,4)] ^ t4[BN(c,6)] ;
     139        b += t4[BN(c,1)] ^ t3[BN(c,3)] ^
     140        t2[BN(c,5)] ^ t1[BN(c,7)] ;     */
     141
     142#define roundX(a,b,c,x)   \
     143"       movl    %10, %%ebx      \n"\
     144"       movq    %11, %%rcx      \n"\
     145"       movq    %13, %%rdx      \n"\
     146"       movq    %6, %%r8  \n"\
     147"       xorq    %%r8, %2                 \n" \
     148"       andq    %2, %%rbx  \n"\
     149"       andq    %2, %%rcx  \n"\
     150"       andq    %2, %%rdx  \n"\
     151"       shrl    $(16-3), %%ebx  \n"\
     152"       shrq    $(32-3), %%rcx  \n"\
     153"       shrq    $(48-3), %%rdx  \n"\
     154"       movzbl  %2b, %%eax      \n"\
     155"       movzwl  %2w, %%edi      \n"\
     156"       movq    (%7,%%rax,8), %%rsi  \n"\
     157"       shrl    $(8), %%edi  \n" \
     158"       movq    %2, %%rax  \n" \
     159"       xorq    (2048*1)(%7,%%rbx), %%rsi  \n"\
     160"       movq    %2, %%rbx  \n"\
     161"       shrl    $24, %%eax \n"\
     162"       andq    %12, %%rbx      \n"\
     163"       xorq    (2048*2)(%7,%%rcx), %%rsi  \n"\
     164"       shrq    $(40-3), %%rbx \n"\
     165"       movq    %2, %%rcx  \n"\
     166"       xorq    (2048*3)(%7,%%rdx), %%rsi  \n"\
     167"       movq    (2048*3)(%7,%%rdi,8), %%rdx  \n"\
     168"       shrq    $56, %%rcx \n"\
     169"       xorq    (2048*2)(%7,%%rax,8), %%rdx  \n"\
     170"       xorq    (2048*1)(%7,%%rbx), %%rdx  \n" \
     171"       subq     %%rsi, %0 \n"\
     172"       xorq    (%7,%%rcx,8), %%rdx  \n"\
     173"       addq     %%rdx, %1 \n"
     174
     175#define round5(a,b,c,x) \
     176        roundstart \
     177        roundX(a,b,c,x) \
     178        /* b*=5; */ \
     179        "leaq   (%1,%1,4), %1\n" \
     180        roundend(a,b,c,x)
     181
     182
     183#define round7(a,b,c,x) \
     184        roundstart \
     185        roundX(a,b,c,x) \
     186        roundend(a,b,c,x) \
     187        /* b*=7; */ \
     188        __asm__ ( \
     189        "leaq   (%1,%1,8), %0\n" \
     190        "addq  %1, %1 \n" \
     191        "subq  %1, %0 " \
     192        :"=&r" (b): "r"(b): "1" );
     193
     194#define round9(a,b,c,x) \
     195        roundstart \
     196        roundX(a,b,c,x) \
     197        "leaq   (%1,%1,8), %1\n" \
     198        roundend(a,b,c,x)
     199
     200#endif
     201
     202
     203
     204
     205/* ============== Common macros ================== */
    126206
    127207#define key_schedule \
    128       x0 -= x7 ^ 0xA5A5A5A5A5A5A5A5LL; \
    129       x1 ^= x0; \
    130       x2 += x1; \
    131       x3 -= x2 ^ ((~x1)<<19); \
    132       x4 ^= x3; \
    133       x5 += x4; \
    134       x6 -= x5 ^ ((~x4)>>23); \
    135       x7 ^= x6; \
    136       x0 += x7; \
    137       x1 -= x0 ^ ((~x7)<<19); \
    138       x2 ^= x1; \
    139       x3 += x2; \
    140       x4 -= x3 ^ ((~x2)>>23); \
    141       x5 ^= x4; \
    142       x6 += x5; \
    143       x7 -= x6 ^ 0x0123456789ABCDEFLL;
     208        x0 -= x7 ^ XOR_CONST1; \
     209        x1 ^= x0; \
     210        x2 += x1;\
     211        x3 -= x2 ^ ((~x1)<<19);\
     212        x4 ^= x3;\
     213        x5 += x4;\
     214        x6 -= x5 ^ ((~x4)>>23); \
     215        x7 ^= x6; \
     216        x0 += x7; \
     217        x1 -= x0 ^ ((~x7)<<19); \
     218        x2 ^= x1; \
     219        x3 += x2; \
     220        x4 -= x3 ^ ((~x2)>>23); \
     221        x5 ^= x4; \
     222        x6 += x5; \
     223        x7 -= x6 ^ XOR_CONST2;
     224
     225#define pass5n(a,b,c) \
     226          round5(a,b,c,x0) \
     227        x0 -= x7 ^ XOR_CONST1; \
     228          round5(b,c,a,x1) \
     229        x1 ^= x0; \
     230          round5(c,a,b,x2) \
     231        x2 += x1; \
     232          round5(a,b,c,x3) \
     233        x3 -= x2 ^ ((~x1)<<19); \
     234          round5(b,c,a,x4) \
     235        x4 ^= x3; \
     236          round5(c,a,b,x5) \
     237        x5 += x4; \
     238          round5(a,b,c,x6) \
     239        x6 -= x5 ^ ((~x4)>>23); \
     240          round5(b,c,a,x7) \
     241        x7 ^= x6; \
     242        x0 += x7; \
     243        x1 -= x0 ^ ((~x7)<<19); \
     244        x2 ^= x1; \
     245        x3 += x2; \
     246        x4 -= x3 ^ ((~x2)>>23); \
     247        x5 ^= x4; \
     248        x6 += x5; \
     249        x7 -= x6 ^ XOR_CONST2;
     250
     251#define pass7n(a,b,c) \
     252          round7(a,b,c,x0) \
     253        x0 -= x7 ^ XOR_CONST1; \
     254          round7(b,c,a,x1) \
     255        x1 ^= x0; \
     256          round7(c,a,b,x2) \
     257        x2 += x1; \
     258          round7(a,b,c,x3) \
     259        x3 -= x2 ^ ((~x1)<<19); \
     260          round7(b,c,a,x4) \
     261        x4 ^= x3; \
     262          round7(c,a,b,x5) \
     263        x5 += x4; \
     264          round7(a,b,c,x6) \
     265        x6 -= x5 ^ ((~x4)>>23); \
     266          round7(b,c,a,x7) \
     267        x7 ^= x6; \
     268        x0 += x7; \
     269        x1 -= x0 ^ ((~x7)<<19); \
     270        x2 ^= x1; \
     271        x3 += x2; \
     272        x4 -= x3 ^ ((~x2)>>23); \
     273        x5 ^= x4; \
     274        x6 += x5; \
     275        x7 -= x6 ^ XOR_CONST2;
     276
     277#define pass5(a,b,c) \
     278        pass_start \
     279          round5(a,b,c,x0) \
     280          round5(b,c,a,x1) \
     281          round5(c,a,b,x2) \
     282          round5(a,b,c,x3) \
     283          round5(b,c,a,x4) \
     284          round5(c,a,b,x5) \
     285          round5(a,b,c,x6) \
     286          round5(b,c,a,x7) \
     287        pass_end
     288
     289#define pass7(a,b,c) \
     290        pass_start \
     291          round7(a,b,c,x0) \
     292          round7(b,c,a,x1) \
     293          round7(c,a,b,x2) \
     294          round7(a,b,c,x3) \
     295          round7(b,c,a,x4) \
     296          round7(c,a,b,x5) \
     297          round7(a,b,c,x6) \
     298          round7(b,c,a,x7) \
     299        pass_end
     300
     301
     302#define pass9(a,b,c) \
     303        pass_start \
     304          round9(a,b,c,x0) \
     305          round9(b,c,a,x1) \
     306          round9(c,a,b,x2) \
     307          round9(a,b,c,x3) \
     308          round9(b,c,a,x4) \
     309          round9(c,a,b,x5) \
     310          round9(a,b,c,x6) \
     311          round9(b,c,a,x7) \
     312        pass_end
    144313
    145314#define feedforward \
    146       a ^= aa; \
    147       b -= bb; \
    148       c += cc;
    149 
    150 #ifdef OPTIMIZE_FOR_ALPHA
    151 /* The loop is unrolled: works better on Alpha */
     315          a ^= aa; \
     316          b -= bb; \
     317          c += cc;
     318
     319
     320/* This version works ok with C variant and also with new asm version
     321 * that just wastes a register r8
     322 * reason? who knows, write forwarding is faster than keeping value
     323 * in register? :)
     324 */
    152325#define compress \
    153       save_abc \
    154       pass(a,b,c,5) \
    155       key_schedule \
    156       pass(c,a,b,7) \
    157       key_schedule \
    158       pass(b,c,a,9) \
    159       for(pass_no=3; pass_no<PASSES; pass_no++) { \
    160         key_schedule \
    161         pass(a,b,c,9) \
    162         tmpa=a; a=c; c=b; b=tmpa;} \
    163       feedforward
    164 #else
    165 /* loop: works better on PC and Sun (smaller cache?) */
    166 #define compress \
    167       save_abc \
    168       for(pass_no=0; pass_no<PASSES; pass_no++) { \
    169         if(pass_no != 0) {key_schedule} \
    170         pass(a,b,c,(pass_no==0?5:pass_no==1?7:9)); \
    171         tmpa=a; a=c; c=b; b=tmpa;} \
    172       feedforward
    173 #endif
     326        save_abc \
     327          pass5n(a,b,c) \
     328          pass7n(c,a,b) \
     329          pass9(b,c,a) \
     330          for(pass_no=3; pass_no<PASSES; pass_no++) { \
     331                key_schedule \
     332                pass9(a,b,c) \
     333                tmpa=a; a=c; c=b; b=tmpa; \
     334          } \
     335        feedforward
     336
     337#define compress_old \
     338        save_abc \
     339          pass5(a,b,c) \
     340          key_schedule \
     341          pass7(c,a,b) \
     342          key_schedule \
     343          pass9(b,c,a) \
     344          for(pass_no=3; pass_no<PASSES; pass_no++) { \
     345                key_schedule \
     346                pass9(a,b,c) \
     347                tmpa=a; a=c; c=b; b=tmpa; \
     348          } \
     349        feedforward
    174350
    175351#define tiger_compress_macro(str, state) \
    176352{ \
    177   register word64 a, b, c, tmpa; \
     353  register word64 a, b, c; \
     354  register word64 tmpa; \
    178355  word64 aa, bb, cc; \
    179   register word64 x0, x1, x2, x3, x4, x5, x6, x7; \
     356  word64 x0, x1, x2, x3, x4, x5, x6, x7; \
    180357  int pass_no; \
    181358\
     
    194371}
    195372
    196 /* The compress function is a function. Requires smaller cache?    */
    197373void tiger_compress(word64 *str, word64 state[3])
    198374{
    199 #ifndef S_SPLINT_S
    200375  tiger_compress_macro(((word64*)str), ((word64*)state));
    201 #endif
    202376}
    203 
    204 #ifdef OPTIMIZE_FOR_ALPHA
    205 /* The compress function is inlined: works better on Alpha.        */
    206 /* Still leaves the function above in the code, in case some other */
    207 /* module calls it directly.                                       */
    208 #define tiger_compress(str, state) \
    209   tiger_compress_macro(((word64*)str), ((word64*)state))
    210 #endif
    211377
    212378void tiger_t(word64 *str, word64 length, word64 res[3])
     
    220386
    221387  /*
    222     res[0]=0x0123456789ABCDEFLL;
    223     res[1]=0xFEDCBA9876543210LL;
    224     res[2]=0xF096A5B4C3B2E187LL;
    225   */
     388   * res[0]=0x0123456789ABCDEFLL;
     389   * res[1]=0xFEDCBA9876543210LL;
     390   * res[2]=0xF096A5B4C3B2E187LL;
     391   */
    226392
    227393  for(i=length; i>=64; i-=64)
     
    229395#ifdef BIG_ENDIAN
    230396      for(j=0; j<64; j++)
    231         temp[j^7] = ((sh_byte*)str)[j];
     397        temp[j^7] = ((sh_byte*)str)[j];
    232398      tiger_compress(((word64*)temp), res);
    233399#else
     
    236402      str += 8;
    237403    }
    238 
    239404}
    240405
     
    246411
    247412  /*
    248     res[0]=0x0123456789ABCDEFLL;
    249     res[1]=0xFEDCBA9876543210LL;
    250     res[2]=0xF096A5B4C3B2E187LL;
    251   */
     413   * res[0]=0x0123456789ABCDEFLL;
     414   * res[1]=0xFEDCBA9876543210LL;
     415   * res[2]=0xF096A5B4C3B2E187LL;
     416   */
    252417
    253418  for(i=length; i>=64; i-=64)
     
    255420#ifdef BIG_ENDIAN
    256421      for(j=0; j<64; j++)
    257         temp[j^7] = ((sh_byte*)str)[j];
     422        temp[j^7] = ((sh_byte*)str)[j];
    258423      tiger_compress(((word64*)temp), res);
    259424#else
     
    272437    temp[j^7] = 0;
    273438#else
     439
     440#ifndef USE_MEMSET
    274441  for(j=0; j<i; j++)
    275442    temp[j] = ((sh_byte*)str)[j];
    276 
     443#else
     444  memcpy( temp, str, j=i );
     445#endif
    277446  temp[j++] = 0x01;
    278447  for(; j&7; j++)
    279     temp[j] = 0;
    280 #endif
     448        temp[j] = 0;
     449
     450#endif
     451
    281452  if(j>56)
    282453    {
     454#ifndef USE_MEMSET
    283455      for(; j<64; j++)
    284456        temp[j] = 0;
     457#else
     458      memset( temp+j, 0, 64-j);
     459#endif
    285460      tiger_compress(((word64*)temp), res);
    286461      j=0;
    287462    }
    288463
     464#ifndef USE_MEMSET
    289465  for(; j<56; j++)
    290466    temp[j] = 0;
     467#else
     468  memset( temp+j, 0, 56-j);
     469#endif
     470
    291471  ((word64*)(&(temp[56])))[0] = ((word64)length)<<3;
    292472  tiger_compress(((word64*)temp), res);
    293473}
    294474
    295 #else
    296 
    297 void dummy_1_64 (int a)
    298 {
    299   (void) a;
    300   return;
    301 }
    302 
    303 #endif
    304 
    305 
    306 
    307 
    308 
    309 
    310 
    311 
    312 
     475#endif
  • trunk/src/sh_tiger2.c

    r1 r18  
    2323
    2424
    25 #if !defined(HAVE_LONG_64) && !defined(HAVE_LONG_LONG_64)
    26 
     25#if !defined(TIGER_64_BIT)
     26
     27/* #if !defined(HAVE_LONG_64) && !defined(HAVE_LONG_LONG_64) */
    2728
    2829/* sboxes32.c: Tiger S boxes for 32-bit-only compilers */
    29 typedef unsigned long word32;
    30 word32 tiger_table[4*256][2] = {
     30#if defined(HAVE_INT_32)
     31typedef unsigned int sh_word32;
     32#elif defined(HAVE_LONG_32)
     33typedef unsigned long sh_word32;
     34#elif defined(HAVE_SHORT_32)
     35typedef unsigned short sh_word32;
     36#else
     37#error No 32 bit type found !
     38#endif
     39
     40sh_word32 tiger_table[4*256][2] = {
    3141  { 0xF7E90C5E, 0x02AAB17C /*    0 */},  {  0xE243A8EC, 0xAC424B03 /*    1 */},
    3242  { 0x0DD5FCD3, 0x72CD5BE3 /*    2 */},  {  0xF6F97F3A, 0x6D019B93 /*    3 */},
  • trunk/src/sh_tiger2_64.c

    r1 r18  
    2222#include "config_xor.h"
    2323
    24 
    25 #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64)
     24#if defined(TIGER_64_BIT)
     25
     26/* #if defined(HAVE_LONG_64) || defined(HAVE_LONG_LONG_64) */
    2627
    2728/*@-type@*/
     
    3031#if defined(HAVE_LONG_64)
    3132typedef unsigned long int word64;
     33#elif defined(HAVE_LONG_LONG_64)
     34typedef unsigned long long int word64;
    3235#else
    33 typedef unsigned long long int word64;
     36#error No 64 bit type found !
    3437#endif
    3538
  • trunk/src/sh_tools.c

    r12 r18  
    125125char * sh_tools_safe_name (const char * instr, int flag)
    126126{
    127   unsigned char c;
     127  unsigned char c, d;
    128128  const  char * p;
    129129  char   *q;
     
    133133  int    i = 0;
    134134  unsigned char   val_octal = '\0';
     135  static char ctable[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
     136                             '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
    135137
    136138  SL_ENTER(_("sh_tools_safe_name"));
     
    202204            {
    203205              --i;
    204               sprintf(&outstr[i], "=%02x", c);          /* known to fit  */
     206              d = c % 16; c = c / 16;
     207              outstr[i] = '=';       ++i;
     208              outstr[i] = ctable[c]; ++i;
     209              outstr[i] = ctable[d]; ++i;
    205210            }
    206211
     
    274279            break;
    275280          default:
    276             if (strlen(p) < 3)
     281            if (strlen(p) < 3) /* certainly not an octal number, skip */
    277282              {
    278283                p += strlen(p);
     
    284289                if (val_octal != '\0') {
    285290                  c = val_octal;
    286                   sprintf(&outstr[i], "=%02x", c);       /* known to fit  */
    287                   i+=3;
     291                  d = c % 16; c = c / 16;
     292                  outstr[i] = '=';       ++i;
     293                  outstr[i] = ctable[c]; ++i;
     294                  outstr[i] = ctable[d]; ++i;
    288295                }
    289296                p += 3;
     
    294301        {
    295302          ++p;
    296           if (!p || !(*p))
    297             break;
     303          if (!p || !(*p))
     304            {
     305              outstr[i] = '&'; ++i;
     306              break;
     307            }
    298308
    299309          if (p[0] == 'a' && p[1] == 'm' && p[2] == 'p' && p[3] == ';')
  • trunk/src/sh_unix.c

    r10 r18  
    12831283     */
    12841284    if (0 == sl_strncmp((*env), _("MYSQL_UNIX_PORT="), 16))
     1285      {
     1286        ++(env);
     1287        continue;
     1288      }
     1289    if (0 == sl_strncmp((*env), _("MYSQL_TCP_PORT="), 15))
     1290      {
     1291        ++(env);
     1292        continue;
     1293      }
     1294    if (0 == sl_strncmp((*env), _("MYSQL_HOME="), 11))
    12851295      {
    12861296        ++(env);
Note: See TracChangeset for help on using the changeset viewer.