]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/rand/rand_vms.c
2 * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 * Modified by VMS Software, Inc (2016)
12 * Eliminate looping through all processes (performance)
13 * Add additional randomizations using rand() function
16 #include <openssl/rand.h>
19 #if defined(OPENSSL_SYS_VMS)
26 # pragma message disable DOLLARID
30 * Use 32-bit pointers almost everywhere. Define the type to which to cast a
31 * pointer passed to an external function.
33 # if __INITIAL_POINTER_SIZE == 64
34 # define PTR_T __void_ptr64
35 # pragma pointer_size save
36 # pragma pointer_size 32
37 # else /* __INITIAL_POINTER_SIZE == 64 */
39 # endif /* __INITIAL_POINTER_SIZE == 64 [else] */
41 static struct items_data_st
{
42 short length
, code
; /* length is number of bytes */
48 {8, JPI$_LAST_LOGIN_I
},
55 {0, 0} /* zero terminated */
61 /* determine the number of items in the JPI array */
63 struct items_data_st item_entry
;
64 int item_entry_count
= sizeof(items_data
)/sizeof(item_entry
);
66 /* Create the JPI itemlist array to hold item_data content */
72 } item
[item_entry_count
], *pitem
; /* number of entries in items_data */
74 struct items_data_st
*pitems_data
;
75 int data_buffer
[(item_entry_count
*2)+4]; /* 8 bytes per entry max */
83 pitems_data
= items_data
;
87 /* Setup itemlist for GETJPI */
88 while (pitems_data
->length
) {
89 pitem
->length
= pitems_data
->length
;
90 pitem
->code
= pitems_data
->code
;
91 pitem
->buffer
= &data_buffer
[total_length
];
93 /* total_length is in longwords */
94 total_length
+= pitems_data
->length
/4;
98 pitem
->length
= pitem
->code
= 0;
100 /* Fill data_buffer with various info bits from this process */
101 /* and twist that data to seed the SSL random number init */
103 if (sys$
getjpiw(EFN$C_ENF
, NULL
, NULL
, item
, &iosb
, 0, 0) == SS$_NORMAL
) {
104 for (i
= 0; i
< total_length
; i
++) {
105 sys$
gettim((struct _generic_64
*)&sys_time
[0]);
106 srand(sys_time
[0] * data_buffer
[0] * data_buffer
[1] + i
);
108 if (i
== (total_length
- 1)) { /* for JPI$_FINALEXC */
109 ptr
= &data_buffer
[i
];
110 for (j
= 0; j
< 4; j
++) {
111 data_buffer
[i
+ j
] = ptr
[j
];
112 /* OK to use rand() just to scramble the seed */
113 data_buffer
[i
+ j
] ^= (sys_time
[0] ^ rand());
117 /* OK to use rand() just to scramble the seed */
118 data_buffer
[i
] ^= (sys_time
[0] ^ rand());
122 total_length
+= (tmp_length
- 1);
124 /* size of seed is total_length*4 bytes (64bytes) */
125 RAND_add((PTR_T
) data_buffer
, total_length
*4, total_length
* 2);