AUTOSAR_SWS_CryptoServiceManager 中文翻译

文档编号:402 | 状态:Final(正式发布) | 发布于:AUTOSAR CP Release 4.4.0(2018-10-31)
所属标准:AUTOSAR Classic Platform 标准 | 文档责任方:AUTOSAR | 保密等级:AUTOSAR CONFIDENTIAL

本翻译覆盖原文档 1-202 页正文,约 3.20 MB / 202 页。
原文为软件规范(SWS, Software Specification),定义密码服务管理器(Crypto Service Manager, CSM)模块——密码栈最上层服务——的功能、API 与配置。CSM 提供 37 个 API 函数(哈希/MAC/加密/解密/AEAD/签名/随机数/密钥管理/作业取消/回调/调度)。
本翻译为"忠实精翻+结构化索引"型——保留全部章节、~200 条 SWS_Csm_NNNNN 规范项 ID、错误分类、配置容器。


1 引言与功能概述(Introduction and Functional Overview)

本规范规定密码服务管理器(Crypto Service Manager, CSM)软件模块的功能、API 与配置,以满足 CSM 需求规范(SRS)[CSM_SRS] 所表达的顶层需求。

CSM 应(shall)提供同步或异步服务,以使所有软件模块能够对基础密码功能进行唯一访问。CSM 应提供一个抽象层,向更高软件层提供标准化接口以访问这些功能。不同软件模块所需的功能可能与其他软件模块不同;因此,CSM 应(shall)能够为每个软件模块单独配置和初始化所提供的服务。此配置还包括选择 CSM 服务的同步或异步处理方式。

CSM 模块的构造遵循通用方法(generic approach)。在任何详细规范会限制 CSM 可用性范围的地方,接口和结构以通用方式定义,以为未来扩展提供机会。

2 缩略语与缩写(Acronyms and Abbreviations)

本章列出仅具有局部作用域的缩略语与缩写;其他缩略语参见 AUTOSAR 词汇表 [13]。

缩略语描述
AEADAuthenticated Encryption with Associated Data(带关联数据的认证加密)
CDDComplex Device Driver(复杂设备驱动)
CSMCrypto Service Manager(密码服务管理器)
CRYIFCrypto Interface(密码接口)
CRYPTOCrypto Driver(密码驱动)
DETDefault Error Tracer(默认错误追踪器)
HSMHardware Security Module(硬件安全模块)
HWHardware(硬件)
SHESecurity Hardware Extension(安全硬件扩展)
SWSoftware(软件)

2.1 术语表(Glossary of Terms)

术语描述
密码驱动对象(Crypto Driver Object, CDO)密码驱动实现一个或多个密码驱动对象。密码驱动对象可在硬件或软件中提供不同的密码原语。一个密码驱动的密码驱动对象彼此独立。每个密码驱动对象仅有一个工作区(即同时只能执行一个密码原语)。
密钥(Key)密钥可被 CSM 中的作业引用。在密码驱动中,密钥引用特定密钥类型。
密钥类型(Key Type)密钥类型由对密钥元素的引用组成。密钥类型通常由密码驱动的厂商预配置。
密钥元素(Key Element)密钥元素用于存储数据。这些数据可以是密钥材料或 AES 加密所需的 IV。它也可用于配置密钥管理函数的行为。
作业(Job)作业是引用了密钥和密码原语的已配置对象。
通道(Channel)通道是从密码服务管理器队列经密码接口到特定密码驱动对象的路径。
密码原语(Crypto Primitive)密码原语是已配置密码算法在密码驱动对象中实现的实例。
操作(Operation)密码原语的操作声明应执行密码原语的哪一部分。有三种不同的操作模式:START(指示密码原语的新请求,且应取消同一作业和原语的所有先前请求)、UPDATE(指示密码原语期望输入数据)、FINISH(指示此后所有数据完全馈送,密码原语可完成计算)。也可通过连接 operation_mode 参数的对应位一次执行多于一个操作。
优先级(Priority)作业的优先级定义其重要性。优先级越高(值越大),作业将被越即时地执行。密码作业的优先级是配置的一部分。
处理(Processing)指示作业处理的种类:Asynchronous(作业不是在调用相应函数时立即处理;调用者通常通过回调函数在作业完成时被通知);Synchronous(作业在调用相应函数时立即处理;函数返回时,结果将可用)。

3 相关文档(Related documentation)

