2004-09-17 18:15:28 +00:00
|
|
|
/*
|
|
|
|
* Unit tests for SHA functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Filip Navara
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-09-17 18:15:28 +00:00
|
|
|
*/
|
|
|
|
|
2004-10-04 19:31:17 +00:00
|
|
|
#include <stdarg.h>
|
2004-09-17 18:15:28 +00:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
|
2004-10-04 19:31:17 +00:00
|
|
|
#include "wine/test.h"
|
|
|
|
|
2004-09-17 18:15:28 +00:00
|
|
|
typedef struct {
|
|
|
|
ULONG Unknown[6];
|
|
|
|
ULONG State[5];
|
|
|
|
ULONG Count[2];
|
|
|
|
UCHAR Buffer[64];
|
|
|
|
} SHA_CTX, *PSHA_CTX;
|
|
|
|
|
2004-10-04 19:31:17 +00:00
|
|
|
static void test_sha_ctx(void)
|
2004-09-17 18:15:28 +00:00
|
|
|
{
|
2009-09-09 11:13:25 +00:00
|
|
|
void (WINAPI *pA_SHAInit)(PSHA_CTX);
|
|
|
|
void (WINAPI *pA_SHAUpdate)(PSHA_CTX, const unsigned char *, UINT);
|
|
|
|
void (WINAPI *pA_SHAFinal)(PSHA_CTX, PULONG);
|
|
|
|
static const unsigned char test_buffer[] = "In our Life there's If"
|
|
|
|
"In our beliefs there's Lie"
|
|
|
|
"In our business there is Sin"
|
|
|
|
"In our bodies, there is Die";
|
2004-09-17 18:15:28 +00:00
|
|
|
HMODULE hmod;
|
|
|
|
SHA_CTX ctx;
|
|
|
|
ULONG result[5];
|
|
|
|
ULONG result_correct[5] = {0xe014f93, 0xe09791ec, 0x6dcf96c8, 0x8e9385fc, 0x1611c1bb};
|
|
|
|
|
2007-03-13 18:41:01 +00:00
|
|
|
hmod = GetModuleHandleA("advapi32.dll");
|
2009-09-09 11:13:25 +00:00
|
|
|
pA_SHAInit = (void *)GetProcAddress(hmod, "A_SHAInit");
|
|
|
|
pA_SHAUpdate = (void *)GetProcAddress(hmod, "A_SHAUpdate");
|
|
|
|
pA_SHAFinal = (void *)GetProcAddress(hmod, "A_SHAFinal");
|
2004-10-04 19:31:17 +00:00
|
|
|
|
2007-03-13 18:41:01 +00:00
|
|
|
if (!pA_SHAInit || !pA_SHAUpdate || !pA_SHAFinal)
|
|
|
|
{
|
2009-02-26 08:45:07 +00:00
|
|
|
win_skip("A_SHAInit and/or A_SHAUpdate and/or A_SHAFinal are not available\n");
|
2007-03-13 18:41:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-09-17 18:15:28 +00:00
|
|
|
|
|
|
|
RtlZeroMemory(&ctx, sizeof(ctx));
|
|
|
|
pA_SHAInit(&ctx);
|
2009-09-09 11:13:25 +00:00
|
|
|
pA_SHAUpdate(&ctx, test_buffer, sizeof(test_buffer)-1);
|
|
|
|
pA_SHAUpdate(&ctx, test_buffer, sizeof(test_buffer)-1);
|
2004-09-17 18:15:28 +00:00
|
|
|
pA_SHAFinal(&ctx, result);
|
|
|
|
ok(!memcmp(result, result_correct, sizeof(result)), "incorrect result\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(crypt_sha)
|
|
|
|
{
|
|
|
|
test_sha_ctx();
|
|
|
|
}
|