Skip to main content

Crate parasol_cpu

Crate parasol_cpu 

Source
Expand description

This crate provides the Parasol processor for running programs over encrypted data. The general workflow for using it is:

  • Compile a program using Parasol-clang
  • Encrypt our data and create an CallData object.
  • Call FheComputer::run_program, passing our key, program binary, the name of the program we want to run, and args.
  • Return or decrypt your program’s result.

§Example

use parasol_cpu::{run_program, ArgsBuilder};
use parasol_runtime::{ComputeKey, Encryption, PublicKey, SecretKey, fluent::Uint};

// Embed the compiled Parasol add program into a constant.
const FHE_FILE: &[u8] = include_bytes!("../data/add");

// Generate a secret key for the user. By default this ensures
// 128-bit security.
let secret_key =
    SecretKey::generate_with_default_params();

// Generate a compute key for the user. These keys are used for
// operations and do not give access to the plaintext data;
// therefore, this key can safely be shared with another party.
let compute_key =
    ComputeKey::generate_with_default_params(
        &secret_key,
    );

// Generate a public key that can be shared, allowing
// users to encrypt (but not decrypt) their data. By default
// this ensures 128-bit security.
let public_key =
    PublicKey::generate_with_default_params();

// Define the values we want to add. The values'
// sizes must match the Parasol C program's parameters
// when we encrypt them. Create the arguments and specify
// the return type
let enc = Encryption::default();
let args = ArgsBuilder::new()
    .arg(UInt8::encrypt(2, &enc, &public_key))
    .arg(UInt8::encrypt(7, &enc, &public_key))
    .return_value::<UInt8>();

// Run the program.
let encrypted_result = run_program(
    compute_key.clone(),
    FHE_FILE,
    "add",
    &args,
)
.unwrap();

// Decrypt the result.
let result = encrypted_result.decrypt(&enc, &secret_key);

println!("Encrypted {a} + {b} = {result}");

Modules§

register_names

Macros§

define_op
Define the list of opcodes for the processors ISA.
dep_idx
Return an expression that evaluates to $idx_ident’s index in $($src_name)*.
rep_len
Emit an expression that evaluates to the length of a macro rep expression.

Structs§

Allocation
A structure for efficiently placing multiple allocations into a single page allocation request.
Arg
The info needed to pass an argument to a function from the host program.
ArgsBuilder
A type for passing arguments to Parasol programs. When invoking crate::FheComputer::run_program, the processor will transparently set up the registers and first stack frame according to Parasol ABI’s calling convention.
CallData
Arguments passed to an FHE program when calling crate::FheComputer::run_program.
FheComputer
The Parasol processor that can run programs over encrypted and plaintext data.
Memory
The memory used by a crate::FheComputer during computation. The Parasol processor uses a Von Neumann architecture, meaning
MemoryConfig
Configuration used when building a memory object.
MemoryConfigBuilder
A builder for constructing a MemoryConfig object.
Ptr32
A 32-bit pointer.
ReturnValue
The info needed to capture the return value from an FHE program on the host.
RunProgramOptions
Options for running FheComputer::run_program_with_options
RunProgramOptionsBuilder
Builder pattern for RunProgramOptions
Word
An encrypted or unencrypted 32-bit value.

Enums§

Byte
An 8-bit encrypted or plaintext value.
Error
Errors that can occur in this crate.
Extend
How to extend an N-byte value to M >= N byte value.

Constants§

PAGE_SIZE
The number of bytes in a page.

Traits§

DynamicToArg
Similar to ToArg but the alignment and size are figured out from the instance not just the type
ToArg
A trait specifying how to convert this value to a form that can be passed as an FHE program argument.

Functions§

check_register_width
Checks if the width of two registers is the same. Used inside an instruction implementation.
register_to_l1glwe_by_trivial_lift
Convert a plaintext register to a L1 GLWE ciphertext register, or copy the existing ciphertext register if it’s already in that form.
run_program
Runs a program by generating a new crate::FheComputer. This function is meant for simple testing of a program; for full applications see the crate::FheComputer struct.

Type Aliases§

Result
Results for this crate.

Derive Macros§

IntoBytes
Allows you to #[derive(IntoBytes)] on structures where each member impls IntoBytes