diff options
Diffstat (limited to 'openpgp/src/crypto/backend')
-rw-r--r-- | openpgp/src/crypto/backend/nettle.rs | 15 | ||||
-rw-r--r-- | openpgp/src/crypto/backend/nettle/aead.rs | 33 |
2 files changed, 46 insertions, 2 deletions
diff --git a/openpgp/src/crypto/backend/nettle.rs b/openpgp/src/crypto/backend/nettle.rs index d2d8750a..b449f8a1 100644 --- a/openpgp/src/crypto/backend/nettle.rs +++ b/openpgp/src/crypto/backend/nettle.rs @@ -65,7 +65,9 @@ impl AEADAlgorithm { match &self { EAX => true, - OCB | Private(_) | Unknown(_) + OCB + => nettle::aead::OCB_IS_SUPPORTED, + Private(_) | Unknown(_) => false, } } @@ -84,6 +86,17 @@ impl AEADAlgorithm { SymmetricAlgorithm::Camellia256 => true, _ => false, }, + AEADAlgorithm::OCB => + match algo { + SymmetricAlgorithm::AES128 | + SymmetricAlgorithm::AES192 | + SymmetricAlgorithm::AES256 | + SymmetricAlgorithm::Twofish | + SymmetricAlgorithm::Camellia128 | + SymmetricAlgorithm::Camellia192 | + SymmetricAlgorithm::Camellia256 => true, + _ => false, + }, _ => false } } diff --git a/openpgp/src/crypto/backend/nettle/aead.rs b/openpgp/src/crypto/backend/nettle/aead.rs index 486269b1..d2c492c3 100644 --- a/openpgp/src/crypto/backend/nettle/aead.rs +++ b/openpgp/src/crypto/backend/nettle/aead.rs @@ -1,7 +1,14 @@ //! Implementation of AEAD using Nettle cryptographic library. use std::cmp::Ordering; -use nettle::{aead::{self, Aead as _}, cipher}; +use nettle::{ + aead::{ + self, + Aead as _, + typenum::consts::U16, + }, + cipher, +}; use crate::{Error, Result}; @@ -110,6 +117,30 @@ impl AEADAlgorithm { }, _ => Err(Error::UnsupportedSymmetricAlgorithm(sym_algo).into()), }, + AEADAlgorithm::OCB => match sym_algo { + SymmetricAlgorithm::AES128 => Ok(Box::new( + aead::Ocb::<cipher::Aes128, U16>::with_key_and_nonce(key, nonce)?, + )), + SymmetricAlgorithm::AES192 => Ok(Box::new( + aead::Ocb::<cipher::Aes192, U16>::with_key_and_nonce(key, nonce)?, + )), + SymmetricAlgorithm::AES256 => Ok(Box::new( + aead::Ocb::<cipher::Aes256, U16>::with_key_and_nonce(key, nonce)?, + )), + SymmetricAlgorithm::Twofish => Ok(Box::new( + aead::Ocb::<cipher::Twofish, U16>::with_key_and_nonce(key, nonce)?, + )), + SymmetricAlgorithm::Camellia128 => Ok(Box::new( + aead::Ocb::<cipher::Camellia128, U16>::with_key_and_nonce(key, nonce)?, + )), + SymmetricAlgorithm::Camellia192 => Ok(Box::new( + aead::Ocb::<cipher::Camellia192, U16>::with_key_and_nonce(key, nonce)?, + )), + SymmetricAlgorithm::Camellia256 => Ok(Box::new( + aead::Ocb::<cipher::Camellia256, U16>::with_key_and_nonce(key, nonce)?, + )), + _ => Err(Error::UnsupportedSymmetricAlgorithm(sym_algo).into()), + }, _ => Err(Error::UnsupportedAEADAlgorithm(*self).into()), } } |