2 * Unit tests for rsabase functions
4 * Copyright (c) 2004 Michael Jung
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
22 #include "wine/test.h"
29 static const char szContainer[] = "Wine Test Container";
30 static const char szProvider[] = MS_DEF_PROV_A;
32 static int init_environment(void)
34 hProv = (HCRYPTPROV)INVALID_HANDLE_VALUE;
36 if (!CryptAcquireContext(&hProv, szContainer, szProvider, PROV_RSA_FULL, 0))
38 if (GetLastError()==NTE_BAD_KEYSET)
40 if(!CryptAcquireContext(&hProv, szContainer, szProvider, PROV_RSA_FULL, CRYPT_NEWKEYSET))
42 trace("%08x\n", (unsigned int)GetLastError());
48 trace("%08x\n", (unsigned int)GetLastError());
56 static void clean_up_environment(void)
58 CryptAcquireContext(&hProv, szContainer, szProvider, PROV_RSA_FULL, CRYPT_DELETEKEYSET);
61 static void test_gen_random(void)
64 BYTE rnd1[16], rnd2[16];
66 memset(rnd1, 0, sizeof(rnd1));
67 memset(rnd2, 0, sizeof(rnd2));
69 result = CryptGenRandom(hProv, sizeof(rnd1), rnd1);
70 ok(result, "%08x\n", (unsigned int)GetLastError());
72 result = CryptGenRandom(hProv, sizeof(rnd2), rnd2);
73 ok(result, "%08x\n", (unsigned int)GetLastError());
75 ok(memcmp(rnd1, rnd2, sizeof(rnd1)), "CryptGenRandom generates non random data\n");
80 if (!init_environment())
83 clean_up_environment();