4
0
mirror of https://github.com/QuasarApp/qca.git synced 2025-05-09 01:09:34 +00:00

Start of big reorganisation of the unit tests.

This now requires QTestLib, as provided with 
Qt 4.1

svn path=/trunk/kdesupport/qca/; revision=478231
This commit is contained in:
Brad Hards 2005-11-06 09:25:56 +00:00
parent 76c875a699
commit 3b58d170b4
26 changed files with 2102 additions and 1571 deletions

@ -1,670 +0,0 @@
//Added by the Qt porting tool:
#include <QTextStream>
/**
* Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "bigintunittest.h"
#include <QtCrypto>
BigIntUnitTest::BigIntUnitTest()
: Tester()
{
}
void BigIntUnitTest::allTests()
{
QCA::Initializer init; // allocates locked memory
QBigInteger result;
// Some string conversion tests
CHECK( QBigInteger("255").toString(), QBigInteger(255).toString() );
CHECK( QBigInteger("-255").toString(), QBigInteger(-255).toString() );
CHECK( QBigInteger("255").toString(), QString("255") );
CHECK( QBigInteger("-255").toString(), QString("-255") );
// Some operator tests
CHECK( QBigInteger("255") == QBigInteger(255), true );
CHECK( QBigInteger("-255") == QBigInteger(-255), true );
CHECK( QBigInteger("256") != QBigInteger(255), true );
CHECK( QBigInteger("-256") != QBigInteger(-255), true );
// Some comparison tests
QBigInteger a( "4000000000000" );
QBigInteger b( "-4000000000000" );
QBigInteger c( "2000000000000" );
CHECK( a < b, false );
CHECK( a <= b, false );
CHECK( a.compare(b), 1 );
CHECK( a > b, true );
CHECK( a >= b, true );
CHECK( a > c, true );
CHECK( c.compare(b), 1 );
CHECK( c.compare(a), -1 );
// Check if the stream operator is any good
QString testString;
QTextStream ts( &testString, QIODevice::WriteOnly);
ts << a << b << c << endl;
CHECK( testString, QString( "4000000000000-40000000000002000000000000\n") );
// Botan's addition tests
CHECK( QBigInteger( 255 ) += QBigInteger ( 1 ), QBigInteger( 256 ) );
result = QBigInteger( 255 ) += QBigInteger( 1 );
CHECK( result.toString(), QBigInteger( 256 ).toString() );
result = QBigInteger( "65535" ) += QBigInteger( "1" );
CHECK( result.toString(), QString( "65536" ) );
CHECK( result, QBigInteger( "65536") );
result = QBigInteger( "4294967295" ) += QBigInteger( 1 );
CHECK( result.toString(), QString( "4294967296" ) );
CHECK( result, QBigInteger( "4294967296" ) );
result = QBigInteger( "18446744073709551615" ) += QBigInteger( 1 );
CHECK( result.toString(), QString( "18446744073709551616" ) );
CHECK( result, QBigInteger( "18446744073709551616" ) );
result = QBigInteger( "124536363637272472" ) += QBigInteger( "124536363637272472" );
CHECK( result.toString(), QString ( "249072727274544944" ) );
CHECK( result, QBigInteger ( "249072727274544944" ) );
result = QBigInteger( "9223372036854775807" ) += QBigInteger( "281474976710655" );
CHECK( result.toString(), QString ( "9223653511831486462" ) );
CHECK( result, QBigInteger ( "9223653511831486462" ) );
result = QBigInteger( "9223372036854775807" ) += QBigInteger( "137438953471" );
CHECK( result.toString(), QString( "9223372174293729278" ) );
CHECK( result, QBigInteger( "9223372174293729278" ) );
// Botan's carry tests
result = QBigInteger( "340282366920938463463374607431768211455" )
+= QBigInteger( "340282366920938463463374607431768211455" );
CHECK( result.toString(), QString( "680564733841876926926749214863536422910" ) );
CHECK( result, QBigInteger( "680564733841876926926749214863536422910" ) );
result = QBigInteger( "340282366920938463463374607431768211455" )
+= QBigInteger( "340282366920938463463374607431768211450" );
CHECK( result.toString(), QString( "680564733841876926926749214863536422905" ) );
CHECK( result, QBigInteger( "680564733841876926926749214863536422905" ) );
result = QBigInteger( "115792089237316195423570985008687907853269984665640564039457584007913129639935" )
+= QBigInteger( "115792089237316195423570985008687907853269984665640564039457584007913129639935" );
CHECK( result.toString(), QString( "231584178474632390847141970017375815706539969331281128078915168015826259279870" ) );
CHECK( result, QBigInteger( "231584178474632390847141970017375815706539969331281128078915168015826259279870" ) );
result = QBigInteger( "115792089237316195423570985008687907853269984665640564039457584007913129639935" )
+= QBigInteger( "115792089237316195423570985008687907853269984665640564039457584007913129639919" );
CHECK( result.toString(), QString( "231584178474632390847141970017375815706539969331281128078915168015826259279854") );
CHECK( result, QBigInteger( "231584178474632390847141970017375815706539969331281128078915168015826259279854") );
result = QBigInteger( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095" )
+= QBigInteger( "18446744073709551616" );
CHECK( result.toString(), QString( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946588393177722715635711" ) );
CHECK( result, QBigInteger( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946588393177722715635711" ) );
result = QBigInteger( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095" )
+= QBigInteger( "1" );
CHECK( result.toString(), QString( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096" ) );
CHECK( result, QBigInteger( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096" ) );
result = QBigInteger( "-39794270013919406610834826960427146769766189764838473416502965291920535601112688579198627475284777498059330306128763345008528325994574657552726381901" )
+= QBigInteger( "-342238655038" );
CHECK( result.toString(), QString( "-39794270013919406610834826960427146769766189764838473416502965291920535601112688579198627475284777498059330306128763345008528325994574657894965036939" ) );
CHECK( result, QBigInteger( "-39794270013919406610834826960427146769766189764838473416502965291920535601112688579198627475284777498059330306128763345008528325994574657894965036939" ) );
result = QBigInteger( "25110291853498940831251897922987678157346336093292373576945426289097725034326735312448621015537884914" )
+= QBigInteger( "-36551081154398645734533965739979697527373251608055056627686956281114038842935173436543461" );
CHECK( result.toString(), QString( "25110291853462389750097499277253144191606356395765000325337371232470038078045621273605685842101341453") );
CHECK( result, QBigInteger( "25110291853462389750097499277253144191606356395765000325337371232470038078045621273605685842101341453") );
result = QBigInteger( "27802650352" )
+= QBigInteger( "660736146705288303126411072388564329913778942" );
CHECK( result.toString(), QString( "660736146705288303126411072388564357716429294" ) );
CHECK( result, QBigInteger( "660736146705288303126411072388564357716429294" ) );
result = QBigInteger( "-1348245899955041864800954463709881466231496038216683608715424566397833766910915722793041224478985289" )
+= QBigInteger( "11517149522866182358565152643595266257020228597058539113114732218008332987904361457299261161227276764386173666571334749062651694592291882972" );
CHECK( result.toString(), QString( "11517149522866182358565152643595266257018880351158584071249931263544623106438129961261044477618561339819775832804423833339858653367812897683" ) );
CHECK( result, QBigInteger( "11517149522866182358565152643595266257018880351158584071249931263544623106438129961261044477618561339819775832804423833339858653367812897683" ) );
result = QBigInteger( "-17540530441681616962868251635133601915039026254996886583618243914226325157426408929602625346567256761818" )
+= QBigInteger( "865200427983527245206901810160356641402419461642082623179544681519016990" );
CHECK( result.toString(), QString( "-17540530441681616962868251635132736714611042727751679681808083557584922737964766846979445801885737744828" ) );
CHECK( result, QBigInteger( "-17540530441681616962868251635132736714611042727751679681808083557584922737964766846979445801885737744828" ) );
result = QBigInteger( "128844776074298261556398714096948603458177018275051329218555498374" )
+= QBigInteger( "443816313829150876362052235134610603220548928107697961229953611873695276391917150913346479060246759720475193648" );
CHECK( result.toString(), QString( "443816313829150876362052235134610603220548928236542737304251873430093990488865754371523497335298088939030692022" ) );
CHECK( result, QBigInteger( "443816313829150876362052235134610603220548928236542737304251873430093990488865754371523497335298088939030692022" ) );
result = QBigInteger( "1709484189262457846620911889502097055085989595277300243221975568275935717696463" )
+= QBigInteger( "-1646592344139809206374540620411514484579951199941360" );
CHECK( result.toString(), QString( "1709484189262457846620911887855504710946180388902759622810461083695984517755103" ) );
CHECK( result, QBigInteger( "1709484189262457846620911887855504710946180388902759622810461083695984517755103" ) );
result = QBigInteger( "320175865429637176165709341576187102540180627806418015204928771170233538951323952509055929139673223273528062883083030595199153877335714942842" )
+= QBigInteger( "-2828241696960736089879965882386687935938570856545481227619497640844399275054327390050478930503975773972" );
CHECK( result.toString(), QString( "320175865429637176165709341576187102537352386109457279115048805287846851015385381652510447912053725632683663608028703205148674946831739168870" ) );
CHECK( result, QBigInteger( "320175865429637176165709341576187102537352386109457279115048805287846851015385381652510447912053725632683663608028703205148674946831739168870" ) );
result = QBigInteger( "-4035398360542181725908295312107496142105415014744259439963377204111754181625695349185753326709217" )
+= QBigInteger( "85450213703789913646546187382091037800" );
CHECK( result.toString(), QString( "-4035398360542181725908295312107496142105415014744259439963291753898050391712048802998371235671417" ) );
CHECK( result, QBigInteger( "-4035398360542181725908295312107496142105415014744259439963291753898050391712048802998371235671417" ) );
result = QBigInteger( "-1292166446073479876801522363382357887431657639184151284775525387363973852756087726243671676713861533673009088319851" )
+= QBigInteger( "804538895874518175537499425282375058236245531798590350403343841766955572070643267141945695624895109330242749935754739434394691714971" );
CHECK( result.toString(), QString( "804538895874518174245332979208895181434723168416232462971686202582804287295117879777971842868807383086571073221893205761385603395120" ) );
CHECK( result, QBigInteger( "804538895874518174245332979208895181434723168416232462971686202582804287295117879777971842868807383086571073221893205761385603395120" ) );
result = QBigInteger( "-451986588700926309459451756852005697379481014956007968529234251884946522682901215022086432597024324062240835564200177389" )
+= QBigInteger( "15762983479" );
CHECK( result.toString(), QString( "-451986588700926309459451756852005697379481014956007968529234251884946522682901215022086432597024324062240835548437193910" ) );
CHECK( result, QBigInteger( "-451986588700926309459451756852005697379481014956007968529234251884946522682901215022086432597024324062240835548437193910" ) );
result = QBigInteger( "-3907475412115728816974567022055278374116794025624287474334038831885743634200801846649105209920908153587891040882946582394429615396962188674594744360388466" )
+= QBigInteger( "193893611236537854694879677478106237157079207398283117392998175454362643521031390" );
CHECK( result.toString(), QString( "-3907475412115728816974567022055278374116794025624287474334038831885743634006908235412567355226028476109784803725867374996146498003964013220232100839357076" ) );
CHECK( result, QBigInteger( "-3907475412115728816974567022055278374116794025624287474334038831885743634006908235412567355226028476109784803725867374996146498003964013220232100839357076" ) );
result = QBigInteger( "-72603710637966201224690926289" )
+= QBigInteger( "-13618442642298533261581255034923612640512507150728017106768861506299813289801666559564532" );
CHECK( result.toString(), QString( "-13618442642298533261581255034923612640512507150728017106768934110010451256002891250490821" ) );
CHECK( result, QBigInteger( "-13618442642298533261581255034923612640512507150728017106768934110010451256002891250490821" ) );
result = QBigInteger( "56077960835713056831402948406790747107889446769357509759472207603483968107693997028111823994257399379783658853302692762256851623103019589392739" )
+= QBigInteger( "-427057313888431079237360487703561848638868677065083968842" );
CHECK( result.toString(), QString( "56077960835713056831402948406790747107889446769357509759472207603483968107693997028111396936943510948704421492814989200408212754425954505423897" ) );
CHECK( result, QBigInteger( "56077960835713056831402948406790747107889446769357509759472207603483968107693997028111396936943510948704421492814989200408212754425954505423897" ) );
result = QBigInteger( "-2209800838508504443494783762534800337712101405156784708782197580824527899758308" )
+= QBigInteger( "42844076503039495864500213925837598507817708418354152774112078596443089606598570396235816327987463393971710495985285591895096794994387176281079" );
CHECK( result.toString(), QString( "42844076503039495864500213925837598507817708418354152774112078594233288768090065952741032565452663056259609090828500883112899214169859276522771" ) );
CHECK( result, QBigInteger( "42844076503039495864500213925837598507817708418354152774112078594233288768090065952741032565452663056259609090828500883112899214169859276522771" ) );
result = QBigInteger( "33887767308809826842417841176152232321272231788338404526859019370507113927387984766381329515371768224976188337692" )
+= QBigInteger( "349484339542971517481628970179002500341" );
CHECK( result.toString(), QString( "33887767308809826842417841176152232321272231788338404526859019370507113927737469105924301032853397195155190838033" ) );
CHECK( result, QBigInteger( "33887767308809826842417841176152232321272231788338404526859019370507113927737469105924301032853397195155190838033" ) );
result = QBigInteger( "85748089639858660722587321621536298082690707526412426951630101551228144063151688592419555048867068162" )
+= QBigInteger( "-383634567691961960211191292397062452265352651123492760493087381707279" );
CHECK( result.toString(), QString( "85748089639858660722587321621535914448123015564452215760337704488775878710500565099659061961485360883" ) );
CHECK( result, QBigInteger( "85748089639858660722587321621535914448123015564452215760337704488775878710500565099659061961485360883" ) );
result = QBigInteger( "23889807888563742283608049816129153552608399262924421832404872043475" )
+= QBigInteger( "995" );
CHECK( result.toString(), QString( "23889807888563742283608049816129153552608399262924421832404872044470" ) );
CHECK( result, QBigInteger( "23889807888563742283608049816129153552608399262924421832404872044470" ) );
result = QBigInteger( "-654786925833474864669230962582694222611472680701859262466465606239654996048306783957549697781271829257774329538985" )
+= QBigInteger( "-276137507159648540503039013089014674747" );
CHECK( result.toString(), QString( "-654786925833474864669230962582694222611472680701859262466465606239654996048582921464709346321774868270863344213732" ) );
CHECK( result, QBigInteger( "-654786925833474864669230962582694222611472680701859262466465606239654996048582921464709346321774868270863344213732" ) );
result = QBigInteger( "50463316268089933" )
+= QBigInteger( "-140591583463431806921000349498135287589005423318927850947894242995310138569473157521312413652439234324419130527702899917161307657443381774866237429" );
CHECK( result.toString(), QString( "-140591583463431806921000349498135287589005423318927850947894242995310138569473157521312413652439234324419130527702899917161307657392918458598147496" ) );
CHECK( result, QBigInteger( "-140591583463431806921000349498135287589005423318927850947894242995310138569473157521312413652439234324419130527702899917161307657392918458598147496" ) );
result = QBigInteger( "1339015021665554488163337105187026760232395594198925052890859936\
418304234254229440059229155546157793544192" )
+= QBigInteger( "6294037420283433712414743361937677483761554699961644450461297486224793278823004487175687771163597590566132592591599249970281125781761944353272" );
CHECK( result.toString(), QString( "6294037420283433712414743361937677485100569721627198938624634591411820039055400081374612824054457526984436826845828690029510281327919737897464" ) );
CHECK( result, QBigInteger( "6294037420283433712414743361937677485100569721627198938624634591411820039055400081374612824054457526984436826845828690029510281327919737897464" ) );
result = QBigInteger( "-241446683" )
+= QBigInteger( "-282671163032866994488211995758272717472259277760825940523445628\
442206062910449311538519756165635175664610569214430918184214" );
CHECK( result.toString(), QString( "-282671163032866994488211995758272717472259277760825940523445628442206062910449311538519756165635175664610569214431159630897" ) );
CHECK( result, QBigInteger( "-282671163032866994488211995758272717472259277760825940523445628442206062910449311538519756165635175664610569214431159630897" ) );
result = QBigInteger( "2358605503303452637996081421902056515951744611718383128442445119505739707550326378912342448355046239066896995563581" )
+= QBigInteger( "-3830437229145325165273364525551261440648845791949681661260946956860463720730123941973615" );
CHECK( result.toString(), QString( "2358605503303452637996081418071619286806419446445018602891183678856893915600644717651395491494582518336773053589966" ) );
CHECK( result, QBigInteger( "2358605503303452637996081418071619286806419446445018602891183678856893915600644717651395491494582518336773053589966" ) );
result = QBigInteger( "1860794367587960058388097846258490" )
+= QBigInteger( "-237344494507203983863096991896035366478949095337787603280" );
CHECK( result.toString(), QString( "-237344494507203983863095131101667778518890707239941344790" ) );
CHECK( result, QBigInteger( "-237344494507203983863095131101667778518890707239941344790" ) );
result = QBigInteger( "-286399096802321907543674770412181810379003627366516307780436082546" )
+= QBigInteger( "6433131620680089024037442172197761714707480582555136398379812339597187475099646442833150194" );
CHECK( result.toString(), QString( "6433131620680089024037441885798664912385573038880365986198001960593560108583338662397067648" ) );
CHECK( result, QBigInteger( "6433131620680089024037441885798664912385573038880365986198001960593560108583338662397067648" ) );
result = QBigInteger( "181180339077102369559537817583627894783322804181859729574752442572146800569023773490164987520541203125338295785763244283224569259250011493" )
+= QBigInteger( "-1199127665773503170250307078028035875479459397657178356959526245067549497129923023348187933280753018204983010837846725666878521137637491" );
CHECK( result.toString(), QString( "179981211411328866389287510505599858907843344784202551217792916327079251071893850466816799587260450107133312774925397557557690738112374002" ) );
CHECK( result, QBigInteger( "179981211411328866389287510505599858907843344784202551217792916327079251071893850466816799587260450107133312774925397557557690738112374002" ) );
result = QBigInteger( "-64140201395555533811408642891620184652051275811075926176282032144915585503450776768366775652419022149512034611311149858695307750874152" )
+= QBigInteger( "174441039" );
CHECK( result.toString(), QString( "-64140201395555533811408642891620184652051275811075926176282032144915585503450776768366775652419022149512034611311149858695307576433113" ) );
CHECK( result, QBigInteger( "-64140201395555533811408642891620184652051275811075926176282032144915585503450776768366775652419022149512034611311149858695307576433113" ) );
result = QBigInteger( "1272757944308835857208037878018507337530557445422230495561634616503724419877512717512360239259640193513601352202821462208896049331599624285621" )
+= QBigInteger( "7326562354017884140300121264633612334070903165496641915889499701\
38457507491850467631029977010" );
CHECK( result.toString(), QString( "1272757944308835857208037878018507337530557445422963151797036404917754432003976078745767329576189857705190302172959919716387899799230654262631" ) );
CHECK( result, QBigInteger( "1272757944308835857208037878018507337530557445422963151797036404917754432003976078745767329576189857705190302172959919716387899799230654262631" ) );
result = QBigInteger( "-296171972628230" )
+= QBigInteger( "-8295766099121843219000823699362222865173820102569731517716391727126741710202086962877467940292139" );
CHECK( result.toString(), QString( "-8295766099121843219000823699362222865173820102569731517716391727126741710202086963173639912920369" ) );
CHECK( result, QBigInteger( "-8295766099121843219000823699362222865173820102569731517716391727126741710202086963173639912920369" ) );
result = QBigInteger( "746985914068199510024843682108839444828414222769191520615967632362127522466922882591" )
+= QBigInteger( "-20487191102299831461877807785745372724903547246374023" );
CHECK( result.toString(), QString( "746985914068199510024843682108818957637311922937729642808181886989402618919676508568" ) );
CHECK( result, QBigInteger( "746985914068199510024843682108818957637311922937729642808181886989402618919676508568" ) );
result = QBigInteger( "-4" )
+= QBigInteger( "-2344390090753264806043234960981151613122271366762590006930318876906455201397017135" );
CHECK( result.toString(), QString( "-2344390090753264806043234960981151613122271366762590006930318876906455201397017139" ) );
CHECK( result, QBigInteger( "-2344390090753264806043234960981151613122271366762590006930318876906455201397017139" ) );
result = QBigInteger( "-44876180273995737337769331875058141129678736711749946388832275767882143882764" )
+= QBigInteger( "20982187786" );
CHECK( result.toString(), QString( "-44876180273995737337769331875058141129678736711749946388832275767861161694978" ) );
CHECK( result, QBigInteger( "-44876180273995737337769331875058141129678736711749946388832275767861161694978" ) );
result = QBigInteger( "-6019440082648243511340058232981487443695615379104154368957939907896782179207195666302228625496897271988494" )
+= QBigInteger( "532566302499155416003316607801593784583652720754079760364736422291735917382015688217276924340984564880" );
CHECK( result.toString(), QString( "-6018907516345744355924054916373685849911031726383400289197575171474490443289813650614011348572556287423614" ) );
CHECK( result, QBigInteger( "-6018907516345744355924054916373685849911031726383400289197575171474490443289813650614011348572556287423614" ) );
result = QBigInteger( "-73755471563616026847726349357167530833850959662921059052928229237814728719448868719278211294785998253117976812683153264088230182865250970217610487" )
+= QBigInteger( "-30100016097092378349958946184353117306134810372681" );
CHECK( result.toString(), QString( "-73755471563616026847726349357167530833850959662921059052928229237814728719448868719278211294786028353134073905061503223034414535982557105027983168" ) );
CHECK( result, QBigInteger( "-73755471563616026847726349357167530833850959662921059052928229237814728719448868719278211294786028353134073905061503223034414535982557105027983168" ) );
result = QBigInteger( "-2211177066689704345686852756638946306674958952044447080285364283965878599873864667094550865713828159912" )
+= QBigInteger( "-5365560439372456892007565798761606781997269201538475736814780300517383963455858081652308237033460360040921820049494698892905680307378540208" );
CHECK( result.toString(), QString( "-5365560439372456892007565798761606784208446268228180082501633057156330270130817033696755317318824644006800419923359365987456546021206700120" ) );
CHECK( result, QBigInteger( "-5365560439372456892007565798761606784208446268228180082501633057156330270130817033696755317318824644006800419923359365987456546021206700120" ) );
result = QBigInteger( "6074122512337108841968521649035076841633691574254417104144285970819068715158037023149867252146570418484850234979838064249373816163440" )
+= QBigInteger( "301843614094506325875637699" );
CHECK( result.toString(), QString( "6074122512337108841968521649035076841633691574254417104144285970819068715158037023149867252146570418484850536823452158755699691801139" ) );
CHECK( result, QBigInteger( "6074122512337108841968521649035076841633691574254417104144285970819068715158037023149867252146570418484850536823452158755699691801139" ) );
result = QBigInteger( "-518214776931158149908771340564348982010543985108065053479219152734659892042499774128809654713651547833087206893256740737426200715673766732196603988" )
+= QBigInteger( "-29835172557747693726115525887386137004674545311422557345658884038760353928226157702249175218280718951979" );
CHECK( result.toString(), QString( "-518214776931158149908771340564348982010544014943237611226912878850185779428636778803354966136208893491971245653610668963583902964848985012915555967" ) );
CHECK( result, QBigInteger( "-518214776931158149908771340564348982010544014943237611226912878850185779428636778803354966136208893491971245653610668963583902964848985012915555967" ) );
result = QBigInteger( "15937412249227240968245047444122" )
+= QBigInteger( "186214680376169426108822450700978827886569053440254258585576645530381613666540347032550716844628275956253" );
CHECK( result.toString(), QString( "186214680376169426108822450700978827886569053440254258585576645530381613682477759281777957812873323400375" ) );
CHECK( result, QBigInteger( "186214680376169426108822450700978827886569053440254258585576645530381613682477759281777957812873323400375" ) );
result = QBigInteger( "-12528010116258685855047504252928107623923105458701761707911969527003855713485846140551107967495813584097081777160" )
+= QBigInteger( "-539986280927242338236008809854961759996986302156061552378097160849129372827386927545686899193598721998757419572890" );
CHECK( result.toString(), QString( "-552514291043501024091056314107889867620909407614763314086009130376133228540872773686238007161094535582854501350050" ) );
CHECK( result, QBigInteger( "-552514291043501024091056314107889867620909407614763314086009130376133228540872773686238007161094535582854501350050" ) );
result = QBigInteger( "-2454746908" )
+= QBigInteger( "-3822957127889394780055242156360370187075592078655552376050604679934415014573879513870030211860839641756441626913419699098985245833920954444218" );
CHECK( result.toString(), QString( "-3822957127889394780055242156360370187075592078655552376050604679934415014573879513870030211860839641756441626913419699098985245833923409191126" ) );
CHECK( result, QBigInteger( "-3822957127889394780055242156360370187075592078655552376050604679934415014573879513870030211860839641756441626913419699098985245833923409191126" ) );
result = QBigInteger( "-54288706131860071583318409080596095357980447323635" )
+= QBigInteger( "-425339410556015631098973742993327323051438456819027069606294261157940297643297240559452124432779202181589763874" );
CHECK( result.toString(), QString( "-425339410556015631098973742993327323051438456819027069606294315446646429503368823877861205028874560162037087509" ) );
CHECK( result, QBigInteger( "-425339410556015631098973742993327323051438456819027069606294315446646429503368823877861205028874560162037087509" ) );
result = QBigInteger( "1418766894051319870818496026367686195459604395660119754151922014257535705077512233275240217434104" )
+= QBigInteger( "-111987390206074845527" );
CHECK( result.toString(), QString( "1418766894051319870818496026367686195459604395660119754151922014257535705077400245885034142588577" ) );
CHECK( result, QBigInteger( "1418766894051319870818496026367686195459604395660119754151922014257535705077400245885034142588577" ) );
result = QBigInteger( "-690410131860410477456103857594543515409677479242833618634809302452962600476353286822550168231234854116465153078845744722987447719420052500874721214723" )
+= QBigInteger( "-2584690377433946747311356992432788361455494791066739384837409609897387109736539600623155880918146331681272708396146283818299" );
CHECK( result.toString(), QString( "-690410131860410477456103860179233892843624226554190611067597663908457391543092671659959778128621963853004753702001625641133779400692760897021005033022" ) );
CHECK( result, QBigInteger( "-690410131860410477456103860179233892843624226554190611067597663908457391543092671659959778128621963853004753702001625641133779400692760897021005033022" ) );
result = QBigInteger( "-2326153002179462643778624079324592172489363679671158" )
+= QBigInteger( "-109819757548464054181938329012610459679" );
CHECK( result.toString(), QString( "-2326153002179572463536172543378774110818376290130837" ) );
CHECK( result, QBigInteger( "-2326153002179572463536172543378774110818376290130837" ) );
result = QBigInteger( "-4428752250566525488353857709194941742993785578807911414016959206453045495320705299466107784149485981354180907411034982168391" )
+= QBigInteger( "-39247778259374215325521768005388007526581235832446540589720560855741992694947322437679214611686905696" );
CHECK( result.toString(), QString( "-4428752250566525488353896956973201117209111100575916802024485787688877941861295020026963526142180928676618586625646669074087" ) );
CHECK( result, QBigInteger( "-4428752250566525488353896956973201117209111100575916802024485787688877941861295020026963526142180928676618586625646669074087" ) );
result = QBigInteger( "3047" )
+= QBigInteger( "-73564587850313153523776932163719610733433776890390204618040173797196000100856070829277943048343156165795282307508135277641315214" );
CHECK( result.toString(), QString( "-73564587850313153523776932163719610733433776890390204618040173797196000100856070829277943048343156165795282307508135277641312167" ) );
CHECK( result, QBigInteger( "-73564587850313153523776932163719610733433776890390204618040173797196000100856070829277943048343156165795282307508135277641312167" ) );
result = QBigInteger( "71397189765381049110362731262243394989390499523719445987286843598407339615555456955143712741779487184644001767776382991377987516772847242986" )
+= QBigInteger( "-5821969555717973232123574849275726788359152255219972775831" );
CHECK( result.toString(), QString( "71397189765381049110362731262243394989390499523719445987286843598407339615555456949321743186061513952520426918500656203018835261552874467155" ) );
CHECK( result, QBigInteger( "71397189765381049110362731262243394989390499523719445987286843598407339615555456949321743186061513952520426918500656203018835261552874467155" ) );
result = QBigInteger( "-181409752656613138777964092635909379021826360390960647186726991165227400176766831466541160049935205507919070233410228328274" )
+= QBigInteger( "-523301382154855044703947051892202646490840761177533623732372519689918420769842424772676407501350528096714904915297347684247802773107355881667545916901" );
CHECK( result.toString(), QString( "-523301382154855044703947052073612399147453899955497716368281898711744781160803071959403398666577928273481736381838507734183008281026426115077774245175" ) );
CHECK( result, QBigInteger( "-523301382154855044703947052073612399147453899955497716368281898711744781160803071959403398666577928273481736381838507734183008281026426115077774245175" ) );
result = QBigInteger( "6858961373707073067" )
+= QBigInteger( "-334051508933893061433844279764271107181974906283364991309903077649971606436918071327072869826471946094594594115614990907" );
CHECK( result.toString(), QString( "-334051508933893061433844279764271107181974906283364991309903077649971606436918071327072869826471946087735632741907917840" ) );
CHECK( result, QBigInteger( "-334051508933893061433844279764271107181974906283364991309903077649971606436918071327072869826471946087735632741907917840" ) );
result = QBigInteger( "-23635098930374569407171906960429616870908424281519944658490940109956689534874971218650241680916564611" )
+= QBigInteger( "-18958917875779522833599589133142827952448539301142718746979271443846670235982743793439686626736428198541647202983677887505430060922528525205" );
CHECK( result.toString(), QString( "-18958917875779522833599589133142827952472174400073093316386443350807099852853652217721206571394919138651603892518552858724080302603445089816" ) );
CHECK( result, QBigInteger( "-18958917875779522833599589133142827952472174400073093316386443350807099852853652217721206571394919138651603892518552858724080302603445089816" ) );
// Botan's subtraction tests
result = QBigInteger( "0" )
-= QBigInteger( "0" );
CHECK( result.toString(), QString( "0" ) );
CHECK( result, QBigInteger( "0" ) );
result = QBigInteger( "0" )
-= QBigInteger( "1" );
CHECK( result.toString(), QString( "-1" ) );
CHECK( result, QBigInteger( "-1" ) );
result = QBigInteger( "0" )
-= QBigInteger( "4294967296" );
CHECK( result.toString(), QString( "-4294967296" ) );
CHECK( result, QBigInteger( "-4294967296" ) );
// Next test is labelled # 2^512 - 1
result = QBigInteger( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095" )
-= QBigInteger( "1" );
CHECK( result.toString(), QString( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084094" ) );
CHECK( result, QBigInteger( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084094" ) );
result = QBigInteger( "89094716573076464980713547115099137014719483620102078148320806773871083148864" )
-= QBigInteger( "49505213825110728957828173754776257356620450607893971553289366249708672306581" );
CHECK( result.toString(), QString( "39589502747965736022885373360322879658099033012208106595031440524162410842283" ) );
CHECK( result, QBigInteger( "39589502747965736022885373360322879658099033012208106595031440524162410842283" ) );
result = QBigInteger( "65894747009896006767807716946835412110318548717263922395390971078905789585431" )
-= QBigInteger( "3884269741925508225990715416862047284194603799902650748631039608684367281358" );
CHECK( result.toString(), QString( "62010477267970498541817001529973364826123944917361271646759931470221422304073" ) );
CHECK( result, QBigInteger( "62010477267970498541817001529973364826123944917361271646759931470221422304073" ) );
result = QBigInteger( "5950196396451977566902121301707054218364717196893101360011491777761952253736964709165962613347710607164178682987783755894811024288429224592316636383" )
-= QBigInteger( "8750653273562160761286422180115618621879821429145276197424652349306577311499807887070429373153777028581165316131683348567" );
CHECK( result.toString(), QString( "5950196396451977566902121292956400944802556435606679179895873155882130824591688511741310264041133295664370795917354382741033995707263908460633287816" ) );
CHECK( result, QBigInteger( "5950196396451977566902121292956400944802556435606679179895873155882130824591688511741310264041133295664370795917354382741033995707263908460633287816" ) );
result = QBigInteger( "9815262808265519920770782360080149146267723690" )
-= QBigInteger( "14067005768891609281364919358115291341352189918255780397560060748765650205261663193732434161580120817" );
CHECK( result.toString(), QString( "-14067005768891609281364919358115291341352189918255780387744797940500130284490880833652285015312397127" ) );
CHECK( result, QBigInteger( "-14067005768891609281364919358115291341352189918255780387744797940500130284490880833652285015312397127" ) );
result = QBigInteger( "-390149102941948621568479722346940666704376013734485343840154221605853412503154993878886490867020934777530894593416337175399865065870417717658815158195790" )
-= QBigInteger( "1456031684988128870809574635750149625240648487837308" );
CHECK( result.toString(), QString( "-390149102941948621568479722346940666704376013734485343840154221605853412503154993878886490867020934778986926278404466046209439701620567342899463646033098" ) );
CHECK( result, QBigInteger( "-390149102941948621568479722346940666704376013734485343840154221605853412503154993878886490867020934778986926278404466046209439701620567342899463646033098" ) );
result = QBigInteger( "7473774301764883450943" )
-= QBigInteger( "-26256369859367890755157372820052387483402723790185562908491933812453" );
CHECK( result.toString(), QString( "26256369859367890755157372820052387483402723797659337210256817263396" ) );
CHECK( result, QBigInteger( "26256369859367890755157372820052387483402723797659337210256817263396" ) );
result = QBigInteger( "36246343251214922024139186757009148849295485593397952003237349660142296147421019916619944353877490544706223768684758263065399016597969" )
-= QBigInteger( "2574427901445527995149185461475228850098549655325125750771680756403104624569522792792597223218143154924988199562355517064962665954307425375180" );
CHECK( result.toString(), QString( "-2574427865199184743934263437336042093089400806029640157373728753165754964427226645371577306598198801047497654856131748380204402888908408777211" ) );
CHECK( result, QBigInteger( "-2574427865199184743934263437336042093089400806029640157373728753165754964427226645371577306598198801047497654856131748380204402888908408777211" ) );
result = QBigInteger( "30129746266682790628283889040897642317014108334116727" )
-= QBigInteger( "-1580480523895398762563721715474380903630073871362143915864398724834897608423" );
CHECK( result.toString(), QString( "1580480523895398762563751845220647586420702155251184813506715738943231725150" ) );
CHECK( result, QBigInteger( "1580480523895398762563751845220647586420702155251184813506715738943231725150" ) );
result = QBigInteger( "-4614735863800137951667138933166372061" )
-= QBigInteger( "87175694379075561307234146162193190462135078700346746992273" );
CHECK( result.toString(), QString( "-87175694379075561307238760898056990600086745839279913364334" ) );
CHECK( result, QBigInteger( "-87175694379075561307238760898056990600086745839279913364334" ) );
result = QBigInteger( "-3753904" )
-= QBigInteger( "-11269137783745339515071988205310702154422777729974" );
CHECK( result.toString(), QString( "11269137783745339515071988205310702154422773976070" ) );
CHECK( result, QBigInteger( "11269137783745339515071988205310702154422773976070" ) );
result = QBigInteger( "592523948495379440082021279738170088402918858455470050140652787171830058864932939900794505955437856926902975870288" )
-= QBigInteger( "-205854658295495452479104108497931263758143158076949293929661651111" );
CHECK( result.toString(), QString( "592523948495379440082021279738170088402918858455675904798948282624309162973430871164552649113514806220832637521399" ) );
CHECK( result, QBigInteger( "592523948495379440082021279738170088402918858455675904798948282624309162973430871164552649113514806220832637521399" ) );
result = QBigInteger( "-33993701617495591491176844355" )
-= QBigInteger( "3438065097398894672826284379125235190693300918673662774192379185002391232383325160416036963599856704698280" );
CHECK( result.toString(), QString( "-3438065097398894672826284379125235190693300918673662774192379185002391232383359154117654459191347881542635" ) );
CHECK( result, QBigInteger( "-3438065097398894672826284379125235190693300918673662774192379185002391232383359154117654459191347881542635" ) );
result = QBigInteger( "26876428790838270949718735111909136008255051776703" )
-= QBigInteger( "-1781128112966810373286192008831149275546995635268767241859967609117529616872536681035700534316457543887601645022" );
CHECK( result.toString(), QString( "1781128112966810373286192008831149275546995635268767241859967635993958407710807630754435646225593552142653421725" ) );
CHECK( result, QBigInteger( "1781128112966810373286192008831149275546995635268767241859967635993958407710807630754435646225593552142653421725" ) );
result = QBigInteger( "2059771092932179758019770618974659367350250375647433386639519387\
69317693429941871882153770641334267205446421916220398066553188" )
-= QBigInteger( "3342500267594994347156312297990633112620923791590960237694328174171473763026" );
CHECK( result.toString(), QString( "205977109293217975801977061897465936735025037564739996163684343774970537117643881249041149717542676245208727588046226592790162" ) );
CHECK( result, QBigInteger( "205977109293217975801977061897465936735025037564739996163684343774970537117643881249041149717542676245208727588046226592790162" ) );
result = QBigInteger( "5545520403000578843599072515870982842927227412121917598877293331575380404618111609" )
-= QBigInteger( "5991287327241003718821424770352575362437680738923552868139860461945460339860477495902" );
CHECK( result.toString(), QString( "-5985741806838003139977825697836704379594753511511430950540983168613884959455859384293" ) );
CHECK( result, QBigInteger( "-5985741806838003139977825697836704379594753511511430950540983168613884959455859384293" ) );
result = QBigInteger( "248039029608125071340" )
-= QBigInteger( "3664608673" );
CHECK( result.toString(), QString( "248039029604460462667" ) );
CHECK( result, QBigInteger( "248039029604460462667" ) );
result = QBigInteger( "15425705711415937103627" )
-= QBigInteger( "-1435504065517745703440045276868982910754081405474123003767554211132837427846963435621523810229738262235546179779885824" );
CHECK( result.toString(), QString( "1435504065517745703440045276868982910754081405474123003767554211132837427846963435621523810229753687941257595716989451" ) );
CHECK( result, QBigInteger( "1435504065517745703440045276868982910754081405474123003767554211132837427846963435621523810229753687941257595716989451" ) );
result = QBigInteger( "50882847205108645607281568922683652688671738236030732914347600821086" )
-= QBigInteger( "12176160963158" );
CHECK( result.toString(), QString( "50882847205108645607281568922683652688671738236030732902171439857928" ) );
CHECK( result, QBigInteger( "50882847205108645607281568922683652688671738236030732902171439857928" ) );
result = QBigInteger( "-35426518565985818947670047877033022885542172461973566228509771053416312543201815881190953762207629232160412058300173038824256783171761132" )
-= QBigInteger( "-4864862607366468843184694353123830534588538011093812418208808135799" );
CHECK( result.toString(), QString( "-35426518565985818947670047877033022885542172461973566228509771053416307678339208514722110577513276108329877469762161945011838574363625333" ) );
CHECK( result, QBigInteger( "-35426518565985818947670047877033022885542172461973566228509771053416307678339208514722110577513276108329877469762161945011838574363625333" ) );
result = QBigInteger( "-1428596214712268310382144828171384812520179141608121870013556402879770424002218157546599921571184" )
-= QBigInteger( "-4054101" );
CHECK( result.toString(), QString( "-1428596214712268310382144828171384812520179141608121870013556402879770424002218157546599917517083" ) );
CHECK( result, QBigInteger( "-1428596214712268310382144828171384812520179141608121870013556402879770424002218157546599917517083" ) );
result = QBigInteger( "-200931" )
-= QBigInteger( "-44558802460130495759482832913160717791151786725570519475449607659705171682283111490834930835045735142966847483009157514950177565952218520297258834187372" );
CHECK( result.toString(), QString( "44558802460130495759482832913160717791151786725570519475449607659705171682283111490834930835045735142966847483009157514950177565952218520297258833986441" ) );
CHECK( result, QBigInteger( "44558802460130495759482832913160717791151786725570519475449607659705171682283111490834930835045735142966847483009157514950177565952218520297258833986441" ) );
result = QBigInteger( "105704314890799915321259" )
-= QBigInteger( "827923545945076415574912438499169814414563066877494100831657761190490697473854369477784874118787495351405549803329615347120938123226038208" );
CHECK( result.toString(), QString( "-827923545945076415574912438499169814414563066877494100831657761190490697473854369477784874118787495351405549803329509642806047323310716949" ) );
CHECK( result, QBigInteger( "-827923545945076415574912438499169814414563066877494100831657761190490697473854369477784874118787495351405549803329509642806047323310716949" ) );
result = QBigInteger( "1448979433940064018828919290452280235308901982649341" )
-= QBigInteger( "303926827425887072291878308433008512899006711759770318009" );
CHECK( result.toString(), QString( "-303925378446453132227859479513718060618771402857787668668" ) );
CHECK( result, QBigInteger( "-303925378446453132227859479513718060618771402857787668668" ) );
result = QBigInteger( "-243237595290235750457450892290434789864" )
-= QBigInteger( "19817702076334276402981273067417321098467533300947463865383702005126562800253466403934608765512316565811954342319565128573969" );
CHECK( result.toString(), QString( "-19817702076334276402981273067417321098467533300947463865383702005126562800253466403934852003107606801562411793211855563363833" ) );
CHECK( result, QBigInteger( "-19817702076334276402981273067417321098467533300947463865383702005126562800253466403934852003107606801562411793211855563363833" ) );
result = QBigInteger( "294037338365659932242802023634" )
-= QBigInteger( "4401245995535867764294876849802142926077599828776505639975554254356763769548465" );
CHECK( result.toString(), QString( "-4401245995535867764294876849802142926077599828776211602637188594424520967524831" ) );
CHECK( result, QBigInteger( "-4401245995535867764294876849802142926077599828776211602637188594424520967524831" ) );
result = QBigInteger( "7303853946195223307036710881687367004566538357189824031021831088365362" )
-= QBigInteger( "119286025999378935715794641163321741" );
CHECK( result.toString(), QString( "7303853946195223307036710881687366885280512357810888315227189925043621" ) );
CHECK( result, QBigInteger( "7303853946195223307036710881687366885280512357810888315227189925043621" ) );
result = QBigInteger( "571167355343287235687602610714110416067426289363505412908804940696550592413192300554016875" )
-= QBigInteger( "15872188842802631759540597" );
CHECK( result.toString(), QString( "571167355343287235687602610714110416067426289363505412908804940680678403570389668794476278" ) );
CHECK( result, QBigInteger( "571167355343287235687602610714110416067426289363505412908804940680678403570389668794476278" ) );
result = QBigInteger( "1002240129784524388754179399598974973256811336031329881209395070412702275169416754240" )
-= QBigInteger( "59429482478860591343145393540420033516478305952872349006715789477946474753657206800070515207967709079933420746952" );
CHECK( result.toString(), QString( "-59429482478860591343145393539417793386693781564118169607116814504689663417625876918861120137555006804764003992712" ) );
CHECK( result, QBigInteger( "-59429482478860591343145393539417793386693781564118169607116814504689663417625876918861120137555006804764003992712" ) );
result = QBigInteger( "1370431648825444838359719050380239722263203134555431526491525074601463042144798545817957389" )
-= QBigInteger( "3473869878" );
CHECK( result.toString(), QString( "1370431648825444838359719050380239722263203134555431526491525074601463042144798542344087511" ) );
CHECK( result, QBigInteger( "1370431648825444838359719050380239722263203134555431526491525074601463042144798542344087511" ) );
result = QBigInteger( "8548280229254726209" )
-= QBigInteger( "33066125035269904981849320434016892734943145935582141989968280846973981913056248918" );
CHECK( result.toString(), QString( "-33066125035269904981849320434016892734943145935582141989968280838425701683801522709" ) );
CHECK( result, QBigInteger( "-33066125035269904981849320434016892734943145935582141989968280838425701683801522709" ) );
result = QBigInteger( "-19023558832687506489508150795966332175990129963029928958584170111759630293276939647334082100169102538364437859846398095065171936899503" )
-= QBigInteger( "24899271127523545342283468762809653407638631966220124695751976894193103779443050843040771191227522843088079031762445684377195650493065096847292797" );
CHECK( result.toString(), QString( "-24899271127542568901116156269299161558434598298396114825715006823151687949554810473334048130874856925188248134300810122237042048588130268784192300" ) );
CHECK( result, QBigInteger( "-24899271127542568901116156269299161558434598298396114825715006823151687949554810473334048130874856925188248134300810122237042048588130268784192300" ) );
result = QBigInteger( "-1800353575522706389288305623797196690530870204356722928042061228497437075035917720399302198953687023" )
-= QBigInteger( "-11875668261530466053708538730940776412171106483072624532757177471384128016458332544642788404765469924496127460164" );
CHECK( result.toString(), QString( "11875668261528665700133016024551488106547309286382093662552820748456085955229835107567752487045070622297173773141" ) );
CHECK( result, QBigInteger( "11875668261528665700133016024551488106547309286382093662552820748456085955229835107567752487045070622297173773141" ) );
result = QBigInteger( "-29861551039945217879" )
-= QBigInteger( "1113473025916855642353456146647542930581669082348409639697282960877889226500319996380838232582376232872868947624793789212829885934" );
CHECK( result.toString(), QString( "-1113473025916855642353456146647542930581669082348409639697282960877889226500319996380838232582376232872868947654655340252775103813" ) );
CHECK( result, QBigInteger( "-1113473025916855642353456146647542930581669082348409639697282960877889226500319996380838232582376232872868947654655340252775103813" ) );
result = QBigInteger( "565532963656761153838218277564957917658707297649757920676303301655328103665512287797108510139837643506491641987188791892506290" )
-= QBigInteger( "-2188105671531473889939411772533707" );
CHECK( result.toString(), QString( "565532963656761153838218277564957917658707297649757920676303301655328103665512287797108510142025749178023115877128203665039997" ) );
CHECK( result, QBigInteger( "565532963656761153838218277564957917658707297649757920676303301655328103665512287797108510142025749178023115877128203665039997" ) );
result = QBigInteger( "-349535960680522202843083381184496349093812380954435872337802226" )
-= QBigInteger( "-1829600726218222026679938" );
CHECK( result.toString(), QString( "-349535960680522202843083381184496349091982780228217650311122288" ) );
CHECK( result, QBigInteger( "-349535960680522202843083381184496349091982780228217650311122288" ) );
result = QBigInteger( "-1" ) -= QBigInteger( "-6726974989587128275" );
CHECK( result.toString(), QString( "6726974989587128274" ) );
CHECK( result, QBigInteger( "6726974989587128274" ) );
result = QBigInteger( "-107142709838121196902389095205618516687047338619382145236348309762148611647954748824" )
-= QBigInteger( "42484103615491" );
CHECK( result.toString(), QString( "-107142709838121196902389095205618516687047338619382145236348309762148654132058364315" ) );
CHECK( result, QBigInteger( "-107142709838121196902389095205618516687047338619382145236348309762148654132058364315" ) );
result = QBigInteger( "-90546630430085769764839607528116121381848878494574360812027599640018921358040178215575723" )
-= QBigInteger( "-118922408531468986902800063237122125617455464103913195171141030774109638861272017660698580914239435114280434761425243" );
CHECK( result.toString(), QString( "118922408531468986902800063146575495187369694339073587643024909392260760366697656848670981274220513756240256545849520" ) );
CHECK( result, QBigInteger( "118922408531468986902800063146575495187369694339073587643024909392260760366697656848670981274220513756240256545849520" ) );
result = QBigInteger( "-5545044667082427128801726416727657360001588430113578182850657573063241939882570324573086267287272360432363387213743735507218270373633222520429" )
-= QBigInteger( "-151423255459028627628896755237194376177115" );
CHECK( result.toString(), QString( "-5545044667082427128801726416727657360001588430113578182850657573063241939882570324573086267287272360280940131754715107878321515136438846343314" ) );
CHECK( result, QBigInteger( "-5545044667082427128801726416727657360001588430113578182850657573063241939882570324573086267287272360280940131754715107878321515136438846343314" ) );
result = QBigInteger( "-5247636471953421659649611318164848102069" )
-= QBigInteger( "-4024324110573096565232590473170599175885004" );
CHECK( result.toString(), QString( "4019076474101143143572940861852434327782935" ) );
CHECK( result, QBigInteger( "4019076474101143143572940861852434327782935" ) );
result = QBigInteger( "39412892606015043322484854253879371723186457838590224795040178472832" )
-= QBigInteger( "-5038321321957452145034687815432890684825466579123474921848465393400312" );
CHECK( result.toString(), QString( "5077734214563467188357172669686770056548653036962065146643505571873144" ) );
CHECK( result, QBigInteger( "5077734214563467188357172669686770056548653036962065146643505571873144" ) );
result = QBigInteger( "-55979414588009227035683624505208766753187469727799640277204274207843317583292736333912783829528270272642583004969175230274821" )
-= QBigInteger( "-109633110576212669339535976775635762395927171313557427036242111476016398579345366908401334025571265714128108308032073779442181369365924213118258269679" );
CHECK( result.toString(), QString( "109633110576212669339535920796221174386700135629932921827475358288546670779705089704127126182253682421391774395248244251171908726782919243943027994858" ) );
CHECK( result, QBigInteger( "109633110576212669339535920796221174386700135629932921827475358288546670779705089704127126182253682421391774395248244251171908726782919243943027994858" ) );
result = QBigInteger( "-38752353898173389347479216285772999906325286421302866854350737050533204094183249691110" )
-= QBigInteger( "2428819407377764342156426895396654728835493564788997075896393065230009911546390816091652653701035085361" );
CHECK( result.toString(), QString( "-2428819407377764380908780793570044076314709850561996982221679486532876765897127866624856747884284776471" ) );
CHECK( result, QBigInteger( "-2428819407377764380908780793570044076314709850561996982221679486532876765897127866624856747884284776471" ) );
result = QBigInteger( "-2784579005241382005249492720344" )
-= QBigInteger( "-164204542616919252351131740123094674" );
CHECK( result.toString(), QString( "164201758037914010969126490630374330" ) );
CHECK( result, QBigInteger( "164201758037914010969126490630374330" ) );
result = QBigInteger( "200948857420871544747808060972375039052401280822505804851732868100" )
-= QBigInteger( "-795957177479360455258269298038670876462147576765875895105714" );
CHECK( result.toString(), QString( "200949653378049024108263319241673077723277742970082570727627973814" ) );
CHECK( result, QBigInteger( "200949653378049024108263319241673077723277742970082570727627973814" ) );
result = QBigInteger( "217570540819" )
-= QBigInteger( "121955083597720420983384282166693307394185530431368476834980748302158718406063500763434561937200696970170700" );
CHECK( result.toString(), QString( "-121955083597720420983384282166693307394185530431368476834980748302158718406063500763434561937200479399629881" ) );
CHECK( result, QBigInteger( QString("-121955083597720420983384282166693307394185530431368476834980748302158718406063500763434561937200479399629881" ) ) );
result = QBigInteger( QString("2335319252198456765380587281374076367944") )
-= QBigInteger( QString("-4500271") );
CHECK( result, QBigInteger( QString( "2335319252198456765380587281374080868215" ) ) );
result = QBigInteger( QString("-393694614027544181700073367147249369966344727230221941008713805434207925307052598" ) )
-= QBigInteger( QString("-153972676737062409261153899615588515236137907791841623991260363840680295565313157972489168132345521780658007459602823125797806770" ) );
CHECK( result.toString(), QString( "153972676737062409261153899615588515236137907791447929377232819658980222198165908602522823405115299839649293654168615200490754172" ) );
CHECK( result, QBigInteger( QString("153972676737062409261153899615588515236137907791447929377232819658980222198165908602522823405115299839649293654168615200490754172" ) ) );
result = QBigInteger( QString("114832549702862263167") )
-= QBigInteger( QString("12921864907229959558745276418830287875386673600892281022286597165773569473039953984775959232814911435097412913078625") );
CHECK( result.toString(), QString( "-12921864907229959558745276418830287875386673600892281022286597165773569473039953984775959232814796602547710050815458" ) );
CHECK( result, QBigInteger( QString( "-12921864907229959558745276418830287875386673600892281022286597165773569473039953984775959232814796602547710050815458" ) ) );
result = QBigInteger( QString( "6489502346837936889305337487724547956628371915228387374094443896266362105931065153072983425911767580294076594078932835008494777866083" ) )
-= QBigInteger( QString( "1099205476533612407829257935144627350486541654788267826664706620630745291371323154513322608446957760026881954001581" ) );
CHECK( result.toString(), QString( "6489502346837936888206132011190935548799113980083760023607902241478094279266358532442238134540444425780753985631975074981612823864502" ) );
CHECK( result, QBigInteger( QString("6489502346837936888206132011190935548799113980083760023607902241478094279266358532442238134540444425780753985631975074981612823864502" ) ) );
result = QBigInteger( QString("169991144123958754253801313173662977337850870273358378951640521601077152994474340806917796870911557233689087716056557" ) )
-= QBigInteger( QString("-15409167") );
CHECK( result.toString(), QString( "169991144123958754253801313173662977337850870273358378951640521601077152994474340806917796870911557233689087731465724" ) );
CHECK( result, QBigInteger( QString("169991144123958754253801313173662977337850870273358378951640521601077152994474340806917796870911557233689087731465724") ) );
}

@ -0,0 +1,668 @@
/**
* Copyright (C) 2004-2005 Brad Hards <bradh@frogmouth.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "bigintunittest.h"
void BigIntUnitTest::initTestCase()
{
m_init = new QCA::Initializer;
#include "../fixpaths.include"
}
void BigIntUnitTest::cleanupTestCase()
{
delete m_init;
}
void BigIntUnitTest::allTests()
{
QBigInteger result;
// Some string conversion tests
QCOMPARE( QBigInteger("255").toString(), QBigInteger(255).toString() );
QCOMPARE( QBigInteger("-255").toString(), QBigInteger(-255).toString() );
QCOMPARE( QBigInteger("255").toString(), QString("255") );
QCOMPARE( QBigInteger("-255").toString(), QString("-255") );
// Some operator tests
QCOMPARE( QBigInteger("255") == QBigInteger(255), true );
QCOMPARE( QBigInteger("-255") == QBigInteger(-255), true );
QCOMPARE( QBigInteger("256") != QBigInteger(255), true );
QCOMPARE( QBigInteger("-256") != QBigInteger(-255), true );
// Some comparison tests
QBigInteger a( "4000000000000" );
QBigInteger b( "-4000000000000" );
QBigInteger c( "2000000000000" );
QCOMPARE( a < b, false );
QCOMPARE( a <= b, false );
QCOMPARE( a.compare(b), 1 );
QCOMPARE( a > b, true );
QCOMPARE( a >= b, true );
QCOMPARE( a > c, true );
QCOMPARE( c.compare(b), 1 );
QCOMPARE( c.compare(a), -1 );
// Check if the stream operator is any good
QString testString;
QTextStream ts( &testString, QIODevice::WriteOnly);
ts << a << b << c << endl;
QCOMPARE( testString, QString( "4000000000000-40000000000002000000000000\n") );
// Botan's addition tests
QCOMPARE( QBigInteger( 255 ) += QBigInteger ( 1 ), QBigInteger( 256 ) );
result = QBigInteger( 255 ) += QBigInteger( 1 );
QCOMPARE( result.toString(), QBigInteger( 256 ).toString() );
result = QBigInteger( "65535" ) += QBigInteger( "1" );
QCOMPARE( result.toString(), QString( "65536" ) );
QCOMPARE( result, QBigInteger( "65536") );
result = QBigInteger( "4294967295" ) += QBigInteger( 1 );
QCOMPARE( result.toString(), QString( "4294967296" ) );
QCOMPARE( result, QBigInteger( "4294967296" ) );
result = QBigInteger( "18446744073709551615" ) += QBigInteger( 1 );
QCOMPARE( result.toString(), QString( "18446744073709551616" ) );
QCOMPARE( result, QBigInteger( "18446744073709551616" ) );
result = QBigInteger( "124536363637272472" ) += QBigInteger( "124536363637272472" );
QCOMPARE( result.toString(), QString ( "249072727274544944" ) );
QCOMPARE( result, QBigInteger ( "249072727274544944" ) );
result = QBigInteger( "9223372036854775807" ) += QBigInteger( "281474976710655" );
QCOMPARE( result.toString(), QString ( "9223653511831486462" ) );
QCOMPARE( result, QBigInteger ( "9223653511831486462" ) );
result = QBigInteger( "9223372036854775807" ) += QBigInteger( "137438953471" );
QCOMPARE( result.toString(), QString( "9223372174293729278" ) );
QCOMPARE( result, QBigInteger( "9223372174293729278" ) );
// Botan's carry tests
result = QBigInteger( "340282366920938463463374607431768211455" )
+= QBigInteger( "340282366920938463463374607431768211455" );
QCOMPARE( result.toString(), QString( "680564733841876926926749214863536422910" ) );
QCOMPARE( result, QBigInteger( "680564733841876926926749214863536422910" ) );
result = QBigInteger( "340282366920938463463374607431768211455" )
+= QBigInteger( "340282366920938463463374607431768211450" );
QCOMPARE( result.toString(), QString( "680564733841876926926749214863536422905" ) );
QCOMPARE( result, QBigInteger( "680564733841876926926749214863536422905" ) );
result = QBigInteger( "115792089237316195423570985008687907853269984665640564039457584007913129639935" )
+= QBigInteger( "115792089237316195423570985008687907853269984665640564039457584007913129639935" );
QCOMPARE( result.toString(), QString( "231584178474632390847141970017375815706539969331281128078915168015826259279870" ) );
QCOMPARE( result, QBigInteger( "231584178474632390847141970017375815706539969331281128078915168015826259279870" ) );
result = QBigInteger( "115792089237316195423570985008687907853269984665640564039457584007913129639935" )
+= QBigInteger( "115792089237316195423570985008687907853269984665640564039457584007913129639919" );
QCOMPARE( result.toString(), QString( "231584178474632390847141970017375815706539969331281128078915168015826259279854") );
QCOMPARE( result, QBigInteger( "231584178474632390847141970017375815706539969331281128078915168015826259279854") );
result = QBigInteger( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095" )
+= QBigInteger( "18446744073709551616" );
QCOMPARE( result.toString(), QString( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946588393177722715635711" ) );
QCOMPARE( result, QBigInteger( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946588393177722715635711" ) );
result = QBigInteger( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095" )
+= QBigInteger( "1" );
QCOMPARE( result.toString(), QString( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096" ) );
QCOMPARE( result, QBigInteger( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096" ) );
result = QBigInteger( "-39794270013919406610834826960427146769766189764838473416502965291920535601112688579198627475284777498059330306128763345008528325994574657552726381901" )
+= QBigInteger( "-342238655038" );
QCOMPARE( result.toString(), QString( "-39794270013919406610834826960427146769766189764838473416502965291920535601112688579198627475284777498059330306128763345008528325994574657894965036939" ) );
QCOMPARE( result, QBigInteger( "-39794270013919406610834826960427146769766189764838473416502965291920535601112688579198627475284777498059330306128763345008528325994574657894965036939" ) );
result = QBigInteger( "25110291853498940831251897922987678157346336093292373576945426289097725034326735312448621015537884914" )
+= QBigInteger( "-36551081154398645734533965739979697527373251608055056627686956281114038842935173436543461" );
QCOMPARE( result.toString(), QString( "25110291853462389750097499277253144191606356395765000325337371232470038078045621273605685842101341453") );
QCOMPARE( result, QBigInteger( "25110291853462389750097499277253144191606356395765000325337371232470038078045621273605685842101341453") );
result = QBigInteger( "27802650352" )
+= QBigInteger( "660736146705288303126411072388564329913778942" );
QCOMPARE( result.toString(), QString( "660736146705288303126411072388564357716429294" ) );
QCOMPARE( result, QBigInteger( "660736146705288303126411072388564357716429294" ) );
result = QBigInteger( "-1348245899955041864800954463709881466231496038216683608715424566397833766910915722793041224478985289" )
+= QBigInteger( "11517149522866182358565152643595266257020228597058539113114732218008332987904361457299261161227276764386173666571334749062651694592291882972" );
QCOMPARE( result.toString(), QString( "11517149522866182358565152643595266257018880351158584071249931263544623106438129961261044477618561339819775832804423833339858653367812897683" ) );
QCOMPARE( result, QBigInteger( "11517149522866182358565152643595266257018880351158584071249931263544623106438129961261044477618561339819775832804423833339858653367812897683" ) );
result = QBigInteger( "-17540530441681616962868251635133601915039026254996886583618243914226325157426408929602625346567256761818" )
+= QBigInteger( "865200427983527245206901810160356641402419461642082623179544681519016990" );
QCOMPARE( result.toString(), QString( "-17540530441681616962868251635132736714611042727751679681808083557584922737964766846979445801885737744828" ) );
QCOMPARE( result, QBigInteger( "-17540530441681616962868251635132736714611042727751679681808083557584922737964766846979445801885737744828" ) );
result = QBigInteger( "128844776074298261556398714096948603458177018275051329218555498374" )
+= QBigInteger( "443816313829150876362052235134610603220548928107697961229953611873695276391917150913346479060246759720475193648" );
QCOMPARE( result.toString(), QString( "443816313829150876362052235134610603220548928236542737304251873430093990488865754371523497335298088939030692022" ) );
QCOMPARE( result, QBigInteger( "443816313829150876362052235134610603220548928236542737304251873430093990488865754371523497335298088939030692022" ) );
result = QBigInteger( "1709484189262457846620911889502097055085989595277300243221975568275935717696463" )
+= QBigInteger( "-1646592344139809206374540620411514484579951199941360" );
QCOMPARE( result.toString(), QString( "1709484189262457846620911887855504710946180388902759622810461083695984517755103" ) );
QCOMPARE( result, QBigInteger( "1709484189262457846620911887855504710946180388902759622810461083695984517755103" ) );
result = QBigInteger( "320175865429637176165709341576187102540180627806418015204928771170233538951323952509055929139673223273528062883083030595199153877335714942842" )
+= QBigInteger( "-2828241696960736089879965882386687935938570856545481227619497640844399275054327390050478930503975773972" );
QCOMPARE( result.toString(), QString( "320175865429637176165709341576187102537352386109457279115048805287846851015385381652510447912053725632683663608028703205148674946831739168870" ) );
QCOMPARE( result, QBigInteger( "320175865429637176165709341576187102537352386109457279115048805287846851015385381652510447912053725632683663608028703205148674946831739168870" ) );
result = QBigInteger( "-4035398360542181725908295312107496142105415014744259439963377204111754181625695349185753326709217" )
+= QBigInteger( "85450213703789913646546187382091037800" );
QCOMPARE( result.toString(), QString( "-4035398360542181725908295312107496142105415014744259439963291753898050391712048802998371235671417" ) );
QCOMPARE( result, QBigInteger( "-4035398360542181725908295312107496142105415014744259439963291753898050391712048802998371235671417" ) );
result = QBigInteger( "-1292166446073479876801522363382357887431657639184151284775525387363973852756087726243671676713861533673009088319851" )
+= QBigInteger( "804538895874518175537499425282375058236245531798590350403343841766955572070643267141945695624895109330242749935754739434394691714971" );
QCOMPARE( result.toString(), QString( "804538895874518174245332979208895181434723168416232462971686202582804287295117879777971842868807383086571073221893205761385603395120" ) );
QCOMPARE( result, QBigInteger( "804538895874518174245332979208895181434723168416232462971686202582804287295117879777971842868807383086571073221893205761385603395120" ) );
result = QBigInteger( "-451986588700926309459451756852005697379481014956007968529234251884946522682901215022086432597024324062240835564200177389" )
+= QBigInteger( "15762983479" );
QCOMPARE( result.toString(), QString( "-451986588700926309459451756852005697379481014956007968529234251884946522682901215022086432597024324062240835548437193910" ) );
QCOMPARE( result, QBigInteger( "-451986588700926309459451756852005697379481014956007968529234251884946522682901215022086432597024324062240835548437193910" ) );
result = QBigInteger( "-3907475412115728816974567022055278374116794025624287474334038831885743634200801846649105209920908153587891040882946582394429615396962188674594744360388466" )
+= QBigInteger( "193893611236537854694879677478106237157079207398283117392998175454362643521031390" );
QCOMPARE( result.toString(), QString( "-3907475412115728816974567022055278374116794025624287474334038831885743634006908235412567355226028476109784803725867374996146498003964013220232100839357076" ) );
QCOMPARE( result, QBigInteger( "-3907475412115728816974567022055278374116794025624287474334038831885743634006908235412567355226028476109784803725867374996146498003964013220232100839357076" ) );
result = QBigInteger( "-72603710637966201224690926289" )
+= QBigInteger( "-13618442642298533261581255034923612640512507150728017106768861506299813289801666559564532" );
QCOMPARE( result.toString(), QString( "-13618442642298533261581255034923612640512507150728017106768934110010451256002891250490821" ) );
QCOMPARE( result, QBigInteger( "-13618442642298533261581255034923612640512507150728017106768934110010451256002891250490821" ) );
result = QBigInteger( "56077960835713056831402948406790747107889446769357509759472207603483968107693997028111823994257399379783658853302692762256851623103019589392739" )
+= QBigInteger( "-427057313888431079237360487703561848638868677065083968842" );
QCOMPARE( result.toString(), QString( "56077960835713056831402948406790747107889446769357509759472207603483968107693997028111396936943510948704421492814989200408212754425954505423897" ) );
QCOMPARE( result, QBigInteger( "56077960835713056831402948406790747107889446769357509759472207603483968107693997028111396936943510948704421492814989200408212754425954505423897" ) );
result = QBigInteger( "-2209800838508504443494783762534800337712101405156784708782197580824527899758308" )
+= QBigInteger( "42844076503039495864500213925837598507817708418354152774112078596443089606598570396235816327987463393971710495985285591895096794994387176281079" );
QCOMPARE( result.toString(), QString( "42844076503039495864500213925837598507817708418354152774112078594233288768090065952741032565452663056259609090828500883112899214169859276522771" ) );
QCOMPARE( result, QBigInteger( "42844076503039495864500213925837598507817708418354152774112078594233288768090065952741032565452663056259609090828500883112899214169859276522771" ) );
result = QBigInteger( "33887767308809826842417841176152232321272231788338404526859019370507113927387984766381329515371768224976188337692" )
+= QBigInteger( "349484339542971517481628970179002500341" );
QCOMPARE( result.toString(), QString( "33887767308809826842417841176152232321272231788338404526859019370507113927737469105924301032853397195155190838033" ) );
QCOMPARE( result, QBigInteger( "33887767308809826842417841176152232321272231788338404526859019370507113927737469105924301032853397195155190838033" ) );
result = QBigInteger( "85748089639858660722587321621536298082690707526412426951630101551228144063151688592419555048867068162" )
+= QBigInteger( "-383634567691961960211191292397062452265352651123492760493087381707279" );
QCOMPARE( result.toString(), QString( "85748089639858660722587321621535914448123015564452215760337704488775878710500565099659061961485360883" ) );
QCOMPARE( result, QBigInteger( "85748089639858660722587321621535914448123015564452215760337704488775878710500565099659061961485360883" ) );
result = QBigInteger( "23889807888563742283608049816129153552608399262924421832404872043475" )
+= QBigInteger( "995" );
QCOMPARE( result.toString(), QString( "23889807888563742283608049816129153552608399262924421832404872044470" ) );
QCOMPARE( result, QBigInteger( "23889807888563742283608049816129153552608399262924421832404872044470" ) );
result = QBigInteger( "-654786925833474864669230962582694222611472680701859262466465606239654996048306783957549697781271829257774329538985" )
+= QBigInteger( "-276137507159648540503039013089014674747" );
QCOMPARE( result.toString(), QString( "-654786925833474864669230962582694222611472680701859262466465606239654996048582921464709346321774868270863344213732" ) );
QCOMPARE( result, QBigInteger( "-654786925833474864669230962582694222611472680701859262466465606239654996048582921464709346321774868270863344213732" ) );
result = QBigInteger( "50463316268089933" )
+= QBigInteger( "-140591583463431806921000349498135287589005423318927850947894242995310138569473157521312413652439234324419130527702899917161307657443381774866237429" );
QCOMPARE( result.toString(), QString( "-140591583463431806921000349498135287589005423318927850947894242995310138569473157521312413652439234324419130527702899917161307657392918458598147496" ) );
QCOMPARE( result, QBigInteger( "-140591583463431806921000349498135287589005423318927850947894242995310138569473157521312413652439234324419130527702899917161307657392918458598147496" ) );
result = QBigInteger( "1339015021665554488163337105187026760232395594198925052890859936\
418304234254229440059229155546157793544192" )
+= QBigInteger( "6294037420283433712414743361937677483761554699961644450461297486224793278823004487175687771163597590566132592591599249970281125781761944353272" );
QCOMPARE( result.toString(), QString( "6294037420283433712414743361937677485100569721627198938624634591411820039055400081374612824054457526984436826845828690029510281327919737897464" ) );
QCOMPARE( result, QBigInteger( "6294037420283433712414743361937677485100569721627198938624634591411820039055400081374612824054457526984436826845828690029510281327919737897464" ) );
result = QBigInteger( "-241446683" )
+= QBigInteger( "-282671163032866994488211995758272717472259277760825940523445628\
442206062910449311538519756165635175664610569214430918184214" );
QCOMPARE( result.toString(), QString( "-282671163032866994488211995758272717472259277760825940523445628442206062910449311538519756165635175664610569214431159630897" ) );
QCOMPARE( result, QBigInteger( "-282671163032866994488211995758272717472259277760825940523445628442206062910449311538519756165635175664610569214431159630897" ) );
result = QBigInteger( "2358605503303452637996081421902056515951744611718383128442445119505739707550326378912342448355046239066896995563581" )
+= QBigInteger( "-3830437229145325165273364525551261440648845791949681661260946956860463720730123941973615" );
QCOMPARE( result.toString(), QString( "2358605503303452637996081418071619286806419446445018602891183678856893915600644717651395491494582518336773053589966" ) );
QCOMPARE( result, QBigInteger( "2358605503303452637996081418071619286806419446445018602891183678856893915600644717651395491494582518336773053589966" ) );
result = QBigInteger( "1860794367587960058388097846258490" )
+= QBigInteger( "-237344494507203983863096991896035366478949095337787603280" );
QCOMPARE( result.toString(), QString( "-237344494507203983863095131101667778518890707239941344790" ) );
QCOMPARE( result, QBigInteger( "-237344494507203983863095131101667778518890707239941344790" ) );
result = QBigInteger( "-286399096802321907543674770412181810379003627366516307780436082546" )
+= QBigInteger( "6433131620680089024037442172197761714707480582555136398379812339597187475099646442833150194" );
QCOMPARE( result.toString(), QString( "6433131620680089024037441885798664912385573038880365986198001960593560108583338662397067648" ) );
QCOMPARE( result, QBigInteger( "6433131620680089024037441885798664912385573038880365986198001960593560108583338662397067648" ) );
result = QBigInteger( "181180339077102369559537817583627894783322804181859729574752442572146800569023773490164987520541203125338295785763244283224569259250011493" )
+= QBigInteger( "-1199127665773503170250307078028035875479459397657178356959526245067549497129923023348187933280753018204983010837846725666878521137637491" );
QCOMPARE( result.toString(), QString( "179981211411328866389287510505599858907843344784202551217792916327079251071893850466816799587260450107133312774925397557557690738112374002" ) );
QCOMPARE( result, QBigInteger( "179981211411328866389287510505599858907843344784202551217792916327079251071893850466816799587260450107133312774925397557557690738112374002" ) );
result = QBigInteger( "-64140201395555533811408642891620184652051275811075926176282032144915585503450776768366775652419022149512034611311149858695307750874152" )
+= QBigInteger( "174441039" );
QCOMPARE( result.toString(), QString( "-64140201395555533811408642891620184652051275811075926176282032144915585503450776768366775652419022149512034611311149858695307576433113" ) );
QCOMPARE( result, QBigInteger( "-64140201395555533811408642891620184652051275811075926176282032144915585503450776768366775652419022149512034611311149858695307576433113" ) );
result = QBigInteger( "1272757944308835857208037878018507337530557445422230495561634616503724419877512717512360239259640193513601352202821462208896049331599624285621" )
+= QBigInteger( "7326562354017884140300121264633612334070903165496641915889499701\
38457507491850467631029977010" );
QCOMPARE( result.toString(), QString( "1272757944308835857208037878018507337530557445422963151797036404917754432003976078745767329576189857705190302172959919716387899799230654262631" ) );
QCOMPARE( result, QBigInteger( "1272757944308835857208037878018507337530557445422963151797036404917754432003976078745767329576189857705190302172959919716387899799230654262631" ) );
result = QBigInteger( "-296171972628230" )
+= QBigInteger( "-8295766099121843219000823699362222865173820102569731517716391727126741710202086962877467940292139" );
QCOMPARE( result.toString(), QString( "-8295766099121843219000823699362222865173820102569731517716391727126741710202086963173639912920369" ) );
QCOMPARE( result, QBigInteger( "-8295766099121843219000823699362222865173820102569731517716391727126741710202086963173639912920369" ) );
result = QBigInteger( "746985914068199510024843682108839444828414222769191520615967632362127522466922882591" )
+= QBigInteger( "-20487191102299831461877807785745372724903547246374023" );
QCOMPARE( result.toString(), QString( "746985914068199510024843682108818957637311922937729642808181886989402618919676508568" ) );
QCOMPARE( result, QBigInteger( "746985914068199510024843682108818957637311922937729642808181886989402618919676508568" ) );
result = QBigInteger( "-4" )
+= QBigInteger( "-2344390090753264806043234960981151613122271366762590006930318876906455201397017135" );
QCOMPARE( result.toString(), QString( "-2344390090753264806043234960981151613122271366762590006930318876906455201397017139" ) );
QCOMPARE( result, QBigInteger( "-2344390090753264806043234960981151613122271366762590006930318876906455201397017139" ) );
result = QBigInteger( "-44876180273995737337769331875058141129678736711749946388832275767882143882764" )
+= QBigInteger( "20982187786" );
QCOMPARE( result.toString(), QString( "-44876180273995737337769331875058141129678736711749946388832275767861161694978" ) );
QCOMPARE( result, QBigInteger( "-44876180273995737337769331875058141129678736711749946388832275767861161694978" ) );
result = QBigInteger( "-6019440082648243511340058232981487443695615379104154368957939907896782179207195666302228625496897271988494" )
+= QBigInteger( "532566302499155416003316607801593784583652720754079760364736422291735917382015688217276924340984564880" );
QCOMPARE( result.toString(), QString( "-6018907516345744355924054916373685849911031726383400289197575171474490443289813650614011348572556287423614" ) );
QCOMPARE( result, QBigInteger( "-6018907516345744355924054916373685849911031726383400289197575171474490443289813650614011348572556287423614" ) );
result = QBigInteger( "-73755471563616026847726349357167530833850959662921059052928229237814728719448868719278211294785998253117976812683153264088230182865250970217610487" )
+= QBigInteger( "-30100016097092378349958946184353117306134810372681" );
QCOMPARE( result.toString(), QString( "-73755471563616026847726349357167530833850959662921059052928229237814728719448868719278211294786028353134073905061503223034414535982557105027983168" ) );
QCOMPARE( result, QBigInteger( "-73755471563616026847726349357167530833850959662921059052928229237814728719448868719278211294786028353134073905061503223034414535982557105027983168" ) );
result = QBigInteger( "-2211177066689704345686852756638946306674958952044447080285364283965878599873864667094550865713828159912" )
+= QBigInteger( "-5365560439372456892007565798761606781997269201538475736814780300517383963455858081652308237033460360040921820049494698892905680307378540208" );
QCOMPARE( result.toString(), QString( "-5365560439372456892007565798761606784208446268228180082501633057156330270130817033696755317318824644006800419923359365987456546021206700120" ) );
QCOMPARE( result, QBigInteger( "-5365560439372456892007565798761606784208446268228180082501633057156330270130817033696755317318824644006800419923359365987456546021206700120" ) );
result = QBigInteger( "6074122512337108841968521649035076841633691574254417104144285970819068715158037023149867252146570418484850234979838064249373816163440" )
+= QBigInteger( "301843614094506325875637699" );
QCOMPARE( result.toString(), QString( "6074122512337108841968521649035076841633691574254417104144285970819068715158037023149867252146570418484850536823452158755699691801139" ) );
QCOMPARE( result, QBigInteger( "6074122512337108841968521649035076841633691574254417104144285970819068715158037023149867252146570418484850536823452158755699691801139" ) );
result = QBigInteger( "-518214776931158149908771340564348982010543985108065053479219152734659892042499774128809654713651547833087206893256740737426200715673766732196603988" )
+= QBigInteger( "-29835172557747693726115525887386137004674545311422557345658884038760353928226157702249175218280718951979" );
QCOMPARE( result.toString(), QString( "-518214776931158149908771340564348982010544014943237611226912878850185779428636778803354966136208893491971245653610668963583902964848985012915555967" ) );
QCOMPARE( result, QBigInteger( "-518214776931158149908771340564348982010544014943237611226912878850185779428636778803354966136208893491971245653610668963583902964848985012915555967" ) );
result = QBigInteger( "15937412249227240968245047444122" )
+= QBigInteger( "186214680376169426108822450700978827886569053440254258585576645530381613666540347032550716844628275956253" );
QCOMPARE( result.toString(), QString( "186214680376169426108822450700978827886569053440254258585576645530381613682477759281777957812873323400375" ) );
QCOMPARE( result, QBigInteger( "186214680376169426108822450700978827886569053440254258585576645530381613682477759281777957812873323400375" ) );
result = QBigInteger( "-12528010116258685855047504252928107623923105458701761707911969527003855713485846140551107967495813584097081777160" )
+= QBigInteger( "-539986280927242338236008809854961759996986302156061552378097160849129372827386927545686899193598721998757419572890" );
QCOMPARE( result.toString(), QString( "-552514291043501024091056314107889867620909407614763314086009130376133228540872773686238007161094535582854501350050" ) );
QCOMPARE( result, QBigInteger( "-552514291043501024091056314107889867620909407614763314086009130376133228540872773686238007161094535582854501350050" ) );
result = QBigInteger( "-2454746908" )
+= QBigInteger( "-3822957127889394780055242156360370187075592078655552376050604679934415014573879513870030211860839641756441626913419699098985245833920954444218" );
QCOMPARE( result.toString(), QString( "-3822957127889394780055242156360370187075592078655552376050604679934415014573879513870030211860839641756441626913419699098985245833923409191126" ) );
QCOMPARE( result, QBigInteger( "-3822957127889394780055242156360370187075592078655552376050604679934415014573879513870030211860839641756441626913419699098985245833923409191126" ) );
result = QBigInteger( "-54288706131860071583318409080596095357980447323635" )
+= QBigInteger( "-425339410556015631098973742993327323051438456819027069606294261157940297643297240559452124432779202181589763874" );
QCOMPARE( result.toString(), QString( "-425339410556015631098973742993327323051438456819027069606294315446646429503368823877861205028874560162037087509" ) );
QCOMPARE( result, QBigInteger( "-425339410556015631098973742993327323051438456819027069606294315446646429503368823877861205028874560162037087509" ) );
result = QBigInteger( "1418766894051319870818496026367686195459604395660119754151922014257535705077512233275240217434104" )
+= QBigInteger( "-111987390206074845527" );
QCOMPARE( result.toString(), QString( "1418766894051319870818496026367686195459604395660119754151922014257535705077400245885034142588577" ) );
QCOMPARE( result, QBigInteger( "1418766894051319870818496026367686195459604395660119754151922014257535705077400245885034142588577" ) );
result = QBigInteger( "-690410131860410477456103857594543515409677479242833618634809302452962600476353286822550168231234854116465153078845744722987447719420052500874721214723" )
+= QBigInteger( "-2584690377433946747311356992432788361455494791066739384837409609897387109736539600623155880918146331681272708396146283818299" );
QCOMPARE( result.toString(), QString( "-690410131860410477456103860179233892843624226554190611067597663908457391543092671659959778128621963853004753702001625641133779400692760897021005033022" ) );
QCOMPARE( result, QBigInteger( "-690410131860410477456103860179233892843624226554190611067597663908457391543092671659959778128621963853004753702001625641133779400692760897021005033022" ) );
result = QBigInteger( "-2326153002179462643778624079324592172489363679671158" )
+= QBigInteger( "-109819757548464054181938329012610459679" );
QCOMPARE( result.toString(), QString( "-2326153002179572463536172543378774110818376290130837" ) );
QCOMPARE( result, QBigInteger( "-2326153002179572463536172543378774110818376290130837" ) );
result = QBigInteger( "-4428752250566525488353857709194941742993785578807911414016959206453045495320705299466107784149485981354180907411034982168391" )
+= QBigInteger( "-39247778259374215325521768005388007526581235832446540589720560855741992694947322437679214611686905696" );
QCOMPARE( result.toString(), QString( "-4428752250566525488353896956973201117209111100575916802024485787688877941861295020026963526142180928676618586625646669074087" ) );
QCOMPARE( result, QBigInteger( "-4428752250566525488353896956973201117209111100575916802024485787688877941861295020026963526142180928676618586625646669074087" ) );
result = QBigInteger( "3047" )
+= QBigInteger( "-73564587850313153523776932163719610733433776890390204618040173797196000100856070829277943048343156165795282307508135277641315214" );
QCOMPARE( result.toString(), QString( "-73564587850313153523776932163719610733433776890390204618040173797196000100856070829277943048343156165795282307508135277641312167" ) );
QCOMPARE( result, QBigInteger( "-73564587850313153523776932163719610733433776890390204618040173797196000100856070829277943048343156165795282307508135277641312167" ) );
result = QBigInteger( "71397189765381049110362731262243394989390499523719445987286843598407339615555456955143712741779487184644001767776382991377987516772847242986" )
+= QBigInteger( "-5821969555717973232123574849275726788359152255219972775831" );
QCOMPARE( result.toString(), QString( "71397189765381049110362731262243394989390499523719445987286843598407339615555456949321743186061513952520426918500656203018835261552874467155" ) );
QCOMPARE( result, QBigInteger( "71397189765381049110362731262243394989390499523719445987286843598407339615555456949321743186061513952520426918500656203018835261552874467155" ) );
result = QBigInteger( "-181409752656613138777964092635909379021826360390960647186726991165227400176766831466541160049935205507919070233410228328274" )
+= QBigInteger( "-523301382154855044703947051892202646490840761177533623732372519689918420769842424772676407501350528096714904915297347684247802773107355881667545916901" );
QCOMPARE( result.toString(), QString( "-523301382154855044703947052073612399147453899955497716368281898711744781160803071959403398666577928273481736381838507734183008281026426115077774245175" ) );
QCOMPARE( result, QBigInteger( "-523301382154855044703947052073612399147453899955497716368281898711744781160803071959403398666577928273481736381838507734183008281026426115077774245175" ) );
result = QBigInteger( "6858961373707073067" )
+= QBigInteger( "-334051508933893061433844279764271107181974906283364991309903077649971606436918071327072869826471946094594594115614990907" );
QCOMPARE( result.toString(), QString( "-334051508933893061433844279764271107181974906283364991309903077649971606436918071327072869826471946087735632741907917840" ) );
QCOMPARE( result, QBigInteger( "-334051508933893061433844279764271107181974906283364991309903077649971606436918071327072869826471946087735632741907917840" ) );
result = QBigInteger( "-23635098930374569407171906960429616870908424281519944658490940109956689534874971218650241680916564611" )
+= QBigInteger( "-18958917875779522833599589133142827952448539301142718746979271443846670235982743793439686626736428198541647202983677887505430060922528525205" );
QCOMPARE( result.toString(), QString( "-18958917875779522833599589133142827952472174400073093316386443350807099852853652217721206571394919138651603892518552858724080302603445089816" ) );
QCOMPARE( result, QBigInteger( "-18958917875779522833599589133142827952472174400073093316386443350807099852853652217721206571394919138651603892518552858724080302603445089816" ) );
// Botan's subtraction tests
result = QBigInteger( "0" )
-= QBigInteger( "0" );
QCOMPARE( result.toString(), QString( "0" ) );
QCOMPARE( result, QBigInteger( "0" ) );
result = QBigInteger( "0" )
-= QBigInteger( "1" );
QCOMPARE( result.toString(), QString( "-1" ) );
QCOMPARE( result, QBigInteger( "-1" ) );
result = QBigInteger( "0" )
-= QBigInteger( "4294967296" );
QCOMPARE( result.toString(), QString( "-4294967296" ) );
QCOMPARE( result, QBigInteger( "-4294967296" ) );
// Next test is labelled # 2^512 - 1
result = QBigInteger( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095" )
-= QBigInteger( "1" );
QCOMPARE( result.toString(), QString( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084094" ) );
QCOMPARE( result, QBigInteger( "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084094" ) );
result = QBigInteger( "89094716573076464980713547115099137014719483620102078148320806773871083148864" )
-= QBigInteger( "49505213825110728957828173754776257356620450607893971553289366249708672306581" );
QCOMPARE( result.toString(), QString( "39589502747965736022885373360322879658099033012208106595031440524162410842283" ) );
QCOMPARE( result, QBigInteger( "39589502747965736022885373360322879658099033012208106595031440524162410842283" ) );
result = QBigInteger( "65894747009896006767807716946835412110318548717263922395390971078905789585431" )
-= QBigInteger( "3884269741925508225990715416862047284194603799902650748631039608684367281358" );
QCOMPARE( result.toString(), QString( "62010477267970498541817001529973364826123944917361271646759931470221422304073" ) );
QCOMPARE( result, QBigInteger( "62010477267970498541817001529973364826123944917361271646759931470221422304073" ) );
result = QBigInteger( "5950196396451977566902121301707054218364717196893101360011491777761952253736964709165962613347710607164178682987783755894811024288429224592316636383" )
-= QBigInteger( "8750653273562160761286422180115618621879821429145276197424652349306577311499807887070429373153777028581165316131683348567" );
QCOMPARE( result.toString(), QString( "5950196396451977566902121292956400944802556435606679179895873155882130824591688511741310264041133295664370795917354382741033995707263908460633287816" ) );
QCOMPARE( result, QBigInteger( "5950196396451977566902121292956400944802556435606679179895873155882130824591688511741310264041133295664370795917354382741033995707263908460633287816" ) );
result = QBigInteger( "9815262808265519920770782360080149146267723690" )
-= QBigInteger( "14067005768891609281364919358115291341352189918255780397560060748765650205261663193732434161580120817" );
QCOMPARE( result.toString(), QString( "-14067005768891609281364919358115291341352189918255780387744797940500130284490880833652285015312397127" ) );
QCOMPARE( result, QBigInteger( "-14067005768891609281364919358115291341352189918255780387744797940500130284490880833652285015312397127" ) );
result = QBigInteger( "-390149102941948621568479722346940666704376013734485343840154221605853412503154993878886490867020934777530894593416337175399865065870417717658815158195790" )
-= QBigInteger( "1456031684988128870809574635750149625240648487837308" );
QCOMPARE( result.toString(), QString( "-390149102941948621568479722346940666704376013734485343840154221605853412503154993878886490867020934778986926278404466046209439701620567342899463646033098" ) );
QCOMPARE( result, QBigInteger( "-390149102941948621568479722346940666704376013734485343840154221605853412503154993878886490867020934778986926278404466046209439701620567342899463646033098" ) );
result = QBigInteger( "7473774301764883450943" )
-= QBigInteger( "-26256369859367890755157372820052387483402723790185562908491933812453" );
QCOMPARE( result.toString(), QString( "26256369859367890755157372820052387483402723797659337210256817263396" ) );
QCOMPARE( result, QBigInteger( "26256369859367890755157372820052387483402723797659337210256817263396" ) );
result = QBigInteger( "36246343251214922024139186757009148849295485593397952003237349660142296147421019916619944353877490544706223768684758263065399016597969" )
-= QBigInteger( "2574427901445527995149185461475228850098549655325125750771680756403104624569522792792597223218143154924988199562355517064962665954307425375180" );
QCOMPARE( result.toString(), QString( "-2574427865199184743934263437336042093089400806029640157373728753165754964427226645371577306598198801047497654856131748380204402888908408777211" ) );
QCOMPARE( result, QBigInteger( "-2574427865199184743934263437336042093089400806029640157373728753165754964427226645371577306598198801047497654856131748380204402888908408777211" ) );
result = QBigInteger( "30129746266682790628283889040897642317014108334116727" )
-= QBigInteger( "-1580480523895398762563721715474380903630073871362143915864398724834897608423" );
QCOMPARE( result.toString(), QString( "1580480523895398762563751845220647586420702155251184813506715738943231725150" ) );
QCOMPARE( result, QBigInteger( "1580480523895398762563751845220647586420702155251184813506715738943231725150" ) );
result = QBigInteger( "-4614735863800137951667138933166372061" )
-= QBigInteger( "87175694379075561307234146162193190462135078700346746992273" );
QCOMPARE( result.toString(), QString( "-87175694379075561307238760898056990600086745839279913364334" ) );
QCOMPARE( result, QBigInteger( "-87175694379075561307238760898056990600086745839279913364334" ) );
result = QBigInteger( "-3753904" )
-= QBigInteger( "-11269137783745339515071988205310702154422777729974" );
QCOMPARE( result.toString(), QString( "11269137783745339515071988205310702154422773976070" ) );
QCOMPARE( result, QBigInteger( "11269137783745339515071988205310702154422773976070" ) );
result = QBigInteger( "592523948495379440082021279738170088402918858455470050140652787171830058864932939900794505955437856926902975870288" )
-= QBigInteger( "-205854658295495452479104108497931263758143158076949293929661651111" );
QCOMPARE( result.toString(), QString( "592523948495379440082021279738170088402918858455675904798948282624309162973430871164552649113514806220832637521399" ) );
QCOMPARE( result, QBigInteger( "592523948495379440082021279738170088402918858455675904798948282624309162973430871164552649113514806220832637521399" ) );
result = QBigInteger( "-33993701617495591491176844355" )
-= QBigInteger( "3438065097398894672826284379125235190693300918673662774192379185002391232383325160416036963599856704698280" );
QCOMPARE( result.toString(), QString( "-3438065097398894672826284379125235190693300918673662774192379185002391232383359154117654459191347881542635" ) );
QCOMPARE( result, QBigInteger( "-3438065097398894672826284379125235190693300918673662774192379185002391232383359154117654459191347881542635" ) );
result = QBigInteger( "26876428790838270949718735111909136008255051776703" )
-= QBigInteger( "-1781128112966810373286192008831149275546995635268767241859967609117529616872536681035700534316457543887601645022" );
QCOMPARE( result.toString(), QString( "1781128112966810373286192008831149275546995635268767241859967635993958407710807630754435646225593552142653421725" ) );
QCOMPARE( result, QBigInteger( "1781128112966810373286192008831149275546995635268767241859967635993958407710807630754435646225593552142653421725" ) );
result = QBigInteger( "2059771092932179758019770618974659367350250375647433386639519387\
69317693429941871882153770641334267205446421916220398066553188" )
-= QBigInteger( "3342500267594994347156312297990633112620923791590960237694328174171473763026" );
QCOMPARE( result.toString(), QString( "205977109293217975801977061897465936735025037564739996163684343774970537117643881249041149717542676245208727588046226592790162" ) );
QCOMPARE( result, QBigInteger( "205977109293217975801977061897465936735025037564739996163684343774970537117643881249041149717542676245208727588046226592790162" ) );
result = QBigInteger( "5545520403000578843599072515870982842927227412121917598877293331575380404618111609" )
-= QBigInteger( "5991287327241003718821424770352575362437680738923552868139860461945460339860477495902" );
QCOMPARE( result.toString(), QString( "-5985741806838003139977825697836704379594753511511430950540983168613884959455859384293" ) );
QCOMPARE( result, QBigInteger( "-5985741806838003139977825697836704379594753511511430950540983168613884959455859384293" ) );
result = QBigInteger( "248039029608125071340" )
-= QBigInteger( "3664608673" );
QCOMPARE( result.toString(), QString( "248039029604460462667" ) );
QCOMPARE( result, QBigInteger( "248039029604460462667" ) );
result = QBigInteger( "15425705711415937103627" )
-= QBigInteger( "-1435504065517745703440045276868982910754081405474123003767554211132837427846963435621523810229738262235546179779885824" );
QCOMPARE( result.toString(), QString( "1435504065517745703440045276868982910754081405474123003767554211132837427846963435621523810229753687941257595716989451" ) );
QCOMPARE( result, QBigInteger( "1435504065517745703440045276868982910754081405474123003767554211132837427846963435621523810229753687941257595716989451" ) );
result = QBigInteger( "50882847205108645607281568922683652688671738236030732914347600821086" )
-= QBigInteger( "12176160963158" );
QCOMPARE( result.toString(), QString( "50882847205108645607281568922683652688671738236030732902171439857928" ) );
QCOMPARE( result, QBigInteger( "50882847205108645607281568922683652688671738236030732902171439857928" ) );
result = QBigInteger( "-35426518565985818947670047877033022885542172461973566228509771053416312543201815881190953762207629232160412058300173038824256783171761132" )
-= QBigInteger( "-4864862607366468843184694353123830534588538011093812418208808135799" );
QCOMPARE( result.toString(), QString( "-35426518565985818947670047877033022885542172461973566228509771053416307678339208514722110577513276108329877469762161945011838574363625333" ) );
QCOMPARE( result, QBigInteger( "-35426518565985818947670047877033022885542172461973566228509771053416307678339208514722110577513276108329877469762161945011838574363625333" ) );
result = QBigInteger( "-1428596214712268310382144828171384812520179141608121870013556402879770424002218157546599921571184" )
-= QBigInteger( "-4054101" );
QCOMPARE( result.toString(), QString( "-1428596214712268310382144828171384812520179141608121870013556402879770424002218157546599917517083" ) );
QCOMPARE( result, QBigInteger( "-1428596214712268310382144828171384812520179141608121870013556402879770424002218157546599917517083" ) );
result = QBigInteger( "-200931" )
-= QBigInteger( "-44558802460130495759482832913160717791151786725570519475449607659705171682283111490834930835045735142966847483009157514950177565952218520297258834187372" );
QCOMPARE( result.toString(), QString( "44558802460130495759482832913160717791151786725570519475449607659705171682283111490834930835045735142966847483009157514950177565952218520297258833986441" ) );
QCOMPARE( result, QBigInteger( "44558802460130495759482832913160717791151786725570519475449607659705171682283111490834930835045735142966847483009157514950177565952218520297258833986441" ) );
result = QBigInteger( "105704314890799915321259" )
-= QBigInteger( "827923545945076415574912438499169814414563066877494100831657761190490697473854369477784874118787495351405549803329615347120938123226038208" );
QCOMPARE( result.toString(), QString( "-827923545945076415574912438499169814414563066877494100831657761190490697473854369477784874118787495351405549803329509642806047323310716949" ) );
QCOMPARE( result, QBigInteger( "-827923545945076415574912438499169814414563066877494100831657761190490697473854369477784874118787495351405549803329509642806047323310716949" ) );
result = QBigInteger( "1448979433940064018828919290452280235308901982649341" )
-= QBigInteger( "303926827425887072291878308433008512899006711759770318009" );
QCOMPARE( result.toString(), QString( "-303925378446453132227859479513718060618771402857787668668" ) );
QCOMPARE( result, QBigInteger( "-303925378446453132227859479513718060618771402857787668668" ) );
result = QBigInteger( "-243237595290235750457450892290434789864" )
-= QBigInteger( "19817702076334276402981273067417321098467533300947463865383702005126562800253466403934608765512316565811954342319565128573969" );
QCOMPARE( result.toString(), QString( "-19817702076334276402981273067417321098467533300947463865383702005126562800253466403934852003107606801562411793211855563363833" ) );
QCOMPARE( result, QBigInteger( "-19817702076334276402981273067417321098467533300947463865383702005126562800253466403934852003107606801562411793211855563363833" ) );
result = QBigInteger( "294037338365659932242802023634" )
-= QBigInteger( "4401245995535867764294876849802142926077599828776505639975554254356763769548465" );
QCOMPARE( result.toString(), QString( "-4401245995535867764294876849802142926077599828776211602637188594424520967524831" ) );
QCOMPARE( result, QBigInteger( "-4401245995535867764294876849802142926077599828776211602637188594424520967524831" ) );
result = QBigInteger( "7303853946195223307036710881687367004566538357189824031021831088365362" )
-= QBigInteger( "119286025999378935715794641163321741" );
QCOMPARE( result.toString(), QString( "7303853946195223307036710881687366885280512357810888315227189925043621" ) );
QCOMPARE( result, QBigInteger( "7303853946195223307036710881687366885280512357810888315227189925043621" ) );
result = QBigInteger( "571167355343287235687602610714110416067426289363505412908804940696550592413192300554016875" )
-= QBigInteger( "15872188842802631759540597" );
QCOMPARE( result.toString(), QString( "571167355343287235687602610714110416067426289363505412908804940680678403570389668794476278" ) );
QCOMPARE( result, QBigInteger( "571167355343287235687602610714110416067426289363505412908804940680678403570389668794476278" ) );
result = QBigInteger( "1002240129784524388754179399598974973256811336031329881209395070412702275169416754240" )
-= QBigInteger( "59429482478860591343145393540420033516478305952872349006715789477946474753657206800070515207967709079933420746952" );
QCOMPARE( result.toString(), QString( "-59429482478860591343145393539417793386693781564118169607116814504689663417625876918861120137555006804764003992712" ) );
QCOMPARE( result, QBigInteger( "-59429482478860591343145393539417793386693781564118169607116814504689663417625876918861120137555006804764003992712" ) );
result = QBigInteger( "1370431648825444838359719050380239722263203134555431526491525074601463042144798545817957389" )
-= QBigInteger( "3473869878" );
QCOMPARE( result.toString(), QString( "1370431648825444838359719050380239722263203134555431526491525074601463042144798542344087511" ) );
QCOMPARE( result, QBigInteger( "1370431648825444838359719050380239722263203134555431526491525074601463042144798542344087511" ) );
result = QBigInteger( "8548280229254726209" )
-= QBigInteger( "33066125035269904981849320434016892734943145935582141989968280846973981913056248918" );
QCOMPARE( result.toString(), QString( "-33066125035269904981849320434016892734943145935582141989968280838425701683801522709" ) );
QCOMPARE( result, QBigInteger( "-33066125035269904981849320434016892734943145935582141989968280838425701683801522709" ) );
result = QBigInteger( "-19023558832687506489508150795966332175990129963029928958584170111759630293276939647334082100169102538364437859846398095065171936899503" )
-= QBigInteger( "24899271127523545342283468762809653407638631966220124695751976894193103779443050843040771191227522843088079031762445684377195650493065096847292797" );
QCOMPARE( result.toString(), QString( "-24899271127542568901116156269299161558434598298396114825715006823151687949554810473334048130874856925188248134300810122237042048588130268784192300" ) );
QCOMPARE( result, QBigInteger( "-24899271127542568901116156269299161558434598298396114825715006823151687949554810473334048130874856925188248134300810122237042048588130268784192300" ) );
result = QBigInteger( "-1800353575522706389288305623797196690530870204356722928042061228497437075035917720399302198953687023" )
-= QBigInteger( "-11875668261530466053708538730940776412171106483072624532757177471384128016458332544642788404765469924496127460164" );
QCOMPARE( result.toString(), QString( "11875668261528665700133016024551488106547309286382093662552820748456085955229835107567752487045070622297173773141" ) );
QCOMPARE( result, QBigInteger( "11875668261528665700133016024551488106547309286382093662552820748456085955229835107567752487045070622297173773141" ) );
result = QBigInteger( "-29861551039945217879" )
-= QBigInteger( "1113473025916855642353456146647542930581669082348409639697282960877889226500319996380838232582376232872868947624793789212829885934" );
QCOMPARE( result.toString(), QString( "-1113473025916855642353456146647542930581669082348409639697282960877889226500319996380838232582376232872868947654655340252775103813" ) );
QCOMPARE( result, QBigInteger( "-1113473025916855642353456146647542930581669082348409639697282960877889226500319996380838232582376232872868947654655340252775103813" ) );
result = QBigInteger( "565532963656761153838218277564957917658707297649757920676303301655328103665512287797108510139837643506491641987188791892506290" )
-= QBigInteger( "-2188105671531473889939411772533707" );
QCOMPARE( result.toString(), QString( "565532963656761153838218277564957917658707297649757920676303301655328103665512287797108510142025749178023115877128203665039997" ) );
QCOMPARE( result, QBigInteger( "565532963656761153838218277564957917658707297649757920676303301655328103665512287797108510142025749178023115877128203665039997" ) );
result = QBigInteger( "-349535960680522202843083381184496349093812380954435872337802226" )
-= QBigInteger( "-1829600726218222026679938" );
QCOMPARE( result.toString(), QString( "-349535960680522202843083381184496349091982780228217650311122288" ) );
QCOMPARE( result, QBigInteger( "-349535960680522202843083381184496349091982780228217650311122288" ) );
result = QBigInteger( "-1" ) -= QBigInteger( "-6726974989587128275" );
QCOMPARE( result.toString(), QString( "6726974989587128274" ) );
QCOMPARE( result, QBigInteger( "6726974989587128274" ) );
result = QBigInteger( "-107142709838121196902389095205618516687047338619382145236348309762148611647954748824" )
-= QBigInteger( "42484103615491" );
QCOMPARE( result.toString(), QString( "-107142709838121196902389095205618516687047338619382145236348309762148654132058364315" ) );
QCOMPARE( result, QBigInteger( "-107142709838121196902389095205618516687047338619382145236348309762148654132058364315" ) );
result = QBigInteger( "-90546630430085769764839607528116121381848878494574360812027599640018921358040178215575723" )
-= QBigInteger( "-118922408531468986902800063237122125617455464103913195171141030774109638861272017660698580914239435114280434761425243" );
QCOMPARE( result.toString(), QString( "118922408531468986902800063146575495187369694339073587643024909392260760366697656848670981274220513756240256545849520" ) );
QCOMPARE( result, QBigInteger( "118922408531468986902800063146575495187369694339073587643024909392260760366697656848670981274220513756240256545849520" ) );
result = QBigInteger( "-5545044667082427128801726416727657360001588430113578182850657573063241939882570324573086267287272360432363387213743735507218270373633222520429" )
-= QBigInteger( "-151423255459028627628896755237194376177115" );
QCOMPARE( result.toString(), QString( "-5545044667082427128801726416727657360001588430113578182850657573063241939882570324573086267287272360280940131754715107878321515136438846343314" ) );
QCOMPARE( result, QBigInteger( "-5545044667082427128801726416727657360001588430113578182850657573063241939882570324573086267287272360280940131754715107878321515136438846343314" ) );
result = QBigInteger( "-5247636471953421659649611318164848102069" )
-= QBigInteger( "-4024324110573096565232590473170599175885004" );
QCOMPARE( result.toString(), QString( "4019076474101143143572940861852434327782935" ) );
QCOMPARE( result, QBigInteger( "4019076474101143143572940861852434327782935" ) );
result = QBigInteger( "39412892606015043322484854253879371723186457838590224795040178472832" )
-= QBigInteger( "-5038321321957452145034687815432890684825466579123474921848465393400312" );
QCOMPARE( result.toString(), QString( "5077734214563467188357172669686770056548653036962065146643505571873144" ) );
QCOMPARE( result, QBigInteger( "5077734214563467188357172669686770056548653036962065146643505571873144" ) );
result = QBigInteger( "-55979414588009227035683624505208766753187469727799640277204274207843317583292736333912783829528270272642583004969175230274821" )
-= QBigInteger( "-109633110576212669339535976775635762395927171313557427036242111476016398579345366908401334025571265714128108308032073779442181369365924213118258269679" );
QCOMPARE( result.toString(), QString( "109633110576212669339535920796221174386700135629932921827475358288546670779705089704127126182253682421391774395248244251171908726782919243943027994858" ) );
QCOMPARE( result, QBigInteger( "109633110576212669339535920796221174386700135629932921827475358288546670779705089704127126182253682421391774395248244251171908726782919243943027994858" ) );
result = QBigInteger( "-38752353898173389347479216285772999906325286421302866854350737050533204094183249691110" )
-= QBigInteger( "2428819407377764342156426895396654728835493564788997075896393065230009911546390816091652653701035085361" );
QCOMPARE( result.toString(), QString( "-2428819407377764380908780793570044076314709850561996982221679486532876765897127866624856747884284776471" ) );
QCOMPARE( result, QBigInteger( "-2428819407377764380908780793570044076314709850561996982221679486532876765897127866624856747884284776471" ) );
result = QBigInteger( "-2784579005241382005249492720344" )
-= QBigInteger( "-164204542616919252351131740123094674" );
QCOMPARE( result.toString(), QString( "164201758037914010969126490630374330" ) );
QCOMPARE( result, QBigInteger( "164201758037914010969126490630374330" ) );
result = QBigInteger( "200948857420871544747808060972375039052401280822505804851732868100" )
-= QBigInteger( "-795957177479360455258269298038670876462147576765875895105714" );
QCOMPARE( result.toString(), QString( "200949653378049024108263319241673077723277742970082570727627973814" ) );
QCOMPARE( result, QBigInteger( "200949653378049024108263319241673077723277742970082570727627973814" ) );
result = QBigInteger( "217570540819" )
-= QBigInteger( "121955083597720420983384282166693307394185530431368476834980748302158718406063500763434561937200696970170700" );
QCOMPARE( result.toString(), QString( "-121955083597720420983384282166693307394185530431368476834980748302158718406063500763434561937200479399629881" ) );
QCOMPARE( result, QBigInteger( QString("-121955083597720420983384282166693307394185530431368476834980748302158718406063500763434561937200479399629881" ) ) );
result = QBigInteger( QString("2335319252198456765380587281374076367944") )
-= QBigInteger( QString("-4500271") );
QCOMPARE( result, QBigInteger( QString( "2335319252198456765380587281374080868215" ) ) );
result = QBigInteger( QString("-393694614027544181700073367147249369966344727230221941008713805434207925307052598" ) )
-= QBigInteger( QString("-153972676737062409261153899615588515236137907791841623991260363840680295565313157972489168132345521780658007459602823125797806770" ) );
QCOMPARE( result.toString(), QString( "153972676737062409261153899615588515236137907791447929377232819658980222198165908602522823405115299839649293654168615200490754172" ) );
QCOMPARE( result, QBigInteger( QString("153972676737062409261153899615588515236137907791447929377232819658980222198165908602522823405115299839649293654168615200490754172" ) ) );
result = QBigInteger( QString("114832549702862263167") )
-= QBigInteger( QString("12921864907229959558745276418830287875386673600892281022286597165773569473039953984775959232814911435097412913078625") );
QCOMPARE( result.toString(), QString( "-12921864907229959558745276418830287875386673600892281022286597165773569473039953984775959232814796602547710050815458" ) );
QCOMPARE( result, QBigInteger( QString( "-12921864907229959558745276418830287875386673600892281022286597165773569473039953984775959232814796602547710050815458" ) ) );
result = QBigInteger( QString( "6489502346837936889305337487724547956628371915228387374094443896266362105931065153072983425911767580294076594078932835008494777866083" ) )
-= QBigInteger( QString( "1099205476533612407829257935144627350486541654788267826664706620630745291371323154513322608446957760026881954001581" ) );
QCOMPARE( result.toString(), QString( "6489502346837936888206132011190935548799113980083760023607902241478094279266358532442238134540444425780753985631975074981612823864502" ) );
QCOMPARE( result, QBigInteger( QString("6489502346837936888206132011190935548799113980083760023607902241478094279266358532442238134540444425780753985631975074981612823864502" ) ) );
result = QBigInteger( QString("169991144123958754253801313173662977337850870273358378951640521601077152994474340806917796870911557233689087716056557" ) )
-= QBigInteger( QString("-15409167") );
QCOMPARE( result.toString(), QString( "169991144123958754253801313173662977337850870273358378951640521601077152994474340806917796870911557233689087731465724" ) );
QCOMPARE( result, QBigInteger( QString("169991144123958754253801313173662977337850870273358378951640521601077152994474340806917796870911557233689087731465724") ) );
}
QTEST_MAIN(BigIntUnitTest)

@ -1,5 +1,5 @@
/**
* Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
* Copyright (C) 2004-2005 Brad Hards <bradh@frogmouth.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -25,15 +25,19 @@
#ifndef BIGINTUNITTEST_H
#define BIGINTUNITTEST_H
#include "tester.h"
#include <QtCrypto>
#include <QtTest/QtTest>
class BigIntUnitTest : public Tester
class BigIntUnitTest : public QObject
{
public:
BigIntUnitTest();
Q_OBJECT
public:
private slots:
void initTestCase();
void cleanupTestCase();
void allTests();
private:
QCA::Initializer* m_init;
};
#endif

@ -0,0 +1,15 @@
TEMPLATE = app
TARGET = bigintunittest
DEPENDPATH += .
INCLUDEPATH += ../../include/QtCrypto
LIBS += -L../../lib -lqca
CONFIG += qttest thread console
# check target
QMAKE_EXTRA_TARGETS = check
check.depends = bigintunittest
check.commands = ./bigintunittest
# Input
HEADERS += bigintunittest.h
SOURCES += bigintunittest.cpp

@ -133,7 +133,7 @@ void CertUnitTest::checkClientCerts(const QString &provider)
CHECK( pubkey1.isDH(), false );
CHECK( pubkey1.isPublic(), true );
CHECK( pubkey1.isPrivate(), false );
XFAIL( pubkey1.bitSize(), 1024 );
CHECK( pubkey1.bitSize(), 1024 );
CHECK( client1.pathLimit(), 0 );
@ -226,7 +226,7 @@ void CertUnitTest::checkServerCerts(const QString &provider)
CHECK( pubkey1.isDH(), false );
CHECK( pubkey1.isPublic(), true );
CHECK( pubkey1.isPrivate(), false );
XFAIL( pubkey1.bitSize(), 1024 );
CHECK( pubkey1.bitSize(), 1024 );
CHECK( server1.pathLimit(), 0 );
@ -263,13 +263,15 @@ void CertUnitTest::allTests()
CHECK( QCA::haveSystemStore(), true );
if ( QCA::haveSystemStore() ) {
if ( QCA::haveSystemStore() && QCA::isSupported("cert") ) {
QCA::CertificateCollection collection1;
collection1 = QCA::systemStore();
}
checkCAcerts(QString());
checkClientCerts(QString());
checkServerCerts(QString());
if ( QCA::isSupported("cert") ) {
checkCAcerts(QString());
checkClientCerts(QString());
checkServerCerts(QString());
}
}

5
unittest/checkall Normal file

@ -0,0 +1,5 @@
export LD_LIBRARY_PATH="../../lib:$LD_LIBRARY_PATH"
cd bigintunittest && make check ; cd ..
cd hashunittest && make check ; cd ..
cd kdfunittest && make check ; cd ..
cd staticunittest && make check ; cd ..

@ -1167,7 +1167,8 @@ void CipherUnitTest::tripleDESTests()
SKIP("Triple DES, ECB not supported!");
else {
QCA::TripleDES cipherObj1( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, QCA::SymmetricKey( 24 ) );
CHECK( cipherObj1.keyLength().minimum(), 24 );
// we don't check minimum, because it varies whether you are
// doing 2 key or 3 key triple DES.
CHECK( cipherObj1.keyLength().maximum(), 24 );
CHECK( cipherObj1.blockSize(), (unsigned)8 );

@ -44,7 +44,7 @@ void DSAUnitTest::allTests()
QCA::KeyGenerator keygen;
CHECK( keygen.isBusy(), false );
CHECK( keygen.blocking(), true );
QCA::DLGroup group = keygen.createDLGroup(QCA::DSA_512);
QCA::DLGroup group = keygen.createDLGroup(QCA::DSA_1024);
CHECK( group.isNull(), false );
QCA::PrivateKey dsaKey = keygen.createDSA( group );
@ -57,8 +57,9 @@ void DSAUnitTest::allTests()
CHECK( dsaKey.canSign(), true );
CHECK( dsaKey.canDecrypt(), false );
CHECK( dsaKey.bitSize(), 1024 );
QCA::DSAPrivateKey dsaPrivKey = dsaKey.toDSA();
XFAIL( dsaPrivKey.bitSize(), 512 );
CHECK( dsaPrivKey.bitSize(), 1024 );
QSecureArray dsaDER = dsaKey.toDER();
CHECK( dsaDER.isEmpty(), false );

15
unittest/fixpaths.include Normal file

@ -0,0 +1,15 @@
// This is some boilerplate to ensure that we can load
// plugins from (a slightly hacked) build directory
//
// It is intended that this be #include'd from an init
// routine of some kind.
QStringList libpaths = QCoreApplication::libraryPaths();
// we prepend, because we prefer the uninstalled version
libpaths.prepend(QString("../../plugins/qca-openssl"));
libpaths.prepend(QString("../../plugins/qca-botan"));
libpaths.prepend(QString("../../plugins/qca-gcrypt"));
// you can add more paths here...
QCoreApplication::setLibraryPaths(libpaths);

@ -1,471 +0,0 @@
/**
* Copyright (C) 2004-2005 Brad Hards <bradh@frogmouth.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "hashunittest.h"
#include <QtCrypto>
#include <qfile.h>
HashUnitTest::HashUnitTest()
: Tester()
{
}
struct hashTestValues {
char *inputString;
char *expectedHash;
};
// These are as specified in RFC 1319
static struct hashTestValues md2TestValues[] = {
{ "", "8350e5a3e24c153df2275c9f80692773" },
{ "a", "32ec01ec4a6dac72c0ab96fb34c0b5d1" },
{ "abc", "da853b0d3f88d99b30283a69e6ded6bb" },
{ "message digest", "ab4f496bfb2a530b219ff33031fe06b0" },
{ "abcdefghijklmnopqrstuvwxyz", "4e8ddff3650292ab5a4108c3aa47940b" },
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"da33def2a42df13975352846c30338cd" },
{ "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
"d5976f79d83d3a0dc9806c3c66f3efd8" },
{ 0, 0 }
};
// These are as specified in RFC 1320
static struct hashTestValues md4TestValues[] = {
{ "", "31d6cfe0d16ae931b73c59d7e0c089c0" },
{ "a", "bde52cb31de33e46245e05fbdbd6fb24" },
{ "abc", "a448017aaf21d8525fc10ae87aa6729d" },
{ "message digest", "d9130a8164549fe818874806e1c7014b" },
{ "abcdefghijklmnopqrstuvwxyz", "d79e1c308aa5bbcdeea8ed63df412da9" },
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"043f8582f241db351ce627e153e7f0e4" },
{ "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
"e33b4ddc9c38f2199c3e7b164fcc0536" },
{ 0, 0 }
};
// These are as specified in RFC 1321
// They also match Australian Standard (AS) 2805.1.3.2-2000 Appendix A
static struct hashTestValues md5TestValues[] = {
{ "", "d41d8cd98f00b204e9800998ecf8427e" },
{ "a", "0cc175b9c0f1b6a831c399e269772661" },
{ "abc", "900150983cd24fb0d6963f7d28e17f72" },
{ "message digest", "f96b697d7cb7938d525a2f31aaf161d0" },
{ "abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b" },
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"d174ab98d277d9f5a5611c2c9f419d9f" },
{ "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
"57edf4a22be3c955ac49da2e2107b67a" },
{ 0, 0 }
};
// These are extracted from OpenOffice.org 1.1.2, in sal/workben/t_digest.c
// Check FIPS 180-1?
static struct hashTestValues sha0TestValues[] = {
{ "abc", "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880" },
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"d2516ee1acfa5baf33dfc1c471e438449ef134c8" },
{ 0, 0 }
};
// These are as specfied in FIPS 180-2. Matches RFC3174
// Some additions from Australian Standard (AS) 2805.13.3-2000
static struct hashTestValues sha1TestValues[] = {
// FIPS 180-2, Appendix A.1
{ "abc", "a9993e364706816aba3e25717850c26c9cd0d89d" },
// FIPS 180-2, Appendix A.2
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"84983e441c3bd26ebaae4aa1f95129e5e54670f1" },
// AS 2805.13.3-200 Appendix A
// has some duplicates from FIPS 180-2
{ "", "da39a3ee5e6b4b0d3255bfef95601890afd80709" },
{ "a", "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8" },
{ "abc", "a9993e364706816aba3e25717850c26c9cd0d89d" },
{ "abcdefghijklmnopqrstuvwxyz", "32d10c7b8cf96570ca04ce37f2a19d84240d3a89" },
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"84983e441c3bd26ebaae4aa1f95129e5e54670f1" },
{ 0, 0 }
};
// These are as specfied in FIPS 180-2
static struct hashTestValues sha256TestValues[] = {
// FIPS 180-2, Appendix B.1
{ "abc", "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" },
// FIPS 180-2, Appendix B.2
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" },
{ 0, 0 }
};
// These are as specfied in FIPS 180-2, change notice 1
static struct hashTestValues sha224TestValues[] = {
// FIPS 180-2, Appendix B.1
{ "abc", "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7" },
// FIPS 180-2, Appendix B.2
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" },
{ 0, 0 }
};
// These are as specfied in FIPS 180-2, and from Aaron Gifford's SHA2 tests
static struct hashTestValues sha384TestValues[] = {
// FIPS 180-2, Appendix D.1
{ "abc", "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7" },
// FIPS 180-2, Appendix D.2
{ "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
"09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039" },
// Aaron Gifford, vector002.info
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b" },
{ 0, 0 }
};
// These are as specfied in FIPS 180-2, and from Aaron Gifford's SHA2 tests
static struct hashTestValues sha512TestValues[] = {
// FIPS 180-2, Appendix C.1
{ "abc", "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" },
// FIPS 180-2, Appendix C.2
{ "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
"8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909" },
// Aaron Gifford, vector002.info
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445" },
{ 0, 0 }
};
// These are as specified in http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
// ISO/IEC 10118-3 costs a bit of money.
static struct hashTestValues ripemd160TestValues[] = {
{ "", "9c1185a5c5e9fc54612808977ee8f548b2258d31" },
{ "a", "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe" },
{ "abc", "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc" },
{ "message digest", "5d0689ef49d2fae572b881b123a85ffa21595f36" },
{ "abcdefghijklmnopqrstuvwxyz", "f71c27109c692c1b56bbdceb5b9d2865b3708dbc" },
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"12a053384a9c0c88e405a06c27dcf49ada62eb2b" },
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"b0e20b6e3116640286ed3a87a5713079b21f5189" },
{ "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
"9b752e45573d4b39f4dbd3323cab82bf63326bfb" },
{ 0, 0 }
};
void HashUnitTest::allTests()
{
QCA::Initializer init;
QString hashResult; // used as the actual result
QStringList providersToTest;
providersToTest.append("qca-openssl");
providersToTest.append("qca-gcrypt");
providersToTest.append("default");
for ( QStringList::Iterator it = providersToTest.begin(); it != providersToTest.end(); ++it ) {
if(!QCA::isSupported("md2"))
SKIP("MD2 not supported" );
else {
for (int n = 0; (0 != md2TestValues[n].expectedHash); n++) {
hashResult = QCA::MD2(*it).hashToString(QByteArray(md2TestValues[n].inputString));
CHECK( hashResult, QString(md2TestValues[n].expectedHash) );
}
}
if(!QCA::isSupported("md4"))
SKIP("MD4 not supported");
else {
for (int n = 0; (0 != md4TestValues[n].expectedHash); n++) {
hashResult = QCA::MD4(*it).hashToString(QByteArray(md4TestValues[n].inputString));
CHECK( hashResult, QString(md4TestValues[n].expectedHash) );
}
}
if(!QCA::isSupported("md5"))
SKIP("MD5 not supported");
else {
for (int n = 0; (0 != md5TestValues[n].expectedHash); n++) {
hashResult = QCA::MD5(*it).hashToString(QByteArray(md5TestValues[n].inputString));
CHECK( hashResult, QString(md5TestValues[n].expectedHash) );
}
QFile f1( "./data/empty" );
if ( f1.open( QIODevice::ReadOnly ) ) {
QCA::MD5 hashObj(*it);
hashObj.update( f1 );
CHECK( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "d41d8cd98f00b204e9800998ecf8427e" ) );
} else {
SKIP( "./data/empty could not be opened - do you need to create it?");
}
QFile f2( "./data/Botan-1.4.1.tar.bz2" );
if ( f2.open( QIODevice::ReadOnly ) ) {
QCA::MD5 hashObj(*it);
hashObj.update( f2 );
CHECK( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "7c4b3d8a360c6c3cb647160fa9adfe71" ) );
} else {
SKIP( "./data/Botan-1.4.1.tar.bz2 could not be opened - do you need to download it?");
}
QFile f3( "./data/linux-2.6.7.tar.bz2" );
if ( f3.open( QIODevice::ReadOnly ) ) {
QCA::MD5 hashObj(*it);
hashObj.update( f3 );
CHECK( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "a74671ea68b0e3c609e8785ed8497c14" ) );
} else {
SKIP( "./data/linux-2.6.7.tar.bz2 could not be opened - do you need to download it?");
}
QFile f4( "./data/scribus-1.2.tar.bz2" );
if ( f4.open( QIODevice::ReadOnly ) ) {
QCA::MD5 hashObj(*it);
hashObj.update( f4 );
CHECK( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "7d2c2b228f9a6ff82c9401fd54bdbe16" ) );
} else {
SKIP( "./data/scribus-1.2.tar.bz2 could not be opened - do you need to download it?");
}
}
if(!QCA::isSupported("sha0"))
SKIP("SHA0 not supported");
else {
for (int n = 0; (0 != sha0TestValues[n].expectedHash); n++) {
hashResult = QCA::SHA0(*it).hashToString(QByteArray(sha0TestValues[n].inputString));
CHECK( hashResult, QString(sha0TestValues[n].expectedHash) );
}
QByteArray fillerString;
fillerString.fill('a', 1000);
// This test extracted from OpenOffice.org 1.1.2, in sal/workben/t_digest.c
QCA::SHA0 shaHash(*it);
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
CHECK( QString(QCA::arrayToHex(shaHash.final())),
QString("3232affa48628a26653b5aaa44541fd90d690603" ) );
shaHash.clear();
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
CHECK( QString(QCA::arrayToHex(shaHash.final())),
QString("3232affa48628a26653b5aaa44541fd90d690603" ) );
}
if(!QCA::isSupported("sha1"))
SKIP("SHA1 not supported");
else {
for (int n = 0; (0 != sha1TestValues[n].expectedHash); n++) {
hashResult = QCA::SHA1(*it).hashToString(QByteArray(sha1TestValues[n].inputString));
CHECK( hashResult, QString(sha1TestValues[n].expectedHash) );
}
QByteArray fillerString;
fillerString.fill('a', 1000);
// This test extracted from OpenOffice.org 1.1.2, in sal/workben/t_digest.c
// It basically reflects FIPS 180-2, Appendix A.3
// Also as per AS 2805.13.3-2000 Appendix A
QCA::SHA1 shaHash(*it);
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
CHECK( QString(QCA::arrayToHex(shaHash.final())),
QString("34aa973cd4c4daa4f61eeb2bdbad27316534016f") );
QFile f1( "./data/empty" );
if ( f1.open( QIODevice::ReadOnly ) ) {
QCA::SHA1 hashObj(*it);
hashObj.update( f1 );
CHECK( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "da39a3ee5e6b4b0d3255bfef95601890afd80709" ) );
} else {
SKIP( "./data/empty could not be opened - do you need to create it?");
}
QFile f2( "./data/Botan-1.4.1.tar.bz2" );
if ( f2.open( QIODevice::ReadOnly ) ) {
QCA::SHA1 hashObj(*it);
hashObj.update( f2 );
CHECK( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "cda343591428a68e22bd2e349b890cbafb642cf7" ) );
} else {
SKIP( "./data/Botan-1.4.1.tar.bz2 could not be opened - do you need to download it?");
}
QFile f3( "./data/linux-2.6.7.tar.bz2" );
if ( f3.open( QIODevice::ReadOnly ) ) {
QCA::SHA1 hashObj(*it);
hashObj.update( f3 );
CHECK( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "a030a9c6dcd10c5d90a86f915ad4710084cbca71" ) );
} else {
SKIP( "./data/linux-2.6.7.tar.bz2 could not be opened - do you need to download it?");
}
QFile f4( "./data/scribus-1.2.tar.bz2" );
if ( f4.open( QIODevice::ReadOnly ) ) {
QCA::SHA1 hashObj(*it);
hashObj.update( f4 );
CHECK( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "a1fb6ed6acfd92381055b310d926d6e83e76ff1e" ) );
} else {
SKIP( "./data/scribus-1.2.tar.bz2 could not be opened - do you need to download it?");
}
}
if(!QCA::isSupported("sha224"))
SKIP("SHA224 not supported");
else {
for (int n = 0; (0 != sha224TestValues[n].expectedHash); n++) {
hashResult = QCA::SHA224(*it).hashToString(QByteArray(sha224TestValues[n].inputString));
CHECK( hashResult, QString(sha224TestValues[n].expectedHash) );
}
QByteArray fillerString;
fillerString.fill('a', 1000);
// This basically reflects FIPS 180-2, change notice 1, section 3
QCA::SHA224 shaHash(*it);
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
CHECK( QString(QCA::arrayToHex(shaHash.final())),
QString("20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67") );
}
if(!QCA::isSupported("sha256"))
SKIP("SHA256 not supported");
else {
for (int n = 0; (0 != sha256TestValues[n].expectedHash); n++) {
hashResult = QCA::SHA256(*it).hashToString(QByteArray(sha256TestValues[n].inputString));
CHECK( hashResult, QString(sha256TestValues[n].expectedHash) );
}
QByteArray fillerString;
fillerString.fill('a', 1000);
// This basically reflects FIPS 180-2, Appendix B.3
QCA::SHA256 shaHash(*it);
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
CHECK( QString(QCA::arrayToHex(shaHash.final())),
QString("cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0") );
}
if(!QCA::isSupported("sha384"))
SKIP("SHA384 not supported");
else {
for (int n = 0; (0 != sha384TestValues[n].expectedHash); n++) {
hashResult = QCA::SHA384(*it).hashToString(QByteArray(sha384TestValues[n].inputString));
CHECK( hashResult, QString(sha384TestValues[n].expectedHash) );
}
QByteArray fillerString;
fillerString.fill('a', 1000);
// This basically reflects FIPS 180-2, Appendix D.3
QCA::SHA384 shaHash(*it);
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
CHECK( QString(QCA::arrayToHex(shaHash.final())),
QString("9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985") );
}
if(!QCA::isSupported("sha512"))
SKIP("SHA512 not supported");
else {
for (int n = 0; (0 != sha512TestValues[n].expectedHash); n++) {
hashResult = QCA::SHA512(*it).hashToString(QByteArray(sha512TestValues[n].inputString));
CHECK( hashResult, QString(sha512TestValues[n].expectedHash) );
}
QByteArray fillerString;
fillerString.fill('a', 1000);
// This basically reflects FIPS 180-2, Appendix C.3
QCA::SHA512 shaHash;
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
CHECK( QString(QCA::arrayToHex(shaHash.final())),
QString("e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b") );
}
if(!QCA::isSupported("ripemd160"))
SKIP("RIPEMD160 not supported");
else {
for (int n = 0; (0 != ripemd160TestValues[n].expectedHash); n++) {
hashResult = QCA::RIPEMD160(*it).hashToString(QByteArray(ripemd160TestValues[n].inputString));
CHECK( hashResult, QString(ripemd160TestValues[n].expectedHash) );
}
// This is the "million times 'a' test"
QByteArray fillerString;
fillerString.fill('a', 1000);
QCA::RIPEMD160 shaHash(*it);
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
CHECK( QString(QCA::arrayToHex(shaHash.final())),
QString("52783243c1697bdbe16d37f97f68f08325dc1528") );
// This is the "8 rounds of 1234567890" test.
// It also ensure that we can re-use hash objects correctly.
static char bindata[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30 };
QByteArray fillerArray( bindata, sizeof(bindata) ); // "1234567890"
shaHash.clear();
for (int i=0; i<8; i++)
shaHash.update(fillerArray);
CHECK( QString(QCA::arrayToHex(shaHash.final())),
QString("9b752e45573d4b39f4dbd3323cab82bf63326bfb") );
}
}
}

@ -0,0 +1,744 @@
/**
* Copyright (C) 2004-2005 Brad Hards <bradh@frogmouth.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "hashunittest.h"
#include <qfile.h>
void HashUnitTest::initTestCase()
{
m_init = new QCA::Initializer;
#include "../fixpaths.include"
}
void HashUnitTest::cleanupTestCase()
{
delete m_init;
}
void HashUnitTest::md2test_data()
{
// These are as specified in RFC 1319
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QString>("expectedHash");
QTest::newRow("md2()") << QByteArray("") << QString("8350e5a3e24c153df2275c9f80692773");
QTest::newRow("md2(a)") << QByteArray("a") << QString("32ec01ec4a6dac72c0ab96fb34c0b5d1");
QTest::newRow("md2(abc)") << QByteArray("abc")
<< QString("da853b0d3f88d99b30283a69e6ded6bb");
QTest::newRow("md2(messageDigest)") << QByteArray("message digest")
<< QString("ab4f496bfb2a530b219ff33031fe06b0");
QTest::newRow("md2([a-z])") << QByteArray("abcdefghijklmnopqrstuvwxyz")
<< QString("4e8ddff3650292ab5a4108c3aa47940b");
QTest::newRow("md2([A-z,0-9])") << QByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
<< QString("da33def2a42df13975352846c30338cd");
QTest::newRow("md2(nums)") << QByteArray("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
<< QString("d5976f79d83d3a0dc9806c3c66f3efd8");
}
void HashUnitTest::md2test()
{
QStringList providersToTest;
providersToTest.append("qca-openssl");
// no MD2 support for libgcrypt...
providersToTest.append("qca-botan");
QFETCH(QByteArray, input);
QFETCH(QString, expectedHash);
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("md2", provider))
QWARN(QString("MD2 not supported for "+provider).toLocal8Bit());
else {
QString hashResult = QCA::MD2(provider).hashToString(input);
QCOMPARE( hashResult, expectedHash );
}
}
}
void HashUnitTest::md4test_data()
{
// These are as specified in RFC 1320
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QString>("expectedHash");
QTest::newRow("md4()") << QByteArray("") << QString("31d6cfe0d16ae931b73c59d7e0c089c0");
QTest::newRow("md4(a)") << QByteArray("a") << QString("bde52cb31de33e46245e05fbdbd6fb24");
QTest::newRow("md4(abc)") << QByteArray("abc")
<< QString("a448017aaf21d8525fc10ae87aa6729d");
QTest::newRow("md4(messageDigest)") << QByteArray("message digest")
<< QString("d9130a8164549fe818874806e1c7014b");
QTest::newRow("md4([a-z])") << QByteArray("abcdefghijklmnopqrstuvwxyz")
<< QString("d79e1c308aa5bbcdeea8ed63df412da9");
QTest::newRow("md4([A-z,0-9])") << QByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
<< QString("043f8582f241db351ce627e153e7f0e4");
QTest::newRow("md4(nums)") << QByteArray("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
<< QString("e33b4ddc9c38f2199c3e7b164fcc0536");
}
void HashUnitTest::md4test()
{
QStringList providersToTest;
providersToTest.append("qca-openssl");
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
QFETCH(QByteArray, input);
QFETCH(QString, expectedHash);
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("md4", provider))
QWARN(QString("MD4 not supported for "+provider).toLocal8Bit());
else {
QString hashResult = QCA::MD4(provider).hashToString(input);
QCOMPARE( hashResult, expectedHash );
}
}
}
void HashUnitTest::md5test_data()
{
// These are as specified in RFC 1321
// They also match Australian Standard (AS) 2805.1.3.2-2000 Appendix A
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QString>("expectedHash");
QTest::newRow("md5()") << QByteArray("") << QString("d41d8cd98f00b204e9800998ecf8427e");
QTest::newRow("md5(a)") << QByteArray("a") << QString("0cc175b9c0f1b6a831c399e269772661");
QTest::newRow("md5(abc)") << QByteArray("abc")
<< QString("900150983cd24fb0d6963f7d28e17f72");
QTest::newRow("md5(messageDigest)") << QByteArray("message digest")
<< QString("f96b697d7cb7938d525a2f31aaf161d0");
QTest::newRow("md5([a-z])") << QByteArray("abcdefghijklmnopqrstuvwxyz")
<< QString("c3fcd3d76192e4007dfb496cca67e13b");
QTest::newRow("md5([A-z,0-9])") << QByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
<< QString("d174ab98d277d9f5a5611c2c9f419d9f");
QTest::newRow("md5(nums)") << QByteArray("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
<< QString("57edf4a22be3c955ac49da2e2107b67a");
}
void HashUnitTest::md5test()
{
QStringList providersToTest;
providersToTest.append("qca-openssl");
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
providersToTest.append("default");
QFETCH(QByteArray, input);
QFETCH(QString, expectedHash);
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("md5", provider))
QWARN(QString("MD5 not supported for "+provider).toLocal8Bit());
else {
QString hashResult = QCA::MD5(provider).hashToString(input);
QCOMPARE( hashResult, expectedHash );
}
}
}
void HashUnitTest::md5filetest()
{
QStringList providersToTest;
providersToTest.append("qca-openssl");
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
providersToTest.append("default");
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("md5", provider))
QWARN(QString("MD5 not supported for "+provider).toLocal8Bit());
else {
QFile f1( "./data/empty" );
if ( f1.open( QIODevice::ReadOnly ) ) {
QCA::MD5 hashObj(provider);
hashObj.update( f1 );
QCOMPARE( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "d41d8cd98f00b204e9800998ecf8427e" ) );
} else {
QWARN( "./data/empty could not be opened - do you need to create it?");
}
QFile f2( "./data/Botan-1.4.1.tar.bz2" );
if ( f2.open( QIODevice::ReadOnly ) ) {
QCA::MD5 hashObj(provider);
hashObj.update( f2 );
QCOMPARE( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "7c4b3d8a360c6c3cb647160fa9adfe71" ) );
} else {
QWARN( "./data/Botan-1.4.1.tar.bz2 could not be opened - do you need to download it?");
}
QFile f3( "./data/linux-2.6.7.tar.bz2" );
if ( f3.open( QIODevice::ReadOnly ) ) {
QCA::MD5 hashObj(provider);
hashObj.update( f3 );
QCOMPARE( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "a74671ea68b0e3c609e8785ed8497c14" ) );
} else {
QWARN( "./data/linux-2.6.7.tar.bz2 could not be opened - do you need to download it?");
}
QFile f4( "./data/scribus-1.2.tar.bz2" );
if ( f4.open( QIODevice::ReadOnly ) ) {
QCA::MD5 hashObj(provider);
hashObj.update( f4 );
QCOMPARE( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "7d2c2b228f9a6ff82c9401fd54bdbe16" ) );
} else {
QWARN( "./data/scribus-1.2.tar.bz2 could not be opened - do you need to download it?");
}
}
}
}
void HashUnitTest::sha0test_data()
{
// These are extracted from OpenOffice.org 1.1.2, in sal/workben/t_digest.c
// Check FIPS 180-1?
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QString>("expectedHash");
QTest::newRow("sha0(abc)") << QByteArray("abc") << QString("0164b8a914cd2a5e74c4f7ff082c4d97f1edf880");
QTest::newRow("sha0(abc)") << QByteArray("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
<< QString("d2516ee1acfa5baf33dfc1c471e438449ef134c8");
}
void HashUnitTest::sha0test()
{
QStringList providersToTest;
providersToTest.append("qca-openssl");
// No SHA0 for botan or gcrypt
QFETCH(QByteArray, input);
QFETCH(QString, expectedHash);
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("sha0", provider))
QWARN(QString("SHA0 not supported for "+provider).toLocal8Bit());
else {
QString hashResult = QCA::SHA0(provider).hashToString(input);
QCOMPARE( hashResult, expectedHash );
}
}
}
void HashUnitTest::sha0longtest()
{
QByteArray fillerString;
fillerString.fill('a', 1000);
// This test extracted from OpenOffice.org 1.1.2, in sal/workben/t_digest.c
QStringList providersToTest;
providersToTest.append("qca-openssl");
// No SHA0 for botan or gcrypt
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("sha0", provider))
QWARN(QString("SHA0 not supported for "+provider).toLocal8Bit());
else {
QCA::SHA0 shaHash(provider);
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
QCOMPARE( QString(QCA::arrayToHex(shaHash.final())),
QString("3232affa48628a26653b5aaa44541fd90d690603" ) );
shaHash.clear();
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
QCOMPARE( QString(QCA::arrayToHex(shaHash.final())),
QString("3232affa48628a26653b5aaa44541fd90d690603" ) );
}
}
}
void HashUnitTest::sha1test_data()
{
// These are as specfied in FIPS 180-2. Matches RFC3174
// Some additions from Australian Standard (AS) 2805.13.3-2000
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QString>("expectedHash");
// FIPS 180-2, Appendix A.1
QTest::newRow("sha1(abc)") << QByteArray("abc") << QString("a9993e364706816aba3e25717850c26c9cd0d89d");
// FIPS 180-2, Appendix A.2
QTest::newRow("sha1(a-q)") << QByteArray("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
<< QString("84983e441c3bd26ebaae4aa1f95129e5e54670f1");
// AS 2805.13.3-200 Appendix A
// also has some duplicates from FIPS 180-2
QTest::newRow("sha1()") << QByteArray("") << QString("da39a3ee5e6b4b0d3255bfef95601890afd80709");
QTest::newRow("sha1(a)") << QByteArray("a") << QString("86f7e437faa5a7fce15d1ddcb9eaeaea377667b8");
QTest::newRow("sha1(a-z)") << QByteArray("abcdefghijklmnopqrstuvwxyz")
<< QString("32d10c7b8cf96570ca04ce37f2a19d84240d3a89");
}
void HashUnitTest::sha1test()
{
QStringList providersToTest;
providersToTest.append("qca-openssl");
providersToTest.append("qca-botan");
providersToTest.append("qca-gcrypt");
providersToTest.append("default");
QFETCH(QByteArray, input);
QFETCH(QString, expectedHash);
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("sha1", provider))
QWARN(QString("SHA1 not supported for "+provider).toLocal8Bit());
else {
QString hashResult = QCA::SHA1(provider).hashToString(input);
QCOMPARE( hashResult, expectedHash );
}
}
}
void HashUnitTest::sha1longtest()
{
QStringList providersToTest;
providersToTest.append("qca-openssl");
providersToTest.append("qca-botan");
providersToTest.append("qca-gcrypt");
providersToTest.append("default");
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("sha1", provider))
QWARN(QString("SHA1 not supported for "+provider).toLocal8Bit());
else {
QByteArray fillerString;
fillerString.fill('a', 1000);
// This test extracted from OpenOffice.org 1.1.2, in sal/workben/t_digest.c
// It basically reflects FIPS 180-2, Appendix A.3
// Also as per AS 2805.13.3-2000 Appendix A
QCA::SHA1 shaHash(provider);
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
QCOMPARE( QString(QCA::arrayToHex(shaHash.final())),
QString("34aa973cd4c4daa4f61eeb2bdbad27316534016f") );
QFile f1( "./data/empty" );
if ( f1.open( QIODevice::ReadOnly ) ) {
QCA::SHA1 hashObj(provider);
hashObj.update( f1 );
QCOMPARE( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "da39a3ee5e6b4b0d3255bfef95601890afd80709" ) );
} else {
QWARN( "./data/empty could not be opened - do you need to create it?");
}
QFile f2( "./data/Botan-1.4.1.tar.bz2" );
if ( f2.open( QIODevice::ReadOnly ) ) {
QCA::SHA1 hashObj(provider);
hashObj.update( f2 );
QCOMPARE( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "cda343591428a68e22bd2e349b890cbafb642cf7" ) );
} else {
QWARN( "./data/Botan-1.4.1.tar.bz2 could not be opened - do you need to download it?");
}
QFile f3( "./data/linux-2.6.7.tar.bz2" );
if ( f3.open( QIODevice::ReadOnly ) ) {
QCA::SHA1 hashObj(provider);
hashObj.update( f3 );
QCOMPARE( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "a030a9c6dcd10c5d90a86f915ad4710084cbca71" ) );
} else {
QWARN( "./data/linux-2.6.7.tar.bz2 could not be opened - do you need to download it?");
}
QFile f4( "./data/scribus-1.2.tar.bz2" );
if ( f4.open( QIODevice::ReadOnly ) ) {
QCA::SHA1 hashObj(provider);
hashObj.update( f4 );
QCOMPARE( QString( QCA::arrayToHex( hashObj.final() ) ),
QString( "a1fb6ed6acfd92381055b310d926d6e83e76ff1e" ) );
} else {
QWARN( "./data/scribus-1.2.tar.bz2 could not be opened - do you need to download it?");
}
}
}
}
void HashUnitTest::sha224test_data()
{
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QString>("expectedHash");
// These are as specfied in FIPS 180-2, change notice 1
// FIPS 180-2, Appendix B.1
QTest::newRow("sh224(abc)") << QByteArray("abc") << QString("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7");
// FIPS 180-2, Appendix B.2
QTest::newRow("sha224(abc)") << QByteArray("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
<< QString("75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525");
}
void HashUnitTest::sha224test()
{
QStringList providersToTest;
providersToTest.append("qca-gcrypt");
QFETCH(QByteArray, input);
QFETCH(QString, expectedHash);
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("sha224", provider))
QWARN(QString("SHA224 not supported for "+provider).toLocal8Bit());
else {
QString hashResult = QCA::SHA224(provider).hashToString(input);
QCOMPARE( hashResult, expectedHash );
}
}
}
void HashUnitTest::sha224longtest()
{
QByteArray fillerString;
fillerString.fill('a', 1000);
QStringList providersToTest;
providersToTest.append("qca-gcrypt");
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("sha224", provider))
QWARN(QString("SHA224 not supported for "+provider).toLocal8Bit());
else {
QCA::SHA224 shaHash(provider);
// This basically reflects FIPS 180-2, change notice 1, section 3
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
QCOMPARE( QString(QCA::arrayToHex(shaHash.final())),
QString("20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67") );
shaHash.clear();
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
QCOMPARE( QString(QCA::arrayToHex(shaHash.final())),
QString("20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67") );
}
}
}
void HashUnitTest::sha256test_data()
{
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QString>("expectedHash");
// These are as specfied in FIPS 180-2
// FIPS 180-2, Appendix B.1
QTest::newRow("sha256(abc)") << QByteArray("abc") << QString("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
// FIPS 180-2, Appendix B.2
QTest::newRow("sha256(abc)") << QByteArray("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
<< QString("248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1");
}
void HashUnitTest::sha256test()
{
QStringList providersToTest;
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
QFETCH(QByteArray, input);
QFETCH(QString, expectedHash);
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("sha256", provider))
QWARN(QString("SHA256 not supported for "+provider).toLocal8Bit());
else {
QString hashResult = QCA::SHA256(provider).hashToString(input);
QCOMPARE( hashResult, expectedHash );
}
}
}
void HashUnitTest::sha256longtest()
{
QByteArray fillerString;
fillerString.fill('a', 1000);
QStringList providersToTest;
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("sha256", provider))
QWARN(QString("SHA256 not supported for "+provider).toLocal8Bit());
else {
QCA::SHA256 shaHash(provider);
// This basically reflects FIPS 180-2, change notice 1, section 3
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
QCOMPARE( QString(QCA::arrayToHex(shaHash.final())),
QString("cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0") );
shaHash.clear();
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
QCOMPARE( QString(QCA::arrayToHex(shaHash.final())),
QString("cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0") );
}
}
}
void HashUnitTest::sha384test_data()
{
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QString>("expectedHash");
// These are as specfied in FIPS 180-2, and from Aaron Gifford's SHA2 tests
// FIPS 180-2, Appendix B.1
QTest::newRow("sha384(abc)") << QByteArray("abc")
<< QString("cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7");
// FIPS 180-2, Appendix B.2
QTest::newRow("sha384(a-u)") << QByteArray("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu")
<< QString("09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039");
// Aaron Gifford, vector002.info
QTest::newRow("sha384(a-q)") << QByteArray("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
<< QString("3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b");
}
void HashUnitTest::sha384test()
{
QStringList providersToTest;
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
QFETCH(QByteArray, input);
QFETCH(QString, expectedHash);
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("sha384", provider))
QWARN(QString("SHA384 not supported for "+provider).toLocal8Bit());
else {
QString hashResult = QCA::SHA384(provider).hashToString(input);
QCOMPARE( hashResult, expectedHash );
}
}
}
void HashUnitTest::sha384longtest()
{
QByteArray fillerString;
fillerString.fill('a', 1000);
QStringList providersToTest;
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("sha384", provider))
QWARN(QString("SHA384 not supported for "+provider).toLocal8Bit());
else {
QCA::SHA384 shaHash(provider);
// This basically reflects FIPS 180-2, change notice 1, section 3
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
QCOMPARE( QString(QCA::arrayToHex(shaHash.final())),
QString("9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985") );
shaHash.clear();
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
QCOMPARE( QString(QCA::arrayToHex(shaHash.final())),
QString("9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985") );
}
}
}
// These are as specfied in FIPS 180-2, and from Aaron Gifford's SHA2 tests
void HashUnitTest::sha512test_data()
{
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QString>("expectedHash");
// FIPS 180-2, Appendix C.1
QTest::newRow("sha512(abc)") << QByteArray("abc")
<< QString("ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f");
// FIPS 180-2, Appendix C.2
QTest::newRow("sha512(a-u)") << QByteArray("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu")
<< QString("8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909");
// Aaron Gifford, vector002.info
QTest::newRow("sha512(a-q)") << QByteArray("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
<< QString("204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445");
}
void HashUnitTest::sha512test()
{
QStringList providersToTest;
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
QFETCH(QByteArray, input);
QFETCH(QString, expectedHash);
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("sha512", provider))
QWARN(QString("SHA512 not supported for "+provider).toLocal8Bit());
else {
QString hashResult = QCA::SHA512(provider).hashToString(input);
QCOMPARE( hashResult, expectedHash );
}
}
}
void HashUnitTest::sha512longtest()
{
QByteArray fillerString;
fillerString.fill('a', 1000);
QStringList providersToTest;
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("sha512", provider))
QWARN(QString("SHA512 not supported for "+provider).toLocal8Bit());
else {
QCA::SHA512 shaHash(provider);
// This basically reflects FIPS 180-2, change notice 1, section 3
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
QCOMPARE( QString(QCA::arrayToHex(shaHash.final())),
QString("e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b") );
shaHash.clear();
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
QCOMPARE( QString(QCA::arrayToHex(shaHash.final())),
QString("e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b") );
}
}
}
// These are as specified in http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
// ISO/IEC 10118-3 costs a bit of money.
void HashUnitTest::rmd160test_data()
{
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QString>("expectedHash");
QTest::newRow("rmd160()") << QByteArray("") << QString("9c1185a5c5e9fc54612808977ee8f548b2258d31");
QTest::newRow("rmd160(a)") << QByteArray("a") << QString("0bdc9d2d256b3ee9daae347be6f4dc835a467ffe");
QTest::newRow("rmd160(abc)") << QByteArray("abc") << QString("8eb208f7e05d987a9b044a8e98c6b087f15a0bfc");
QTest::newRow("rmd160(md)") << QByteArray("message digest") << QString("5d0689ef49d2fae572b881b123a85ffa21595f36");
QTest::newRow("rmd160(a-z)") << QByteArray("abcdefghijklmnopqrstuvwxyz") << QString("f71c27109c692c1b56bbdceb5b9d2865b3708dbc");
QTest::newRow("rmd160(a-q)") << QByteArray("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
<< QString("12a053384a9c0c88e405a06c27dcf49ada62eb2b");
QTest::newRow("rmd160(A-9)") << QByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
<< QString("b0e20b6e3116640286ed3a87a5713079b21f5189");
QTest::newRow("rmd160(1-0)") << QByteArray("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
<< QString("9b752e45573d4b39f4dbd3323cab82bf63326bfb");
};
void HashUnitTest::rmd160test()
{
QStringList providersToTest;
providersToTest.append("qca-openssl");
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
QFETCH(QByteArray, input);
QFETCH(QString, expectedHash);
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("ripemd160", provider))
QWARN(QString("RIPEMD160 not supported for "+provider).toLocal8Bit());
else {
QString hashResult = QCA::RIPEMD160(provider).hashToString(input);
QCOMPARE( hashResult, expectedHash );
}
}
}
void HashUnitTest::rmd160longtest()
{
QByteArray fillerString;
fillerString.fill('a', 1000);
QStringList providersToTest;
providersToTest.append("qca-openssl");
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("ripemd160", provider))
QWARN(QString("RIPEMD160 not supported for "+provider).toLocal8Bit());
else {
QCA::RIPEMD160 rmdHash(provider);
// This is the "million times 'a' test"
for (int i=0; i<1000; i++)
rmdHash.update(fillerString);
QCOMPARE( QString(QCA::arrayToHex(rmdHash.final())),
QString("52783243c1697bdbe16d37f97f68f08325dc1528") );
rmdHash.clear();
for (int i=0; i<1000; i++)
rmdHash.update(fillerString);
QCOMPARE( QString(QCA::arrayToHex(rmdHash.final())),
QString("52783243c1697bdbe16d37f97f68f08325dc1528") );
// This is the "8 rounds of 1234567890" test.
// It also ensure that we can re-use hash objects correctly.
static char bindata[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30 };
QByteArray fillerArray( bindata, sizeof(bindata) ); // "1234567890"
rmdHash.clear();
for (int i=0; i<8; i++)
rmdHash.update(fillerArray);
QCOMPARE( QString(QCA::arrayToHex(rmdHash.final())),
QString("9b752e45573d4b39f4dbd3323cab82bf63326bfb") );
}
}
}
QTEST_MAIN(HashUnitTest)

@ -1,5 +1,5 @@
/**
* Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
* Copyright (C) 2004-2005 Brad Hards <bradh@frogmouth.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -25,15 +25,45 @@
#ifndef HASHUNITTEST_H
#define HASHUNITTEST_H
#include "tester.h"
#include <QtCrypto>
#include <QtTest/QtTest>
class HashUnitTest : public Tester
class HashUnitTest : public QObject
{
public:
HashUnitTest();
Q_OBJECT
public:
void allTests();
private slots:
void initTestCase();
void cleanupTestCase();
void md2test_data();
void md2test();
void md4test_data();
void md4test();
void md5test_data();
void md5test();
void md5filetest();
void sha0test_data();
void sha0test();
void sha0longtest();
void sha1test_data();
void sha1test();
void sha1longtest();
void sha224test_data();
void sha224test();
void sha224longtest();
void sha256test_data();
void sha256test();
void sha256longtest();
void sha384test_data();
void sha384test();
void sha384longtest();
void sha512test_data();
void sha512test();
void sha512longtest();
void rmd160test_data();
void rmd160test();
void rmd160longtest();
private:
QCA::Initializer* m_init;
};
#endif

@ -0,0 +1,15 @@
TEMPLATE = app
TARGET = hashunittest
DEPENDPATH += .
INCLUDEPATH += ../../include/QtCrypto
LIBS += -L../../lib -lqca
CONFIG += qttest thread console
# check target
QMAKE_EXTRA_TARGETS = check
check.depends = hashunittest
check.commands = ./hashunittest
# Input
HEADERS += hashunittest.h
SOURCES += hashunittest.cpp

@ -1,256 +0,0 @@
/**
* Copyright (C) 2004-2005 Brad Hards <bradh@frogmouth.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "kdfunittest.h"
#include <QtCrypto>
struct kdfTestValues {
char *secret; // usually a password or passphrase
char *output; // the key you get back
char *salt; // a salt or initialisation vector
unsigned int outputLength; // if the algo supports variable length keys, len
unsigned int iterationCount; // number of iterations
};
// These are from Botan's test suite
static struct kdfTestValues pbkdf1MD2TestValues[] = {
{ "71616c7a73656774",
"7c1991f3f38a09d70cf3b1acadb70bc6",
"40cf117c3865e0cf", 16, 1000 },
{ "766e68617a6a66736978626f6d787175",
"677500eda9f0c5e96e0a11f90fb9",
"3a2484ce5d3e1b4d", 14, 1 },
{ "66686565746e657162646d7171716e797977696f716a666c6f6976636371756a",
"91a5b689156b441bf27dd2bdd276",
"5d838b0f4fa22bfa2157f9083d87f8752e0495bb2113012761ef11b66e87c3cb", 14, 15 },
{ "736e6279696e6a7075696b7176787867726c6b66",
"49516935cc9f438bafa30ff038fb",
"f22d341361b47e3390107bd973fdc0d3e0bc02a3", 14, 2 },
{ 0, 0, 0, 0, 0 }
};
// These are from Botan's test suite
static struct kdfTestValues pbkdf1SHA1TestValues[] = {
{ "66746c6b6662786474626a62766c6c7662776977",
"768b277dc970f912dbdd3edad48ad2f065d25d",
"40ac5837560251c275af5e30a6a3074e57ced38e", 19, 6 },
{ "786e736f736d6b766867677a7370636e63706f63",
"4d90e846a4b6aaa02ac548014a00e97e506b2afb",
"7008a9dc1b9a81470a2360275c19dab77f716824", 20, 6 },
{ "6f74696c71776c756b717473",
"71ed1a995e693efcd33155935e800037da74ea28",
"ccfc44c09339040e55d3f7f76ca6ef838fde928717241deb9ac1a4ef45a27711", 20, 2001 },
{ "6b7a6e657166666c6274767374686e6663746166",
"f345fb8fbd880206b650266661f6",
"8108883fc04a01feb10661651516425dad1c93e0", 14, 10000 },
{ "716b78686c7170656d7868796b6d7975636a626f",
"2d54dfed0c7ef7d20b0945ba414a",
"bc8bc53d4604977c3adb1d19c15e87b77a84c2f6", 14, 10000 },
{ 0, 0, 0, 0, 0 }
};
// These are from Botan's test suite
static struct kdfTestValues pbkdf2TestValues[] = {
{ "6a79756571677872736367676c707864796b6366", "df6d9d72872404bf73e708cf3b7d", "9b56e55328a4c97a250738f8dba1b992e8a1b508", 14, 10000 },
{ "61717271737a6e7a76767a67746b73616d6d676f", "fa13f40af1ade2a30f2fffd66fc8a659ef95e6388c1682fc0fe4d15a70109517a32942e39c371440", "57487813cdd2220dfc485d932a2979ee8769ea8b", 40, 101 },
{ "6c7465786d666579796c6d6c62727379696b6177", "027afadd48f4be8dcc4f", "ed1f39a0a7f3889aaf7e60743b3bc1cc2c738e60", 10, 1000 },
{ "6378676e7972636772766c6c796c6f6c736a706f", "7c0d009fc91b48cb6d19bafbfccff3e2ccabfe725eaa234e56bde1d551c132f2", "94ac88200743fb0f6ac51be62166cbef08d94c15", 32, 1 },
{ "7871796668727865686965646c6865776e76626a", "4661301d3517ca4443a6a607b32b2a63f69996299df75db75f1e0b98dd0eb7d8", "24a1a50b17d63ee8394b69fc70887f4f94883d68", 32, 5 },
{ "616e6461716b706a7761627663666e706e6a6b6c", "82fb44a521448d5aac94b5158ead1e4dcd7363081a747b9f7626752bda2d", "9316c80801623cc2734af74bec42cf4dbaa3f6d5", 30, 100 },
{ "687361767679766f636c6f79757a746c736e6975", "f8ec2b0ac817896ac8189d787c6424ed24a6d881436687a4629802c0ecce", "612cc61df3cf2bdb36e10c4d8c9d73192bddee05", 30, 100 },
{ "6561696d72627a70636f706275736171746b6d77", "c9a0b2622f13916036e29e7462e206e8ba5b50ce9212752eb8ea2a4aa7b40a4cc1bf", "45248f9d0cebcb86a18243e76c972a1f3b36772a", 34, 100 },
{ "67777278707178756d7364736d626d6866686d666463766c63766e677a6b6967", "4c9db7ba24955225d5b845f65ef24ef1b0c6e86f2e39c8ddaa4b8abd26082d1f350381fadeaeb560dc447afc68a6b47e6ea1e7412f6cf7b2d82342fccd11d3b4", "a39b76c6eec8374a11493ad08c246a3e40dfae5064f4ee3489c273646178", 64, 1000 },
{ 0, 0, 0, 0, 0 }
};
KDFUnitTest::KDFUnitTest()
: Tester()
{
}
void KDFUnitTest::allTests()
{
QCA::Initializer init;
pbkdf1Tests();
pbkdf2Tests();
}
void KDFUnitTest::pbkdf1Tests()
{
if(!QCA::isSupported("pbkdf1(md2)"))
SKIP("PBKDF version 1 with MD2 not supported");
else {
for (int n = 0; (0 != pbkdf1MD2TestValues[n].secret); n++) {
QSecureArray password = QCA::hexToArray( pbkdf1MD2TestValues[n].secret );
QCA::InitializationVector salt( QCA::hexToArray( pbkdf1MD2TestValues[n].salt) );
QCA::SymmetricKey key = QCA::PBKDF1("md2").makeKey( password,
salt,
pbkdf1MD2TestValues[n].outputLength,
pbkdf1MD2TestValues[n].iterationCount);
CHECK( QCA::arrayToHex( key ), QString( pbkdf1MD2TestValues[n].output ) );
}
}
if(!QCA::isSupported("pbkdf1(sha1)"))
SKIP("PBKDF version 1 with SHA1 not supported");
else {
for (int n = 0; (0 != pbkdf1SHA1TestValues[n].secret); n++) {
QSecureArray password = QCA::hexToArray( pbkdf1SHA1TestValues[n].secret );
QCA::InitializationVector salt( QCA::hexToArray( pbkdf1SHA1TestValues[n].salt) );
QCA::SymmetricKey key = QCA::PBKDF1().makeKey( password,
salt,
pbkdf1SHA1TestValues[n].outputLength,
pbkdf1SHA1TestValues[n].iterationCount);
CHECK( QCA::arrayToHex( key ), QString( pbkdf1SHA1TestValues[n].output ) );
}
}
}
void KDFUnitTest::pbkdf2Tests()
{
if(!QCA::isSupported("pbkdf2(sha1)"))
SKIP("PBKDF version 2 with SHA1 not supported");
else {
{
QCA::InitializationVector salt(QSecureArray("what do ya want for nothing?"));
QSecureArray password("Jefe");
int iterations = 1000;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
CHECK( QCA::arrayToHex(passwordOut), QString( "6349e09cb6b8c1485cfa9780ee3264df" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("ATHENA.MIT.EDUraeburn"));
QSecureArray password("password");
int iterations = 1;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
CHECK( QCA::arrayToHex(passwordOut), QString( "cdedb5281bb2f801565a1122b2563515" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
CHECK( QCA::arrayToHex(passwordOut),
QString( "cdedb5281bb2f801565a1122b25635150ad1f7a04bb9f3a333ecc0e2e1f70837" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("ATHENA.MIT.EDUraeburn"));
QSecureArray password("password");
int iterations = 2;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
CHECK( QCA::arrayToHex(passwordOut), QString( "01dbee7f4a9e243e988b62c73cda935d" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
CHECK( QCA::arrayToHex(passwordOut),
QString( "01dbee7f4a9e243e988b62c73cda935da05378b93244ec8f48a99e61ad799d86" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("ATHENA.MIT.EDUraeburn"));
QSecureArray password("password");
int iterations = 1200;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
CHECK( QCA::arrayToHex(passwordOut), QString( "5c08eb61fdf71e4e4ec3cf6ba1f5512b" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
CHECK( QCA::arrayToHex(passwordOut),
QString( "5c08eb61fdf71e4e4ec3cf6ba1f5512ba7e52ddbc5e5142f708a31e2e62b1e13" ) );
}
// RFC3211 and RFC3962, Appendix B
{
QCA::InitializationVector salt(QCA::hexToArray("1234567878563412"));
QSecureArray password("password");
int iterations = 5;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
CHECK( QCA::arrayToHex(passwordOut), QString( "d1daa78615f287e6a1c8b120d7062a49" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
CHECK( QCA::arrayToHex(passwordOut),
QString( "d1daa78615f287e6a1c8b120d7062a493f98d203e6be49a6adf4fa574b6e64ee" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 8, iterations);
CHECK( QCA::arrayToHex(passwordOut),
QString( "d1daa78615f287e6" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("pass phrase equals block size"));
QSecureArray password("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
int iterations = 1200;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
CHECK( QCA::arrayToHex(passwordOut), QString( "139c30c0966bc32ba55fdbf212530ac9" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
CHECK( QCA::arrayToHex(passwordOut),
QString( "139c30c0966bc32ba55fdbf212530ac9c5ec59f1a452f5cc9ad940fea0598ed1" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("pass phrase exceeds block size"));
QSecureArray password("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
int iterations = 1200;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
CHECK( QCA::arrayToHex(passwordOut), QString( "9ccad6d468770cd51b10e6a68721be61" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
CHECK( QCA::arrayToHex(passwordOut),
QString( "9ccad6d468770cd51b10e6a68721be611a8b4d282601db3b36be9246915ec82a" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("EXAMPLE.COMpianist"));
QSecureArray password(QCA::hexToArray("f09d849e"));
int iterations = 50;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
CHECK( QCA::arrayToHex(passwordOut), QString( "6b9cf26d45455a43a5b8bb276a403b39" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
CHECK( QCA::arrayToHex(passwordOut),
QString( "6b9cf26d45455a43a5b8bb276a403b39e7fe37a0c41e02c281ff3069e1e94f52" ) );
}
for (int n = 0; (0 != pbkdf2TestValues[n].secret); n++) {
QSecureArray password = QCA::hexToArray( pbkdf2TestValues[n].secret );
QCA::InitializationVector salt( QCA::hexToArray( pbkdf2TestValues[n].salt) );
QCA::SymmetricKey key = QCA::PBKDF2().makeKey( password,
salt,
pbkdf2TestValues[n].outputLength,
pbkdf2TestValues[n].iterationCount);
CHECK( QCA::arrayToHex( key ), QString( pbkdf2TestValues[n].output ) );
}
}
}

@ -0,0 +1,377 @@
/**
* Copyright (C) 2004-2005 Brad Hards <bradh@frogmouth.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "kdfunittest.h"
void KDFUnitTest::initTestCase()
{
m_init = new QCA::Initializer;
#include "../fixpaths.include"
}
void KDFUnitTest::cleanupTestCase()
{
delete m_init;
}
void KDFUnitTest::pbkdf1md2Tests_data()
{
QTest::addColumn<QString>("secret"); // usually a password or passphrase
QTest::addColumn<QString>("output"); // the key you get back
QTest::addColumn<QString>("salt"); // a salt or initialisation vector
QTest::addColumn<unsigned int>("outputLength"); // if the algo supports variable length keys, len
QTest::addColumn<unsigned int>("iterationCount"); // number of iterations
// These are from Botan's test suite
QTest::newRow("1") << QString("71616c7a73656774")
<< QString("7c1991f3f38a09d70cf3b1acadb70bc6")
<< QString("40cf117c3865e0cf")
<< static_cast<unsigned int>(16)
<< static_cast<unsigned int>(1000);
QTest::newRow("2") << QString("766e68617a6a66736978626f6d787175")
<< QString("677500eda9f0c5e96e0a11f90fb9")
<< QString("3a2484ce5d3e1b4d")
<< static_cast<unsigned int>(14)
<< static_cast<unsigned int>(1);
QTest::newRow("3") << QString("66686565746e657162646d7171716e797977696f716a666c6f6976636371756a")
<< QString("91a5b689156b441bf27dd2bdd276")
<< QString("5d838b0f4fa22bfa2157f9083d87f8752e0495bb2113012761ef11b66e87c3cb")
<< static_cast<unsigned int>(14)
<< static_cast<unsigned int>(15);
QTest::newRow("4") << QString("736e6279696e6a7075696b7176787867726c6b66")
<< QString("49516935cc9f438bafa30ff038fb")
<< QString("f22d341361b47e3390107bd973fdc0d3e0bc02a3")
<< static_cast<unsigned int>(14)
<< static_cast<unsigned int>(2);
}
void KDFUnitTest::pbkdf1md2Tests()
{
QStringList providersToTest;
providersToTest.append("qca-openssl");
// providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
QFETCH(QString, secret);
QFETCH(QString, output);
QFETCH(QString, salt);
QFETCH(unsigned int, outputLength);
QFETCH(unsigned int, iterationCount);
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("pbkdf1(md2)", provider))
QWARN(QString("PBKDF version 1 with MD2 not supported for "+provider).toLocal8Bit());
else {
QSecureArray password = QCA::hexToArray( secret );
QCA::InitializationVector iv( QCA::hexToArray( salt) );
QCA::SymmetricKey key = QCA::PBKDF1("md2", provider).makeKey( password,
iv,
outputLength,
iterationCount);
QCOMPARE( QCA::arrayToHex( key ), output );
}
}
}
void KDFUnitTest::pbkdf1sha1Tests_data()
{
QTest::addColumn<QString>("secret"); // usually a password or passphrase
QTest::addColumn<QString>("output"); // the key you get back
QTest::addColumn<QString>("salt"); // a salt or initialisation vector
QTest::addColumn<unsigned int>("outputLength"); // if the algo supports variable length keys, len
QTest::addColumn<unsigned int>("iterationCount"); // number of iterations
// These are from Botan's test suite
QTest::newRow("1") << QString("66746c6b6662786474626a62766c6c7662776977")
<< QString("768b277dc970f912dbdd3edad48ad2f065d25d")
<< QString("40ac5837560251c275af5e30a6a3074e57ced38e")
<< static_cast<unsigned int>(19)
<< static_cast<unsigned int>(6);
QTest::newRow("2") << QString("786e736f736d6b766867677a7370636e63706f63")
<< QString("4d90e846a4b6aaa02ac548014a00e97e506b2afb")
<< QString("7008a9dc1b9a81470a2360275c19dab77f716824")
<< static_cast<unsigned int>(20)
<< static_cast<unsigned int>(6);
QTest::newRow("3") << QString("6f74696c71776c756b717473")
<< QString("71ed1a995e693efcd33155935e800037da74ea28")
<< QString("ccfc44c09339040e55d3f7f76ca6ef838fde928717241deb9ac1a4ef45a27711")
<< static_cast<unsigned int>(20)
<< static_cast<unsigned int>(2001);
QTest::newRow("4") << QString("6b7a6e657166666c6274767374686e6663746166")
<< QString("f345fb8fbd880206b650266661f6")
<< QString("8108883fc04a01feb10661651516425dad1c93e0")
<< static_cast<unsigned int>(14)
<< static_cast<unsigned int>(10000);
QTest::newRow("5") << QString("716b78686c7170656d7868796b6d7975636a626f")
<< QString("2d54dfed0c7ef7d20b0945ba414a")
<< QString("bc8bc53d4604977c3adb1d19c15e87b77a84c2f6")
<< static_cast<unsigned int>(14)
<< static_cast<unsigned int>(10000);
};
void KDFUnitTest::pbkdf1sha1Tests()
{
QStringList providersToTest;
providersToTest.append("qca-openssl");
// providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
QFETCH(QString, secret);
QFETCH(QString, output);
QFETCH(QString, salt);
QFETCH(unsigned int, outputLength);
QFETCH(unsigned int, iterationCount);
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("pbkdf1(md2)", provider))
QWARN(QString("PBKDF version 1 with SHA1 not supported for "+provider).toLocal8Bit());
else {
QSecureArray password = QCA::hexToArray( secret );
QCA::InitializationVector iv( QCA::hexToArray( salt) );
QCA::SymmetricKey key = QCA::PBKDF1("sha1", provider).makeKey( password,
iv,
outputLength,
iterationCount);
QCOMPARE( QCA::arrayToHex( key ), output );
}
}
}
void KDFUnitTest::pbkdf2Tests_data()
{
QTest::addColumn<QString>("secret"); // usually a password or passphrase
QTest::addColumn<QString>("output"); // the key you get back
QTest::addColumn<QString>("salt"); // a salt or initialisation vector
QTest::addColumn<unsigned int>("outputLength"); // if the algo supports variable length keys, len
QTest::addColumn<unsigned int>("iterationCount"); // number of iterations
// These are from Botan's test suite
QTest::newRow("1") << QString("6a79756571677872736367676c707864796b6366")
<< QString("df6d9d72872404bf73e708cf3b7d")
<< QString("9b56e55328a4c97a250738f8dba1b992e8a1b508")
<< static_cast<unsigned int>(14)
<< static_cast<unsigned int>(10000);
QTest::newRow("2") << QString("61717271737a6e7a76767a67746b73616d6d676f")
<< QString("fa13f40af1ade2a30f2fffd66fc8a659ef95e6388c1682fc0fe4d15a70109517a32942e39c371440")
<< QString("57487813cdd2220dfc485d932a2979ee8769ea8b")
<< static_cast<unsigned int>(40)
<< static_cast<unsigned int>(101);
QTest::newRow("3") << QString("6c7465786d666579796c6d6c62727379696b6177")
<< QString("027afadd48f4be8dcc4f")
<< QString("ed1f39a0a7f3889aaf7e60743b3bc1cc2c738e60")
<< static_cast<unsigned int>(10)
<< static_cast<unsigned int>(1000);
QTest::newRow("4") << QString("6378676e7972636772766c6c796c6f6c736a706f")
<< QString("7c0d009fc91b48cb6d19bafbfccff3e2ccabfe725eaa234e56bde1d551c132f2")
<< QString("94ac88200743fb0f6ac51be62166cbef08d94c15")
<< static_cast<unsigned int>(32)
<< static_cast<unsigned int>(1);
QTest::newRow("5") << QString("7871796668727865686965646c6865776e76626a")
<< QString("4661301d3517ca4443a6a607b32b2a63f69996299df75db75f1e0b98dd0eb7d8")
<< QString("24a1a50b17d63ee8394b69fc70887f4f94883d68")
<< static_cast<unsigned int>(32)
<< static_cast<unsigned int>(5);
QTest::newRow("6") << QString("616e6461716b706a7761627663666e706e6a6b6c")
<< QString("82fb44a521448d5aac94b5158ead1e4dcd7363081a747b9f7626752bda2d")
<< QString("9316c80801623cc2734af74bec42cf4dbaa3f6d5")
<< static_cast<unsigned int>(30)
<< static_cast<unsigned int>(100);
QTest::newRow("7") << QString("687361767679766f636c6f79757a746c736e6975")
<< QString("f8ec2b0ac817896ac8189d787c6424ed24a6d881436687a4629802c0ecce")
<< QString("612cc61df3cf2bdb36e10c4d8c9d73192bddee05")
<< static_cast<unsigned int>(30)
<< static_cast<unsigned int>(100);
QTest::newRow("8") << QString("6561696d72627a70636f706275736171746b6d77")
<< QString("c9a0b2622f13916036e29e7462e206e8ba5b50ce9212752eb8ea2a4aa7b40a4cc1bf")
<< QString("45248f9d0cebcb86a18243e76c972a1f3b36772a")
<< static_cast<unsigned int>(34)
<< static_cast<unsigned int>(100);
QTest::newRow("9") << QString("67777278707178756d7364736d626d6866686d666463766c63766e677a6b6967")
<< QString("4c9db7ba24955225d5b845f65ef24ef1b0c6e86f2e39c8ddaa4b8abd26082d1f350381fadeaeb560dc447afc68a6b47e6ea1e7412f6cf7b2d82342fccd11d3b4")
<< QString("a39b76c6eec8374a11493ad08c246a3e40dfae5064f4ee3489c273646178")
<< static_cast<unsigned int>(64)
<< static_cast<unsigned int>(1000);
}
void KDFUnitTest::pbkdf2Tests()
{
QStringList providersToTest;
// providersToTest.append("qca-openssl");
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
QFETCH(QString, secret);
QFETCH(QString, output);
QFETCH(QString, salt);
QFETCH(unsigned int, outputLength);
QFETCH(unsigned int, iterationCount);
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("pbkdf2(sha1)", provider))
QWARN(QString("PBKDF version 2 with SHA1 not supported for "+provider).toLocal8Bit());
else {
QSecureArray password = QCA::hexToArray( secret );
QCA::InitializationVector iv( QCA::hexToArray( salt) );
QCA::SymmetricKey key = QCA::PBKDF2("sha1", provider).makeKey( password,
iv,
outputLength,
iterationCount);
QCOMPARE( QCA::arrayToHex( key ), output );
}
}
}
void KDFUnitTest::pbkdf2extraTests()
{
QStringList providersToTest;
// providersToTest.append("qca-openssl");
providersToTest.append("qca-gcrypt");
providersToTest.append("qca-botan");
foreach(QString provider, providersToTest) {
if(!QCA::isSupported("pbkdf2(sha1)", provider))
QWARN(QString("PBKDF version 2 with SHA1 not supported for "+provider).toLocal8Bit());
else {
// Not sure where this one came from...
{
QCA::InitializationVector salt(QSecureArray("what do ya want for nothing?"));
QSecureArray password("Jefe");
int iterations = 1000;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut), QString( "6349e09cb6b8c1485cfa9780ee3264df" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("ATHENA.MIT.EDUraeburn"));
QSecureArray password("password");
int iterations = 1;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut), QString( "cdedb5281bb2f801565a1122b2563515" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut),
QString( "cdedb5281bb2f801565a1122b25635150ad1f7a04bb9f3a333ecc0e2e1f70837" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("ATHENA.MIT.EDUraeburn"));
QSecureArray password("password");
int iterations = 2;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut), QString( "01dbee7f4a9e243e988b62c73cda935d" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut),
QString( "01dbee7f4a9e243e988b62c73cda935da05378b93244ec8f48a99e61ad799d86" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("ATHENA.MIT.EDUraeburn"));
QSecureArray password("password");
int iterations = 1200;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut), QString( "5c08eb61fdf71e4e4ec3cf6ba1f5512b" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut),
QString( "5c08eb61fdf71e4e4ec3cf6ba1f5512ba7e52ddbc5e5142f708a31e2e62b1e13" ) );
}
// RFC3211 and RFC3962, Appendix B
{
QCA::InitializationVector salt(QCA::hexToArray("1234567878563412"));
QSecureArray password("password");
int iterations = 5;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut), QString( "d1daa78615f287e6a1c8b120d7062a49" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut),
QString( "d1daa78615f287e6a1c8b120d7062a493f98d203e6be49a6adf4fa574b6e64ee" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 8, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut),
QString( "d1daa78615f287e6" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("pass phrase equals block size"));
QSecureArray password("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
int iterations = 1200;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut), QString( "139c30c0966bc32ba55fdbf212530ac9" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut),
QString( "139c30c0966bc32ba55fdbf212530ac9c5ec59f1a452f5cc9ad940fea0598ed1" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("pass phrase exceeds block size"));
QSecureArray password("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
int iterations = 1200;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut), QString( "9ccad6d468770cd51b10e6a68721be61" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut),
QString( "9ccad6d468770cd51b10e6a68721be611a8b4d282601db3b36be9246915ec82a" ) );
}
// RFC3962, Appendix B
{
QCA::InitializationVector salt(QSecureArray("EXAMPLE.COMpianist"));
QSecureArray password(QCA::hexToArray("f09d849e"));
int iterations = 50;
QCA::SymmetricKey passwordOut = QCA::PBKDF2().makeKey (password, salt, 16, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut), QString( "6b9cf26d45455a43a5b8bb276a403b39" ) );
passwordOut = QCA::PBKDF2().makeKey (password, salt, 32, iterations);
QCOMPARE( QCA::arrayToHex(passwordOut),
QString( "6b9cf26d45455a43a5b8bb276a403b39e7fe37a0c41e02c281ff3069e1e94f52" ) );
}
}
}
}
QTEST_MAIN(KDFUnitTest)

@ -1,5 +1,5 @@
/**
* Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
* Copyright (C) 2004-2005 Brad Hards <bradh@frogmouth.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -25,18 +25,25 @@
#ifndef KDFUNITTEST_H
#define KDFUNITTEST_H
#include "tester.h"
#include <QtCrypto>
#include <QtTest>
class KDFUnitTest : public Tester
class KDFUnitTest : public QObject
{
public:
KDFUnitTest();
Q_OBJECT
public:
void allTests();
private:
void pbkdf1Tests();
private slots:
void initTestCase();
void cleanupTestCase();
void pbkdf1md2Tests_data();
void pbkdf1md2Tests();
void pbkdf1sha1Tests_data();
void pbkdf1sha1Tests();
void pbkdf2Tests_data();
void pbkdf2Tests();
void pbkdf2extraTests();
private:
QCA::Initializer* m_init;
};
#endif

@ -0,0 +1,15 @@
TEMPLATE = app
TARGET = kdfunittest
DEPENDPATH += .
INCLUDEPATH += ../../include/QtCrypto
LIBS += -L../../lib -lqca
CONFIG += qttest thread console
# check target
QMAKE_EXTRA_TARGETS = check
check.depends = kdfunittest
check.commands = ./kdfunittest
# Input
HEADERS += kdfunittest.h
SOURCES += kdfunittest.cpp

@ -40,20 +40,72 @@ void KeyGenUnitTest::allTests()
CHECK( keygen.isBusy(), false );
CHECK( keygen.blocking(), true );
QCA::PrivateKey priv1 = keygen.createRSA( 1024, 65537 );
QCA::RSAPrivateKey rsa1 = priv1.toRSA();
CHECK( rsa1.isNull(), false );
CHECK( rsa1.e(), QBigInteger(65537) );
if(!QCA::isSupported("pkey") ||
!QCA::PKey::supportedTypes().contains(QCA::PKey::RSA) ||
!QCA::PKey::supportedIOTypes().contains(QCA::PKey::RSA))
SKIP("RSA not supported!");
else {
QCA::PrivateKey priv1 = keygen.createRSA( 1024, 65537 );
QCA::RSAPrivateKey rsa1 = priv1.toRSA();
CHECK( rsa1.isNull(), false );
CHECK( rsa1.e(), QBigInteger(65537) );
CHECK( rsa1.bitSize(), 1024);
priv1 = keygen.createRSA( 512, 17 );
rsa1 = priv1.toRSA();
CHECK( rsa1.isNull(), false );
CHECK( rsa1.e(), QBigInteger(17) );
priv1 = keygen.createRSA( 512, 17 );
rsa1 = priv1.toRSA();
CHECK( rsa1.isNull(), false );
CHECK( rsa1.e(), QBigInteger(17) );
CHECK( rsa1.bitSize(), 512);
priv1 = keygen.createRSA( 512, 3 );
rsa1 = priv1.toRSA();
CHECK( rsa1.isNull(), false );
CHECK( rsa1.e(), QBigInteger(3) );
priv1 = keygen.createRSA( 512, 3 );
rsa1 = priv1.toRSA();
CHECK( rsa1.isNull(), false );
CHECK( rsa1.e(), QBigInteger(3) );
CHECK( rsa1.bitSize(), 512);
}
// DSA
if(!QCA::isSupported("pkey") ||
!QCA::PKey::supportedTypes().contains(QCA::PKey::DSA) ||
!QCA::PKey::supportedIOTypes().contains(QCA::PKey::DSA))
SKIP("DSA not supported!");
else {
QCA::DLGroup group = keygen.createDLGroup( QCA::DSA_512 );
QCA::PrivateKey priv2 = keygen.createDSA( group );
QCA::DSAPrivateKey dsa1 = priv2.toDSA();
CHECK( dsa1.isNull(), false );
CHECK( dsa1.bitSize(), 512 );
group = keygen.createDLGroup( QCA::DSA_768 );
priv2 = keygen.createDSA( group );
dsa1 = priv2.toDSA();
CHECK( dsa1.isNull(), false );
CHECK( dsa1.bitSize(), 768 );
group = keygen.createDLGroup( QCA::DSA_1024 );
priv2 = keygen.createDSA( group );
dsa1 = priv2.toDSA();
CHECK( dsa1.isNull(), false );
CHECK( dsa1.bitSize(), 1024 );
}
// DH
if(!QCA::isSupported("pkey") ||
!QCA::PKey::supportedTypes().contains(QCA::PKey::DH) ||
!QCA::PKey::supportedIOTypes().contains(QCA::PKey::DH))
SKIP("DH not supported!");
else {
QCA::DLGroup group = keygen.createDLGroup( QCA::IETF_1024 );
QCA::PrivateKey priv3 = keygen.createDH( group );
QCA::DHPrivateKey dh1 = priv3.toDH();
CHECK( dh1.isNull(), false );
CHECK( dh1.bitSize(), 1024 );
group = keygen.createDLGroup( QCA::IETF_2048 );
priv3 = keygen.createDH( group );
dh1 = priv3.toDH();
CHECK( dh1.isNull(), false );
CHECK( dh1.bitSize(), 2048 );
}
}

@ -23,14 +23,22 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "macunittest.h"
#include <QtTest>
#include <QtCrypto>
#include <iostream>
MACUnitTest::MACUnitTest()
: Tester()
class MACUnitTest : public QObject
{
}
Q_OBJECT
private slots:
void HMACMD5test( const QString &provider );
void HMACSHA1test( const QString &provider );
void HMACSHA256test( const QString &provider );
void HMACSHA224test( const QString &provider );
void HMACSHA384test( const QString &provider );
void HMACSHA512test( const QString &provider );
void HMACRMD160test( const QString &provider );
};
void MACUnitTest::HMACMD5test( const QString &provider )
{

@ -1,39 +0,0 @@
/**
* Copyright (C) 2004 Zack Rusin <zack@kde.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "kunittest.h"
#include <QtCore>
#include <QtCrypto>
int main( int argc, char** argv )
{
// the Initializer object sets things up, and
// also does cleanup when it goes out of scope
QCA::Initializer init;
QCoreApplication app(argc, argv);
KUnitTest tests;
return tests.runTests();
}

@ -59,7 +59,7 @@ void RSAUnitTest::allTests()
CHECK( rsaKey.canDecrypt(), true);
QCA::RSAPrivateKey rsaPrivKey = rsaKey.toRSA();
XFAIL( rsaPrivKey.bitSize(), keysize );
CHECK( rsaPrivKey.bitSize(), keysize );
QString rsaPEM = rsaKey.toPEM();
CHECK( rsaPEM.isEmpty(), false );

@ -1,5 +1,5 @@
/**
* Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
* Copyright (C) 2004-2005 Brad Hards <bradh@frogmouth.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -23,103 +23,116 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "staticunittest.h"
#include <QtCrypto>
StaticUnitTest::StaticUnitTest()
: Tester()
void StaticUnitTest::initTestCase()
{
m_init = new QCA::Initializer;
#include "../fixpaths.include"
}
void StaticUnitTest::allTests()
void StaticUnitTest::cleanupTestCase()
{
QCA::Initializer init;
delete m_init;
}
void StaticUnitTest::hexConversions()
{
QByteArray test(10, 'a');
CHECK( QCA::arrayToHex(test), QString("61616161616161616161") );
QCOMPARE( QCA::arrayToHex(test), QString("61616161616161616161") );
test.fill('b');
test[7] = 0x00;
CHECK( test == QCA::hexToArray(QString("62626262626262006262")), true );
QCOMPARE( test == QCA::hexToArray(QString("62626262626262006262")), true );
QSecureArray testArray(10);
//testArray.fill( 'a' );
for (int i = 0; i < testArray.size(); i++) {
testArray[ i ] = 0x61;
}
CHECK( QCA::arrayToHex( testArray ), QString( "61616161616161616161" ) );
QCOMPARE( QCA::arrayToHex( testArray ), QString( "61616161616161616161" ) );
//testArray.fill( 'b' );
for (int i = 0; i < testArray.size(); i++) {
testArray[ i ] = 0x62;
}
testArray[6] = 0x00;
CHECK( testArray == QCA::hexToArray(QString("62626262626200626262")), true );
QCOMPARE( testArray == QCA::hexToArray(QString("62626262626200626262")), true );
CHECK( testArray == QCA::hexToArray( QCA::arrayToHex( testArray ) ), true );
QCOMPARE( testArray == QCA::hexToArray( QCA::arrayToHex( testArray ) ), true );
testArray[9] = 0x00;
CHECK( testArray == QCA::hexToArray( QCA::arrayToHex( testArray ) ), true );
QCOMPARE( testArray == QCA::hexToArray( QCA::arrayToHex( testArray ) ), true );
}
// capabilities are reported as a list - that is a problem for
void StaticUnitTest::capabilities()
{
// capabilities are reported as a list - that is a problem for
// doing a direct comparison, since they change
// We try to work around that using contains()
QStringList supportedCapabilities = QCA::supportedFeatures();
CHECK( supportedCapabilities.contains("random"), (QBool)true );
CHECK( supportedCapabilities.contains("sha1"), (QBool)true );
CHECK( supportedCapabilities.contains("sha0"), (QBool)true );
CHECK( supportedCapabilities.contains("md2"),(QBool) true );
CHECK( supportedCapabilities.contains("md4"), (QBool)true );
CHECK( supportedCapabilities.contains("md5"), (QBool)true );
CHECK( supportedCapabilities.contains("ripemd160"), (QBool)true );
QCOMPARE( supportedCapabilities.contains("random"), (QBool)true );
QCOMPARE( supportedCapabilities.contains("sha1"), (QBool)true );
QCOMPARE( supportedCapabilities.contains("sha0"), (QBool)true );
QCOMPARE( supportedCapabilities.contains("md2"),(QBool) true );
QCOMPARE( supportedCapabilities.contains("md4"), (QBool)true );
QCOMPARE( supportedCapabilities.contains("md5"), (QBool)true );
QCOMPARE( supportedCapabilities.contains("ripemd160"), (QBool)true );
QStringList defaultCapabilities = QCA::defaultFeatures();
CHECK( defaultCapabilities.contains("random"), (QBool)true );
QCOMPARE( defaultCapabilities.contains("random"), (QBool)true );
CHECK( QCA::isSupported("random"), true );
CHECK( QCA::isSupported("sha0"), true );
CHECK( QCA::isSupported("sha0,sha1"), true );
CHECK( QCA::isSupported("md2,md4,md5"), true );
CHECK( QCA::isSupported("md5"), true );
CHECK( QCA::isSupported("ripemd160"), true );
CHECK( QCA::isSupported("sha256,sha384,sha512"), true );
CHECK( QCA::isSupported("nosuchfeature"), false );
QCOMPARE( QCA::isSupported("random"), true );
QCOMPARE( QCA::isSupported("sha0"), true );
QCOMPARE( QCA::isSupported("sha0,sha1"), true );
QCOMPARE( QCA::isSupported("md2,md4,md5"), true );
QCOMPARE( QCA::isSupported("md5"), true );
QCOMPARE( QCA::isSupported("ripemd160"), true );
QCOMPARE( QCA::isSupported("sha256,sha384,sha512"), true );
QCOMPARE( QCA::isSupported("nosuchfeature"), false );
QString caps( "random,sha1,md5,ripemd160");
QStringList capList;
capList = caps.split( "," );
CHECK( QCA::isSupported(capList), true );
QCOMPARE( QCA::isSupported(capList), true );
capList.append("noSuch");
CHECK( QCA::isSupported(capList), false );
QCOMPARE( QCA::isSupported(capList), false );
capList.clear();
capList.append("noSuch");
CHECK( QCA::isSupported(capList), false );
QCOMPARE( QCA::isSupported(capList), false );
}
void StaticUnitTest::secureMemory()
{
// this should be reliably true
CHECK( QCA::haveSecureMemory(), true );
QCOMPARE( QCA::haveSecureMemory(), true );
}
void StaticUnitTest::providers()
{
// providers are obviously variable, this might be a bit brittle
QStringList providerNames;
QCA::scanForPlugins();
QCA::ProviderList qcaProviders = QCA::providers();
for (int i = 0; i < qcaProviders.size(); ++i) {
providerNames.append( qcaProviders[i]->name() );
}
CHECK( providerNames.contains("qca-openssl"), (QBool)true );
CHECK( providerNames.contains("qca-gcrypt"), (QBool)true );
CHECK( providerNames.contains("qca-botan"), (QBool)true );
QCOMPARE( providerNames.contains("qca-openssl"), (QBool)true );
QCOMPARE( providerNames.contains("qca-gcrypt"), (QBool)true );
QCOMPARE( providerNames.contains("qca-botan"), (QBool)true );
QCA::setProviderPriority("qca-openssl", 4);
QCA::setProviderPriority("qca-botan", 2);
CHECK( QCA::providerPriority( "qca-openssl"), 4 );
CHECK( QCA::providerPriority( "qca-gcrypt"), 0 );
CHECK( QCA::providerPriority( "qca-botan"), 2 );
QCOMPARE( QCA::providerPriority( "qca-openssl"), 4 );
QCOMPARE( QCA::providerPriority( "qca-gcrypt"), 0 );
QCOMPARE( QCA::providerPriority( "qca-botan"), 2 );
QCA::setProviderPriority("qca-openssl", 3);
// reuse last
QCA::setProviderPriority("qca-botan", -1);
CHECK( QCA::providerPriority( "qca-botan"), 3 );
QCOMPARE( QCA::providerPriority( "qca-botan"), 3 );
QCA::unloadAllPlugins();
}
QTEST_MAIN(StaticUnitTest)

@ -1,5 +1,5 @@
/**
* Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
* Copyright (C) 2004-2005 Brad Hards <bradh@frogmouth.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -25,15 +25,22 @@
#ifndef STATICUNITTEST_H
#define STATICUNITTEST_H
#include "tester.h"
#include <QtCrypto>
#include <QtTest/QtTest>
class StaticUnitTest : public Tester
class StaticUnitTest : public QObject
{
public:
StaticUnitTest();
Q_OBJECT
public:
void allTests();
private slots:
void initTestCase();
void cleanupTestCase();
void hexConversions();
void providers();
void capabilities();
void secureMemory();
private:
QCA::Initializer* m_init;
};
#endif

@ -0,0 +1,15 @@
TEMPLATE = app
TARGET = staticunittest
DEPENDPATH += .
INCLUDEPATH += ../../include/QtCrypto
LIBS += -L../../lib -lqca
CONFIG += qttest thread console
# check target
QMAKE_EXTRA_TARGETS = check
check.depends = staticunittest
check.commands = ./staticunittest
# Input
HEADERS += staticunittest.h
SOURCES += staticunittest.cpp

@ -1,39 +1,12 @@
TEMPLATE = app
CONFIG += qt warn_on console debug
QT -=gui
TARGET = qca-unittest
TEMPLATE = subdirs
#QMAKE_CXXFLAGS_DEBUG += -fprofile-arcs -ftest-coverage
SUBDIRS += \
bigintunittest \
hashunittest \
kdfunittest \
staticunittest
INCLUDEPATH += ../include/QtCrypto
LIBS += -L../lib
LIBS += -lqca
#DEFINES += QT_STATICPLUGIN
#SOURCES += ../plugins/qca-botan/qca-botan.cpp
#LIBS += -L/usr/lib -lm -lpthread -lrt -lbotan
QMAKE_EXTRA_TARGETS += check
check.commands = sh ./checkall
HEADERS += kunittest.h tester.h
SOURCES += kunittest.cpp main.cpp
HEADERS += randomunittest.h hexunittest.h bigintunittest.h
HEADERS += keylengthunittest.h symmetrickeyunittest.h
HEADERS += staticunittest.h hashunittest.h
HEADERS += securearrayunittest.h
HEADERS += macunittest.h
HEADERS += cipherunittest.h kdfunittest.h
HEADERS += base64unittest.h certunittest.h
HEADERS += rsaunittest.h
HEADERS += dsaunittest.h
HEADERS += keygenunittest.h
SOURCES += randomunittest.cpp hexunittest.cpp bigintunittest.cpp
SOURCES += keylengthunittest.cpp symmetrickeyunittest.cpp
SOURCES += staticunittest.cpp hashunittest.cpp
SOURCES += securearrayunittest.cpp
SOURCES += macunittest.cpp
SOURCES += cipherunittest.cpp kdfunittest.cpp
SOURCES += base64unittest.cpp certunittest.cpp
SOURCES += rsaunittest.cpp
SOURCES += dsaunittest.cpp
SOURCES += keygenunittest.cpp