DEENESPTFRRUARHIKOZHNL

AUTOSAR Classic Crypto Services

集群指南人工智能生成

通过硬件和软件驱动程序提供标准化的加密计算与密钥管理服务。
AI 生成 未审核 模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: b0f0d6315c89 来源 未决问题(1)
因果锚点:R20-11 自 R20-11 起有效 为此规范版本重新合成。
译自德文指南gemini-3.8-flash-low · 2026-10-13 · 德文原文

通过硬件和软件驱动程序提供标准化的加密计算与密钥管理服务。

该集群捆绑了 CSM、CryIf 和 Crypto Driver 模块,用于在 AUTOSAR Classic Platform 中以独立于硬件的方式提供加密服务和密钥管理功能 EXP_UtilizationOfCryptoServices 第8页。加密作业通过 CSM 进行优先级排序,在 CryIf 中路由到逻辑通道,并在 Crypto Driver 中同步或异步执行 [SWS_CryIf_91003]。出于一致性原因,NVM 中的密钥持久化严格仅在通过 KeySetValid 成功验证后进行 SWS_CryptoDriver 第37页。

“Crypto Services & Hardware Abstraction”模块集群包含 AUTOSAR Classic 模块 Crypto Service Manager(csm)、Crypto Interface(cryif)和 Crypto Driver(crypto)EXP_UtilizationOfCryptoServices 第8页。它为加密操作(其中包括加密、签名、MAC 计算和随机数生成)以及安全密钥管理提供了一个独立于硬件的抽象层 [SWS_Csm_00982]、[SWS_Csm_00984]、SWS_CryptoDriver 第15页。

加密请求被封装为 Crypto_JobType,其定义了优先级、输入和输出缓冲区以及操作模式(用于流式处理或 SingleCall 的 Start、Update、Finish)[SWS_Csm_01013]、[SWS_Csm_01039]。CSM 接收作业,将其分配给软件队列,并通过 CryIf_ProcessJob() 转发 [SWS_Csm_00017]、[SWS_CryIf_91003]。CryIf 负责到驱动程序的通道路由,并将 CSM 密钥标识符转换为模块特定的驱动程序密钥 ID [SWS_CryIf_00133]。

CryptoArchitecture cluster_app Application Layer / BSW Users cluster_csm Service Layer cluster_cryif ECU Abstraction Layer cluster_crypto Microcontroller Abstraction Layer (MCAL) SecOC SecOC / TLS / SW-C CSM Crypto Service Manager (csm) - Service-APIs (Csm_MacGenerate, ...) - Priorisierte Job-Queues - Csm_MainFunction SecOC->CSM Job / Service Request CSM->SecOC Application Callback CryIf Crypto Interface (cryif) - Channel Dispatching (CryIf_ProcessJob) - Key-ID Mapping (cryIfKeyId -> cryptoKeyId) - Callback Notification Dispatching CSM->CryIf CryIf_ProcessJob() / CryIf_Key*() CryIf->CSM Csm_CallbackNotification() CryptoDrv1 Crypto Driver (crypto) - HW - Crypto Driver Object 0(例如 AES / HSM) - NVM 同步 CryIf->CryptoDrv1 Crypto_ProcessJob() [Kanal 0] CryptoDrv2 Crypto Driver (crypto) - SW - Crypto Driver Object 1(例如软件 RSA) CryIf->CryptoDrv2 Crypto_ProcessJob() [Kanal 1] CryptoDrv1->CryIf CryIf_CallbackNotification() CryptoDrv2->CryIf CryIf_CallbackNotification()

上下文图:AUTOSAR 加密栈的分层架构与接口级联。来源:SWS_CryptoDriver 第15页、SWS_CryptoServiceManager 第29页

用于同步异步加密作业的是周期性的 Csm_MainFunction(),它清空队列并触发待处理的计算 [SWS_Csm_00479]。异步硬件计算完成后,Crypto Driver 通过 CryIf_CallbackNotification() 通知 CryIf,后者将消息进一步传递给 Csm_CallbackNotification(),并最终传递给调用应用程序 [SWS_CryIf_91013]、[SWS_Csm_00970]。

Crypto 集群中的异步加密作业流程ApplicationcsmcryifcryptoCsm_MacGenerate(jobId, mode, ...)检查作业 / 队列检查altTreiberobjekt freiCryIf_ProcessJob(channelId, job)Key-ID Mapping (cryIfKeyId -> cryptoKeyId)Crypto_ProcessJob(objectId, job)E_OK (Auftrag angenommen)E_OKTreiberobjekt belegt / Queuing aktivJob in CSM-Queue einreihenE_OK (Asynchron gepuffert)Csm_MainFunction(): Dequeue JobCryIf_ProcessJob(channelId, job)Crypto_ProcessJob(objectId, job)E_OKUse Case: Hardware-/Treiber-Berechnung & AbschlussKrypto-Primitive berechnen (HW/ISR)CryIf_CallbackNotification(job, result)Csm_CallbackNotification(job, result)CallbackNotification(result)

时序图:具有排队和回调级联的异步加密作业流程。来源:[SWS_Csm_00970]、[SWS_CryIf_91013]、AUTOSAR_CP_SWS_CryptoServiceManager 第146页

密钥管理通过诸如 Csm_KeyElementSet() 和 CryIf_KeyElementCopy() 等标准化接口进行,并严格遵守配置的访问权限 [SWS_Csm_00957]、[SWS_CryIf_91015]、[SWS_Crypto_00219]。仅在通过 Crypto_KeySetValid() 进行显式验证时才会触发在 NVM 中的持久化,从而避免了不完整的密钥存储 [SWS_Crypto_91014]、SWS_CryptoDriver 第37页。诸如过载或无效密钥状态等错误会通过 CRYPTO_E_BUSY 或 CRYPTO_E_KEY_NOT_VALID 被稳健地拦截 [SWS_Csm_00018]、[SWS_CryIf_91003]。

