1 /* crypto/rand/rand_vms.c */
3 * Written by Richard Levitte <richard@levitte.org> for the OpenSSL project
7 * Modified by VMS Software, Inc (2016)
8 * Eliminate looping through all processes (performance)
9 * Add additional randomizations using rand() function
11 /* ====================================================================
12 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in
23 * the documentation and/or other materials provided with the
26 * 3. All advertising materials mentioning features or use of this
27 * software must display the following acknowledgment:
28 * "This product includes software developed by the OpenSSL Project
29 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
31 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
32 * endorse or promote products derived from this software without
33 * prior written permission. For written permission, please contact
34 * openssl-core@openssl.org.
36 * 5. Products derived from this software may not be called "OpenSSL"
37 * nor may "OpenSSL" appear in their names without prior written
38 * permission of the OpenSSL Project.
40 * 6. Redistributions of any form whatsoever must retain the following
42 * "This product includes software developed by the OpenSSL Project
43 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
45 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
46 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
49 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
52 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
54 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
56 * OF THE POSSIBILITY OF SUCH DAMAGE.
57 * ====================================================================
59 * This product includes cryptographic software written by Eric Young
60 * (eay@cryptsoft.com). This product includes software written by Tim
61 * Hudson (tjh@cryptsoft.com).
65 #include <openssl/rand.h>
68 #if defined(OPENSSL_SYS_VMS)
75 # pragma message disable DOLLARID
79 * Use 32-bit pointers almost everywhere. Define the type to which to cast a
80 * pointer passed to an external function.
82 # if __INITIAL_POINTER_SIZE == 64
83 # define PTR_T __void_ptr64
84 # pragma pointer_size save
85 # pragma pointer_size 32
86 # else /* __INITIAL_POINTER_SIZE == 64 */
88 # endif /* __INITIAL_POINTER_SIZE == 64 [else] */
90 static struct items_data_st {
91 short length, code; /* length is number of bytes */
97 {8, JPI$_LAST_LOGIN_I},
104 {0, 0} /* zero terminated */
110 /* determine the number of items in the JPI array */
112 struct items_data_st item_entry;
113 int item_entry_count = sizeof(items_data)/sizeof(item_entry);
115 /* Create the JPI itemlist array to hold item_data content */
121 } item[item_entry_count], *pitem; /* number of entries in items_data */
123 struct items_data_st *pitems_data;
124 pitems_data = items_data;
126 int data_buffer[(item_entry_count*2)+4]; /* 8 bytes per entry max */
132 int total_length = 0;
134 /* Setup itemlist for GETJPI */
136 while (pitems_data->length) {
137 pitem->length = pitems_data->length;
138 pitem->code = pitems_data->code;
139 pitem->buffer = &data_buffer[total_length];
141 /* total_length is in longwords */
142 total_length += pitems_data->length/4;
146 pitem->length = pitem->code = 0;
148 /* Fill data_buffer with various info bits from this process */
149 /* and twist that data to seed the SSL random number init */
151 if (sys$getjpiw(EFN$C_ENF, NULL, NULL, item, &iosb, 0, 0) == SS$_NORMAL) {
152 for (i = 0; i < total_length; i++) {
153 sys$gettim((struct _generic_64 *)&sys_time[0]);
154 srand(sys_time[0] * data_buffer[0] * data_buffer[1] + i);
156 if (i == (total_length - 1)) { /* for JPI$_FINALEXC */
157 ptr = &data_buffer[i];
158 for (j = 0; j < 4; j++) {
159 data_buffer[i + j] = ptr[j];
160 /* OK to use rand() just to scramble the seed */
161 data_buffer[i + j] ^= (sys_time[0] ^ rand());
165 /* OK to use rand() just to scramble the seed */
166 data_buffer[i] ^= (sys_time[0] ^ rand());
170 total_length += (tmp_length - 1);
172 /* size of seed is total_length*4 bytes (64bytes) */
173 RAND_add((PTR_T) data_buffer, total_length*4, total_length * 2);