Skip to content

Commit

Permalink
Cryptography for encrypted messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ducknote committed Sep 30, 2014
1 parent 7055ade commit caf9925
Show file tree
Hide file tree
Showing 37 changed files with 902 additions and 886 deletions.
4 changes: 4 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Release notes 1.0.1

- Encrypted messages implementation

Release notes 1.0.0

- DarkNote
Expand Down
230 changes: 0 additions & 230 deletions contrib/epee/include/net/http_server_handlers_map2.h.bak

This file was deleted.

24 changes: 22 additions & 2 deletions include/IWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ const TransactionId INVALID_TRANSACTION_ID = std::numeric_limits<TransactionI
const TransferId INVALID_TRANSFER_ID = std::numeric_limits<TransferId>::max();
const uint64_t UNCONFIRMED_TRANSACTION_HEIGHT = std::numeric_limits<uint64_t>::max();

struct TransactionMessage
{
std::string message;
std::string address;
};

struct TransactionInfo {
TransferId firstTransferId;
size_t transferCount;
Expand All @@ -51,6 +57,17 @@ struct TransactionInfo {
uint64_t blockHeight;
uint64_t timestamp;
std::string extra;
std::vector<std::string> messages;
};

typedef std::array<uint8_t, 32> PublicKey;
typedef std::array<uint8_t, 32> SecretKey;

struct AccountKeys {
PublicKey viewPublicKey;
SecretKey viewSecretKey;
PublicKey spendPublicKey;
SecretKey spendSecretKey;
};

class IWalletObserver {
Expand All @@ -73,6 +90,7 @@ class IWallet {

virtual void initAndGenerate(const std::string& password) = 0;
virtual void initAndLoad(std::istream& source, const std::string& password) = 0;
virtual void initWithKeys(const AccountKeys& accountKeys, const std::string& password) = 0;
virtual void shutdown() = 0;

virtual void save(std::ostream& destination, bool saveDetailed = true, bool saveCache = true) = 0;
Expand All @@ -92,9 +110,11 @@ class IWallet {
virtual bool getTransaction(TransactionId transactionId, TransactionInfo& transaction) = 0;
virtual bool getTransfer(TransferId transferId, Transfer& transfer) = 0;

virtual TransactionId sendTransaction(const Transfer& transfer, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0) = 0;
virtual TransactionId sendTransaction(const std::vector<Transfer>& transfers, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0) = 0;
virtual TransactionId sendTransaction(const Transfer& transfer, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0, const std::vector<TransactionMessage>& messages = std::vector<TransactionMessage>()) = 0;
virtual TransactionId sendTransaction(const std::vector<Transfer>& transfers, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0, const std::vector<TransactionMessage>& messages = std::vector<TransactionMessage>()) = 0;
virtual std::error_code cancelTransaction(size_t transferId) = 0;

virtual void getAccountKeys(AccountKeys& keys) = 0;
};

}
6 changes: 3 additions & 3 deletions src/crypto/chacha8.c → src/crypto/chacha.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Public domain.
#include <stdio.h>
#include <sys/param.h>

#include "chacha8.h"
#include "chacha.h"
#include "common/int-util.h"
#include "warnings.h"

Expand Down Expand Up @@ -40,7 +40,7 @@ static const char sigma[] = "expand 32-byte k";

DISABLE_GCC_AND_CLANG_WARNING(strict-aliasing)

void chacha8(const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher) {
void chacha(size_t doubleRounds, const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher) {
uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
uint32_t j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
char* ctarget = 0;
Expand Down Expand Up @@ -89,7 +89,7 @@ void chacha8(const void* data, size_t length, const uint8_t* key, const uint8_t*
x13 = j13;
x14 = j14;
x15 = j15;
for (i = 8;i > 0;i -= 2) {
for (i = 0; i < doubleRounds; i++) {
QUARTERROUND( x0, x4, x8,x12)
QUARTERROUND( x1, x5, x9,x13)
QUARTERROUND( x2, x6,x10,x14)
Expand Down
28 changes: 14 additions & 14 deletions src/crypto/chacha8.h → src/crypto/chacha.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include <stdint.h>
#include <stddef.h>

#define CHACHA8_KEY_SIZE 32
#define CHACHA8_IV_SIZE 8
#define CHACHA_KEY_SIZE 32
#define CHACHA_IV_SIZE 8

#if defined(__cplusplus)
#include <memory.h>
Expand All @@ -31,34 +31,34 @@
namespace crypto {
extern "C" {
#endif
void chacha8(const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher);
void chacha(size_t doubleRounds, const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher);
#if defined(__cplusplus)
}

#pragma pack(push, 1)
struct chacha8_key {
uint8_t data[CHACHA8_KEY_SIZE];
struct chacha_key {
uint8_t data[CHACHA_KEY_SIZE];

~chacha8_key()
~chacha_key()
{
memset(data, 0, sizeof(data));
}
};

// MS VC 2012 doesn't interpret `class chacha8_iv` as POD in spite of [9.0.10], so it is a struct
struct chacha8_iv {
uint8_t data[CHACHA8_IV_SIZE];
// MS VC 2012 doesn't interpret `class chacha_iv` as POD in spite of [9.0.10], so it is a struct
struct chacha_iv {
uint8_t data[CHACHA_IV_SIZE];
};
#pragma pack(pop)

static_assert(sizeof(chacha8_key) == CHACHA8_KEY_SIZE && sizeof(chacha8_iv) == CHACHA8_IV_SIZE, "Invalid structure size");
static_assert(sizeof(chacha_key) == CHACHA_KEY_SIZE && sizeof(chacha_iv) == CHACHA_IV_SIZE, "Invalid structure size");

inline void chacha8(const void* data, std::size_t length, const chacha8_key& key, const chacha8_iv& iv, char* cipher) {
chacha8(data, length, reinterpret_cast<const uint8_t*>(&key), reinterpret_cast<const uint8_t*>(&iv), cipher);
inline void chacha8(const void* data, std::size_t length, const chacha_key& key, const chacha_iv& iv, char* cipher) {
chacha(4, data, length, reinterpret_cast<const uint8_t*>(&key), reinterpret_cast<const uint8_t*>(&iv), cipher);
}

inline void generate_chacha8_key(crypto::cn_context &context, std::string password, chacha8_key& key) {
static_assert(sizeof(chacha8_key) <= sizeof(hash), "Size of hash must be at least that of chacha8_key");
inline void generate_chacha8_key(crypto::cn_context &context, std::string password, chacha_key& key) {
static_assert(sizeof(chacha_key) <= sizeof(hash), "Size of hash must be at least that of chacha_key");
crypto::hash pwd_hash;
crypto::cn_slow_hash(context, password.data(), password.size(), pwd_hash);
memcpy(&key, &pwd_hash, sizeof(key));
Expand Down
3 changes: 1 addition & 2 deletions src/cryptonote_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ const CheckpointData CHECKPOINTS[] = {
{ 4200, "76af92fc41eadf9c99df91efc08011d0fce6f3f55b131da2449c187f432f91f7" },
{ 11000, "970c15459e4d484166c36e303fcf35886e14633b40b1fe4e3f250eb03eaca1f8" },
{ 22000, "ae9ab36c4ff2cf215d49ffa4358d108dd777b8897c2d873a064dc103fea2b5ab" },
{ 33000, "3fac95a900e65391d693e2cb331a26c757595baac133b9fa24936dd50fc7465f" },
{ 40420, "572b1e54baedf349b2fda493fe8d42dccb5b6c5ee3ff1008611dc326198c52fa" },
{ 33000, "3fac95a900e65391d693e2cb331a26c757595baac133b9fa24936dd50fc7465f" }
};

} // cryptonote
Expand Down

0 comments on commit caf9925

Please sign in to comment.