1. 系统架构与模块群集的作用

“Crypto Services & Hardware Abstraction”模块集群构成了 AUTOSAR Classic Platform 中加密操作、基于软件和硬件的密钥管理以及安全板载通信的功能基础 EXP_UtilizationOfCryptoServices 第8页。该架构严格按照 AUTOSAR 分层模型划分为三个标准化 BSW 模块:服务层中的 Crypto Service Manager(csm)、ECU Abstraction Layer 中的 Crypto Interface(cryif)以及 Microcontroller Abstraction Layer(MCAL)上的至少一个 Crypto Driver(crypto)SWS_CryptoDriver 第15页。该分层体系将安全应用(例如 SecOC、TLS 连接建立和 UDS 诊断身份验证)与专有加密协处理器(如硬件安全模块(HSM)或安全硬件扩展(SHE))完全抽象隔离开来 SWS_SecureOnboardCommunication 第78页。

Crypto Service Manager(CSM)充当应用程序组件(SW-C)和更高层 BSW 模块的主要服务提供商。它为对称和非对称算法(例如 AES、RSA)、哈希、消息身份验证码(MAC)、随机数生成(RNG)以及 AEAD 方法提供标准化编程接口 [SWS_Csm_00980]、[SWS_Csm_00982]、[SWS_Csm_00984]、[SWS_Csm_01023]。此外,CSM 还实现软件作业队列并控制并行加密作业的优先级排序 [SWS_Csm_00022]、SWS_CryptoServiceManager 第29页。

Crypto Interface(CryIf)作为抽象层,在 CSM 和任意数量的加密驱动程序之间提供统一的 1:n 接口。其核心任务是分发(Dispatching):它根据配置的逻辑通道(channelId)将作业转发给相应的 Crypto Driver 实例,并将逻辑密钥引用(cryIfKeyId)转换为驱动程序特定标识符(cryptoKeyId)[SWS_CryIf_00133]、[SWS_CryIf_91003]。Crypto Driver 封装了物理执行单元(Crypto Driver Object),并服务于纯软件加密原语或专用硬件安全模块 [SWS_Crypto_00224]、SWS_CryptoDriver 第15页。

CryptoArchitecture cluster_app Application Layer / BSW Users cluster_csm Service Layer cluster_cryif ECU Abstraction Layer cluster_crypto Microcontroller Abstraction Layer (MCAL) SecOC SecOC / TLS / SW-C CSM Crypto Service Manager (csm) - Service-APIs (Csm_MacGenerate, ...) - Priorisierte Job-Queues - Csm_MainFunction SecOC->CSM Job / Service Request CSM->SecOC Application Callback CryIf Crypto Interface (cryif) - Channel Dispatching (CryIf_ProcessJob) - Key-ID Mapping (cryIfKeyId -> cryptoKeyId) - Callback Notification Dispatching CSM->CryIf CryIf_ProcessJob() / CryIf_Key*() CryIf->CSM Csm_CallbackNotification() CryptoDrv1 Crypto Driver (crypto) - HW - Crypto Driver Object 0(例如 AES / HSM) - NVM 同步 CryIf->CryptoDrv1 Crypto_ProcessJob() [Kanal 0] CryptoDrv2 Crypto Driver (crypto) - SW - Crypto Driver Object 1(例如软件 RSA) CryIf->CryptoDrv2 Crypto_ProcessJob() [Kanal 1] CryptoDrv1->CryIf CryIf_CallbackNotification() CryptoDrv2->CryIf CryIf_CallbackNotification()

上下文图:AUTOSAR 加密栈的分层架构与接口级联。来源:SWS_CryptoDriver 第15页、SWS_CryptoServiceManager 第29页

2. 模块间的相互协作与交互路径

集群内的作业处理主要通过使用结构 Crypto_JobType 的基于作业的模型进行 [SWS_Csm_01013]、AUTOSAR_CP_SWS_CryptoServiceManager 第21页。一个加密作业捆绑了作业 ID、优先级信息、密钥引用、原语元数据以及用于输入、输出和长度参数指针管理的结构 Crypto_JobPrimitiveInputOutputType [SWS_Csm_01012]。通过位掩码字段 Crypto_OperationModeType(包含标志 START、UPDATE、FINISH)来控制作业是作为连贯的单次调用(SINGLECALL)计算,还是在流模式下增量计算 [SWS_Csm_01039]、[SWS_Csm_01029]。

当同步调用 CSM 服务函数时,CSM 会检查作业状态。若驱动程序空闲或作业被配置为同步,CSM 将直接调用 CryIf_ProcessJob() [SWS_Csm_00017]、[SWS_CryIf_91003]。CryIf 映射密钥 ID 并通过 Crypto_ProcessJob() 将作业分发至分配的驱动程序实例 [SWS_CryIf_00133]。对于异步请求,当驱动程序对象被占用时,作业会被排入 CSM 队列 [SWS_Csm_00018]、AUTOSAR_CP_SWS_CryptoServiceManager 第30页。在异步驱动程序计算完成后,驱动程序触发 CryIf_CallbackNotification() [SWS_CryIf_91013],CryIf 将该消息转发给 Csm_CallbackNotification() [SWS_Csm_00970],最终 CSM 通过其配置的回调通知请求的应用程序 [SWS_Csm_01044]、[SWS_Csm_00928]。

