1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
#include "apr_private.h"
19
#include "apr_general.h"
20
#include "apr_portable.h"
21
#include "apr_arch_misc.h"
25
APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf,
29
apr_status_t res = APR_SUCCESS;
31
/* 0x40 bit = CRYPT_SILENT, only introduced in more recent PSDKs
32
* and will only work for Win2K and later.
34
DWORD flags = CRYPT_VERIFYCONTEXT
35
| ((apr_os_level >= APR_WIN_2000) ? 0x40 : 0);
37
if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, flags)) {
38
return apr_get_os_error();
40
/* XXX: An ugly hack for Win64, randomness is such that noone should
41
* ever expect > 2^31 bytes of data at once without the prng
42
* coming to a complete halt.
44
if (!CryptGenRandom(hProv, (DWORD)length, buf)) {
45
res = apr_get_os_error();
47
CryptReleaseContext(hProv, 0);
52
APR_DECLARE(apr_status_t) apr_os_uuid_get(unsigned char *uuid_data)
54
/* Note: this call doesn't actually require CoInitialize() first
56
* XXX: we should scramble the bytes or some such to eliminate the
57
* possible misuse/abuse since uuid is based on the NIC address, and
58
* is therefore not only a uniqifier, but an identity (which might not
59
* be appropriate in all cases.
61
* Note that Win2000, XP and later no longer suffer from this problem,
62
* a scrambling fix is only needed for (apr_os_level < APR_WIN_2000)
64
if (FAILED(UuidCreate((UUID *)uuid_data))) {