1 /* 2 * Unit tests for SHA functions 3 * 4 * Copyright (c) 2004 Filip Navara 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 */ 20 21 #include "precomp.h" 22 23 typedef struct { 24 ULONG Unknown[6]; 25 ULONG State[5]; 26 ULONG Count[2]; 27 UCHAR Buffer[64]; 28 } SHA_CTX, *PSHA_CTX; 29 30 static void test_sha_ctx(void) 31 { 32 void (WINAPI *pA_SHAInit)(PSHA_CTX); 33 void (WINAPI *pA_SHAUpdate)(PSHA_CTX, const unsigned char *, UINT); 34 void (WINAPI *pA_SHAFinal)(PSHA_CTX, PULONG); 35 static const unsigned char test_buffer[] = "In our Life there's If" 36 "In our beliefs there's Lie" 37 "In our business there is Sin" 38 "In our bodies, there is Die"; 39 HMODULE hmod; 40 SHA_CTX ctx; 41 ULONG result[5]; 42 ULONG result_correct[5] = {0xe014f93, 0xe09791ec, 0x6dcf96c8, 0x8e9385fc, 0x1611c1bb}; 43 44 hmod = GetModuleHandleA("advapi32.dll"); 45 pA_SHAInit = (void *)GetProcAddress(hmod, "A_SHAInit"); 46 pA_SHAUpdate = (void *)GetProcAddress(hmod, "A_SHAUpdate"); 47 pA_SHAFinal = (void *)GetProcAddress(hmod, "A_SHAFinal"); 48 49 if (!pA_SHAInit || !pA_SHAUpdate || !pA_SHAFinal) 50 { 51 win_skip("A_SHAInit and/or A_SHAUpdate and/or A_SHAFinal are not available\n"); 52 return; 53 } 54 55 RtlZeroMemory(&ctx, sizeof(ctx)); 56 pA_SHAInit(&ctx); 57 pA_SHAUpdate(&ctx, test_buffer, sizeof(test_buffer)-1); 58 pA_SHAUpdate(&ctx, test_buffer, sizeof(test_buffer)-1); 59 pA_SHAFinal(&ctx, result); 60 ok(!memcmp(result, result_correct, sizeof(result)), "incorrect result\n"); 61 } 62 63 START_TEST(crypt_sha) 64 { 65 test_sha_ctx(); 66 } 67