-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for ChaCha20/Poly1305 to COSE module
- Loading branch information
1 parent
66acdf6
commit 91d0419
Showing
16 changed files
with
418 additions
and
72 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
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
27 changes: 27 additions & 0 deletions
27
src/token/cose/crypto_impl/rustcrypto/encrypt/chacha_poly.rs
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,27 @@ | ||
use crate::error::CoseCipherError; | ||
use crate::token::cose::crypto_impl::rustcrypto::RustCryptoContext; | ||
use crate::token::cose::{CoseSymmetricKey, CryptoBackend}; | ||
use alloc::vec::Vec; | ||
use chacha20poly1305::ChaCha20Poly1305; | ||
use rand::CryptoRng; | ||
use rand::RngCore; | ||
|
||
impl<RNG: RngCore + CryptoRng> RustCryptoContext<RNG> { | ||
pub(super) fn encrypt_chacha20_poly1305( | ||
key: &CoseSymmetricKey<'_, <Self as CryptoBackend>::Error>, | ||
plaintext: &[u8], | ||
aad: &[u8], | ||
iv: &[u8], | ||
) -> Result<Vec<u8>, CoseCipherError<<Self as CryptoBackend>::Error>> { | ||
Self::encrypt_aead::<ChaCha20Poly1305>(key, plaintext, aad, iv) | ||
} | ||
|
||
pub(super) fn decrypt_chacha20_poly1305( | ||
key: &CoseSymmetricKey<'_, <Self as CryptoBackend>::Error>, | ||
ciphertext_with_tag: &[u8], | ||
aad: &[u8], | ||
iv: &[u8], | ||
) -> Result<Vec<u8>, CoseCipherError<<Self as CryptoBackend>::Error>> { | ||
Self::decrypt_aead::<ChaCha20Poly1305>(key, ciphertext_with_tag, aad, iv) | ||
} | ||
} |
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
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
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
Oops, something went wrong.