aboutsummaryrefslogtreecommitdiff
path: root/guests/rsa/src/lib.rs
blob: b2067cf7f6def46ea481e20b7d664277aabb34ed (plain) (blame)
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
#![cfg_attr(feature = "no_std", no_std)]

#[cfg(feature = "no_std")]
extern crate alloc;
#[cfg(feature = "no_std")]
use alloc::vec::Vec;

use sha2::{Digest, Sha256};

#[cfg(feature = "sp1")]
use rsa_sp1::{pkcs8::DecodePublicKey, Pkcs1v15Sign, RsaPublicKey};

#[cfg(not(feature = "sp1"))]
use rsa::{pkcs8::DecodePublicKey, Pkcs1v15Sign, RsaPublicKey};

#[guests_macro::proving_entrypoint]
pub fn main(public_key: Vec<u8>, message: String, signature: Vec<u8>) -> bool {
    let public_key = RsaPublicKey::from_public_key_der(&public_key).unwrap();

    let mut hasher = Sha256::new();
    hasher.update(message);
    let hashed_msg = hasher.finalize();

    public_key
        .verify(Pkcs1v15Sign::new::<Sha256>(), &hashed_msg, &signature)
        .is_ok()
}