0

在这里原谅我的无知。我没有很好地阅读Python,我根本不会写它。

我正在尝试审核 CVE-2013-1445 的 python 项目。我相信找到了一个可能需要注意的源文件(以及其他改进机会)。该文件是util.py,它有以下行:

import base64

from Crypto.Hash import HMAC
from Crypto import Random
...

当我查看Python crypto docs时,我没有看到提到一个Random类。只有hashlibhmac

The modules described in this chapter implement various algorithms of a
cryptographic nature. They are available at the discretion of the
installation. On Unix systems, the crypt module may also be available.
Here’s an overview:

    15.1. hashlib — Secure hashes and message digests
    15.2. hmac — Keyed-Hashing for Message Authentication

...

究竟是Random从哪里来的?是本地的还是第三方的?

或者我的问题应该是,从哪里来Crypto?如果Crypto是第三方,我如何确定第三方库和类的包含方式/位置(相对于本机库和类)?

为了完整起见,我试图理解 Python 的作用域和命名空间,但目前对我来说毫无意义(正如这个问题可能表明的那样)。例如, or 没有明显的范围或命名空间CryptoRandom除了Random是 的一部分Crypto)。

提前致谢。

4

2 回答 2

2

你问文件存储在哪里?模块有一个名为的属性__file__,它列出了模块在磁盘上的路径。

>>> from Crypto import Random
>>> Random.__file__
'/home/ubuntu/.env/local/lib/python2.7/site-packages/Crypto/Random/__init__.pyc'

(就我而言,PyCrypto 安装在我的主目录中的一个 virtualenv 中)

于 2013-10-21T03:53:39.490 回答
2

Crypto不是任何标准 Python 发行版的一部分。这就是 Python 文档没有提及它的原因;-) 您可以在此处下载源代码:

https://www.dlitz.net/software/pycrypto/

于 2013-10-21T03:55:31.840 回答