了解不透明数据类型

Understanding opaque data type

在 TLS 1.0 规范中提供了其中使用的类型的描述。这是该描述的一部分:

Single byte entities containing uninterpreted data are of type opaque.

对我来说,不太清楚应将未解释的数据视为什么。例如,它用于以下结构:

struct {
  ConnectionEnd          entity;
  BulkCipherAlgorithm    bulk_cipher_algorithm;
  CipherType             cipher_type;
  uint8                  key_size;
  uint8                  key_material_length;
  IsExportable           is_exportable;
  MACAlgorithm           mac_algorithm;
  uint8                  hash_size;
  CompressionMethod      compression_algorithm;
      opaque                 master_secret[48];
      opaque                 client_random[32];
      opaque                 server_random[32];
  } SecurityParameters;

谁能给我解释一下?

他们仅将 opaque 用于文档目的,以强调 TLS 本身不解释数据(因为其含义特定于所使用的密码和哈希函数等)。实际中,可以把opaque想成char,保证是单字节

在包含这样的 struct 定义的实际实现中,您可能会发现

typedef char opaque;

#define opaque char

在它之前的某个地方。

(unsigned char,uint8_t(来自),还有自己的uint8是一些其他的可能, 但这只是一个次要的实现细节。在实践中,这些都归结为 charunsigned char#define opaque char 变体出现在 /usr/include/rpc/key_prot 中。 h 顺便说一句,在我的 Linux 系统上。)