shared2p.sc

shared2p.sc

Module with shared2p protection domain functions.

Functions:

abs

all

any

max

min

sum

abs

Function for finding absolute values.

Detailed Description

D - shared2p protection domain

Supported types - int8 / int16 / int32 / int

Parameters

x

- an array of any dimension

returns an array of equal shape, size and dimension, where all values are the absolute values of the input array at that position

Function Overloads

D uint8 abs(D int8[[N]] x)

D uint16 abs(D int16[[N]] x)

D uint32 abs(D int32[[N]] x)

D uint abs(D int[[N]] x)

all

Function for checking if all values of the input vector are true.

Detailed Description

D - shared2p protection domain

Supported types - bool

true if all of the input bits are set

false if any input bit is not set

performs one vectorized cast, and one comparison against length of the vector

Function Overloads

D bool all(D bool b)

Parameters

b

- scalar boolean

D bool all(D bool[[1]] arr)

Parameters

arr

- boolean 1-dimensional vector

D bool all(D bool[[1]] vec, uint k)

Parameters

vec

- boolean 1-dimensional vector

k

- an uint type value that shows in how many subarrays must all be found

D bool all(D bool[[N]] arr)

Parameters

arr

- boolean any dimension vector

any

Function for checking if any value of the input vector is true.

Detailed Description

D - shared2p protection domain

Supported types - bool

true if any of the input bits is set

false if all input bits are not set

performs one vectorized cast, and one comparison against zero

Function Overloads

D bool any(D bool b)

Parameters

b

- scalar boolean

D bool any(D bool[[1]] vec)

Parameters

vec

- boolean 1-dimensional vector

D bool any(D bool[[1]] vec, uint k)

Parameters

vec

- boolean 1-dimensional vector

k

- an uint type value that shows in how many subarrays must any be found

D bool any(D bool[[N]] arr)

Parameters

arr

- boolean any dimension vector

argument

Function for accessing the named program arguments of shared2p types.

Detailed Description

T - any data type

Parameters

name

The name of the argument.

returns the value associated with the argument specified by parameter name.

Function Overloads

D T argument(string name)

An argument of scalar type.

An argument of 1-dimensional array type.

bit extraction

Function for converting xor_uint(X) type value to the bit representation.

Detailed Description

D - shared2p protection domain

Supported types - xor_uint8 / xor_uint16 / xor_uint32 / xor_uint64

The input is arbitrary dimensional array, output is flattened to one boolean vector. Reshape the result to get appropriate dimensionality.

Parameters

input

- the input value to convert

returns filattened vector of extracted bits

Function Overloads

D bool bit_extract(D xor_uint8[[N]] input)

D bool bit_extract(D xor_uint16[[N]] input)

D bool bit_extract(D xor_uint32[[N]] input)

D bool bit_extract(D xor_uint64[[N]] input)

choose

Function for obliviously choosing pointwise from the inputs.

Detailed Description

D - shared2p protection domain

Supported types - xor_uint8 / xor_uint16 / xor_uint32 / xor_uint64

Parameters

cond

- a boolean vector

first

- values for true case

second

- values for false case

pointwise check if cond at a certain position is true or false. if true the element of first at that position is returned else the element of second at that position is returned

Function Overloads

D xor_uint8 choose(D bool[[N]] cond, D xor_uint8[[N]] first, D xor_uint8[[N]] second)

D xor_uint16 choose(D bool[[N]] cond, D xor_uint16[[N]] first, D xor_uint16[[N]] second)

D xor_uint32 choose(D bool[[N]] cond, D xor_uint32[[N]] first, D xor_uint32[[N]] second)

D xor_uint64 choose(D bool[[N]] cond, D xor_uint64[[N]] first, D xor_uint64[[N]] second)

publish

Function for publishing the named values of shared2p types.

Detailed Description

N - any array size of any dimension

T - any data type

Parameters

name

The name of the argument.

val

the value to publish under the given name. Accepts scalars as well as arrays.

