Commit f99e718
committed
Add AUTOSAR Classic Crypto Driver + Adaptive CryptoProvider
Adds a new port/ that exposes the wolfHSM client API as the standard
AUTOSAR R22-11 Crypto interfaces, so wolfHSM can replace OEM / vendor
HSM firmware in existing AUTOSAR Classic and Adaptive stacks with no
SWC code changes.
Layout
port/autosar/classic/ AUTOSAR Classic Crypto Driver (C, R22-11)
implements AUTOSAR_SWS_CryptoDriver; drops
in below CryIf in any AUTOSAR Classic BSW.
port/autosar/adaptive/ AUTOSAR Adaptive CryptoProvider (C++17).
Lives in a wolfhsm::ara_crypto namespace so
the port itself stays free of AUTOSAR-
Consortium-licensed headers; integrators
write a thin ara::crypto::cryp::CryptoProvider
adapter that forwards each call.
port/autosar/common/ algorithm + key-id mapping shared by both.
port/autosar/docs/ integration guides, algorithm coverage
matrix, and a note on the one in-port
translation (client_workarounds.md).
Classic — primitives wired through both sync and real async paths
(Crypto_MainFunction drives wolfHSM Request/Response):
- Hash: SHA-256 / 384 / 512 (single-call and START / UPDATE /
FINISH streamed)
- AES: ECB / CBC / CTR / GCM
- MAC: AES-CMAC (gen + verify)
- Signature: ECDSA P-256, Ed25519 (RFC 8032 pure), RSA-PKCS#1-v1.5
(sign + verify, plus tampered-sig negative paths)
- Key agreement: ECDH (P-256)
- KDF: HKDF, CMAC-KDF
- Key management: KeyElementSet / Get / Copy, KeyCopy,
KeySetValid, KeyGenerate (AES / ECC / Ed25519 / X25519 / RSA),
KeyDerive, KeyExchangeCalcPubVal / CalcSecret
- RNG: RandomGenerate
Async dispatcher honours wolfHSM's "one Request in-flight per
whClientContext" contract — Crypto_ProcessJob enqueues into
WH_AUTOSAR_ASYNC_QUEUED; Crypto_MainFunction promotes the oldest
queued slot to PENDING only when nothing else is in flight.
Crypto_CancelJob handles the cancel-vs-completion race. Hash async
chunks input across as many Sha*UpdateRequest cycles as needed.
PENDING slots that exceed CRYPTO_ASYNC_TIMEOUT_TICKS are force-
cleaned; resource cleanup goes through a single slotFreeWcResources
path so wc_*Free runs exactly once on every terminal transition.
Adaptive — WolfhsmCryptoProvider with nine context classes:
- RandomGeneratorCtx, HashFunctionCtx
- SymmetricBlockCipherCtx (AES ECB/CBC/CTR)
- AuthCipherCtx (AES-GCM)
- MessageAuthnCodeCtx (AES-CMAC)
- SignerPrivateCtx / VerifierPublicCtx (ECDSA, Ed25519,
RSA-PKCS1-v1.5; same isVerifyRejection translation as Classic)
- KeyAgreementPrivateCtx (ECDH P-256)
- KeyDerivationFunctionCtx (HKDF, CMAC-KDF)
- KeyStorageProvider (Save / Load / Commit / Erase)
Tests
csm_smoke (Classic, C, per-category):
- test_kat.c: NIST SHA / AES-CBC / ECDSA / Ed25519 / RSA-PKCS1v1.5
sign+verify+tampered-sig.
- test_det.c: 10 parameter-check paths assert their
(serviceId, errorId) tuples fire through Det_ReportError.
- test_accounting.c: every test asserts
wh_Autosar_DebugActiveSlotCount and ActiveHashStateCount return
to zero, with a 2-second drain budget.
- test_concurrency.c: 2 worker threads x 500 ms + a cancel
thread; asserts submitted - cancelled == callbacks_delivered.
- test_timeout.c: synthetic fake-pending injection + tick advance
exercises the force-cleanup path deterministically.
- test_cancel.c: accepts both cancel-vs-completion race outcomes
via per-job callback tracking.
ap_smoke (Adaptive, C++17): one end-to-end test per cluster
against wh_posix_server.
CI: new .github/workflows/build-and-test-autosar.yml builds the POSIX
server, csm_smoke and ap_smoke, runs both suites under ASAN on/off.
clang-format-check.yml passes on every new file in the diff.
Sample smoke output (TCP against wh_posix_server):
[basic]
[kat]
KAT hash: 5 vector(s) OK
KAT aes-cbc: 2 vector(s) OK
KAT ecdsa P-256: sign + good-sig verify + tampered-sig OK
KAT ed25519: keygen + sign + verify + tampered-sig OK
KAT rsa-pkcs1-v1.5 2048: keygen + sign + verify + tampered-sig OK
[det]
DET: 10 parameter-check paths fire correct (apiId, errorId)
[accounting]
accounting: leak-free across UPDATE/START misuse + 20-cycle async churn
[cancel]
cancel: queued / pending / unknown-job paths OK
[timeout]
timeout: force-cleanup after CRYPTO_ASYNC_TIMEOUT_TICKS fires E_NOT_OK callback
[concurrency]
concurrency: 32 async submitted, N cancelled, (32-N) callbacks delivered
csm_smoke: all tests passed
wolfHSM Adaptive Crypto Provider smoke (TCP)
Random OK (32 bytes)
Hash SHA-256("abc") matches NIST vector
AES-CBC-128 NIST F.2.1 OK
AES-GCM-128 roundtrip OK
CMAC-AES generate + verify good + verify tampered OK
ECDSA P-256 sign + verify-good + verify-bad OK
ECDH P-256 shared secret OK (32 bytes)
HKDF-SHA256 -> 32 bytes OK
KeyStorage save / load roundtrip OK
ap_smoke: all tests passed
Scope notes
- No vendor BSW headers vendored. Crypto.h, Crypto_GeneralTypes.h
and the ara::crypto-shaped C++ headers are written from the
public AUTOSAR SWS documents. Integrators supply Std_Types.h,
Det.h, CryIf_Cbk.h and the vendor's Crypto_GeneralTypes.h from
their BSW. The csm_smoke harness keeps a minimal fake_bsw/
directory for tool-free CI builds.
- One client-side translation lives in
Crypto_ProcessJob.c::isVerifyRejection — maps wolfCrypt-range
negative return codes from wh_Client_EccVerify (currently
surfaced when the signature is malformed-DER before math runs)
into SWS-correct E_OK + verifyPtr=NOT_OK. The wolfHSM team has
confirmed the underlying verify-handler contract is a real
fix-up candidate; the port stays correct either way. See
port/autosar/docs/client_workarounds.md.
- AUTOSAR "conformant" labelling is reserved to AUTOSAR Partners.
The port describes itself as "implements AUTOSAR R22-11
interfaces". Wording-only; no code impact.
Out of scope
- Reference CSM / CryIf inside the port (integrators use their
BSW's).
- AUTOSAR SHE wrapper (wolfhsm/wh_client_she.h already covers
SHE).
- PKCS#11 bridge.
- ISO 26262 / ASIL qualification artefacts.
- RSA-PSS / RSA-OAEP signature padding (separate follow-up).
- ML-DSA / X25519 signature / agreement in Adaptive (waiting on
keyId-shaped accessors).
GPLv3 across all new files, copyright wolfSSL Inc., consistent with
the rest of the repo. user_settings.h follows the existing
convention of header-less user-overridable config. clang-format-15
clean across the whole port/autosar/ tree.1 parent 7972967 commit f99e718
45 files changed
Lines changed: 9422 additions & 0 deletions
File tree
- .github/workflows
- port/autosar
- adaptive
- examples/ap_smoke
- include/wolfhsm/ara_crypto
- manifest
- src
- classic
- config
- examples/csm_smoke
- fake_bsw
- include
- src
- common
- config
- include
- src
- docs
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
0 commit comments