引用 Python 密码模块的 "backend" 是什么?

What is the "backend" in reference to the Python cryptography module?

使用Python cryptography模块时"backend"指的是什么。

例如.RSABackend简单状态:A backend with methods for using RSA..

有问题的库本身没有实现加密代码。这是因为加密代码容易出现范围广泛的问题,这些问题 most programmers don't even think about - 或者不需要在他们的 day-to-day 工作中考虑。

这些库所做的是使用其他软件以(希望)安全的方式实现它们。这些软件被称为后端。

但是具体是什么后端?

Class-wise,我将以 HashBackend 为例,但它可以很容易地外推到其他后端。出于所有意图和目的,它是一个抽象 class,必须实现两个方法:

  • hash_supported(algorithm)
  • create_hash_ctx(algorithm)

hash_supported 将采用一种算法,return 是否支持特定算法。并非每个后端都可能支持所有算法,因此您可以使用它来根据可用性确定要使用的算法。

create_hash_ctx 将采用算法和 return 一个“哈希上下文”,这是用于实际计算数据哈希的对象。

对于这两个,有问题的 class 实际上并没有实现任何功能。它仅仅定义了它们的存在,文档解释了它们应该做什么。 “实际”后端代码,例如 OpenSSL backend,然后将与密码代码的实际实现接口。

+-----------------+
|    Your Code    | This is your code, calling someting like GetHash(input.password)
+-----------------+
   |
+--v--------------+
|   High-Level    | This is the "nice" interface provided by your crypto library
|   Crypto Code   | This is what you should use 100% of the time
+-----------------+
   |
+--v--------------+
|  Hash Backend   | This is the backend that the "nice" interface calls
+-----------------+
   |
+--v--------------+
| OpenSSL Backend | This is what translates requests to a way OpenSSL understands
+-----------------+
   |
+--v--------------+
| OpenSSL Library | This is what actually does the cryptographic operations
+-----------------+

根据所讨论的加密任务,库可能会调用一些 OS 函数来完成某些任务,例如读取随机数据。