Skip to main content

tss_esapi/structures/ecc/
parameter_details.rs

1// Copyright 2026 Contributors to the Parsec project.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::{
5    Error, Result,
6    interface_types::ecc::EccCurve,
7    structures::{EccParameter, EccScheme, KeyDerivationFunctionScheme},
8    tss2_esys::TPMS_ALGORITHM_DETAIL_ECC,
9};
10use std::convert::{TryFrom, TryInto};
11
12/// Detailed information about an ECC curve.
13///
14/// # Details
15/// This corresponds to `TPMS_ALGORITHM_DETAIL_ECC`.
16#[derive(Debug, Clone)]
17pub struct EccParameterDetails {
18    curve_id: EccCurve,
19    key_size: u16,
20    kdf: KeyDerivationFunctionScheme,
21    sign: EccScheme,
22    p: EccParameter,
23    a: EccParameter,
24    b: EccParameter,
25    g_x: EccParameter,
26    g_y: EccParameter,
27    n: EccParameter,
28    h: EccParameter,
29}
30
31impl EccParameterDetails {
32    /// Returns the curve ID.
33    pub const fn curve_id(&self) -> EccCurve {
34        self.curve_id
35    }
36
37    /// Returns the key size in bits.
38    pub const fn key_size(&self) -> u16 {
39        self.key_size
40    }
41
42    /// Returns the key derivation function scheme.
43    pub const fn kdf(&self) -> &KeyDerivationFunctionScheme {
44        &self.kdf
45    }
46
47    /// Returns the signing scheme.
48    pub const fn sign(&self) -> &EccScheme {
49        &self.sign
50    }
51
52    /// Returns the prime modulus p.
53    pub const fn p(&self) -> &EccParameter {
54        &self.p
55    }
56
57    /// Returns the curve coefficient a.
58    pub const fn a(&self) -> &EccParameter {
59        &self.a
60    }
61
62    /// Returns the curve coefficient b.
63    pub const fn b(&self) -> &EccParameter {
64        &self.b
65    }
66
67    /// Returns the x-coordinate of the base point G.
68    pub const fn g_x(&self) -> &EccParameter {
69        &self.g_x
70    }
71
72    /// Returns the y-coordinate of the base point G.
73    pub const fn g_y(&self) -> &EccParameter {
74        &self.g_y
75    }
76
77    /// Returns the order of the base point n.
78    pub const fn n(&self) -> &EccParameter {
79        &self.n
80    }
81
82    /// Returns the cofactor h.
83    pub const fn h(&self) -> &EccParameter {
84        &self.h
85    }
86}
87
88impl TryFrom<TPMS_ALGORITHM_DETAIL_ECC> for EccParameterDetails {
89    type Error = Error;
90
91    fn try_from(details: TPMS_ALGORITHM_DETAIL_ECC) -> Result<Self> {
92        Ok(EccParameterDetails {
93            curve_id: EccCurve::try_from(details.curveID)?,
94            key_size: details.keySize,
95            kdf: details.kdf.try_into()?,
96            sign: details.sign.try_into()?,
97            p: details.p.try_into()?,
98            a: details.a.try_into()?,
99            b: details.b.try_into()?,
100            g_x: details.gX.try_into()?,
101            g_y: details.gY.try_into()?,
102            n: details.n.try_into()?,
103            h: details.h.try_into()?,
104        })
105    }
106}