Added bytes_of to structs that can be created through the trait extension of Scratch

This commit is contained in:
Jean-Philippe Bossuat
2025-05-28 15:19:52 +02:00
parent 187756a495
commit f58d06ddf5
8 changed files with 41 additions and 0 deletions

View File

@@ -26,6 +26,10 @@ impl AutomorphismKey<Vec<u8>, FFT64> {
p: 0,
}
}
pub fn bytes_of(module: &Module<FFT64>, basek: usize, k: usize, rows: usize, rank: usize) -> usize {
GLWESwitchingKey::<Vec<u8>, FFT64>::bytes_of(module, basek, k, rows, rank, rank)
}
}
impl<T, B: Backend> Infos for AutomorphismKey<T, B> {

View File

@@ -27,6 +27,10 @@ impl<B: Backend> GGLWECiphertext<Vec<u8>, B> {
k,
}
}
pub fn bytes_of(module: &Module<FFT64>, basek: usize, k: usize, rows: usize, rank_in: usize, rank_out: usize) -> usize {
module.bytes_of_mat_znx_dft(rows, rank_in, rank_out + 1, derive_size(basek, k))
}
}
impl<T, B: Backend> Infos for GGLWECiphertext<T, B> {

View File

@@ -31,6 +31,10 @@ impl<B: Backend> GGSWCiphertext<Vec<u8>, B> {
k: k,
}
}
pub fn bytes_of(module: &Module<FFT64>, basek: usize, k: usize, rows: usize, rank: usize) -> usize {
module.bytes_of_mat_znx_dft(rows, rank + 1, rank + 1, derive_size(basek, k))
}
}
impl<T, B: Backend> Infos for GGSWCiphertext<T, B> {

View File

@@ -32,6 +32,10 @@ impl GLWECiphertext<Vec<u8>> {
k,
}
}
pub fn bytes_of(module: &Module<FFT64>, basek: usize, k: usize, rank: usize) -> usize {
module.bytes_of_vec_znx(rank + 1, derive_size(basek, k))
}
}
impl<T> Infos for GLWECiphertext<T> {

View File

@@ -23,6 +23,10 @@ impl<B: Backend> GLWECiphertextFourier<Vec<u8>, B> {
k: k,
}
}
pub fn bytes_of(module: &Module<B>, basek: usize, k: usize, rank: usize) -> usize {
module.bytes_of_vec_znx_dft(rank + 1, derive_size(basek, k))
}
}
impl<T, B: Backend> Infos for GLWECiphertextFourier<T, B> {

View File

@@ -26,6 +26,10 @@ impl SecretKey<Vec<u8>> {
dist: SecretDistribution::NONE,
}
}
pub fn bytes_of(module: &Module<FFT64>, rank: usize) -> usize {
module.bytes_of_scalar_znx(rank + 1)
}
}
impl<DataSelf> SecretKey<DataSelf> {
@@ -89,6 +93,10 @@ impl<B: Backend> SecretKeyFourier<Vec<u8>, B> {
dist: SecretDistribution::NONE,
}
}
pub fn bytes_of(module: &Module<B>, rank: usize) -> usize {
module.bytes_of_scalar_znx_dft(rank + 1)
}
}
impl<D: AsRef<[u8]> + AsMut<[u8]>> SecretKeyFourier<D, FFT64> {
@@ -124,6 +132,10 @@ impl<B: Backend> GLWEPublicKey<Vec<u8>, B> {
dist: SecretDistribution::NONE,
}
}
pub fn bytes_of(module: &Module<B>, basek: usize, k: usize, rank: usize) -> usize {
GLWECiphertextFourier::<Vec<u8>, B>::bytes_of(module, basek, k, rank)
}
}
impl<T, B: Backend> Infos for GLWEPublicKey<T, B> {

View File

@@ -17,6 +17,10 @@ impl GLWESwitchingKey<Vec<u8>, FFT64> {
module, basek, k, rows, rank_in, rank_out,
))
}
pub fn bytes_of(module: &Module<FFT64>, basek: usize, k: usize, rows: usize, rank_in: usize, rank_out: usize) -> usize {
GGLWECiphertext::<Vec<u8>, FFT64>::bytes_of(module, basek, k, rows, rank_in, rank_out)
}
}
impl<T, B: Backend> Infos for GLWESwitchingKey<T, B> {

View File

@@ -20,6 +20,11 @@ impl TensorKey<Vec<u8>, FFT64> {
});
Self { keys: keys }
}
pub fn bytes_of(module: &Module<FFT64>, basek: usize, k: usize, rows: usize, rank: usize) -> usize {
let pairs: usize = (((rank + 1) * rank) >> 1).max(1);
pairs * GLWESwitchingKey::<Vec<u8>, FFT64>::bytes_of(module, basek, k, rows, 1, rank)
}
}
impl<T, B: Backend> Infos for TensorKey<T, B> {