thig_debug.h

Go to the documentation of this file.
00001  
00008 #ifdef DEBUG    /* keep these macros common so they are same for both versions */
00009 CONST int debugCompile  =   1;
00010 extern  int debug;
00011 extern  void DebugIO(CONST char *s);    
00013 #define DebugDump(x,s,R,XOR,doRot,showT,needBswap)  \
00014     { if (debug) _Dump(x,s,R,XOR,doRot,showT,needBswap,t0,t1); }
00015 #define DebugDumpKey(key) { if (debug) _DumpKey(key); }
00016 #define IV_ROUND    -100
00017     
00018 void _Dump(CONST void *p,CONST char *s,int R,int XOR,int doRot,int showT,int needBswap,
00019            DWORD t0,DWORD t1)
00020     {
00021     char line[512]; /* build output here */
00022     int  i,n;
00023     DWORD q[4];
00024 
00025     if (R == IV_ROUND)
00026         sprintf(line,"%sIV:    ",s);
00027     else
00028         sprintf(line,"%sR[%2d]: ",s,R);
00029     for (n=0;line[n];n++) ;
00030     
00031     for (i=0;i<4;i++)
00032         {
00033         q[i]=((CONST DWORD *)p)[i^(XOR)];
00034         if (needBswap) q[i]=Bswap(q[i]);
00035         }
00036 
00037     sprintf(line+n,"x= %08lX  %08lX  %08lX  %08lX.",
00038             ROR(q[0],doRot*(R  )/2),
00039             ROL(q[1],doRot*(R  )/2),
00040             ROR(q[2],doRot*(R+1)/2),
00041             ROL(q[3],doRot*(R+1)/2));
00042     for (;line[n];n++) ;
00043 
00044     if (showT)
00045         sprintf(line+n,"    t0=%08lX. t1=%08lX.",t0,t1);
00046     for (;line[n];n++) ;
00047 
00048     sprintf(line+n,"\n");
00049     DebugIO(line);
00050     }
00051 
00052 void _DumpKey(CONST keyInstance *key)
00053     {
00054     char    line[512];
00055     int     i;
00056     int     k64Cnt=(key->keyLen+63)/64; /* round up to next multiple of 64 bits */
00057     int     subkeyCnt = ROUND_SUBKEYS + 2*key->numRounds;
00058 
00059     sprintf(line,";\n;makeKey:   Input key            -->  S-box key     [%s]\n",
00060            (key->direction == DIR_ENCRYPT) ? "Encrypt" : "Decrypt");
00061     DebugIO(line);
00062     for (i=0;i<k64Cnt;i++)  /* display in RS format */
00063         {
00064         sprintf(line,";%12s %08lX %08lX  -->  %08lX\n","",
00065                key->key32[2*i+1],key->key32[2*i],key->sboxKeys[k64Cnt-1-i]);
00066         DebugIO(line);
00067         }
00068     sprintf(line,";%11sSubkeys\n","");
00069     DebugIO(line);
00070     for (i=0;i<subkeyCnt/2;i++)
00071         {
00072         sprintf(line,";%12s %08lX %08lX%s\n","",key->subKeys[2*i],key->subKeys[2*i+1],
00073               (2*i ==  INPUT_WHITEN) ? "   Input whiten" :
00074               (2*i == OUTPUT_WHITEN) ? "  Output whiten" :
00075               (2*i == ROUND_SUBKEYS) ? "  Round subkeys" : "");
00076         DebugIO(line);
00077         }
00078     DebugIO(";\n");
00079     }
00080 #else
00081 CONST int debugCompile  =   0;
00082 #define DebugDump(x,s,R,XOR,doRot,showT,needBswap)
00083 #define DebugDumpKey(key)
00084 #endif

Generated on Thu Oct 23 04:14:38 2008 for Open IMS Core CSCFs by  doxygen 1.5.2