Function Overloads

void publish(string name, D T[[N]] val)

reshare

Function for converting uint(X) type values to xor_uint(X) and the other way around.

Detailed Description

D - shared2p protection domain

Supported types - xor_uint8 / xor_uint16 / xor_uint32 / xor_uint64

Parameters

input

- the input value to convert

returns a converted value from uint(X) → xor_uint(X) or xor_uint(X) → uint(X)

Function Overloads

D xor_uint8 reshare(D uint8 input)

D uint8 reshare(D xor_uint8 input)

D xor_uint8 reshare(D uint8[[1]] input)

D uint8 reshare(D xor_uint8[[1]] input)

D xor_uint8 reshare(D uint8[[2]] input)

D uint8 reshare(D xor_uint8[[2]] input)

D xor_uint16 reshare(D uint16 input)

D uint16 reshare(D xor_uint16 input)

D xor_uint16 reshare(D uint16[[1]] input)

D uint16 reshare(D xor_uint16[[1]] input)

D xor_uint16 reshare(D uint16[[2]] input)

D uint16 reshare(D xor_uint16[[2]] input)

D xor_uint32 reshare(D uint32 input)

D uint32 reshare(D xor_uint32 input)

D xor_uint32 reshare(D uint32[[1]] input)

D uint32 reshare(D xor_uint32[[1]] input)

D xor_uint32 reshare(D uint32[[2]] input)

D uint32 reshare(D xor_uint32[[2]] input)

D xor_uint64 reshare(D uint64 input)

D uint64 reshare(D xor_uint64 input)

D xor_uint64 reshare(D uint64[[1]] input)

D uint64 reshare(D xor_uint64[[1]] input)

D xor_uint64 reshare(D uint64[[2]] input)

D uint64 reshare(D xor_uint64[[2]] input)

sign

Function for determining the sign of values.

Detailed Description

D - shared2p protection domain

Supported types - int8 / int16 / int32 / int

Parameters

x

- an array of any dimension

returns an array of equal shape, size and dimension, where -1 signifies that, in the input array at that position was a negative number and 1 that it was a positive number

Function Overloads

D int8 sign(D int8[[N]] x)

D int16 sign(D int16[[N]] x)

D int32 sign(D int32[[N]] x)

D int sign(D int[[N]] x)

truePrefixLength

Function for finding how many elements from the start of a vector are true.

Detailed Description

D - shared2p protection domain

Supported types - bool

the number of set bits in the longest constant true prefix of the input

this function performs log n multiplications on vectors of at most size n this is more efficient than performing n multiplications on scalars

Function Overloads

D uint truePrefixLength(D bool[[1]] arr)

Parameters

arr

- boolean 1-dimensional vector

max

Functions for finding the maximum value.

Functions:

max

D - shared2p protection domain

Supported types - uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / xor_uint8 / xor_uint16 / xor_uint32 / xor_uint64

max

Function for finding the maximum element of the input vector.

Detailed Description

D - shared2p protection domain

Supported types - uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / xor_uint8 / xor_uint16 / xor_uint32 / xor_uint64

Parameters

x

- input

maximum element of the input vector.

input vector is not empty

Function Overloads

D T max(D T x)

D uint8 max(D uint8[[1]] x)

D uint16 max(D uint16[[1]] x)

D uint32 max(D uint32[[1]] x)

D uint max(D uint[[1]] x)

D int8 max(D int8[[1]] x)

D int16 max(D int16[[1]] x)

D int32 max(D int32[[1]] x)

D int max(D int[[1]] x)

D xor_uint8 max(D xor_uint8[[1]] x)

D xor_uint16 max(D xor_uint16[[1]] x)

D xor_uint32 max(D xor_uint32[[1]] x)

D xor_uint64 max(D xor_uint64[[1]] x)

max(2 vectors)

Function for finding the pointwise maximum of 2 arrays.

Detailed Description

D - shared2p protection domain

