{"record":{"id":"288041ebf288dadb","repo":"embassy-rs/embassy","slug":"pka-error","errorCode":null,"errorMessage":"PKA error: {:?}","messagePattern":"PKA error: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"embassy-stm32/src/pka/driver.rs","lineNumber":108,"sourceCode":"\nimpl<const N: usize> Aff<N> {\n    fn from_ecc_point(p: &EccPoint) -> Self {\n        Self {\n            x: p.x[..N].try_into().unwrap(),\n            y: p.y[..N].try_into().unwrap(),\n        }\n    }\n}\n\n/// The arithmetic driver's point: affine coordinates, or `None` for the point at infinity.\ntype Pt<const N: usize> = Option<Aff<N>>;\n\n/// Every value crossing the arithmetic driver boundary is valid, so the engine can only fail\n/// on a hardware fault, which there is no way to report through the driver traits.\nfn expect<T>(r: Result<T, Error>) -> T {\n    match r {\n        Ok(v) => v,\n        Err(e) => panic!(\"PKA error: {:?}\", e),\n    }\n}\n\nfn is_zero(v: &[u8]) -> bool {\n    v.iter().all(|&b| b == 0)\n}\n\n/// Returns whether `v < limit`, both big-endian and of the same length.\nfn less_than(v: &[u8], limit: &[u8]) -> bool {\n    for (a, b) in v.iter().zip(limit) {\n        if a != b {\n            return a < b;\n        }\n    }\n    false\n}\n\n/// Returns whether `v` is zero, in constant time.","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/pka/driver.rs#L90-L126","documentation":"The PKA arithmetic driver validates every value crossing its boundary, so the underlying engine can only return Err on a hardware fault that cannot be expressed through the elliptic-curve driver traits. expect() converts that result into a panic with the debug-formatted PKA error. This is an internal invariant, not something the caller can cause with bad input.","triggerScenarios":"Calling is_on_curve(), mul(), or add() on a Pka-based elliptic-curve implementation while the PKA engine reports an Error (hardware fault, RAM corruption, or unexpected IP behavior).","commonSituations":"Silicon errata / PKA IP misbehavior on a given chip revision; memory corruption of PKA RAM; running the PKA without the clock/enable the HAL assumed it had set up.","solutions":["Inspect the Debug-formatted error to identify which PKA operation failed and check the chip errata sheet for that PKA error code.","Reset and reinitialize the PKA peripheral, then retry the operation.","Report the case to embassy-stm32 as a driver/hardware-fault issue; there is no user-side configuration fix."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Hardware fault surfaced as panic; no caller-side catch. Handle at fault level:\n// log the Debug error payload, reset the PKA peripheral, retry once.\nmatch std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| curve.mul(p, k))) {\n    Ok(r) => r,\n    Err(_) => { /* reset PKA, retry or abort */ unreachable_in_prod() }\n} // only if unwinding is enabled; on embedded defaults, treat as fatal","preventionTips":["Check the chip errata sheet for PKA issues on your silicon revision.","Ensure the PKA clock/enable setup matches the HAL's expectations.","Keep buffers backing PKA RAM stable and initialized; report unexpected faults upstream."],"tags":["rust","embedded","stm32","pka","crypto","hardware-fault"],"backgroundTag":"internal-invariant-violation","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}