Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions openssl-sys/src/evp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ pub const EVP_PKEY_CTRL_HKDF_INFO: c_int = EVP_PKEY_ALG_CTRL + 6;
#[cfg(any(ossl111, libressl360))]
pub const EVP_PKEY_CTRL_HKDF_MODE: c_int = EVP_PKEY_ALG_CTRL + 7;

#[cfg(all(ossl111, not(ossl300)))]
pub const EVP_PKEY_CTRL_SET1_ID: c_int = EVP_PKEY_ALG_CTRL + 11;

#[cfg(ossl300)]
pub const EVP_PKEY_CTRL_SET1_ID: c_int = 15;

#[cfg(any(all(ossl111, not(ossl300)), libressl360))]
pub unsafe fn EVP_PKEY_CTX_set_hkdf_mode(ctx: *mut EVP_PKEY_CTX, mode: c_int) -> c_int {
EVP_PKEY_CTX_ctrl(
Expand Down Expand Up @@ -323,6 +329,18 @@ pub unsafe fn EVP_PKEY_CTX_add1_hkdf_info(
)
}

#[cfg(all(ossl111, not(ossl300)))]
pub unsafe fn EVP_PKEY_CTX_set1_id(ctx: *mut EVP_PKEY_CTX, id: *const c_void, len: c_int) -> c_int {
EVP_PKEY_CTX_ctrl(
ctx,
-1,
-1,
EVP_PKEY_CTRL_SET1_ID,
len,
id as *mut c_void,
)
}

#[cfg(not(any(ossl300, boringssl, awslc)))]
pub unsafe fn EVP_PKEY_CTX_set_signature_md(cxt: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int {
EVP_PKEY_CTX_ctrl(
Expand Down
3 changes: 3 additions & 0 deletions openssl-sys/src/handwritten/evp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ extern "C" {
#[cfg(ossl300)]
pub fn EVP_PKEY_CTX_set_signature_md(ctx: *mut EVP_PKEY_CTX, md: *const EVP_MD) -> c_int;

#[cfg(ossl300)]
pub fn EVP_PKEY_CTX_set1_id(ctx: *mut EVP_PKEY_CTX, id: *const c_void, len: c_int) -> c_int;

#[cfg(ossl300)]
pub fn EVP_PKEY_CTX_set_params(ctx: *mut EVP_PKEY_CTX, params: *const OSSL_PARAM) -> c_int;

Expand Down
30 changes: 30 additions & 0 deletions openssl/src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,21 @@ impl Signer<'_> {
}
}

/// Sets the SM2 ID.
///
/// This is only useful for SM2 keys.
#[corresponds(EVP_PKEY_CTX_set1_id)]
pub fn set1_id(&mut self, id :&[u8]) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::EVP_PKEY_CTX_set1_id(
self.pctx,
id.as_ptr() as *const _,
id.len() as c_int,
))
.map(|_| ())
}
}

/// Feeds more data into the `Signer`.
///
/// Please note that PureEdDSA (Ed25519 and Ed448 keys) do not support streaming.
Expand Down Expand Up @@ -509,6 +524,21 @@ impl<'a> Verifier<'a> {
}
}

/// Sets the SM2 ID.
///
/// This is only useful for SM2 keys.
#[corresponds(EVP_PKEY_CTX_set1_id)]
pub fn set1_id(&mut self, id :&[u8]) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::EVP_PKEY_CTX_set1_id(
self.pctx,
id.as_ptr() as *const _,
id.len() as c_int,
))
.map(|_| ())
}
}

/// Feeds more data into the `Verifier`.
///
/// Please note that PureEdDSA (Ed25519 and Ed448 keys) do not support streaming.
Expand Down
Loading