source: trunk/libtransmission/crypto.h @ 12204

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

(trunk) #4138 "use stdbool.h instead of tr_bool" -- done.

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