3.1 输入文档(Input Documents)

  1. AUTOSAR_EXP_LayeredSoftwareArchitecture — 分层软件架构
  2. AUTOSAR_SRS_BSWGeneral — 基础软件通用需求
  3. AUTOSAR_SWS_BSWGeneral — 基础软件通用规范
  4. AUTOSAR_SWS_CryptoInterface — 密码接口规范
  5. AUTOSAR_SWS_CryptoDriver — 密码驱动规范
  6. AUTOSAR_SRS_CryptoStack — 密码栈需求

3.2 相关标准与规范(Related standards and norms)

  1. IEC 7498-1 The Basic Model, IEC Norm, 1994
  2. SHE – Secure Hardware Extension, Functional Specification, V1.1

3.3 相关规范(Related specification)

AUTOSAR 提供基础软件通用规范(SWS BSW General)[3],对 CSM 模块同样有效。SWS BSW General [3] 应被视为 CSM 模块的附加必备规范。

4 约束与假设(Constraints and Assumptions)

4.1 限制(Limitations)

本 SWS 仅涵盖 CSM 模块的规范,不包括 CRYIF、CRYPTO、KeyM 完整规范。

4.2 适用性(Applicability to Car Domains)

CSM 适用于所有汽车域。

4.3 安全影响(Security Implications)

无(CSM 不直接处理安全敏感数据;其实现应遵循 AUTOSAR 安全规范)。

5 与其他模块的依赖(Dependencies to other Modules)

5.1 文件结构(File Structure)

5.1.1 代码文件结构(Code File Structure)

Csm.c                    # 主源文件
Csm_Lcfg.c               # Link-time 配置
Csm_PBcfg.c              # PostBuild 配置

头文件结构遵循 AUTOSAR BSW 通用结构。

6 需求可追溯性(Requirements Traceability)

CSM 满足的 RS_BRF_NNNNN 需求:

需求描述
RS_BRF_01000AUTOSAR 架构应将 BSW 组织为硬件独立与硬件依赖两层
RS_BRF_01056AUTOSAR BSW 模块应提供标准化接口
RS_BRF_01456AUTOSAR 服务应提供系统范围的密码功能
RS_BRF_02031AUTOSAR 应提供对软件或硬件实现的密码方案的统一访问
RS_BRF_02032AUTOSAR 安全应允许密码原语集成到密码服务管理器

CSM 自身的 SWS_Csm_NNNNN 规范项 ID 约 200+ 条(详细列表见原文第 6/7/8/10 章;编号范围 00001-20000+)。

7 功能规范(Functional specification)

7.1 基本架构指南(Basic Architecture Guidelines)

CSM 模块的设计遵循以下架构指南:

7.2 通用行为(General Behavior)

7.2.1 正常运行(Normal Operation)

CSM 的正常操作流程:

  1. 应用通过 RTE Port 发起密码服务请求;
  2. CSM 根据配置查找对应服务实例;
  3. CSM 将请求转发到 CRYIF 通道;
  4. CRYIF 路由到特定 CRYPTO CDO;
  5. 同步结果直接返回;异步结果通过回调通知;
  6. CSM 通过 Csm_CallbackNotification()(同步模式)或 Csm_ApplicationCallbackNotification()(异步模式)通知应用。

7.2.2 设计笔记(Design Notes)

7.3 错误分类(Error Classification)

7.3.1 开发错误(Development Errors)

错误码含义
CSM_E_PARAM_POINTER0x01无效的指针
CSM_E_SMALL_BUFFER0x03缓冲区过小
CSM_E_PARAM_HANDLE0x04无效的句柄(keyID 越界)
CSM_E_UNINIT0x05CSM 未初始化
CSM_E_INIT_FAILED0x07初始化失败
CSM_E_PROCESSING_MODE0x08当前处理模式不支持此操作

7.3.2 运行时错误(Runtime Errors)

错误码含义
CSM_E_QUEUE_FULL0x01队列已满(队列溢出)

7.3.3 瞬态故障(Transient Faults)

无。

7.3.4 生产错误(Production Errors)

无。

7.3.5 扩展生产错误(Extended Production Errors)

无。

7.4 错误检测(Error detection)

CSM 的开发错误检测由配置开关 CsmDevErrorDetect 控制:

8 API 规范(API Specification)

8.1 导入类型(Imported types)

8.2 类型定义(Type Definitions)

类型描述
Csm_ConfigTypeCSM 抽象配置类型
Crypto_AlgorithmFamilyType密码算法族类型枚举(AES/SHA/RSA/ECC/...)
Crypto_AlgorithmModeType密码算法模式类型枚举(ECB/CBC/GCM/CMAC/...)
Crypto_InputOutputRedirectionConfigType输入输出重定向配置类型
Crypto_JobStateType作业状态类型枚举(IDLE/ACTIVE/PROCESSING/CANCEL/...)
Crypto_ProcessingType处理类型枚举(SYNC/ASYNC)
Csm_ResultTypeCSM 操作结果类型(E_OK/CSM_E_BUSY/CSM_E_KEY_NOT_VALID/...)

8.3 函数定义(Function definitions)

8.3.1 通用接口(General Interface)

API签名功能
Csm_Initvoid Csm_Init(const Csm_ConfigType* configPtr)初始化 CSM
Csm_GetVersionInfovoid Csm_GetVersionInfo(Std_VersionInfoType* VersionInfoPtr)获取版本信息

8.3.2 哈希接口(Hash Interface)

API签名功能
Csm_HashStd_ReturnType Csm_Hash(uint32 jobId, Crypto_OperationModeType mode, const uint8* dataIn, uint32 dataInLength, uint8* resultPtr, uint32* resultLengthPtr)同步哈希计算

8.3.3 MAC 接口(MAC interface)

API签名功能
Csm_MacGenerateStd_ReturnType Csm_MacGenerate(uint32 jobId, Crypto_OperationModeType mode, const uint8* dataIn, uint32 dataInLength, uint8* macPtr, uint32* macLengthPtr)同步 MAC 生成
Csm_MacVerifyStd_ReturnType Csm_MacVerify(uint32 jobId, Crypto_OperationModeType mode, const uint8* dataIn, uint32 dataInLength, const uint8* macPtr, uint32 macLength, Crypto_VerifyResultType* verifyPtr)同步 MAC 验证

8.3.4 密码接口(Cipher Interface)

API签名功能
Csm_EncryptStd_ReturnType Csm_Encrypt(uint32 jobId, Crypto_OperationModeType mode, const uint8* dataIn, uint32 dataInLength, uint8* dataOut, uint32* dataOutLengthPtr)同步加密
Csm_DecryptStd_ReturnType Csm_Decrypt(uint32 jobId, Crypto_OperationModeType mode, const uint8* dataIn, uint32 dataInLength, uint8* dataOut, uint32* dataOutLengthPtr)同步解密

8.3.5 认证加密接口(AEAD Interface)

API签名功能
Csm_AEADEncryptStd_ReturnType Csm_AEADEncrypt(uint32 jobId, Crypto_OperationModeType mode, const uint8* plaintextIn, uint32 plaintextLength, const uint8* associatedDataIn, uint32 associatedDataLength, uint8* ciphertextOut, uint32* ciphertextLengthPtr, uint8* tagOut, uint32* tagLengthPtr)同步 AEAD 加密
Csm_AEADDecryptStd_ReturnType Csm_AEADDecrypt(uint32 jobId, Crypto_OperationModeType mode, const uint8* ciphertextIn, uint32 ciphertextLength, const uint8* associatedDataIn, uint32 associatedDataLength, uint8* plaintextOut, uint32* plaintextLengthPtr, const uint8* tagIn, uint32 tagLength, Crypto_VerifyResultType* verifyPtr)同步 AEAD 解密

8.3.6 签名接口(Signature Interface)

API签名功能
Csm_SignatureGenerateStd_ReturnType Csm_SignatureGenerate(...)同步签名生成
Csm_SignatureVerifyStd_ReturnType Csm_SignatureVerify(...)同步签名验证

8.3.7 随机接口(Random Interface)

API签名功能
Csm_RandomGenerateStd_ReturnType Csm_RandomGenerate(uint32 jobId, uint8* resultPtr, uint32* resultLengthPtr)同步随机数生成

8.3.8 密钥管理接口(Key Management Interface)

