1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. 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.
20 #include "apr_private.h"
21 #include "apr_general.h"
22 #include "apr_portable.h"
23 #include "apr_arch_misc.h"
26 APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf,
30 apr_status_t res = APR_SUCCESS;
32 /* 0x40 bit = CRYPT_SILENT, only introduced in more recent PSDKs
33 * and will only work for Win2K and later.
35 DWORD flags = CRYPT_VERIFYCONTEXT
36 | ((apr_os_level >= APR_WIN_2000) ? 0x40 : 0);
38 if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, flags)) {
39 return apr_get_os_error();
41 /* XXX: An ugly hack for Win64, randomness is such that noone should
42 * ever expect > 2^31 bytes of data at once without the prng
43 * coming to a complete halt.
45 if (!CryptGenRandom(hProv, (DWORD)length, buf)) {
46 res = apr_get_os_error();
48 CryptReleaseContext(hProv, 0);
53 APR_DECLARE(apr_status_t) apr_os_uuid_get(unsigned char *uuid_data)
55 /* Note: this call doesn't actually require CoInitialize() first
57 * XXX: we should scramble the bytes or some such to eliminate the
58 * possible misuse/abuse since uuid is based on the NIC address, and
59 * is therefore not only a uniqifier, but an identity (which might not
60 * be appropriate in all cases.
62 * Note that Win2000, XP and later no longer suffer from this problem,
63 * a scrambling fix is only needed for (apr_os_level < APR_WIN_2000)
65 if (FAILED(UuidCreate((UUID *)uuid_data))) {