Skip to content

Commit

Permalink
Merge #191
Browse files Browse the repository at this point in the history
191: Add serde support for the ARIA cipher r=AdrianCX a=zugzwang

This PR adds serde support for the Aria cipher. This is needed to use the `update` API. This is a follow-up of #187.

Co-authored-by: Francisco Vial-Prado <[email protected]>
  • Loading branch information
bors[bot] and zugzwang authored Mar 7, 2022
2 parents bb89c2e + fe43d23 commit b99bd02
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mbedtls/src/cipher/raw/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct SavedRawCipher {
#[derive(Serialize, Deserialize)]
enum AlgorithmContext {
Aes(Bytes<aes_context>),
Aria(Bytes<aria_context>),
Des(Bytes<des_context>),
Des3(Bytes<des3_context>),
Gcm {
Expand Down Expand Up @@ -95,6 +96,12 @@ unsafe fn serialize_raw_cipher(mut cipher_context: cipher_context_t)
aes_context.rk = ::core::ptr::null_mut();
AlgorithmContext::Aes(Bytes(aes_context))
}
(CIPHER_ID_ARIA, MODE_CBC)
| (CIPHER_ID_ARIA, MODE_CTR)
| (CIPHER_ID_ARIA, MODE_CFB)
| (CIPHER_ID_ARIA, MODE_ECB) => {
AlgorithmContext::Aria(Bytes(*(cipher_context.cipher_ctx as *const aria_context)))
}
(CIPHER_ID_DES, MODE_CBC)
| (CIPHER_ID_DES, MODE_CTR)
| (CIPHER_ID_DES, MODE_OFB)
Expand Down Expand Up @@ -211,6 +218,9 @@ unsafe fn deserialize_raw_cipher(raw: SavedRawCipher, padding: raw::CipherPaddin
// mbedtls_aes_context in the mbedTLS source).
(*ret_aes_ctx).rk = &mut (*ret_aes_ctx).buf[0];
}
(CIPHER_ID_ARIA, AlgorithmContext::Aria(Bytes(aria_ctx))) => {
*(cipher_context.cipher_ctx as *mut aria_context) = aria_ctx
}
(CIPHER_ID_DES, AlgorithmContext::Des(Bytes(des_ctx))) => {
*(cipher_context.cipher_ctx as *mut des_context) = des_ctx
}
Expand Down Expand Up @@ -324,6 +334,7 @@ impl<'de, T: BytesSerde> Deserialize<'de> for Bytes<T> {

unsafe impl BytesSerde for cipher_context_t {}
unsafe impl BytesSerde for aes_context {}
unsafe impl BytesSerde for aria_context {}
unsafe impl BytesSerde for des_context {}
unsafe impl BytesSerde for des3_context {}
unsafe impl BytesSerde for gcm_context {}
Expand Down

0 comments on commit b99bd02

Please sign in to comment.