summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/backend/fuzzing.rs
blob: e36ee34e3bc69a96300dd921a9a4563d3bba6d76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! Implementation of Sequoia crypto API using a fuzzing-friendly null
//! backend.

use crate::types::*;

#[allow(unused_variables)]
pub mod aead;
#[allow(unused_variables)]
pub mod asymmetric;
#[allow(unused_variables)]
pub mod ecdh;
#[allow(unused_variables)]
pub mod hash;
#[allow(unused_variables)]
pub mod symmetric;

pub struct Backend(());

impl super::interface::Backend for Backend {
    fn backend() -> String {
        "Fuzzing".to_string()
    }

    fn random(buf: &mut [u8]) -> crate::Result<()> {
        buf.iter_mut().for_each(|b| *b = 4);
        Ok(())
    }
}

impl AEADAlgorithm {
    /// Returns the best AEAD mode supported by the backend.
    ///
    /// This SHOULD return OCB, which is the mandatory-to-implement
    /// algorithm and the most performing one, but fall back to any
    /// supported algorithm.
    pub(crate) const fn const_default() -> AEADAlgorithm {
        AEADAlgorithm::OCB
    }

    pub(crate) fn is_supported_by_backend(&self) -> bool {
        true
    }

    #[cfg(test)]
    pub(crate) fn supports_symmetric_algo(&self, _: &SymmetricAlgorithm)
                                          -> bool {
        true
    }
}