Crypto 集群中的异步加密作业流程ApplicationcsmcryifcryptoCsm_MacGenerate(jobId, mode, ...)检查作业 / 队列检查altTreiberobjekt freiCryIf_ProcessJob(channelId, job)Key-ID Mapping (cryIfKeyId -> cryptoKeyId)Crypto_ProcessJob(objectId, job)E_OK (Auftrag angenommen)E_OKTreiberobjekt belegt / Queuing aktivJob in CSM-Queue einreihenE_OK (Asynchron gepuffert)Csm_MainFunction(): Dequeue JobCryIf_ProcessJob(channelId, job)Crypto_ProcessJob(objectId, job)E_OKUse Case: Hardware-/Treiber-Berechnung & AbschlussKrypto-Primitive berechnen (HW/ISR)CryIf_CallbackNotification(job, result)Csm_CallbackNotification(job, result)CallbackNotification(result)

时序图:具有排队和回调级联的异步加密作业流程。来源:[SWS_Csm_00970]、[SWS_CryIf_91013]、AUTOSAR_CP_SWS_CryptoServiceManager 第146页

除主要的加密执行外,密钥管理也是该集群不可或缺的交互路径 SWS_CryptoDriver 第24页。一个密钥由多个逻辑密钥元素(如密钥材料、初始化向量或迭代值)组成 [SWS_Csm_00954]、[SWS_Csm_01022]。诸如通过 Csm_KeyElementSet() 设置密钥材料、通过 Csm_KeyElementCopy() 复制或通过 Csm_KeyDerive() 导出密钥等操作,均通过 CryIf(CryIf_KeyElementCopy()、CryIf_KeyDerive())同步转发至驱动程序函数 [SWS_Csm_00957]、[SWS_Csm_00969]、[SWS_CryIf_91015]、[SWS_CryIf_91009]。在此过程中,对密钥元素的访问受到配置的访问权限(CRYPTO_RA_ALLOWED、CRYPTO_RA_ENCRYPTED、CRYPTO_RA_INTERNAL_COPY)的严格监控 [SWS_Crypto_00219]。

3. 同步、可重入性与任务上下文

加密操作的执行时间差异极大。虽然快速的分组密码或哈希计算可以在调用者的任务上下文中同步执行,但非对称计算(例如 RSA 签名生成)或耗时的硬件流程需要进行异步处理 [SWS_Csm_00984]、[SWS_Csm_00992]。为了实现解耦,CSM 提供了循环调用的主函数 Csm_MainFunction() [SWS_Csm_00479]。该函数监控队列,将待处理作业分发至 CryIf,并推进异步原语的内部状态机 [SWS_Csm_00019]。

在现代多核和多扇区架构中,CSM 支持多个实例 Csm_MainFunction_<shortName>(),这些实例分配给专用的 OS 分区 [SWS_Csm_00479]、AUTOSAR_SWS_CryptoServiceManager 第170页。在异步驱动程序执行中,计算要么通过驱动程序 MainFunction 中的轮询完成,要么通过基于硬件的加密引擎的中断服务例程(ISR)完成 [SWS_Crypto_00027]、[SWS_Crypto_00028]。根据定义,单个 Crypto Driver Object 同一时间只能恰好处理一个加密作业;具有 n 个对象的驱动程序可以真正并行处理 n 个作业 [SWS_Crypto_00014]、[SWS_Crypto_00117]。

关于可重入性,诸如 Csm_MacGenerate() 或 CryIf_ProcessJob() 之类的服务接口被设计为针对不同作业是可重入的,但禁止对同一作业实例进行并行多次调用 [SWS_Csm_00016]、[SWS_CryIf_91003]。诸如 Csm_KeyElementCopy()、CryIf_KeyElementCopy() 或 Crypto_KeyCopy() 等密钥管理功能实现为可重入的,但不得并发应用于同一源密钥标识符(keyId 或 cryptoKeyId),以避免数据不一致和竞态条件 [SWS_Csm_00969]、[SWS_CryIf_91015]、[SWS_Crypto_00155]。硬件驱动程序可以使用内部互斥区域(Exclusive Areas)来修改内部工作区和密钥寄存器,以拦截 ISR 与任务级别之间的竞态条件 SWS_CryptoDriver 第27页。 问题 Q-b1e9578255723a0e (未决)

CsmDispatchLogic Start Eintritt Csm_<Service>() CheckActive Job aktiv? (jobState == ACTIVE) Start->CheckActive CheckSync Synchroner Modus? (CRYPTO_PROCESSING_SYNC) CheckActive->CheckSync Nein DirectCall 执行 CryIf_ProcessJob() CheckActive->DirectCall Ja (Streaming Update/Finish) CheckSync->DirectCall Ja CheckQueueEmpty CSM-Queue leer? CheckSync->CheckQueueEmpty Nein (Asynchron) CheckPrio 优先级是否高于最高队列作业? CheckQueueEmpty->CheckPrio Nein ForwardCryIf Job sofort dispatchen: CryIf_ProcessJob() CheckQueueEmpty->ForwardCryIf Ja CheckQueueFull CSM-Queue voll? CheckPrio->CheckQueueFull Nein CheckPrio->ForwardCryIf Ja EnqueueJob Job in CSM-Queue einreihen Return E_OK CheckQueueFull->EnqueueJob Nein ReturnBusy Return CRYPTO_E_BUSY (Det: CSM_E_QUEUE_FULL) CheckQueueFull->ReturnBusy Ja

活动图:CSM 中作业接收时的决策逻辑与排队解耦。来源:AUTOSAR_CP_SWS_CryptoServiceManager 第30页、[SWS_Csm_00017]、[SWS_Csm_00018]

