pub fn create_api_childkey(self, curve: Curve) -> Result<APIchildkey, ()> {
        match self.paillier_pk.clone() {
            Some(val) => val,
            None => return Err(()),
        };
        if curve == Curve::Secp256k1 {
            let random = match Secp256k1Scalar::new_random() {
                Ok(v) => Zeroizing::<Secp256k1Scalar>::new(v),
                Err(_) => return Err(()),
            };
            // client's secret share is set to the full secret key
            let secret_key = match ECScalar::from(&self.secret_key) {
                Ok(v) => Zeroizing::<Secp256k1Scalar>::new(v),
                Err(_) => return Err(()),
            };
            let rand_inv = match random.invert() {
                Ok(v) => v,
                Err(_) => return Err(()),
            };
            let client_secret_share = match rand_inv * secret_key.deref() {
                Ok(v) => Zeroizing::<Secp256k1Scalar>::new(v),
                Err(_) => return Err(()),
            };
            // server's secret share is set to random * 1
            let mut server_secret_share = random.to_bigint();
            let public_key =
                publickey_from_secretkey(&self.secret_key, curve).expect("Invalid curve");
            let server_secret_share_encrypted =
                encrypt_secret_share(&self.paillier_pk.clone().unwrap(), &server_secret_share);
            server_secret_share.zeroize_bn();
            Ok(APIchildkey {
                paillier_pk: self.paillier_pk.unwrap(),
                public_key,
                client_secret_share: client_secret_share.to_bigint(),
                server_secret_share_encrypted,
            })
        } else if curve == Curve::Secp256r1 {
            let random = match Secp256r1Scalar::new_random() {
                Ok(v) => Zeroizing::<Secp256r1Scalar>::new(v),
                Err(_) => return Err(()),
            };
            // client's secret share is set to the full secret key
            let secret_key = match ECScalar::from(&self.secret_key) {
                Ok(v) => Zeroizing::<Secp256r1Scalar>::new(v),
                Err(_) => return Err(()),
            };
            let rand_inv = match random.invert() {
                Ok(v) => v,
                Err(_) => return Err(()),
            };
            let client_secret_share = match rand_inv * secret_key.deref() {
                Ok(v) => Zeroizing::<Secp256r1Scalar>::new(v),
                Err(_) => return Err(()),
            };
            // server's secret share is set to random * 1
            let mut server_secret_share = random.to_bigint();
            let public_key =
                publickey_from_secretkey(&self.secret_key, curve).expect("Invalid curve");
            let server_secret_share_encrypted =
                encrypt_secret_share(&self.paillier_pk.clone().unwrap(), &server_secret_share);
            server_secret_share.zeroize_bn();
            Ok(APIchildkey {
                paillier_pk: self.paillier_pk.unwrap(),
                public_key,
                client_secret_share: client_secret_share.to_bigint(),
                server_secret_share_encrypted,
            })
        } else {
            Err(())
        }
    }
/// create api childkey, i.e., both secret shares, paillier pk, and public key
/// client can do this iff:
///        - the client knows the full secret key, and
///        - the client is trusted, and
///        - we don't allow rekeying.
/// we do this to facilitate fast api childkey creation (as we can skip the range proof entirely).
create api childkey, i.e., both secret shares, paillier pk, and public key
client can do this iff:
the client knows the full secret key, and
the client is trusted, and
we don't allow rekeying.
we do this to facilitate fast api childkey creation (as we can skip the range proof entirely).
create api childkey i . e . both secret shares paillier pk and public key client can do this iff : the client knows the full secret key and the client is trusted and we don ' t allow rekeying . we do this to facilitate fast api childkey creation ( as we can skip the range proof entirely ) .
pub fn create_api_childkey(self, curve: Curve) -> Result<APIchildkey, ()> {
        match self.paillier_pk.clone() {
            Some(val) => val,
            None => return Err(()),
        };
        if curve == Curve::Secp256k1 {
            let random = match Secp256k1Scalar::new_random() {
                Ok(v) => Zeroizing::<Secp256k1Scalar>::new(v),
                Err(_) => return Err(()),
            };
            // client's secret share is set to the full secret key
            let secret_key = match ECScalar::from(&self.secret_key) {
                Ok(v) => Zeroizing::<Secp256k1Scalar>::new(v),
                Err(_) => return Err(()),
            };
            let rand_inv = match random.invert() {
                Ok(v) => v,
                Err(_) => return Err(()),
            };
            let client_secret_share = match rand_inv * secret_key.deref() {
                Ok(v) => Zeroizing::<Secp256k1Scalar>::new(v),
                Err(_) => return Err(()),
            };
            // server's secret share is set to random * 1
            let mut server_secret_share = random.to_bigint();
            let public_key =
                publickey_from_secretkey(&self.secret_key, curve).expect("Invalid curve");
            let server_secret_share_encrypted =
                encrypt_secret_share(&self.paillier_pk.clone().unwrap(), &server_secret_share);
            server_secret_share.zeroize_bn();
            Ok(APIchildkey {
                paillier_pk: self.paillier_pk.unwrap(),
                public_key,
                client_secret_share: client_secret_share.to_bigint(),
                server_secret_share_encrypted,
            })
        } else if curve == Curve::Secp256r1 {
            let random = match Secp256r1Scalar::new_random() {
                Ok(v) => Zeroizing::<Secp256r1Scalar>::new(v),
                Err(_) => return Err(()),
            };
            // client's secret share is set to the full secret key
            let secret_key = match ECScalar::from(&self.secret_key) {
                Ok(v) => Zeroizing::<Secp256r1Scalar>::new(v),
                Err(_) => return Err(()),
            };
            let rand_inv = match random.invert() {
                Ok(v) => v,
                Err(_) => return Err(()),
            };
            let client_secret_share = match rand_inv * secret_key.deref() {
                Ok(v) => Zeroizing::<Secp256r1Scalar>::new(v),
                Err(_) => return Err(()),
            };
            // server's secret share is set to random * 1
            let mut server_secret_share = random.to_bigint();
            let public_key =
                publickey_from_secretkey(&self.secret_key, curve).expect("Invalid curve");
            let server_secret_share_encrypted =
                encrypt_secret_share(&self.paillier_pk.clone().unwrap(), &server_secret_share);
            server_secret_share.zeroize_bn();
            Ok(APIchildkey {
                paillier_pk: self.paillier_pk.unwrap(),
                public_key,
                client_secret_share: client_secret_share.to_bigint(),
                server_secret_share_encrypted,
            })
        } else {
            Err(())
        }
    }
