md5 и Ассемблер

Тема в разделе "WASM.BEGINNERS", создана пользователем tagegor, 13 сен 2009.

  1. tagegor

    tagegor New Member

    Публикаций:
    0
    Регистрация:
    8 июл 2009
    Сообщения:
    54
    Собственно немогу никак найти исходник на масме для подсчета md5 суммы файла. Просьба ссылками из гугла не делиться, так как я полез туда в первую очередь :)
     
  2. wasm_test

    wasm_test wasm test user

    Публикаций:
    0
    Регистрация:
    24 ноя 2006
    Сообщения:
    5.582
    а не вариант взять сишный и переписать?)
     
  3. litrovith

    litrovith Member

    Публикаций:
    0
    Регистрация:
    20 июн 2007
    Сообщения:
    509
    http://www.wasm.ru/srclist.php?list=9
     
  4. Clerk

    Clerk Забанен

    Публикаций:
    0
    Регистрация:
    4 янв 2008
    Сообщения:
    6.689
    Адрес:
    РБ, Могилёв
    TransformMD5() основная, а её сишный компилятор собирает с оптимизацией, код получается линейный и все регистры используются, поэтому на масме, учитывая его малую гибкость нет смысла это собирать, просто дизассемблированный код скопировать из системного модуля к примеру.
     
  5. Clerk

    Clerk Забанен

    Публикаций:
    0
    Регистрация:
    4 янв 2008
    Сообщения:
    6.689
    Адрес:
    РБ, Могилёв
    Код (Text):
    1. TransformMD5 proc C
    2.     mov eax,dword ptr ss:[esp + 4]
    3.     push ebx
    4.     mov ecx,dword ptr ss:[esp + 4*3]
    5.     push esi
    6.     push edi
    7.     mov edx,dword ptr ds:[eax + 4]
    8.     push ebp
    9.     mov esi,dword ptr ds:[eax + 4*2]
    10.     mov edi,dword ptr ds:[eax + 4*3]
    11.     mov ebp,dword ptr ds:[ecx]
    12.     mov ebx,edi
    13.     xor ebx,esi
    14.     and ebx,edx
    15.     xor ebx,edi
    16.     add ebx,ebp
    17.     mov ebp,dword ptr ds:[eax]
    18.     lea ebx,dword ptr ss:[ebp + ebx + 0D76AA478H]
    19.     rol ebx,07H
    20.     mov eax,esi
    21.     add ebx,edx
    22.     xor eax,edx
    23.     and eax,ebx
    24.     mov ebp,dword ptr ds:[ecx + 4]
    25.     xor eax,esi
    26.     add edi,ebp
    27.     add eax,0E8C7B756H
    28.     add edi,eax
    29.     rol edi,0CH
    30.     mov eax,edx
    31.     add edi,ebx
    32.     xor eax,ebx
    33.     and eax,edi
    34.     mov ebp,dword ptr ds:[ecx + 2*4]
    35.     xor eax,edx
    36.     add esi,ebp
    37.     add eax,0242070DBH
    38.     add esi,eax
    39.     rol esi,11H
    40.     mov eax,edi
    41.     add esi,edi
    42.     xor eax,ebx
    43.     and eax,esi
    44.     mov ebp,dword ptr ds:[ecx + 3*4]
    45.     xor eax,ebx
    46.     add edx,ebp
    47.     add eax,0C1BDCEEEH
    48.     add edx,eax
    49.     rol edx,16H
    50.     mov eax,edi
    51.     add edx,esi
    52.     xor eax,esi
    53.     and eax,edx
    54.     mov ebp,dword ptr ds:[ecx + 4*4]
    55.     xor eax,edi
    56.     add ebx,ebp
    57.     add eax,0F57C0FAFH
    58.     add ebx,eax
    59.     rol ebx,07H
    60.     mov eax,esi
    61.     add ebx,edx
    62.     xor eax,edx
    63.     and eax,ebx
    64.     mov ebp,dword ptr ds:[ecx + 4*5]
    65.     xor eax,esi
    66.     add edi,ebp
    67.     add eax,04787C62AH
    68.     add edi,eax
    69.     rol edi,0CH
    70.     mov eax,edx
    71.     add edi,ebx
    72.     xor eax,ebx
    73.     and eax,edi
    74.     mov ebp,dword ptr ds:[ecx + 4*6]
    75.     xor eax,edx
    76.     add esi,ebp
    77.     add eax,0A8304613H
    78.     add esi,eax
    79.     rol esi,11H
    80.     mov eax,edi
    81.     add esi,edi
    82.     xor eax,ebx
    83.     and eax,esi
    84.     mov ebp,dword ptr ds:[ecx + 4*7]
    85.     xor eax,ebx
    86.     add edx,ebp
    87.     add eax,0FD469501H
    88.     add edx,eax
    89.     rol edx,16H
    90.     mov eax,edi
    91.     add edx,esi
    92.     xor eax,esi
    93.     and eax,edx
    94.     mov ebp,dword ptr ds:[ecx + 4*8]
    95.     xor eax,edi
    96.     add ebx,ebp
    97.     add eax,0698098D8H
    98.     add ebx,eax
    99.     rol ebx,07H
    100.     mov eax,esi
    101.     add ebx,edx
    102.     xor eax,edx
    103.     and eax,ebx
    104.     mov ebp,dword ptr ds:[ecx + 4*9]
    105.     xor eax,esi
    106.     add edi,ebp
    107.     add eax,08B44F7AFH
    108.     add edi,eax
    109.     rol edi,0CH
    110.     mov eax,edx
    111.     add edi,ebx
    112.     xor eax,ebx
    113.     and eax,edi
    114.     mov ebp,dword ptr ds:[ecx + 4*10]
    115.     xor eax,edx
    116.     add esi,ebp
    117.     add eax,0FFFF5BB1H
    118.     add esi,eax
    119.     rol esi,11H
    120.     mov eax,edi
    121.     add esi,edi
    122.     xor eax,ebx
    123.     and eax,esi
    124.     mov ebp,dword ptr ds:[ecx + 4*11]
    125.     xor eax,ebx
    126.     add edx,ebp
    127.     add eax,0895CD7BEH
    128.     add edx,eax
    129.     rol edx,16H
    130.     mov eax,edi
    131.     add edx,esi
    132.     xor eax,esi
    133.     and eax,edx
    134.     mov ebp,dword ptr ds:[ecx + 4*12]
    135.     xor eax,edi
    136.     add ebx,ebp
    137.     add eax,06B901122H
    138.     add ebx,eax
    139.     rol ebx,07H
    140.     mov eax,esi
    141.     add ebx,edx
    142.     xor eax,edx
    143.     and eax,ebx
    144.     mov ebp,dword ptr ds:[ecx + 4*13]
    145.     xor eax,esi
    146.     add edi,ebp
    147.     add eax,0FD987193H
    148.     add edi,eax
    149.     rol edi,0CH
    150.     mov eax,edx
    151.     add edi,ebx
    152.     xor eax,ebx
    153.     and eax,edi
    154.     mov ebp,dword ptr ds:[ecx + 4*14]
    155.     xor eax,edx
    156.     add esi,ebp
    157.     add eax,0A679438EH
    158.     add esi,eax
    159.     rol esi,11H
    160.     mov eax,edi
    161.     add esi,edi
    162.     xor eax,ebx
    163.     and eax,esi
    164.     mov ebp,dword ptr ds:[ecx + 4*15]
    165.     xor eax,ebx
    166.     add edx,ebp
    167.     add eax,049B40821H
    168.     add edx,eax
    169.     rol edx,16H
    170.     mov eax,esi
    171.     add edx,esi
    172.     mov ebp,dword ptr ds:[ecx + 4]
    173.     xor eax,edx
    174.     and eax,edi
    175.     xor eax,esi
    176.     add ebx,ebp
    177.     add eax,0F61E2562H
    178.     add ebx,eax
    179.     mov eax,edx
    180.     rol ebx,05H
    181.     mov ebp,dword ptr ds:[ecx + 18]
    182.     add ebx,edx
    183.     xor eax,ebx
    184.     and eax,esi
    185.     xor eax,edx
    186.     add edi,ebp
    187.     add eax,0C040B340H
    188.     add edi,eax
    189.     mov ebp,dword ptr ds:[ecx + 4*11]
    190.     rol edi,09H
    191.     add edi,ebx
    192.     mov eax,edi
    193.     xor eax,ebx
    194.     and eax,edx
    195.     xor eax,ebx
    196.     add esi,ebp
    197.     add eax,0265E5A51H
    198.     add esi,eax
    199.     mov eax,edi
    200.     rol esi,0EH
    201.     mov ebp,dword ptr ds:[ecx]
    202.     add esi,edi
    203.     xor eax,esi
    204.     and eax,ebx
    205.     xor eax,edi
    206.     add edx,ebp
    207.     add eax,0E9B6C7AAH
    208.     add edx,eax
    209.     mov eax,esi
    210.     rol edx,14H
    211.     mov ebp,dword ptr ds:[ecx + 4*5]
    212.     add edx,esi
    213.     xor eax,edx
    214.     and eax,edi
    215.     xor eax,esi
    216.     add ebx,ebp
    217.     add eax,0D62F105DH
    218.     add ebx,eax
    219.     mov eax,edx
    220.     rol ebx,05H
    221.     mov ebp,dword ptr ds:[ecx + 4*10]
    222.     add ebx,edx
    223.     xor eax,ebx
    224.     and eax,esi
    225.     xor eax,edx
    226.     add edi,ebp
    227.     add eax,02441453H
    228.     add edi,eax
    229.     rol edi,09H
    230.     add edi,ebx
    231.     mov ebp,dword ptr ds:[ecx + 4*15]
    232.     mov eax,edi
    233.     xor eax,ebx
    234.     and eax,edx
    235.     xor eax,ebx
    236.     add esi,ebp
    237.     add eax,0D8A1E681H
    238.     add esi,eax
    239.     mov eax,edi
    240.     rol esi,0EH
    241.     mov ebp,dword ptr ds:[ecx + 4*4]
    242.     add esi,edi
    243.     xor eax,esi
    244.     and eax,ebx
    245.     xor eax,edi
    246.     add edx,ebp
    247.     add eax,0E7D3FBC8H
    248.     add edx,eax
    249.     mov eax,esi
    250.     rol edx,14H
    251.     mov ebp,dword ptr ds:[ecx + 4*9]
    252.     add edx,esi
    253.     xor eax,edx
    254.     and eax,edi
    255.     xor eax,esi
    256.     add ebx,ebp
    257.     add eax,021E1CDE6H
    258.     add ebx,eax
    259.     mov eax,edx
    260.     rol ebx,05H
    261.     mov ebp,dword ptr ds:[ecx + 4*14]
    262.     add ebx,edx
    263.     xor eax,ebx
    264.     and eax,esi
    265.     xor eax,edx
    266.     add edi,ebp
    267.     add eax,0C33707D6H
    268.     add edi,eax
    269.     mov ebp,dword ptr ds:[ecx + 4*3]
    270.     rol edi,09H
    271.     add edi,ebx
    272.     mov eax,edi
    273.     xor eax,ebx
    274.     and eax,edx
    275.     xor eax,ebx
    276.     add esi,ebp
    277.     add eax,0F4D50D87H
    278.     add esi,eax
    279.     mov eax,edi
    280.     rol esi,0EH
    281.     mov ebp,dword ptr ds:[ecx + 4*8]
    282.     add esi,edi
    283.     xor eax,esi
    284.     and eax,ebx
    285.     xor eax,edi
    286.     add edx,ebp
    287.     add eax,0455A14EDH
    288.     add edx,eax
    289.     rol edx,14H
    290.     add edx,esi
    291.     mov eax,esi
    292.     mov ebp,dword ptr ds:[ecx + 4*13]
    293.     xor eax,edx
    294.     and eax,edi
    295.     xor eax,esi
    296.     add ebx,ebp
    297.     add eax,0A9E3E905H
    298.     add ebx,eax
    299.     mov eax,edx
    300.     rol ebx,05H
    301.     mov ebp,dword ptr ds:[ecx + 4*2]
    302.     add ebx,edx
    303.     xor eax,ebx
    304.     and eax,esi
    305.     xor eax,edx
    306.     add edi,ebp
    307.     add eax,0FCEFA3F8H
    308.     add edi,eax
    309.     mov ebp,dword ptr ds:[ecx + 4*7]
    310.     rol edi,9H
    311.     add edi,ebx
    312.     mov eax,edi
    313.     xor eax,ebx
    314.     and eax,edx
    315.     xor eax,ebx
    316.     add esi,ebp
    317.     add eax,0676F02D9H
    318.     add esi,eax
    319.     mov eax,edi
    320.     rol esi,0EH
    321.     add esi,edi
    322.     xor eax,esi
    323.     mov ebp,eax
    324.     and ebp,ebx
    325.     xor ebp,edi
    326.     mov eax,dword ptr ds:[ecx + 4*12]
    327.     add edx,ebp
    328.     add eax,08D2A4C8AH
    329.     add edx,eax
    330.     rol edx,14H
    331.     mov eax,edi
    332.     add edx,esi
    333.     xor eax,esi
    334.     mov ebp,dword ptr ds:[ecx + 4*5]
    335.     xor eax,edx
    336.     add ebx,ebp
    337.     add eax,0FFFA3942H
    338.     add ebx,eax
    339.     rol ebx,04H
    340.     mov eax,esi
    341.     add ebx,edx
    342.     xor eax,edx
    343.     mov ebp,dword ptr ds:[ecx + 4*8]
    344.     xor eax,ebx
    345.     add edi,ebp
    346.     add eax,08771F681H
    347.     add edi,eax
    348.     rol edi,0BH
    349.     mov ebp,dword ptr ds:[ecx + 4*11]
    350.     add esi,ebp
    351.     add edi,ebx
    352.     mov eax,edi
    353.     add esi,06D9D6122H
    354.     xor eax,edx
    355.     xor eax,ebx
    356.     add esi,eax
    357.     rol esi,10H
    358.     mov eax,edi
    359.     add esi,edi
    360.     xor eax,esi
    361.     mov ebp,dword ptr ds:[ecx + 4*14]
    362.     add edx,ebp
    363.     mov ebp,ebx
    364.     xor ebp,eax
    365.     add edx,0FDE5380CH
    366.     add edx,ebp
    367.     rol edx,17H
    368.     mov ebp,dword ptr ds:[ecx  + 4]
    369.     add ebx,ebp
    370.     add edx,esi
    371.     mov ebp,edx
    372.     add ebx,0A4BEEA44H
    373.     xor ebp,eax
    374.     add ebx,ebp
    375.     rol ebx,4H
    376.     mov eax,esi
    377.     add ebx,edx
    378.     xor eax,edx
    379.     mov ebp,dword ptr ds:[ecx + 4*4]
    380.     xor eax,ebx
    381.     add edi,ebp
    382.     add eax,04BDECFA9H
    383.     add edi,eax
    384.     rol edi,0BH
    385.     mov ebp,dword ptr ds:[ecx + 4*7]
    386.     add esi,ebp
    387.     add edi,ebx
    388.     mov eax,edi
    389.     add esi,0F6BB4B60H
    390.     xor eax,edx
    391.     xor eax,ebx
    392.     add esi,eax
    393.     rol esi,10H
    394.     mov eax,edi
    395.     add esi,edi
    396.     mov ebp,dword ptr ds:[ecx + 4*10]
    397.     add edx,ebp
    398.     mov ebp,ebx
    399.     xor eax,esi
    400.     add edx,0BEBFBC70H
    401.     xor ebp,eax
    402.     add edx,ebp
    403.     rol edx,17H
    404.     mov ebp,dword ptr ds:[ecx + 4*13]
    405.     add ebx,ebp
    406.     add edx,esi
    407.     mov ebp,edx
    408.     add ebx,0289B7EC6H
    409.     xor ebp,eax
    410.     add ebx,ebp
    411.     rol ebx,04H
    412.     mov eax,esi
    413.     add ebx,edx
    414.     xor eax,edx
    415.     mov ebp,dword ptr ds:[ecx]
    416.     xor eax,ebx
    417.     add edi,ebp
    418.     add eax,0EAA127FAH
    419.     add edi,eax
    420.     rol edi,0BH
    421.     mov ebp,dword ptr ds:[ecx + 4*3]
    422.     add esi,ebp
    423.     add edi,ebx
    424.     mov eax,edi
    425.     add esi,0D4EF3085H
    426.     xor eax,edx
    427.     xor eax,ebx
    428.     add esi,eax
    429.     rol esi,10H
    430.     mov eax,edi
    431.     add esi,edi
    432.     mov ebp,dword ptr ds:[ecx + 4*6]
    433.     add edx,ebp
    434.     mov ebp,ebx
    435.     xor eax,esi
    436.     add edx,04881D05H
    437.     xor ebp,eax
    438.     add edx,ebp
    439.     rol edx,17H
    440.     add edx,esi
    441.     mov ebp,edx
    442.     xor ebp,eax
    443.     mov eax,dword ptr ds:[ecx + 4*9]
    444.     add ebx,ebp
    445.     add eax,0D9D4D039H
    446.     add ebx,eax
    447.     rol ebx,04H
    448.     mov eax,esi
    449.     add ebx,edx
    450.     xor eax,edx
    451.     mov ebp,dword ptr ds:[ecx + 4*12]
    452.     xor eax,ebx
    453.     add eax,0E6DB99E5H
    454.     add edi,ebp
    455.     add edi,eax
    456.     rol edi,0BH
    457.     mov ebp,dword ptr ds:[ecx + 4*15]
    458.     add edi,ebx
    459.     add esi,ebp
    460.     mov eax,edi
    461.     add esi,01FA27CF8H
    462.     xor eax,edx
    463.     xor eax,ebx
    464.     add esi,eax
    465.     rol esi,10H
    466.     mov eax,edi
    467.     add esi,edi
    468.     mov ebp,dword ptr ds:[ecx + 4*2]
    469.     xor eax,esi
    470.     add edx,ebp
    471.     xor eax,ebx
    472.     add edx,0C4AC5665H
    473.     add edx,eax
    474.     rol edx,17H
    475.     mov eax,edi
    476.     not eax
    477.     add edx,esi
    478.     mov ebp,dword ptr ds:[ecx]
    479.     or eax,edx
    480.     xor eax,esi
    481.     add ebx,ebp
    482.     add eax,0F4292244H
    483.     add ebx,eax
    484.     rol ebx,06H
    485.     mov eax,esi
    486.     not eax
    487.     add ebx,edx
    488.     mov ebp,dword ptr ds:[ecx + 4*7]
    489.     or eax,ebx
    490.     xor eax,edx
    491.     add edi,ebp
    492.     add eax,0432AFF97H
    493.     add edi,eax
    494.     rol edi,0AH
    495.     mov eax,edx
    496.     not eax
    497.     add edi,ebx
    498.     mov ebp,dword ptr ds:[ecx + 4*14]
    499.     or eax,edi
    500.     xor eax,ebx
    501.     add esi,ebp
    502.     add eax,0AB9423A7H
    503.     add esi,eax
    504.     rol esi,0FH
    505.     mov eax,ebx
    506.     not eax
    507.     add esi,edi
    508.     mov ebp,dword ptr ds:[ecx + 4*5]
    509.     or eax,esi
    510.     xor eax,edi
    511.     add edx,ebp
    512.     add edx,0FC93A039H
    513.     add edx,eax
    514.     rol edx,15H
    515.     mov eax,edi
    516.     not eax
    517.     add edx,esi
    518.     mov ebp,dword ptr ds:[ecx + 4*12]
    519.     or eax,edx
    520.     xor eax,esi
    521.     add ebx,ebp
    522.     add eax,0655B59C3H
    523.     add ebx,eax
    524.     rol ebx,06H
    525.     mov eax,esi
    526.     not eax
    527.     add ebx,edx
    528.     mov ebp,dword ptr ds:[ecx + 4*3]
    529.     or eax,ebx
    530.     xor eax,edx
    531.     add edi,ebp
    532.     add eax,08F0CCC92H
    533.     add edi,eax
    534.     rol edi,0AH
    535.     mov eax,edx
    536.     not eax
    537.     add edi,ebx
    538.     mov ebp,dword ptr ds:[ecx + 4*10]
    539.     or eax,edi
    540.     xor eax,ebx
    541.     add esi,ebp
    542.     add eax,0FFEFF47DH
    543.     add esi,eax
    544.     rol esi,0FH
    545.     mov eax,ebx
    546.     not eax
    547.     add esi,edi
    548.     mov ebp,dword ptr ds:[ecx + 4]
    549.     or eax,esi
    550.     xor eax,edi
    551.     add edx,ebp
    552.     add eax,085845DD1H
    553.     add edx,eax
    554.     rol edx,15H
    555.     mov eax,edi
    556.     not eax
    557.     add edx,esi
    558.     mov ebp,dword ptr ds:[ecx + 4*8]
    559.     or eax,edx
    560.     xor eax,esi
    561.     add ebx,ebp
    562.     add eax,06FA87E4FH
    563.     add ebx,eax
    564.     rol ebx,06H
    565.     mov eax,esi
    566.     not eax
    567.     add ebx,edx
    568.     mov ebp,dword ptr ds:[ecx + 4*15]
    569.     or eax,ebx
    570.     xor eax,edx
    571.     add edi,ebp
    572.     add eax,0FE2CE6E0H
    573.     add edi,eax
    574.     rol edi,0AH
    575.     mov eax,edx
    576.     not eax
    577.     add edi,ebx
    578.     mov ebp,dword ptr ds:[ecx + 4*6]
    579.     or eax,edi
    580.     xor eax,ebx
    581.     add esi,ebp
    582.     add eax,0A3014314H
    583.     add esi,eax
    584.     rol esi,0FH
    585.     mov eax,ebx
    586.     not eax
    587.     add esi,edi
    588.     mov ebp,dword ptr ds:[ecx + 4*13]
    589.     or eax,esi
    590.     xor eax,edi
    591.     add edx,ebp
    592.     add eax,04E0811A1H
    593.     add edx,eax
    594.     rol edx,15H
    595.     mov eax,edi
    596.     not eax
    597.     add edx,esi
    598.     mov ebp,dword ptr ds:[ecx + 4*4]
    599.     or eax,edx
    600.     xor eax,esi
    601.     add ebx,ebp
    602.     add eax,0F7537E82H
    603.     add ebx,eax
    604.     rol ebx,06H
    605.     mov eax,esi
    606.     not eax
    607.     add ebx,edx
    608.     mov ebp,dword ptr ds:[ecx + 4*11]
    609.     or eax,ebx
    610.     xor eax,edx
    611.     add edi,ebp
    612.     add eax,0BD3AF235H
    613.     add edi,eax
    614.     rol edi,0AH
    615.     mov eax,edx
    616.     not eax
    617.     add edi,ebx
    618.     mov ebp,dword ptr ds:[ecx + 4*2]
    619.     or eax,edi
    620.     xor eax,ebx
    621.     add esi,ebp
    622.     add eax,02AD7D2BBH
    623.     add esi,eax
    624.     rol esi,0FH
    625.     mov eax,ebx
    626.     not eax
    627.     add esi,edi
    628.     mov ebp,dword ptr ds:[ecx + 4*6]
    629.     or eax,esi
    630.     xor eax,edi
    631.     add edx,ebp
    632.     add eax,00EB86D391H
    633.     add edx,eax
    634.     rol edx,15H
    635.     mov eax,dword ptr ss:[esp + 4*5]
    636.     add edx,esi
    637.     mov ecx,dword ptr ds:[eax]
    638.     add ebx,ecx
    639.     mov ecx,dword ptr ds:[eax + 4]
    640.     add edx,ecx
    641.     mov dword ptr ds:[eax],ebx
    642.     mov ecx,dword ptr ds:[eax + 2*4]
    643.     mov dword ptr ds:[eax + 4],edx
    644.     add esi,ecx
    645.     pop ebp
    646.     mov ecx,dword ptr ds:[eax + 3*4]
    647.     mov dword ptr ds:[eax + 2*4],esi
    648.     add edi,ecx
    649.     mov dword ptr ds:[eax + 3*4],edi
    650.     pop edi
    651.     pop esi
    652.     pop ebx
    653.     ret
    654. TransformMD5 endp
    Надеюсь без опечаток.
     
  6. AsmGuru62

    AsmGuru62 Member

    Публикаций:
    0
    Регистрация:
    12 сен 2002
    Сообщения:
    689
    Адрес:
    Toronto
  7. Clerk

    Clerk Забанен

    Публикаций:
    0
    Регистрация:
    4 янв 2008
    Сообщения:
    6.689
    Адрес:
    РБ, Могилёв
    Код (Text):
    1. /*
    2.  ***********************************************************************
    3.  ** md5.c                                                             **
    4.  ** RSA Data Security, Inc. MD5 Message-Digest Algorithm              **
    5.  ** Created: 2/17/90 RLR                                              **
    6.  ** Revised: 1/91 SRD,AJ,BSK,JT Reference C Version                   **
    7.  ***********************************************************************
    8.  */
    9.  
    10. /*
    11.  ***********************************************************************
    12.  ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.  **
    13.  **                                                                   **
    14.  ** License to copy and use this software is granted provided that    **
    15.  ** it is identified as the "RSA Data Security, Inc. MD5 Message-     **
    16.  ** Digest Algorithm" in all material mentioning or referencing this  **
    17.  ** software or this function.                                        **
    18.  **                                                                   **
    19.  ** License is also granted to make and use derivative works          **
    20.  ** provided that such works are identified as "derived from the RSA  **
    21.  ** Data Security, Inc. MD5 Message-Digest Algorithm" in all          **
    22.  ** material mentioning or referencing the derived work.              **
    23.  **                                                                   **
    24.  ** RSA Data Security, Inc. makes no representations concerning       **
    25.  ** either the merchantability of this software or the suitability    **
    26.  ** of this software for any particular purpose.  It is provided "as  **
    27.  ** is" without express or implied warranty of any kind.              **
    28.  **                                                                   **
    29.  ** These notices must be retained in any copies of any part of this  **
    30.  ** documentation and/or software.                                    **
    31.  ***********************************************************************
    32.  */
    33.  
    34. //  Portions copyright (c) 1992 Microsoft Corp.
    35. //  All rights reserved
    36.  
    37.  
    38.  
    39. #include <nt.h>
    40. #define UINT4   ULONG
    41.  
    42. #include "md5.h"
    43.  
    44.  
    45. /* Constants for Transform routine.
    46.  */
    47. #define S11 7
    48. #define S12 12
    49. #define S13 17
    50. #define S14 22
    51. #define S21 5
    52. #define S22 9
    53. #define S23 14
    54. #define S24 20
    55. #define S31 4
    56. #define S32 11
    57. #define S33 16
    58. #define S34 23
    59. #define S41 6
    60. #define S42 10
    61. #define S43 15
    62. #define S44 21
    63.  
    64. static void TransformMD5 PROTO_LIST ((UINT4 *, UINT4 *));
    65.  
    66. static unsigned char PADDING[64] = {
    67.   0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    68.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    69.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    70.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    71.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    72.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    73.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    74.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    75. };
    76.  
    77. /* F, G and H are basic MD5 functions */
    78. #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
    79. #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
    80. #define H(x, y, z) ((x) ^ (y) ^ (z))
    81. #define I(x, y, z) ((y) ^ ((x) | (~z)))
    82.  
    83. /* ROTATE_LEFT rotates x left n bits.
    84.  */
    85. #if CT_COMPILER == CT_MPW
    86.  
    87. /* MPW doesn't compile the macro correctly, so use a procedure. */
    88. static UINT4 RotateLeft (UINT4, unsigned int);
    89. #define ROTATE_LEFT RotateLeft
    90.  
    91. #else
    92. #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
    93. #endif
    94.  
    95. /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
    96. /* Rotation is separate from addition to prevent recomputation */
    97. #define FF(a, b, c, d, x, s, ac) \
    98.   {(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
    99.    (a) = ROTATE_LEFT ((a), (s)); \
    100.    (a) += (b); \
    101.   }
    102. #define GG(a, b, c, d, x, s, ac) \
    103.   {(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
    104.    (a) = ROTATE_LEFT ((a), (s)); \
    105.    (a) += (b); \
    106.   }
    107. #define HH(a, b, c, d, x, s, ac) \
    108.   {(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
    109.    (a) = ROTATE_LEFT ((a), (s)); \
    110.    (a) += (b); \
    111.   }
    112. #define II(a, b, c, d, x, s, ac) \
    113.   {(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
    114.    (a) = ROTATE_LEFT ((a), (s)); \
    115.    (a) += (b); \
    116.   }
    117.  
    118. void MD5Init (mdContext)
    119. MD5_CTX *mdContext;
    120. {
    121.   mdContext->i[0] = mdContext->i[1] = (UINT4)0;
    122.  
    123.   /* Load magic initialization constants.
    124.    */
    125.   mdContext->buf[0] = (UINT4)0x67452301;
    126.   mdContext->buf[1] = (UINT4)0xefcdab89;
    127.   mdContext->buf[2] = (UINT4)0x98badcfe;
    128.   mdContext->buf[3] = (UINT4)0x10325476;
    129. }
    130.  
    131. void MD5Update (mdContext, inBuf, inLen)
    132. MD5_CTX *mdContext;
    133. const unsigned char *inBuf;
    134. unsigned int inLen;
    135. {
    136.   UINT4 in[16];
    137.   int mdi;
    138.   unsigned int i, ii;
    139.  
    140.   /* compute number of bytes mod 64 */
    141.   mdi = (int)((mdContext->i[0] >> 3) & 0x3f);
    142.  
    143.   /* update number of bits */
    144.   if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0])
    145.     mdContext->i[1]++;
    146.   mdContext->i[0] += ((UINT4)inLen << 3);
    147.   mdContext->i[1] += ((UINT4)inLen >> 29);
    148.  
    149.   while (inLen--) {
    150.     /* add new character to buffer, increment mdi */
    151.     mdContext->in[mdi++] = *inBuf++;
    152.  
    153.     /* transform if necessary */
    154.     if (mdi == 0x40) {
    155.       for (i = 0, ii = 0; i < 16; i++, ii += 4)
    156.         in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
    157.                 (((UINT4)mdContext->in[ii+2]) << 16) |
    158.                 (((UINT4)mdContext->in[ii+1]) << 8) |
    159.                 ((UINT4)mdContext->in[ii]);
    160.       TransformMD5 (mdContext->buf, in);
    161.       mdi = 0;
    162.     }
    163.   }
    164. }
    165.  
    166. void MD5Final (mdContext)
    167. MD5_CTX *mdContext;
    168. {
    169.   UINT4 in[16];
    170.   int mdi;
    171.   unsigned int i, ii;
    172.   unsigned int padLen;
    173.  
    174.   /* save number of bits */
    175.   in[14] = mdContext->i[0];
    176.   in[15] = mdContext->i[1];
    177.  
    178.   /* compute number of bytes mod 64 */
    179.   mdi = (int)((mdContext->i[0] >> 3) & 0x3f);
    180.  
    181.   /* pad out to 56 mod 64 */
    182.   padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
    183.   MD5Update (mdContext, PADDING, padLen);
    184.  
    185.   /* append length in bits and transform */
    186.   for (i = 0, ii = 0; i < 14; i++, ii += 4)
    187.     in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
    188.             (((UINT4)mdContext->in[ii+2]) << 16) |
    189.             (((UINT4)mdContext->in[ii+1]) << 8) |
    190.             ((UINT4)mdContext->in[ii]);
    191.   TransformMD5 (mdContext->buf, in);
    192.  
    193.   /* store buffer in digest */
    194.   for (i = 0, ii = 0; i < 4; i++, ii += 4) {
    195.     mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xff);
    196.     mdContext->digest[ii+1] =
    197.       (unsigned char)((mdContext->buf[i] >> 8) & 0xff);
    198.     mdContext->digest[ii+2] =
    199.       (unsigned char)((mdContext->buf[i] >> 16) & 0xff);
    200.     mdContext->digest[ii+3] =
    201.       (unsigned char)((mdContext->buf[i] >> 24) & 0xff);
    202.   }
    203. }
    204.  
    205. /* Basic MD5 step. Transforms buf based on in.
    206.  */
    207. static void TransformMD5 (buf, in)
    208. UINT4 *buf;
    209. UINT4 *in;
    210. {
    211.   UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
    212.  
    213.   /* Round 1 */
    214.   FF ( a, b, c, d, in[ 0], S11, 0xd76aa478); /* 1 */
    215.   FF ( d, a, b, c, in[ 1], S12, 0xe8c7b756); /* 2 */
    216.   FF ( c, d, a, b, in[ 2], S13, 0x242070db); /* 3 */
    217.   FF ( b, c, d, a, in[ 3], S14, 0xc1bdceee); /* 4 */
    218.   FF ( a, b, c, d, in[ 4], S11, 0xf57c0faf); /* 5 */
    219.   FF ( d, a, b, c, in[ 5], S12, 0x4787c62a); /* 6 */
    220.   FF ( c, d, a, b, in[ 6], S13, 0xa8304613); /* 7 */
    221.   FF ( b, c, d, a, in[ 7], S14, 0xfd469501); /* 8 */
    222.   FF ( a, b, c, d, in[ 8], S11, 0x698098d8); /* 9 */
    223.   FF ( d, a, b, c, in[ 9], S12, 0x8b44f7af); /* 10 */
    224.   FF ( c, d, a, b, in[10], S13, 0xffff5bb1); /* 11 */
    225.   FF ( b, c, d, a, in[11], S14, 0x895cd7be); /* 12 */
    226.   FF ( a, b, c, d, in[12], S11, 0x6b901122); /* 13 */
    227.   FF ( d, a, b, c, in[13], S12, 0xfd987193); /* 14 */
    228.   FF ( c, d, a, b, in[14], S13, 0xa679438e); /* 15 */
    229.   FF ( b, c, d, a, in[15], S14, 0x49b40821); /* 16 */
    230.  
    231.   /* Round 2 */
    232.   GG ( a, b, c, d, in[ 1], S21, 0xf61e2562); /* 17 */
    233.   GG ( d, a, b, c, in[ 6], S22, 0xc040b340); /* 18 */
    234.   GG ( c, d, a, b, in[11], S23, 0x265e5a51); /* 19 */
    235.   GG ( b, c, d, a, in[ 0], S24, 0xe9b6c7aa); /* 20 */
    236.   GG ( a, b, c, d, in[ 5], S21, 0xd62f105d); /* 21 */
    237.   GG ( d, a, b, c, in[10], S22,  0x2441453); /* 22 */
    238.   GG ( c, d, a, b, in[15], S23, 0xd8a1e681); /* 23 */
    239.   GG ( b, c, d, a, in[ 4], S24, 0xe7d3fbc8); /* 24 */
    240.   GG ( a, b, c, d, in[ 9], S21, 0x21e1cde6); /* 25 */
    241.   GG ( d, a, b, c, in[14], S22, 0xc33707d6); /* 26 */
    242.   GG ( c, d, a, b, in[ 3], S23, 0xf4d50d87); /* 27 */
    243.   GG ( b, c, d, a, in[ 8], S24, 0x455a14ed); /* 28 */
    244.   GG ( a, b, c, d, in[13], S21, 0xa9e3e905); /* 29 */
    245.   GG ( d, a, b, c, in[ 2], S22, 0xfcefa3f8); /* 30 */
    246.   GG ( c, d, a, b, in[ 7], S23, 0x676f02d9); /* 31 */
    247.   GG ( b, c, d, a, in[12], S24, 0x8d2a4c8a); /* 32 */
    248.  
    249.   /* Round 3 */
    250.   HH ( a, b, c, d, in[ 5], S31, 0xfffa3942); /* 33 */
    251.   HH ( d, a, b, c, in[ 8], S32, 0x8771f681); /* 34 */
    252.   HH ( c, d, a, b, in[11], S33, 0x6d9d6122); /* 35 */
    253.   HH ( b, c, d, a, in[14], S34, 0xfde5380c); /* 36 */
    254.   HH ( a, b, c, d, in[ 1], S31, 0xa4beea44); /* 37 */
    255.   HH ( d, a, b, c, in[ 4], S32, 0x4bdecfa9); /* 38 */
    256.   HH ( c, d, a, b, in[ 7], S33, 0xf6bb4b60); /* 39 */
    257.   HH ( b, c, d, a, in[10], S34, 0xbebfbc70); /* 40 */
    258.   HH ( a, b, c, d, in[13], S31, 0x289b7ec6); /* 41 */
    259.   HH ( d, a, b, c, in[ 0], S32, 0xeaa127fa); /* 42 */
    260.   HH ( c, d, a, b, in[ 3], S33, 0xd4ef3085); /* 43 */
    261.   HH ( b, c, d, a, in[ 6], S34,  0x4881d05); /* 44 */
    262.   HH ( a, b, c, d, in[ 9], S31, 0xd9d4d039); /* 45 */
    263.   HH ( d, a, b, c, in[12], S32, 0xe6db99e5); /* 46 */
    264.   HH ( c, d, a, b, in[15], S33, 0x1fa27cf8); /* 47 */
    265.   HH ( b, c, d, a, in[ 2], S34, 0xc4ac5665); /* 48 */
    266.  
    267.   /* Round 4 */
    268.   II ( a, b, c, d, in[ 0], S41, 0xf4292244); /* 49 */
    269.   II ( d, a, b, c, in[ 7], S42, 0x432aff97); /* 50 */
    270.   II ( c, d, a, b, in[14], S43, 0xab9423a7); /* 51 */
    271.   II ( b, c, d, a, in[ 5], S44, 0xfc93a039); /* 52 */
    272.   II ( a, b, c, d, in[12], S41, 0x655b59c3); /* 53 */
    273.   II ( d, a, b, c, in[ 3], S42, 0x8f0ccc92); /* 54 */
    274.   II ( c, d, a, b, in[10], S43, 0xffeff47d); /* 55 */
    275.   II ( b, c, d, a, in[ 1], S44, 0x85845dd1); /* 56 */
    276.   II ( a, b, c, d, in[ 8], S41, 0x6fa87e4f); /* 57 */
    277.   II ( d, a, b, c, in[15], S42, 0xfe2ce6e0); /* 58 */
    278.   II ( c, d, a, b, in[ 6], S43, 0xa3014314); /* 59 */
    279.   II ( b, c, d, a, in[13], S44, 0x4e0811a1); /* 60 */
    280.   II ( a, b, c, d, in[ 4], S41, 0xf7537e82); /* 61 */
    281.   II ( d, a, b, c, in[11], S42, 0xbd3af235); /* 62 */
    282.   II ( c, d, a, b, in[ 2], S43, 0x2ad7d2bb); /* 63 */
    283.   II ( b, c, d, a, in[ 9], S44, 0xeb86d391); /* 64 */
    284.  
    285.   buf[0] += a;
    286.   buf[1] += b;
    287.   buf[2] += c;
    288.   buf[3] += d;
    289. }
    290.  
    291. #if CT_COMPILER == CT_MPW
    292. static UINT4 RotateLeft (x, n)
    293. UINT4 x;
    294. unsigned int n;
    295. {
    296.   return (((x) << (n)) | ((x) >> (32-(n))));
    297. }
    298. #endif
     
  8. VictorV79

    VictorV79 New Member

    Публикаций:
    0
    Регистрация:
    26 мар 2009
    Сообщения:
    130
    У ся код прогнал для интереса
    вроде без опечаток
    прошёл полностью

    http://ru.wikipedia.org/wiki/MD5
     
  9. l_inc

    l_inc New Member

    Публикаций:
    0
    Регистрация:
    29 сен 2005
    Сообщения:
    2.566