source: trunk/libtransmission/crypto.h @ 8080

Last change on this file since 8080 was 8080, checked in by jhujhiti, 13 years ago

(trunk libT) #1276 - hash rpc password with sha1

  • 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 8080 2009-03-24 01:39:06Z jhujhiti $
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;
29typedef struct tr_crypto tr_crypto;
30
31/**
32***
33**/
34
35tr_crypto*     tr_cryptoNew( const uint8_t * torrentHash,
36                             int             isIncoming );
37
38void           tr_cryptoFree( tr_crypto * crypto );
39
40/**
41***
42**/
43
44void           tr_cryptoSetTorrentHash( tr_crypto *     crypto,
45                                        const uint8_t * torrentHash );
46
47const uint8_t* tr_cryptoGetTorrentHash( const tr_crypto * crypto );
48
49int            tr_cryptoHasTorrentHash( const tr_crypto * crypto );
50
51/**
52***
53**/
54
55const uint8_t* tr_cryptoComputeSecret( tr_crypto *     crypto,
56                                       const uint8_t * peerPublicKey );
57
58const uint8_t* tr_cryptoGetMyPublicKey( const tr_crypto * crypto,
59                                        int *             setme_len );
60
61void           tr_cryptoDecryptInit( tr_crypto * crypto );
62
63void           tr_cryptoDecrypt( tr_crypto *  crypto,
64                                 size_t       buflen,
65                                 const void * buf_in,
66                                 void *       buf_out );
67
68/**
69***
70**/
71
72void           tr_cryptoEncryptInit( tr_crypto * crypto );
73
74void           tr_cryptoEncrypt( tr_crypto *  crypto,
75                                 size_t       buflen,
76                                 const void * buf_in,
77                                 void *       buf_out );
78
79void           tr_sha1( uint8_t *    setme,
80                        const void * content1,
81                        int          content1_len,
82                        ... ) TR_GNUC_NULL_TERMINATED;
83
84
85/** Returns a random number in the range of [0...n) */
86int            tr_cryptoRandInt( int n );
87
88/** Returns a vaguely random number in the range of [0...n).
89    This is faster -- BUT WEAKER -- than tr_cryptoRandInt()
90    and should only be used when tr_cryptoRandInt() is too
91    slow, and NEVER in sensitive cases */
92int            tr_cryptoWeakRandInt( int n );
93
94/** Fills a buffer with random bytes */
95void           tr_cryptoRandBuf( unsigned char *buf,
96                                 size_t         len );
97
98char*          tr_ssha1( const void * plaintext );
99
100tr_bool        tr_ssha1_matches( const char * source, const char * pass );
101
102#endif
Note: See TracBrowser for help on using the repository browser.