Skip to content

Commit

Permalink
checkpoint in merging friend
Browse files Browse the repository at this point in the history
  • Loading branch information
Shengtong Zhang committed Jun 27, 2022
1 parent 50f62da commit 1f391d5
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 58 deletions.
53 changes: 0 additions & 53 deletions daemon/crypto/crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ auto generate_kx_keypair() -> std::pair<string, string> {
string(reinterpret_cast<char*>(secret_key), crypto_kx_SECRETKEYBYTES)};
}

<<<<<<< HEAD
auto generate_friend_request_keypair() -> std::pair<string, string> {
unsigned char public_key[crypto_box_PUBLICKEYBYTES];
unsigned char secret_key[crypto_box_SECRETKEYBYTES];
crypto_box_keypair(public_key, secret_key);
return {
string(reinterpret_cast<char*>(public_key), crypto_box_PUBLICKEYBYTES),
string(reinterpret_cast<char*>(secret_key), crypto_box_SECRETKEYBYTES)};
=======
auto generic_hash(string_view data) -> std::string {
unsigned char hash[crypto_generichash_BYTES];
crypto_generichash(hash, sizeof hash,
Expand All @@ -32,50 +23,6 @@ auto generic_hash(string_view data) -> std::string {
return string(reinterpret_cast<char*>(hash), sizeof hash);
}

auto generate_friend_key(const string& my_public_key, int index) -> string {
string public_key_b64;
public_key_b64.resize(sodium_base64_ENCODED_LEN(
my_public_key.size(), sodium_base64_VARIANT_URLSAFE_NO_PADDING));
sodium_bin2base64(
public_key_b64.data(), public_key_b64.size(),
reinterpret_cast<const unsigned char*>(my_public_key.data()),
my_public_key.size(), sodium_base64_VARIANT_URLSAFE_NO_PADDING);

// TODO: figure out a better way to encode both index and public key
return asphr::StrCat(index, "a", public_key_b64);
}

auto decode_friend_key(const string& friend_key)
-> asphr::StatusOr<std::pair<int, string>> {
string index_str;
string public_key_b64;
for (size_t i = 0; i < friend_key.size(); ++i) {
if (friend_key.at(i) == 'a') {
public_key_b64 = friend_key.substr(i + 1);
break;
}
index_str += friend_key.at(i);
}
int index;
auto success = absl::SimpleAtoi(index_str, &index);
if (!success) {
return asphr::InvalidArgumentError("friend key index must be an integer");
}

string public_key;
public_key.resize(public_key_b64.size());
size_t public_key_len;
const char* b64_end;
sodium_base642bin(reinterpret_cast<unsigned char*>(public_key.data()),
public_key.size(), public_key_b64.data(),
public_key_b64.size(), "", &public_key_len, &b64_end,
sodium_base64_VARIANT_URLSAFE_NO_PADDING);
public_key.resize(public_key_len);

return make_pair(index, public_key);
>>>>>>> origin/friends
}

auto derive_read_write_keys(string my_public_key, string my_private_key,
string friend_public_key)
-> std::pair<string, string> {
Expand Down
5 changes: 0 additions & 5 deletions daemon/crypto/crypto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
#include <stdexcept>
#include <string>

<<<<<<< HEAD
#include "asphr/asphr.hpp"
#include "daemon/constants.hpp"
=======
#include "constants.hpp"
>>>>>>> origin/friends
#include "schema/message.pb.h"

/* Crypto implements an IND-CCA2 secure scheme.
Expand Down

0 comments on commit 1f391d5

Please sign in to comment.