[zk-token-sdk] Refactor encryption error types (#31569)

* reorganize encryption error types

* remove encryption errors module

* cargo fmt
This commit is contained in:
samkim-crypto 2023-05-11 04:43:25 +09:00 committed by GitHub
parent fb79e2bbb8
commit 39701fa560
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 29 deletions

View File

@ -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"))]

View File

@ -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.

View File

@ -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 {

View File

@ -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,
}

View File

@ -13,5 +13,4 @@
pub mod auth_encryption;
pub mod discrete_log;
pub mod elgamal;
pub mod errors;
pub mod pedersen;