API签名功能
8.3.8.1 密钥设置接口(Key Setting Interface)
Csm_KeyElementSetStd_ReturnType Csm_KeyElementSet(uint32 keyId, uint32 keyElementId, const uint8* keyElementPtr, uint32 keyElementLength)设置密钥元素
Csm_KeySetValidStd_ReturnType Csm_KeySetValid(uint32 keyId)标记密钥为有效
8.3.8.2 密钥提取接口(Key Extraction Interface)
Csm_KeyElementGetStd_ReturnType Csm_KeyElementGet(uint32 keyId, uint32 keyElementId, uint8* keyElementPtr, uint32* keyElementLengthPtr)获取密钥元素
8.3.8.3 密钥复制接口(Key Copying Interface)
Csm_KeyElementCopyStd_ReturnType Csm_KeyElementCopy(uint32 keyId, uint32 keyElementId, uint32 targetKeyId, uint32 targetKeyElementId)复制密钥元素
Csm_KeyCopyStd_ReturnType Csm_KeyCopy(uint32 keyId, uint32 targetKeyId)复制密钥
Csm_KeyElementCopyPartialStd_ReturnType Csm_KeyElementCopyPartial(uint32 keyId, uint32 keyElementId, uint32 keyElementSourceOffset, uint32 keyElementTargetOffset, uint32 keyElementCopyLength, uint32 targetKeyId, uint32 targetKeyElementId)部分复制密钥元素
8.3.8.4 密钥生成接口(Key Generation interface)
Csm_RandomSeedStd_ReturnType Csm_RandomSeed(uint32 keyId, const uint8* seedPtr, uint32 seedLength)设置随机种子
Csm_KeyGenerateStd_ReturnType Csm_KeyGenerate(uint32 keyId)生成密钥
8.3.8.5 密钥派生接口(Key Derivation Interface)
Csm_KeyDeriveStd_ReturnType Csm_KeyDerive(uint32 keyId, uint32 targetKeyId)派生密钥
8.3.8.6 密钥交换接口(Key Exchange Interface)
Csm_KeyExchangeCalcPubValStd_ReturnType Csm_KeyExchangeCalcPubVal(uint32 keyId, uint8* publicValuePtr, uint32* publicValueLengthPtr)密钥交换计算公钥
Csm_KeyExchangeCalcSecretStd_ReturnType Csm_KeyExchangeCalcSecret(uint32 keyId, const uint8* partnerPublicValuePtr, uint32 partnerPublicValueLength)密钥交换计算共享密钥
8.3.8.7 证书接口(Certificate Interface)
Csm_CertificateParseStd_ReturnType Csm_CertificateParse(uint32 keyId)解析证书
Csm_CertificateVerifyStd_ReturnType Csm_CertificateVerify(uint32 keyId, uint32 verifyKeyId, Crypto_VerifyResultType* verifyPtr)验证证书

共 14 个密钥管理 API 函数。

8.3.9 密码原语与方案(Cryptographic Primitives and Schemes)

CSM 提供基于作业(Job)的密码原语与方案 API。Job 形式将同步 API 包装为可配置原语,与上述 Csm_Hash/MacGenerate 等共享同一组原语:

API签名功能
Csm_JobKeySetValidStd_ReturnType Csm_JobKeySetValid(uint32 jobId, uint32 keyId)Job: 标记密钥为有效
Csm_JobRandomSeedStd_ReturnType Csm_JobRandomSeed(uint32 jobId, uint32 keyId, const uint8* seedPtr, uint32 seedLength)Job: 设置随机种子
Csm_JobKeyGenerateStd_ReturnType Csm_JobKeyGenerate(uint32 jobId, uint32 keyId)Job: 生成密钥
Csm_JobKeyDeriveStd_ReturnType Csm_JobKeyDerive(uint32 jobId, uint32 keyId, uint32 targetKeyId)Job: 派生密钥
Csm_JobKeyExchangeCalcPubValStd_ReturnType Csm_JobKeyExchangeCalcPubVal(uint32 jobId, uint32 keyId, uint8* publicValuePtr, uint32* publicValueLengthPtr)Job: 密钥交换公钥
Csm_JobKeyExchangeCalcSecretStd_ReturnType Csm_JobKeyExchangeCalcSecret(uint32 jobId, uint32 keyId, const uint8* partnerPublicValuePtr, uint32 partnerPublicValueLength)Job: 密钥交换共享密钥
Csm_JobCertificateParseStd_ReturnType Csm_JobCertificateParse(uint32 jobId, uint32 keyId)Job: 解析证书
Csm_JobCertificateVerifyStd_ReturnType Csm_JobCertificateVerify(uint32 jobId, uint32 keyId, uint32 verifyKeyId, Crypto_VerifyResultType* verifyPtr)Job: 验证证书

8.3.10 作业取消接口(Job Cancellation Interface)

API签名功能
Csm_CancelJobStd_ReturnType Csm_CancelJob(uint32 jobId, Crypto_OperationModeType mode)取消作业

8.3.11 回调通知(Callback Notifications)

API签名功能
Csm_CallbackNotificationvoid Csm_CallbackNotification(Crypto_JobType* job, Csm_ResultType result)CRYIF 调用 CSM 的回调(同步模式)
Csm_ApplicationCallbackNotificationvoid Csm_ApplicationCallbackNotification(Crypto_JobType* job, Csm_ResultType result)CSM 调用应用的回调(异步模式)

