mirror of
https://github.com/transmission/transmission
synced 2024-12-28 02:27:41 +00:00
d424ed143e
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 RC4 ciphering to crypto-utils.{c,h}. OpenSSL-related functionality (RC4 context management) is moved to crypto-utils-openssl.c. Add new tr_rc4_ctx_t type and functions to be implemented by crypto backends: * tr_rc4_new - allocate RC4 context, * tr_rc4_free - free the context, * tr_rc4_set_key - set cipher key, * tr_rc4_process - cipher memory block.
97 lines
2.5 KiB
C
97 lines
2.5 KiB
C
/*
|
|
* This file Copyright (C) 2007-2014 Mnemosyne LLC
|
|
*
|
|
* It may be used under the GNU GPL versions 2 or 3
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
*
|
|
* $Id$
|
|
*/
|
|
|
|
#ifndef TR_ENCRYPTION_H
|
|
#define TR_ENCRYPTION_H
|
|
|
|
#ifndef __TRANSMISSION__
|
|
#error only libtransmission should #include this header.
|
|
#endif
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include "crypto-utils.h"
|
|
#include "utils.h" /* TR_GNUC_NULL_TERMINATED */
|
|
|
|
/**
|
|
*** @addtogroup peers
|
|
*** @{
|
|
**/
|
|
|
|
#include <openssl/dh.h> /* DH */
|
|
|
|
enum
|
|
{
|
|
KEY_LEN = 96
|
|
};
|
|
|
|
/** @brief Holds state information for encrypted peer communications */
|
|
typedef struct
|
|
{
|
|
tr_rc4_ctx_t dec_key;
|
|
tr_rc4_ctx_t enc_key;
|
|
DH * dh;
|
|
uint8_t myPublicKey[KEY_LEN];
|
|
uint8_t mySecret[KEY_LEN];
|
|
uint8_t torrentHash[SHA_DIGEST_LENGTH];
|
|
bool isIncoming;
|
|
bool torrentHashIsSet;
|
|
bool mySecretIsSet;
|
|
}
|
|
tr_crypto;
|
|
|
|
/** @brief construct a new tr_crypto object */
|
|
void tr_cryptoConstruct (tr_crypto * crypto, const uint8_t * torrentHash, bool isIncoming);
|
|
|
|
/** @brief destruct an existing tr_crypto object */
|
|
void tr_cryptoDestruct (tr_crypto * crypto);
|
|
|
|
|
|
void tr_cryptoSetTorrentHash (tr_crypto * crypto, const uint8_t * torrentHash);
|
|
|
|
const uint8_t* tr_cryptoGetTorrentHash (const tr_crypto * crypto);
|
|
|
|
bool tr_cryptoHasTorrentHash (const tr_crypto * crypto);
|
|
|
|
const uint8_t* tr_cryptoComputeSecret (tr_crypto * crypto,
|
|
const uint8_t * peerPublicKey);
|
|
|
|
const uint8_t* tr_cryptoGetMyPublicKey (const tr_crypto * crypto,
|
|
int * setme_len);
|
|
|
|
void tr_cryptoDecryptInit (tr_crypto * crypto);
|
|
|
|
void tr_cryptoDecrypt (tr_crypto * crypto,
|
|
size_t buflen,
|
|
const void * buf_in,
|
|
void * buf_out);
|
|
|
|
void tr_cryptoEncryptInit (tr_crypto * crypto);
|
|
|
|
void tr_cryptoEncrypt (tr_crypto * crypto,
|
|
size_t buflen,
|
|
const void * buf_in,
|
|
void * buf_out);
|
|
|
|
/* @} */
|
|
|
|
/**
|
|
*** @addtogroup utils Utilities
|
|
*** @{
|
|
**/
|
|
|
|
/** @brief generate a SSHA password from its plaintext source */
|
|
char* tr_ssha1 (const void * plaintext);
|
|
|
|
/** @brief Validate a test password against the a ssha1 password */
|
|
bool tr_ssha1_matches (const char * ssha1, const char * pass);
|
|
|
|
/* @} */
|
|
|
|
#endif
|