rand_vms.c revision 296465
1273438Sdelphij/* crypto/rand/rand_vms.c -*- mode:C; c-file-style: "eay" -*- */ 2273438Sdelphij/* 3273438Sdelphij * Written by Richard Levitte <richard@levitte.org> for the OpenSSL project 4273438Sdelphij * 2000. 5273438Sdelphij */ 6273438Sdelphij/* ==================================================================== 7273438Sdelphij * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. 8273438Sdelphij * 9273438Sdelphij * Redistribution and use in source and binary forms, with or without 10273438Sdelphij * modification, are permitted provided that the following conditions 11273438Sdelphij * are met: 12273438Sdelphij * 13273438Sdelphij * 1. Redistributions of source code must retain the above copyright 14273438Sdelphij * notice, this list of conditions and the following disclaimer. 15273438Sdelphij * 16273438Sdelphij * 2. Redistributions in binary form must reproduce the above copyright 17273438Sdelphij * notice, this list of conditions and the following disclaimer in 18273438Sdelphij * the documentation and/or other materials provided with the 19273438Sdelphij * distribution. 20273438Sdelphij * 21273438Sdelphij * 3. All advertising materials mentioning features or use of this 22273438Sdelphij * software must display the following acknowledgment: 23273438Sdelphij * "This product includes software developed by the OpenSSL Project 24273438Sdelphij * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 25273438Sdelphij * 26273438Sdelphij * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 27273438Sdelphij * endorse or promote products derived from this software without 28273438Sdelphij * prior written permission. For written permission, please contact 29273438Sdelphij * openssl-core@openssl.org. 30273438Sdelphij * 31273438Sdelphij * 5. Products derived from this software may not be called "OpenSSL" 32273438Sdelphij * nor may "OpenSSL" appear in their names without prior written 33273438Sdelphij * permission of the OpenSSL Project. 34273438Sdelphij * 35273438Sdelphij * 6. Redistributions of any form whatsoever must retain the following 36273438Sdelphij * acknowledgment: 37273438Sdelphij * "This product includes software developed by the OpenSSL Project 38273438Sdelphij * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 39273438Sdelphij * 40273438Sdelphij * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 41273438Sdelphij * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42273438Sdelphij * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 43273438Sdelphij * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 44273438Sdelphij * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45273438Sdelphij * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46273438Sdelphij * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47273438Sdelphij * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48273438Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 49273438Sdelphij * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50273438Sdelphij * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51273438Sdelphij * OF THE POSSIBILITY OF SUCH DAMAGE. 52273438Sdelphij * ==================================================================== 53273438Sdelphij * 54273438Sdelphij * This product includes cryptographic software written by Eric Young 55273438Sdelphij * (eay@cryptsoft.com). This product includes software written by Tim 56273438Sdelphij * Hudson (tjh@cryptsoft.com). 57273438Sdelphij * 58273438Sdelphij */ 59273438Sdelphij 60273438Sdelphij#include <openssl/rand.h> 61273438Sdelphij#include "rand_lcl.h" 62273438Sdelphij 63273438Sdelphij#if defined(OPENSSL_SYS_VMS) 64273438Sdelphij 65273438Sdelphij# include <descrip.h> 66273438Sdelphij# include <jpidef.h> 67273438Sdelphij# include <ssdef.h> 68273438Sdelphij# include <starlet.h> 69273438Sdelphij# ifdef __DECC 70273438Sdelphij# pragma message disable DOLLARID 71273438Sdelphij# endif 72273438Sdelphij 73273438Sdelphijstatic struct items_data_st { 74273438Sdelphij short length, code; /* length is amount of bytes */ 75273438Sdelphij} items_data[] = { 76273438Sdelphij { 77273438Sdelphij 4, JPI$_BUFIO 78273438Sdelphij }, 79273438Sdelphij { 80273438Sdelphij 4, JPI$_CPUTIM 81273438Sdelphij }, 82273438Sdelphij { 83273438Sdelphij 4, JPI$_DIRIO 84273438Sdelphij }, 85273438Sdelphij { 86273438Sdelphij 8, JPI$_LOGINTIM 87273438Sdelphij }, 88273438Sdelphij { 89273438Sdelphij 4, JPI$_PAGEFLTS 90273438Sdelphij }, 91273438Sdelphij { 92273438Sdelphij 4, JPI$_PID 93273438Sdelphij }, 94273438Sdelphij { 95273438Sdelphij 4, JPI$_WSSIZE 96273438Sdelphij }, 97273438Sdelphij { 98273438Sdelphij 0, 0 99273438Sdelphij } 100273438Sdelphij}; 101273438Sdelphij 102273438Sdelphijint RAND_poll(void) 103273438Sdelphij{ 104273438Sdelphij long pid, iosb[2]; 105273438Sdelphij int status = 0; 106273438Sdelphij struct { 107273438Sdelphij short length, code; 108273438Sdelphij long *buffer; 109273438Sdelphij int *retlen; 110273438Sdelphij } item[32], *pitem; 111273438Sdelphij unsigned char data_buffer[256]; 112273438Sdelphij short total_length = 0; 113273438Sdelphij struct items_data_st *pitems_data; 114273438Sdelphij 115273438Sdelphij pitems_data = items_data; 116273438Sdelphij pitem = item; 117273438Sdelphij 118273438Sdelphij /* Setup */ 119273438Sdelphij while (pitems_data->length && (total_length + pitems_data->length <= 256)) { 120273438Sdelphij pitem->length = pitems_data->length; 121273438Sdelphij pitem->code = pitems_data->code; 122273438Sdelphij pitem->buffer = (long *)&data_buffer[total_length]; 123273438Sdelphij pitem->retlen = 0; 124273438Sdelphij total_length += pitems_data->length; 125273438Sdelphij pitems_data++; 126273438Sdelphij pitem ++; 127273438Sdelphij } 128273438Sdelphij pitem->length = pitem->code = 0; 129273438Sdelphij 130273438Sdelphij /* 131273438Sdelphij * Scan through all the processes in the system and add entropy with 132273438Sdelphij * results from the processes that were possible to look at. 133273438Sdelphij * However, view the information as only half trustable. 134273438Sdelphij */ 135273438Sdelphij pid = -1; /* search context */ 136273438Sdelphij while ((status = sys$getjpiw(0, &pid, 0, item, iosb, 0, 0)) 137273438Sdelphij != SS$_NOMOREPROC) { 138273438Sdelphij if (status == SS$_NORMAL) { 139273438Sdelphij RAND_add(data_buffer, total_length, total_length / 2); 140273438Sdelphij } 141273438Sdelphij } 142273438Sdelphij sys$gettim(iosb); 143273438Sdelphij RAND_add((unsigned char *)iosb, sizeof(iosb), sizeof(iosb) / 2); 144273438Sdelphij return 1; 145273438Sdelphij} 146273438Sdelphij 147273438Sdelphij#endif 148273438Sdelphij