Supported types - uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / xor_uint8 / xor_uint16 / xor_uint32 / xor_uint64

Parameters

x

- first argument

y

- second argument

an array with the pointwise maximum of each element in the two input vectors

both input vectors are of equal length

Function Overloads

D uint8 max(D uint8 x, D uint8 y)

D uint16 max(D uint16 x, D uint16 y)

D uint32 max(D uint32 x, D uint32 y)

D uint max(D uint x, D uint y)

D int8 max(D int8 x, D int8 y)

D int16 max(D int16 x, D int16 y)

D int32 max(D int32 x, D int32 y)

D int max(D int x, D int y)

D uint8 max(D uint8[[1]] x, D uint8[[1]] y)

D uint16 max(D uint16[[1]] x, D uint16[[1]] y)

D uint32 max(D uint32[[1]] x, D uint32[[1]] y)

D uint max(D uint[[1]] x, D uint[[1]] y)

D int8 max(D int8[[1]] x, D int8[[1]] y)

D int16 max(D int16[[1]] x, D int16[[1]] y)

D int32 max(D int32[[1]] x, D int32[[1]] y)

D int max(D int[[1]] x, D int[[1]] y)

D uint8 max(D uint8[[N]] x, D uint8[[N]] y)

D uint16 max(D uint16[[N]] x, D uint16[[N]] y)

D uint32 max(D uint32[[N]] x, D uint32[[N]] y)

D uint max(D uint[[N]] x, D uint[[N]] y)

D int8 max(D int8[[N]] x, D int8[[N]] y)

D int16 max(D int16[[N]] x, D int16[[N]] y)

D int32 max(D int32[[N]] x, D int32[[N]] y)

D int max(D int[[N]] x, D int[[N]] y)

D xor_uint8 max(D xor_uint8 x, D xor_uint8 y)

D xor_uint16 max(D xor_uint16 x, D xor_uint16 y)

D xor_uint32 max(D xor_uint32 x, D xor_uint32 y)

D xor_uint64 max(D xor_uint64 x, D xor_uint64 y)

D xor_uint8 max(D xor_uint8[[1]] x, D xor_uint8[[1]] y)

D xor_uint16 max(D xor_uint16[[1]] x, D xor_uint16[[1]] y)

D xor_uint32 max(D xor_uint32[[1]] x, D xor_uint32[[1]] y)

D xor_uint64 max(D xor_uint64[[1]] x, D xor_uint64[[1]] y)

D xor_uint8 max(D xor_uint8[[N]] x, D xor_uint8[[N]] y)

D xor_uint16 max(D xor_uint16[[N]] x, D xor_uint16[[N]] y)

D xor_uint32 max(D xor_uint32[[N]] x, D xor_uint32[[N]] y)

D xor_uint64 max(D xor_uint64[[N]] x, D xor_uint64[[N]] y)

max(parts)

Function for finding the maximum element in the specified parts of the vector.

Detailed Description

D - shared2p protection domain

Supported types - uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

Parameters

x

- input vector

k

- an uint type value, which specifies into how many subarrays must the input array be divided

a vector with all the maximum elements of all the subarrays specified by k

input vector is not empty

the size of the input array is dividable by k

Function Overloads

D uint8 max(D uint8[[1]] x, uint k)

D uint16 max(D uint16[[1]] x, uint k)

D uint32 max(D uint32[[1]] x, uint k)

D uint max(D uint[[1]] x, uint k)

D int8 max(D int8[[1]] x, uint k)

D int16 max(D int16[[1]] x, uint k)

D int32 max(D int32[[1]] x, uint k)

D int max(D int[[1]] x, uint k)

min

Functions for finding the minimum value.

Functions:

min

D - shared2p protection domain

Supported types - uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

min

Function for finding the minimum element of the input vector.

Detailed Description

D - shared2p protection domain

Supported types - uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / xor_uint8 / xor_uint16 / xor_uint32 / xor_uint64