4. 典型生命周期与运行模式

加密集群的初始化在 BSW 启动期间按分层顺序进行。首先,EcuM 或 BswM 通过传递配置 Crypto_ConfigType 经由 Crypto_Init() 初始化驱动程序级 [SWS_Crypto_91016],随后通过带有 CryIf_ConfigType 的 CryIf_Init() 初始化接口层 [SWS_CryIf_91118]。最后,通过 Csm_Init() 启动 CSM,其中根据规范,其配置指针必须始终设置为 NULL_PTR [SWS_Csm_00646]。只有在所有层完全初始化后,才允许接受加密作业或密钥访问 [SWS_CryIf_00076]、[SWS_Crypto_00196]。

密钥生命周期的一个核心方面是非易失性存储器(NVM)中的验证与持久化。在通过 Csm_KeyElementSet() 加载新密钥值后,密钥保持在“不完整或未知”状态 [SWS_Csm_00957]。只有显式调用 Csm_JobKeySetValid() 或 Crypto_KeySetValid() 才会检查一致性并将密钥状态切换为有效 [SWS_Csm_91027]、[SWS_Crypto_91014]。对于持久化密钥,仅此验证会触发在 NVM 中的存储 [SWS_Crypto_91026]、SWS_CryptoDriver 第37页。这可以防止多次零碎的 NVM 写入周期并防止出现不完整的密钥集 SWS_CryptoDriver 第37页。为了与 NVRAM Manager 同步,Crypto Driver 使用回调 Crypto_<vi>_<ai>_NvBlock_ReadFrom_<NvBlock>() 和 Crypto_<vi>_<ai>_NvBlock_WriteTo_<NvBlock>() 以及 NvM_WriteBlock() [SWS_Crypto_91024]、[SWS_Crypto_91025]、[SWS_Crypto_91017]。

正在运行的流作业在需要时可以通过 Csm_SaveContextJob() 中断,保存在应用程序专用的缓冲区中,并在稍后通过上下文恢复继续进行 [SWS_Csm_91063]、[SWS_Csm_01029]。在 ECU 关机或转换到低功耗模式之前,可以通过 Csm_CancelJob() 受控地中止异步作业,从而使 CryIf 通过 CryIf_CancelJob() 从驱动程序队列和硬件通道中移除作业 [SWS_Csm_00968]、[SWS_CryIf_91014]。

5. 错误处理、DET 跟踪与降级

该集群实现了多级错误检测与防御策略。在激活跟踪时,开发错误会直接报告给 Default Error Tracer(DET)模块 [SWS_Csm_91101]、[SWS_Crypto_91017]。典型的 DET 事件包括初始化之前的模块调用(CRYIF_E_UNINIT、CRYPTO_E_UNINIT)、无效的句柄或密钥参数(CRYIF_E_PARAM_HANDLE、CRYPTO_E_PARAM_HANDLE)以及空指针传递 [SWS_CryIf_00076]、[SWS_CryIf_00134]、[SWS_Crypto_00196]、[SWS_Crypto_00217]。

运行时过载和资源瓶颈通过定义的返回值进行确定性拦截。如果用于异步作业的 CSM 队列已耗尽,CSM 将以状态代码 CRYPTO_E_BUSY 拒绝该作业,并生成运行时错误 CSM_E_QUEUE_FULL [SWS_Csm_00018]、[SWS_Csm_01089]。如果提供的结果缓冲区尺寸不足,驱动程序将以 CRYPTO_E_SMALL_BUFFER 中止操作 [SWS_Crypto_00195]。如果加密服务引用了未初始化或显式失效的密钥(例如在调用 Csm_JobKeySetInvalid() 或 Crypto_KeySetInvalid() 之后),服务请求将受控地失败并返回 CRYPTO_E_KEY_NOT_VALID 或 CRYPTO_E_KEY_EMPTY [SWS_Csm_91002]、[SWS_CryIf_91003]、[SWS_Crypto_91020]。

降级和回退机制在系统级得以实现:应用程序可以在提交作业前通过 Csm_KeyGetStatus() 检查密钥的完整性状态 [SWS_Csm_91047]、[SWS_CryIf_91012]。如果硬件加密加速器被永久占用或发生故障,只要集成了冗余的软件驱动程序,CryIf 通道配置就允许采用基于软件的替代路由 SWS_CryptoDriver 第15页。

本指南完全基于 AUTOSAR Classic 规范 R20-11,并由 autodocs 管理助手生成。

Die Crypto Services bieten hardware- und softwaregestützte Kryptographie-Primitive (CSM, CryIf, Crypto-Treiber) für symmetrische/asymmetrische Verschlüsselung, Signaturen und Hashing.

Module im Cluster

Crypto Abstraction Library (Cal)

AUTOSAR Classic Crypto Services-Modul Crypto Abstraction Library (Cal, Spezifikation: AUTOSAR_SWS_CryptoAbstractionLibrary.pdf).

BSW ID 206 Keine C-API · 0 Records #include "Cal.h"

Crypto Interface (CryIf)

Abstracts cryptographic hardware and software acceleration engines.

BSW ID 112 19 APIs (18 Funktionen, 1 Typen) #include "CryIf.h"

Crypto Driver (Crypto)

Low-level driver executing cryptographic primitives on hardware security modules (HSM) or software libraries.

BSW ID 114 20 APIs (19 Funktionen, 1 Typen) #include "Crypto.h"

Crypto Service Manager (CSM)

Provides standardized cryptographic services (encryption, hashing, digital signatures, key management) to applications and BSW.

BSW ID 110 82 APIs (38 Funktionen, 44 Typen) #include "Csm.h"

主题图

