source: trunk/libtransmission/crypto.h @ 12226

Last change on this file since 12226 was 12226, checked in by jordan, 11 years ago

(trunk libT) copyediting: '#include "crypto.h"' cleanup

  • Property svn:keywords set to Date Rev Author Id
File size: 2.8 KB
Line 
1/*
2 * This file Copyright (C) Mnemosyne LLC
3 *
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.
9 *
10 * $Id: crypto.h 12226 2011-03-25 01:21:31Z jordan $
11 */
12
13#ifndef TR_ENCRYPTION_H
14#define TR_ENCRYPTION_H
15
16#ifndef __TRANSMISSION__
17#error only libtransmission should #include this header.
18#endif
19
20#include <inttypes.h>
21
22#include "utils.h" /* TR_GNUC_NULL_TERMINATED */
23
24/**
25*** @addtogroup peers
26*** @{
27**/
28
29typedef struct tr_crypto tr_crypto;
30
31/** @brief create a new tr_crypto object */
32tr_crypto*  tr_cryptoNew( const uint8_t * torrentHash, int isIncoming );
33
34/** @brief destroy an existing tr_crypto object */
35void           tr_cryptoFree( tr_crypto * crypto );
36
37
38void tr_cryptoSetTorrentHash( tr_crypto * crypto, const uint8_t * torrentHash );
39
40const uint8_t* tr_cryptoGetTorrentHash( const tr_crypto * crypto );
41
42int            tr_cryptoHasTorrentHash( const tr_crypto * crypto );
43
44const uint8_t* tr_cryptoComputeSecret( tr_crypto *     crypto,
45                                       const uint8_t * peerPublicKey );
46
47const uint8_t* tr_cryptoGetMyPublicKey( const tr_crypto * crypto,
48                                        int *             setme_len );
49
50void           tr_cryptoDecryptInit( tr_crypto * crypto );
51
52void           tr_cryptoDecrypt( tr_crypto *  crypto,
53                                 size_t       buflen,
54                                 const void * buf_in,
55                                 void *       buf_out );
56
57void           tr_cryptoEncryptInit( tr_crypto * crypto );
58
59void           tr_cryptoEncrypt( tr_crypto *  crypto,
60                                 size_t       buflen,
61                                 const void * buf_in,
62                                 void *       buf_out );
63
64/* @} */
65
66/**
67*** @addtogroup utils Utilities
68*** @{
69**/
70
71
72/** @brief generate a SHA1 hash from one or more chunks of memory */
73void tr_sha1( uint8_t    * setme,
74              const void * content1,
75              int          content1_len,
76              ... ) TR_GNUC_NULL_TERMINATED;
77
78
79/** @brief returns a random number in the range of [0...n) */
80int tr_cryptoRandInt( int n );
81
82/**
83 * @brief returns a pseudorandom number in the range of [0...n)
84 *
85 * This is faster, BUT WEAKER, than tr_cryptoRandInt() and never
86 * be used in sensitive cases.
87 * @see tr_cryptoRandInt()
88 */
89int            tr_cryptoWeakRandInt( int n );
90
91/** @brief fill a buffer with random bytes */
92void  tr_cryptoRandBuf( void * buf, size_t len );
93
94/** @brief generate a SSHA password from its plaintext source */
95char*  tr_ssha1( const void * plaintext );
96
97/** @brief Validate a test password against the a ssha1 password */
98bool tr_ssha1_matches( const char * ssha1, const char * pass );
99
100/* @} */
101
102#endif
Note: See TracBrowser for help on using the repository browser.