Tag

Struct Tag 

Source
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

Source

pub fn data(&self) -> &[u8]

Returns a slice to the bytes stored

Source

pub fn as_slice(&self) -> &[u8]

Returns a slice to the bytes stored (same a Self::data)

Source

pub fn as_mut_slice(&mut self) -> &mut [u8]

Returns a mutable slice to the bytes stored

Source

pub fn len(&self) -> usize

Returns the len, i.e. the number of bytes stored in the tag

Source

pub fn is_empty(&self) -> bool

Returns whether the tag is empty

Source

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
Source

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
Source

pub fn set_data(&mut self, data: &[u8])

Sets the data stored in the tag

This overwrites existing data stored

Source

pub fn set_u64(&mut self, value: u64)

Sets the tag with the given u64 value

  • Bytes are stored in little endian
  • This overwrites existing data stored
Source

pub fn set_u128(&mut self, value: u128)

Sets the tag with the given u128 value

  • Bytes are stored in little endian
  • This overwrites existing data stored

Trait Implementations§

Source§

impl Clone for Tag

Source§

fn clone(&self) -> Tag

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tag

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Tag

Source§

fn default() -> Tag

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Tag

Source§

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 From<&str> for Tag

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Tag

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Tag

Source§

fn eq(&self, other: &Tag) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Tag

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Unversionize for Tag

Source§

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 Tag

Source§

impl Version for Tag

Source§

type Ref<'vers> = TagVersion<'vers>

Source§

type Owned = TagVersionOwned

Source§

impl Versionize for Tag

Source§

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<'_>

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 Tag

Source§

type VersionedOwned = <TagVersions as VersionsDispatch<Tag>>::Owned

Source§

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 Tag

Source§

type VersionedSlice<'vers> = Vec<<Tag as Versionize>::Versioned<'vers>>

Source§

fn versionize_slice(slice: &[Self]) -> Self::VersionedSlice<'_>

Source§

impl VersionizeVec for Tag

Source§

impl VersionsDispatch<Tag> for TagVersions
where Tag: Version,

Source§

type Ref<'vers> = TagVersionsDispatch<'vers>

Source§

type Owned = TagVersionsDispatchOwned

Source§

impl Eq for Tag

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Input, Output> CastInto<Output> for Input
where Output: CastFrom<Input>,

Source§

fn cast_into(self) -> Output

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,