CSM

82
<Csm_ApplicationCallbackNotification>Csm_AEADDecryptCsm_AEADEncryptCsm_CallbackNotificationCsm_CancelJobCsm_DecryptCsm_EncryptCsm_GetVersionInfoCsm_HashCsm_InitCsm_JobKeyDeriveCsm_JobKeyExchangeCalcPubValCsm_JobKeyExchangeCalcSecretCsm_JobKeyGenerateCsm_JobKeySetInvalidCsm_JobKeySetValidCsm_JobRandomSeedCsm_KeyCopyCsm_KeyDeriveCsm_KeyElementCopyCsm_KeyElementCopyPartialCsm_KeyElementGetCsm_KeyElementSetCsm_KeyExchangeCalcPubValCsm_KeyExchangeCalcSecretCsm_KeyGenerateCsm_KeyGetStatusCsm_KeySetInvalidCsm_KeySetValidCsm_MacGenerateCsm_MacVerifyCsm_MainFunctionCsm_RandomGenerateCsm_RandomSeedCsm_RestoreContextJobCsm_SaveContextJobCsm_SignatureGenerateCsm_SignatureVerifyCrypto_AlgorithmFamilyTypeCrypto_AlgorithmInfoTypeCrypto_AlgorithmModeTypeCrypto_InputOutputRedirectionConfigTypeCrypto_JobPrimitiveInfoTypeCrypto_JobPrimitiveInputOutputTypeCrypto_JobRedirectionInfoTypeCrypto_JobStateTypeCrypto_JobTypeCrypto_KeyStatusTypeCrypto_OperationModeTypeCrypto_PrimitiveInfoTypeCrypto_ProcessingTypeCrypto_ResultTypeCrypto_ServiceInfoTypeCrypto_VerifyResultTypeCsm_AEADDecryptAssociatedDataTypeCsm_AEADDecryptCiphertextTypeCsm_AEADDecryptPlaintextTypeCsm_AEADDecryptTagTypeCsm_AEADEncryptAssociatedDataTypeCsm_AEADEncryptCiphertextTypeCsm_AEADEncryptPlaintextTypeCsm_AEADEncryptTagTypeCsm_ConfigIdTypeCsm_ConfigTypeCsm_DecryptDataTypeCsm_DecryptResultTypeCsm_EncryptDataTypeCsm_EncryptResultTypeCsm_HashDataTypeCsm_HashResultTypeCsm_KeyDataTypeCsm_LengthPtrCsm_MacGenerateDataTypeCsm_MacGenerateResultTypeCsm_MacVerifyCompareTypeCsm_MacVerifyDataTypeCsm_RandomGenerateResultTypeCsm_SignatureGenerateDataTypeCsm_SignatureGenerateResultTypeCsm_SignatureVerifyCompareTypeCsm_SignatureVerifyDataTypeCsm_VerifyResultPtr

详细视图

请在大纲中选择一个条目。

CryIf

Notifies the CRYIF about the completion of the request with the result of the cryptographic operation.

void CryIf_CallbackNotification (Crypto_JobType* job, Crypto_ResultType result);

This interface dispatches the job cancellation function to the configured crypto driver object.

Std_ReturnType CryIf_CancelJob (uint32 channelId, Crypto_JobType* job);

Returns the version information of this module.

void CryIf_GetVersionInfo (Std_VersionInfoType* versioninfo);
CryIf_Init 函数

Initializes the CRYIF module. AUTOSAR CP R20 - of Document ID : AUTOSAR_SWS_CryptoInterface

void CryIf_Init (const CryIf_ConfigType* configPtr);

This function shall co py all key elements from the source key to a target key.

Std_ReturnType CryIf_KeyCopy (uint32 cryIfKeyId, uint32 targetCryIfKeyId);

This function shall dispatch th e key derive function to the configured crypto driver object.

Std_ReturnType CryIf_KeyDerive (uint32 cryIfKeyId, uint32 targetCryIfKeyId);

Service CryIf_KeyElementCopy.

Std_ReturnType CryIf_KeyElementCopy (uint32 cryIfKeyId, uint32 keyElementId, uint32 targetCryIfKeyId, uint32 targetKeyElementId);

Service CryIf_KeyElementCopyPartial.

Std_ReturnType CryIf_KeyElementCopyPartial (uint32 cryIfKeyId, uint32 keyElementId, uint32 keyElementSourceOffset, uint32 keyElementTargetOffset, uint32 keyElementCopyLength, uint32 targetCryIfKeyId, uint32 targetKeyElementId);

This function shall dispatch the get key ele ment function to the configured crypto driver object.

Std_ReturnType CryIf_KeyElementGet (uint32 cryIfKeyId, uint32 keyElementId, uint8* resultPtr, uint32* resultLengthPtr);

This function shall dispatch the set key element function to the configured crypto driver object.

Std_ReturnType CryIf_KeyElementSet (uint32 cryIfKeyId, uint32 keyElementId, const uint8* keyPtr, uint32 keyLength);

This function shall dispatch the key exchange public value calculation function to the configured crypto driver object. Available

Std_ReturnType CryIf_KeyExchangeCalcPubVal (uint32 cryIfKeyId, uint8* publicValuePtr, uint32* publicValueLengthPtr);

This function shall dispatch the key exchange common shared secret calculation function to the configured crypto driver object.

Std_ReturnType CryIf_KeyExchangeCalcSecret (uint32 cryIfKeyId, const uint8* partnerPublicValuePtr, uint32 partnerPublicValueLength);

This function shall dispatch the key generate function to the configured crypto driver object.

Std_ReturnType CryIf_KeyGenerate (uint32 cryIfKeyId);

