pub struct Tag { /* private fields */ }Expand description
Tag
The Tag allows to store bytes alongside entities (keys, and ciphertexts)
the main purpose of this system is to tag / identify ciphertext with their keys.
TFHE-rs generally does not interpret or check this data, it only stores it and passes it around.
The crate::upgrade::UpgradeKeyChain uses the tag to differentiate keys
The rules for how the Tag is passed around are:
- When encrypted, a ciphertext gets the tag of the key used to encrypt it.
- Ciphertexts resulting from operations (add, sub, etc.) get the tag from the ServerKey used
- PublicKey gets its tag from the ClientKey that was used to create it
- ServerKey gets its tag from the ClientKey that was used to create it
User can change the tag of any entities at any point.
§Example
use rand::random;
use tfhe::prelude::*;
use tfhe::{ClientKey, ConfigBuilder, FheUint32, ServerKey};
// Generate the client key then set its tag
let mut cks = ClientKey::generate(ConfigBuilder::default());
let tag_value = random();
cks.tag_mut().set_u64(tag_value);
assert_eq!(cks.tag().as_u64(), tag_value);
// The server key inherits the client key tag
let sks = ServerKey::new(&cks);
assert_eq!(sks.tag(), cks.tag());
// Encrypted data inherits the tag of the encryption key
let a = FheUint32::encrypt(32832u32, &cks);
assert_eq!(a.tag(), cks.tag());Implementations§
Source§impl Tag
impl Tag
Sourcepub fn as_slice(&self) -> &[u8] ⓘ
pub fn as_slice(&self) -> &[u8] ⓘ
Returns a slice to the bytes stored (same a Self::data)
Sourcepub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Returns a mutable slice to the bytes stored
Sourcepub fn as_u64(&self) -> u64
pub fn as_u64(&self) -> u64
Return the u64 value when interpreting the bytes as a u64
- Bytes are interpreted in little endian
- Bytes above the 8th are ignored
Sourcepub fn as_u128(&self) -> u128
pub fn as_u128(&self) -> u128
Return the u128 value when interpreting the bytes as a u128
- Bytes are interpreted in little endian
- Bytes above the 16th are ignored
Sourcepub fn set_data(&mut self, data: &[u8])
pub fn set_data(&mut self, data: &[u8])
Sets the data stored in the tag
This overwrites existing data stored
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Tag
impl<'de> Deserialize<'de> for Tag
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Unversionize for Tagwhere
TagVersions: VersionsDispatch<Self>,
impl Unversionize for Tagwhere
TagVersions: VersionsDispatch<Self>,
Source§fn unversionize(
versioned: Self::VersionedOwned,
) -> Result<Self, UnversionizeError>
fn unversionize( versioned: Self::VersionedOwned, ) -> Result<Self, UnversionizeError>
Creates an object from a versioned enum, and eventually upgrades from previous
variants.
Source§impl UnversionizeVec for Tagwhere
TagVersions: VersionsDispatch<Self>,
impl UnversionizeVec for Tagwhere
TagVersions: VersionsDispatch<Self>,
fn unversionize_vec( versioned: Self::VersionedVec, ) -> Result<Vec<Self>, UnversionizeError>
Source§impl Versionize for Tagwhere
TagVersions: VersionsDispatch<Self>,
impl Versionize for Tagwhere
TagVersions: VersionsDispatch<Self>,
Source§type Versioned<'vers> = <TagVersions as VersionsDispatch<Tag>>::Ref<'vers>
type Versioned<'vers> = <TagVersions as VersionsDispatch<Tag>>::Ref<'vers>
The equivalent versioned type. It should have a variant for each version.
It may own the underlying data or only hold a read-only reference to it.
Source§fn versionize(&self) -> Self::Versioned<'_>
fn versionize(&self) -> Self::Versioned<'_>
Wraps the object into a versioned enum with a variant for each version. This will
use references on the underlying types if possible.
Source§impl VersionizeOwned for Tagwhere
TagVersions: VersionsDispatch<Self>,
impl VersionizeOwned for Tagwhere
TagVersions: VersionsDispatch<Self>,
type VersionedOwned = <TagVersions as VersionsDispatch<Tag>>::Owned
Source§fn versionize_owned(self) -> Self::VersionedOwned
fn versionize_owned(self) -> Self::VersionedOwned
Wraps the object into a versioned enum with a variant for each version. This will
clone the underlying types.
Source§impl VersionizeSlice for Tagwhere
TagVersions: VersionsDispatch<Self>,
impl VersionizeSlice for Tagwhere
TagVersions: VersionsDispatch<Self>,
type VersionedSlice<'vers> = Vec<<Tag as Versionize>::Versioned<'vers>>
fn versionize_slice(slice: &[Self]) -> Self::VersionedSlice<'_>
Source§impl VersionizeVec for Tagwhere
TagVersions: VersionsDispatch<Self>,
impl VersionizeVec for Tagwhere
TagVersions: VersionsDispatch<Self>,
type VersionedVec = Vec<<Tag as VersionizeOwned>::VersionedOwned>
fn versionize_vec(vec: Vec<Self>) -> Self::VersionedVec
Source§impl VersionsDispatch<Tag> for TagVersions
impl VersionsDispatch<Tag> for TagVersions
impl Eq for Tag
impl StructuralPartialEq for Tag
Auto Trait Implementations§
impl Freeze for Tag
impl RefUnwindSafe for Tag
impl Send for Tag
impl Sync for Tag
impl Unpin for Tag
impl UnwindSafe for Tag
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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