哪里可以找到os.urandom()的源代码?
Where can I find the source code of os.urandom()?
想调查研究python3.7的os.urandom()
函数的代码。
我查看了各自的标准库 os.py
,但既没有在那里定义,也没有在那里导入。
我还尝试了 grep 的定义:
/usr/lib/python3.7 $ grep -rFl "def urandom" 2> /dev/null
但是什么也没有。
我怀疑 os.urandom() 发生了一些神奇的事情。
在哪里可以找到用于研究和密码分析的函数定义?
许多为 os
模块定义的名称由 Modules/posixmodule.c
处理,在 POSIX 系统和 Windows 上都是如此。请注意,源代码在 C,而不是 Python,因为访问系统功能需要本机代码。
你可以看到这是 os.py
source code,它根据当前的 OS 导入 posix
或 nt
,其中这两个名称都是从上面编译而来的posixmodule.c
文件,但已重命名以更好地反映平台并表明两个变体之间的功能不同(nt
变体提供的功能较少)。
参见os_urandom_impl()
function for the implementation details of os.urandom()
. This delegates to an internal function, _PyOS_URandom()
, which together with other helper functions needed early in Python's startup process, is defined in Python/bootstrap_hash.c
。
想调查研究python3.7的os.urandom()
函数的代码。
我查看了各自的标准库 os.py
,但既没有在那里定义,也没有在那里导入。
我还尝试了 grep 的定义:
/usr/lib/python3.7 $ grep -rFl "def urandom" 2> /dev/null
但是什么也没有。
我怀疑 os.urandom() 发生了一些神奇的事情。
在哪里可以找到用于研究和密码分析的函数定义?
许多为 os
模块定义的名称由 Modules/posixmodule.c
处理,在 POSIX 系统和 Windows 上都是如此。请注意,源代码在 C,而不是 Python,因为访问系统功能需要本机代码。
你可以看到这是 os.py
source code,它根据当前的 OS 导入 posix
或 nt
,其中这两个名称都是从上面编译而来的posixmodule.c
文件,但已重命名以更好地反映平台并表明两个变体之间的功能不同(nt
变体提供的功能较少)。
参见os_urandom_impl()
function for the implementation details of os.urandom()
. This delegates to an internal function, _PyOS_URandom()
, which together with other helper functions needed early in Python's startup process, is defined in Python/bootstrap_hash.c
。