[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdesupport/qca
From:       Brad Hards <bradh () frogmouth ! net>
Date:       2007-01-05 5:22:37
Message-ID: 1167974557.764681.25938.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 620048 by bhards:

Remove the Quality enum from the Random capability, as
discussed with Justin.

It was only really supported by the Botan provider, and
Botan dropped the idea in 1.6.0. Also, it never ensured
that the random number was actually secure.


 M  +4 -12     examples/randomtest/randomtest.cpp  
 M  +5 -37     include/QtCrypto/qca_basic.h  
 M  +1 -1      include/QtCrypto/qcaprovider.h  
 M  +2 -21     plugins/qca-botan/qca-botan.cpp  
 M  +11 -11    src/qca_basic.cpp  
 M  +2 -2      src/qca_core.cpp  
 M  +1 -1      src/qca_default.cpp  
 M  +1 -12     unittest/randomunittest/randomunittest.cpp  


--- trunk/kdesupport/qca/examples/randomtest/randomtest.cpp #620047:620048
@@ -7,10 +7,10 @@
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
- 
+
  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.
- 
+
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
@@ -30,7 +30,7 @@
 
 	qDebug() << "This example generates random numbers";
 
-	// the Initializer object sets things up, and 
+	// the Initializer object sets things up, and
 	// also does cleanup when it goes out of scope
 	QCA::Initializer init;
 
@@ -39,12 +39,6 @@
 	randInt = QCA::Random::randomInt();
 	qDebug() << "A random number: " << randInt;
 
-	// If this was going to be a really important random
-	// number, you migth want to ask for higher Quality:
-	randInt = QCA::Random::randomInt(QCA::Random::LongTermKey);
-	// or if this was just a junk value, you could use:
-	randInt = QCA::Random::randomInt(QCA::Random::Nonce);
-
 	// If you wanted a random character (octet), you could
 	// use something like:
 	unsigned char randChar;
@@ -56,8 +50,6 @@
 	// If you need more random values, you may want to
 	// get an array, as shown below.
 	tenBytes = QCA::Random::randomArray(10);
-	// You can still use Quality settings, as shown below
-	tenBytes = QCA::Random::randomArray(10, QCA::Random::Nonce);
 
 	// To make this viewable, we convert to hexadecimal.
 	std::cout << "A random 10 byte array (in hex): ";
@@ -68,7 +60,7 @@
 	// This isn't normally the easiest way, but it does work
 	QCA::Random myRandomObject;
 	randChar = myRandomObject.nextByte();
-	tenBytes = myRandomObject.nextBytes(10, QCA::Random::Nonce);
+	tenBytes = myRandomObject.nextBytes(10);
 	return 0;
 }
 
--- trunk/kdesupport/qca/include/QtCrypto/qca_basic.h #620047:620048
@@ -46,13 +46,6 @@
 	   an alternative random number source, by implementing
 	   another provider.
 	 
-	   You can select the "quality" of the random numbers. For 
-	   best results, you should use Nonce or PublicValue for values
-	   that are likely to become public, and SessionKey or LongTermKey
-	   for those values that are more critical. All that said, please
-	   note that this is only a hint to the provider - it may make
-	   no difference at all.
-	 
 	   The normal use of this class is expected to be through the
 	   static members - randomChar(), randomInt() and randomArray().
 	 */
