~keepassx/keepassx/trunk

« back to all changes in this revision

Viewing changes to src/crypto/Random.cpp

  • Committer: Felix Geyer
  • Date: 2010-09-11 17:49:30 UTC
  • Revision ID: git-v1:6a2034fa248385d1d1637d4c3444045e50e0c5f5
Add crypto classes and tests. Link to libgcrypt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
 
3
 *
 
4
 *  This program is free software: you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation, either version 2 or (at your option)
 
7
 *  version 3 of the License.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU General Public License for more details.
 
13
 *
 
14
 *  You should have received a copy of the GNU General Public License
 
15
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 */
 
17
 
 
18
#include "Random.h"
 
19
 
 
20
#include <gcrypt.h>
 
21
 
 
22
void Random::randomize(QByteArray& ba)
 
23
{
 
24
    gcry_randomize(ba.data(), ba.size(), GCRY_STRONG_RANDOM);
 
25
}
 
26
 
 
27
QByteArray Random::randomArray(int len)
 
28
{
 
29
    QByteArray ba;
 
30
    ba.resize(len);
 
31
 
 
32
    randomize(ba);
 
33
 
 
34
    return ba;
 
35
}
 
36
 
 
37
Random::Random()
 
38
{
 
39
}