[zk-token-sdk] Refactor encryption error types (#31569)
* reorganize encryption error types * remove encryption errors module * cargo fmt
This commit is contained in:
parent
fb79e2bbb8
commit
39701fa560
|
@ -3,12 +3,12 @@
|
|||
//! This module is a simple wrapper of the `Aes128GcmSiv` implementation.
|
||||
#[cfg(not(target_os = "solana"))]
|
||||
use {
|
||||
crate::encryption::errors::AuthenticatedEncryptionError,
|
||||
aes_gcm_siv::{
|
||||
aead::{Aead, NewAead},
|
||||
Aes128GcmSiv,
|
||||
},
|
||||
rand::{rngs::OsRng, CryptoRng, Rng, RngCore},
|
||||
thiserror::Error,
|
||||
};
|
||||
use {
|
||||
arrayref::{array_ref, array_refs},
|
||||
|
@ -33,6 +33,15 @@ use {
|
|||
zeroize::Zeroize,
|
||||
};
|
||||
|
||||
#[derive(Error, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum AuthenticatedEncryptionError {
|
||||
#[error("key derivation method not supported")]
|
||||
DerivationMethodNotSupported,
|
||||
|
||||
#[error("pubkey does not exist")]
|
||||
PubkeyDoesNotExist,
|
||||
}
|
||||
|
||||
struct AuthenticatedEncryption;
|
||||
impl AuthenticatedEncryption {
|
||||
#[cfg(not(target_os = "solana"))]
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#![cfg(not(target_os = "solana"))]
|
||||
|
||||
use {
|
||||
crate::encryption::errors::DiscreteLogError,
|
||||
curve25519_dalek::{
|
||||
constants::RISTRETTO_BASEPOINT_POINT as G,
|
||||
ristretto::RistrettoPoint,
|
||||
|
@ -27,11 +26,20 @@ use {
|
|||
itertools::Itertools,
|
||||
serde::{Deserialize, Serialize},
|
||||
std::{collections::HashMap, thread},
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
const TWO16: u64 = 65536; // 2^16
|
||||
const TWO17: u64 = 131072; // 2^17
|
||||
|
||||
#[derive(Error, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum DiscreteLogError {
|
||||
#[error("discrete log number of threads not power-of-two")]
|
||||
DiscreteLogThreads,
|
||||
#[error("discrete log batch size too large")]
|
||||
DiscreteLogBatchSize,
|
||||
}
|
||||
|
||||
/// Type that captures a discrete log challenge.
|
||||
///
|
||||
/// The goal of discrete log is to find x such that x * generator = target.
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
use {
|
||||
crate::encryption::{
|
||||
discrete_log::DiscreteLog,
|
||||
errors::ElGamalError,
|
||||
pedersen::{Pedersen, PedersenCommitment, PedersenOpening, G, H},
|
||||
},
|
||||
core::ops::{Add, Mul, Sub},
|
||||
|
@ -39,6 +38,7 @@ use {
|
|||
},
|
||||
std::convert::TryInto,
|
||||
subtle::{Choice, ConstantTimeEq},
|
||||
thiserror::Error,
|
||||
zeroize::Zeroize,
|
||||
};
|
||||
#[cfg(not(target_os = "solana"))]
|
||||
|
@ -52,6 +52,12 @@ use {
|
|||
},
|
||||
};
|
||||
|
||||
#[derive(Error, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum ElGamalError {
|
||||
#[error("key derivation method not supported")]
|
||||
DerivationMethodNotSupported,
|
||||
}
|
||||
|
||||
/// Algorithm handle for the twisted ElGamal encryption scheme
|
||||
pub struct ElGamal;
|
||||
impl ElGamal {
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
//! Errors related to the twisted ElGamal encryption scheme.
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum DiscreteLogError {
|
||||
#[error("discrete log number of threads not power-of-two")]
|
||||
DiscreteLogThreads,
|
||||
#[error("discrete log batch size too large")]
|
||||
DiscreteLogBatchSize,
|
||||
}
|
||||
|
||||
#[derive(Error, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum ElGamalError {
|
||||
#[error("key derivation method not supported")]
|
||||
DerivationMethodNotSupported,
|
||||
}
|
||||
|
||||
#[derive(Error, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum AuthenticatedEncryptionError {
|
||||
#[error("key derivation method not supported")]
|
||||
DerivationMethodNotSupported,
|
||||
|
||||
#[error("pubkey does not exist")]
|
||||
PubkeyDoesNotExist,
|
||||
}
|
|
@ -13,5 +13,4 @@
|
|||
pub mod auth_encryption;
|
||||
pub mod discrete_log;
|
||||
pub mod elgamal;
|
||||
pub mod errors;
|
||||
pub mod pedersen;
|
||||
|
|
Loading…
Reference in New Issue