]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/rand/rand_vms.c
2 * Copyright 2001-2017 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
12 #if defined(OPENSSL_SYS_VMS)
13 # include <openssl/rand.h>
14 # include "internal/rand_int.h"
15 # include "rand_lcl.h"
22 # pragma message disable DOLLARID
25 # ifndef OPENSSL_RAND_SEED_OS
26 # error "Unsupported seeding method configured; must be os"
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
41 static struct items_data_st
{
42 short length
, code
; /* length is number of bytes */
48 {8, JPI$_LAST_LOGIN_I
},
58 size_t rand_pool_acquire_entropy(RAND_POOL
*pool
)
60 /* determine the number of items in the JPI array */
61 struct items_data_st item_entry
;
62 int item_entry_count
= OSSL_NELEM(items_data
);
63 /* Create the JPI itemlist array to hold item_data content */
68 } item
[item_entry_count
], *pitem
;
69 struct items_data_st
*pitems_data
;
70 int data_buffer
[(item_entry_count
* 2) + 4]; /* 8 bytes per entry max */
78 /* Setup itemlist for GETJPI */
79 pitems_data
= items_data
;
80 for (pitem
= item
; pitems_data
->length
!= 0; pitem
++) {
81 pitem
->length
= pitems_data
->length
;
82 pitem
->code
= pitems_data
->code
;
83 pitem
->buffer
= &data_buffer
[total_length
];
85 /* total_length is in longwords */
86 total_length
+= pitems_data
->length
/ 4;
89 pitem
->length
= pitem
->code
= 0;
91 /* Fill data_buffer with various info bits from this process */
92 if (sys$
getjpiw(EFN$C_ENF
, NULL
, NULL
, item
, &iosb
, 0, 0) != SS$_NORMAL
)
95 /* Now twist that data to seed the SSL random number init */
96 for (i
= 0; i
< total_length
; i
++) {
97 sys$
gettim((struct _generic_64
*)&sys_time
[0]);
98 srand(sys_time
[0] * data_buffer
[0] * data_buffer
[1] + i
);
100 if (i
== (total_length
- 1)) { /* for JPI$_FINALEXC */
101 ptr
= &data_buffer
[i
];
102 for (j
= 0; j
< 4; j
++) {
103 data_buffer
[i
+ j
] = ptr
[j
];
104 /* OK to use rand() just to scramble the seed */
105 data_buffer
[i
+ j
] ^= (sys_time
[0] ^ rand());
109 /* OK to use rand() just to scramble the seed */
110 data_buffer
[i
] ^= (sys_time
[0] ^ rand());
114 total_length
+= (tmp_length
- 1);
117 * Size of seed is total_length*4 bytes (64bytes). The original assumption
118 * was that it contains 4 bits of entropy per byte. This makes a total
119 * amount of total_length*16 bits (256bits).
121 return rand_pool_add(pool
,
122 (PTR_T
)data_buffer
, total_length
* 4,