Skip to content

Commit

Permalink
rename kx_key
Browse files Browse the repository at this point in the history
  • Loading branch information
Shengtong Zhang committed Jun 22, 2022
1 parent f5e07bd commit aec1b8b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 42 deletions.
16 changes: 8 additions & 8 deletions daemon/db/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ pub mod ffi {
#[derive(Queryable)]
struct Registration {
pub uid: i32,
pub public_key: Vec<u8>,
pub private_key: Vec<u8>,
pub kx_public_key: Vec<u8>,
pub kx_private_key: Vec<u8>,
pub allocation: i32,
pub pir_secret_key: Vec<u8>,
pub pir_galois_key: Vec<u8>,
Expand All @@ -181,8 +181,8 @@ pub mod ffi {
#[derive(Insertable)]
#[diesel(table_name = crate::schema::registration)]
struct RegistrationFragment {
pub public_key: Vec<u8>,
pub private_key: Vec<u8>,
pub kx_public_key: Vec<u8>,
pub kx_private_key: Vec<u8>,
pub allocation: i32,
pub pir_secret_key: Vec<u8>,
pub pir_galois_key: Vec<u8>,
Expand All @@ -196,8 +196,8 @@ pub mod ffi {
#[derive(Queryable)]
struct SmallRegistrationFragment {
pub uid: i32,
pub public_key: Vec<u8>,
pub private_key: Vec<u8>,
pub kx_public_key: Vec<u8>,
pub kx_private_key: Vec<u8>,
pub allocation: i32,
pub authentication_token: String,
}
Expand Down Expand Up @@ -588,8 +588,8 @@ impl DB {

let q = registration::table.select((
registration::uid,
registration::public_key,
registration::private_key,
registration::kx_public_key,
registration::kx_private_key,
registration::allocation,
registration::authentication_token,
));
Expand Down
26 changes: 13 additions & 13 deletions daemon/db/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ diesel::table! {
diesel::table! {
registration (uid) {
uid -> Integer,
public_key -> Binary,
private_key -> Binary,
kx_public_key -> Binary,
kx_private_key -> Binary,
allocation -> Integer,
pir_secret_key -> Binary,
pir_galois_key -> Binary,
Expand Down Expand Up @@ -122,15 +122,15 @@ diesel::joinable!(sent -> message (uid));
diesel::joinable!(status -> friend (uid));

diesel::allow_tables_to_appear_in_same_query!(
address,
config,
draft,
friend,
incoming_chunk,
message,
outgoing_chunk,
received,
registration,
sent,
status,
address,
config,
draft,
friend,
incoming_chunk,
message,
outgoing_chunk,
received,
registration,
sent,
status,
);
12 changes: 6 additions & 6 deletions daemon/db/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ use crate::db::*;
use rand::Rng;

fn get_registration_fragment() -> ffi::RegistrationFragment {
let public_key: Vec<u8> = br#"zIUWz21AsWme9KxgS43TbrlaKYlLJqVMj/j1TKTIjx0="#.to_vec();
let private_key: Vec<u8> = br#""EUSOOwjVEHRD1XzruR93LcK8YosZ3gWUkrrk8yjrpIQ="#.to_vec();
let kx_public_key: Vec<u8> = br#"zIUWz21AsWme9KxgS43TbrlaKYlLJqVMj/j1TKTIjx0="#.to_vec();
let kx_private_key: Vec<u8> = br#""EUSOOwjVEHRD1XzruR93LcK8YosZ3gWUkrrk8yjrpIQ="#.to_vec();
let allocation: i32 = 34;
let pir_secret_key: Vec<u8> = br#""hi hi"#.to_vec();
let pir_galois_key: Vec<u8> = br#""hi hi hi"#.to_vec();
let authentication_token: String = "X6H3ILWIrDGThjbi4IpYfWGtJ3YWdMIf".to_string();

ffi::RegistrationFragment {
public_key,
private_key,
kx_public_key,
kx_private_key,
allocation,
pir_secret_key,
pir_galois_key,
Expand Down Expand Up @@ -75,8 +75,8 @@ fn test_register() {

match new_registration {
Ok(registration) => {
assert_eq!(registration.public_key, config_clone.public_key);
assert_eq!(registration.private_key, config_clone.private_key);
assert_eq!(registration.kx_public_key, config_clone.kx_public_key);
assert_eq!(registration.kx_private_key, config_clone.kx_private_key);
assert_eq!(registration.allocation, config_clone.allocation);
assert_eq!(registration.pir_secret_key, config_clone.pir_secret_key);
assert_eq!(registration.pir_galois_key, config_clone.pir_galois_key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ CREATE TABLE config (
-- 0-1 elements always!
CREATE TABLE registration (
uid integer PRIMARY KEY NOT NULL,
public_key blob NOT NULL,
private_key blob NOT NULL,
kx_public_key blob NOT NULL,
kx_private_key blob NOT NULL,
allocation integer NOT NULL,
pir_secret_key blob NOT NULL,
pir_galois_key blob NOT NULL,
Expand Down
18 changes: 9 additions & 9 deletions daemon/rpc/daemon_rpc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ Status DaemonRpc::RegisterUser(
}

const auto name = registerUserRequest->name();
const auto [public_key, secret_key] = crypto::generate_keypair();
const auto [kx_public_key, secret_key] = crypto::generate_keypair();
const auto [pir_secret_key, pir_galois_keys] = generate_keys();

auto beta_key = registerUserRequest->beta_key();

// call register rpc to send the register request
asphrserver::RegisterInfo request;
request.set_public_key(public_key);
request.set_public_key(kx_public_key);
request.set_beta_key(beta_key);

asphrserver::RegisterResponse reply;
Expand Down Expand Up @@ -66,8 +66,8 @@ Status DaemonRpc::RegisterUser(

try {
G.db->do_register(db::RegistrationFragment{
.public_key = string_to_rust_u8Vec(public_key),
.private_key = string_to_rust_u8Vec(secret_key),
.kx_public_key = string_to_rust_u8Vec(kx_public_key),
.kx_private_key = string_to_rust_u8Vec(secret_key),
.allocation = allocation.at(0),
.pir_secret_key = string_to_rust_u8Vec(pir_secret_key),
.pir_galois_key = string_to_rust_u8Vec(pir_galois_keys),
Expand Down Expand Up @@ -130,8 +130,8 @@ Status DaemonRpc::GenerateFriendKey(
// note: for now, we only support the first index ever!
auto reg = G.db->get_small_registration();
auto index = reg.allocation;
auto friend_key =
crypto::generate_friend_key(rust_u8Vec_to_string(reg.public_key), index);
auto friend_key = crypto::generate_friend_key(
rust_u8Vec_to_string(reg.kx_public_key), index);

try {
const auto f = G.db->create_friend(generateFriendKeyRequest->unique_name(),
Expand Down Expand Up @@ -166,12 +166,12 @@ Status DaemonRpc::AddFriend(
ASPHR_LOG_ERR("Invalid friend key.", rpc_call, "AddFriend");
return Status(grpc::StatusCode::INVALID_ARGUMENT, "invalid friend key");
}
auto [read_index, friend_public_key] = decoded_friend_key.value();
auto [read_index, friend_kx_public_key] = decoded_friend_key.value();

auto reg = G.db->get_small_registration();
auto [read_key, write_key] = crypto::derive_read_write_keys(
rust_u8Vec_to_string(reg.public_key),
rust_u8Vec_to_string(reg.private_key), friend_public_key);
rust_u8Vec_to_string(reg.kx_public_key),
rust_u8Vec_to_string(reg.kx_private_key), friend_kx_public_key);

try {
G.db->add_friend_address(
Expand Down
8 changes: 4 additions & 4 deletions daemon/transmitter/transmitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ auto generate_dummy_address(const Global& G, const db::Registration& reg)
-> db::Address {
auto dummy_friend_keypair = crypto::generate_keypair();

// convert reg.public_key, private_key to a string
auto public_key_str = rust_u8Vec_to_string(reg.public_key);
auto private_key_str = rust_u8Vec_to_string(reg.private_key);
// convert reg.kx_public_key, kx_private_key to a string
auto kx_public_key_str = rust_u8Vec_to_string(reg.kx_public_key);
auto kx_private_key_str = rust_u8Vec_to_string(reg.kx_private_key);

auto dummy_read_write_keys = crypto::derive_read_write_keys(
public_key_str, private_key_str, dummy_friend_keypair.first);
kx_public_key_str, kx_private_key_str, dummy_friend_keypair.first);

// convert dummy_read_write_keys to a rust::Vec<uint8_t>
auto read_key_vec_rust = string_to_rust_u8Vec(dummy_read_write_keys.first);
Expand Down

0 comments on commit aec1b8b

Please sign in to comment.