-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from mpretty-cyro/general-encryption
General encryption
- Loading branch information
Showing
42 changed files
with
3,702 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/build*/ | ||
/compile_commands.json | ||
/.cache/ | ||
/.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <stddef.h> | ||
|
||
#include "export.h" | ||
|
||
/// API: crypto/session_blind15_key_pair | ||
/// | ||
/// This function attempts to generate a blind15 key pair. | ||
/// | ||
/// Inputs: | ||
/// - `ed25519_seckey` -- [in] the Ed25519 private key of the sender (64 bytes). | ||
/// - `server_pk` -- [in] the public key of the open group server to generate the | ||
/// blinded id for (32 bytes). | ||
/// - `blinded_pk_out` -- [out] pointer to a buffer of at least 32 bytes where the blinded_pk will | ||
/// be written if generation was successful. | ||
/// - `blinded_sk_out` -- [out] pointer to a buffer of at least 32 bytes where the blinded_sk will | ||
/// be written if generation was successful. | ||
/// | ||
/// Outputs: | ||
/// - `bool` -- True if the key was successfully generated, false if generation failed. | ||
LIBSESSION_EXPORT bool session_blind15_key_pair( | ||
const unsigned char* ed25519_seckey, /* 64 bytes */ | ||
const unsigned char* server_pk, /* 32 bytes */ | ||
unsigned char* blinded_pk_out, /* 32 byte output buffer */ | ||
unsigned char* blinded_sk_out /* 32 byte output buffer */); | ||
|
||
/// API: crypto/session_blind25_key_pair | ||
/// | ||
/// This function attempts to generate a blind25 key pair. | ||
/// | ||
/// Inputs: | ||
/// - `ed25519_seckey` -- [in] the Ed25519 private key of the sender (64 bytes). | ||
/// - `server_pk` -- [in] the public key of the open group server to generate the | ||
/// blinded id for (32 bytes). | ||
/// - `blinded_pk_out` -- [out] pointer to a buffer of at least 32 bytes where the blinded_pk will | ||
/// be written if generation was successful. | ||
/// - `blinded_sk_out` -- [out] pointer to a buffer of at least 32 bytes where the blinded_sk will | ||
/// be written if generation was successful. | ||
/// | ||
/// Outputs: | ||
/// - `bool` -- True if the key was successfully generated, false if generation failed. | ||
LIBSESSION_EXPORT bool session_blind25_key_pair( | ||
const unsigned char* ed25519_seckey, /* 64 bytes */ | ||
const unsigned char* server_pk, /* 32 bytes */ | ||
unsigned char* blinded_pk_out, /* 32 byte output buffer */ | ||
unsigned char* blinded_sk_out /* 32 byte output buffer */); | ||
|
||
/// API: crypto/session_blind15_sign | ||
/// | ||
/// This function attempts to generate a signature for a message using a blind15 private key. | ||
/// | ||
/// Inputs: | ||
/// - `ed25519_seckey` -- [in] the Ed25519 private key of the sender (64 bytes). | ||
/// - `server_pk` -- [in] the public key of the open group server to generate the | ||
/// blinded id for (32 bytes). | ||
/// - `msg` -- [in] Pointer to a data buffer containing the message to generate a signature for. | ||
/// - `msg_len` -- [in] Length of `msg` | ||
/// - `blinded_sig_out` -- [out] pointer to a buffer of at least 64 bytes where the signature will | ||
/// be written if generation was successful. | ||
/// | ||
/// Outputs: | ||
/// - `bool` -- True if the signature was successfully generated, false if generation failed. | ||
LIBSESSION_EXPORT bool session_blind15_sign( | ||
const unsigned char* ed25519_seckey, /* 64 bytes */ | ||
const unsigned char* server_pk, /* 32 bytes */ | ||
const unsigned char* msg, | ||
size_t msg_len, | ||
unsigned char* blinded_sig_out /* 64 byte output buffer */); | ||
|
||
/// API: crypto/session_blind25_sign | ||
/// | ||
/// This function attempts to generate a signature for a message using a blind25 private key. | ||
/// | ||
/// Inputs: | ||
/// - `ed25519_seckey` -- [in] the Ed25519 private key of the sender (64 bytes). | ||
/// - `server_pk` -- [in] the public key of the open group server to generate the | ||
/// blinded id for (32 bytes). | ||
/// - `msg` -- [in] Pointer to a data buffer containing the message to generate a signature for. | ||
/// - `msg_len` -- [in] Length of `msg` | ||
/// - `blinded_sig_out` -- [out] pointer to a buffer of at least 64 bytes where the signature will | ||
/// be written if generation was successful. | ||
/// | ||
/// Outputs: | ||
/// - `bool` -- True if the signature was successfully generated, false if generation failed. | ||
LIBSESSION_EXPORT bool session_blind25_sign( | ||
const unsigned char* ed25519_seckey, /* 64 bytes */ | ||
const unsigned char* server_pk, /* 32 bytes */ | ||
const unsigned char* msg, | ||
size_t msg_len, | ||
unsigned char* blinded_sig_out /* 64 byte output buffer */); | ||
|
||
/// API: crypto/session_blind25_sign | ||
/// | ||
/// This function attempts to generate a signature for a message using a blind25 private key. | ||
/// | ||
/// Inputs: | ||
/// - `session_id` -- [in] the session_id to compare (66 bytes with a 05 prefix). | ||
/// - `blinded_id` -- [in] the blinded_id to compare, can be either 15 or 25 blinded (66 bytes). | ||
/// - `server_pk` -- [in] the public key of the open group server to the blinded id came from (64 | ||
/// bytes). | ||
/// | ||
/// Outputs: | ||
/// - `bool` -- True if the session_id matches the blinded_id, false if not. | ||
LIBSESSION_EXPORT bool session_id_matches_blinded_id( | ||
const char* session_id, /* 66 bytes */ | ||
const char* blinded_id, /* 66 bytes */ | ||
const char* server_pk /* 64 bytes */); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <stddef.h> | ||
|
||
#include "export.h" | ||
|
||
/// API: crypto/session_curve25519_key_pair | ||
/// | ||
/// Generates a random curve25519 key pair. | ||
/// | ||
/// Inputs: | ||
/// - `curve25519_pk_out` -- [out] pointer to a buffer of 32 bytes where the public key will be | ||
/// written. | ||
/// - `curve25519_sk_out` -- [out] pointer to a buffer of 32 bytes where the private key will be | ||
/// written. | ||
/// | ||
/// Outputs: | ||
/// - `bool` -- True if the seed was successfully retrieved, false if failed. | ||
LIBSESSION_EXPORT bool session_curve25519_key_pair( | ||
unsigned char* curve25519_pk_out, /* 32 byte output buffer */ | ||
unsigned char* curve25519_sk_out /* 32 byte output buffer */); | ||
|
||
/// API: crypto/session_to_curve25519_pubkey | ||
/// | ||
/// Generates a curve25519 public key for an ed25519 public key. | ||
/// | ||
/// Inputs: | ||
/// - `ed25519_pubkey` -- the ed25519 public key (32 bytes). | ||
/// - `curve25519_pk_out` -- [out] pointer to a buffer of 32 bytes where the public key will be | ||
/// written. | ||
/// | ||
/// Outputs: | ||
/// - `bool` -- True if the public key was successfully generated, false if failed. | ||
LIBSESSION_EXPORT bool session_to_curve25519_pubkey( | ||
const unsigned char* ed25519_pubkey, /* 32 bytes */ | ||
unsigned char* curve25519_pk_out /* 32 byte output buffer */); | ||
|
||
/// API: crypto/session_to_curve25519_seckey | ||
/// | ||
/// Generates a curve25519 secret key given given either a libsodium-style secret key, 64 | ||
/// bytes. Can also be passed as a 32-byte seed. | ||
/// | ||
/// Inputs: | ||
/// - `ed25519_seckey` -- [in] the libsodium-style secret key, 64 bytes. Can also be | ||
/// passed as a 32-byte seed. | ||
/// - `curve25519_sk_out` -- [out] pointer to a buffer of 32 bytes where the secret key will be | ||
/// written. | ||
/// | ||
/// Outputs: | ||
/// - `bool` -- True if the secret key was successfully generated, false if failed. | ||
LIBSESSION_EXPORT bool session_to_curve25519_seckey( | ||
const unsigned char* ed25519_seckey, /* 64 bytes */ | ||
unsigned char* curve25519_sk_out /* 32 byte output buffer */); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
|
||
#include "types.hpp" | ||
|
||
namespace session::curve25519 { | ||
|
||
/// Generates a random curve25519 key pair | ||
std::pair<std::array<unsigned char, 32>, std::array<unsigned char, 64>> curve25519_key_pair(); | ||
|
||
/// API: curve25519/to_curve25519_pubkey | ||
/// | ||
/// Generates a curve25519 public key for an ed25519 public key. | ||
/// | ||
/// Inputs: | ||
/// - `ed25519_pubkey` -- the ed25519 public key. | ||
/// | ||
/// Outputs: | ||
/// - The curve25519 public key | ||
std::array<unsigned char, 32> to_curve25519_pubkey(ustring_view ed25519_pubkey); | ||
|
||
/// API: curve25519/to_curve25519_seckey | ||
/// | ||
/// Generates a curve25519 secret key given given a libsodium-style secret key, 64 | ||
/// bytes. | ||
/// | ||
/// Inputs: | ||
/// - `ed25519_seckey` -- the libsodium-style secret key, 64 bytes. | ||
/// | ||
/// Outputs: | ||
/// - The curve25519 secret key | ||
std::array<unsigned char, 32> to_curve25519_seckey(ustring_view ed25519_seckey); | ||
|
||
} // namespace session::curve25519 |
Oops, something went wrong.