Returns the key state of the key identified by cry If Key Id.

Std_ReturnType CryIf_KeyGetStatus (uint32 cryIfKeyId, Crypto_KeyStatusType* keyStatusPtr);

Sets invalid for the status of the key identifi ed by cry If Key Id.

Std_ReturnType CryIf_KeySetInvalid (uint32 cryIfKeyId);

This function shall dispatch the set key valid function to the configured crypto driver object.

Std_ReturnType CryIf_KeySetValid (uint32 cryIfKeyId);

Service CryIf_ProcessJob.

Std_ReturnType CryIf_ProcessJob (uint32 channelId, Crypto_JobType* job);

This function shall dispatch the random seed function to the configured crypto driver object.

Std_ReturnType CryIf_RandomSeed (uint32 cryIfKeyId, const uint8* seedPtr, uint32 seedLength);

Configuration data structure of Cry If module

Crypto

This interface removes the provided job from the queue and cancels the processing of the job if possible.

Std_ReturnType Crypto_CancelJob (uint32 objectId, Crypto_JobType* job);

Returns the version information of this module.

void Crypto_GetVersionInfo (Std_VersionInfoType* versioninfo);

Initializes the Crypto Driver.

void Crypto_Init (const Crypto_ConfigType* configPtr);

Copies a key with all its elements to another key in the same crypto driver. Note: If the actual key element is directly mapped to flash memory, there could be a bigger delay when calling this function (synchronous operation)

Std_ReturnType Crypto_KeyCopy (uint32 cryptoKeyId, uint32 targetCryptoKeyId);

Derives a new key by using the key elements in the given key identified by the crypto Key Id. The given key contains the key elements for the password, salt. The derived key is stored in the key element with the id 1 of the key identified by target Crypto Key Id. The number of iterations is given in the key element CRYPTO_ KE_ KEYDERIVATION_ ITERATIONS.

Std_ReturnType Crypto_KeyDerive (uint32 cryptoKeyId, uint32 targetCryptoKeyId);

Service Crypto_KeyElementCopy.

Std_ReturnType Crypto_KeyElementCopy (uint32 cryptoKeyId, uint32 keyElementId, uint32 targetCryptoKeyId, uint32 targetKeyElementId);

Service Crypto_KeyElementCopyPartial.

Std_ReturnType Crypto_KeyElementCopyPartial (uint32 cryptoKeyId, uint32 keyElementId, uint32 keyElementSourceOffset, uint32 keyElementTargetOffset, uint32 keyElementCopyLength, uint32 targetCryptoKeyId, uint32 targetKeyElementId);

This interface shall be used to get a key element of the key identified by the crypto

Std_ReturnType Crypto_KeyElementGet (uint32 cryptoKeyId, uint32 keyElementId, uint8* resultPtr, uint32* resultLengthPtr);

Used to retrieve information which key elements are available in a given key.

Std_ReturnType Crypto_KeyElementIdsGet (uint32 cryptoKeyId, uint32* keyElementIdsPtr, uint32* keyElementIdsLengthPtr);

Sets the given key element bytes to the key identified by crypto Key Id.

Std_ReturnType Crypto_KeyElementSet (uint32 cryptoKeyId, uint32 keyElementId, const uint8* keyPtr, uint32 keyLength);

Calculates the public value for the key exchange a nd stores the public key in the memory location pointed by the public value pointer.

Std_ReturnType Crypto_KeyExchangeCalcPubVal (uint32 cryptoKeyId, uint8* publicValuePtr, uint32* publicValueLengthPtr);

Calculates the shared secret key for the key exchange with the key material of the key identified by the crypto Key Id and the partner public key. The shared secret key is stored as a key element in the same key.

Std_ReturnType Crypto_KeyExchangeCalcSecret (uint32 cryptoKeyId, const uint8* partnerPublicValuePtr, uint32 partnerPublicValueLength);

Generates new key material store it in the key identified by crypto Key Id.

Std_ReturnType Crypto_KeyGenerate (uint32 cryptoKeyId);

Returns the key state of the key identified by crypto Key Id.

Std_ReturnType Crypto_KeyGetStatus (uint32 cryptoKeyId, Crypto_KeyStatusType* keyStatusPtr);

Sets invalid for the status of the key identifi ed by crypto Key Id.

Std_ReturnType Crypto_KeySetInvalid (uint32 cryptoKeyId);

Sets the key state of the key identified by crypto Key Id to valid.

Std_ReturnType Crypto_KeySetValid (uint32 cryptoKeyId);

If asynchronous job processing is configured and there are job queues, the function is called cyclically to process queued jobs. AUTOSAR CP R20 - of Document ID : AUTOSAR_SWS_CryptoDriver

void Crypto_MainFunction (void);

Service Crypto_ProcessJob.

Std_ReturnType Crypto_ProcessJob (uint32 objectId, Crypto_JobType* job);

This function generates the internal seed state using the pro vided entropy source. Furthermore, this function can be used to update the seed state with new entropy

Std_ReturnType Crypto_RandomSeed (uint32 cryptoKeyId, const uint8* seedPtr, uint32 seedLength);

Configuration data structure of Cry If module

CSM

CSM notifies the application that a job has finished. The function name is configurable. The function name itself is derived from "{CSM Job/ CSM Job Primitive Callback Ref}/CSM Callback Func".

void <Csm_ApplicationCallbackNotification> (uint32 jobId, Crypto_ResultType result);

Service Csm_AEADDecryptManager.

