summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/backend/fuzzing/ecdh.rs
blob: a01eccbbe31501923b288bea548bed852e413aa3 (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
//! Elliptic Curve Diffie-Hellman.

use crate::{Error, Result};
use crate::crypto::SessionKey;
use crate::crypto::mpi::{MPI, Ciphertext, SecretKeyMaterial};
use crate::packet::{key, Key};

/// Wraps a session key using Elliptic Curve Diffie-Hellman.
#[allow(dead_code)]
pub fn encrypt<R>(recipient: &Key<key::PublicParts, R>,
                  session_key: &SessionKey)
    -> Result<Ciphertext>
    where R: key::KeyRole
{
    Ok(Ciphertext::ECDH {
        e: MPI::new(&session_key),
        key: Vec::from(&session_key[..]).into_boxed_slice(),
    })
}

/// Unwraps a session key using Elliptic Curve Diffie-Hellman.
#[allow(dead_code)]
pub fn decrypt<R>(recipient: &Key<key::PublicParts, R>,
                  recipient_sec: &SecretKeyMaterial,
                  ciphertext: &Ciphertext)
    -> Result<SessionKey>
    where R: key::KeyRole
{
    match ciphertext {
        Ciphertext::ECDH { key, .. } => Ok(Vec::from(&key[..]).into()),
        _ => Err(Error::InvalidArgument("not a ecdh ciphertext".into()).into()),
    }
}