Vidalia 0.3.1
crypto.h
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If you
4** did not receive the LICENSE file with this file, you may obtain it from the
5** Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9**
10** * * *
11**
12** Pseudorandom number generation support in this file is derived from
13** Tor's crypto.[ch]. Tor is distributed under this license.
14**
15** Copyright (c) 2001-2004, Roger Dingledine
16** Copyright (c) 2004-2007, Roger Dingledine, Nick Mathewson
17**
18** Redistribution and use in source and binary forms, with or without
19** modification, are permitted provided that the following conditions are
20** met:
21**
22** * Redistributions of source code must retain the above copyright
23** notice, this list of conditions and the following disclaimer.
24**
25** * Redistributions in binary form must reproduce the above
26** copyright notice, this list of conditions and the following disclaimer
27** in the documentation and/or other materials provided with the
28** distribution.
29**
30** * Neither the names of the copyright owners nor the names of its
31** contributors may be used to endorse or promote products derived from
32** this software without specific prior written permission.
33**
34** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45*/
46
47/*
48** \file crypto.h
49** \brief Provides support for pseuodrandom number generation.
50*/
51
52#ifndef _CRYPTO_H
53#define _CRYPTO_H
54
55#include <QByteArray>
56#include <QString>
57
58/** Returns <b>len</b> bytes of pseudorandom data on success, or an empty
59 * QByteArray on failure. This function is based on crypto_seed_rng() from
60 * Tor's crypto.c. See LICENSE for details on Tor's license. */
61QByteArray crypto_rand_bytes(int len);
62/** Returns a pseudorandom integer, chosen uniformly from the the values in
63 * the range [0, max). This function is based on crypto_rand_int() from Tor's
64 * crypto.c. See LICENSE for details on Tor's license. */
66/** Generates a pseudorandom string of length <b>len</b> containing printable
67 * ASCII characters from the range '!' (0x21) to '~' (0x7e). */
68QString crypto_rand_string(int len);
69/** Generates a salted hash of <b>secret</b> using the random <b>salt</b>
70 * according to the iterated and salted S2K algorithm in RFC 2440. <b>c</b>
71 * is the one-octet coded count value that specifies how much data to hash.
72 * <b>salt</b> must contain at least 8 bytes, otherwise this method will
73 * return a default-constructed QByteArray. */
74QByteArray
75crypto_secret_to_key(const QString &secret, const QByteArray &salt, quint8 c);
76
77#endif
78
quint32 crypto_rand_quint32(quint32 max)
Definition: crypto.cpp:128
QByteArray crypto_secret_to_key(const QString &secret, const QByteArray &salt, quint8 c)
Definition: crypto.cpp:166
QString crypto_rand_string(int len)
Definition: crypto.cpp:150
QByteArray crypto_rand_bytes(int len)
Definition: crypto.cpp:71