source: trunk/libtransmission/crypto.h @ 8903

Last change on this file since 8903 was 8903, checked in by charles, 12 years ago

(trunk) all this commit does is remove trailing whitespace from some c, c++, and javascript source

  • Property svn:keywords set to Date Rev Author Id
File size: 2.8 KB
Line 
1/*
2 * This file Copyright (C) 2007-2009 Charles Kerr <charles@transmissionbt.com>
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 8903 2009-08-12 14:40:32Z charles $
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***
26**/
27
28struct evbuffer;
29
30/**
31 * @addtogroup utils Utilities
32 * @{
33 */
34
35typedef struct tr_crypto tr_crypto;
36
37/**
38***
39**/
40
41tr_crypto*     tr_cryptoNew( const uint8_t * torrentHash,
42                             int             isIncoming );
43
44void           tr_cryptoFree( tr_crypto * crypto );
45
46/**
47***
48**/
49
50void           tr_cryptoSetTorrentHash( tr_crypto *     crypto,
51                                        const uint8_t * torrentHash );
52
53const uint8_t* tr_cryptoGetTorrentHash( const tr_crypto * crypto );
54
55int            tr_cryptoHasTorrentHash( const tr_crypto * crypto );
56
57/**
58***
59**/
60
61const uint8_t* tr_cryptoComputeSecret( tr_crypto *     crypto,
62                                       const uint8_t * peerPublicKey );
63
64const uint8_t* tr_cryptoGetMyPublicKey( const tr_crypto * crypto,
65                                        int *             setme_len );
66
67void           tr_cryptoDecryptInit( tr_crypto * crypto );
68
69void           tr_cryptoDecrypt( tr_crypto *  crypto,
70                                 size_t       buflen,
71                                 const void * buf_in,
72                                 void *       buf_out );
73
74/**
75***
76**/
77
78void           tr_cryptoEncryptInit( tr_crypto * crypto );
79
80void           tr_cryptoEncrypt( tr_crypto *  crypto,
81                                 size_t       buflen,
82                                 const void * buf_in,
83                                 void *       buf_out );
84
85void           tr_sha1( uint8_t *    setme,
86                        const void * content1,
87                        int          content1_len,
88                        ... ) TR_GNUC_NULL_TERMINATED;
89
90
91/** Returns a random number in the range of [0...n) */
92int            tr_cryptoRandInt( int n );
93
94/** Returns a vaguely random number in the range of [0...n).
95    This is faster -- BUT WEAKER -- than tr_cryptoRandInt()
96    and should only be used when tr_cryptoRandInt() is too
97    slow, and NEVER in sensitive cases */
98int            tr_cryptoWeakRandInt( int n );
99
100/** Fills a buffer with random bytes */
101void           tr_cryptoRandBuf( void * buf, size_t len );
102
103char*          tr_ssha1( const void * plaintext );
104
105tr_bool        tr_ssha1_matches( const char * source, const char * pass );
106
107/* @} */
108
109#endif
Note: See TracBrowser for help on using the repository browser.