Skip to content

Commit

Permalink
openpgp: Update win-crypto-ng to 0.5
Browse files Browse the repository at this point in the history
  - Fixes #1014
  • Loading branch information
nwalfield committed May 3, 2023
1 parent ec4d690 commit 4980fd6
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
61 changes: 45 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions openpgp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ typenum = { version = "1.12.0", optional = true }
x25519-dalek = { version = "1.1.0", optional = true }

[target.'cfg(windows)'.dependencies]
win-crypto-ng = { version = "0.4", features = ["rand", "block-cipher"], optional = true }
win-crypto-ng = { version = ">=0.4, <0.6", features = ["rand", "block-cipher"], optional = true }
winapi = { version = "0.3.8", default-features = false, features = ["bcrypt"], optional = true }

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
Expand All @@ -112,7 +112,10 @@ crypto-rust = [
"ripemd160", "rsa", "sha-1", "sha2", "twofish", "typenum", "x25519-dalek", "p256",
"rand_core", "rand_core/getrandom", "ecdsa"
]
crypto-cng = ["eax", "winapi", "win-crypto-ng", "ed25519-dalek", "num-bigint-dig"]
crypto-cng = [
"cipher", "eax", "winapi", "win-crypto-ng", "ed25519-dalek",
"num-bigint-dig"
]
crypto-openssl = ["openssl", "openssl-sys", "foreign-types-shared"]
crypto-botan = ["botan"]
__implicit-crypto-backend-for-tests = []
Expand Down
2 changes: 2 additions & 0 deletions openpgp/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Changes in 1.15.0
** New functionality
- StandardPolicy::accept_hash_property
* Notable changes
- Updated the crypto-cng backend.
* Changes in 1.14.0
** New cryptographic backends
- We added a backend that uses Botan.
Expand Down
13 changes: 8 additions & 5 deletions openpgp/src/crypto/backend/cng/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use crate::crypto::mem::secure_cmp;
use crate::seal;
use crate::types::{AEADAlgorithm, SymmetricAlgorithm};

use cipher::generic_array::{GenericArray, ArrayLength};
use cipher::generic_array::typenum::{U16, U128, U192, U256};
use cipher::Unsigned;
use eax::online::{Eax, Encrypt, Decrypt};
use win_crypto_ng::symmetric::{BlockCipherKey, Aes};
use win_crypto_ng::symmetric::block_cipher::generic_array::{GenericArray, ArrayLength};
use win_crypto_ng::symmetric::block_cipher::generic_array::typenum::{U128, U192, U256};

/// Disables authentication checks.
///
Expand Down Expand Up @@ -110,12 +111,14 @@ impl AEADAlgorithm {
}
}

type EaxTagLen = U16;

macro_rules! impl_aead {
($($type: ty),*) => {
$(
impl Aead for Eax<$type, Encrypt> {
impl Aead for Eax<$type, Encrypt, EaxTagLen> {
fn digest_size(&self) -> usize {
<eax::Tag as GenericArrayExt<_, _>>::LEN
EaxTagLen::USIZE
}
fn encrypt_seal(&mut self, dst: &mut [u8], src: &[u8]) -> Result<()> {
debug_assert_eq!(dst.len(), src.len() + self.digest_size());
Expand All @@ -136,7 +139,7 @@ macro_rules! impl_aead {
$(
impl Aead for Eax<$type, Decrypt> {
fn digest_size(&self) -> usize {
<eax::Tag as GenericArrayExt<_, _>>::LEN
EaxTagLen::USIZE
}
fn encrypt_seal(&mut self, _dst: &mut [u8], _src: &[u8]) -> Result<()> {
panic!("AEAD encryption called in the decryption context")
Expand Down

0 comments on commit 4980fd6

Please sign in to comment.