Parameters

x

- input

minimum element of the input vector.

input vector is not empty

Function Overloads

D T min(D T x)

D uint8 min(D uint8[[1]] x)

D uint16 min(D uint16[[1]] x)

D uint32 min(D uint32[[1]] x)

D uint min(D uint[[1]] x)

D int8 min(D int8[[1]] x)

D int16 min(D int16[[1]] x)

D int32 min(D int32[[1]] x)

D int min(D int[[1]] x)

D xor_uint8 min(D xor_uint8[[1]] x)

D xor_uint16 min(D xor_uint16[[1]] x)

D xor_uint32 min(D xor_uint32[[1]] x)

D xor_uint64 min(D xor_uint64[[1]] x)

min(2 vectors)

Function for finding the pointwise minimum of 2 arrays.

Detailed Description

D - shared2p protection domain

Supported types - uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / xor_uint8 / xor_uint16 / xor_uint32 / xor_uint64

Parameters

x

- first argument

y

- second argument

an array with the pointwise minimum of each element in the two input vectors

both input vectors are of equal length

Function Overloads

D uint8 min(D uint8 x, D uint8 y)

D uint16 min(D uint16 x, D uint16 y)

D uint32 min(D uint32 x, D uint32 y)

D uint min(D uint x, D uint y)

D int8 min(D int8 x, D int8 y)

D int16 min(D int16 x, D int16 y)

D int32 min(D int32 x, D int32 y)

D int min(D int x, D int y)

D uint8 min(D uint8[[1]] x, D uint8[[1]] y)

D uint16 min(D uint16[[1]] x, D uint16[[1]] y)

D uint32 min(D uint32[[1]] x, D uint32[[1]] y)

D uint min(D uint[[1]] x, D uint[[1]] y)

D int8 min(D int8[[1]] x, D int8[[1]] y)

D int16 min(D int16[[1]] x, D int16[[1]] y)

D int32 min(D int32[[1]] x, D int32[[1]] y)

D int min(D int[[1]] x, D int[[1]] y)

D uint8 min(D uint8[[N]] x, D uint8[[N]] y)

D uint16 min(D uint16[[N]] x, D uint16[[N]] y)

D uint32 min(D uint32[[N]] x, D uint32[[N]] y)

D uint min(D uint[[N]] x, D uint[[N]] y)

D int8 min(D int8[[N]] x, D int8[[N]] y)

D int16 min(D int16[[N]] x, D int16[[N]] y)

D int32 min(D int32[[N]] x, D int32[[N]] y)

D int min(D int[[N]] x, D int[[N]] y)

D xor_uint8 min(D xor_uint8 x, D xor_uint8 y)

D xor_uint16 min(D xor_uint16 x, D xor_uint16 y)

D xor_uint32 min(D xor_uint32 x, D xor_uint32 y)

D xor_uint64 min(D xor_uint64 x, D xor_uint64 y)

D xor_uint8 min(D xor_uint8[[1]] x, D xor_uint8[[1]] y)

D xor_uint16 min(D xor_uint16[[1]] x, D xor_uint16[[1]] y)

D xor_uint32 min(D xor_uint32[[1]] x, D xor_uint32[[1]] y)

D xor_uint64 min(D xor_uint64[[1]] x, D xor_uint64[[1]] y)

D xor_uint8 min(D xor_uint8[[N]] x, D xor_uint8[[N]] y)

D xor_uint16 min(D xor_uint16[[N]] x, D xor_uint16[[N]] y)

D xor_uint32 min(D xor_uint32[[N]] x, D xor_uint32[[N]] y)

D xor_uint64 min(D xor_uint64[[N]] x, D xor_uint64[[N]] y)

min(parts)

Function for finding the minimum element in the specified parts of the vector.

Detailed Description

D - shared2p protection domain

Supported types - uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

Parameters

x

- input vector

k

- an uint type value, which specifies into how many subarrays must the input array be divided

