Vidalia 0.2.12

crypto.h

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 ** 
00010 **                     *       *       *
00011 ** 
00012 **  Pseudorandom number generation support in this file is derived from
00013 **  Tor's crypto.[ch]. Tor is distributed under this license.
00014 ** 
00015 **    Copyright (c) 2001-2004, Roger Dingledine
00016 **    Copyright (c) 2004-2007, Roger Dingledine, Nick Mathewson
00017 **
00018 **   Redistribution and use in source and binary forms, with or without
00019 **   modification, are permitted provided that the following conditions are
00020 **   met:
00021 **
00022 **     * Redistributions of source code must retain the above copyright
00023 **       notice, this list of conditions and the following disclaimer.
00024 **
00025 **     * Redistributions in binary form must reproduce the above
00026 **       copyright notice, this list of conditions and the following disclaimer
00027 **       in the documentation and/or other materials provided with the
00028 **       distribution.
00029 ** 
00030 **     * Neither the names of the copyright owners nor the names of its
00031 **       contributors may be used to endorse or promote products derived from
00032 **       this software without specific prior written permission.
00033 **
00034 **    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00035 **    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00036 **    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00037 **    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00038 **    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00039 **    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00040 **    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00041 **    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00042 **    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00043 **    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00044 **    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00045 */
00046 
00047 /*
00048 ** \file crypto.h
00049 ** \brief Provides support for pseuodrandom number generation.
00050 */
00051 
00052 #ifndef _CRYPTO_H
00053 #define _CRYPTO_H
00054 
00055 #include <QByteArray>
00056 #include <QString>
00057 
00058 /** Returns <b>len</b> bytes of pseudorandom data on success, or an empty
00059  * QByteArray on failure. This function is based on crypto_seed_rng() from
00060  * Tor's crypto.c. See LICENSE for details on Tor's license. */
00061 QByteArray crypto_rand_bytes(int len);
00062 /** Returns a pseudorandom integer, chosen uniformly from the the values in
00063  * the range [0, max). This function is based on crypto_rand_int() from Tor's
00064  * crypto.c. See LICENSE for details on Tor's license. */
00065 quint32 crypto_rand_quint32(quint32 max);
00066 /** Generates a pseudorandom string of length <b>len</b> containing printable
00067  * ASCII characters from the range '!' (0x21) to '~' (0x7e). */
00068 QString crypto_rand_string(int len);
00069 /** Generates a salted hash of <b>secret</b> using the random <b>salt</b>
00070  * according to the iterated and salted S2K algorithm in RFC 2440. <b>c</b>
00071  * is the one-octet coded count value that specifies how much data to hash. 
00072  * <b>salt</b> must contain at least 8 bytes, otherwise this method will
00073  * return a default-constructed QByteArray. */
00074 QByteArray 
00075 crypto_secret_to_key(const QString &secret, const QByteArray &salt, quint8 c);
00076 
00077 #endif
00078