]>
Commit | Line | Data |
---|---|---|
0f113f3e | 1 | /* |
8389ec4b | 2 | * Copyright 2001-2017 The OpenSSL Project Authors. All Rights Reserved. |
0c61e299 | 3 | * |
b1322259 RS |
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 | |
0c61e299 RL |
8 | */ |
9 | ||
da8fc25a | 10 | #include "e_os.h" |
0c61e299 | 11 | |
bc36ee62 | 12 | #if defined(OPENSSL_SYS_VMS) |
da8fc25a RS |
13 | # include <openssl/rand.h> |
14 | # include "rand_lcl.h" | |
0f113f3e MC |
15 | # include <descrip.h> |
16 | # include <jpidef.h> | |
17 | # include <ssdef.h> | |
18 | # include <starlet.h> | |
5fc2c689 | 19 | # include <efndef> |
0f113f3e MC |
20 | # ifdef __DECC |
21 | # pragma message disable DOLLARID | |
22 | # endif | |
0c61e299 | 23 | |
8389ec4b RS |
24 | # ifndef OPENSSL_RAND_SEED_OS |
25 | # error "Unsupported seeding method configured; must be os" | |
26 | # endif | |
27 | ||
0f113f3e MC |
28 | /* |
29 | * Use 32-bit pointers almost everywhere. Define the type to which to cast a | |
30 | * pointer passed to an external function. | |
537c9823 | 31 | */ |
0f113f3e MC |
32 | # if __INITIAL_POINTER_SIZE == 64 |
33 | # define PTR_T __void_ptr64 | |
34 | # pragma pointer_size save | |
35 | # pragma pointer_size 32 | |
da8fc25a | 36 | # else |
0f113f3e | 37 | # define PTR_T void * |
da8fc25a | 38 | # endif |
0f113f3e MC |
39 | |
40 | static struct items_data_st { | |
5fc2c689 | 41 | short length, code; /* length is number of bytes */ |
0f113f3e | 42 | } items_data[] = { |
5fc2c689 RL |
43 | {4, JPI$_BUFIO}, |
44 | {4, JPI$_CPUTIM}, | |
45 | {4, JPI$_DIRIO}, | |
46 | {4, JPI$_IMAGECOUNT}, | |
47 | {8, JPI$_LAST_LOGIN_I}, | |
48 | {8, JPI$_LOGINTIM}, | |
49 | {4, JPI$_PAGEFLTS}, | |
50 | {4, JPI$_PID}, | |
51 | {4, JPI$_PPGCNT}, | |
52 | {4, JPI$_WSPEAK}, | |
53 | {4, JPI$_FINALEXC}, | |
da8fc25a | 54 | {0, 0} |
0f113f3e | 55 | }; |
537c9823 | 56 | |
4871fa49 | 57 | int RAND_poll_ex(RAND_poll_cb rand_add, void *arg) |
0f113f3e | 58 | { |
5fc2c689 | 59 | /* determine the number of items in the JPI array */ |
5fc2c689 | 60 | struct items_data_st item_entry; |
da8fc25a | 61 | int item_entry_count = OSSL_NELEM(items_data); |
5fc2c689 | 62 | /* Create the JPI itemlist array to hold item_data content */ |
0f113f3e MC |
63 | struct { |
64 | short length, code; | |
5fc2c689 | 65 | int *buffer; |
0f113f3e | 66 | int *retlen; |
da8fc25a | 67 | } item[item_entry_count], *pitem; |
0f113f3e | 68 | struct items_data_st *pitems_data; |
da8fc25a | 69 | int data_buffer[(item_entry_count * 2) + 4]; /* 8 bytes per entry max */ |
5fc2c689 RL |
70 | int iosb[2]; |
71 | int sys_time[2]; | |
72 | int *ptr; | |
73 | int i, j ; | |
74 | int tmp_length = 0; | |
75 | int total_length = 0; | |
73986238 | 76 | |
5fc2c689 | 77 | /* Setup itemlist for GETJPI */ |
da8fc25a RS |
78 | pitems_data = items_data; |
79 | for (pitem = item; pitems_data->length != 0; pitem++) { | |
0f113f3e | 80 | pitem->length = pitems_data->length; |
5fc2c689 RL |
81 | pitem->code = pitems_data->code; |
82 | pitem->buffer = &data_buffer[total_length]; | |
0f113f3e | 83 | pitem->retlen = 0; |
5fc2c689 | 84 | /* total_length is in longwords */ |
da8fc25a | 85 | total_length += pitems_data->length / 4; |
0f113f3e | 86 | pitems_data++; |
0f113f3e MC |
87 | } |
88 | pitem->length = pitem->code = 0; | |
73986238 | 89 | |
5fc2c689 | 90 | /* Fill data_buffer with various info bits from this process */ |
da8fc25a RS |
91 | if (sys$getjpiw(EFN$C_ENF, NULL, NULL, item, &iosb, 0, 0) != SS$_NORMAL) |
92 | return 0; | |
5fc2c689 | 93 | |
da8fc25a RS |
94 | /* Now twist that data to seed the SSL random number init */ |
95 | for (i = 0; i < total_length; i++) { | |
96 | sys$gettim((struct _generic_64 *)&sys_time[0]); | |
97 | srand(sys_time[0] * data_buffer[0] * data_buffer[1] + i); | |
5fc2c689 | 98 | |
da8fc25a RS |
99 | if (i == (total_length - 1)) { /* for JPI$_FINALEXC */ |
100 | ptr = &data_buffer[i]; | |
101 | for (j = 0; j < 4; j++) { | |
102 | data_buffer[i + j] = ptr[j]; | |
5fc2c689 | 103 | /* OK to use rand() just to scramble the seed */ |
da8fc25a RS |
104 | data_buffer[i + j] ^= (sys_time[0] ^ rand()); |
105 | tmp_length++; | |
5fc2c689 | 106 | } |
da8fc25a RS |
107 | } else { |
108 | /* OK to use rand() just to scramble the seed */ | |
109 | data_buffer[i] ^= (sys_time[0] ^ rand()); | |
0f113f3e MC |
110 | } |
111 | } | |
5fc2c689 | 112 | |
da8fc25a RS |
113 | total_length += (tmp_length - 1); |
114 | ||
115 | /* size of seed is total_length*4 bytes (64bytes) */ | |
4871fa49 | 116 | rand_add(arg, (PTR_T)data_buffer, total_length * 4, total_length * 2); |
0f113f3e | 117 | return 1; |
0c61e299 RL |
118 | } |
119 | ||
120 | #endif |