a vector with all the minimum elements of all the subarrays specified by k

input vector is not empty

the size of the input array is dividable by k

Function Overloads

D uint8 min(D uint8[[1]] x, uint k)

D uint16 min(D uint16[[1]] x, uint k)

D uint32 min(D uint32[[1]] x, uint k)

D uint min(D uint[[1]] x, uint k)

D int8 min(D int8[[1]] x, uint k)

D int16 min(D int16[[1]] x, uint k)

D int32 min(D int32[[1]] x, uint k)

D int min(D int[[1]] x, uint k)

product

Functions for finding products.

Functions:

D - shared2p protection domain

Supported types - uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

product

Function for finding the product of the input vector.

Detailed Description

D - shared2p protection domain

Supported types - uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

Parameters

x

- input of supported type

The product of the input vector

Function Overloads

D T product(D T x)

D uint8 product(D uint8[[1]] x)

D uint16 product(D uint16[[1]] x)

D uint32 product(D uint32[[1]] x)

D uint product(D uint[[1]] x)

D int8 product(D int8[[1]] x)

D int16 product(D int16[[1]] x)

D int32 product(D int32[[1]] x)

D int product(D int[[1]] x)

product(parts)

Function for finding the product of all elements in the input vector in specified parts.

Detailed Description

D - shared2p protection domain

Supported types - uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

the length of the input array must be a multiple of k

Parameters

vec

- The input array of subarrays to find the product of. The subarrays are stacked one after another and are all of the same size.

k

- The number of subarrays in the input array.

The array of subarrayCount number of products, each corresponding to respective subarray in the input array vec.

Function Overloads

D uint8 product(D uint8[[1]] vec, uint k)

D uint16 product(D uint16[[1]] vec, uint k)

D uint32 product(D uint32[[1]] vec, uint k)

D uint product(D uint[[1]] vec, uint k)

D int8 product(D int8[[1]] vec, uint k)

D int16 product(D int16[[1]] vec, uint k)

D int32 product(D int32[[1]] vec, uint k)

D int product(D int[[1]] vec, uint k)

sum

Functions for finding sums.

Functions:

sum

D - shared2p protection domain

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

sum

Function for finding the sum of all the elements in a vector.

Detailed Description

D - shared2p protection domain

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

We are using a system call for summing vectors as it’s very common operation, and the performance overhead of manually summing is in the range of 100 to 200 times slower.

Parameters

vec

- a 1-dimensional array

the sum of all input vector elements

Function Overloads

D uint sum(D bool[[1]] vec)

boolean values are converted to numerical values and then added, for more info click here

returns the sum of all the elements in the input vector as an uint64 type value

D uint8 sum(D uint8[[1]] vec)

D uint16 sum(D uint16[[1]] vec)

D uint32 sum(D uint32[[1]] vec)

D uint sum(D uint[[1]] vec)

D int8 sum(D int8[[1]] vec)

D int16 sum(D int16[[1]] vec)

D int32 sum(D int32[[1]] vec)

D int sum(D int[[1]] vec)

sum(parts)

Function for finding the sum of all elements in the input vector in specified parts.

Detailed Description

D - shared2p protection domain

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

the length of the input array must be a multiple of k

Parameters

vec

- The input array of subarrays to sum. The subarrays are stacked one after another and are all of the same size.

k

- The number of subarrays in the input array.

The array of subarrayCount number of sums, each corresponding to respective subarray in the input array vec.

Function Overloads

D uint sum(D bool[[1]] vec, uint k)

D uint8 sum(D uint8[[1]] vec, uint k)

D uint16 sum(D uint16[[1]] vec, uint k)

D uint32 sum(D uint32[[1]] vec, uint k)

D uint sum(D uint[[1]] vec, uint k)

D int8 sum(D int8[[1]] vec, uint k)

D int16 sum(D int16[[1]] vec, uint k)

D int32 sum(D int32[[1]] vec, uint k)

D int sum(D int[[1]] vec, uint k)