Std_ReturnType Csm_AEADDecrypt (uint32 jobId, Crypto_OperationModeType mode, const uint8* ciphertextPtr, uint32 ciphertextLength, const uint8* associatedDataPtr, uint32 associatedDataLength, const uint8* tagPtr, uint32 tagLength, uint8* plaintextPtr, uint32* plaintextLengthPtr, Crypto_VerifyResultType* verifyPtr);

Service Csm_AEADEncrypt.

Std_ReturnType Csm_AEADEncrypt (uint32 jobId, Crypto_OperationModeType mode, const uint8* plaintextPtr, uint32 plaintextLength, const uint8* associatedDataPtr, uint32 associatedDataLength, uint8* ciphertextPtr, uint32* ciphertextLengthPtr, uint8* tagPtr, uint32* tagLengthPtr);

Notifies the CSM that a job has finished. This function is used by the underlying layer (CRYIF).

void Csm_CallbackNotification (Crypto_JobType* job, Crypto_ResultType result);

Cancels the job processing from asynchronous or streaming jobs .

Service Csm_Decrypt.

Std_ReturnType Csm_Decrypt (uint32 jobId, Crypto_OperationModeType mode, const uint8* dataPtr, uint32 DataLength, uint8* resultPtr, uint32* resultLengthPtr);

Service Csm_Encrypt.

Std_ReturnType Csm_Encrypt (uint32 jobId, Crypto_OperationModeType mode, const uint8* dataPtr, uint32 DataLength, uint8* resultPtr, uint32* resultLengthPtr);

Returns the version information of this module.

void Csm_GetVersionInfo (Std_VersionInfoType* versioninfo);
Csm_Hash 函数

Uses the given data to perform the hash calculation and stores the hash.

Std_ReturnType Csm_Hash (uint32 jobId, Crypto_OperationModeType mode, const uint8* dataPtr, uint32 DataLength, uint8* resultPtr, uint32* resultLengthPtr);
Csm_Init 函数

Initializes the CSM module. In configurations, in which CSM is assigned to more than one partition (i.e. Csm_ Main Functions are mapped to partitions), CSM may provide one init function per partition.

void Csm_Init (const Csm_ConfigType* configPtr);

Derives a new key by using the key elements in the given key identified by the key Id. The given key contains the key elements for the password and salt. The derived key is stored in the key element with the id 1 of the key identified by target Crypto

Std_ReturnType Csm_JobKeyDerive (uint32 jobId, uint32 keyId, uint32 targetKeyId);

Calculates the public value of the current user for the key exchange and stores the

Std_ReturnType Csm_JobKeyExchangeCalcPubVal (uint32 jobId, uint32 keyId, uint8* publicValuePtr, uint32* publicValueLengthPtr);

Calculates the shared secret key for the key exchange with the key material of the key identified by the key Id and the partner public key. The shared secret key is stored as a key element in the same key.

Std_ReturnType Csm_JobKeyExchangeCalcSecret (uint32 jobId, uint32 keyId, const uint8* partnerPublicValuePtr, uint32 partnerPublicValueLength);

Generates new key material and stores it in the key identified by key Id.

Std_ReturnType Csm_JobKeyGenerate (uint32 jobId, uint32 keyId);

Sets the key status to invalid. The key cannot be used any longer for cryptographic operations until it has been set to valid state again.

Std_ReturnType Csm_JobKeySetInvalid (uint32 jobId, uint32 keyId);

Stores the key if necessary and sets the key state of the key identified by key Id to valid.

Std_ReturnType Csm_JobKeySetValid (uint32 jobId, uint32 keyId);

Provides a new seed for the specified key that is used for an associated random number generator.

Std_ReturnType Csm_JobRandomSeed (uint32 jobId, uint32 keyId, const uint8* seedPtr, Manager uint32 seedLength);

This function shall copy all key elements from the source key to a target key. Ava ilable via Csm.h

Std_ReturnType Csm_KeyCopy (const uint32 keyId, const uint32 targetKeyId);

Derives a new key by using the key elements in the given key identified by the key Id. The given key contains the key elements for the password and salt. The derived key is stored in the k ey element with the id 1 of the key identified by target Crypto Key Id.

Std_ReturnType Csm_KeyDerive (uint32 keyId, uint32 targetKeyId);

Service Csm_KeyElementCopyManager.

Std_ReturnType Csm_KeyElementCopy (const uint32 keyId, const uint32 keyElementId, const uint32 targetKeyId, const uint32 targetKeyElementId);

Service Csm_KeyElementCopyPartial.

Std_ReturnType Csm_KeyElementCopyPartial (uint32 keyId, uint32 keyElementId, uint32 keyElementSourceOffset, uint32 keyElementTargetOffset, uint32 keyElementCopyLength, uint32 targetKeyId, uint32 targetKeyElementId);

Service Csm_KeyElementGet.

Std_ReturnType Csm_KeyElementGet (uint32 keyId, uint32 keyElementId, uint8* keyElementPtr, Manager uint32* keyElementLengthPtr);

Sets the given key element bytes to the key identified by key Id.

Std_ReturnType Csm_KeyElementSet (uint32 keyId, uint32 keyElementId, const uint8* keyElementPtr, uint32 keyElementLength);

Calculates the public value of the current user for the key exchange and stores the pub lic key in the memory location pointed by the public value pointer.

Std_ReturnType Csm_KeyExchangeCalcPubVal (uint32 keyId, uint8* publicValuePtr, uint32* publicValueLengthPtr);

Calculates the shared secret key for the key exchange with the key material of the key identified by the key Id and the partner public key. The shared secret key is stored as a key element in the same key.

Std_ReturnType Csm_KeyExchangeCalcSecret (uint32 keyId, const uint8* partnerPublicValuePtr, uint32 partnerPublicValueLength);

