Skip to main content

Rs256Verify

Struct Rs256Verify 

Source
pub struct Rs256Verify {
    pub message: ByteVec,
    pub signature: ByteVec,
    pub modulus: ByteVec,
    pub rsa_intermediates: RsaIntermediates,
}
Expand description

RS256 signature verification circuit (internal implementation)

This circuit verifies a signature for a given message according to the signature verification algorithm RSASSA-PKCS1-v1_5, using SHA-256 as a hash.

This signature verification algorithm is used in JWT signatures which have the “alg” header set to “RS256”. https://datatracker.ietf.org/doc/html/rfc7518#section-3.1

Fields§

§message: ByteVec

The message to verify (packed as 64-bit words, 8 bytes per wire)

§signature: ByteVec

The RSA signature as a FixedByteVec (the primary input interface)

§modulus: ByteVec

The RSA modulus as a FixedByteVec (the primary input interface)

§rsa_intermediates: RsaIntermediates

Wires associated with intermediate RSA computations

Implementations§

Source§

impl Rs256Verify

Source

pub fn new( builder: &mut CircuitBuilder, message: ByteVec, signature: ByteVec, modulus: ByteVec, ) -> Self

Create a new RS256 verification circuit

This constructor accepts inputs with little-endian wire packing, which is convenient when composing with other circuits (e.g base64, concat) which use the same wire packing.

RS256 uses the public exponent 2^16 + 1 (65537). The circuit verifies that the encoded message (EM) has the following properties:

  • signature < modulus
  • EM = signature^65537 mod modulus
  • EM has a valid PKCS#1 v1.5 prefix
  • The hash stored in EM is equal to the SHA-256 hash of the provided message.
§Arguments
  • builder - Circuit builder
  • message - A FixedByteVec containing the plaintext message
  • signature - The RSA signature with little-endian wire packing (256 bytes for 2048-bit RSA)
  • modulus - The RSA modulus with little-endian wire packing (256 bytes for 2048-bit RSA)
§Panics
  • If signature or modulus don’t have at least 256 bytes
Source

pub fn populate_len_bytes(&self, w: &mut WitnessFiller<'_>, len_bytes: usize)

Populate the message length

Source

pub fn populate_rsa( &self, w: &mut WitnessFiller<'_>, signature: &[u8], modulus: &[u8], )

Populate the RSA signature, modulus and intermediate computations

Source

pub fn populate_intermediates( &self, w: &mut WitnessFiller<'_>, signature: &[u8], modulus: &[u8], )

Source

pub fn populate_message(&self, w: &mut WitnessFiller<'_>, message: &[u8])

Populate the message

§Panics

Panics if message.len() > self.message.len() * 8

Source

pub fn populate_modulus(&self, w: &mut WitnessFiller<'_>, modulus_bytes: &[u8])

Populate the RSA modulus

§Panics

Panics if modulus_bytes.len() != 256

Source

pub fn populate_signature( &self, w: &mut WitnessFiller<'_>, signature_bytes: &[u8], )

Populate the RSA signature

§Arguments
  • w - Witness filler
  • signature_bytes - The bytes of an RSA signature
§Panics

Panics if signature_bytes.len() != 256

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more