push 5f793418e14616d83a4fb368b755a8821b49820b
[wine/hacks.git] / dlls / advapi32 / tests / crypt_sha.c
blob025f2cdcd47496cbc46788f20eccf4acc7a1e2c3
1 /*
2 * Unit tests for SHA functions
4 * Copyright (c) 2004 Filip Navara
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.
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.
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
27 #include "wine/test.h"
29 typedef struct {
30 ULONG Unknown[6];
31 ULONG State[5];
32 ULONG Count[2];
33 UCHAR Buffer[64];
34 } SHA_CTX, *PSHA_CTX;
36 static void test_sha_ctx(void)
38 FARPROC pA_SHAInit, pA_SHAUpdate, pA_SHAFinal;
39 static const char test_buffer[] = "In our Life there's If"
40 "In our beliefs there's Lie"
41 "In our business there is Sin"
42 "In our bodies, there is Die";
43 ULONG test_buffer_size = strlen(test_buffer);
44 HMODULE hmod;
45 SHA_CTX ctx;
46 ULONG result[5];
47 ULONG result_correct[5] = {0xe014f93, 0xe09791ec, 0x6dcf96c8, 0x8e9385fc, 0x1611c1bb};
49 hmod = GetModuleHandleA("advapi32.dll");
50 pA_SHAInit = GetProcAddress(hmod, "A_SHAInit");
51 pA_SHAUpdate = GetProcAddress(hmod, "A_SHAUpdate");
52 pA_SHAFinal = GetProcAddress(hmod, "A_SHAFinal");
54 if (!pA_SHAInit || !pA_SHAUpdate || !pA_SHAFinal)
56 win_skip("A_SHAInit and/or A_SHAUpdate and/or A_SHAFinal are not available\n");
57 return;
60 RtlZeroMemory(&ctx, sizeof(ctx));
61 pA_SHAInit(&ctx);
62 pA_SHAUpdate(&ctx, test_buffer, test_buffer_size);
63 pA_SHAUpdate(&ctx, test_buffer, test_buffer_size);
64 pA_SHAFinal(&ctx, result);
65 ok(!memcmp(result, result_correct, sizeof(result)), "incorrect result\n");
68 START_TEST(crypt_sha)
70 test_sha_ctx();