home *** CD-ROM | disk | FTP | other *** search
/ CD-X 1 / cdx_01.iso / shareuti / secdev13 / source / md5_86.asm < prev    next >
Encoding:
Assembly Source File  |  1994-02-27  |  29.7 KB  |  686 lines

  1. IDEAL
  2. MODEL       TINY,C
  3.  
  4. ; ***********************************************************************
  5. ; ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.  **
  6. ; **                                                                   **
  7. ; ** License to copy and use this software is granted provided that    **
  8. ; ** it is identified as the "RSA Data Security, Inc. MD5 Message-     **
  9. ; ** Digest Algorithm" in all material mentioning or referencing this  **
  10. ; ** software or this function.                                        **
  11. ; **                                                                   **
  12. ; ** License is also granted to make and use derivative works          **
  13. ; ** provided that such works are identified as "derived from the RSA  **
  14. ; ** Data Security, Inc. MD5 Message-Digest Algorithm" in all          **
  15. ; ** material mentioning or referencing the derived work.              **
  16. ; **                                                                   **
  17. ; ** RSA Data Security, Inc. makes no representations concerning       **
  18. ; ** either the merchantability of this software or the suitability    **
  19. ; ** of this software for any particular purpose.  It is provided "as  **
  20. ; ** is" without express or implied warranty of any kind.              **
  21. ; **                                                                   **
  22. ; ** These notices must be retained in any copies of any part of this  **
  23. ; ** documentation and/or software.                                    **
  24. ; ***********************************************************************
  25.  
  26. PUBLIC      MD5Init,MD5Update,MD5Final
  27.  
  28. STRUC       MD5_CTX
  29.             ; typedef struct {
  30.             ;   UINT4 buf[4];                                    /* scratch buffer */
  31.             ;   UINT4 i[2];                   /* number of _bits_ handled mod 2^64 */
  32.             ;   unsigned char inn[64];                              /* input buffer */
  33.             ; } MD5_CTX;
  34.             buf         DD          4 DUP (?)
  35.             i           DW          4 DUP (?)
  36.             inn         DB          64 DUP (?)
  37. ENDS        MD5_CTX
  38.  
  39. CODESEG
  40.  
  41.             Padding DB      128, 63 DUP (0)
  42.  
  43. PROC        MD5Init
  44.             ; void MD5Init ( MD5_CTX far *mdContext)
  45.             ARG         mdContext:DWORD
  46.  
  47.                         PUSH        ES BX
  48.  
  49.                         LES         BX,[mdContext]
  50.             ; { mdContext->i[0] = mdContext->i[1] = (UINT4)0;
  51.  
  52.                         MOV         [WORD PTR (MD5_CTX PTR ES:BX).i],0
  53.                         MOV         [WORD PTR (MD5_CTX PTR ES:BX+2).i],0
  54.                         MOV         [WORD PTR (MD5_CTX PTR ES:BX+4).i],0
  55.                         MOV         [WORD PTR (MD5_CTX PTR ES:BX+6).i],0
  56.             ;   /* Load magic initialization constants.
  57.             ;    */
  58.             ;   mdContext->buf[0] = (UINT4)0x67452301L;
  59.                         MOV         [WORD PTR (MD5_CTX PTR ES:BX).Buf],2301h
  60.                         MOV         [WORD PTR (MD5_CTX PTR ES:BX+2).Buf],6745h
  61.             ;   mdContext->buf[1] = (UINT4)0xefcdab89L;
  62.                         MOV         [WORD PTR (MD5_CTX PTR ES:BX+4).Buf],0AB89h
  63.                         MOV         [WORD PTR (MD5_CTX PTR ES:BX+6).Buf],0EFCDh
  64.             ;   mdContext->buf[2] = (UINT4)0x98badcfeL;
  65.                         MOV         [WORD PTR (MD5_CTX PTR ES:BX+8).Buf],0DCFEh
  66.                         MOV         [WORD PTR (MD5_CTX PTR ES:BX+0Ah).Buf],98BAh
  67.             ;   mdContext->buf[3] = (UINT4)0x10325476L;
  68.                         MOV         [WORD PTR (MD5_CTX PTR ES:BX+0Ch).Buf],5476h
  69.                         MOV         [WORD PTR (MD5_CTX PTR ES:BX+0Eh).Buf],1032h
  70.             ; }
  71.                         POP         BX ES
  72.                         RET
  73. ENDP        MD5Init
  74.  
  75. PROC        MD5Update
  76.             ASSUME      DS:NOTHING
  77.             ; void MD5Update (MD5_CTX far *mdContext, unsigned char far *inBuf,unsigned int inLen)
  78.             ARG         mdContext:DWORD,inBuf:DWORD,inLen:WORD
  79.  
  80.             ; { register int i, ii;
  81.             ;   int mdi;
  82.             ;   UINT4 inn[16];
  83.  
  84.             ; BX = mdi
  85.  
  86.             ;   /* compute number of bytes mod 64 */
  87.             ;   mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
  88.                         PUSH        ES DS SI DI AX BX CX DX
  89.  
  90.                         LES         DI,[mdContext]
  91.  
  92.                         MOV         BX,[WORD PTR (MD5_CTX PTR ES:DI).i]
  93.                         SHR         BX,1
  94.                         SHR         BX,1
  95.                         SHR         BX,1
  96.                         AND         BX,3Fh
  97.  
  98.             ;   /* update number of bits */
  99.             ;   if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0]) mdContext->i[1]++;
  100.             ;   mdContext->i[0] += ((UINT4)inLen << 3);
  101.             ;   mdContext->i[1] += ((UINT4)inLen >> 29);                ?? always 0
  102.                         MOV         AX,[inLen]
  103.                         MOV         CX,0
  104.                         SHL         AX,1
  105.                         RCL         CX,1
  106.                         SHL         AX,1
  107.                         RCL         CX,1
  108.                         SHL         AX,1
  109.                         RCL         CX,1
  110.                         ADD         [WORD PTR (MD5_CTX PTR ES:DI).i],AX
  111.                         ADC         [WORD PTR (MD5_CTX PTR ES:DI+2).i],CX
  112.                         ADC         [WORD PTR (MD5_CTX PTR ES:DI+4).i],0
  113.                         ADC         [WORD PTR (MD5_CTX PTR ES:DI+6).i],0
  114.  
  115.             ;   while (inLen--) {
  116.                         MOV         CX,[InLen]
  117.                         JCXZ        @@Finished
  118.  
  119.             ;     /* add new character to buffer, increment mdi */
  120.             ;     mdContext->inn[mdi++] = *inBuf++;
  121.                         LDS         SI,[inBuf]
  122.                         CLD
  123.  
  124.             @@Next:     LODSB
  125.                         MOV         [(MD5_CTX PTR ES:DI+BX).inn],AL
  126.                         INC         BX
  127.  
  128.             ;     /* transform if necessary */
  129.             ;     if (mdi == 0x40) {
  130.                         CMP         BX,40h
  131.                         JNE         @@EndLoop
  132.             ;       for (i = 0, ii = 0; i < 16; i++, ii += 4)           unnecessary!
  133.             ;         inn[i] = (((UINT4)mdContext->inn[ii+3]) << 24) |
  134.             ;                 (((UINT4)mdContext->inn[ii+2]) << 16) |
  135.             ;                 (((UINT4)mdContext->inn[ii+1]) << 8) |
  136.             ;                 ((UINT4)mdContext->inn[ii]);
  137.  
  138.             ;       Transform (mdContext->buf, inn);
  139.                         LEA         AX,[WORD PTR (MD5_CTX PTR ES:DI).inn]
  140.                         PUSH        ES AX
  141.                         LEA         AX,[WORD PTR (MD5_CTX PTR ES:DI).buf]
  142.                         PUSH        ES AX
  143.                         CALL        Transform
  144.                         POP         AX AX AX AX
  145.  
  146.             ;       mdi = 0;
  147.                         MOV         BX,0
  148.             ;     }
  149.             ;   }
  150.             @@EndLoop:  LOOP        @@Next
  151.             @@Finished:
  152.  
  153.                         POP         DX CX BX AX DI SI DS ES
  154.                         RET
  155.  
  156. ENDP        MD5Update
  157.  
  158. PROC        MD5Final
  159.             ; void MD5Final (unsigned char far digest[16], MD5_CTX *mdContext)
  160.                         ARG         digest:DWORD,mdContext:DWORD
  161.                         LOCAL       NofBits:WORD:4
  162.  
  163.             ; { UINT4 inn[16];
  164.             ;   int mdi;
  165.             ;   unsigned int i, ii;
  166.             ;   unsigned int padLen;
  167.                         PUSH        ES DS SI DI AX BX CX
  168.                         LES         DI,[mdContext]
  169.  
  170.             ;  /* save number of bits */
  171.             ;  inn[14] = mdContext->i[0];
  172.             ;  inn[15] = mdContext->i[1];
  173.  
  174.                         MOV         AX,[(MD5_CTX PTR ES:DI).i]
  175.                         MOV         [NofBits],AX
  176.                         MOV         AX,[(MD5_CTX PTR ES:DI+2).i]
  177.                         MOV         [NofBits+2],AX
  178.                         MOV         AX,[(MD5_CTX PTR ES:DI+4).i]
  179.                         MOV         [NofBits+4],AX
  180.                         MOV         AX,[(MD5_CTX PTR ES:DI+6).i]
  181.                         MOV         [NofBits+6],AX
  182.  
  183.             ;   /* compute number of bytes mod 64 */
  184.             ;   mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
  185.  
  186.                         MOV         BX,[WORD PTR (MD5_CTX PTR ES:DI).i]
  187.                         SHR         BX,1
  188.                         SHR         BX,1
  189.                         SHR         BX,1
  190.                         AND         BX,3Fh
  191.  
  192.             ;   /* pad out to 56 mod 64 */
  193.             ;   padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
  194.                         MOV         CX,56
  195.                         CMP         BX,56
  196.                         JB          @0
  197.                         MOV         CX,120
  198.             @0:         SUB         CX,BX
  199.  
  200.             ;   MD5Update (mdContext, PADDING, padLen);
  201.                         MOV         AX,OFFSET Padding
  202.                         PUSH        CX CS AX ES DI
  203.                         CALL        MD5Update
  204.                         ADD         SP,0Ah
  205.  
  206.             ;   /* append length inn bits and transform */
  207.             ;   for (i = 0, ii = 0; i < 14; i++, ii += 4)
  208.             ;    inn[i] = (((UINT4)mdContext->inn[ii+3]) << 24) |
  209.             ;      (((UINT4)mdContext->inn[ii+2]) << 16) |
  210.             ;      (((UINT4)mdContext->inn[ii+1]) << 8) |
  211.             ;      ((UINT4)mdContext->inn[ii]);
  212.  
  213.                         MOV         AX,[NofBits]
  214.                         MOV         [WORD PTR (MD5_CTX PTR ES:DI+4*14).inn],AX
  215.                         MOV         AX,[NofBits+2]
  216.                         MOV         [WORD PTR (MD5_CTX PTR ES:DI+4*14+2).inn],AX
  217.                         MOV         AX,[NofBits+4]
  218.                         MOV         [WORD PTR (MD5_CTX PTR ES:DI+4*15).inn],AX
  219.                         MOV         AX,[NofBits+6]
  220.                         MOV         [WORD PTR (MD5_CTX PTR ES:DI+4*15+2).inn],AX
  221.  
  222.             ;   Transform (mdContext->buf, inn);
  223.                         LEA         AX,[(MD5_CTX PTR ES:DI).inn]
  224.                         PUSH        ES AX
  225.                         LEA         AX,[(MD5_CTX PTR ES:DI).buf]
  226.                         PUSH        ES AX
  227.                         CALL        Transform
  228.                         POP         AX AX AX AX
  229.  
  230.             ;   /* store buffer inn digest */
  231.             ;   for (i = 0, ii = 0; i < 4; i++, ii += 4) {
  232.             ;     digest[ii]   = (unsigned char) (mdContext->buf[i]        & 0xFF);
  233.             ;     digest[ii+1] = (unsigned char)((mdContext->buf[i] >> 8)  & 0xFF);
  234.             ;     digest[ii+2] = (unsigned char)((mdContext->buf[i] >> 16) & 0xFF);
  235.             ;     digest[ii+3] = (unsigned char)((mdContext->buf[i] >> 24) & 0xFF);
  236.                         LEA         SI,[(MD5_CTX PTR ES:DI).buf]
  237.                         PUSH        ES
  238.                         LES         DI,[digest]
  239.                         POP         DS
  240.                         CLD
  241.                         MOV         CX,8
  242.                         REP         MOVSW
  243.             ;   }
  244.             ; }
  245.                         POP         CX BX AX DI SI DS ES
  246.                         RET
  247. ENDP        MD5Final
  248.  
  249. PROC        RotateLeft
  250.             ; #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
  251.  
  252.             ; DS:SI target
  253.             ; CX = count
  254.  
  255.                         XCHG        AX,[WORD PTR DS:SI]
  256.                         XCHG        DX,[WORD PTR DS:SI+2]
  257.                         PUSH        SI DI BX CX
  258.  
  259.                         TEST        CX,10h
  260.                         JE          @@0
  261.  
  262.                         XCHG        AX,DX
  263.                         AND         CX,0Fh
  264.  
  265.             @@0:        ROL         AX,CL
  266.                         ROL         DX,CL
  267.  
  268.                         MOV         SI,1
  269.                         SHL         SI,CL
  270.                         DEC         SI
  271.                         MOV         DI,SI
  272.                         NOT         DI
  273.  
  274.                         MOV         BX,AX
  275.                         MOV         CX,DX
  276.                         AND         BX,SI
  277.                         AND         CX,SI
  278.                         AND         AX,DI
  279.                         AND         DX,DI
  280.                         OR          DX,BX
  281.                         OR          AX,CX
  282.  
  283.                         POP         CX BX DI SI
  284.                         XCHG        AX,[WORD PTR DS:SI]
  285.                         XCHG        DX,[WORD PTR DS:SI+2]
  286.                         RET
  287.  
  288. ENDP        RotateLeft
  289.  
  290. PROC        F           NEAR
  291.             ; #define F(b, c, d) (((b) & (c)) | ((~b) & (d)))
  292.             ; SI->c, BX->d, CX & AX dummy's
  293.                         PUSH        CX BX
  294.                         XCHG        DX,SI
  295.                         XCHG        BX,AX
  296.                         MOV         AX,[WORD PTR DS:DI+2]   ; hi b
  297.                         MOV         CX,AX
  298.                         AND         AX,[WORD PTR DS:SI+2]   ; hi c
  299.                         NOT         CX
  300.                         AND         CX,[WORD PTR DS:BX+2]   ; hi d
  301.                         OR          AX,CX
  302.                         PUSH        AX                                  ; = hi result
  303.                         MOV         AX,[WORD PTR DS:DI]     ; lo b
  304.                         MOV         CX,AX
  305.                         AND         AX,[WORD PTR DS:SI]     ; lo c
  306.                         NOT         CX
  307.                         AND         CX,[WORD PTR DS:BX]     ; lo d
  308.                         OR          AX,CX
  309.                         PUSH        AX                                  ; = lo result
  310.                         XCHG        AX,BX
  311.                         XCHG        DX,SI
  312.                         POP         CX                                  ; = lo result
  313.                         ADD         [WORD PTR DS:SI],CX     ; lo a
  314.                         POP         CX                                  ; = hi result
  315.                         ADC         [WORD PTR DS:SI+2],CX   ; hi a
  316.                         POP         BX CX
  317.                         RET
  318. ENDP        F
  319. PROC        G
  320.             ; #define G(b, c, d) (((b) & (d)) | ((c) & (~d)))  = F(
  321.                         PUSH        CX BX
  322.                         XCHG        DX,SI
  323.                         XCHG        BX,AX
  324.             ; SI->c, BX->d, CX & AX dummy's
  325.                         MOV         AX,[WORD PTR DS:BX+2]   ; hi d
  326.                         MOV         CX,AX
  327.                         AND         AX,[WORD PTR DS:DI+2]   ; hi b
  328.                         NOT         CX
  329.                         AND         CX,[WORD PTR DS:SI+2]   ; hi c
  330.                         OR          AX,CX
  331.                         PUSH        AX                                  ; = hi result
  332.                         MOV         AX,[WORD PTR DS:BX]     ; lo d
  333.                         MOV         CX,AX
  334.                         AND         AX,[WORD PTR DS:DI]     ; lo b
  335.                         NOT         CX
  336.                         AND         CX,[WORD PTR DS:SI]     ; lo c
  337.                         OR          AX,CX
  338.                         PUSH        AX                                  ; = lo result
  339.                         XCHG        AX,BX
  340.                         XCHG        DX,SI
  341.                         POP         CX                                  ; = lo result
  342.                         ADD         [WORD PTR DS:SI],CX     ; lo a
  343.                         POP         CX                                  ; = hi result
  344.                         ADC         [WORD PTR DS:SI+2],CX   ; hi a
  345.                         POP         BX CX
  346.                         RET
  347. ENDP        G
  348. PROC        H
  349.             ; #define H(b, c, d) ((b) ^ (c) ^ (d))
  350.                         PUSH        CX
  351.                         XCHG        DX,SI
  352.                         XCHG        BX,AX
  353.             ; SI->c, BX->d, CX dummy
  354.                         MOV         CX,[WORD PTR DS:DI+2]   ; hi b
  355.                         XOR         CX,[WORD PTR DS:SI+2]   ; hi c
  356.                         XOR         CX,[WORD PTR DS:BX+2]   ; hi d
  357.                         PUSH        CX                                  ; = hi result
  358.                         MOV         CX,[WORD PTR DS:DI]     ; lo b
  359.                         XOR         CX,[WORD PTR DS:SI]     ; lo c
  360.                         XOR         CX,[WORD PTR DS:BX]     ; lo d
  361.  
  362.                         XCHG        AX,BX
  363.                         XCHG        DX,SI
  364.  
  365.                         ADD         [WORD PTR DS:SI],CX     ; lo a
  366.                         POP         CX                                  ; = hi result
  367.                         ADC         [WORD PTR DS:SI+2],CX   ; hi a
  368.                         POP         CX
  369.                         RET
  370. ENDP        H
  371. PROC        I
  372.                         PUSH        CX
  373.                         XCHG        DX,SI
  374.                         XCHG        BX,AX
  375.             ; SI->c, BX->d, CX dummy
  376.                         MOV         CX,[WORD PTR DS:BX+2]   ; hi d
  377.                         NOT         CX
  378.                         OR          CX,[WORD PTR DS:DI+2]   ; hi b
  379.                         XOR         CX,[WORD PTR DS:SI+2]   ; hi c
  380.                         PUSH        CX                                  ; = hi result
  381.                         MOV         CX,[WORD PTR DS:BX]     ; hi d
  382.                         NOT         CX
  383.                         OR          CX,[WORD PTR DS:DI]     ; hi b
  384.                         XOR         CX,[WORD PTR DS:SI]     ; hi c
  385.  
  386.                         XCHG        AX,BX
  387.                         XCHG        DX,SI
  388.  
  389.                         ADD         [WORD PTR DS:SI],CX     ; lo a
  390.                         POP         CX                                  ; = hi result
  391.                         ADC         [WORD PTR DS:SI+2],CX   ; hi a
  392.                         POP         CX
  393.                         RET
  394. ENDP        I
  395.  
  396. PROC        FFGGHHII
  397.             ARG         SUBAlgo:WORD
  398.             ; #define FF(a, b, c, d, x, s, ac) \
  399.             ;  {(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
  400.             ;   (a) = ROTATE_LEFT ((a), (s)); \
  401.             ;   (a) += (b); \
  402.             ;  }
  403.             ;   SI->a, DI->b, DX->c, AX->d, ES:CX->x, BX->ac,s
  404.  
  405.  
  406.             ; SI->c, BX->d, CX & AX dummy's
  407.                         CALL        [SubAlgo]
  408.  
  409.  
  410.                         XCHG        BP,CX
  411.                         PUSH        CX
  412.             ; CX dummy, ES:BP->x
  413.                         MOV         CX,[WORD PTR ES:BP]     ; lo x
  414.                         ADD         [WORD PTR DS:SI],CX     ; lo a
  415.                         MOV         CX,[WORD PTR ES:BP+2]   ; hi x
  416.                         ADC         [WORD PTR DS:SI+2],CX   ; hi a
  417.                         MOV         CX,[WORD PTR DS:BX]     ; lo ac
  418.                         ADD         [WORD PTR DS:SI],CX     ; lo a
  419.                         MOV         CX,[WORD PTR DS:BX+2]   ; hi ac
  420.                         ADC         [WORD PTR DS:SI+2],CX   ; hi a
  421.  
  422.                         MOV         CX,[WORD PTR DS:BX+4]   ; s
  423.                         CALL        RotateLeft
  424.  
  425.                         MOV         CX,[WORD PTR DS:DI]     ; lo b
  426.                         ADD         [WORD PTR DS:SI],CX     ; lo a
  427.                         MOV         CX,[WORD PTR DS:DI+2]   ; hi b
  428.                         ADC         [WORD PTR DS:SI+2],CX   ; hi a
  429.                         MOV         CX,BP
  430.  
  431.                         POP         BP
  432.                         RET
  433. ENDP        FFGGHHII
  434.  
  435. PROC        Transform
  436.             ; void Transform(register UINT4 *buf,register UINT4 *in)
  437.             ARG         buf:DWORD,inn:DWORD
  438.  
  439.                         PUSH        ES DS SI DI AX BX CX DX
  440.  
  441.             ; register UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
  442.                         LDS         SI,[buf]
  443.                         PUSH        CS
  444.                         POP         ES
  445.                         LEA         DI,[a]
  446.                         CLD
  447.                         MOV         CX,8
  448.                         REP         MOVSW
  449.                         PUSH        CS
  450.                         POP         DS
  451.  
  452.                         PUSH        BP
  453.                         MOV         AX,OFFSET I
  454.                         PUSH        AX
  455.                         MOV         AX,OFFSET H
  456.                         PUSH        AX
  457.                         MOV         AX,OFFSET G
  458.                         PUSH        AX
  459.                         MOV         AX,OFFSET F
  460.                         PUSH        AX
  461. ;   SI->a, DI->b, DX->c, AX->d, ES:CX->x, BX->ac,s
  462.                         LES         CX,[inn]
  463.                         MOV         [Offinn],CX
  464.                         LEA         SI,[a]
  465.                         LEA         DI,[b]
  466.                         LEA         DX,[c]
  467.                         LEA         AX,[d]
  468.                         LEA         BX,[acsTable]
  469.  
  470. ;  /* Round 1 */
  471. ; FF ( a, b, c, d, in[ 0], S11, 0xD76AA478L); /* 1 */
  472. ; FF ( d, a, b, c, in[ 1], S12, 0xE8C7B756L); /* 2 */
  473. ; FF ( c, d, a, b, in[ 2], S13, 0x242070DBL); /* 3 */
  474. ; FF ( b, c, d, a, in[ 3], S14, 0xC1BDCEEEL); /* 4 */
  475. ; FF ( a, b, c, d, in[ 4], S11, 0xF57C0FAFL); /* 5 */
  476. ; FF ( d, a, b, c, in[ 5], S12, 0x4787C62AL); /* 6 */
  477. ; FF ( c, d, a, b, in[ 6], S13, 0xA8304613L); /* 7 */
  478. ; FF ( b, c, d, a, in[ 7], S14, 0xFD469501L); /* 8 */
  479. ; FF ( a, b, c, d, in[ 8], S11, 0x698098D8L); /* 9 */
  480. ; FF ( d, a, b, c, in[ 9], S12, 0x8B44F7AFL); /* 10 */
  481. ; FF ( c, d, a, b, in[10], S13, 0xFFFF5BB1L); /* 11 */
  482. ; FF ( b, c, d, a, in[11], S14, 0x895CD7BEL); /* 12 */
  483. ; FF ( a, b, c, d, in[12], S11, 0x6B901122L); /* 13 */
  484. ; FF ( d, a, b, c, in[13], S12, 0xFD987193L); /* 14 */
  485. ; FF ( c, d, a, b, in[14], S13, 0xA679438EL); /* 15 */
  486. ; FF ( b, c, d, a, in[15], S14, 0x49B40821L); /* 16 */
  487.  
  488.                         MOV         BP,16
  489.  
  490.             @@NextFF:   CALL        FFGGHHII
  491.                         ADD         BX,6
  492.                         ADD         CX,4
  493.  
  494.                         PUSH        SI DI DX AX
  495.                         POP         SI AX DX DI
  496.                         DEC         BP
  497.                         JNZ         @@NextFF
  498.  
  499.                         ADD         SP,2
  500.  
  501.  
  502. ;  /* Round 2 */
  503. ;  GG ( a, b, c, d, in[ 1], S21, 0xF61E2562L); /* 17 */
  504. ;  GG ( d, a, b, c, in[ 6], S22, 0xC040B340L); /* 18 */
  505. ;  GG ( c, d, a, b, in[11], S23, 0x265E5A51L); /* 19 */
  506. ;  GG ( b, c, d, a, in[ 0], S24, 0xE9B6C7AAL); /* 20 */
  507. ;  GG ( a, b, c, d, in[ 5], S21, 0xD62F105DL); /* 21 */
  508. ;  GG ( d, a, b, c, in[10], S22, 0x02441453L); /* 22 */
  509. ;  GG ( c, d, a, b, in[15], S23, 0xD8A1E681L); /* 23 */
  510. ;  GG ( b, c, d, a, in[ 4], S24, 0xE7D3FBC8L); /* 24 */
  511. ;  GG ( a, b, c, d, in[ 9], S21, 0x21E1CDE6L); /* 25 */
  512. ;  GG ( d, a, b, c, in[14], S22, 0xC33707D6L); /* 26 */
  513. ;  GG ( c, d, a, b, in[ 3], S23, 0xF4D50D87L); /* 27 */
  514. ;  GG ( b, c, d, a, in[ 8], S24, 0x455A14EDL); /* 28 */
  515. ;  GG ( a, b, c, d, in[13], S21, 0xA9E3E905L); /* 29 */
  516. ;  GG ( d, a, b, c, in[ 2], S22, 0xFCEFA3F8L); /* 30 */
  517. ;  GG ( c, d, a, b, in[ 7], S23, 0x676F02D9L); /* 31 */
  518. ;  GG ( b, c, d, a, in[12], S24, 0x8D2A4C8AL); /* 32 */
  519.  
  520.                         MOV         CX,[Offinn]
  521.                         ADD         CX,4
  522.  
  523.                         MOV         BP,16
  524.  
  525.             @@NextGG:   CALL        FFGGHHII
  526.                         ADD         BX,6
  527.                         ADD         CX,5*4
  528.                         SUB         CX,[Offinn]
  529.                         AND         CX,4*0Fh
  530.                         ADD         CX,[Offinn]
  531.                         PUSH        SI DI DX AX
  532.                         POP         SI AX DX DI
  533.                         DEC         BP
  534.                         JNZ         @@NextGG
  535.  
  536.                         ADD         SP,2
  537.  
  538. ;  /* Round 3 */
  539. ;  HH ( a, b, c, d, in[ 5], S31, 0xFFFA3942L); /* 33 */
  540. ;  HH ( d, a, b, c, in[ 8], S32, 0x8771F681L); /* 34 */
  541. ;  HH ( c, d, a, b, in[11], S33, 0x6D9D6122L); /* 35 */
  542. ;  HH ( b, c, d, a, in[14], S34, 0xFDE5380CL); /* 36 */
  543. ;  HH ( a, b, c, d, in[ 1], S31, 0xA4BEEA44L); /* 37 */
  544. ;  HH ( d, a, b, c, in[ 4], S32, 0x4BDECFA9L); /* 38 */
  545. ;  HH ( c, d, a, b, in[ 7], S33, 0xF6BB4B60L); /* 39 */
  546. ;  HH ( b, c, d, a, in[10], S34, 0xBEBFBC70L); /* 40 */
  547. ;  HH ( a, b, c, d, in[13], S31, 0x289B7EC6L); /* 41 */
  548. ;  HH ( d, a, b, c, in[ 0], S32, 0xEAA127FAL); /* 42 */
  549. ;  HH ( c, d, a, b, in[ 3], S33, 0xD4EF3085L); /* 43 */
  550. ;  HH ( b, c, d, a, in[ 6], S34, 0x04881D05L); /* 44 */
  551. ;  HH ( a, b, c, d, in[ 9], S31, 0xD9D4D039L); /* 45 */
  552. ;  HH ( d, a, b, c, in[12], S32, 0xE6DB99E5L); /* 46 */
  553. ;  HH ( c, d, a, b, in[15], S33, 0x1FA27CF8L); /* 47 */
  554. ;  HH ( b, c, d, a, in[ 2], S34, 0xC4AC5665L); /* 48 */
  555.  
  556.                         MOV         CX,[Offinn]
  557.                         ADD         CX,5*4
  558.  
  559.                         MOV         BP,16
  560.  
  561.             @@NextHH:   CALL        FFGGHHII
  562.                         ADD         BX,6
  563.                         ADD         CX,3*4
  564.                         SUB         CX,[Offinn]
  565.                         AND         CX,4*0Fh
  566.                         ADD         CX,[Offinn]
  567.                         PUSH        SI DI DX AX
  568.                         POP         SI AX DX DI
  569.                         DEC         BP
  570.                         JNZ         @@NextHH
  571.  
  572.                         ADD         SP,2
  573.  
  574. ;  /* Round 4 */
  575. ;  II ( a, b, c, d, in[ 0], S41, 0xF4292244L); /* 49 */
  576. ;  II ( d, a, b, c, in[ 7], S42, 0x432AFF97L); /* 50 */
  577. ;  II ( c, d, a, b, in[14], S43, 0xAB9423A7L); /* 51 */
  578. ;  II ( b, c, d, a, in[ 5], S44, 0xFC93A039L); /* 52 */
  579. ;  II ( a, b, c, d, in[12], S41, 0x655B59C3L); /* 53 */
  580. ;  II ( d, a, b, c, in[ 3], S42, 0x8F0CCC92L); /* 54 */
  581. ;  II ( c, d, a, b, in[10], S43, 0xFFEFF47DL); /* 55 */
  582. ;  II ( b, c, d, a, in[ 1], S44, 0x85845DD1L); /* 56 */
  583. ;  II ( a, b, c, d, in[ 8], S41, 0x6FA87E4FL); /* 57 */
  584. ;  II ( d, a, b, c, in[15], S42, 0xFE2CE6E0L); /* 58 */
  585. ;  II ( c, d, a, b, in[ 6], S43, 0xA3014314L); /* 59 */
  586. ;  II ( b, c, d, a, in[13], S44, 0x4E0811A1L); /* 60 */
  587. ;  II ( a, b, c, d, in[ 4], S41, 0xF7537E82L); /* 61 */
  588. ;  II ( d, a, b, c, in[11], S42, 0xBD3AF235L); /* 62 */
  589. ;  II ( c, d, a, b, in[ 2], S43, 0x2AD7D2BBL); /* 63 */
  590. ;  II ( b, c, d, a, in[ 9], S44, 0xEB86D391L); /* 64 */
  591.  
  592.                         MOV         CX,[Offinn]
  593.  
  594.                         MOV         BP,16
  595.  
  596.             @@NextII:   CALL        FFGGHHII
  597.                         ADD         BX,6
  598.                         ADD         CX,7*4
  599.                         SUB         CX,[Offinn]
  600.                         AND         CX,4*0Fh
  601.                         ADD         CX,[Offinn]
  602.                         PUSH        SI DI DX AX
  603.                         POP         SI AX DX DI
  604.                         DEC         BP
  605.                         JNZ         @@NextII
  606.  
  607.                         ADD         SP,2
  608.  
  609.                         POP         BP
  610.  
  611. ;  buf[0] += a;
  612.                         LES         DI,[buf]
  613.                         MOV         AX,[WORD PTR a]
  614.                         MOV         DX,[WORD PTR a+2]
  615.                         ADD         [WORD PTR ES:DI],AX
  616.                         ADC         [WORD PTR ES:DI+2],DX
  617. ;  buf[1] += b;
  618.                         MOV         AX,[WORD PTR b]
  619.                         MOV         DX,[WORD PTR b+2]
  620.                         ADD         [WORD PTR ES:DI+4],AX
  621.                         ADC         [WORD PTR ES:DI+6],DX
  622. ;  buf[2] += c;
  623.                         MOV         AX,[WORD PTR c]
  624.                         MOV         DX,[WORD PTR c+2]
  625.                         ADD         [WORD PTR ES:DI+8],AX
  626.                         ADC         [WORD PTR ES:DI+0Ah],DX
  627. ;  buf[3] += d;
  628.                         MOV         AX,[WORD PTR d]
  629.                         MOV         DX,[WORD PTR d+2]
  630.                         ADD         [WORD PTR ES:DI+0Ch],AX
  631.                         ADC         [WORD PTR ES:DI+0Eh],DX
  632. ;}
  633.                         POP         DX CX BX AX DI SI DS ES
  634.                         RET
  635.  
  636.  
  637. S11=7
  638. S12=12
  639. S13=17
  640. S14=22
  641. S21=5
  642. S22=9
  643. S23=14
  644. S24=20
  645. S31=4
  646. S32=11
  647. S33=16
  648. S34=23
  649. S41=6
  650. S42=10
  651. S43=15
  652. S44=21
  653.  
  654. a           DD          ?
  655. b           DD          ?
  656. c           DD          ?
  657. d           DD          ?
  658. OffInn      DW          ?
  659.  
  660. STRUC       acsItem
  661.                         ac          DD          ?
  662.                         s           DW          ?
  663. ENDS        acsItem
  664.  
  665. acsTable    acsItem     <0D76AA478h,S11>,<0E8C7B756h,S12>,<0242070DBh,S13>,<0C1BDCEEEh,S14>
  666.             acsItem     <0F57C0FAFh,S11>,<04787C62Ah,S12>,<0A8304613h,S13>,<0FD469501h,S14>
  667.             acsItem     <0698098D8h,S11>,<08B44F7AFh,S12>,<0FFFF5BB1h,S13>,<0895CD7BEh,S14>
  668.             acsItem     <06B901122h,S11>,<0FD987193h,S12>,<0A679438Eh,S13>,<049B40821h,S14>
  669.             acsItem     <0F61E2562h,S21>,<0C040B340h,S22>,<0265E5A51h,S23>,<0E9B6C7AAh,S24>
  670.             acsItem     <0D62F105Dh,S21>,<002441453h,S22>,<0D8A1E681h,S23>,<0E7D3FBC8h,S24>
  671.             acsItem     <021E1CDE6h,S21>,<0C33707D6h,S22>,<0F4D50D87h,S23>,<0455A14EDh,S24>
  672.             acsItem     <0A9E3E905h,S21>,<0FCEFA3F8h,S22>,<0676F02D9h,S23>,<08D2A4C8Ah,S24>
  673.             acsItem     <0FFFA3942h,S31>,<08771F681h,S32>,<06D9D6122h,S33>,<0FDE5380Ch,S34>
  674.             acsItem     <0A4BEEA44h,S31>,<04BDECFA9h,S32>,<0F6BB4B60h,S33>,<0BEBFBC70h,S34>
  675.             acsItem     <0289B7EC6h,S31>,<0EAA127FAh,S32>,<0D4EF3085h,S33>,<004881D05h,S34>
  676.             acsItem     <0D9D4D039h,S31>,<0E6DB99E5h,S32>,<01FA27CF8h,S33>,<0C4AC5665h,S34>
  677.             acsItem     <0F4292244h,S41>,<0432AFF97h,S42>,<0AB9423A7h,S43>,<0FC93A039h,S44>
  678.             acsItem     <0655B59C3h,S41>,<08F0CCC92h,S42>,<0FFEFF47Dh,S43>,<085845DD1h,S44>
  679.             acsItem     <06FA87E4Fh,S41>,<0FE2CE6E0h,S42>,<0A3014314h,S43>,<04E0811A1h,S44>
  680.             acsItem     <0F7537E82h,S41>,<0BD3AF235h,S42>,<02AD7D2BBh,S43>,<0EB86D391h,S44>
  681. ENDP        Transform
  682. END
  683.  
  684.  
  685. END
  686.