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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
2016-03-29 16:37:21 +00:00
|
|
|
#error only libtransmission should #include this header.
|
2008-11-24 20:17:36 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-29 19:02:26 +00:00
|
|
|
#ifndef TR_ENCRYPTION_H
|
|
|
|
#define TR_ENCRYPTION_H
|
2016-03-29 16:37:21 +00:00
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2014-12-04 12:37:08 +00:00
|
|
|
#include "crypto-utils.h"
|
2008-10-22 17:19:22 +00:00
|
|
|
#include "utils.h" /* TR_GNUC_NULL_TERMINATED */
|
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
|
|
|
|
{
|
#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
|
|
|
KEY_LEN = 96
|
2011-04-17 05:22:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief Holds state information for encrypted peer communications */
|
|
|
|
typedef struct
|
|
|
|
{
|
2014-12-04 12:37:08 +00:00
|
|
|
tr_rc4_ctx_t dec_key;
|
|
|
|
tr_rc4_ctx_t enc_key;
|
#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
|
|
|
tr_dh_ctx_t dh;
|
2011-04-17 05:22:50 +00:00
|
|
|
uint8_t myPublicKey[KEY_LEN];
|
#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
|
|
|
tr_dh_secret_t mySecret;
|
2011-04-17 05:22:50 +00:00
|
|
|
uint8_t torrentHash[SHA_DIGEST_LENGTH];
|
|
|
|
bool isIncoming;
|
|
|
|
bool torrentHashIsSet;
|
|
|
|
}
|
|
|
|
tr_crypto;
|
|
|
|
|
|
|
|
/** @brief construct a new tr_crypto object */
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_cryptoConstruct (tr_crypto * crypto, const uint8_t * torrentHash, bool isIncoming);
|
2011-04-17 05:22:50 +00:00
|
|
|
|
|
|
|
/** @brief destruct an existing tr_crypto object */
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_cryptoDestruct (tr_crypto * crypto);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_cryptoSetTorrentHash (tr_crypto * crypto, const uint8_t * torrentHash);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
const uint8_t* tr_cryptoGetTorrentHash (const tr_crypto * crypto);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2014-11-30 19:38:47 +00:00
|
|
|
bool tr_cryptoHasTorrentHash (const tr_crypto * crypto);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
#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
|
|
|
bool tr_cryptoComputeSecret (tr_crypto * crypto,
|
2012-12-05 17:29:46 +00:00
|
|
|
const uint8_t * peerPublicKey);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
const uint8_t* tr_cryptoGetMyPublicKey (const tr_crypto * crypto,
|
|
|
|
int * setme_len);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_cryptoDecryptInit (tr_crypto * crypto);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_cryptoDecrypt (tr_crypto * crypto,
|
2008-09-23 19:11:04 +00:00
|
|
|
size_t buflen,
|
|
|
|
const void * buf_in,
|
2012-12-05 17:29:46 +00:00
|
|
|
void * buf_out);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_cryptoEncryptInit (tr_crypto * crypto);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_cryptoEncrypt (tr_crypto * crypto,
|
2008-09-23 19:11:04 +00:00
|
|
|
size_t buflen,
|
|
|
|
const void * buf_in,
|
2012-12-05 17:29:46 +00:00
|
|
|
void * buf_out);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
#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
|
|
|
bool tr_cryptoSecretKeySha1 (const tr_crypto * crypto,
|
|
|
|
const void * prepend_data,
|
|
|
|
size_t prepend_data_size,
|
|
|
|
const void * append_data,
|
|
|
|
size_t append_data_size,
|
|
|
|
uint8_t * hash);
|
|
|
|
|
2010-01-19 19:37:00 +00:00
|
|
|
/* @} */
|
|
|
|
|
2016-03-29 19:02:26 +00:00
|
|
|
#endif
|