2007-09-20 16:32:01 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2007-2014 Mnemosyne LLC
|
2007-09-20 16:32:01 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2007-09-20 16:32:01 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
// NB: crypto-test-ref.h needs this, so use it instead of #pragma once
|
2017-11-14 20:21:28 +00:00
|
|
|
#ifndef TR_ENCRYPTION_H
|
|
|
|
#define TR_ENCRYPTION_H
|
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
2017-04-19 12:04:45 +00:00
|
|
|
#error only libtransmission should #include this header.
|
2008-11-24 20:17:36 +00:00
|
|
|
#endif
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2014-12-04 12:37:08 +00:00
|
|
|
#include "crypto-utils.h"
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "tr-macros.h"
|
2008-10-22 17:14:50 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/**
|
2010-01-19 19:37:00 +00:00
|
|
|
*** @addtogroup peers
|
|
|
|
*** @{
|
|
|
|
**/
|
2009-05-29 19:17:12 +00:00
|
|
|
|
2011-04-17 05:22:50 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
KEY_LEN = 96
|
2011-04-17 05:22:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief Holds state information for encrypted peer communications */
|
2021-10-06 14:26:07 +00:00
|
|
|
struct tr_crypto
|
2011-04-17 05:22:50 +00:00
|
|
|
{
|
2021-09-12 03:47:29 +00:00
|
|
|
struct arc4_context* dec_key;
|
|
|
|
struct arc4_context* enc_key;
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_dh_ctx_t dh;
|
|
|
|
uint8_t myPublicKey[KEY_LEN];
|
|
|
|
tr_dh_secret_t mySecret;
|
|
|
|
uint8_t torrentHash[SHA_DIGEST_LENGTH];
|
|
|
|
bool isIncoming;
|
|
|
|
bool torrentHashIsSet;
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2011-04-17 05:22:50 +00:00
|
|
|
|
|
|
|
/** @brief construct a new tr_crypto object */
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_cryptoConstruct(tr_crypto* crypto, uint8_t const* torrentHash, bool isIncoming);
|
2011-04-17 05:22:50 +00:00
|
|
|
|
|
|
|
/** @brief destruct an existing tr_crypto object */
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_cryptoDestruct(tr_crypto* crypto);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_cryptoSetTorrentHash(tr_crypto* crypto, uint8_t const* torrentHash);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
uint8_t const* tr_cryptoGetTorrentHash(tr_crypto const* crypto);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_cryptoHasTorrentHash(tr_crypto const* crypto);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_cryptoComputeSecret(tr_crypto* crypto, uint8_t const* peerPublicKey);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
uint8_t const* tr_cryptoGetMyPublicKey(tr_crypto const* crypto, int* setme_len);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_cryptoDecryptInit(tr_crypto* crypto);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_cryptoDecrypt(tr_crypto* crypto, size_t buflen, void const* buf_in, void* buf_out);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_cryptoEncryptInit(tr_crypto* crypto);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_cryptoEncrypt(tr_crypto* crypto, size_t buflen, void const* buf_in, void* buf_out);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
bool tr_cryptoSecretKeySha1(
|
|
|
|
tr_crypto const* crypto,
|
|
|
|
void const* prepend_data,
|
|
|
|
size_t prepend_data_size,
|
|
|
|
void const* append_data,
|
|
|
|
size_t append_data_size,
|
|
|
|
uint8_t* hash);
|
#4400, #5462: Move DH helpers to crypto-utils
On a way to factoring out OpenSSL support to a standalone file to ease
addition of other crypto libraries support in the future, move helpers
providing DH key exchange to crypto-utils.{c,h}. OpenSSL-related
functionality (DH context management) is moved to crypto-utils-openssl.c.
Since we know in advance that DH secret key management code will be the
same for most of backends, implement common functionality in separate
crypto-utils-fallback.c.
Add new tr_dh_ctx_t and tr_dh_secret_t types and functions to be
implemented by crypto backends:
* tr_dh_new - allocate DH context,
* tr_dh_free - free the context,
* tr_dh_make_key - generate private/public keypair,
* tr_dh_agree - perform DH key exchange and generate secret key,
* tr_dh_secret_derive - calculate secret key hash,
* tr_dh_secret_free - free the secret key,
* tr_dh_align_key - align some DH key in the buffer allocated for it.
Make DH secret key not accessible in plain form outside the crypto
backend. This allows for implementations where the key is managed by
the underlying library and is not even exposed to our backend.
2014-12-04 19:18:08 +00:00
|
|
|
|
2010-01-19 19:37:00 +00:00
|
|
|
/* @} */
|
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
#endif // TR_ENCRYPTION_H
|