Skip to content

Commit 161eb60

Browse files
bors[bot]zugzwang
andcommitted
Merge #191
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]>
1 parent 4774b09 commit 161eb60

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

mbedtls/src/cipher/raw/serde.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub struct SavedRawCipher {
4444
#[derive(Serialize, Deserialize)]
4545
enum AlgorithmContext {
4646
Aes(Bytes<aes_context>),
47+
Aria(Bytes<aria_context>),
4748
Des(Bytes<des_context>),
4849
Des3(Bytes<des3_context>),
4950
Gcm {
@@ -94,6 +95,12 @@ unsafe fn serialize_raw_cipher(mut cipher_context: cipher_context_t)
9495
aes_context.rk = ::core::ptr::null_mut();
9596
AlgorithmContext::Aes(Bytes(aes_context))
9697
}
98+
(CIPHER_ID_ARIA, MODE_CBC)
99+
| (CIPHER_ID_ARIA, MODE_CTR)
100+
| (CIPHER_ID_ARIA, MODE_CFB)
101+
| (CIPHER_ID_ARIA, MODE_ECB) => {
102+
AlgorithmContext::Aria(Bytes(*(cipher_context.cipher_ctx as *const aria_context)))
103+
}
97104
(CIPHER_ID_DES, MODE_CBC)
98105
| (CIPHER_ID_DES, MODE_CTR)
99106
| (CIPHER_ID_DES, MODE_CFB) => {
@@ -208,6 +215,9 @@ unsafe fn deserialize_raw_cipher(raw: SavedRawCipher, padding: raw::CipherPaddin
208215
// mbedtls_aes_context in the mbedTLS source).
209216
(*ret_aes_ctx).rk = &mut (*ret_aes_ctx).buf[0];
210217
}
218+
(CIPHER_ID_ARIA, AlgorithmContext::Aria(Bytes(aria_ctx))) => {
219+
*(cipher_context.cipher_ctx as *mut aria_context) = aria_ctx
220+
}
211221
(CIPHER_ID_DES, AlgorithmContext::Des(Bytes(des_ctx))) => {
212222
*(cipher_context.cipher_ctx as *mut des_context) = des_ctx
213223
}
@@ -321,6 +331,7 @@ impl<'de, T: BytesSerde> Deserialize<'de> for Bytes<T> {
321331

322332
unsafe impl BytesSerde for cipher_context_t {}
323333
unsafe impl BytesSerde for aes_context {}
334+
unsafe impl BytesSerde for aria_context {}
324335
unsafe impl BytesSerde for des_context {}
325336
unsafe impl BytesSerde for des3_context {}
326337
unsafe impl BytesSerde for gcm_context {}

0 commit comments

Comments
 (0)