2 * This file Copyright (C) 2007-2010 Mnemosyne LLC
4 * This file is licensed by the GPL version 2. Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
10 * $Id: crypto.h 9965 2010-01-19 19:37:00Z charles $
13 #ifndef TR_ENCRYPTION_H
14 #define TR_ENCRYPTION_H
16 #ifndef __TRANSMISSION__
17 #error only libtransmission should #include this header.
22 #include "utils.h" /* TR_GNUC_NULL_TERMINATED */
35 typedef struct tr_crypto tr_crypto
;
37 /** @brief create a new tr_crypto object */
38 tr_crypto
* tr_cryptoNew( const uint8_t * torrentHash
, int isIncoming
);
40 /** @brief destroy an existing tr_crypto object */
41 void tr_cryptoFree( tr_crypto
* crypto
);
44 void tr_cryptoSetTorrentHash( tr_crypto
* crypto
, const uint8_t * torrentHash
);
46 const uint8_t* tr_cryptoGetTorrentHash( const tr_crypto
* crypto
);
48 int tr_cryptoHasTorrentHash( const tr_crypto
* crypto
);
50 const uint8_t* tr_cryptoComputeSecret( tr_crypto
* crypto
,
51 const uint8_t * peerPublicKey
);
53 const uint8_t* tr_cryptoGetMyPublicKey( const tr_crypto
* crypto
,
56 void tr_cryptoDecryptInit( tr_crypto
* crypto
);
58 void tr_cryptoDecrypt( tr_crypto
* crypto
,
63 void tr_cryptoEncryptInit( tr_crypto
* crypto
);
65 void tr_cryptoEncrypt( tr_crypto
* crypto
,
73 *** @addtogroup utils Utilities
78 /** @brief generate a SHA1 hash from one or more chunks of memory */
79 void tr_sha1( uint8_t * setme
,
80 const void * content1
,
82 ... ) TR_GNUC_NULL_TERMINATED
;
85 /** @brief returns a random number in the range of [0...n) */
86 int tr_cryptoRandInt( int n
);
89 * @brief returns a pseudorandom number in the range of [0...n)
91 * This is faster, BUT WEAKER, than tr_cryptoRandInt() and never
92 * be used in sensitive cases.
93 * @see tr_cryptoRandInt()
95 int tr_cryptoWeakRandInt( int n
);
97 /** @brief fill a buffer with random bytes */
98 void tr_cryptoRandBuf( void * buf
, size_t len
);
100 /** @brief generate a SSHA password from its plaintext source */
101 char* tr_ssha1( const void * plaintext
);
103 /** @brief Validate a test password against the a ssha1 password */
104 tr_bool
tr_ssha1_matches( const char * ssha1
, const char * pass
);