2007-09-20 16:32:01 +00:00
|
|
|
/*
|
2009-12-05 02:19:24 +00:00
|
|
|
* This file Copyright (C) 2007-2009 Mnemosyne LLC
|
2007-09-20 16:32:01 +00:00
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
2008-09-23 19:11:04 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2007-09-20 16:32:01 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TR_ENCRYPTION_H
|
|
|
|
#define TR_ENCRYPTION_H
|
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
|
|
|
#error only libtransmission should #include this header.
|
|
|
|
#endif
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2008-10-22 17:19:22 +00:00
|
|
|
#include "utils.h" /* TR_GNUC_NULL_TERMINATED */
|
2008-10-22 17:14:50 +00:00
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
|
|
|
struct evbuffer;
|
2009-05-29 19:17:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup utils Utilities
|
2009-08-12 14:40:32 +00:00
|
|
|
* @{
|
2009-05-29 19:17:12 +00:00
|
|
|
*/
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
typedef struct tr_crypto tr_crypto;
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_crypto* tr_cryptoNew( const uint8_t * torrentHash,
|
|
|
|
int isIncoming );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_cryptoFree( tr_crypto * crypto );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_cryptoSetTorrentHash( tr_crypto * crypto,
|
|
|
|
const uint8_t * torrentHash );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
const uint8_t* tr_cryptoGetTorrentHash( const tr_crypto * crypto );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
int tr_cryptoHasTorrentHash( const tr_crypto * crypto );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
const uint8_t* tr_cryptoComputeSecret( tr_crypto * crypto,
|
|
|
|
const uint8_t * peerPublicKey );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
const uint8_t* tr_cryptoGetMyPublicKey( const tr_crypto * crypto,
|
|
|
|
int * setme_len );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_cryptoDecryptInit( tr_crypto * crypto );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_cryptoDecrypt( tr_crypto * crypto,
|
|
|
|
size_t buflen,
|
|
|
|
const void * buf_in,
|
|
|
|
void * buf_out );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_cryptoEncryptInit( tr_crypto * crypto );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_cryptoEncrypt( tr_crypto * crypto,
|
|
|
|
size_t buflen,
|
|
|
|
const void * buf_in,
|
|
|
|
void * buf_out );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_sha1( uint8_t * setme,
|
|
|
|
const void * content1,
|
|
|
|
int content1_len,
|
2008-10-22 17:14:50 +00:00
|
|
|
... ) TR_GNUC_NULL_TERMINATED;
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-08-14 11:11:25 +00:00
|
|
|
|
|
|
|
/** Returns a random number in the range of [0...n) */
|
2008-09-23 19:11:04 +00:00
|
|
|
int tr_cryptoRandInt( int n );
|
2008-08-14 11:11:25 +00:00
|
|
|
|
2008-08-27 18:50:21 +00:00
|
|
|
/** Returns a vaguely random number in the range of [0...n).
|
|
|
|
This is faster -- BUT WEAKER -- than tr_cryptoRandInt()
|
|
|
|
and should only be used when tr_cryptoRandInt() is too
|
|
|
|
slow, and NEVER in sensitive cases */
|
2008-09-23 19:11:04 +00:00
|
|
|
int tr_cryptoWeakRandInt( int n );
|
2008-08-27 18:50:21 +00:00
|
|
|
|
2008-08-14 11:11:25 +00:00
|
|
|
/** Fills a buffer with random bytes */
|
2009-06-14 14:39:51 +00:00
|
|
|
void tr_cryptoRandBuf( void * buf, size_t len );
|
2008-08-14 11:11:25 +00:00
|
|
|
|
2009-03-24 01:39:06 +00:00
|
|
|
char* tr_ssha1( const void * plaintext );
|
2009-03-17 21:50:20 +00:00
|
|
|
|
2009-03-24 01:39:06 +00:00
|
|
|
tr_bool tr_ssha1_matches( const char * source, const char * pass );
|
2009-03-17 21:50:20 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/* @} */
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
#endif
|