-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: revise EdDSA mechanism to support optional params
This revises the `Mechanism::Eddsa` struct to receive a `EddsaParams` struct as an optional argument. Signed-off-by: Mete Can Eriş <[email protected]>
- Loading branch information
Showing
3 changed files
with
130 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//! EdDSA mechanism types | ||
use cryptoki_sys::*; | ||
use std::marker::PhantomData; | ||
|
||
/// EdDSA parameters. | ||
/// | ||
/// The EdDSA mechanism, denoted CKM_EDDSA, is a mechanism for | ||
/// single-part and multipart signatures and verification for | ||
/// EdDSA. This mechanism implements the five EdDSA signature | ||
/// schemes defined in RFC 8032 and RFC 8410. | ||
/// | ||
/// For curves according to RFC 8032, this mechanism has an | ||
/// optional parameter, a CK_EDDSA_PARAMS structure. | ||
/// | ||
/// The absence or presence of the parameter as well as its | ||
/// content is used to identify which signature scheme is to be | ||
/// used. | ||
/// | ||
/// | Signature Scheme | Mechanism Param | phFlag | Context Data | | ||
/// |------------------|-----------------|--------|--------------| | ||
/// | Ed25519 | Not Required | N/A | N/A | | ||
/// | Ed25519ctx | Required | False | Optional | | ||
/// | Ed25519ph | Required | True | Optional | | ||
/// | Ed448 | Required | False | Optional | | ||
/// | Ed448ph | Required | True | Optional | | ||
/// | ||
/// This structure wraps a `CK_EDDSA_PARAMS` structure. | ||
#[derive(Copy, Debug, Clone)] | ||
#[repr(transparent)] | ||
pub struct EddsaParams<'a> { | ||
inner: CK_EDDSA_PARAMS, | ||
_marker: PhantomData<&'a [u8]>, | ||
} | ||
|
||
impl EddsaParams<'_> { | ||
/// Construct EdDSA parameters. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `params` - The CK_EDDSA_PARAMS structure. | ||
pub fn new(params: CK_EDDSA_PARAMS) -> Self { | ||
Self { | ||
inner: params, | ||
_marker: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
impl Default for EddsaParams<'_> { | ||
/// Provide a default instance of `EddsaParams`. | ||
/// | ||
/// This initializes `EddsaParams` with the default value | ||
/// of the `CK_EDDSA_PARAMS` structure. | ||
fn default() -> Self { | ||
Self { | ||
inner: CK_EDDSA_PARAMS::default(), | ||
_marker: PhantomData, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters