]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/rand/rand_vms.c
crypto/rand/rand_vms.c: include "internal/rand_int.h"
[thirdparty/openssl.git] / crypto / rand / rand_vms.c
CommitLineData
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 13# include <openssl/rand.h>
93bf1945 14# include "internal/rand_int.h"
da8fc25a 15# include "rand_lcl.h"
0f113f3e
MC
16# include <descrip.h>
17# include <jpidef.h>
18# include <ssdef.h>
19# include <starlet.h>
5fc2c689 20# include <efndef>
0f113f3e
MC
21# ifdef __DECC
22# pragma message disable DOLLARID
23# endif
0c61e299 24
8389ec4b
RS
25# ifndef OPENSSL_RAND_SEED_OS
26# error "Unsupported seeding method configured; must be os"
27# endif
28
0f113f3e
MC
29/*
30 * Use 32-bit pointers almost everywhere. Define the type to which to cast a
31 * pointer passed to an external function.
537c9823 32 */
0f113f3e
MC
33# if __INITIAL_POINTER_SIZE == 64
34# define PTR_T __void_ptr64
35# pragma pointer_size save
36# pragma pointer_size 32
da8fc25a 37# else
0f113f3e 38# define PTR_T void *
da8fc25a 39# endif
0f113f3e
MC
40
41static struct items_data_st {
5fc2c689 42 short length, code; /* length is number of bytes */
0f113f3e 43} items_data[] = {
5fc2c689
RL
44 {4, JPI$_BUFIO},
45 {4, JPI$_CPUTIM},
46 {4, JPI$_DIRIO},
47 {4, JPI$_IMAGECOUNT},
48 {8, JPI$_LAST_LOGIN_I},
49 {8, JPI$_LOGINTIM},
50 {4, JPI$_PAGEFLTS},
51 {4, JPI$_PID},
52 {4, JPI$_PPGCNT},
53 {4, JPI$_WSPEAK},
54 {4, JPI$_FINALEXC},
da8fc25a 55 {0, 0}
0f113f3e 56};
537c9823 57
6decf943 58size_t rand_pool_acquire_entropy(RAND_POOL *pool)
0f113f3e 59{
5fc2c689 60 /* determine the number of items in the JPI array */
5fc2c689 61 struct items_data_st item_entry;
da8fc25a 62 int item_entry_count = OSSL_NELEM(items_data);
5fc2c689 63 /* Create the JPI itemlist array to hold item_data content */
0f113f3e
MC
64 struct {
65 short length, code;
5fc2c689 66 int *buffer;
0f113f3e 67 int *retlen;
da8fc25a 68 } item[item_entry_count], *pitem;
0f113f3e 69 struct items_data_st *pitems_data;
da8fc25a 70 int data_buffer[(item_entry_count * 2) + 4]; /* 8 bytes per entry max */
5fc2c689
RL
71 int iosb[2];
72 int sys_time[2];
73 int *ptr;
74 int i, j ;
75 int tmp_length = 0;
76 int total_length = 0;
73986238 77
5fc2c689 78 /* Setup itemlist for GETJPI */
da8fc25a
RS
79 pitems_data = items_data;
80 for (pitem = item; pitems_data->length != 0; pitem++) {
0f113f3e 81 pitem->length = pitems_data->length;
5fc2c689
RL
82 pitem->code = pitems_data->code;
83 pitem->buffer = &data_buffer[total_length];
0f113f3e 84 pitem->retlen = 0;
5fc2c689 85 /* total_length is in longwords */
da8fc25a 86 total_length += pitems_data->length / 4;
0f113f3e 87 pitems_data++;
0f113f3e
MC
88 }
89 pitem->length = pitem->code = 0;
73986238 90
5fc2c689 91 /* Fill data_buffer with various info bits from this process */
da8fc25a
RS
92 if (sys$getjpiw(EFN$C_ENF, NULL, NULL, item, &iosb, 0, 0) != SS$_NORMAL)
93 return 0;
5fc2c689 94
da8fc25a
RS
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);
5fc2c689 99
da8fc25a
RS
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];
5fc2c689 104 /* OK to use rand() just to scramble the seed */
da8fc25a
RS
105 data_buffer[i + j] ^= (sys_time[0] ^ rand());
106 tmp_length++;
5fc2c689 107 }
da8fc25a
RS
108 } else {
109 /* OK to use rand() just to scramble the seed */
110 data_buffer[i] ^= (sys_time[0] ^ rand());
0f113f3e
MC
111 }
112 }
5fc2c689 113
da8fc25a
RS
114 total_length += (tmp_length - 1);
115
c16de9d8
DMSP
116 /*
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).
120 */
6decf943 121 return rand_pool_add(pool,
c16de9d8
DMSP
122 (PTR_T)data_buffer, total_length * 4,
123 total_length * 16);
0c61e299
RL
124}
125
126#endif