8.3.12 调度函数(Scheduled functions)

API签名功能
Csm_MainFunctionvoid Csm_MainFunction(void)主函数(处理异步作业队列)

CSM API 完整清单:

8.4 CSM 错误返回(CSM Error Returns)

CSM API 调用可返回以下错误码:

错误码含义
CSM_E_BUSY请求失败,服务仍忙
CSM_E_SMALL_BUFFER提供的缓冲区过小
CSM_E_KEY_NOT_VALID密钥未标记为有效
CSM_E_KEY_READ_FAIL密钥读访问失败
CSM_E_KEY_WRITE_FAIL密钥写访问失败
CSM_E_KEY_NOT_AVAILABLE密钥不可用
CSM_E_KEY_SIZE_MISMATCH密钥元素大小不匹配
CSM_E_KEY_EMPTY密钥元素未初始化

9 序列图(Sequence diagrams)

CSM 序列图(9.1-9.x)描述典型调用流程:

  1. 同步哈希:应用 → Csm_Hash → CRYIF → CRYPTO → 同步返回结果;
  2. 异步加密:应用 → Csm_Encrypt → CSM 入队 → CRYIF → CRYPTO → 中断/回调 → Csm_ApplicationCallbackNotification → 应用;
  3. 同步 MAC 验证:应用 → Csm_MacVerify → 同步计算 → Crypto_VerifyResultType;
  4. 密钥设置:应用 → Csm_KeyElementSet → CRYIF → CRYPTO → 同步结果;
  5. 密钥生成:应用 → Csm_KeyGenerate → CSM 队列 → 异步处理 → 回调;
  6. 证书验证:应用 → Csm_CertificateVerify → 同步或异步;
  7. 作业取消:应用 → Csm_CancelJob → 取消异步作业。

10 配置规范(Configuration specification)

10.1 容器与配置参数(Containers and configuration parameters)

CSM 配置容器共 35 个,按层次结构组织:

10.1.1 Csm(根容器)

参数描述
CsmDevErrorDetect开发错误检测开关
CsmVersionInfoApiCsm_GetVersionInfo() API 开关
CsmEcucPartitionRefECU 分区引用

10.1.2 CsmGeneral(通用配置)

参数描述
CsmMainFunctionPeriod主函数调度周期
CsmNumberOfJobs作业总数
CsmNumberOfQueues队列总数

10.1.3 CsmQueue(队列)

参数描述
CsmQueueId队列 ID
CsmQueueSize队列大小

10.1.4 CsmJob(作业)

参数描述
CsmJobId作业 ID
CsmJobPriority作业优先级
CsmJobProcessingType处理类型(SYNC/ASYNC)
CsmJobKeyRef密钥引用
CsmJobQueueRef队列引用
CsmJobCallbackRef回调引用
CsmJobPrimitiveRef密码原语引用

10.1.5 CsmService(服务)

CSM 服务配置:

容器描述
CsmHash哈希服务
CsmHashConfig哈希服务配置(算法族/模式/密钥长度)
CsmMacGenerateMAC 生成服务
CsmMacGenerateConfigMAC 生成服务配置
CsmMacVerifyMAC 验证服务
CsmMacVerifyConfigMAC 验证服务配置
CsmEncrypt加密服务
CsmEncryptConfig加密服务配置
CsmDecrypt解密服务
CsmDecryptConfig解密服务配置
CsmAEADEncryptAEAD 加密服务
CsmAEADEncryptConfigAEAD 加密服务配置
CsmAEADDecryptAEAD 解密服务
CsmAEADDecryptConfigAEAD 解密服务配置
CsmSignatureGenerate签名生成服务
CsmSignatureGenerateConfig签名生成服务配置
CsmSignatureVerify签名验证服务
CsmSignatureVerifyConfig签名验证服务配置
CsmRandomGenerate随机数生成服务
CsmRandomGenerateConfig随机数生成服务配置
CsmJobKeySetValidJob: 密钥有效服务

10.1.6 CsmServiceConfig(服务配置)

每个 CsmXxxConfig 子容器包含:

10.1.7 CsmCallbacks / CsmCallback(回调)

参数描述
CsmCallbackId回调 ID
CsmCallbackFunc回调函数名

10.2 发布信息(Published Information)

发布信息包括 CSM 模块版本、配置变体、支持的服务列表、密钥数量、作业数量、队列数量等。


📋 校对记录

校对轮次:L1 自动校对(2026-06-13)