@@ -7882,6 +7882,42 @@ win32_urandom(PyObject *self, PyObject *args)
78827882}
78837883#endif
78847884
7885+ #ifdef __VMS
7886+ /* Use openssl random routine */
7887+ #include <openssl/rand.h>
7888+ PyDoc_STRVAR (vms_urandom__doc__ ,
7889+ "urandom(n) -> str\n\n\
7890+ Return a string of n random bytes suitable for cryptographic use." );
7891+
7892+ static PyObject *
7893+ vms_urandom (PyObject * self , PyObject * args )
7894+ {
7895+ int howMany ;
7896+ PyObject * result ;
7897+
7898+ /* Read arguments */
7899+ if (! PyArg_ParseTuple (args , "i:urandom" , & howMany ))
7900+ return NULL ;
7901+ if (howMany < 0 )
7902+ return PyErr_Format (PyExc_ValueError ,
7903+ "negative argument not allowed" );
7904+
7905+ /* Allocate bytes */
7906+ result = PyString_FromStringAndSize (NULL , howMany );
7907+ if (result != NULL ) {
7908+ /* Get random data */
7909+ if (RAND_pseudo_bytes ((unsigned char * )
7910+ PyString_AS_STRING (result ),
7911+ howMany ) < 0 ) {
7912+ Py_DECREF (result );
7913+ return PyErr_Format (PyExc_ValueError ,
7914+ "RAND_pseudo_bytes" );
7915+ }
7916+ }
7917+ return result ;
7918+ }
7919+ #endif
7920+
78857921static PyMethodDef posix_methods [] = {
78867922 {"access" , posix_access , METH_VARARGS , posix_access__doc__ },
78877923#ifdef HAVE_TTYNAME
@@ -8174,6 +8210,9 @@ static PyMethodDef posix_methods[] = {
81748210#endif
81758211 #ifdef MS_WINDOWS
81768212 {"urandom" , win32_urandom , METH_VARARGS , win32_urandom__doc__ },
8213+ #endif
8214+ #ifdef __VMS
8215+ {"urandom" , vms_urandom , METH_VARARGS , vms_urandom__doc__ },
81778216 #endif
81788217 {NULL , NULL } /* Sentinel */
81798218};
0 commit comments