Generates new key material and store it in the key identified by key Id.

Std_ReturnType Csm_KeyGenerate (uint32 keyId);

Returns the key state of the key identified by key Id.

Std_ReturnType Csm_KeyGetStatus (uint32 keyId, Crypto_KeyStatusType* keyStatusPtr);

Sets the key status to invalid. The key cannot be used any longer for cryptographic operations until it has been set to valid state again.

Std_ReturnType Csm_KeySetInvalid (uint32 keyId);

Sets the key state of the key identified by key Id to valid.

Std_ReturnType Csm_KeySetValid (uint32 keyId);

Service Csm_MacGenerate.

Std_ReturnType Csm_MacGenerate (uint32 jobId, Crypto_OperationModeType mode, const uint8* dataPtr, uint32 DataLength, uint8* macPtr, uint32* macLengthPtr);

Service Csm_MacVerify.

Std_ReturnType Csm_MacVerify (uint32 jobId, Crypto_OperationModeType mode, const uint8* dataPtr, uint32 DataLength, const uint8* macPtr, const uint32 macLength, Crypto_VerifyResultType* verifyPtr);

API to be called cyclically to process the requested jobs. The Csm_ Main Function shall check the queues for jobs to pass to the underlying CRYIF. Per configured CSM Main Function ins tance one Csm_ Main Function_ shall be implemented. Hereby is the short name of the CSM Main Function configuration container in the ECU configuration.

void Csm_MainFunction (void);

Generate a random number and stores it in the memory location pointed by th e result pointer.

Std_ReturnType Csm_RandomGenerate (uint32 jobId, uint8* resultPtr, uint32* resultLengthPtr);

Feeds the key element CRYPTO_ KE_ RANDOM_ SEED with a random seed. Manager AUTOSAR CP R20 - of Document ID : AUTOSAR_SWS_CryptoServiceManager

Std_ReturnType Csm_RandomSeed (uint32 keyId, const uint8* seedPtr, uint32 seedLength);

The Crypto Driver extracts the context data from the context Buffer and restores the internal state so that further crypto operation of this crypto service will continue at the exact point when the context was taken.

Std_ReturnType Csm_RestoreContextJob (uint32 jobId, uint8* contextBufferPtr, uint32 contextBufferLength);

The Crypto Driver stores the internal context of the respective crypto operation to the context Buffer.

Std_ReturnType Csm_SaveContextJob (uint32 jobId, uint8* contextBufferPtr, uint32* contextBufferLengthPtr);

Service Csm_SignatureGenerate.

Std_ReturnType Csm_SignatureGenerate (uint32 jobId, Crypto_OperationModeType mode, const uint8* dataPtr, uint32 DataLength, uint8* signaturePtr, uint32* signatureLengthPtr);

Service Csm_SignatureVerify.

Std_ReturnType Csm_SignatureVerify (uint32 jobId, Crypto_OperationModeType mode, const uint8* dataPtr, uint32 DataLength, const uint8* signaturePtr, uint32 signatureLength, Crypto_VerifyResultType* verifyPtr);

Type Crypto_AlgorithmFamilyType.

Structure which determines the exact algorithm. Note, not every algorithm needs to specify all fields. AUTOSAR shall only allow valid combinations.

Type Crypto_AlgorithmModeType.

Defines which of the input/ output parameters are re - directed to a key element. The values can be combined to define a bit field.

Structure which contains further information, which depends on the job and the crypto primitive.

Type Crypto_JobPrimitiveInputOutputType.

Type Crypto_JobRedirectionInfoType.

Enumeration of the current job state.

Structure which contains further information, which depends on the job and the crypto primitive.

Enumeration for key status.

Enume ration which operation shall be performed. This enumeration is constructed from a bit mask, where the first bit indicates "Start", the second "Update" and the third "Finish".

Structure which contains basic information about the crypto primitive. Manager AUTOSAR CP R20 - of Document ID : AUTOSAR_SWS_CryptoServiceManager

Enumeration of the processing type.

Return for Std_ Return Type for Cryptostack.

Enumeration of the kind of the service.

Enumeration of the result type of verification operations.

Array long enough to store the data of the header.

Array long enough to store the ciphertext to be decrypted with AEAD.

Array long enough to store the data of the plaintext.

Array long enough to store the data of the Tag.

Array long enough to store the data of the header.

Array long enough to store the data of the cipher.

Array long enough to store the plaintext to be encrypted with AEAD.

Array long enough to store the data of the Tag.

Identification of a CSM service configuration via a numeric identifier, that is unique within a service. The name of a CSM service configuration, i.e. the name of the container Csm_Config, shall serve as a symbolic name for this parameter Avail able via Csm.h

Configuration data structure of CSM module

Array long enough to store the data to be decrypted.

Array long enough to store the data of the decrypted plaintext.

Array long enough to store the data to be encrypted.

Array long enough to store the data of the cipher.

Array long enough to store the data which shall be hashed.

Array long enough to store the data of the hash.

Array long enough to store any key element of the considered key

Implementation Data Type of category DATA_ REFERENCE with the pointer target uint32 to be able to return asynchronously the length.

Array long enough to store the data from which a MAC shall be generated.

Array long enough to store the data of the MAC.

Array long enough to store a MAC to be verified.

Array long enough to store the data for whichs MAC shall be verified.

Array long enough to store the data of the random number.

Array long enough to store the data from which the signature shall be generated.

Array long enough to store the signature and its length.

Array long enough to store a signature to be verified.

Array long enough to store the data for whichs signature shall be verified.

Implementation Data Type of category DATA_ REFERENCE with the pointer target Csm_ Verify Result Type to be able to return asynchronously the verify result.