pub fn create_api_childkey ( self , curve : Curve ) -> Result < APIchildkey , ( ) > { match self . paillier_pk . clone ( ) { Some ( val ) => val , None => return Err ( ( ) ) , } ; if curve == Curve :: Secp256k1 { let random = match Secp256k1Scalar :: new_random ( ) { Ok ( v ) => Zeroizing :: < Secp256k1Scalar > :: new ( v ) , Err ( _ ) => return Err ( ( ) ) , } ; // client's secret share is set to the full secret key let secret_key = match ECScalar :: from ( & self . secret_key ) { Ok ( v ) => Zeroizing :: < Secp256k1Scalar > :: new ( v ) , Err ( _ ) => return Err ( ( ) ) , } ; let rand_inv = match random . invert ( ) { Ok ( v ) => v , Err ( _ ) => return Err ( ( ) ) , } ; let client_secret_share = match rand_inv * secret_key . deref ( ) { Ok ( v ) => Zeroizing :: < Secp256k1Scalar > :: new ( v ) , Err ( _ ) => return Err ( ( ) ) , } ; // server's secret share is set to random * 1 let mut server_secret_share = random . to_bigint ( ) ; let public_key = publickey_from_secretkey ( & self . secret_key , curve ) . expect ( " " ) ; let server_secret_share_encrypted = encrypt_secret_share ( & self . paillier_pk . clone ( ) . unwrap ( ) , & server_secret_share ) ; server_secret_share . zeroize_bn ( ) ; Ok ( APIchildkey { paillier_pk : self . paillier_pk . unwrap ( ) , public_key , client_secret_share : client_secret_share . to_bigint ( ) , server_secret_share_encrypted , } ) } else if curve == Curve :: Secp256r1 { let random = match Secp256r1Scalar :: new_random ( ) { Ok ( v ) => Zeroizing :: < Secp256r1Scalar > :: new ( v ) , Err ( _ ) => return Err ( ( ) ) , } ; // client's secret share is set to the full secret key let secret_key = match ECScalar :: from ( & self . secret_key ) { Ok ( v ) => Zeroizing :: < Secp256r1Scalar > :: new ( v ) , Err ( _ ) => return Err ( ( ) ) , } ; let rand_inv = match random . invert ( ) { Ok ( v ) => v , Err ( _ ) => return Err ( ( ) ) , } ; let client_secret_share = match rand_inv * secret_key . deref ( ) { Ok ( v ) => Zeroizing :: < Secp256r1Scalar > :: new ( v ) , Err ( _ ) => return Err ( ( ) ) , } ; // server's secret share is set to random * 1 let mut server_secret_share = random . to_bigint ( ) ; let public_key = publickey_from_secretkey ( & self . secret_key , curve ) . expect ( " " ) ; let server_secret_share_encrypted = encrypt_secret_share ( & self . paillier_pk . clone ( ) . unwrap ( ) , & server_secret_share ) ; server_secret_share . zeroize_bn ( ) ; Ok ( APIchildkey { paillier_pk : self . paillier_pk . unwrap ( ) , public_key , client_secret_share : client_secret_share . to_bigint ( ) , server_secret_share_encrypted , } ) } else { Err ( ( ) ) } }
create api childkey, i.e., both secret shares, paillier pk, and public key
client can do this iff:
 the client knows the full secret key, and
 the client is trusted, and
 we don't allow rekeying.
create api childkey i . e . both secret shares paillier pk and public key client can do this iff : the client knows the full secret key and the client is trusted and we don ' t allow rekeying .
self
curve
Curve