@@ -60,18 +53,6 @@
 	{
 	public:
 		/**
-		 * How much entropy to use for the random numbers that
-		 * are required.
-		 */
-		enum Quality
-		{
-			Nonce,      ///< Low quality, will become public
-			PublicValue,///< Will become public
-			SessionKey, ///< Intended to remain private
-			LongTermKey ///< Best available quality
-		};
-
-		/**
 		 * Standard Constructor
 		 *
 		 * \param provider the provider library for the random
@@ -84,12 +65,10 @@
 		 *
 		 * This method isn't normally required - you should use
 		 * the static randomChar() method instead.
-		 * 
-		 * \param q the quality of the random byte that is required
 		 *
 		 * \sa randomChar
 		 */
-		uchar nextByte(Quality q = SessionKey);
+		uchar nextByte();
 
 		/**
 		 * Provide a specified number of random bytes
@@ -98,11 +77,10 @@
 		 * the static randomArray() method instead.
 		 *
 		 * \param size the number of bytes to provide
-		 * \param q the quality of the random bytes that are required
 		 *
 		 * \sa randomArray
 		 */
-		QSecureArray nextBytes(int size, Quality q = SessionKey);
+		QSecureArray nextBytes(int size);
 
 		/**
 		 * Provide a random character (byte)
@@ -112,12 +90,10 @@
 		 * \code
 		 * myRandomChar = QCA::Random::randomChar();
 		 * \endcode
-		 * 
-		 * \param q the quality of the random character that is required
 		 *
 		 * If you need a number of bytes, perhaps randomArray() may be of use
 		 */
-		static uchar randomChar(Quality q = SessionKey);
+		static uchar randomChar();
 
 		/**
 		 * Provide a random integer
@@ -125,15 +101,10 @@
 		 * This is the normal way of obtaining a single random integer,
 		 * as shown below:
 		 * \code
-		 * // default quality
 		 * myRandomInt = QCA::Random::randomInt();
-		 * // cheap integer
-		 * myCheapInt = QCA::Random::randomInt( QCA::Random::Nonce );
 		 * \endcode
-		 *
-		 * \param q the quality of the random integer that is required
 		 */
-		static uint randomInt(Quality q = SessionKey);
+		static uint randomInt();
 
 		/**
 		 * Provide a specified number of random bytes
@@ -141,14 +112,11 @@
 		 * \code
 		 * // build a 30 byte secure array.
 		 * QSecureArray arry = QCA::Random::randomArray(30);
-		 * // take 20 bytes, as high a quality as we can get
-		 * QSecureArray newKey = QCA::Random::randomArray(20, QCA::Random::LongTermKey);
 		 * \endcode
 		 *
 		 * \param size the number of bytes to provide
-		 * \param q the quality of the random bytes that are required
 		 */
-		static QSecureArray randomArray(int size, Quality q = SessionKey);
+		static QSecureArray randomArray(int size);
 	};
 
 	/**
--- trunk/kdesupport/qca/include/QtCrypto/qcaprovider.h #620047:620048
@@ -49,7 +49,7 @@
 	Q_OBJECT
 public:
 	RandomContext(Provider *p) : BasicContext(p, "random") {}
-	virtual QSecureArray nextBytes(int size, Random::Quality q) = 0;
+	virtual QSecureArray nextBytes(int size) = 0;
 };
 
 class QCA_EXPORT HashContext : public BasicContext
--- trunk/kdesupport/qca/plugins/qca-botan/qca-botan.cpp #620047:620048
@@ -42,35 +42,16 @@
 	return new botanRandomContext( *this );
     }
 
-    QSecureArray nextBytes(int size, QCA::Random::Quality quality)
+    QSecureArray nextBytes(int size)
     {
 	QSecureArray buf(size);
 #if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,5,0)
-	Botan::Global_RNG::randomize( (Botan::byte*)buf.data(), buf.size(), \
lookup_quality(quality) ); +	Botan::Global_RNG::randomize( (Botan::byte*)buf.data(), \
buf.size(), Botan::SessionKey );  #else
 	Botan::Global_RNG::randomize( (Botan::byte*)buf.data(), buf.size() );
 #endif
 	return buf;
     }
-
-private:
-#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,5,0)
-    Botan::RNG_Quality lookup_quality( QCA::Random::Quality quality )
-    {
-	if ( QCA::Random::Nonce == quality )
-	    return Botan::Nonce;
-	else if ( QCA::Random::PublicValue == quality )
-	    return Botan::PublicValue;
-	else if ( QCA::Random::SessionKey == quality )
-	    return Botan::SessionKey;
-	else if ( QCA::Random::LongTermKey == quality )
-	    return Botan::LongTermKey;
-	else
-	    // this can't happen, but insurance against an accidental
-	    // addition of a value to the enum
-	    return Botan::SessionKey;
-    }
-#endif
 };
 
 
--- trunk/kdesupport/qca/src/qca_basic.cpp #620047:620048
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2003-2005  Justin Karneges <justin@affinix.com>
- * Copyright (C) 2004,2005  Brad Hards <bradh@frogmouth.net>
+ * Copyright (C) 2004,2005,2007  Brad Hards <bradh@frogmouth.net>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -33,32 +33,32 @@
 {
 }
 
-uchar Random::nextByte(Quality q)
+uchar Random::nextByte()
 {
-	return (uchar)(nextBytes(1, q)[0]);
+	return (uchar)(nextBytes(1)[0]);
 }
 
-QSecureArray Random::nextBytes(int size, Quality q)
+QSecureArray Random::nextBytes(int size)
 {
-	return static_cast<RandomContext *>(context())->nextBytes(size, q);
+	return static_cast<RandomContext *>(context())->nextBytes(size);
 }
 
-uchar Random::randomChar(Quality q)
+uchar Random::randomChar()
 {
-	return globalRNG().nextByte(q);
+	return globalRNG().nextByte();
 }
 
-uint Random::randomInt(Quality q)
+uint Random::randomInt()
 {
-	QSecureArray a = globalRNG().nextBytes(sizeof(int), q);
+	QSecureArray a = globalRNG().nextBytes(sizeof(int));
 	uint x;
 	memcpy(&x, a.data(), a.size());
 	return x;
 }
 
-QSecureArray Random::randomArray(int size, Quality q)
+QSecureArray Random::randomArray(int size)
 {
-	return globalRNG().nextBytes(size, q);
+	return globalRNG().nextBytes(size);
 }
 
 //----------------------------------------------------------------------------
--- trunk/kdesupport/qca/src/qca_core.cpp #620047:620048
@@ -1042,7 +1042,7 @@
 
 SymmetricKey::SymmetricKey(int size)
 {
-	set(globalRNG().nextBytes(size, Random::SessionKey));
+	set(globalRNG().nextBytes(size));
 }
 
 SymmetricKey::SymmetricKey(const QSecureArray &a)
@@ -1150,7 +1150,7 @@
 
 InitializationVector::InitializationVector(int size)
 {
-	set(globalRNG().nextBytes(size, Random::Nonce));
+	set(globalRNG().nextBytes(size));
 }
 
 InitializationVector::InitializationVector(const QSecureArray &a)
--- trunk/kdesupport/qca/src/qca_default.cpp #620047:620048
@@ -44,7 +44,7 @@
 		return new DefaultRandomContext(provider());
 	}
 
-	virtual QSecureArray nextBytes(int size, Random::Quality)
+	virtual QSecureArray nextBytes(int size)
 	{
 		QSecureArray buf(size);
 		for(int n = 0; n < (int)buf.size(); ++n)
--- trunk/kdesupport/qca/unittest/randomunittest/randomunittest.cpp #620047:620048
@@ -86,19 +86,8 @@
 	QCOMPARE( QCA::Random().randomArray(3) == QCA::Random().randomArray(3), false );
 	QCOMPARE( QCA::Random::randomArray(3) == QCA::Random::randomArray(3), false );
 
-	QCOMPARE( randObject.nextByte(QCA::Random::Nonce) == \
                randObject.nextByte(QCA::Random::SessionKey), false );
-	QCOMPARE( QCA::Random().nextByte(QCA::Random::PublicValue) == \
                QCA::Random().nextByte(), false );
-	QCOMPARE( randObject.nextBytes(4) == randObject.nextBytes(4, QCA::Random::Nonce), \
                false );
-	QCOMPARE( randObject.randomChar(QCA::Random::LongTermKey) == \
                randObject.randomChar(), false );
-	QCOMPARE( QCA::Random().randomChar() == \
                QCA::Random().randomChar(QCA::Random::PublicValue), false );
-	QCOMPARE( QCA::Random::randomChar(QCA::Random::PublicValue) == \
                QCA::Random::randomChar(QCA::Random::Nonce), false );
-	QCOMPARE( QCA::Random().randomInt(QCA::Random::Nonce) == QCA::Random().randomInt(), \
                false );
-	QCOMPARE( QCA::Random::randomInt(QCA::Random::Nonce) == \
                QCA::Random::randomInt(QCA::Random::Nonce), false );
-	QCOMPARE( QCA::Random().randomArray(3, QCA::Random::Nonce) == \
                QCA::Random().randomArray(3), false );
-	QCOMPARE( QCA::Random::randomArray(3, QCA::Random::SessionKey) == \
                QCA::Random::randomArray(3, QCA::Random::PublicValue), false );
-
 	for (int len = 1; len <= 1024; len*=2 ) {
-	    QCOMPARE( QCA::globalRNG().nextBytes(len, QCA::Random::SessionKey).size(), len \
); +	    QCOMPARE( QCA::globalRNG().nextBytes(len).size(), len );
 	}
     }
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic