SymmetricAlgorithmTest.cs 280 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972
  1. // !!! DO NOT EDIT - This file is generated automatically - DO NOT EDIT !!!
  2. // Note: Key and IV will be different each time the file is generated
  3. //
  4. // SymmetricAlgorithmTest.cs - NUnit Test Cases for SymmetricAlgorithmTest
  5. //
  6. // Author:
  7. // Sebastien Pouliot ([email protected])
  8. //
  9. // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
  10. //
  11. using NUnit.Framework;
  12. using System;
  13. using System.Security.Cryptography;
  14. using System.Text;
  15. namespace MonoTests.System.Security.Cryptography {
  16. [TestFixture]
  17. public class SymmetricAlgorithmTest {
  18. public void AssertEquals (string msg, byte[] array1, byte[] array2)
  19. {
  20. AllTests.AssertEquals (msg, array1, array2);
  21. }
  22. //--8<-- NON GENERATED CODE STARTS HERE --8<----8<----8<----8<----8<----8<--
  23. //-->8-- NON GENERATED CODE ENDS HERE -->8---->8---->8---->8---->8---->8--
  24. private void Encrypt (ICryptoTransform trans, byte[] input, byte[] output)
  25. {
  26. int bs = trans.InputBlockSize;
  27. int full = input.Length / bs;
  28. int partial = input.Length % bs;
  29. int pos = 0;
  30. for (int i=0; i < full; i++) {
  31. trans.TransformBlock (input, pos, bs, output, pos);
  32. pos += bs;
  33. }
  34. if (partial > 0) {
  35. byte[] final = trans.TransformFinalBlock (input, pos, partial);
  36. Array.Copy (final, 0, output, pos, bs);
  37. }
  38. }
  39. private void Decrypt (ICryptoTransform trans, byte[] input, byte[] output)
  40. {
  41. int bs = trans.InputBlockSize;
  42. int full = input.Length / bs;
  43. int partial = input.Length % bs;
  44. int pos = 0;
  45. for (int i=0; i < full; i++) {
  46. trans.TransformBlock (input, pos, bs, output, pos);
  47. pos += bs;
  48. }
  49. if (partial > 0) {
  50. byte[] final = trans.TransformFinalBlock (input, pos, partial);
  51. Array.Copy (final, 0, output, pos, partial);
  52. }
  53. }
  54. [Test]
  55. public void TestDES_k64b64_ECB_None ()
  56. {
  57. byte[] key = { 0x12, 0xE7, 0x7B, 0xBF, 0x11, 0x90, 0x9D, 0xB0 };
  58. // not used for ECB but make the code more uniform
  59. byte[] iv = { 0xD2, 0x0E, 0xA7, 0xA4, 0x00, 0xF3, 0x17, 0x69 };
  60. byte[] expected = { 0x4B, 0x63, 0x6D, 0x2C, 0xA7, 0x0B, 0x77, 0x1C, 0x4B, 0x63, 0x6D, 0x2C, 0xA7, 0x0B, 0x77, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  61. SymmetricAlgorithm algo = DES.Create ();
  62. algo.Mode = CipherMode.ECB;
  63. algo.Padding = PaddingMode.None;
  64. algo.BlockSize = 64;
  65. int blockLength = (algo.BlockSize >> 3);
  66. byte[] input = new byte [blockLength * 2];
  67. byte[] output = new byte [blockLength * 3];
  68. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  69. Encrypt (encryptor, input, output);
  70. AssertEquals ("DES_k64b64_ECB_None Encrypt", expected, output);
  71. // in ECB the first 2 blocks should be equals (as the IV is not used)
  72. byte[] block1 = new byte[blockLength];
  73. Array.Copy (output, 0, block1, 0, blockLength);
  74. byte[] block2 = new byte[blockLength];
  75. Array.Copy (output, blockLength, block2, 0, blockLength);
  76. AssertEquals ("DES_k64b64_ECB_None b1==b2", block1, block2);
  77. byte[] reverse = new byte [blockLength * 3];
  78. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  79. Decrypt (decryptor, output, reverse);
  80. byte[] original = new byte [input.Length];
  81. Array.Copy (reverse, 0, original, 0, original.Length);
  82. AssertEquals ("DES_k64b64_ECB_None Decrypt", input, original);
  83. }
  84. [Test]
  85. public void TestDES_k64b64_ECB_Zeros ()
  86. {
  87. byte[] key = { 0x2E, 0xCA, 0x2E, 0xC9, 0x1A, 0xB6, 0x9A, 0x5A };
  88. // not used for ECB but make the code more uniform
  89. byte[] iv = { 0x79, 0x75, 0xD0, 0x3F, 0xFD, 0x1B, 0x12, 0x13 };
  90. byte[] expected = { 0x9B, 0x58, 0x07, 0x30, 0xE5, 0xDA, 0x3E, 0x7F, 0x9B, 0x58, 0x07, 0x30, 0xE5, 0xDA, 0x3E, 0x7F, 0x9B, 0x58, 0x07, 0x30, 0xE5, 0xDA, 0x3E, 0x7F };
  91. SymmetricAlgorithm algo = DES.Create ();
  92. algo.Mode = CipherMode.ECB;
  93. algo.Padding = PaddingMode.Zeros;
  94. algo.BlockSize = 64;
  95. int blockLength = (algo.BlockSize >> 3);
  96. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  97. byte[] output = new byte [blockLength * 3];
  98. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  99. Encrypt (encryptor, input, output);
  100. AssertEquals ("DES_k64b64_ECB_Zeros Encrypt", expected, output);
  101. // in ECB the first 2 blocks should be equals (as the IV is not used)
  102. byte[] block1 = new byte[blockLength];
  103. Array.Copy (output, 0, block1, 0, blockLength);
  104. byte[] block2 = new byte[blockLength];
  105. Array.Copy (output, blockLength, block2, 0, blockLength);
  106. AssertEquals ("DES_k64b64_ECB_Zeros b1==b2", block1, block2);
  107. // also if padding is Zeros then all three blocks should be equals
  108. byte[] block3 = new byte[blockLength];
  109. Array.Copy (output, blockLength, block3, 0, blockLength);
  110. AssertEquals ("DES_k64b64_ECB_Zeros b1==b3", block1, block3);
  111. byte[] reverse = new byte [blockLength * 3];
  112. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  113. Decrypt (decryptor, output, reverse);
  114. byte[] original = new byte [input.Length];
  115. Array.Copy (reverse, 0, original, 0, original.Length);
  116. AssertEquals ("DES_k64b64_ECB_Zeros Decrypt", input, original);
  117. }
  118. [Test]
  119. public void TestDES_k64b64_ECB_PKCS7 ()
  120. {
  121. byte[] key = { 0x32, 0xE8, 0x8D, 0xF7, 0xDC, 0xFC, 0x6C, 0xCD };
  122. // not used for ECB but make the code more uniform
  123. byte[] iv = { 0x74, 0xB2, 0x5E, 0x33, 0xBD, 0xA3, 0xC1, 0xB8 };
  124. byte[] expected = { 0x0E, 0xB6, 0xA5, 0x6F, 0x4A, 0xAE, 0xED, 0x95, 0x0E, 0xB6, 0xA5, 0x6F, 0x4A, 0xAE, 0xED, 0x95, 0x45, 0xEC, 0x24, 0x40, 0xF4, 0xB3, 0x97, 0xF3 };
  125. SymmetricAlgorithm algo = DES.Create ();
  126. algo.Mode = CipherMode.ECB;
  127. algo.Padding = PaddingMode.PKCS7;
  128. algo.BlockSize = 64;
  129. int blockLength = (algo.BlockSize >> 3);
  130. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  131. byte[] output = new byte [blockLength * 3];
  132. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  133. Encrypt (encryptor, input, output);
  134. AssertEquals ("DES_k64b64_ECB_PKCS7 Encrypt", expected, output);
  135. // in ECB the first 2 blocks should be equals (as the IV is not used)
  136. byte[] block1 = new byte[blockLength];
  137. Array.Copy (output, 0, block1, 0, blockLength);
  138. byte[] block2 = new byte[blockLength];
  139. Array.Copy (output, blockLength, block2, 0, blockLength);
  140. AssertEquals ("DES_k64b64_ECB_PKCS7 b1==b2", block1, block2);
  141. byte[] reverse = new byte [blockLength * 3];
  142. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  143. Decrypt (decryptor, output, reverse);
  144. byte[] original = new byte [input.Length];
  145. Array.Copy (reverse, 0, original, 0, original.Length);
  146. AssertEquals ("DES_k64b64_ECB_PKCS7 Decrypt", input, original);
  147. }
  148. [Test]
  149. public void TestDES_k64b64_CBC_None ()
  150. {
  151. byte[] key = { 0x91, 0xB4, 0x33, 0xB9, 0xA3, 0x7C, 0x47, 0x76 };
  152. byte[] iv = { 0x96, 0x98, 0xCC, 0x84, 0xDD, 0xC3, 0xA1, 0x14 };
  153. byte[] expected = { 0x71, 0x8A, 0xD7, 0xC1, 0x3F, 0xBC, 0x0C, 0xB7, 0xB7, 0x91, 0x96, 0x6A, 0xA9, 0xA6, 0xFC, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  154. SymmetricAlgorithm algo = DES.Create ();
  155. algo.Mode = CipherMode.CBC;
  156. algo.Padding = PaddingMode.None;
  157. algo.BlockSize = 64;
  158. int blockLength = (algo.BlockSize >> 3);
  159. byte[] input = new byte [blockLength * 2];
  160. byte[] output = new byte [blockLength * 3];
  161. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  162. Encrypt (encryptor, input, output);
  163. AssertEquals ("DES_k64b64_CBC_None Encrypt", expected, output);
  164. byte[] reverse = new byte [blockLength * 3];
  165. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  166. Decrypt (decryptor, output, reverse);
  167. byte[] original = new byte [input.Length];
  168. Array.Copy (reverse, 0, original, 0, original.Length);
  169. AssertEquals ("DES_k64b64_CBC_None Decrypt", input, original);
  170. }
  171. [Test]
  172. public void TestDES_k64b64_CBC_Zeros ()
  173. {
  174. byte[] key = { 0x4A, 0x8B, 0xC7, 0xC5, 0x9C, 0x10, 0xB4, 0x6C };
  175. byte[] iv = { 0x4B, 0x53, 0x53, 0xEA, 0xAF, 0xCC, 0x5A, 0x2B };
  176. byte[] expected = { 0xCA, 0xBC, 0xB7, 0xB9, 0xCF, 0x72, 0x63, 0x1F, 0x83, 0x96, 0xA4, 0xB7, 0x95, 0xF7, 0xFE, 0x13, 0x90, 0x6A, 0x4B, 0x74, 0x9E, 0xE0, 0xF9, 0x30 };
  177. SymmetricAlgorithm algo = DES.Create ();
  178. algo.Mode = CipherMode.CBC;
  179. algo.Padding = PaddingMode.Zeros;
  180. algo.BlockSize = 64;
  181. int blockLength = (algo.BlockSize >> 3);
  182. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  183. byte[] output = new byte [blockLength * 3];
  184. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  185. Encrypt (encryptor, input, output);
  186. AssertEquals ("DES_k64b64_CBC_Zeros Encrypt", expected, output);
  187. byte[] reverse = new byte [blockLength * 3];
  188. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  189. Decrypt (decryptor, output, reverse);
  190. byte[] original = new byte [input.Length];
  191. Array.Copy (reverse, 0, original, 0, original.Length);
  192. AssertEquals ("DES_k64b64_CBC_Zeros Decrypt", input, original);
  193. }
  194. [Test]
  195. public void TestDES_k64b64_CBC_PKCS7 ()
  196. {
  197. byte[] key = { 0xEA, 0x7D, 0x6D, 0x2C, 0xB8, 0x93, 0x33, 0xF4 };
  198. byte[] iv = { 0x77, 0xE4, 0xAA, 0x7C, 0xFE, 0xA9, 0x0F, 0x94 };
  199. byte[] expected = { 0x83, 0xB0, 0x83, 0xCA, 0xAC, 0x64, 0xE3, 0xDF, 0x1F, 0x5B, 0xE2, 0x9C, 0x16, 0x3E, 0x68, 0x91, 0x9E, 0xE5, 0xB5, 0x67, 0x80, 0xD2, 0x52, 0xC6 };
  200. SymmetricAlgorithm algo = DES.Create ();
  201. algo.Mode = CipherMode.CBC;
  202. algo.Padding = PaddingMode.PKCS7;
  203. algo.BlockSize = 64;
  204. int blockLength = (algo.BlockSize >> 3);
  205. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  206. byte[] output = new byte [blockLength * 3];
  207. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  208. Encrypt (encryptor, input, output);
  209. AssertEquals ("DES_k64b64_CBC_PKCS7 Encrypt", expected, output);
  210. byte[] reverse = new byte [blockLength * 3];
  211. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  212. Decrypt (decryptor, output, reverse);
  213. byte[] original = new byte [input.Length];
  214. Array.Copy (reverse, 0, original, 0, original.Length);
  215. AssertEquals ("DES_k64b64_CBC_PKCS7 Decrypt", input, original);
  216. }
  217. /* Invalid parameters DES_k64b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  218. /* Invalid parameters DES_k64b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  219. /* Invalid parameters DES_k64b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  220. [Test]
  221. public void TestDES_k64b64_CFB8_None ()
  222. {
  223. byte[] key = { 0x52, 0x5E, 0x49, 0x90, 0x10, 0x20, 0x6D, 0x5C };
  224. byte[] iv = { 0x00, 0x45, 0x9B, 0x7F, 0xC2, 0x9D, 0x90, 0x37 };
  225. byte[] expected = { 0x9C, 0x9F, 0xE0, 0x9F, 0x2E, 0x0C, 0xE0, 0xBA, 0xD3, 0x2F, 0xF4, 0x54, 0x89, 0x83, 0x82, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  226. SymmetricAlgorithm algo = DES.Create ();
  227. algo.Mode = CipherMode.CFB;
  228. algo.Padding = PaddingMode.None;
  229. algo.BlockSize = 64;
  230. algo.FeedbackSize = 8;
  231. int blockLength = (algo.BlockSize >> 3);
  232. byte[] input = new byte [blockLength * 2];
  233. byte[] output = new byte [blockLength * 3];
  234. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  235. Encrypt (encryptor, input, output);
  236. AssertEquals ("DES_k64b64_CFB8_None Encrypt", expected, output);
  237. byte[] reverse = new byte [blockLength * 3];
  238. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  239. Decrypt (decryptor, output, reverse);
  240. byte[] original = new byte [input.Length];
  241. Array.Copy (reverse, 0, original, 0, original.Length);
  242. AssertEquals ("DES_k64b64_CFB8_None Decrypt", input, original);
  243. }
  244. [Test]
  245. public void TestDES_k64b64_CFB8_Zeros ()
  246. {
  247. byte[] key = { 0xAF, 0x35, 0x0A, 0x91, 0x8F, 0x45, 0x46, 0xAF };
  248. byte[] iv = { 0x3A, 0xF5, 0xCD, 0x22, 0xDC, 0xEF, 0xF4, 0x61 };
  249. byte[] expected = { 0xFB, 0x7E, 0xA8, 0xEC, 0xC0, 0x65, 0x30, 0xE3, 0x84, 0xBC, 0x49, 0xB9, 0x1C, 0xFD, 0xF6, 0x81, 0xCE, 0x2A, 0x69, 0x70, 0x73, 0xF0, 0x9A, 0xA8 };
  250. SymmetricAlgorithm algo = DES.Create ();
  251. algo.Mode = CipherMode.CFB;
  252. algo.Padding = PaddingMode.Zeros;
  253. algo.BlockSize = 64;
  254. algo.FeedbackSize = 8;
  255. int blockLength = (algo.BlockSize >> 3);
  256. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  257. byte[] output = new byte [blockLength * 3];
  258. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  259. Encrypt (encryptor, input, output);
  260. AssertEquals ("DES_k64b64_CFB8_Zeros Encrypt", expected, output);
  261. byte[] reverse = new byte [blockLength * 3];
  262. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  263. Decrypt (decryptor, output, reverse);
  264. byte[] original = new byte [input.Length];
  265. Array.Copy (reverse, 0, original, 0, original.Length);
  266. AssertEquals ("DES_k64b64_CFB8_Zeros Decrypt", input, original);
  267. }
  268. [Test]
  269. public void TestDES_k64b64_CFB8_PKCS7 ()
  270. {
  271. byte[] key = { 0x5D, 0xAD, 0x6F, 0xFF, 0x48, 0x89, 0x18, 0xE6 };
  272. byte[] iv = { 0x98, 0x46, 0xD3, 0xFC, 0x1A, 0x59, 0xF6, 0x20 };
  273. byte[] expected = { 0xC3, 0xAC, 0xCF, 0x49, 0xFF, 0x46, 0x82, 0x21, 0xE8, 0x1F, 0x31, 0x4E, 0x1C, 0x33, 0xEA, 0x49, 0x54, 0x67, 0x3E, 0x9C, 0xFD, 0x77, 0x39, 0x69 };
  274. SymmetricAlgorithm algo = DES.Create ();
  275. algo.Mode = CipherMode.CFB;
  276. algo.Padding = PaddingMode.PKCS7;
  277. algo.BlockSize = 64;
  278. algo.FeedbackSize = 8;
  279. int blockLength = (algo.BlockSize >> 3);
  280. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  281. byte[] output = new byte [blockLength * 3];
  282. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  283. Encrypt (encryptor, input, output);
  284. AssertEquals ("DES_k64b64_CFB8_PKCS7 Encrypt", expected, output);
  285. byte[] reverse = new byte [blockLength * 3];
  286. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  287. Decrypt (decryptor, output, reverse);
  288. byte[] original = new byte [input.Length];
  289. Array.Copy (reverse, 0, original, 0, original.Length);
  290. AssertEquals ("DES_k64b64_CFB8_PKCS7 Decrypt", input, original);
  291. }
  292. /* Invalid parameters DES_k64b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  293. /* Invalid parameters DES_k64b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  294. /* Invalid parameters DES_k64b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  295. [Test]
  296. public void TestRC2_k40b64_ECB_None ()
  297. {
  298. byte[] key = { 0xC3, 0x69, 0xCB, 0x65, 0x22 };
  299. // not used for ECB but make the code more uniform
  300. byte[] iv = { 0x5E, 0x8E, 0xDB, 0xFD, 0x10, 0x1F, 0x14, 0x90 };
  301. byte[] expected = { 0xCC, 0x71, 0xF5, 0xC1, 0x2F, 0xAF, 0xB8, 0xF4, 0xCC, 0x71, 0xF5, 0xC1, 0x2F, 0xAF, 0xB8, 0xF4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  302. SymmetricAlgorithm algo = RC2.Create ();
  303. algo.Mode = CipherMode.ECB;
  304. algo.Padding = PaddingMode.None;
  305. algo.BlockSize = 64;
  306. int blockLength = (algo.BlockSize >> 3);
  307. byte[] input = new byte [blockLength * 2];
  308. byte[] output = new byte [blockLength * 3];
  309. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  310. Encrypt (encryptor, input, output);
  311. AssertEquals ("RC2_k40b64_ECB_None Encrypt", expected, output);
  312. // in ECB the first 2 blocks should be equals (as the IV is not used)
  313. byte[] block1 = new byte[blockLength];
  314. Array.Copy (output, 0, block1, 0, blockLength);
  315. byte[] block2 = new byte[blockLength];
  316. Array.Copy (output, blockLength, block2, 0, blockLength);
  317. AssertEquals ("RC2_k40b64_ECB_None b1==b2", block1, block2);
  318. byte[] reverse = new byte [blockLength * 3];
  319. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  320. Decrypt (decryptor, output, reverse);
  321. byte[] original = new byte [input.Length];
  322. Array.Copy (reverse, 0, original, 0, original.Length);
  323. AssertEquals ("RC2_k40b64_ECB_None Decrypt", input, original);
  324. }
  325. [Test]
  326. public void TestRC2_k40b64_ECB_Zeros ()
  327. {
  328. byte[] key = { 0x12, 0x66, 0x49, 0x15, 0xBC };
  329. // not used for ECB but make the code more uniform
  330. byte[] iv = { 0x3C, 0x1C, 0x38, 0x12, 0x1C, 0x78, 0x0C, 0x19 };
  331. byte[] expected = { 0xDF, 0xD0, 0xD8, 0x24, 0xD8, 0x22, 0x51, 0x7C, 0xDF, 0xD0, 0xD8, 0x24, 0xD8, 0x22, 0x51, 0x7C, 0xDF, 0xD0, 0xD8, 0x24, 0xD8, 0x22, 0x51, 0x7C };
  332. SymmetricAlgorithm algo = RC2.Create ();
  333. algo.Mode = CipherMode.ECB;
  334. algo.Padding = PaddingMode.Zeros;
  335. algo.BlockSize = 64;
  336. int blockLength = (algo.BlockSize >> 3);
  337. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  338. byte[] output = new byte [blockLength * 3];
  339. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  340. Encrypt (encryptor, input, output);
  341. AssertEquals ("RC2_k40b64_ECB_Zeros Encrypt", expected, output);
  342. // in ECB the first 2 blocks should be equals (as the IV is not used)
  343. byte[] block1 = new byte[blockLength];
  344. Array.Copy (output, 0, block1, 0, blockLength);
  345. byte[] block2 = new byte[blockLength];
  346. Array.Copy (output, blockLength, block2, 0, blockLength);
  347. AssertEquals ("RC2_k40b64_ECB_Zeros b1==b2", block1, block2);
  348. // also if padding is Zeros then all three blocks should be equals
  349. byte[] block3 = new byte[blockLength];
  350. Array.Copy (output, blockLength, block3, 0, blockLength);
  351. AssertEquals ("RC2_k40b64_ECB_Zeros b1==b3", block1, block3);
  352. byte[] reverse = new byte [blockLength * 3];
  353. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  354. Decrypt (decryptor, output, reverse);
  355. byte[] original = new byte [input.Length];
  356. Array.Copy (reverse, 0, original, 0, original.Length);
  357. AssertEquals ("RC2_k40b64_ECB_Zeros Decrypt", input, original);
  358. }
  359. [Test]
  360. public void TestRC2_k40b64_ECB_PKCS7 ()
  361. {
  362. byte[] key = { 0xC2, 0x76, 0x2F, 0xCE, 0xED };
  363. // not used for ECB but make the code more uniform
  364. byte[] iv = { 0xB1, 0x88, 0x93, 0x03, 0xDA, 0x23, 0xE6, 0x87 };
  365. byte[] expected = { 0xE2, 0x9B, 0x89, 0x15, 0xEC, 0x57, 0x0B, 0x05, 0xE2, 0x9B, 0x89, 0x15, 0xEC, 0x57, 0x0B, 0x05, 0x44, 0x77, 0xF0, 0x47, 0x2A, 0x12, 0xEA, 0xA1 };
  366. SymmetricAlgorithm algo = RC2.Create ();
  367. algo.Mode = CipherMode.ECB;
  368. algo.Padding = PaddingMode.PKCS7;
  369. algo.BlockSize = 64;
  370. int blockLength = (algo.BlockSize >> 3);
  371. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  372. byte[] output = new byte [blockLength * 3];
  373. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  374. Encrypt (encryptor, input, output);
  375. AssertEquals ("RC2_k40b64_ECB_PKCS7 Encrypt", expected, output);
  376. // in ECB the first 2 blocks should be equals (as the IV is not used)
  377. byte[] block1 = new byte[blockLength];
  378. Array.Copy (output, 0, block1, 0, blockLength);
  379. byte[] block2 = new byte[blockLength];
  380. Array.Copy (output, blockLength, block2, 0, blockLength);
  381. AssertEquals ("RC2_k40b64_ECB_PKCS7 b1==b2", block1, block2);
  382. byte[] reverse = new byte [blockLength * 3];
  383. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  384. Decrypt (decryptor, output, reverse);
  385. byte[] original = new byte [input.Length];
  386. Array.Copy (reverse, 0, original, 0, original.Length);
  387. AssertEquals ("RC2_k40b64_ECB_PKCS7 Decrypt", input, original);
  388. }
  389. [Test]
  390. public void TestRC2_k40b64_CBC_None ()
  391. {
  392. byte[] key = { 0xD0, 0xE1, 0x4E, 0x9C, 0x58 };
  393. byte[] iv = { 0x8E, 0x5E, 0x76, 0x18, 0xB8, 0x76, 0xCF, 0x77 };
  394. byte[] expected = { 0x36, 0x1B, 0x18, 0x98, 0xEE, 0xC6, 0x18, 0xB8, 0x67, 0xC0, 0x92, 0x09, 0x22, 0xDC, 0x65, 0xC5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  395. SymmetricAlgorithm algo = RC2.Create ();
  396. algo.Mode = CipherMode.CBC;
  397. algo.Padding = PaddingMode.None;
  398. algo.BlockSize = 64;
  399. int blockLength = (algo.BlockSize >> 3);
  400. byte[] input = new byte [blockLength * 2];
  401. byte[] output = new byte [blockLength * 3];
  402. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  403. Encrypt (encryptor, input, output);
  404. AssertEquals ("RC2_k40b64_CBC_None Encrypt", expected, output);
  405. byte[] reverse = new byte [blockLength * 3];
  406. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  407. Decrypt (decryptor, output, reverse);
  408. byte[] original = new byte [input.Length];
  409. Array.Copy (reverse, 0, original, 0, original.Length);
  410. AssertEquals ("RC2_k40b64_CBC_None Decrypt", input, original);
  411. }
  412. [Test]
  413. public void TestRC2_k40b64_CBC_Zeros ()
  414. {
  415. byte[] key = { 0xB5, 0x6F, 0xC7, 0x4F, 0xF8 };
  416. byte[] iv = { 0xB6, 0x95, 0xE9, 0x3E, 0x04, 0x98, 0x39, 0x3D };
  417. byte[] expected = { 0x32, 0x10, 0x36, 0x24, 0x9F, 0xB6, 0x87, 0x4E, 0x00, 0xB6, 0xEF, 0x33, 0x52, 0x8B, 0xDE, 0x8A, 0x90, 0xE2, 0x0C, 0x60, 0xD3, 0x1A, 0x72, 0xCC };
  418. SymmetricAlgorithm algo = RC2.Create ();
  419. algo.Mode = CipherMode.CBC;
  420. algo.Padding = PaddingMode.Zeros;
  421. algo.BlockSize = 64;
  422. int blockLength = (algo.BlockSize >> 3);
  423. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  424. byte[] output = new byte [blockLength * 3];
  425. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  426. Encrypt (encryptor, input, output);
  427. AssertEquals ("RC2_k40b64_CBC_Zeros Encrypt", expected, output);
  428. byte[] reverse = new byte [blockLength * 3];
  429. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  430. Decrypt (decryptor, output, reverse);
  431. byte[] original = new byte [input.Length];
  432. Array.Copy (reverse, 0, original, 0, original.Length);
  433. AssertEquals ("RC2_k40b64_CBC_Zeros Decrypt", input, original);
  434. }
  435. [Test]
  436. public void TestRC2_k40b64_CBC_PKCS7 ()
  437. {
  438. byte[] key = { 0x67, 0xB6, 0xEE, 0xF5, 0x21 };
  439. byte[] iv = { 0xD3, 0xF1, 0xE7, 0xFF, 0x23, 0x92, 0xDC, 0xD9 };
  440. byte[] expected = { 0x24, 0x2F, 0x90, 0xAE, 0x75, 0x8E, 0x0C, 0x7F, 0xCA, 0xE4, 0xE7, 0x87, 0x2D, 0xEE, 0x9E, 0x30, 0x49, 0xF0, 0xBB, 0xC4, 0x4C, 0x8D, 0x44, 0x5C };
  441. SymmetricAlgorithm algo = RC2.Create ();
  442. algo.Mode = CipherMode.CBC;
  443. algo.Padding = PaddingMode.PKCS7;
  444. algo.BlockSize = 64;
  445. int blockLength = (algo.BlockSize >> 3);
  446. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  447. byte[] output = new byte [blockLength * 3];
  448. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  449. Encrypt (encryptor, input, output);
  450. AssertEquals ("RC2_k40b64_CBC_PKCS7 Encrypt", expected, output);
  451. byte[] reverse = new byte [blockLength * 3];
  452. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  453. Decrypt (decryptor, output, reverse);
  454. byte[] original = new byte [input.Length];
  455. Array.Copy (reverse, 0, original, 0, original.Length);
  456. AssertEquals ("RC2_k40b64_CBC_PKCS7 Decrypt", input, original);
  457. }
  458. /* Invalid parameters RC2_k40b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  459. /* Invalid parameters RC2_k40b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  460. /* Invalid parameters RC2_k40b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  461. [Test]
  462. public void TestRC2_k40b64_CFB8_None ()
  463. {
  464. byte[] key = { 0x35, 0xCF, 0xA0, 0x20, 0x56 };
  465. byte[] iv = { 0xC5, 0x47, 0xFA, 0x9D, 0x19, 0x4F, 0xA9, 0x06 };
  466. byte[] expected = { 0xEF, 0xF9, 0xE1, 0xEE, 0x23, 0x89, 0xF6, 0x6B, 0x1F, 0xA6, 0x07, 0xAC, 0x73, 0x4A, 0xC1, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  467. SymmetricAlgorithm algo = RC2.Create ();
  468. algo.Mode = CipherMode.CFB;
  469. algo.Padding = PaddingMode.None;
  470. algo.BlockSize = 64;
  471. algo.FeedbackSize = 8;
  472. int blockLength = (algo.BlockSize >> 3);
  473. byte[] input = new byte [blockLength * 2];
  474. byte[] output = new byte [blockLength * 3];
  475. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  476. Encrypt (encryptor, input, output);
  477. AssertEquals ("RC2_k40b64_CFB8_None Encrypt", expected, output);
  478. byte[] reverse = new byte [blockLength * 3];
  479. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  480. Decrypt (decryptor, output, reverse);
  481. byte[] original = new byte [input.Length];
  482. Array.Copy (reverse, 0, original, 0, original.Length);
  483. AssertEquals ("RC2_k40b64_CFB8_None Decrypt", input, original);
  484. }
  485. [Test]
  486. public void TestRC2_k40b64_CFB8_Zeros ()
  487. {
  488. byte[] key = { 0xDA, 0xD8, 0xF9, 0x76, 0xE4 };
  489. byte[] iv = { 0xAA, 0xC5, 0x42, 0xF9, 0x88, 0x42, 0x09, 0xB4 };
  490. byte[] expected = { 0x49, 0x08, 0xFD, 0x7B, 0x1A, 0xA2, 0xDB, 0xF3, 0xB7, 0x13, 0x01, 0x4F, 0xB8, 0x79, 0x3A, 0x0E, 0xA0, 0x11, 0x1E, 0x27, 0xA7, 0xFE, 0xFA, 0x48 };
  491. SymmetricAlgorithm algo = RC2.Create ();
  492. algo.Mode = CipherMode.CFB;
  493. algo.Padding = PaddingMode.Zeros;
  494. algo.BlockSize = 64;
  495. algo.FeedbackSize = 8;
  496. int blockLength = (algo.BlockSize >> 3);
  497. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  498. byte[] output = new byte [blockLength * 3];
  499. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  500. Encrypt (encryptor, input, output);
  501. AssertEquals ("RC2_k40b64_CFB8_Zeros Encrypt", expected, output);
  502. byte[] reverse = new byte [blockLength * 3];
  503. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  504. Decrypt (decryptor, output, reverse);
  505. byte[] original = new byte [input.Length];
  506. Array.Copy (reverse, 0, original, 0, original.Length);
  507. AssertEquals ("RC2_k40b64_CFB8_Zeros Decrypt", input, original);
  508. }
  509. [Test]
  510. public void TestRC2_k40b64_CFB8_PKCS7 ()
  511. {
  512. byte[] key = { 0xDF, 0x8C, 0xC7, 0x3C, 0xDE };
  513. byte[] iv = { 0x1D, 0x0A, 0x92, 0x74, 0xD6, 0xEB, 0x99, 0x0F };
  514. byte[] expected = { 0xF9, 0x7A, 0x8E, 0xE1, 0xF2, 0x93, 0xB8, 0xCF, 0xD4, 0x7C, 0xF8, 0x81, 0x7F, 0x53, 0x7C, 0x8F, 0x42, 0x8C, 0xC4, 0xFB, 0x9E, 0x0C, 0x65, 0x53 };
  515. SymmetricAlgorithm algo = RC2.Create ();
  516. algo.Mode = CipherMode.CFB;
  517. algo.Padding = PaddingMode.PKCS7;
  518. algo.BlockSize = 64;
  519. algo.FeedbackSize = 8;
  520. int blockLength = (algo.BlockSize >> 3);
  521. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  522. byte[] output = new byte [blockLength * 3];
  523. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  524. Encrypt (encryptor, input, output);
  525. AssertEquals ("RC2_k40b64_CFB8_PKCS7 Encrypt", expected, output);
  526. byte[] reverse = new byte [blockLength * 3];
  527. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  528. Decrypt (decryptor, output, reverse);
  529. byte[] original = new byte [input.Length];
  530. Array.Copy (reverse, 0, original, 0, original.Length);
  531. AssertEquals ("RC2_k40b64_CFB8_PKCS7 Decrypt", input, original);
  532. }
  533. /* Invalid parameters RC2_k40b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  534. /* Invalid parameters RC2_k40b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  535. /* Invalid parameters RC2_k40b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  536. [Test]
  537. public void TestRC2_k48b64_ECB_None ()
  538. {
  539. byte[] key = { 0xAA, 0x37, 0x60, 0x52, 0x8A, 0xBE };
  540. // not used for ECB but make the code more uniform
  541. byte[] iv = { 0x0D, 0x5B, 0x94, 0x0F, 0x9A, 0x87, 0x08, 0x56 };
  542. byte[] expected = { 0xB4, 0xB4, 0x2B, 0x12, 0x9C, 0x07, 0xD4, 0xC9, 0xB4, 0xB4, 0x2B, 0x12, 0x9C, 0x07, 0xD4, 0xC9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  543. SymmetricAlgorithm algo = RC2.Create ();
  544. algo.Mode = CipherMode.ECB;
  545. algo.Padding = PaddingMode.None;
  546. algo.BlockSize = 64;
  547. int blockLength = (algo.BlockSize >> 3);
  548. byte[] input = new byte [blockLength * 2];
  549. byte[] output = new byte [blockLength * 3];
  550. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  551. Encrypt (encryptor, input, output);
  552. AssertEquals ("RC2_k48b64_ECB_None Encrypt", expected, output);
  553. // in ECB the first 2 blocks should be equals (as the IV is not used)
  554. byte[] block1 = new byte[blockLength];
  555. Array.Copy (output, 0, block1, 0, blockLength);
  556. byte[] block2 = new byte[blockLength];
  557. Array.Copy (output, blockLength, block2, 0, blockLength);
  558. AssertEquals ("RC2_k48b64_ECB_None b1==b2", block1, block2);
  559. byte[] reverse = new byte [blockLength * 3];
  560. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  561. Decrypt (decryptor, output, reverse);
  562. byte[] original = new byte [input.Length];
  563. Array.Copy (reverse, 0, original, 0, original.Length);
  564. AssertEquals ("RC2_k48b64_ECB_None Decrypt", input, original);
  565. }
  566. [Test]
  567. public void TestRC2_k48b64_ECB_Zeros ()
  568. {
  569. byte[] key = { 0x9B, 0x92, 0x8C, 0xC2, 0x18, 0xA3 };
  570. // not used for ECB but make the code more uniform
  571. byte[] iv = { 0xB7, 0xC2, 0xAD, 0x13, 0x0A, 0x62, 0x0A, 0x50 };
  572. byte[] expected = { 0x24, 0x74, 0x0F, 0x4B, 0xAA, 0xB1, 0xB8, 0xF5, 0x24, 0x74, 0x0F, 0x4B, 0xAA, 0xB1, 0xB8, 0xF5, 0x24, 0x74, 0x0F, 0x4B, 0xAA, 0xB1, 0xB8, 0xF5 };
  573. SymmetricAlgorithm algo = RC2.Create ();
  574. algo.Mode = CipherMode.ECB;
  575. algo.Padding = PaddingMode.Zeros;
  576. algo.BlockSize = 64;
  577. int blockLength = (algo.BlockSize >> 3);
  578. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  579. byte[] output = new byte [blockLength * 3];
  580. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  581. Encrypt (encryptor, input, output);
  582. AssertEquals ("RC2_k48b64_ECB_Zeros Encrypt", expected, output);
  583. // in ECB the first 2 blocks should be equals (as the IV is not used)
  584. byte[] block1 = new byte[blockLength];
  585. Array.Copy (output, 0, block1, 0, blockLength);
  586. byte[] block2 = new byte[blockLength];
  587. Array.Copy (output, blockLength, block2, 0, blockLength);
  588. AssertEquals ("RC2_k48b64_ECB_Zeros b1==b2", block1, block2);
  589. // also if padding is Zeros then all three blocks should be equals
  590. byte[] block3 = new byte[blockLength];
  591. Array.Copy (output, blockLength, block3, 0, blockLength);
  592. AssertEquals ("RC2_k48b64_ECB_Zeros b1==b3", block1, block3);
  593. byte[] reverse = new byte [blockLength * 3];
  594. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  595. Decrypt (decryptor, output, reverse);
  596. byte[] original = new byte [input.Length];
  597. Array.Copy (reverse, 0, original, 0, original.Length);
  598. AssertEquals ("RC2_k48b64_ECB_Zeros Decrypt", input, original);
  599. }
  600. [Test]
  601. public void TestRC2_k48b64_ECB_PKCS7 ()
  602. {
  603. byte[] key = { 0x58, 0x1A, 0xD6, 0x96, 0x02, 0x75 };
  604. // not used for ECB but make the code more uniform
  605. byte[] iv = { 0x56, 0x83, 0x39, 0x7F, 0x3B, 0xD9, 0xB0, 0x33 };
  606. byte[] expected = { 0x87, 0x46, 0x9E, 0xFF, 0x4B, 0xE8, 0xDA, 0xF2, 0x87, 0x46, 0x9E, 0xFF, 0x4B, 0xE8, 0xDA, 0xF2, 0x31, 0x54, 0x04, 0x63, 0xE0, 0x76, 0x74, 0x39 };
  607. SymmetricAlgorithm algo = RC2.Create ();
  608. algo.Mode = CipherMode.ECB;
  609. algo.Padding = PaddingMode.PKCS7;
  610. algo.BlockSize = 64;
  611. int blockLength = (algo.BlockSize >> 3);
  612. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  613. byte[] output = new byte [blockLength * 3];
  614. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  615. Encrypt (encryptor, input, output);
  616. AssertEquals ("RC2_k48b64_ECB_PKCS7 Encrypt", expected, output);
  617. // in ECB the first 2 blocks should be equals (as the IV is not used)
  618. byte[] block1 = new byte[blockLength];
  619. Array.Copy (output, 0, block1, 0, blockLength);
  620. byte[] block2 = new byte[blockLength];
  621. Array.Copy (output, blockLength, block2, 0, blockLength);
  622. AssertEquals ("RC2_k48b64_ECB_PKCS7 b1==b2", block1, block2);
  623. byte[] reverse = new byte [blockLength * 3];
  624. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  625. Decrypt (decryptor, output, reverse);
  626. byte[] original = new byte [input.Length];
  627. Array.Copy (reverse, 0, original, 0, original.Length);
  628. AssertEquals ("RC2_k48b64_ECB_PKCS7 Decrypt", input, original);
  629. }
  630. [Test]
  631. public void TestRC2_k48b64_CBC_None ()
  632. {
  633. byte[] key = { 0x21, 0x9A, 0xD6, 0x31, 0x99, 0x81 };
  634. byte[] iv = { 0x5E, 0x6E, 0xB6, 0x33, 0xC0, 0x25, 0xAE, 0x5C };
  635. byte[] expected = { 0x35, 0xFA, 0x8F, 0x4F, 0x75, 0xD1, 0x10, 0x11, 0xC0, 0xA4, 0x73, 0x69, 0xBD, 0xD2, 0xE3, 0x9D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  636. SymmetricAlgorithm algo = RC2.Create ();
  637. algo.Mode = CipherMode.CBC;
  638. algo.Padding = PaddingMode.None;
  639. algo.BlockSize = 64;
  640. int blockLength = (algo.BlockSize >> 3);
  641. byte[] input = new byte [blockLength * 2];
  642. byte[] output = new byte [blockLength * 3];
  643. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  644. Encrypt (encryptor, input, output);
  645. AssertEquals ("RC2_k48b64_CBC_None Encrypt", expected, output);
  646. byte[] reverse = new byte [blockLength * 3];
  647. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  648. Decrypt (decryptor, output, reverse);
  649. byte[] original = new byte [input.Length];
  650. Array.Copy (reverse, 0, original, 0, original.Length);
  651. AssertEquals ("RC2_k48b64_CBC_None Decrypt", input, original);
  652. }
  653. [Test]
  654. public void TestRC2_k48b64_CBC_Zeros ()
  655. {
  656. byte[] key = { 0x59, 0x0A, 0xD4, 0x25, 0xA5, 0xB9 };
  657. byte[] iv = { 0x10, 0x2D, 0x42, 0x54, 0xC8, 0x97, 0xD0, 0xA7 };
  658. byte[] expected = { 0x4F, 0x1A, 0x5F, 0xD0, 0xA2, 0x54, 0x57, 0x60, 0x55, 0x9B, 0x4D, 0x1B, 0x55, 0xC9, 0x30, 0xA9, 0x7E, 0xF6, 0xAF, 0xFB, 0x50, 0x8B, 0xC0, 0xB6 };
  659. SymmetricAlgorithm algo = RC2.Create ();
  660. algo.Mode = CipherMode.CBC;
  661. algo.Padding = PaddingMode.Zeros;
  662. algo.BlockSize = 64;
  663. int blockLength = (algo.BlockSize >> 3);
  664. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  665. byte[] output = new byte [blockLength * 3];
  666. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  667. Encrypt (encryptor, input, output);
  668. AssertEquals ("RC2_k48b64_CBC_Zeros Encrypt", expected, output);
  669. byte[] reverse = new byte [blockLength * 3];
  670. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  671. Decrypt (decryptor, output, reverse);
  672. byte[] original = new byte [input.Length];
  673. Array.Copy (reverse, 0, original, 0, original.Length);
  674. AssertEquals ("RC2_k48b64_CBC_Zeros Decrypt", input, original);
  675. }
  676. [Test]
  677. public void TestRC2_k48b64_CBC_PKCS7 ()
  678. {
  679. byte[] key = { 0x39, 0x6C, 0xB3, 0x7B, 0xB5, 0xA9 };
  680. byte[] iv = { 0x42, 0x56, 0x99, 0x18, 0xA8, 0x96, 0x93, 0x5D };
  681. byte[] expected = { 0x92, 0x8B, 0x67, 0xC7, 0xAE, 0xF3, 0xF7, 0x03, 0x24, 0x67, 0xAC, 0xEA, 0xFE, 0xB7, 0x6B, 0x1E, 0x53, 0xB3, 0xF5, 0xDB, 0x64, 0x63, 0xB3, 0xE5 };
  682. SymmetricAlgorithm algo = RC2.Create ();
  683. algo.Mode = CipherMode.CBC;
  684. algo.Padding = PaddingMode.PKCS7;
  685. algo.BlockSize = 64;
  686. int blockLength = (algo.BlockSize >> 3);
  687. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  688. byte[] output = new byte [blockLength * 3];
  689. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  690. Encrypt (encryptor, input, output);
  691. AssertEquals ("RC2_k48b64_CBC_PKCS7 Encrypt", expected, output);
  692. byte[] reverse = new byte [blockLength * 3];
  693. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  694. Decrypt (decryptor, output, reverse);
  695. byte[] original = new byte [input.Length];
  696. Array.Copy (reverse, 0, original, 0, original.Length);
  697. AssertEquals ("RC2_k48b64_CBC_PKCS7 Decrypt", input, original);
  698. }
  699. /* Invalid parameters RC2_k48b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  700. /* Invalid parameters RC2_k48b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  701. /* Invalid parameters RC2_k48b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  702. [Test]
  703. public void TestRC2_k48b64_CFB8_None ()
  704. {
  705. byte[] key = { 0x06, 0xCE, 0x23, 0x86, 0xEC, 0xB3 };
  706. byte[] iv = { 0x14, 0xF7, 0xBA, 0xEC, 0xC2, 0x4A, 0x26, 0x6D };
  707. byte[] expected = { 0x69, 0x7A, 0x1A, 0xCC, 0x40, 0x41, 0x78, 0xC1, 0xFA, 0x89, 0x90, 0x7F, 0xC1, 0x1C, 0x27, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  708. SymmetricAlgorithm algo = RC2.Create ();
  709. algo.Mode = CipherMode.CFB;
  710. algo.Padding = PaddingMode.None;
  711. algo.BlockSize = 64;
  712. algo.FeedbackSize = 8;
  713. int blockLength = (algo.BlockSize >> 3);
  714. byte[] input = new byte [blockLength * 2];
  715. byte[] output = new byte [blockLength * 3];
  716. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  717. Encrypt (encryptor, input, output);
  718. AssertEquals ("RC2_k48b64_CFB8_None Encrypt", expected, output);
  719. byte[] reverse = new byte [blockLength * 3];
  720. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  721. Decrypt (decryptor, output, reverse);
  722. byte[] original = new byte [input.Length];
  723. Array.Copy (reverse, 0, original, 0, original.Length);
  724. AssertEquals ("RC2_k48b64_CFB8_None Decrypt", input, original);
  725. }
  726. [Test]
  727. public void TestRC2_k48b64_CFB8_Zeros ()
  728. {
  729. byte[] key = { 0x4B, 0xC8, 0x03, 0x4F, 0x43, 0x27 };
  730. byte[] iv = { 0x02, 0x24, 0xB8, 0xE9, 0xF6, 0x19, 0xA1, 0x81 };
  731. byte[] expected = { 0xE2, 0xD2, 0x50, 0x68, 0x56, 0x61, 0x30, 0x72, 0xA2, 0xDE, 0x97, 0xF5, 0x5C, 0xE9, 0xD5, 0xA0, 0x35, 0xD2, 0xC3, 0xEB, 0xC9, 0x2A, 0x64, 0x4D };
  732. SymmetricAlgorithm algo = RC2.Create ();
  733. algo.Mode = CipherMode.CFB;
  734. algo.Padding = PaddingMode.Zeros;
  735. algo.BlockSize = 64;
  736. algo.FeedbackSize = 8;
  737. int blockLength = (algo.BlockSize >> 3);
  738. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  739. byte[] output = new byte [blockLength * 3];
  740. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  741. Encrypt (encryptor, input, output);
  742. AssertEquals ("RC2_k48b64_CFB8_Zeros Encrypt", expected, output);
  743. byte[] reverse = new byte [blockLength * 3];
  744. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  745. Decrypt (decryptor, output, reverse);
  746. byte[] original = new byte [input.Length];
  747. Array.Copy (reverse, 0, original, 0, original.Length);
  748. AssertEquals ("RC2_k48b64_CFB8_Zeros Decrypt", input, original);
  749. }
  750. [Test]
  751. public void TestRC2_k48b64_CFB8_PKCS7 ()
  752. {
  753. byte[] key = { 0x22, 0x94, 0x8C, 0x13, 0x7F, 0x7A };
  754. byte[] iv = { 0x4B, 0xDF, 0xB8, 0xBF, 0x0D, 0xBE, 0x1E, 0x3D };
  755. byte[] expected = { 0x24, 0xE9, 0x2B, 0xBF, 0x84, 0x49, 0x4D, 0x2B, 0xC4, 0xD8, 0xEE, 0xAB, 0x52, 0x03, 0xC6, 0xAF, 0x19, 0x0A, 0x5B, 0x38, 0xB6, 0xF1, 0x98, 0x6F };
  756. SymmetricAlgorithm algo = RC2.Create ();
  757. algo.Mode = CipherMode.CFB;
  758. algo.Padding = PaddingMode.PKCS7;
  759. algo.BlockSize = 64;
  760. algo.FeedbackSize = 8;
  761. int blockLength = (algo.BlockSize >> 3);
  762. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  763. byte[] output = new byte [blockLength * 3];
  764. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  765. Encrypt (encryptor, input, output);
  766. AssertEquals ("RC2_k48b64_CFB8_PKCS7 Encrypt", expected, output);
  767. byte[] reverse = new byte [blockLength * 3];
  768. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  769. Decrypt (decryptor, output, reverse);
  770. byte[] original = new byte [input.Length];
  771. Array.Copy (reverse, 0, original, 0, original.Length);
  772. AssertEquals ("RC2_k48b64_CFB8_PKCS7 Decrypt", input, original);
  773. }
  774. /* Invalid parameters RC2_k48b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  775. /* Invalid parameters RC2_k48b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  776. /* Invalid parameters RC2_k48b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  777. [Test]
  778. public void TestRC2_k56b64_ECB_None ()
  779. {
  780. byte[] key = { 0xCA, 0x6B, 0x7A, 0xA1, 0xB1, 0x6E, 0x4A };
  781. // not used for ECB but make the code more uniform
  782. byte[] iv = { 0xF0, 0xA9, 0x35, 0xDB, 0x4F, 0xB5, 0x3D, 0xE4 };
  783. byte[] expected = { 0x23, 0x39, 0x2D, 0xD9, 0x7C, 0xC0, 0xFF, 0x64, 0x23, 0x39, 0x2D, 0xD9, 0x7C, 0xC0, 0xFF, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  784. SymmetricAlgorithm algo = RC2.Create ();
  785. algo.Mode = CipherMode.ECB;
  786. algo.Padding = PaddingMode.None;
  787. algo.BlockSize = 64;
  788. int blockLength = (algo.BlockSize >> 3);
  789. byte[] input = new byte [blockLength * 2];
  790. byte[] output = new byte [blockLength * 3];
  791. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  792. Encrypt (encryptor, input, output);
  793. AssertEquals ("RC2_k56b64_ECB_None Encrypt", expected, output);
  794. // in ECB the first 2 blocks should be equals (as the IV is not used)
  795. byte[] block1 = new byte[blockLength];
  796. Array.Copy (output, 0, block1, 0, blockLength);
  797. byte[] block2 = new byte[blockLength];
  798. Array.Copy (output, blockLength, block2, 0, blockLength);
  799. AssertEquals ("RC2_k56b64_ECB_None b1==b2", block1, block2);
  800. byte[] reverse = new byte [blockLength * 3];
  801. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  802. Decrypt (decryptor, output, reverse);
  803. byte[] original = new byte [input.Length];
  804. Array.Copy (reverse, 0, original, 0, original.Length);
  805. AssertEquals ("RC2_k56b64_ECB_None Decrypt", input, original);
  806. }
  807. [Test]
  808. public void TestRC2_k56b64_ECB_Zeros ()
  809. {
  810. byte[] key = { 0x96, 0x43, 0x86, 0xAA, 0x0E, 0x66, 0x95 };
  811. // not used for ECB but make the code more uniform
  812. byte[] iv = { 0xD3, 0xD7, 0x93, 0xED, 0xAF, 0xD6, 0x83, 0x3F };
  813. byte[] expected = { 0x1C, 0x72, 0x96, 0xCF, 0x7D, 0x18, 0xDB, 0x4B, 0x1C, 0x72, 0x96, 0xCF, 0x7D, 0x18, 0xDB, 0x4B, 0x1C, 0x72, 0x96, 0xCF, 0x7D, 0x18, 0xDB, 0x4B };
  814. SymmetricAlgorithm algo = RC2.Create ();
  815. algo.Mode = CipherMode.ECB;
  816. algo.Padding = PaddingMode.Zeros;
  817. algo.BlockSize = 64;
  818. int blockLength = (algo.BlockSize >> 3);
  819. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  820. byte[] output = new byte [blockLength * 3];
  821. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  822. Encrypt (encryptor, input, output);
  823. AssertEquals ("RC2_k56b64_ECB_Zeros Encrypt", expected, output);
  824. // in ECB the first 2 blocks should be equals (as the IV is not used)
  825. byte[] block1 = new byte[blockLength];
  826. Array.Copy (output, 0, block1, 0, blockLength);
  827. byte[] block2 = new byte[blockLength];
  828. Array.Copy (output, blockLength, block2, 0, blockLength);
  829. AssertEquals ("RC2_k56b64_ECB_Zeros b1==b2", block1, block2);
  830. // also if padding is Zeros then all three blocks should be equals
  831. byte[] block3 = new byte[blockLength];
  832. Array.Copy (output, blockLength, block3, 0, blockLength);
  833. AssertEquals ("RC2_k56b64_ECB_Zeros b1==b3", block1, block3);
  834. byte[] reverse = new byte [blockLength * 3];
  835. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  836. Decrypt (decryptor, output, reverse);
  837. byte[] original = new byte [input.Length];
  838. Array.Copy (reverse, 0, original, 0, original.Length);
  839. AssertEquals ("RC2_k56b64_ECB_Zeros Decrypt", input, original);
  840. }
  841. [Test]
  842. public void TestRC2_k56b64_ECB_PKCS7 ()
  843. {
  844. byte[] key = { 0x5A, 0x29, 0xE4, 0x77, 0x99, 0x9D, 0x5B };
  845. // not used for ECB but make the code more uniform
  846. byte[] iv = { 0xA6, 0x7B, 0x92, 0x40, 0x74, 0x9E, 0x0D, 0xAD };
  847. byte[] expected = { 0xE1, 0xBB, 0xAA, 0x43, 0x54, 0x2E, 0xFF, 0x3A, 0xE1, 0xBB, 0xAA, 0x43, 0x54, 0x2E, 0xFF, 0x3A, 0x2E, 0xA1, 0x81, 0xF1, 0x85, 0x86, 0x35, 0x97 };
  848. SymmetricAlgorithm algo = RC2.Create ();
  849. algo.Mode = CipherMode.ECB;
  850. algo.Padding = PaddingMode.PKCS7;
  851. algo.BlockSize = 64;
  852. int blockLength = (algo.BlockSize >> 3);
  853. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  854. byte[] output = new byte [blockLength * 3];
  855. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  856. Encrypt (encryptor, input, output);
  857. AssertEquals ("RC2_k56b64_ECB_PKCS7 Encrypt", expected, output);
  858. // in ECB the first 2 blocks should be equals (as the IV is not used)
  859. byte[] block1 = new byte[blockLength];
  860. Array.Copy (output, 0, block1, 0, blockLength);
  861. byte[] block2 = new byte[blockLength];
  862. Array.Copy (output, blockLength, block2, 0, blockLength);
  863. AssertEquals ("RC2_k56b64_ECB_PKCS7 b1==b2", block1, block2);
  864. byte[] reverse = new byte [blockLength * 3];
  865. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  866. Decrypt (decryptor, output, reverse);
  867. byte[] original = new byte [input.Length];
  868. Array.Copy (reverse, 0, original, 0, original.Length);
  869. AssertEquals ("RC2_k56b64_ECB_PKCS7 Decrypt", input, original);
  870. }
  871. [Test]
  872. public void TestRC2_k56b64_CBC_None ()
  873. {
  874. byte[] key = { 0xDD, 0x2F, 0x84, 0x9F, 0xBA, 0xB1, 0xF3 };
  875. byte[] iv = { 0x97, 0xB2, 0xCD, 0x3F, 0x1E, 0x53, 0xE8, 0xA9 };
  876. byte[] expected = { 0x63, 0x6E, 0x62, 0xE5, 0x0F, 0x58, 0x86, 0x4A, 0xEF, 0x64, 0x4C, 0xDC, 0x36, 0x5D, 0x29, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  877. SymmetricAlgorithm algo = RC2.Create ();
  878. algo.Mode = CipherMode.CBC;
  879. algo.Padding = PaddingMode.None;
  880. algo.BlockSize = 64;
  881. int blockLength = (algo.BlockSize >> 3);
  882. byte[] input = new byte [blockLength * 2];
  883. byte[] output = new byte [blockLength * 3];
  884. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  885. Encrypt (encryptor, input, output);
  886. AssertEquals ("RC2_k56b64_CBC_None Encrypt", expected, output);
  887. byte[] reverse = new byte [blockLength * 3];
  888. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  889. Decrypt (decryptor, output, reverse);
  890. byte[] original = new byte [input.Length];
  891. Array.Copy (reverse, 0, original, 0, original.Length);
  892. AssertEquals ("RC2_k56b64_CBC_None Decrypt", input, original);
  893. }
  894. [Test]
  895. public void TestRC2_k56b64_CBC_Zeros ()
  896. {
  897. byte[] key = { 0xED, 0xEE, 0x33, 0x8E, 0x97, 0x20, 0x58 };
  898. byte[] iv = { 0x0B, 0xAB, 0xAB, 0xED, 0xCC, 0x1C, 0x77, 0xA4 };
  899. byte[] expected = { 0x8B, 0x2F, 0x52, 0x93, 0x48, 0x7A, 0x54, 0x03, 0x58, 0x6A, 0x9B, 0xC4, 0x13, 0x99, 0xCD, 0xE2, 0x18, 0x31, 0x67, 0x05, 0x27, 0x90, 0x1D, 0xFE };
  900. SymmetricAlgorithm algo = RC2.Create ();
  901. algo.Mode = CipherMode.CBC;
  902. algo.Padding = PaddingMode.Zeros;
  903. algo.BlockSize = 64;
  904. int blockLength = (algo.BlockSize >> 3);
  905. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  906. byte[] output = new byte [blockLength * 3];
  907. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  908. Encrypt (encryptor, input, output);
  909. AssertEquals ("RC2_k56b64_CBC_Zeros Encrypt", expected, output);
  910. byte[] reverse = new byte [blockLength * 3];
  911. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  912. Decrypt (decryptor, output, reverse);
  913. byte[] original = new byte [input.Length];
  914. Array.Copy (reverse, 0, original, 0, original.Length);
  915. AssertEquals ("RC2_k56b64_CBC_Zeros Decrypt", input, original);
  916. }
  917. [Test]
  918. public void TestRC2_k56b64_CBC_PKCS7 ()
  919. {
  920. byte[] key = { 0x52, 0xF6, 0xC3, 0xC3, 0x13, 0x9E, 0xF7 };
  921. byte[] iv = { 0x8E, 0xF8, 0xE5, 0x66, 0x64, 0x1C, 0xE6, 0xE3 };
  922. byte[] expected = { 0x7B, 0xD1, 0x1A, 0xD0, 0x62, 0x1B, 0x66, 0x5B, 0x92, 0xB0, 0x42, 0xC7, 0x63, 0x3A, 0x95, 0xED, 0x87, 0x6B, 0xA0, 0x88, 0x18, 0xC2, 0x92, 0xB4 };
  923. SymmetricAlgorithm algo = RC2.Create ();
  924. algo.Mode = CipherMode.CBC;
  925. algo.Padding = PaddingMode.PKCS7;
  926. algo.BlockSize = 64;
  927. int blockLength = (algo.BlockSize >> 3);
  928. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  929. byte[] output = new byte [blockLength * 3];
  930. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  931. Encrypt (encryptor, input, output);
  932. AssertEquals ("RC2_k56b64_CBC_PKCS7 Encrypt", expected, output);
  933. byte[] reverse = new byte [blockLength * 3];
  934. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  935. Decrypt (decryptor, output, reverse);
  936. byte[] original = new byte [input.Length];
  937. Array.Copy (reverse, 0, original, 0, original.Length);
  938. AssertEquals ("RC2_k56b64_CBC_PKCS7 Decrypt", input, original);
  939. }
  940. /* Invalid parameters RC2_k56b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  941. /* Invalid parameters RC2_k56b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  942. /* Invalid parameters RC2_k56b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  943. [Test]
  944. public void TestRC2_k56b64_CFB8_None ()
  945. {
  946. byte[] key = { 0xEA, 0x1D, 0xB2, 0x0E, 0x17, 0xF0, 0x4A };
  947. byte[] iv = { 0xB7, 0xEE, 0xEE, 0xFF, 0x36, 0x8C, 0x9B, 0xBB };
  948. byte[] expected = { 0x49, 0x1D, 0x32, 0xB4, 0x93, 0xEC, 0x96, 0xC9, 0xDC, 0x3B, 0x26, 0x4B, 0x3C, 0xA2, 0xE8, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  949. SymmetricAlgorithm algo = RC2.Create ();
  950. algo.Mode = CipherMode.CFB;
  951. algo.Padding = PaddingMode.None;
  952. algo.BlockSize = 64;
  953. algo.FeedbackSize = 8;
  954. int blockLength = (algo.BlockSize >> 3);
  955. byte[] input = new byte [blockLength * 2];
  956. byte[] output = new byte [blockLength * 3];
  957. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  958. Encrypt (encryptor, input, output);
  959. AssertEquals ("RC2_k56b64_CFB8_None Encrypt", expected, output);
  960. byte[] reverse = new byte [blockLength * 3];
  961. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  962. Decrypt (decryptor, output, reverse);
  963. byte[] original = new byte [input.Length];
  964. Array.Copy (reverse, 0, original, 0, original.Length);
  965. AssertEquals ("RC2_k56b64_CFB8_None Decrypt", input, original);
  966. }
  967. [Test]
  968. public void TestRC2_k56b64_CFB8_Zeros ()
  969. {
  970. byte[] key = { 0x24, 0x6F, 0xE0, 0xC7, 0x3C, 0xC0, 0x4B };
  971. byte[] iv = { 0xD7, 0x83, 0xCA, 0xB7, 0x9C, 0x6D, 0xC3, 0x25 };
  972. byte[] expected = { 0x37, 0xF7, 0x35, 0xF4, 0xB2, 0x0C, 0xCB, 0xC4, 0xAE, 0x42, 0x83, 0x99, 0x55, 0xF6, 0x51, 0x5A, 0x1A, 0xE7, 0x7B, 0xFD, 0x4E, 0x78, 0xD7, 0x80 };
  973. SymmetricAlgorithm algo = RC2.Create ();
  974. algo.Mode = CipherMode.CFB;
  975. algo.Padding = PaddingMode.Zeros;
  976. algo.BlockSize = 64;
  977. algo.FeedbackSize = 8;
  978. int blockLength = (algo.BlockSize >> 3);
  979. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  980. byte[] output = new byte [blockLength * 3];
  981. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  982. Encrypt (encryptor, input, output);
  983. AssertEquals ("RC2_k56b64_CFB8_Zeros Encrypt", expected, output);
  984. byte[] reverse = new byte [blockLength * 3];
  985. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  986. Decrypt (decryptor, output, reverse);
  987. byte[] original = new byte [input.Length];
  988. Array.Copy (reverse, 0, original, 0, original.Length);
  989. AssertEquals ("RC2_k56b64_CFB8_Zeros Decrypt", input, original);
  990. }
  991. [Test]
  992. public void TestRC2_k56b64_CFB8_PKCS7 ()
  993. {
  994. byte[] key = { 0x58, 0xE4, 0xC8, 0x6F, 0xB4, 0x14, 0xAC };
  995. byte[] iv = { 0xA1, 0xBC, 0x94, 0xB5, 0xF5, 0x4F, 0x78, 0x19 };
  996. byte[] expected = { 0xBA, 0x15, 0xE2, 0x73, 0x56, 0x5E, 0xB6, 0x30, 0xA8, 0x50, 0xA2, 0x61, 0x52, 0x2F, 0x61, 0xCC, 0x97, 0x9A, 0x91, 0xB1, 0xF0, 0x87, 0x3F, 0xA7 };
  997. SymmetricAlgorithm algo = RC2.Create ();
  998. algo.Mode = CipherMode.CFB;
  999. algo.Padding = PaddingMode.PKCS7;
  1000. algo.BlockSize = 64;
  1001. algo.FeedbackSize = 8;
  1002. int blockLength = (algo.BlockSize >> 3);
  1003. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1004. byte[] output = new byte [blockLength * 3];
  1005. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1006. Encrypt (encryptor, input, output);
  1007. AssertEquals ("RC2_k56b64_CFB8_PKCS7 Encrypt", expected, output);
  1008. byte[] reverse = new byte [blockLength * 3];
  1009. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1010. Decrypt (decryptor, output, reverse);
  1011. byte[] original = new byte [input.Length];
  1012. Array.Copy (reverse, 0, original, 0, original.Length);
  1013. AssertEquals ("RC2_k56b64_CFB8_PKCS7 Decrypt", input, original);
  1014. }
  1015. /* Invalid parameters RC2_k56b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1016. /* Invalid parameters RC2_k56b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1017. /* Invalid parameters RC2_k56b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1018. [Test]
  1019. public void TestRC2_k64b64_ECB_None ()
  1020. {
  1021. byte[] key = { 0x2C, 0x52, 0xB4, 0x93, 0xF1, 0xEA, 0xC8, 0x8F };
  1022. // not used for ECB but make the code more uniform
  1023. byte[] iv = { 0xDE, 0x10, 0xA1, 0x1C, 0x5E, 0x43, 0x5F, 0x97 };
  1024. byte[] expected = { 0xDB, 0x1D, 0x72, 0x2C, 0x7C, 0x4A, 0x31, 0xDB, 0xDB, 0x1D, 0x72, 0x2C, 0x7C, 0x4A, 0x31, 0xDB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1025. SymmetricAlgorithm algo = RC2.Create ();
  1026. algo.Mode = CipherMode.ECB;
  1027. algo.Padding = PaddingMode.None;
  1028. algo.BlockSize = 64;
  1029. int blockLength = (algo.BlockSize >> 3);
  1030. byte[] input = new byte [blockLength * 2];
  1031. byte[] output = new byte [blockLength * 3];
  1032. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1033. Encrypt (encryptor, input, output);
  1034. AssertEquals ("RC2_k64b64_ECB_None Encrypt", expected, output);
  1035. // in ECB the first 2 blocks should be equals (as the IV is not used)
  1036. byte[] block1 = new byte[blockLength];
  1037. Array.Copy (output, 0, block1, 0, blockLength);
  1038. byte[] block2 = new byte[blockLength];
  1039. Array.Copy (output, blockLength, block2, 0, blockLength);
  1040. AssertEquals ("RC2_k64b64_ECB_None b1==b2", block1, block2);
  1041. byte[] reverse = new byte [blockLength * 3];
  1042. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1043. Decrypt (decryptor, output, reverse);
  1044. byte[] original = new byte [input.Length];
  1045. Array.Copy (reverse, 0, original, 0, original.Length);
  1046. AssertEquals ("RC2_k64b64_ECB_None Decrypt", input, original);
  1047. }
  1048. [Test]
  1049. public void TestRC2_k64b64_ECB_Zeros ()
  1050. {
  1051. byte[] key = { 0x05, 0x0C, 0x49, 0xE3, 0x25, 0x49, 0xFA, 0x35 };
  1052. // not used for ECB but make the code more uniform
  1053. byte[] iv = { 0x4D, 0x94, 0x32, 0xD2, 0x8B, 0xB6, 0x52, 0x9C };
  1054. byte[] expected = { 0x39, 0x35, 0xCE, 0x5C, 0x75, 0xF5, 0xB7, 0xA1, 0x39, 0x35, 0xCE, 0x5C, 0x75, 0xF5, 0xB7, 0xA1, 0x39, 0x35, 0xCE, 0x5C, 0x75, 0xF5, 0xB7, 0xA1 };
  1055. SymmetricAlgorithm algo = RC2.Create ();
  1056. algo.Mode = CipherMode.ECB;
  1057. algo.Padding = PaddingMode.Zeros;
  1058. algo.BlockSize = 64;
  1059. int blockLength = (algo.BlockSize >> 3);
  1060. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1061. byte[] output = new byte [blockLength * 3];
  1062. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1063. Encrypt (encryptor, input, output);
  1064. AssertEquals ("RC2_k64b64_ECB_Zeros Encrypt", expected, output);
  1065. // in ECB the first 2 blocks should be equals (as the IV is not used)
  1066. byte[] block1 = new byte[blockLength];
  1067. Array.Copy (output, 0, block1, 0, blockLength);
  1068. byte[] block2 = new byte[blockLength];
  1069. Array.Copy (output, blockLength, block2, 0, blockLength);
  1070. AssertEquals ("RC2_k64b64_ECB_Zeros b1==b2", block1, block2);
  1071. // also if padding is Zeros then all three blocks should be equals
  1072. byte[] block3 = new byte[blockLength];
  1073. Array.Copy (output, blockLength, block3, 0, blockLength);
  1074. AssertEquals ("RC2_k64b64_ECB_Zeros b1==b3", block1, block3);
  1075. byte[] reverse = new byte [blockLength * 3];
  1076. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1077. Decrypt (decryptor, output, reverse);
  1078. byte[] original = new byte [input.Length];
  1079. Array.Copy (reverse, 0, original, 0, original.Length);
  1080. AssertEquals ("RC2_k64b64_ECB_Zeros Decrypt", input, original);
  1081. }
  1082. [Test]
  1083. public void TestRC2_k64b64_ECB_PKCS7 ()
  1084. {
  1085. byte[] key = { 0xE6, 0x57, 0xF2, 0x73, 0x3A, 0x20, 0xB0, 0x7E };
  1086. // not used for ECB but make the code more uniform
  1087. byte[] iv = { 0x34, 0x25, 0xD2, 0x35, 0x1C, 0xE4, 0x9D, 0xC6 };
  1088. byte[] expected = { 0x7A, 0x3F, 0x95, 0xA0, 0xA1, 0x70, 0xBD, 0xC3, 0x7A, 0x3F, 0x95, 0xA0, 0xA1, 0x70, 0xBD, 0xC3, 0xDA, 0xE7, 0x0C, 0xC3, 0xAD, 0xC3, 0xEA, 0xE9 };
  1089. SymmetricAlgorithm algo = RC2.Create ();
  1090. algo.Mode = CipherMode.ECB;
  1091. algo.Padding = PaddingMode.PKCS7;
  1092. algo.BlockSize = 64;
  1093. int blockLength = (algo.BlockSize >> 3);
  1094. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1095. byte[] output = new byte [blockLength * 3];
  1096. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1097. Encrypt (encryptor, input, output);
  1098. AssertEquals ("RC2_k64b64_ECB_PKCS7 Encrypt", expected, output);
  1099. // in ECB the first 2 blocks should be equals (as the IV is not used)
  1100. byte[] block1 = new byte[blockLength];
  1101. Array.Copy (output, 0, block1, 0, blockLength);
  1102. byte[] block2 = new byte[blockLength];
  1103. Array.Copy (output, blockLength, block2, 0, blockLength);
  1104. AssertEquals ("RC2_k64b64_ECB_PKCS7 b1==b2", block1, block2);
  1105. byte[] reverse = new byte [blockLength * 3];
  1106. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1107. Decrypt (decryptor, output, reverse);
  1108. byte[] original = new byte [input.Length];
  1109. Array.Copy (reverse, 0, original, 0, original.Length);
  1110. AssertEquals ("RC2_k64b64_ECB_PKCS7 Decrypt", input, original);
  1111. }
  1112. [Test]
  1113. public void TestRC2_k64b64_CBC_None ()
  1114. {
  1115. byte[] key = { 0x91, 0x14, 0x49, 0xC4, 0x0D, 0xF9, 0x90, 0x77 };
  1116. byte[] iv = { 0xB9, 0xBD, 0x6B, 0x9E, 0x52, 0xC9, 0x8C, 0xA5 };
  1117. byte[] expected = { 0xF1, 0x7C, 0xDF, 0x18, 0x54, 0xC2, 0xDE, 0x3B, 0x05, 0x20, 0x99, 0x94, 0x8A, 0x5E, 0x29, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1118. SymmetricAlgorithm algo = RC2.Create ();
  1119. algo.Mode = CipherMode.CBC;
  1120. algo.Padding = PaddingMode.None;
  1121. algo.BlockSize = 64;
  1122. int blockLength = (algo.BlockSize >> 3);
  1123. byte[] input = new byte [blockLength * 2];
  1124. byte[] output = new byte [blockLength * 3];
  1125. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1126. Encrypt (encryptor, input, output);
  1127. AssertEquals ("RC2_k64b64_CBC_None Encrypt", expected, output);
  1128. byte[] reverse = new byte [blockLength * 3];
  1129. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1130. Decrypt (decryptor, output, reverse);
  1131. byte[] original = new byte [input.Length];
  1132. Array.Copy (reverse, 0, original, 0, original.Length);
  1133. AssertEquals ("RC2_k64b64_CBC_None Decrypt", input, original);
  1134. }
  1135. [Test]
  1136. public void TestRC2_k64b64_CBC_Zeros ()
  1137. {
  1138. byte[] key = { 0x0E, 0xE0, 0xAD, 0xFD, 0x86, 0x22, 0x1D, 0x05 };
  1139. byte[] iv = { 0xDF, 0x41, 0x2B, 0x6E, 0x82, 0x00, 0xCB, 0x38 };
  1140. byte[] expected = { 0x98, 0x43, 0x84, 0x05, 0x68, 0xAE, 0x99, 0x3B, 0xB1, 0xCD, 0x2F, 0x69, 0xD9, 0xDD, 0x54, 0x79, 0x37, 0x36, 0x96, 0xE9, 0xC3, 0x62, 0xC2, 0x35 };
  1141. SymmetricAlgorithm algo = RC2.Create ();
  1142. algo.Mode = CipherMode.CBC;
  1143. algo.Padding = PaddingMode.Zeros;
  1144. algo.BlockSize = 64;
  1145. int blockLength = (algo.BlockSize >> 3);
  1146. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1147. byte[] output = new byte [blockLength * 3];
  1148. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1149. Encrypt (encryptor, input, output);
  1150. AssertEquals ("RC2_k64b64_CBC_Zeros Encrypt", expected, output);
  1151. byte[] reverse = new byte [blockLength * 3];
  1152. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1153. Decrypt (decryptor, output, reverse);
  1154. byte[] original = new byte [input.Length];
  1155. Array.Copy (reverse, 0, original, 0, original.Length);
  1156. AssertEquals ("RC2_k64b64_CBC_Zeros Decrypt", input, original);
  1157. }
  1158. [Test]
  1159. public void TestRC2_k64b64_CBC_PKCS7 ()
  1160. {
  1161. byte[] key = { 0x2D, 0x70, 0x15, 0xFF, 0x15, 0xEB, 0xDC, 0x33 };
  1162. byte[] iv = { 0x04, 0x33, 0x63, 0x52, 0x5B, 0xA1, 0xAB, 0xAC };
  1163. byte[] expected = { 0x07, 0x9B, 0x58, 0x27, 0xB4, 0x36, 0xDD, 0x9D, 0x7C, 0xC5, 0xE0, 0x83, 0x6A, 0x76, 0x87, 0x08, 0xF1, 0xEF, 0xCB, 0xE2, 0xA1, 0xF6, 0xA9, 0xBE };
  1164. SymmetricAlgorithm algo = RC2.Create ();
  1165. algo.Mode = CipherMode.CBC;
  1166. algo.Padding = PaddingMode.PKCS7;
  1167. algo.BlockSize = 64;
  1168. int blockLength = (algo.BlockSize >> 3);
  1169. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1170. byte[] output = new byte [blockLength * 3];
  1171. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1172. Encrypt (encryptor, input, output);
  1173. AssertEquals ("RC2_k64b64_CBC_PKCS7 Encrypt", expected, output);
  1174. byte[] reverse = new byte [blockLength * 3];
  1175. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1176. Decrypt (decryptor, output, reverse);
  1177. byte[] original = new byte [input.Length];
  1178. Array.Copy (reverse, 0, original, 0, original.Length);
  1179. AssertEquals ("RC2_k64b64_CBC_PKCS7 Decrypt", input, original);
  1180. }
  1181. /* Invalid parameters RC2_k64b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  1182. /* Invalid parameters RC2_k64b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  1183. /* Invalid parameters RC2_k64b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  1184. [Test]
  1185. public void TestRC2_k64b64_CFB8_None ()
  1186. {
  1187. byte[] key = { 0x1B, 0x23, 0x16, 0xEA, 0x19, 0xF0, 0x53, 0xEE };
  1188. byte[] iv = { 0x60, 0x8D, 0x23, 0x2B, 0x0D, 0x56, 0x6F, 0x92 };
  1189. byte[] expected = { 0x0C, 0xE2, 0x26, 0xA8, 0x0A, 0xB8, 0xFE, 0x03, 0x71, 0x2B, 0x56, 0x59, 0xA3, 0x45, 0xC0, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1190. SymmetricAlgorithm algo = RC2.Create ();
  1191. algo.Mode = CipherMode.CFB;
  1192. algo.Padding = PaddingMode.None;
  1193. algo.BlockSize = 64;
  1194. algo.FeedbackSize = 8;
  1195. int blockLength = (algo.BlockSize >> 3);
  1196. byte[] input = new byte [blockLength * 2];
  1197. byte[] output = new byte [blockLength * 3];
  1198. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1199. Encrypt (encryptor, input, output);
  1200. AssertEquals ("RC2_k64b64_CFB8_None Encrypt", expected, output);
  1201. byte[] reverse = new byte [blockLength * 3];
  1202. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1203. Decrypt (decryptor, output, reverse);
  1204. byte[] original = new byte [input.Length];
  1205. Array.Copy (reverse, 0, original, 0, original.Length);
  1206. AssertEquals ("RC2_k64b64_CFB8_None Decrypt", input, original);
  1207. }
  1208. [Test]
  1209. public void TestRC2_k64b64_CFB8_Zeros ()
  1210. {
  1211. byte[] key = { 0x49, 0xAD, 0xCD, 0xF8, 0xB6, 0x44, 0xA1, 0x86 };
  1212. byte[] iv = { 0xCA, 0x6A, 0x96, 0xA8, 0x18, 0xA8, 0xF6, 0x77 };
  1213. byte[] expected = { 0x12, 0x88, 0x7D, 0xC4, 0x8A, 0x04, 0x86, 0x09, 0x4A, 0x64, 0xBE, 0x31, 0xD2, 0x1F, 0xF9, 0xA1, 0x80, 0x5D, 0x0B, 0x5A, 0x01, 0x9F, 0x10, 0x6D };
  1214. SymmetricAlgorithm algo = RC2.Create ();
  1215. algo.Mode = CipherMode.CFB;
  1216. algo.Padding = PaddingMode.Zeros;
  1217. algo.BlockSize = 64;
  1218. algo.FeedbackSize = 8;
  1219. int blockLength = (algo.BlockSize >> 3);
  1220. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1221. byte[] output = new byte [blockLength * 3];
  1222. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1223. Encrypt (encryptor, input, output);
  1224. AssertEquals ("RC2_k64b64_CFB8_Zeros Encrypt", expected, output);
  1225. byte[] reverse = new byte [blockLength * 3];
  1226. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1227. Decrypt (decryptor, output, reverse);
  1228. byte[] original = new byte [input.Length];
  1229. Array.Copy (reverse, 0, original, 0, original.Length);
  1230. AssertEquals ("RC2_k64b64_CFB8_Zeros Decrypt", input, original);
  1231. }
  1232. [Test]
  1233. public void TestRC2_k64b64_CFB8_PKCS7 ()
  1234. {
  1235. byte[] key = { 0xF6, 0xE6, 0xA0, 0x33, 0xD3, 0x77, 0x0C, 0x28 };
  1236. byte[] iv = { 0x50, 0x31, 0x14, 0xAF, 0x27, 0x92, 0xFC, 0x57 };
  1237. byte[] expected = { 0xFF, 0x4B, 0xA2, 0x37, 0x56, 0xFB, 0x37, 0x4A, 0xB5, 0x6A, 0xCB, 0x27, 0x06, 0xED, 0xC2, 0x38, 0x7C, 0x4B, 0xBE, 0xC0, 0xD5, 0xD7, 0x6A, 0x79 };
  1238. SymmetricAlgorithm algo = RC2.Create ();
  1239. algo.Mode = CipherMode.CFB;
  1240. algo.Padding = PaddingMode.PKCS7;
  1241. algo.BlockSize = 64;
  1242. algo.FeedbackSize = 8;
  1243. int blockLength = (algo.BlockSize >> 3);
  1244. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1245. byte[] output = new byte [blockLength * 3];
  1246. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1247. Encrypt (encryptor, input, output);
  1248. AssertEquals ("RC2_k64b64_CFB8_PKCS7 Encrypt", expected, output);
  1249. byte[] reverse = new byte [blockLength * 3];
  1250. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1251. Decrypt (decryptor, output, reverse);
  1252. byte[] original = new byte [input.Length];
  1253. Array.Copy (reverse, 0, original, 0, original.Length);
  1254. AssertEquals ("RC2_k64b64_CFB8_PKCS7 Decrypt", input, original);
  1255. }
  1256. /* Invalid parameters RC2_k64b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1257. /* Invalid parameters RC2_k64b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1258. /* Invalid parameters RC2_k64b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1259. [Test]
  1260. public void TestRC2_k72b64_ECB_None ()
  1261. {
  1262. byte[] key = { 0xEC, 0x93, 0x9A, 0xF0, 0x51, 0x69, 0x59, 0x0B, 0x15 };
  1263. // not used for ECB but make the code more uniform
  1264. byte[] iv = { 0x36, 0xDB, 0xE8, 0x7F, 0xB5, 0x43, 0x4C, 0xF6 };
  1265. byte[] expected = { 0xD6, 0x8A, 0x11, 0x59, 0x38, 0x6B, 0x93, 0x8F, 0xD6, 0x8A, 0x11, 0x59, 0x38, 0x6B, 0x93, 0x8F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1266. SymmetricAlgorithm algo = RC2.Create ();
  1267. algo.Mode = CipherMode.ECB;
  1268. algo.Padding = PaddingMode.None;
  1269. algo.BlockSize = 64;
  1270. int blockLength = (algo.BlockSize >> 3);
  1271. byte[] input = new byte [blockLength * 2];
  1272. byte[] output = new byte [blockLength * 3];
  1273. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1274. Encrypt (encryptor, input, output);
  1275. AssertEquals ("RC2_k72b64_ECB_None Encrypt", expected, output);
  1276. // in ECB the first 2 blocks should be equals (as the IV is not used)
  1277. byte[] block1 = new byte[blockLength];
  1278. Array.Copy (output, 0, block1, 0, blockLength);
  1279. byte[] block2 = new byte[blockLength];
  1280. Array.Copy (output, blockLength, block2, 0, blockLength);
  1281. AssertEquals ("RC2_k72b64_ECB_None b1==b2", block1, block2);
  1282. byte[] reverse = new byte [blockLength * 3];
  1283. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1284. Decrypt (decryptor, output, reverse);
  1285. byte[] original = new byte [input.Length];
  1286. Array.Copy (reverse, 0, original, 0, original.Length);
  1287. AssertEquals ("RC2_k72b64_ECB_None Decrypt", input, original);
  1288. }
  1289. [Test]
  1290. public void TestRC2_k72b64_ECB_Zeros ()
  1291. {
  1292. byte[] key = { 0x19, 0x14, 0x2D, 0xF6, 0x48, 0xED, 0x5A, 0xF3, 0x1F };
  1293. // not used for ECB but make the code more uniform
  1294. byte[] iv = { 0x8C, 0x1D, 0x0D, 0xC7, 0xE3, 0x77, 0x68, 0x40 };
  1295. byte[] expected = { 0x38, 0xD4, 0x18, 0x61, 0xF6, 0x8E, 0x55, 0xD7, 0x38, 0xD4, 0x18, 0x61, 0xF6, 0x8E, 0x55, 0xD7, 0x38, 0xD4, 0x18, 0x61, 0xF6, 0x8E, 0x55, 0xD7 };
  1296. SymmetricAlgorithm algo = RC2.Create ();
  1297. algo.Mode = CipherMode.ECB;
  1298. algo.Padding = PaddingMode.Zeros;
  1299. algo.BlockSize = 64;
  1300. int blockLength = (algo.BlockSize >> 3);
  1301. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1302. byte[] output = new byte [blockLength * 3];
  1303. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1304. Encrypt (encryptor, input, output);
  1305. AssertEquals ("RC2_k72b64_ECB_Zeros Encrypt", expected, output);
  1306. // in ECB the first 2 blocks should be equals (as the IV is not used)
  1307. byte[] block1 = new byte[blockLength];
  1308. Array.Copy (output, 0, block1, 0, blockLength);
  1309. byte[] block2 = new byte[blockLength];
  1310. Array.Copy (output, blockLength, block2, 0, blockLength);
  1311. AssertEquals ("RC2_k72b64_ECB_Zeros b1==b2", block1, block2);
  1312. // also if padding is Zeros then all three blocks should be equals
  1313. byte[] block3 = new byte[blockLength];
  1314. Array.Copy (output, blockLength, block3, 0, blockLength);
  1315. AssertEquals ("RC2_k72b64_ECB_Zeros b1==b3", block1, block3);
  1316. byte[] reverse = new byte [blockLength * 3];
  1317. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1318. Decrypt (decryptor, output, reverse);
  1319. byte[] original = new byte [input.Length];
  1320. Array.Copy (reverse, 0, original, 0, original.Length);
  1321. AssertEquals ("RC2_k72b64_ECB_Zeros Decrypt", input, original);
  1322. }
  1323. [Test]
  1324. public void TestRC2_k72b64_ECB_PKCS7 ()
  1325. {
  1326. byte[] key = { 0x1C, 0xAA, 0x46, 0xE7, 0x37, 0x23, 0x14, 0xC9, 0x31 };
  1327. // not used for ECB but make the code more uniform
  1328. byte[] iv = { 0x3B, 0x0B, 0x1D, 0xE0, 0x3A, 0x6E, 0xF3, 0x1C };
  1329. byte[] expected = { 0x71, 0x04, 0xA2, 0x66, 0xFC, 0xB9, 0x0F, 0x48, 0x71, 0x04, 0xA2, 0x66, 0xFC, 0xB9, 0x0F, 0x48, 0xFA, 0xF7, 0x6F, 0xA9, 0xA0, 0x23, 0xF8, 0x7E };
  1330. SymmetricAlgorithm algo = RC2.Create ();
  1331. algo.Mode = CipherMode.ECB;
  1332. algo.Padding = PaddingMode.PKCS7;
  1333. algo.BlockSize = 64;
  1334. int blockLength = (algo.BlockSize >> 3);
  1335. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1336. byte[] output = new byte [blockLength * 3];
  1337. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1338. Encrypt (encryptor, input, output);
  1339. AssertEquals ("RC2_k72b64_ECB_PKCS7 Encrypt", expected, output);
  1340. // in ECB the first 2 blocks should be equals (as the IV is not used)
  1341. byte[] block1 = new byte[blockLength];
  1342. Array.Copy (output, 0, block1, 0, blockLength);
  1343. byte[] block2 = new byte[blockLength];
  1344. Array.Copy (output, blockLength, block2, 0, blockLength);
  1345. AssertEquals ("RC2_k72b64_ECB_PKCS7 b1==b2", block1, block2);
  1346. byte[] reverse = new byte [blockLength * 3];
  1347. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1348. Decrypt (decryptor, output, reverse);
  1349. byte[] original = new byte [input.Length];
  1350. Array.Copy (reverse, 0, original, 0, original.Length);
  1351. AssertEquals ("RC2_k72b64_ECB_PKCS7 Decrypt", input, original);
  1352. }
  1353. [Test]
  1354. public void TestRC2_k72b64_CBC_None ()
  1355. {
  1356. byte[] key = { 0xF7, 0x60, 0xC5, 0x87, 0x4E, 0x36, 0xCE, 0x3C, 0xE6 };
  1357. byte[] iv = { 0x60, 0x0E, 0xAC, 0x58, 0x1C, 0x91, 0x1D, 0xAC };
  1358. byte[] expected = { 0xF7, 0xFE, 0xC3, 0x0E, 0x68, 0x6C, 0x15, 0x38, 0xDC, 0x06, 0xD9, 0x3A, 0x02, 0x08, 0xE2, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1359. SymmetricAlgorithm algo = RC2.Create ();
  1360. algo.Mode = CipherMode.CBC;
  1361. algo.Padding = PaddingMode.None;
  1362. algo.BlockSize = 64;
  1363. int blockLength = (algo.BlockSize >> 3);
  1364. byte[] input = new byte [blockLength * 2];
  1365. byte[] output = new byte [blockLength * 3];
  1366. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1367. Encrypt (encryptor, input, output);
  1368. AssertEquals ("RC2_k72b64_CBC_None Encrypt", expected, output);
  1369. byte[] reverse = new byte [blockLength * 3];
  1370. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1371. Decrypt (decryptor, output, reverse);
  1372. byte[] original = new byte [input.Length];
  1373. Array.Copy (reverse, 0, original, 0, original.Length);
  1374. AssertEquals ("RC2_k72b64_CBC_None Decrypt", input, original);
  1375. }
  1376. [Test]
  1377. public void TestRC2_k72b64_CBC_Zeros ()
  1378. {
  1379. byte[] key = { 0xD2, 0x3C, 0xD2, 0x40, 0xF1, 0x1D, 0x2E, 0xF4, 0x92 };
  1380. byte[] iv = { 0xBE, 0x7C, 0xF7, 0xBE, 0x35, 0x11, 0x94, 0x46 };
  1381. byte[] expected = { 0x7B, 0x6C, 0x73, 0xE4, 0x19, 0x69, 0x32, 0x61, 0x48, 0xE0, 0x21, 0x03, 0xAF, 0xC4, 0x54, 0x61, 0xE7, 0xB7, 0x00, 0x55, 0xDB, 0x57, 0x3C, 0x40 };
  1382. SymmetricAlgorithm algo = RC2.Create ();
  1383. algo.Mode = CipherMode.CBC;
  1384. algo.Padding = PaddingMode.Zeros;
  1385. algo.BlockSize = 64;
  1386. int blockLength = (algo.BlockSize >> 3);
  1387. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1388. byte[] output = new byte [blockLength * 3];
  1389. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1390. Encrypt (encryptor, input, output);
  1391. AssertEquals ("RC2_k72b64_CBC_Zeros Encrypt", expected, output);
  1392. byte[] reverse = new byte [blockLength * 3];
  1393. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1394. Decrypt (decryptor, output, reverse);
  1395. byte[] original = new byte [input.Length];
  1396. Array.Copy (reverse, 0, original, 0, original.Length);
  1397. AssertEquals ("RC2_k72b64_CBC_Zeros Decrypt", input, original);
  1398. }
  1399. [Test]
  1400. public void TestRC2_k72b64_CBC_PKCS7 ()
  1401. {
  1402. byte[] key = { 0xE6, 0x09, 0x99, 0x96, 0x84, 0x2D, 0x9B, 0xE9, 0x34 };
  1403. byte[] iv = { 0x00, 0xE9, 0x3B, 0x59, 0x6C, 0x5E, 0xF3, 0x8A };
  1404. byte[] expected = { 0xA9, 0x4E, 0x30, 0x5F, 0xEF, 0xF5, 0x77, 0xC5, 0x26, 0x96, 0xDA, 0x3E, 0x53, 0xF5, 0xCB, 0xEC, 0xBC, 0xF9, 0x85, 0x00, 0xF2, 0x0D, 0x32, 0x2D };
  1405. SymmetricAlgorithm algo = RC2.Create ();
  1406. algo.Mode = CipherMode.CBC;
  1407. algo.Padding = PaddingMode.PKCS7;
  1408. algo.BlockSize = 64;
  1409. int blockLength = (algo.BlockSize >> 3);
  1410. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1411. byte[] output = new byte [blockLength * 3];
  1412. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1413. Encrypt (encryptor, input, output);
  1414. AssertEquals ("RC2_k72b64_CBC_PKCS7 Encrypt", expected, output);
  1415. byte[] reverse = new byte [blockLength * 3];
  1416. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1417. Decrypt (decryptor, output, reverse);
  1418. byte[] original = new byte [input.Length];
  1419. Array.Copy (reverse, 0, original, 0, original.Length);
  1420. AssertEquals ("RC2_k72b64_CBC_PKCS7 Decrypt", input, original);
  1421. }
  1422. /* Invalid parameters RC2_k72b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  1423. /* Invalid parameters RC2_k72b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  1424. /* Invalid parameters RC2_k72b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  1425. [Test]
  1426. public void TestRC2_k72b64_CFB8_None ()
  1427. {
  1428. byte[] key = { 0x65, 0x6B, 0x23, 0x3F, 0xB3, 0xE5, 0x6F, 0x30, 0x01 };
  1429. byte[] iv = { 0x10, 0x16, 0x28, 0x20, 0xAB, 0x77, 0x74, 0x46 };
  1430. byte[] expected = { 0x5A, 0x35, 0x9B, 0x9E, 0x7A, 0xD6, 0xED, 0x1D, 0x36, 0xC9, 0x95, 0x0E, 0x04, 0xE1, 0x9C, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1431. SymmetricAlgorithm algo = RC2.Create ();
  1432. algo.Mode = CipherMode.CFB;
  1433. algo.Padding = PaddingMode.None;
  1434. algo.BlockSize = 64;
  1435. algo.FeedbackSize = 8;
  1436. int blockLength = (algo.BlockSize >> 3);
  1437. byte[] input = new byte [blockLength * 2];
  1438. byte[] output = new byte [blockLength * 3];
  1439. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1440. Encrypt (encryptor, input, output);
  1441. AssertEquals ("RC2_k72b64_CFB8_None Encrypt", expected, output);
  1442. byte[] reverse = new byte [blockLength * 3];
  1443. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1444. Decrypt (decryptor, output, reverse);
  1445. byte[] original = new byte [input.Length];
  1446. Array.Copy (reverse, 0, original, 0, original.Length);
  1447. AssertEquals ("RC2_k72b64_CFB8_None Decrypt", input, original);
  1448. }
  1449. [Test]
  1450. public void TestRC2_k72b64_CFB8_Zeros ()
  1451. {
  1452. byte[] key = { 0x87, 0xC1, 0x80, 0x41, 0xD6, 0xF1, 0x33, 0xC7, 0x78 };
  1453. byte[] iv = { 0x21, 0x55, 0xCF, 0x6E, 0xF5, 0x3B, 0xF0, 0x6B };
  1454. byte[] expected = { 0x83, 0xFC, 0xD7, 0x43, 0xC0, 0x4F, 0x9F, 0xE0, 0x60, 0xAD, 0x3B, 0x0D, 0x5A, 0xF3, 0xF3, 0x0B, 0x96, 0x25, 0x97, 0x6D, 0x58, 0x8B, 0x5A, 0x26 };
  1455. SymmetricAlgorithm algo = RC2.Create ();
  1456. algo.Mode = CipherMode.CFB;
  1457. algo.Padding = PaddingMode.Zeros;
  1458. algo.BlockSize = 64;
  1459. algo.FeedbackSize = 8;
  1460. int blockLength = (algo.BlockSize >> 3);
  1461. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1462. byte[] output = new byte [blockLength * 3];
  1463. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1464. Encrypt (encryptor, input, output);
  1465. AssertEquals ("RC2_k72b64_CFB8_Zeros Encrypt", expected, output);
  1466. byte[] reverse = new byte [blockLength * 3];
  1467. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1468. Decrypt (decryptor, output, reverse);
  1469. byte[] original = new byte [input.Length];
  1470. Array.Copy (reverse, 0, original, 0, original.Length);
  1471. AssertEquals ("RC2_k72b64_CFB8_Zeros Decrypt", input, original);
  1472. }
  1473. [Test]
  1474. public void TestRC2_k72b64_CFB8_PKCS7 ()
  1475. {
  1476. byte[] key = { 0xAE, 0xE0, 0x44, 0x66, 0xDA, 0x34, 0xFD, 0xD4, 0x71 };
  1477. byte[] iv = { 0xFA, 0x66, 0x5F, 0x55, 0xBC, 0x1B, 0xC7, 0x83 };
  1478. byte[] expected = { 0xF3, 0xAB, 0x63, 0x11, 0xA0, 0x27, 0x05, 0x42, 0x0A, 0xCD, 0x16, 0xCA, 0x22, 0x4E, 0x0B, 0xCB, 0x96, 0xCA, 0xD9, 0x38, 0x6D, 0x5E, 0x5E, 0x55 };
  1479. SymmetricAlgorithm algo = RC2.Create ();
  1480. algo.Mode = CipherMode.CFB;
  1481. algo.Padding = PaddingMode.PKCS7;
  1482. algo.BlockSize = 64;
  1483. algo.FeedbackSize = 8;
  1484. int blockLength = (algo.BlockSize >> 3);
  1485. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1486. byte[] output = new byte [blockLength * 3];
  1487. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1488. Encrypt (encryptor, input, output);
  1489. AssertEquals ("RC2_k72b64_CFB8_PKCS7 Encrypt", expected, output);
  1490. byte[] reverse = new byte [blockLength * 3];
  1491. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1492. Decrypt (decryptor, output, reverse);
  1493. byte[] original = new byte [input.Length];
  1494. Array.Copy (reverse, 0, original, 0, original.Length);
  1495. AssertEquals ("RC2_k72b64_CFB8_PKCS7 Decrypt", input, original);
  1496. }
  1497. /* Invalid parameters RC2_k72b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1498. /* Invalid parameters RC2_k72b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1499. /* Invalid parameters RC2_k72b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1500. [Test]
  1501. public void TestRC2_k80b64_ECB_None ()
  1502. {
  1503. byte[] key = { 0xB8, 0xA4, 0x76, 0xF8, 0x59, 0x86, 0x40, 0x53, 0x33, 0x68 };
  1504. // not used for ECB but make the code more uniform
  1505. byte[] iv = { 0xFF, 0x5F, 0x8B, 0x5E, 0xCF, 0xB8, 0xA5, 0xCB };
  1506. byte[] expected = { 0x7A, 0x56, 0x73, 0x0A, 0x72, 0x69, 0x95, 0x16, 0x7A, 0x56, 0x73, 0x0A, 0x72, 0x69, 0x95, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1507. SymmetricAlgorithm algo = RC2.Create ();
  1508. algo.Mode = CipherMode.ECB;
  1509. algo.Padding = PaddingMode.None;
  1510. algo.BlockSize = 64;
  1511. int blockLength = (algo.BlockSize >> 3);
  1512. byte[] input = new byte [blockLength * 2];
  1513. byte[] output = new byte [blockLength * 3];
  1514. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1515. Encrypt (encryptor, input, output);
  1516. AssertEquals ("RC2_k80b64_ECB_None Encrypt", expected, output);
  1517. // in ECB the first 2 blocks should be equals (as the IV is not used)
  1518. byte[] block1 = new byte[blockLength];
  1519. Array.Copy (output, 0, block1, 0, blockLength);
  1520. byte[] block2 = new byte[blockLength];
  1521. Array.Copy (output, blockLength, block2, 0, blockLength);
  1522. AssertEquals ("RC2_k80b64_ECB_None b1==b2", block1, block2);
  1523. byte[] reverse = new byte [blockLength * 3];
  1524. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1525. Decrypt (decryptor, output, reverse);
  1526. byte[] original = new byte [input.Length];
  1527. Array.Copy (reverse, 0, original, 0, original.Length);
  1528. AssertEquals ("RC2_k80b64_ECB_None Decrypt", input, original);
  1529. }
  1530. [Test]
  1531. public void TestRC2_k80b64_ECB_Zeros ()
  1532. {
  1533. byte[] key = { 0x9A, 0xE1, 0xE1, 0x17, 0xCB, 0x2B, 0x9C, 0x5D, 0x5D, 0x28 };
  1534. // not used for ECB but make the code more uniform
  1535. byte[] iv = { 0x71, 0x29, 0x89, 0x9C, 0x66, 0xF5, 0x90, 0x63 };
  1536. byte[] expected = { 0x38, 0x83, 0x30, 0xE0, 0xC6, 0x8A, 0x0B, 0x11, 0x38, 0x83, 0x30, 0xE0, 0xC6, 0x8A, 0x0B, 0x11, 0x38, 0x83, 0x30, 0xE0, 0xC6, 0x8A, 0x0B, 0x11 };
  1537. SymmetricAlgorithm algo = RC2.Create ();
  1538. algo.Mode = CipherMode.ECB;
  1539. algo.Padding = PaddingMode.Zeros;
  1540. algo.BlockSize = 64;
  1541. int blockLength = (algo.BlockSize >> 3);
  1542. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1543. byte[] output = new byte [blockLength * 3];
  1544. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1545. Encrypt (encryptor, input, output);
  1546. AssertEquals ("RC2_k80b64_ECB_Zeros Encrypt", expected, output);
  1547. // in ECB the first 2 blocks should be equals (as the IV is not used)
  1548. byte[] block1 = new byte[blockLength];
  1549. Array.Copy (output, 0, block1, 0, blockLength);
  1550. byte[] block2 = new byte[blockLength];
  1551. Array.Copy (output, blockLength, block2, 0, blockLength);
  1552. AssertEquals ("RC2_k80b64_ECB_Zeros b1==b2", block1, block2);
  1553. // also if padding is Zeros then all three blocks should be equals
  1554. byte[] block3 = new byte[blockLength];
  1555. Array.Copy (output, blockLength, block3, 0, blockLength);
  1556. AssertEquals ("RC2_k80b64_ECB_Zeros b1==b3", block1, block3);
  1557. byte[] reverse = new byte [blockLength * 3];
  1558. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1559. Decrypt (decryptor, output, reverse);
  1560. byte[] original = new byte [input.Length];
  1561. Array.Copy (reverse, 0, original, 0, original.Length);
  1562. AssertEquals ("RC2_k80b64_ECB_Zeros Decrypt", input, original);
  1563. }
  1564. [Test]
  1565. public void TestRC2_k80b64_ECB_PKCS7 ()
  1566. {
  1567. byte[] key = { 0x8D, 0xF8, 0xDA, 0xA2, 0x31, 0xEA, 0x86, 0x92, 0x52, 0xBB };
  1568. // not used for ECB but make the code more uniform
  1569. byte[] iv = { 0xD3, 0x1C, 0x57, 0x72, 0xDE, 0xFD, 0xCA, 0xC7 };
  1570. byte[] expected = { 0x51, 0xD4, 0x00, 0x54, 0x58, 0xE5, 0xED, 0x5C, 0x51, 0xD4, 0x00, 0x54, 0x58, 0xE5, 0xED, 0x5C, 0xCE, 0xF6, 0xDB, 0x31, 0x10, 0xE9, 0x0E, 0xD8 };
  1571. SymmetricAlgorithm algo = RC2.Create ();
  1572. algo.Mode = CipherMode.ECB;
  1573. algo.Padding = PaddingMode.PKCS7;
  1574. algo.BlockSize = 64;
  1575. int blockLength = (algo.BlockSize >> 3);
  1576. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1577. byte[] output = new byte [blockLength * 3];
  1578. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1579. Encrypt (encryptor, input, output);
  1580. AssertEquals ("RC2_k80b64_ECB_PKCS7 Encrypt", expected, output);
  1581. // in ECB the first 2 blocks should be equals (as the IV is not used)
  1582. byte[] block1 = new byte[blockLength];
  1583. Array.Copy (output, 0, block1, 0, blockLength);
  1584. byte[] block2 = new byte[blockLength];
  1585. Array.Copy (output, blockLength, block2, 0, blockLength);
  1586. AssertEquals ("RC2_k80b64_ECB_PKCS7 b1==b2", block1, block2);
  1587. byte[] reverse = new byte [blockLength * 3];
  1588. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1589. Decrypt (decryptor, output, reverse);
  1590. byte[] original = new byte [input.Length];
  1591. Array.Copy (reverse, 0, original, 0, original.Length);
  1592. AssertEquals ("RC2_k80b64_ECB_PKCS7 Decrypt", input, original);
  1593. }
  1594. [Test]
  1595. public void TestRC2_k80b64_CBC_None ()
  1596. {
  1597. byte[] key = { 0x5B, 0x45, 0x99, 0x10, 0x47, 0x42, 0x89, 0xC8, 0x2A, 0x6C };
  1598. byte[] iv = { 0xE4, 0x8F, 0x2A, 0x4D, 0x25, 0x38, 0x01, 0x04 };
  1599. byte[] expected = { 0xA3, 0x23, 0xE7, 0xCD, 0xC1, 0x5E, 0x4E, 0x1D, 0x2F, 0x7F, 0x8B, 0xA7, 0xD0, 0x42, 0xF2, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1600. SymmetricAlgorithm algo = RC2.Create ();
  1601. algo.Mode = CipherMode.CBC;
  1602. algo.Padding = PaddingMode.None;
  1603. algo.BlockSize = 64;
  1604. int blockLength = (algo.BlockSize >> 3);
  1605. byte[] input = new byte [blockLength * 2];
  1606. byte[] output = new byte [blockLength * 3];
  1607. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1608. Encrypt (encryptor, input, output);
  1609. AssertEquals ("RC2_k80b64_CBC_None Encrypt", expected, output);
  1610. byte[] reverse = new byte [blockLength * 3];
  1611. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1612. Decrypt (decryptor, output, reverse);
  1613. byte[] original = new byte [input.Length];
  1614. Array.Copy (reverse, 0, original, 0, original.Length);
  1615. AssertEquals ("RC2_k80b64_CBC_None Decrypt", input, original);
  1616. }
  1617. [Test]
  1618. public void TestRC2_k80b64_CBC_Zeros ()
  1619. {
  1620. byte[] key = { 0xD4, 0x47, 0xFF, 0x5A, 0x70, 0xE8, 0x48, 0x0F, 0x23, 0xD1 };
  1621. byte[] iv = { 0x8B, 0xF8, 0x94, 0x02, 0xB3, 0xFB, 0xB0, 0x0D };
  1622. byte[] expected = { 0x88, 0x5C, 0x72, 0x4C, 0x35, 0x7F, 0x73, 0x1C, 0x8A, 0x06, 0x6B, 0x90, 0x82, 0xC5, 0xBC, 0x46, 0x75, 0xC1, 0x87, 0xD9, 0xED, 0x29, 0x1D, 0xB8 };
  1623. SymmetricAlgorithm algo = RC2.Create ();
  1624. algo.Mode = CipherMode.CBC;
  1625. algo.Padding = PaddingMode.Zeros;
  1626. algo.BlockSize = 64;
  1627. int blockLength = (algo.BlockSize >> 3);
  1628. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1629. byte[] output = new byte [blockLength * 3];
  1630. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1631. Encrypt (encryptor, input, output);
  1632. AssertEquals ("RC2_k80b64_CBC_Zeros Encrypt", expected, output);
  1633. byte[] reverse = new byte [blockLength * 3];
  1634. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1635. Decrypt (decryptor, output, reverse);
  1636. byte[] original = new byte [input.Length];
  1637. Array.Copy (reverse, 0, original, 0, original.Length);
  1638. AssertEquals ("RC2_k80b64_CBC_Zeros Decrypt", input, original);
  1639. }
  1640. [Test]
  1641. public void TestRC2_k80b64_CBC_PKCS7 ()
  1642. {
  1643. byte[] key = { 0x8D, 0x77, 0xC5, 0x6E, 0xC2, 0x8F, 0x10, 0x51, 0xD2, 0x20 };
  1644. byte[] iv = { 0x43, 0xC5, 0x4E, 0x58, 0xF0, 0xD7, 0xB3, 0x92 };
  1645. byte[] expected = { 0xE9, 0xB0, 0x67, 0x7C, 0x6C, 0x77, 0x68, 0x4D, 0xD0, 0xA5, 0x93, 0x9F, 0x84, 0xE0, 0xA0, 0xA9, 0x36, 0x21, 0xD7, 0x07, 0x0B, 0x8D, 0xD7, 0xB9 };
  1646. SymmetricAlgorithm algo = RC2.Create ();
  1647. algo.Mode = CipherMode.CBC;
  1648. algo.Padding = PaddingMode.PKCS7;
  1649. algo.BlockSize = 64;
  1650. int blockLength = (algo.BlockSize >> 3);
  1651. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1652. byte[] output = new byte [blockLength * 3];
  1653. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1654. Encrypt (encryptor, input, output);
  1655. AssertEquals ("RC2_k80b64_CBC_PKCS7 Encrypt", expected, output);
  1656. byte[] reverse = new byte [blockLength * 3];
  1657. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1658. Decrypt (decryptor, output, reverse);
  1659. byte[] original = new byte [input.Length];
  1660. Array.Copy (reverse, 0, original, 0, original.Length);
  1661. AssertEquals ("RC2_k80b64_CBC_PKCS7 Decrypt", input, original);
  1662. }
  1663. /* Invalid parameters RC2_k80b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  1664. /* Invalid parameters RC2_k80b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  1665. /* Invalid parameters RC2_k80b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  1666. [Test]
  1667. public void TestRC2_k80b64_CFB8_None ()
  1668. {
  1669. byte[] key = { 0x2A, 0x44, 0xD9, 0x1C, 0x5E, 0x7C, 0x79, 0x3D, 0x88, 0x55 };
  1670. byte[] iv = { 0xA0, 0x48, 0x00, 0x04, 0xA8, 0xB8, 0x83, 0x9F };
  1671. byte[] expected = { 0xEA, 0xD0, 0x3D, 0x9A, 0x62, 0xEA, 0x9C, 0x59, 0xAC, 0xD4, 0xA1, 0xDE, 0xDB, 0x3D, 0xF8, 0x4E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1672. SymmetricAlgorithm algo = RC2.Create ();
  1673. algo.Mode = CipherMode.CFB;
  1674. algo.Padding = PaddingMode.None;
  1675. algo.BlockSize = 64;
  1676. algo.FeedbackSize = 8;
  1677. int blockLength = (algo.BlockSize >> 3);
  1678. byte[] input = new byte [blockLength * 2];
  1679. byte[] output = new byte [blockLength * 3];
  1680. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1681. Encrypt (encryptor, input, output);
  1682. AssertEquals ("RC2_k80b64_CFB8_None Encrypt", expected, output);
  1683. byte[] reverse = new byte [blockLength * 3];
  1684. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1685. Decrypt (decryptor, output, reverse);
  1686. byte[] original = new byte [input.Length];
  1687. Array.Copy (reverse, 0, original, 0, original.Length);
  1688. AssertEquals ("RC2_k80b64_CFB8_None Decrypt", input, original);
  1689. }
  1690. [Test]
  1691. public void TestRC2_k80b64_CFB8_Zeros ()
  1692. {
  1693. byte[] key = { 0x30, 0x51, 0xCD, 0x3B, 0x8A, 0x8A, 0x8C, 0xF4, 0x76, 0x64 };
  1694. byte[] iv = { 0xD9, 0x5F, 0xEB, 0x11, 0x8F, 0x0A, 0x7D, 0xDC };
  1695. byte[] expected = { 0x02, 0xB4, 0x0F, 0xB5, 0x79, 0x81, 0xAC, 0xFD, 0xBA, 0x40, 0xF1, 0x61, 0x96, 0x70, 0x09, 0x5B, 0xFF, 0x0D, 0x90, 0xB4, 0x54, 0x27, 0x4A, 0x3C };
  1696. SymmetricAlgorithm algo = RC2.Create ();
  1697. algo.Mode = CipherMode.CFB;
  1698. algo.Padding = PaddingMode.Zeros;
  1699. algo.BlockSize = 64;
  1700. algo.FeedbackSize = 8;
  1701. int blockLength = (algo.BlockSize >> 3);
  1702. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1703. byte[] output = new byte [blockLength * 3];
  1704. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1705. Encrypt (encryptor, input, output);
  1706. AssertEquals ("RC2_k80b64_CFB8_Zeros Encrypt", expected, output);
  1707. byte[] reverse = new byte [blockLength * 3];
  1708. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1709. Decrypt (decryptor, output, reverse);
  1710. byte[] original = new byte [input.Length];
  1711. Array.Copy (reverse, 0, original, 0, original.Length);
  1712. AssertEquals ("RC2_k80b64_CFB8_Zeros Decrypt", input, original);
  1713. }
  1714. [Test]
  1715. public void TestRC2_k80b64_CFB8_PKCS7 ()
  1716. {
  1717. byte[] key = { 0xA7, 0x24, 0xA0, 0x14, 0x78, 0xDC, 0x8B, 0x99, 0x77, 0xCD };
  1718. byte[] iv = { 0xB8, 0x68, 0xD0, 0x5A, 0x13, 0x3C, 0xBA, 0x59 };
  1719. byte[] expected = { 0x3B, 0x35, 0xF6, 0x3F, 0x36, 0x7B, 0xF1, 0x7D, 0xCE, 0xC8, 0x62, 0xF8, 0x34, 0xC6, 0x42, 0x6F, 0x77, 0xCF, 0x32, 0x41, 0xF3, 0x0B, 0x28, 0x37 };
  1720. SymmetricAlgorithm algo = RC2.Create ();
  1721. algo.Mode = CipherMode.CFB;
  1722. algo.Padding = PaddingMode.PKCS7;
  1723. algo.BlockSize = 64;
  1724. algo.FeedbackSize = 8;
  1725. int blockLength = (algo.BlockSize >> 3);
  1726. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1727. byte[] output = new byte [blockLength * 3];
  1728. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1729. Encrypt (encryptor, input, output);
  1730. AssertEquals ("RC2_k80b64_CFB8_PKCS7 Encrypt", expected, output);
  1731. byte[] reverse = new byte [blockLength * 3];
  1732. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1733. Decrypt (decryptor, output, reverse);
  1734. byte[] original = new byte [input.Length];
  1735. Array.Copy (reverse, 0, original, 0, original.Length);
  1736. AssertEquals ("RC2_k80b64_CFB8_PKCS7 Decrypt", input, original);
  1737. }
  1738. /* Invalid parameters RC2_k80b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1739. /* Invalid parameters RC2_k80b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1740. /* Invalid parameters RC2_k80b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1741. [Test]
  1742. public void TestRC2_k88b64_ECB_None ()
  1743. {
  1744. byte[] key = { 0xCE, 0x12, 0x59, 0x88, 0x7A, 0xCD, 0x57, 0x4C, 0xCD, 0xA9, 0xD2 };
  1745. // not used for ECB but make the code more uniform
  1746. byte[] iv = { 0x91, 0x4C, 0x2D, 0xB4, 0x6E, 0x19, 0x3F, 0x6F };
  1747. byte[] expected = { 0x74, 0x25, 0xAD, 0x2E, 0x88, 0xA9, 0x3E, 0x1F, 0x74, 0x25, 0xAD, 0x2E, 0x88, 0xA9, 0x3E, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1748. SymmetricAlgorithm algo = RC2.Create ();
  1749. algo.Mode = CipherMode.ECB;
  1750. algo.Padding = PaddingMode.None;
  1751. algo.BlockSize = 64;
  1752. int blockLength = (algo.BlockSize >> 3);
  1753. byte[] input = new byte [blockLength * 2];
  1754. byte[] output = new byte [blockLength * 3];
  1755. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1756. Encrypt (encryptor, input, output);
  1757. AssertEquals ("RC2_k88b64_ECB_None Encrypt", expected, output);
  1758. // in ECB the first 2 blocks should be equals (as the IV is not used)
  1759. byte[] block1 = new byte[blockLength];
  1760. Array.Copy (output, 0, block1, 0, blockLength);
  1761. byte[] block2 = new byte[blockLength];
  1762. Array.Copy (output, blockLength, block2, 0, blockLength);
  1763. AssertEquals ("RC2_k88b64_ECB_None b1==b2", block1, block2);
  1764. byte[] reverse = new byte [blockLength * 3];
  1765. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1766. Decrypt (decryptor, output, reverse);
  1767. byte[] original = new byte [input.Length];
  1768. Array.Copy (reverse, 0, original, 0, original.Length);
  1769. AssertEquals ("RC2_k88b64_ECB_None Decrypt", input, original);
  1770. }
  1771. [Test]
  1772. public void TestRC2_k88b64_ECB_Zeros ()
  1773. {
  1774. byte[] key = { 0x28, 0xDC, 0x09, 0x80, 0x85, 0x25, 0x95, 0x41, 0x7B, 0xD4, 0x06 };
  1775. // not used for ECB but make the code more uniform
  1776. byte[] iv = { 0xAE, 0x0D, 0xC1, 0x42, 0x01, 0x1C, 0x6E, 0x5A };
  1777. byte[] expected = { 0x48, 0xD6, 0x9F, 0x9A, 0x7C, 0x93, 0x89, 0x5F, 0x48, 0xD6, 0x9F, 0x9A, 0x7C, 0x93, 0x89, 0x5F, 0x48, 0xD6, 0x9F, 0x9A, 0x7C, 0x93, 0x89, 0x5F };
  1778. SymmetricAlgorithm algo = RC2.Create ();
  1779. algo.Mode = CipherMode.ECB;
  1780. algo.Padding = PaddingMode.Zeros;
  1781. algo.BlockSize = 64;
  1782. int blockLength = (algo.BlockSize >> 3);
  1783. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1784. byte[] output = new byte [blockLength * 3];
  1785. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1786. Encrypt (encryptor, input, output);
  1787. AssertEquals ("RC2_k88b64_ECB_Zeros Encrypt", expected, output);
  1788. // in ECB the first 2 blocks should be equals (as the IV is not used)
  1789. byte[] block1 = new byte[blockLength];
  1790. Array.Copy (output, 0, block1, 0, blockLength);
  1791. byte[] block2 = new byte[blockLength];
  1792. Array.Copy (output, blockLength, block2, 0, blockLength);
  1793. AssertEquals ("RC2_k88b64_ECB_Zeros b1==b2", block1, block2);
  1794. // also if padding is Zeros then all three blocks should be equals
  1795. byte[] block3 = new byte[blockLength];
  1796. Array.Copy (output, blockLength, block3, 0, blockLength);
  1797. AssertEquals ("RC2_k88b64_ECB_Zeros b1==b3", block1, block3);
  1798. byte[] reverse = new byte [blockLength * 3];
  1799. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1800. Decrypt (decryptor, output, reverse);
  1801. byte[] original = new byte [input.Length];
  1802. Array.Copy (reverse, 0, original, 0, original.Length);
  1803. AssertEquals ("RC2_k88b64_ECB_Zeros Decrypt", input, original);
  1804. }
  1805. [Test]
  1806. public void TestRC2_k88b64_ECB_PKCS7 ()
  1807. {
  1808. byte[] key = { 0xAB, 0x26, 0x7E, 0xD3, 0x3A, 0x0A, 0x3F, 0x50, 0x0B, 0x84, 0x5F };
  1809. // not used for ECB but make the code more uniform
  1810. byte[] iv = { 0x28, 0x3C, 0x18, 0x06, 0x3C, 0xF7, 0x83, 0x51 };
  1811. byte[] expected = { 0xE0, 0x60, 0x29, 0xC5, 0xE5, 0xFE, 0x75, 0x95, 0xE0, 0x60, 0x29, 0xC5, 0xE5, 0xFE, 0x75, 0x95, 0xE8, 0x61, 0x0A, 0x2A, 0x79, 0x3F, 0x0A, 0xB7 };
  1812. SymmetricAlgorithm algo = RC2.Create ();
  1813. algo.Mode = CipherMode.ECB;
  1814. algo.Padding = PaddingMode.PKCS7;
  1815. algo.BlockSize = 64;
  1816. int blockLength = (algo.BlockSize >> 3);
  1817. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1818. byte[] output = new byte [blockLength * 3];
  1819. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1820. Encrypt (encryptor, input, output);
  1821. AssertEquals ("RC2_k88b64_ECB_PKCS7 Encrypt", expected, output);
  1822. // in ECB the first 2 blocks should be equals (as the IV is not used)
  1823. byte[] block1 = new byte[blockLength];
  1824. Array.Copy (output, 0, block1, 0, blockLength);
  1825. byte[] block2 = new byte[blockLength];
  1826. Array.Copy (output, blockLength, block2, 0, blockLength);
  1827. AssertEquals ("RC2_k88b64_ECB_PKCS7 b1==b2", block1, block2);
  1828. byte[] reverse = new byte [blockLength * 3];
  1829. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1830. Decrypt (decryptor, output, reverse);
  1831. byte[] original = new byte [input.Length];
  1832. Array.Copy (reverse, 0, original, 0, original.Length);
  1833. AssertEquals ("RC2_k88b64_ECB_PKCS7 Decrypt", input, original);
  1834. }
  1835. [Test]
  1836. public void TestRC2_k88b64_CBC_None ()
  1837. {
  1838. byte[] key = { 0x01, 0x2F, 0x45, 0x5F, 0x2D, 0x9E, 0xDB, 0x29, 0x6C, 0x54, 0xF5 };
  1839. byte[] iv = { 0x4C, 0x6A, 0x4D, 0x77, 0x7E, 0x34, 0xB4, 0x75 };
  1840. byte[] expected = { 0x66, 0x58, 0x7F, 0xE7, 0x6D, 0x3B, 0x6A, 0x97, 0xFC, 0x65, 0x15, 0x8D, 0xAC, 0xB0, 0xB1, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1841. SymmetricAlgorithm algo = RC2.Create ();
  1842. algo.Mode = CipherMode.CBC;
  1843. algo.Padding = PaddingMode.None;
  1844. algo.BlockSize = 64;
  1845. int blockLength = (algo.BlockSize >> 3);
  1846. byte[] input = new byte [blockLength * 2];
  1847. byte[] output = new byte [blockLength * 3];
  1848. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1849. Encrypt (encryptor, input, output);
  1850. AssertEquals ("RC2_k88b64_CBC_None Encrypt", expected, output);
  1851. byte[] reverse = new byte [blockLength * 3];
  1852. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1853. Decrypt (decryptor, output, reverse);
  1854. byte[] original = new byte [input.Length];
  1855. Array.Copy (reverse, 0, original, 0, original.Length);
  1856. AssertEquals ("RC2_k88b64_CBC_None Decrypt", input, original);
  1857. }
  1858. [Test]
  1859. public void TestRC2_k88b64_CBC_Zeros ()
  1860. {
  1861. byte[] key = { 0xA9, 0xD1, 0xDA, 0xCB, 0x4C, 0xA7, 0xD3, 0x35, 0x70, 0x1E, 0x15 };
  1862. byte[] iv = { 0xF2, 0x17, 0x14, 0x41, 0x36, 0x58, 0x27, 0x48 };
  1863. byte[] expected = { 0x41, 0xDD, 0xFE, 0x10, 0x56, 0xE2, 0x86, 0xDC, 0xC6, 0x53, 0x69, 0x1A, 0x2D, 0x66, 0x1D, 0x1C, 0xAD, 0x3C, 0x1F, 0xCE, 0xE3, 0xE2, 0x52, 0x13 };
  1864. SymmetricAlgorithm algo = RC2.Create ();
  1865. algo.Mode = CipherMode.CBC;
  1866. algo.Padding = PaddingMode.Zeros;
  1867. algo.BlockSize = 64;
  1868. int blockLength = (algo.BlockSize >> 3);
  1869. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1870. byte[] output = new byte [blockLength * 3];
  1871. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1872. Encrypt (encryptor, input, output);
  1873. AssertEquals ("RC2_k88b64_CBC_Zeros Encrypt", expected, output);
  1874. byte[] reverse = new byte [blockLength * 3];
  1875. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1876. Decrypt (decryptor, output, reverse);
  1877. byte[] original = new byte [input.Length];
  1878. Array.Copy (reverse, 0, original, 0, original.Length);
  1879. AssertEquals ("RC2_k88b64_CBC_Zeros Decrypt", input, original);
  1880. }
  1881. [Test]
  1882. public void TestRC2_k88b64_CBC_PKCS7 ()
  1883. {
  1884. byte[] key = { 0x07, 0x97, 0xCB, 0xA3, 0xB6, 0xFF, 0x57, 0x30, 0x5A, 0x2E, 0x3E };
  1885. byte[] iv = { 0x78, 0x44, 0xCE, 0xBA, 0xC6, 0xCD, 0x0C, 0xB7 };
  1886. byte[] expected = { 0x07, 0xCC, 0xFD, 0x12, 0x0D, 0x07, 0xED, 0xB2, 0x8C, 0xDA, 0xB9, 0xC3, 0xE7, 0x04, 0x41, 0x5A, 0xA3, 0x9C, 0x50, 0x8B, 0x8F, 0x9D, 0x2E, 0x65 };
  1887. SymmetricAlgorithm algo = RC2.Create ();
  1888. algo.Mode = CipherMode.CBC;
  1889. algo.Padding = PaddingMode.PKCS7;
  1890. algo.BlockSize = 64;
  1891. int blockLength = (algo.BlockSize >> 3);
  1892. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1893. byte[] output = new byte [blockLength * 3];
  1894. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1895. Encrypt (encryptor, input, output);
  1896. AssertEquals ("RC2_k88b64_CBC_PKCS7 Encrypt", expected, output);
  1897. byte[] reverse = new byte [blockLength * 3];
  1898. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1899. Decrypt (decryptor, output, reverse);
  1900. byte[] original = new byte [input.Length];
  1901. Array.Copy (reverse, 0, original, 0, original.Length);
  1902. AssertEquals ("RC2_k88b64_CBC_PKCS7 Decrypt", input, original);
  1903. }
  1904. /* Invalid parameters RC2_k88b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  1905. /* Invalid parameters RC2_k88b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  1906. /* Invalid parameters RC2_k88b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  1907. [Test]
  1908. public void TestRC2_k88b64_CFB8_None ()
  1909. {
  1910. byte[] key = { 0x6E, 0x73, 0x03, 0xFD, 0x20, 0xAB, 0x21, 0x9D, 0x54, 0x0C, 0xB9 };
  1911. byte[] iv = { 0x69, 0x6B, 0xF5, 0xD0, 0x10, 0xB5, 0xFE, 0xEF };
  1912. byte[] expected = { 0x12, 0x2B, 0xF0, 0x54, 0xFF, 0x2F, 0xE2, 0xF0, 0x36, 0x9A, 0x3E, 0xFE, 0x57, 0x56, 0x0E, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1913. SymmetricAlgorithm algo = RC2.Create ();
  1914. algo.Mode = CipherMode.CFB;
  1915. algo.Padding = PaddingMode.None;
  1916. algo.BlockSize = 64;
  1917. algo.FeedbackSize = 8;
  1918. int blockLength = (algo.BlockSize >> 3);
  1919. byte[] input = new byte [blockLength * 2];
  1920. byte[] output = new byte [blockLength * 3];
  1921. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1922. Encrypt (encryptor, input, output);
  1923. AssertEquals ("RC2_k88b64_CFB8_None Encrypt", expected, output);
  1924. byte[] reverse = new byte [blockLength * 3];
  1925. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1926. Decrypt (decryptor, output, reverse);
  1927. byte[] original = new byte [input.Length];
  1928. Array.Copy (reverse, 0, original, 0, original.Length);
  1929. AssertEquals ("RC2_k88b64_CFB8_None Decrypt", input, original);
  1930. }
  1931. [Test]
  1932. public void TestRC2_k88b64_CFB8_Zeros ()
  1933. {
  1934. byte[] key = { 0x8B, 0x1D, 0xD0, 0x5C, 0x3E, 0xF4, 0x5B, 0xA5, 0x56, 0x87, 0xE8 };
  1935. byte[] iv = { 0x14, 0x01, 0x4B, 0x90, 0x67, 0x02, 0x79, 0x3F };
  1936. byte[] expected = { 0xA1, 0x7D, 0x02, 0x58, 0xBC, 0x3E, 0x56, 0x3E, 0xF6, 0x08, 0x08, 0xB0, 0xD0, 0xD1, 0xAC, 0x9F, 0x29, 0x65, 0x18, 0x76, 0x2C, 0x96, 0xCC, 0x8C };
  1937. SymmetricAlgorithm algo = RC2.Create ();
  1938. algo.Mode = CipherMode.CFB;
  1939. algo.Padding = PaddingMode.Zeros;
  1940. algo.BlockSize = 64;
  1941. algo.FeedbackSize = 8;
  1942. int blockLength = (algo.BlockSize >> 3);
  1943. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1944. byte[] output = new byte [blockLength * 3];
  1945. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1946. Encrypt (encryptor, input, output);
  1947. AssertEquals ("RC2_k88b64_CFB8_Zeros Encrypt", expected, output);
  1948. byte[] reverse = new byte [blockLength * 3];
  1949. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1950. Decrypt (decryptor, output, reverse);
  1951. byte[] original = new byte [input.Length];
  1952. Array.Copy (reverse, 0, original, 0, original.Length);
  1953. AssertEquals ("RC2_k88b64_CFB8_Zeros Decrypt", input, original);
  1954. }
  1955. [Test]
  1956. public void TestRC2_k88b64_CFB8_PKCS7 ()
  1957. {
  1958. byte[] key = { 0xCB, 0xD9, 0xE0, 0xD8, 0x82, 0xA0, 0x06, 0xD1, 0x6C, 0x5F, 0x8F };
  1959. byte[] iv = { 0x73, 0x14, 0x81, 0x8C, 0x59, 0xE4, 0x33, 0xDF };
  1960. byte[] expected = { 0x31, 0xA2, 0xA9, 0xCE, 0xAF, 0xF1, 0x8F, 0xA5, 0x02, 0xD8, 0xF5, 0xDC, 0x2C, 0x41, 0x8E, 0x64, 0x81, 0xCA, 0xBE, 0x89, 0xC3, 0x19, 0x24, 0x78 };
  1961. SymmetricAlgorithm algo = RC2.Create ();
  1962. algo.Mode = CipherMode.CFB;
  1963. algo.Padding = PaddingMode.PKCS7;
  1964. algo.BlockSize = 64;
  1965. algo.FeedbackSize = 8;
  1966. int blockLength = (algo.BlockSize >> 3);
  1967. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  1968. byte[] output = new byte [blockLength * 3];
  1969. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1970. Encrypt (encryptor, input, output);
  1971. AssertEquals ("RC2_k88b64_CFB8_PKCS7 Encrypt", expected, output);
  1972. byte[] reverse = new byte [blockLength * 3];
  1973. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  1974. Decrypt (decryptor, output, reverse);
  1975. byte[] original = new byte [input.Length];
  1976. Array.Copy (reverse, 0, original, 0, original.Length);
  1977. AssertEquals ("RC2_k88b64_CFB8_PKCS7 Decrypt", input, original);
  1978. }
  1979. /* Invalid parameters RC2_k88b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1980. /* Invalid parameters RC2_k88b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1981. /* Invalid parameters RC2_k88b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  1982. [Test]
  1983. public void TestRC2_k96b64_ECB_None ()
  1984. {
  1985. byte[] key = { 0x72, 0xD8, 0x0A, 0x9D, 0xDA, 0x9D, 0xB1, 0x78, 0x61, 0x9C, 0xD8, 0x57 };
  1986. // not used for ECB but make the code more uniform
  1987. byte[] iv = { 0x31, 0x21, 0x9D, 0xD9, 0x12, 0x95, 0x79, 0x30 };
  1988. byte[] expected = { 0x41, 0xA6, 0x5B, 0x2D, 0x51, 0x55, 0x1B, 0xE2, 0x41, 0xA6, 0x5B, 0x2D, 0x51, 0x55, 0x1B, 0xE2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  1989. SymmetricAlgorithm algo = RC2.Create ();
  1990. algo.Mode = CipherMode.ECB;
  1991. algo.Padding = PaddingMode.None;
  1992. algo.BlockSize = 64;
  1993. int blockLength = (algo.BlockSize >> 3);
  1994. byte[] input = new byte [blockLength * 2];
  1995. byte[] output = new byte [blockLength * 3];
  1996. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  1997. Encrypt (encryptor, input, output);
  1998. AssertEquals ("RC2_k96b64_ECB_None Encrypt", expected, output);
  1999. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2000. byte[] block1 = new byte[blockLength];
  2001. Array.Copy (output, 0, block1, 0, blockLength);
  2002. byte[] block2 = new byte[blockLength];
  2003. Array.Copy (output, blockLength, block2, 0, blockLength);
  2004. AssertEquals ("RC2_k96b64_ECB_None b1==b2", block1, block2);
  2005. byte[] reverse = new byte [blockLength * 3];
  2006. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2007. Decrypt (decryptor, output, reverse);
  2008. byte[] original = new byte [input.Length];
  2009. Array.Copy (reverse, 0, original, 0, original.Length);
  2010. AssertEquals ("RC2_k96b64_ECB_None Decrypt", input, original);
  2011. }
  2012. [Test]
  2013. public void TestRC2_k96b64_ECB_Zeros ()
  2014. {
  2015. byte[] key = { 0x5D, 0x07, 0x3C, 0x15, 0x3F, 0xE1, 0xB2, 0x72, 0x9F, 0x1A, 0xBE, 0x21 };
  2016. // not used for ECB but make the code more uniform
  2017. byte[] iv = { 0x76, 0xE9, 0x93, 0x9F, 0xD1, 0x6A, 0xCE, 0x79 };
  2018. byte[] expected = { 0x56, 0xF6, 0xF3, 0xAE, 0xCD, 0x73, 0x4F, 0x12, 0x56, 0xF6, 0xF3, 0xAE, 0xCD, 0x73, 0x4F, 0x12, 0x56, 0xF6, 0xF3, 0xAE, 0xCD, 0x73, 0x4F, 0x12 };
  2019. SymmetricAlgorithm algo = RC2.Create ();
  2020. algo.Mode = CipherMode.ECB;
  2021. algo.Padding = PaddingMode.Zeros;
  2022. algo.BlockSize = 64;
  2023. int blockLength = (algo.BlockSize >> 3);
  2024. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2025. byte[] output = new byte [blockLength * 3];
  2026. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2027. Encrypt (encryptor, input, output);
  2028. AssertEquals ("RC2_k96b64_ECB_Zeros Encrypt", expected, output);
  2029. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2030. byte[] block1 = new byte[blockLength];
  2031. Array.Copy (output, 0, block1, 0, blockLength);
  2032. byte[] block2 = new byte[blockLength];
  2033. Array.Copy (output, blockLength, block2, 0, blockLength);
  2034. AssertEquals ("RC2_k96b64_ECB_Zeros b1==b2", block1, block2);
  2035. // also if padding is Zeros then all three blocks should be equals
  2036. byte[] block3 = new byte[blockLength];
  2037. Array.Copy (output, blockLength, block3, 0, blockLength);
  2038. AssertEquals ("RC2_k96b64_ECB_Zeros b1==b3", block1, block3);
  2039. byte[] reverse = new byte [blockLength * 3];
  2040. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2041. Decrypt (decryptor, output, reverse);
  2042. byte[] original = new byte [input.Length];
  2043. Array.Copy (reverse, 0, original, 0, original.Length);
  2044. AssertEquals ("RC2_k96b64_ECB_Zeros Decrypt", input, original);
  2045. }
  2046. [Test]
  2047. public void TestRC2_k96b64_ECB_PKCS7 ()
  2048. {
  2049. byte[] key = { 0x79, 0xCA, 0xDB, 0xBE, 0x8C, 0x10, 0x1E, 0xEB, 0x8B, 0x16, 0x00, 0x1B };
  2050. // not used for ECB but make the code more uniform
  2051. byte[] iv = { 0x17, 0x42, 0x68, 0x21, 0xBC, 0x52, 0x6A, 0xF6 };
  2052. byte[] expected = { 0x86, 0xB2, 0x84, 0xAA, 0x58, 0xCB, 0x3F, 0x19, 0x86, 0xB2, 0x84, 0xAA, 0x58, 0xCB, 0x3F, 0x19, 0x75, 0xB8, 0x91, 0xC8, 0x17, 0xE2, 0x1C, 0x4A };
  2053. SymmetricAlgorithm algo = RC2.Create ();
  2054. algo.Mode = CipherMode.ECB;
  2055. algo.Padding = PaddingMode.PKCS7;
  2056. algo.BlockSize = 64;
  2057. int blockLength = (algo.BlockSize >> 3);
  2058. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2059. byte[] output = new byte [blockLength * 3];
  2060. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2061. Encrypt (encryptor, input, output);
  2062. AssertEquals ("RC2_k96b64_ECB_PKCS7 Encrypt", expected, output);
  2063. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2064. byte[] block1 = new byte[blockLength];
  2065. Array.Copy (output, 0, block1, 0, blockLength);
  2066. byte[] block2 = new byte[blockLength];
  2067. Array.Copy (output, blockLength, block2, 0, blockLength);
  2068. AssertEquals ("RC2_k96b64_ECB_PKCS7 b1==b2", block1, block2);
  2069. byte[] reverse = new byte [blockLength * 3];
  2070. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2071. Decrypt (decryptor, output, reverse);
  2072. byte[] original = new byte [input.Length];
  2073. Array.Copy (reverse, 0, original, 0, original.Length);
  2074. AssertEquals ("RC2_k96b64_ECB_PKCS7 Decrypt", input, original);
  2075. }
  2076. [Test]
  2077. public void TestRC2_k96b64_CBC_None ()
  2078. {
  2079. byte[] key = { 0x68, 0xC6, 0xF2, 0x13, 0xEA, 0x3D, 0x68, 0x09, 0xAC, 0x07, 0x21, 0x1F };
  2080. byte[] iv = { 0x42, 0x47, 0xE6, 0x98, 0xF8, 0xFE, 0xCD, 0xFE };
  2081. byte[] expected = { 0x7F, 0x9C, 0xCE, 0xC5, 0x2C, 0xB6, 0x60, 0xC3, 0xF3, 0x5F, 0x7E, 0x95, 0x6F, 0xFE, 0x8E, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2082. SymmetricAlgorithm algo = RC2.Create ();
  2083. algo.Mode = CipherMode.CBC;
  2084. algo.Padding = PaddingMode.None;
  2085. algo.BlockSize = 64;
  2086. int blockLength = (algo.BlockSize >> 3);
  2087. byte[] input = new byte [blockLength * 2];
  2088. byte[] output = new byte [blockLength * 3];
  2089. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2090. Encrypt (encryptor, input, output);
  2091. AssertEquals ("RC2_k96b64_CBC_None Encrypt", expected, output);
  2092. byte[] reverse = new byte [blockLength * 3];
  2093. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2094. Decrypt (decryptor, output, reverse);
  2095. byte[] original = new byte [input.Length];
  2096. Array.Copy (reverse, 0, original, 0, original.Length);
  2097. AssertEquals ("RC2_k96b64_CBC_None Decrypt", input, original);
  2098. }
  2099. [Test]
  2100. public void TestRC2_k96b64_CBC_Zeros ()
  2101. {
  2102. byte[] key = { 0xDF, 0x00, 0x49, 0x93, 0xA1, 0x49, 0x50, 0x03, 0x52, 0x9C, 0x86, 0xF6 };
  2103. byte[] iv = { 0x69, 0xFC, 0x72, 0xA2, 0x60, 0xF7, 0x4C, 0xB0 };
  2104. byte[] expected = { 0x16, 0x07, 0x45, 0x07, 0xF8, 0xAE, 0xD3, 0xEA, 0x94, 0x1E, 0xC9, 0x1A, 0xEF, 0x8D, 0x3E, 0xF7, 0x88, 0x7D, 0x8D, 0xF8, 0xC6, 0x0A, 0xFA, 0x82 };
  2105. SymmetricAlgorithm algo = RC2.Create ();
  2106. algo.Mode = CipherMode.CBC;
  2107. algo.Padding = PaddingMode.Zeros;
  2108. algo.BlockSize = 64;
  2109. int blockLength = (algo.BlockSize >> 3);
  2110. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2111. byte[] output = new byte [blockLength * 3];
  2112. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2113. Encrypt (encryptor, input, output);
  2114. AssertEquals ("RC2_k96b64_CBC_Zeros Encrypt", expected, output);
  2115. byte[] reverse = new byte [blockLength * 3];
  2116. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2117. Decrypt (decryptor, output, reverse);
  2118. byte[] original = new byte [input.Length];
  2119. Array.Copy (reverse, 0, original, 0, original.Length);
  2120. AssertEquals ("RC2_k96b64_CBC_Zeros Decrypt", input, original);
  2121. }
  2122. [Test]
  2123. public void TestRC2_k96b64_CBC_PKCS7 ()
  2124. {
  2125. byte[] key = { 0x04, 0x2B, 0x2E, 0x98, 0x97, 0x84, 0x72, 0x0A, 0x78, 0x61, 0x02, 0xA9 };
  2126. byte[] iv = { 0x16, 0x0A, 0x00, 0x48, 0xC3, 0x4F, 0x63, 0x05 };
  2127. byte[] expected = { 0xD2, 0xC4, 0xC7, 0x02, 0xC7, 0xDB, 0xFB, 0xF6, 0xC1, 0x4D, 0x2D, 0x62, 0xF6, 0x57, 0x84, 0x84, 0xF2, 0x9B, 0x5C, 0x42, 0x66, 0x9B, 0x33, 0x1D };
  2128. SymmetricAlgorithm algo = RC2.Create ();
  2129. algo.Mode = CipherMode.CBC;
  2130. algo.Padding = PaddingMode.PKCS7;
  2131. algo.BlockSize = 64;
  2132. int blockLength = (algo.BlockSize >> 3);
  2133. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2134. byte[] output = new byte [blockLength * 3];
  2135. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2136. Encrypt (encryptor, input, output);
  2137. AssertEquals ("RC2_k96b64_CBC_PKCS7 Encrypt", expected, output);
  2138. byte[] reverse = new byte [blockLength * 3];
  2139. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2140. Decrypt (decryptor, output, reverse);
  2141. byte[] original = new byte [input.Length];
  2142. Array.Copy (reverse, 0, original, 0, original.Length);
  2143. AssertEquals ("RC2_k96b64_CBC_PKCS7 Decrypt", input, original);
  2144. }
  2145. /* Invalid parameters RC2_k96b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  2146. /* Invalid parameters RC2_k96b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  2147. /* Invalid parameters RC2_k96b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  2148. [Test]
  2149. public void TestRC2_k96b64_CFB8_None ()
  2150. {
  2151. byte[] key = { 0xDE, 0x6E, 0x40, 0xC3, 0x7D, 0x71, 0x0D, 0xCB, 0xA3, 0x62, 0x14, 0x76 };
  2152. byte[] iv = { 0x72, 0x9E, 0xB4, 0xEE, 0x9B, 0x87, 0xAF, 0x12 };
  2153. byte[] expected = { 0x14, 0x20, 0x3B, 0x35, 0xE2, 0x81, 0x84, 0x15, 0x6C, 0xA5, 0x4A, 0x94, 0xB3, 0xC0, 0x8D, 0x6A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2154. SymmetricAlgorithm algo = RC2.Create ();
  2155. algo.Mode = CipherMode.CFB;
  2156. algo.Padding = PaddingMode.None;
  2157. algo.BlockSize = 64;
  2158. algo.FeedbackSize = 8;
  2159. int blockLength = (algo.BlockSize >> 3);
  2160. byte[] input = new byte [blockLength * 2];
  2161. byte[] output = new byte [blockLength * 3];
  2162. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2163. Encrypt (encryptor, input, output);
  2164. AssertEquals ("RC2_k96b64_CFB8_None Encrypt", expected, output);
  2165. byte[] reverse = new byte [blockLength * 3];
  2166. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2167. Decrypt (decryptor, output, reverse);
  2168. byte[] original = new byte [input.Length];
  2169. Array.Copy (reverse, 0, original, 0, original.Length);
  2170. AssertEquals ("RC2_k96b64_CFB8_None Decrypt", input, original);
  2171. }
  2172. [Test]
  2173. public void TestRC2_k96b64_CFB8_Zeros ()
  2174. {
  2175. byte[] key = { 0xCF, 0x64, 0x81, 0x8F, 0x7D, 0x75, 0x8D, 0xB2, 0x9D, 0xE7, 0x39, 0xE3 };
  2176. byte[] iv = { 0x30, 0xF2, 0x9E, 0x76, 0x96, 0x13, 0xCB, 0xDF };
  2177. byte[] expected = { 0xC4, 0x0E, 0xE8, 0x61, 0x92, 0xB8, 0x9D, 0xDE, 0x0B, 0x39, 0x47, 0xD4, 0xD8, 0x05, 0x35, 0xF9, 0x0A, 0xAF, 0x63, 0x30, 0x4A, 0x82, 0x8C, 0xF2 };
  2178. SymmetricAlgorithm algo = RC2.Create ();
  2179. algo.Mode = CipherMode.CFB;
  2180. algo.Padding = PaddingMode.Zeros;
  2181. algo.BlockSize = 64;
  2182. algo.FeedbackSize = 8;
  2183. int blockLength = (algo.BlockSize >> 3);
  2184. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2185. byte[] output = new byte [blockLength * 3];
  2186. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2187. Encrypt (encryptor, input, output);
  2188. AssertEquals ("RC2_k96b64_CFB8_Zeros Encrypt", expected, output);
  2189. byte[] reverse = new byte [blockLength * 3];
  2190. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2191. Decrypt (decryptor, output, reverse);
  2192. byte[] original = new byte [input.Length];
  2193. Array.Copy (reverse, 0, original, 0, original.Length);
  2194. AssertEquals ("RC2_k96b64_CFB8_Zeros Decrypt", input, original);
  2195. }
  2196. [Test]
  2197. public void TestRC2_k96b64_CFB8_PKCS7 ()
  2198. {
  2199. byte[] key = { 0xC5, 0xF4, 0x44, 0xF2, 0xA0, 0xC3, 0xA7, 0x87, 0x64, 0x36, 0x5A, 0xFA };
  2200. byte[] iv = { 0x20, 0xC5, 0x5E, 0x57, 0x5E, 0x0E, 0x2D, 0xDD };
  2201. byte[] expected = { 0x66, 0x93, 0x1E, 0x15, 0x17, 0x5C, 0x3C, 0x07, 0xDB, 0x2F, 0xD9, 0x00, 0x0C, 0x3F, 0x9E, 0xBB, 0xB9, 0x32, 0xDD, 0x2D, 0x57, 0x69, 0x3D, 0xC3 };
  2202. SymmetricAlgorithm algo = RC2.Create ();
  2203. algo.Mode = CipherMode.CFB;
  2204. algo.Padding = PaddingMode.PKCS7;
  2205. algo.BlockSize = 64;
  2206. algo.FeedbackSize = 8;
  2207. int blockLength = (algo.BlockSize >> 3);
  2208. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2209. byte[] output = new byte [blockLength * 3];
  2210. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2211. Encrypt (encryptor, input, output);
  2212. AssertEquals ("RC2_k96b64_CFB8_PKCS7 Encrypt", expected, output);
  2213. byte[] reverse = new byte [blockLength * 3];
  2214. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2215. Decrypt (decryptor, output, reverse);
  2216. byte[] original = new byte [input.Length];
  2217. Array.Copy (reverse, 0, original, 0, original.Length);
  2218. AssertEquals ("RC2_k96b64_CFB8_PKCS7 Decrypt", input, original);
  2219. }
  2220. /* Invalid parameters RC2_k96b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  2221. /* Invalid parameters RC2_k96b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  2222. /* Invalid parameters RC2_k96b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  2223. [Test]
  2224. public void TestRC2_k104b64_ECB_None ()
  2225. {
  2226. byte[] key = { 0x04, 0x5B, 0x99, 0xD3, 0xBC, 0x00, 0x27, 0xA3, 0xDC, 0x57, 0x4C, 0x82, 0xD6 };
  2227. // not used for ECB but make the code more uniform
  2228. byte[] iv = { 0x70, 0x3D, 0xE7, 0xBC, 0x82, 0xFD, 0x8F, 0x03 };
  2229. byte[] expected = { 0x5D, 0xEA, 0x9F, 0x1F, 0x19, 0xBB, 0x3D, 0x26, 0x5D, 0xEA, 0x9F, 0x1F, 0x19, 0xBB, 0x3D, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2230. SymmetricAlgorithm algo = RC2.Create ();
  2231. algo.Mode = CipherMode.ECB;
  2232. algo.Padding = PaddingMode.None;
  2233. algo.BlockSize = 64;
  2234. int blockLength = (algo.BlockSize >> 3);
  2235. byte[] input = new byte [blockLength * 2];
  2236. byte[] output = new byte [blockLength * 3];
  2237. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2238. Encrypt (encryptor, input, output);
  2239. AssertEquals ("RC2_k104b64_ECB_None Encrypt", expected, output);
  2240. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2241. byte[] block1 = new byte[blockLength];
  2242. Array.Copy (output, 0, block1, 0, blockLength);
  2243. byte[] block2 = new byte[blockLength];
  2244. Array.Copy (output, blockLength, block2, 0, blockLength);
  2245. AssertEquals ("RC2_k104b64_ECB_None b1==b2", block1, block2);
  2246. byte[] reverse = new byte [blockLength * 3];
  2247. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2248. Decrypt (decryptor, output, reverse);
  2249. byte[] original = new byte [input.Length];
  2250. Array.Copy (reverse, 0, original, 0, original.Length);
  2251. AssertEquals ("RC2_k104b64_ECB_None Decrypt", input, original);
  2252. }
  2253. [Test]
  2254. public void TestRC2_k104b64_ECB_Zeros ()
  2255. {
  2256. byte[] key = { 0xA1, 0x3B, 0xDF, 0x6F, 0x6D, 0x2B, 0x7B, 0x0B, 0x13, 0x3E, 0x84, 0x35, 0x3C };
  2257. // not used for ECB but make the code more uniform
  2258. byte[] iv = { 0xE6, 0x74, 0x41, 0xB6, 0xB4, 0x31, 0xB2, 0x6A };
  2259. byte[] expected = { 0xAF, 0x46, 0x98, 0xF8, 0xC1, 0x4B, 0x45, 0x09, 0xAF, 0x46, 0x98, 0xF8, 0xC1, 0x4B, 0x45, 0x09, 0xAF, 0x46, 0x98, 0xF8, 0xC1, 0x4B, 0x45, 0x09 };
  2260. SymmetricAlgorithm algo = RC2.Create ();
  2261. algo.Mode = CipherMode.ECB;
  2262. algo.Padding = PaddingMode.Zeros;
  2263. algo.BlockSize = 64;
  2264. int blockLength = (algo.BlockSize >> 3);
  2265. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2266. byte[] output = new byte [blockLength * 3];
  2267. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2268. Encrypt (encryptor, input, output);
  2269. AssertEquals ("RC2_k104b64_ECB_Zeros Encrypt", expected, output);
  2270. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2271. byte[] block1 = new byte[blockLength];
  2272. Array.Copy (output, 0, block1, 0, blockLength);
  2273. byte[] block2 = new byte[blockLength];
  2274. Array.Copy (output, blockLength, block2, 0, blockLength);
  2275. AssertEquals ("RC2_k104b64_ECB_Zeros b1==b2", block1, block2);
  2276. // also if padding is Zeros then all three blocks should be equals
  2277. byte[] block3 = new byte[blockLength];
  2278. Array.Copy (output, blockLength, block3, 0, blockLength);
  2279. AssertEquals ("RC2_k104b64_ECB_Zeros b1==b3", block1, block3);
  2280. byte[] reverse = new byte [blockLength * 3];
  2281. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2282. Decrypt (decryptor, output, reverse);
  2283. byte[] original = new byte [input.Length];
  2284. Array.Copy (reverse, 0, original, 0, original.Length);
  2285. AssertEquals ("RC2_k104b64_ECB_Zeros Decrypt", input, original);
  2286. }
  2287. [Test]
  2288. public void TestRC2_k104b64_ECB_PKCS7 ()
  2289. {
  2290. byte[] key = { 0x28, 0xDF, 0x8C, 0x1B, 0x7E, 0x04, 0xB2, 0x89, 0x72, 0xDA, 0x19, 0x57, 0x81 };
  2291. // not used for ECB but make the code more uniform
  2292. byte[] iv = { 0xB8, 0x82, 0xA7, 0xBF, 0x99, 0xE9, 0x39, 0x02 };
  2293. byte[] expected = { 0x5D, 0xEB, 0xD8, 0x26, 0x51, 0x86, 0xFB, 0x0E, 0x5D, 0xEB, 0xD8, 0x26, 0x51, 0x86, 0xFB, 0x0E, 0x1C, 0xFD, 0xE2, 0x77, 0xB6, 0x74, 0x55, 0x9C };
  2294. SymmetricAlgorithm algo = RC2.Create ();
  2295. algo.Mode = CipherMode.ECB;
  2296. algo.Padding = PaddingMode.PKCS7;
  2297. algo.BlockSize = 64;
  2298. int blockLength = (algo.BlockSize >> 3);
  2299. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2300. byte[] output = new byte [blockLength * 3];
  2301. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2302. Encrypt (encryptor, input, output);
  2303. AssertEquals ("RC2_k104b64_ECB_PKCS7 Encrypt", expected, output);
  2304. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2305. byte[] block1 = new byte[blockLength];
  2306. Array.Copy (output, 0, block1, 0, blockLength);
  2307. byte[] block2 = new byte[blockLength];
  2308. Array.Copy (output, blockLength, block2, 0, blockLength);
  2309. AssertEquals ("RC2_k104b64_ECB_PKCS7 b1==b2", block1, block2);
  2310. byte[] reverse = new byte [blockLength * 3];
  2311. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2312. Decrypt (decryptor, output, reverse);
  2313. byte[] original = new byte [input.Length];
  2314. Array.Copy (reverse, 0, original, 0, original.Length);
  2315. AssertEquals ("RC2_k104b64_ECB_PKCS7 Decrypt", input, original);
  2316. }
  2317. [Test]
  2318. public void TestRC2_k104b64_CBC_None ()
  2319. {
  2320. byte[] key = { 0xF8, 0xCE, 0xA2, 0x33, 0xE5, 0x7D, 0x43, 0x72, 0xA9, 0xF5, 0xF1, 0x80, 0xBC };
  2321. byte[] iv = { 0x12, 0xFF, 0x74, 0x3A, 0x36, 0x42, 0xBE, 0x78 };
  2322. byte[] expected = { 0x64, 0xCD, 0x86, 0xA1, 0x1B, 0xB1, 0xD3, 0x9F, 0x8E, 0xFC, 0x42, 0xB8, 0x56, 0x96, 0x56, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2323. SymmetricAlgorithm algo = RC2.Create ();
  2324. algo.Mode = CipherMode.CBC;
  2325. algo.Padding = PaddingMode.None;
  2326. algo.BlockSize = 64;
  2327. int blockLength = (algo.BlockSize >> 3);
  2328. byte[] input = new byte [blockLength * 2];
  2329. byte[] output = new byte [blockLength * 3];
  2330. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2331. Encrypt (encryptor, input, output);
  2332. AssertEquals ("RC2_k104b64_CBC_None Encrypt", expected, output);
  2333. byte[] reverse = new byte [blockLength * 3];
  2334. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2335. Decrypt (decryptor, output, reverse);
  2336. byte[] original = new byte [input.Length];
  2337. Array.Copy (reverse, 0, original, 0, original.Length);
  2338. AssertEquals ("RC2_k104b64_CBC_None Decrypt", input, original);
  2339. }
  2340. [Test]
  2341. public void TestRC2_k104b64_CBC_Zeros ()
  2342. {
  2343. byte[] key = { 0xEF, 0x4E, 0x02, 0x86, 0x5F, 0xE5, 0x94, 0x05, 0xEF, 0x8D, 0x8D, 0x5D, 0x04 };
  2344. byte[] iv = { 0x98, 0x23, 0x93, 0xF7, 0x6D, 0x02, 0xB1, 0x73 };
  2345. byte[] expected = { 0x50, 0x08, 0xAB, 0x8B, 0x26, 0x0D, 0x5B, 0x73, 0x3F, 0xE7, 0x75, 0x55, 0x4F, 0x9C, 0xDC, 0xFC, 0x17, 0x58, 0x2A, 0xB2, 0xFC, 0x54, 0x15, 0x97 };
  2346. SymmetricAlgorithm algo = RC2.Create ();
  2347. algo.Mode = CipherMode.CBC;
  2348. algo.Padding = PaddingMode.Zeros;
  2349. algo.BlockSize = 64;
  2350. int blockLength = (algo.BlockSize >> 3);
  2351. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2352. byte[] output = new byte [blockLength * 3];
  2353. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2354. Encrypt (encryptor, input, output);
  2355. AssertEquals ("RC2_k104b64_CBC_Zeros Encrypt", expected, output);
  2356. byte[] reverse = new byte [blockLength * 3];
  2357. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2358. Decrypt (decryptor, output, reverse);
  2359. byte[] original = new byte [input.Length];
  2360. Array.Copy (reverse, 0, original, 0, original.Length);
  2361. AssertEquals ("RC2_k104b64_CBC_Zeros Decrypt", input, original);
  2362. }
  2363. [Test]
  2364. public void TestRC2_k104b64_CBC_PKCS7 ()
  2365. {
  2366. byte[] key = { 0xE3, 0xD2, 0xC2, 0xA0, 0x54, 0xF5, 0xFC, 0xFC, 0x94, 0xA2, 0x6F, 0x6F, 0x52 };
  2367. byte[] iv = { 0xBA, 0x5D, 0x0D, 0xBA, 0x0D, 0x0C, 0x4E, 0x5B };
  2368. byte[] expected = { 0x6C, 0x5B, 0x74, 0x54, 0x0F, 0x86, 0x62, 0x06, 0x11, 0x65, 0xAA, 0x0B, 0x4F, 0x65, 0x34, 0x26, 0xAF, 0x26, 0x0D, 0xF4, 0xCE, 0xB6, 0xEE, 0xF0 };
  2369. SymmetricAlgorithm algo = RC2.Create ();
  2370. algo.Mode = CipherMode.CBC;
  2371. algo.Padding = PaddingMode.PKCS7;
  2372. algo.BlockSize = 64;
  2373. int blockLength = (algo.BlockSize >> 3);
  2374. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2375. byte[] output = new byte [blockLength * 3];
  2376. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2377. Encrypt (encryptor, input, output);
  2378. AssertEquals ("RC2_k104b64_CBC_PKCS7 Encrypt", expected, output);
  2379. byte[] reverse = new byte [blockLength * 3];
  2380. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2381. Decrypt (decryptor, output, reverse);
  2382. byte[] original = new byte [input.Length];
  2383. Array.Copy (reverse, 0, original, 0, original.Length);
  2384. AssertEquals ("RC2_k104b64_CBC_PKCS7 Decrypt", input, original);
  2385. }
  2386. /* Invalid parameters RC2_k104b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  2387. /* Invalid parameters RC2_k104b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  2388. /* Invalid parameters RC2_k104b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  2389. [Test]
  2390. public void TestRC2_k104b64_CFB8_None ()
  2391. {
  2392. byte[] key = { 0xB3, 0xE2, 0x4D, 0x91, 0xE9, 0xF8, 0x72, 0xA4, 0x2E, 0x00, 0x0C, 0x08, 0x96 };
  2393. byte[] iv = { 0x48, 0xF8, 0xDD, 0x61, 0xD5, 0x00, 0xD0, 0xE1 };
  2394. byte[] expected = { 0xB9, 0xAA, 0x53, 0xD8, 0xCB, 0x23, 0xA6, 0x41, 0x69, 0x84, 0x2D, 0xD5, 0x4F, 0x45, 0xC2, 0x8D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2395. SymmetricAlgorithm algo = RC2.Create ();
  2396. algo.Mode = CipherMode.CFB;
  2397. algo.Padding = PaddingMode.None;
  2398. algo.BlockSize = 64;
  2399. algo.FeedbackSize = 8;
  2400. int blockLength = (algo.BlockSize >> 3);
  2401. byte[] input = new byte [blockLength * 2];
  2402. byte[] output = new byte [blockLength * 3];
  2403. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2404. Encrypt (encryptor, input, output);
  2405. AssertEquals ("RC2_k104b64_CFB8_None Encrypt", expected, output);
  2406. byte[] reverse = new byte [blockLength * 3];
  2407. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2408. Decrypt (decryptor, output, reverse);
  2409. byte[] original = new byte [input.Length];
  2410. Array.Copy (reverse, 0, original, 0, original.Length);
  2411. AssertEquals ("RC2_k104b64_CFB8_None Decrypt", input, original);
  2412. }
  2413. [Test]
  2414. public void TestRC2_k104b64_CFB8_Zeros ()
  2415. {
  2416. byte[] key = { 0xD4, 0x9C, 0x6B, 0x12, 0x41, 0x93, 0xEB, 0xDA, 0xDF, 0x7A, 0x81, 0x23, 0x1F };
  2417. byte[] iv = { 0x3C, 0x0E, 0x48, 0xAA, 0xD8, 0x48, 0xE9, 0xC8 };
  2418. byte[] expected = { 0x66, 0x39, 0x26, 0x0B, 0x81, 0xD8, 0x9A, 0x2F, 0xF1, 0x2C, 0xCF, 0x75, 0x8C, 0x01, 0x4D, 0x6E, 0x2A, 0x67, 0x9D, 0x0D, 0xA5, 0x56, 0x15, 0x41 };
  2419. SymmetricAlgorithm algo = RC2.Create ();
  2420. algo.Mode = CipherMode.CFB;
  2421. algo.Padding = PaddingMode.Zeros;
  2422. algo.BlockSize = 64;
  2423. algo.FeedbackSize = 8;
  2424. int blockLength = (algo.BlockSize >> 3);
  2425. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2426. byte[] output = new byte [blockLength * 3];
  2427. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2428. Encrypt (encryptor, input, output);
  2429. AssertEquals ("RC2_k104b64_CFB8_Zeros Encrypt", expected, output);
  2430. byte[] reverse = new byte [blockLength * 3];
  2431. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2432. Decrypt (decryptor, output, reverse);
  2433. byte[] original = new byte [input.Length];
  2434. Array.Copy (reverse, 0, original, 0, original.Length);
  2435. AssertEquals ("RC2_k104b64_CFB8_Zeros Decrypt", input, original);
  2436. }
  2437. [Test]
  2438. public void TestRC2_k104b64_CFB8_PKCS7 ()
  2439. {
  2440. byte[] key = { 0x2C, 0x38, 0x19, 0x43, 0x93, 0x38, 0x85, 0xC4, 0xF2, 0x19, 0xC7, 0x1B, 0x76 };
  2441. byte[] iv = { 0xB4, 0x1B, 0x9C, 0x82, 0xB5, 0x6E, 0x42, 0xAF };
  2442. byte[] expected = { 0xC5, 0x56, 0x04, 0x85, 0x0A, 0x52, 0x8B, 0x02, 0x69, 0xB6, 0xCF, 0xC7, 0xA9, 0x35, 0x63, 0xF7, 0x4B, 0x48, 0xF3, 0xD0, 0xFF, 0x74, 0xA7, 0xB5 };
  2443. SymmetricAlgorithm algo = RC2.Create ();
  2444. algo.Mode = CipherMode.CFB;
  2445. algo.Padding = PaddingMode.PKCS7;
  2446. algo.BlockSize = 64;
  2447. algo.FeedbackSize = 8;
  2448. int blockLength = (algo.BlockSize >> 3);
  2449. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2450. byte[] output = new byte [blockLength * 3];
  2451. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2452. Encrypt (encryptor, input, output);
  2453. AssertEquals ("RC2_k104b64_CFB8_PKCS7 Encrypt", expected, output);
  2454. byte[] reverse = new byte [blockLength * 3];
  2455. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2456. Decrypt (decryptor, output, reverse);
  2457. byte[] original = new byte [input.Length];
  2458. Array.Copy (reverse, 0, original, 0, original.Length);
  2459. AssertEquals ("RC2_k104b64_CFB8_PKCS7 Decrypt", input, original);
  2460. }
  2461. /* Invalid parameters RC2_k104b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  2462. /* Invalid parameters RC2_k104b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  2463. /* Invalid parameters RC2_k104b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  2464. [Test]
  2465. public void TestRC2_k112b64_ECB_None ()
  2466. {
  2467. byte[] key = { 0xB7, 0x95, 0xA4, 0x42, 0x21, 0x3D, 0x30, 0x51, 0x98, 0x01, 0xA0, 0x6C, 0x45, 0x68 };
  2468. // not used for ECB but make the code more uniform
  2469. byte[] iv = { 0x3B, 0x36, 0x51, 0x24, 0xF4, 0x1A, 0xC1, 0x91 };
  2470. byte[] expected = { 0x31, 0xAE, 0xBA, 0xFB, 0xB4, 0xFA, 0x78, 0x30, 0x31, 0xAE, 0xBA, 0xFB, 0xB4, 0xFA, 0x78, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2471. SymmetricAlgorithm algo = RC2.Create ();
  2472. algo.Mode = CipherMode.ECB;
  2473. algo.Padding = PaddingMode.None;
  2474. algo.BlockSize = 64;
  2475. int blockLength = (algo.BlockSize >> 3);
  2476. byte[] input = new byte [blockLength * 2];
  2477. byte[] output = new byte [blockLength * 3];
  2478. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2479. Encrypt (encryptor, input, output);
  2480. AssertEquals ("RC2_k112b64_ECB_None Encrypt", expected, output);
  2481. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2482. byte[] block1 = new byte[blockLength];
  2483. Array.Copy (output, 0, block1, 0, blockLength);
  2484. byte[] block2 = new byte[blockLength];
  2485. Array.Copy (output, blockLength, block2, 0, blockLength);
  2486. AssertEquals ("RC2_k112b64_ECB_None b1==b2", block1, block2);
  2487. byte[] reverse = new byte [blockLength * 3];
  2488. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2489. Decrypt (decryptor, output, reverse);
  2490. byte[] original = new byte [input.Length];
  2491. Array.Copy (reverse, 0, original, 0, original.Length);
  2492. AssertEquals ("RC2_k112b64_ECB_None Decrypt", input, original);
  2493. }
  2494. [Test]
  2495. public void TestRC2_k112b64_ECB_Zeros ()
  2496. {
  2497. byte[] key = { 0xB1, 0x8E, 0x09, 0xFB, 0x70, 0x03, 0x6A, 0xF2, 0xCF, 0x9D, 0x9B, 0xD7, 0x10, 0xD4 };
  2498. // not used for ECB but make the code more uniform
  2499. byte[] iv = { 0x64, 0x15, 0x78, 0xB8, 0x25, 0x15, 0xFA, 0xC8 };
  2500. byte[] expected = { 0xB1, 0xC2, 0x27, 0xA8, 0x32, 0xBA, 0x34, 0x06, 0xB1, 0xC2, 0x27, 0xA8, 0x32, 0xBA, 0x34, 0x06, 0xB1, 0xC2, 0x27, 0xA8, 0x32, 0xBA, 0x34, 0x06 };
  2501. SymmetricAlgorithm algo = RC2.Create ();
  2502. algo.Mode = CipherMode.ECB;
  2503. algo.Padding = PaddingMode.Zeros;
  2504. algo.BlockSize = 64;
  2505. int blockLength = (algo.BlockSize >> 3);
  2506. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2507. byte[] output = new byte [blockLength * 3];
  2508. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2509. Encrypt (encryptor, input, output);
  2510. AssertEquals ("RC2_k112b64_ECB_Zeros Encrypt", expected, output);
  2511. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2512. byte[] block1 = new byte[blockLength];
  2513. Array.Copy (output, 0, block1, 0, blockLength);
  2514. byte[] block2 = new byte[blockLength];
  2515. Array.Copy (output, blockLength, block2, 0, blockLength);
  2516. AssertEquals ("RC2_k112b64_ECB_Zeros b1==b2", block1, block2);
  2517. // also if padding is Zeros then all three blocks should be equals
  2518. byte[] block3 = new byte[blockLength];
  2519. Array.Copy (output, blockLength, block3, 0, blockLength);
  2520. AssertEquals ("RC2_k112b64_ECB_Zeros b1==b3", block1, block3);
  2521. byte[] reverse = new byte [blockLength * 3];
  2522. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2523. Decrypt (decryptor, output, reverse);
  2524. byte[] original = new byte [input.Length];
  2525. Array.Copy (reverse, 0, original, 0, original.Length);
  2526. AssertEquals ("RC2_k112b64_ECB_Zeros Decrypt", input, original);
  2527. }
  2528. [Test]
  2529. public void TestRC2_k112b64_ECB_PKCS7 ()
  2530. {
  2531. byte[] key = { 0x4F, 0xE8, 0x2C, 0x62, 0x98, 0x89, 0xEF, 0x11, 0x29, 0xB2, 0xDD, 0x4D, 0xE1, 0x39 };
  2532. // not used for ECB but make the code more uniform
  2533. byte[] iv = { 0x15, 0xE0, 0x95, 0x29, 0xEB, 0xE5, 0xC7, 0x8E };
  2534. byte[] expected = { 0x43, 0x79, 0x6E, 0xCF, 0x63, 0x68, 0xF0, 0x55, 0x43, 0x79, 0x6E, 0xCF, 0x63, 0x68, 0xF0, 0x55, 0x80, 0x64, 0x15, 0x36, 0x08, 0xD0, 0x76, 0x58 };
  2535. SymmetricAlgorithm algo = RC2.Create ();
  2536. algo.Mode = CipherMode.ECB;
  2537. algo.Padding = PaddingMode.PKCS7;
  2538. algo.BlockSize = 64;
  2539. int blockLength = (algo.BlockSize >> 3);
  2540. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2541. byte[] output = new byte [blockLength * 3];
  2542. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2543. Encrypt (encryptor, input, output);
  2544. AssertEquals ("RC2_k112b64_ECB_PKCS7 Encrypt", expected, output);
  2545. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2546. byte[] block1 = new byte[blockLength];
  2547. Array.Copy (output, 0, block1, 0, blockLength);
  2548. byte[] block2 = new byte[blockLength];
  2549. Array.Copy (output, blockLength, block2, 0, blockLength);
  2550. AssertEquals ("RC2_k112b64_ECB_PKCS7 b1==b2", block1, block2);
  2551. byte[] reverse = new byte [blockLength * 3];
  2552. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2553. Decrypt (decryptor, output, reverse);
  2554. byte[] original = new byte [input.Length];
  2555. Array.Copy (reverse, 0, original, 0, original.Length);
  2556. AssertEquals ("RC2_k112b64_ECB_PKCS7 Decrypt", input, original);
  2557. }
  2558. [Test]
  2559. public void TestRC2_k112b64_CBC_None ()
  2560. {
  2561. byte[] key = { 0xC0, 0x04, 0xA9, 0x3C, 0x94, 0xA1, 0x78, 0xA2, 0x4B, 0x94, 0x6F, 0x19, 0xD1, 0xE1 };
  2562. byte[] iv = { 0x28, 0x94, 0x16, 0x28, 0x69, 0x64, 0xF6, 0x83 };
  2563. byte[] expected = { 0xB7, 0x2F, 0x20, 0x02, 0xAD, 0x97, 0x21, 0x45, 0xDA, 0xC2, 0x0D, 0xD9, 0xEB, 0xCC, 0xA0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2564. SymmetricAlgorithm algo = RC2.Create ();
  2565. algo.Mode = CipherMode.CBC;
  2566. algo.Padding = PaddingMode.None;
  2567. algo.BlockSize = 64;
  2568. int blockLength = (algo.BlockSize >> 3);
  2569. byte[] input = new byte [blockLength * 2];
  2570. byte[] output = new byte [blockLength * 3];
  2571. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2572. Encrypt (encryptor, input, output);
  2573. AssertEquals ("RC2_k112b64_CBC_None Encrypt", expected, output);
  2574. byte[] reverse = new byte [blockLength * 3];
  2575. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2576. Decrypt (decryptor, output, reverse);
  2577. byte[] original = new byte [input.Length];
  2578. Array.Copy (reverse, 0, original, 0, original.Length);
  2579. AssertEquals ("RC2_k112b64_CBC_None Decrypt", input, original);
  2580. }
  2581. [Test]
  2582. public void TestRC2_k112b64_CBC_Zeros ()
  2583. {
  2584. byte[] key = { 0x59, 0xFF, 0xC2, 0xB5, 0x62, 0x84, 0x27, 0x49, 0x4B, 0xFF, 0xFF, 0xCE, 0xBB, 0xBD };
  2585. byte[] iv = { 0x2E, 0x9E, 0xD3, 0xF6, 0xFC, 0xD7, 0xC6, 0x1C };
  2586. byte[] expected = { 0x38, 0xE4, 0x4D, 0xD5, 0x3F, 0x74, 0x44, 0x90, 0x11, 0xCD, 0x6E, 0x13, 0x7A, 0x9A, 0x82, 0xBB, 0xBD, 0xD1, 0x0F, 0x38, 0x0F, 0x5F, 0x97, 0x14 };
  2587. SymmetricAlgorithm algo = RC2.Create ();
  2588. algo.Mode = CipherMode.CBC;
  2589. algo.Padding = PaddingMode.Zeros;
  2590. algo.BlockSize = 64;
  2591. int blockLength = (algo.BlockSize >> 3);
  2592. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2593. byte[] output = new byte [blockLength * 3];
  2594. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2595. Encrypt (encryptor, input, output);
  2596. AssertEquals ("RC2_k112b64_CBC_Zeros Encrypt", expected, output);
  2597. byte[] reverse = new byte [blockLength * 3];
  2598. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2599. Decrypt (decryptor, output, reverse);
  2600. byte[] original = new byte [input.Length];
  2601. Array.Copy (reverse, 0, original, 0, original.Length);
  2602. AssertEquals ("RC2_k112b64_CBC_Zeros Decrypt", input, original);
  2603. }
  2604. [Test]
  2605. public void TestRC2_k112b64_CBC_PKCS7 ()
  2606. {
  2607. byte[] key = { 0xE4, 0x49, 0xA4, 0xBE, 0x30, 0xE1, 0xB5, 0x21, 0x33, 0xC6, 0x37, 0x88, 0x30, 0xEC };
  2608. byte[] iv = { 0x74, 0xAC, 0x28, 0x92, 0xA5, 0xF1, 0x31, 0xC9 };
  2609. byte[] expected = { 0xE5, 0x7B, 0x53, 0x65, 0x37, 0xD8, 0x29, 0xBD, 0x4B, 0x73, 0x3B, 0x1B, 0x5B, 0x00, 0x04, 0xE2, 0x11, 0x5B, 0x24, 0x6F, 0x6D, 0x7F, 0x1C, 0xE8 };
  2610. SymmetricAlgorithm algo = RC2.Create ();
  2611. algo.Mode = CipherMode.CBC;
  2612. algo.Padding = PaddingMode.PKCS7;
  2613. algo.BlockSize = 64;
  2614. int blockLength = (algo.BlockSize >> 3);
  2615. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2616. byte[] output = new byte [blockLength * 3];
  2617. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2618. Encrypt (encryptor, input, output);
  2619. AssertEquals ("RC2_k112b64_CBC_PKCS7 Encrypt", expected, output);
  2620. byte[] reverse = new byte [blockLength * 3];
  2621. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2622. Decrypt (decryptor, output, reverse);
  2623. byte[] original = new byte [input.Length];
  2624. Array.Copy (reverse, 0, original, 0, original.Length);
  2625. AssertEquals ("RC2_k112b64_CBC_PKCS7 Decrypt", input, original);
  2626. }
  2627. /* Invalid parameters RC2_k112b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  2628. /* Invalid parameters RC2_k112b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  2629. /* Invalid parameters RC2_k112b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  2630. [Test]
  2631. public void TestRC2_k112b64_CFB8_None ()
  2632. {
  2633. byte[] key = { 0x70, 0x12, 0xEC, 0xAB, 0x6E, 0x1D, 0xEF, 0x51, 0xEE, 0xA8, 0x81, 0xE1, 0x21, 0xFF };
  2634. byte[] iv = { 0x0E, 0x56, 0xA2, 0xA3, 0x8C, 0x5D, 0x9C, 0x1F };
  2635. byte[] expected = { 0x71, 0x1C, 0x76, 0xB1, 0x61, 0x32, 0x77, 0xB7, 0x98, 0x42, 0x31, 0xF1, 0x0A, 0xE4, 0xC3, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2636. SymmetricAlgorithm algo = RC2.Create ();
  2637. algo.Mode = CipherMode.CFB;
  2638. algo.Padding = PaddingMode.None;
  2639. algo.BlockSize = 64;
  2640. algo.FeedbackSize = 8;
  2641. int blockLength = (algo.BlockSize >> 3);
  2642. byte[] input = new byte [blockLength * 2];
  2643. byte[] output = new byte [blockLength * 3];
  2644. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2645. Encrypt (encryptor, input, output);
  2646. AssertEquals ("RC2_k112b64_CFB8_None Encrypt", expected, output);
  2647. byte[] reverse = new byte [blockLength * 3];
  2648. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2649. Decrypt (decryptor, output, reverse);
  2650. byte[] original = new byte [input.Length];
  2651. Array.Copy (reverse, 0, original, 0, original.Length);
  2652. AssertEquals ("RC2_k112b64_CFB8_None Decrypt", input, original);
  2653. }
  2654. [Test]
  2655. public void TestRC2_k112b64_CFB8_Zeros ()
  2656. {
  2657. byte[] key = { 0x48, 0x66, 0x16, 0xD6, 0x57, 0xBF, 0x38, 0xB7, 0x22, 0x81, 0x9F, 0x75, 0xE0, 0x88 };
  2658. byte[] iv = { 0x51, 0x2C, 0x6A, 0x59, 0xAB, 0xD2, 0xAE, 0x6E };
  2659. byte[] expected = { 0xF1, 0x9E, 0x85, 0x7A, 0x7D, 0xF0, 0x39, 0x0D, 0x11, 0x47, 0x11, 0xC0, 0x1A, 0x19, 0x21, 0x85, 0x95, 0x40, 0xDA, 0x4A, 0xEE, 0x49, 0xC7, 0x54 };
  2660. SymmetricAlgorithm algo = RC2.Create ();
  2661. algo.Mode = CipherMode.CFB;
  2662. algo.Padding = PaddingMode.Zeros;
  2663. algo.BlockSize = 64;
  2664. algo.FeedbackSize = 8;
  2665. int blockLength = (algo.BlockSize >> 3);
  2666. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2667. byte[] output = new byte [blockLength * 3];
  2668. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2669. Encrypt (encryptor, input, output);
  2670. AssertEquals ("RC2_k112b64_CFB8_Zeros Encrypt", expected, output);
  2671. byte[] reverse = new byte [blockLength * 3];
  2672. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2673. Decrypt (decryptor, output, reverse);
  2674. byte[] original = new byte [input.Length];
  2675. Array.Copy (reverse, 0, original, 0, original.Length);
  2676. AssertEquals ("RC2_k112b64_CFB8_Zeros Decrypt", input, original);
  2677. }
  2678. [Test]
  2679. public void TestRC2_k112b64_CFB8_PKCS7 ()
  2680. {
  2681. byte[] key = { 0x55, 0x20, 0xA1, 0xD8, 0xFA, 0xE7, 0x0D, 0xF9, 0xB6, 0x4B, 0x90, 0x10, 0xDE, 0xB1 };
  2682. byte[] iv = { 0x26, 0x6C, 0xB0, 0xB4, 0x4D, 0x7F, 0x5C, 0x18 };
  2683. byte[] expected = { 0xC8, 0x00, 0x9F, 0x21, 0x2C, 0xB0, 0x75, 0x6C, 0x62, 0xD8, 0xD0, 0x30, 0x11, 0x93, 0x73, 0x2F, 0xC5, 0xBC, 0xB1, 0xED, 0x2E, 0xBE, 0xCF, 0xBC };
  2684. SymmetricAlgorithm algo = RC2.Create ();
  2685. algo.Mode = CipherMode.CFB;
  2686. algo.Padding = PaddingMode.PKCS7;
  2687. algo.BlockSize = 64;
  2688. algo.FeedbackSize = 8;
  2689. int blockLength = (algo.BlockSize >> 3);
  2690. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2691. byte[] output = new byte [blockLength * 3];
  2692. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2693. Encrypt (encryptor, input, output);
  2694. AssertEquals ("RC2_k112b64_CFB8_PKCS7 Encrypt", expected, output);
  2695. byte[] reverse = new byte [blockLength * 3];
  2696. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2697. Decrypt (decryptor, output, reverse);
  2698. byte[] original = new byte [input.Length];
  2699. Array.Copy (reverse, 0, original, 0, original.Length);
  2700. AssertEquals ("RC2_k112b64_CFB8_PKCS7 Decrypt", input, original);
  2701. }
  2702. /* Invalid parameters RC2_k112b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  2703. /* Invalid parameters RC2_k112b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  2704. /* Invalid parameters RC2_k112b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  2705. [Test]
  2706. public void TestRC2_k120b64_ECB_None ()
  2707. {
  2708. byte[] key = { 0x5D, 0x08, 0xC7, 0xB8, 0xB1, 0xEB, 0x89, 0x1C, 0xC0, 0x3F, 0xE6, 0x2F, 0xC4, 0x79, 0x11 };
  2709. // not used for ECB but make the code more uniform
  2710. byte[] iv = { 0x76, 0x1C, 0xAC, 0x0F, 0x39, 0x6C, 0x1A, 0x44 };
  2711. byte[] expected = { 0xA4, 0xC1, 0x60, 0x59, 0x6B, 0x45, 0xE0, 0x4C, 0xA4, 0xC1, 0x60, 0x59, 0x6B, 0x45, 0xE0, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2712. SymmetricAlgorithm algo = RC2.Create ();
  2713. algo.Mode = CipherMode.ECB;
  2714. algo.Padding = PaddingMode.None;
  2715. algo.BlockSize = 64;
  2716. int blockLength = (algo.BlockSize >> 3);
  2717. byte[] input = new byte [blockLength * 2];
  2718. byte[] output = new byte [blockLength * 3];
  2719. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2720. Encrypt (encryptor, input, output);
  2721. AssertEquals ("RC2_k120b64_ECB_None Encrypt", expected, output);
  2722. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2723. byte[] block1 = new byte[blockLength];
  2724. Array.Copy (output, 0, block1, 0, blockLength);
  2725. byte[] block2 = new byte[blockLength];
  2726. Array.Copy (output, blockLength, block2, 0, blockLength);
  2727. AssertEquals ("RC2_k120b64_ECB_None b1==b2", block1, block2);
  2728. byte[] reverse = new byte [blockLength * 3];
  2729. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2730. Decrypt (decryptor, output, reverse);
  2731. byte[] original = new byte [input.Length];
  2732. Array.Copy (reverse, 0, original, 0, original.Length);
  2733. AssertEquals ("RC2_k120b64_ECB_None Decrypt", input, original);
  2734. }
  2735. [Test]
  2736. public void TestRC2_k120b64_ECB_Zeros ()
  2737. {
  2738. byte[] key = { 0x1D, 0x13, 0x51, 0x02, 0x28, 0xF4, 0xF0, 0x13, 0x90, 0xFD, 0xE4, 0xC0, 0xE5, 0x57, 0x9A };
  2739. // not used for ECB but make the code more uniform
  2740. byte[] iv = { 0x9E, 0xC9, 0xA7, 0x52, 0xD2, 0x6E, 0x9B, 0xE4 };
  2741. byte[] expected = { 0x23, 0x58, 0x1C, 0x66, 0x7D, 0x2F, 0x71, 0x4F, 0x23, 0x58, 0x1C, 0x66, 0x7D, 0x2F, 0x71, 0x4F, 0x23, 0x58, 0x1C, 0x66, 0x7D, 0x2F, 0x71, 0x4F };
  2742. SymmetricAlgorithm algo = RC2.Create ();
  2743. algo.Mode = CipherMode.ECB;
  2744. algo.Padding = PaddingMode.Zeros;
  2745. algo.BlockSize = 64;
  2746. int blockLength = (algo.BlockSize >> 3);
  2747. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2748. byte[] output = new byte [blockLength * 3];
  2749. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2750. Encrypt (encryptor, input, output);
  2751. AssertEquals ("RC2_k120b64_ECB_Zeros Encrypt", expected, output);
  2752. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2753. byte[] block1 = new byte[blockLength];
  2754. Array.Copy (output, 0, block1, 0, blockLength);
  2755. byte[] block2 = new byte[blockLength];
  2756. Array.Copy (output, blockLength, block2, 0, blockLength);
  2757. AssertEquals ("RC2_k120b64_ECB_Zeros b1==b2", block1, block2);
  2758. // also if padding is Zeros then all three blocks should be equals
  2759. byte[] block3 = new byte[blockLength];
  2760. Array.Copy (output, blockLength, block3, 0, blockLength);
  2761. AssertEquals ("RC2_k120b64_ECB_Zeros b1==b3", block1, block3);
  2762. byte[] reverse = new byte [blockLength * 3];
  2763. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2764. Decrypt (decryptor, output, reverse);
  2765. byte[] original = new byte [input.Length];
  2766. Array.Copy (reverse, 0, original, 0, original.Length);
  2767. AssertEquals ("RC2_k120b64_ECB_Zeros Decrypt", input, original);
  2768. }
  2769. [Test]
  2770. public void TestRC2_k120b64_ECB_PKCS7 ()
  2771. {
  2772. byte[] key = { 0x23, 0xF2, 0xFB, 0x09, 0xC1, 0xEF, 0xC1, 0xFF, 0x16, 0xFF, 0x60, 0xC1, 0x3A, 0x94, 0x3E };
  2773. // not used for ECB but make the code more uniform
  2774. byte[] iv = { 0xB6, 0x10, 0xE3, 0xE9, 0x24, 0x03, 0xCA, 0xAA };
  2775. byte[] expected = { 0x92, 0xF3, 0xF0, 0x81, 0x13, 0x40, 0x19, 0x61, 0x92, 0xF3, 0xF0, 0x81, 0x13, 0x40, 0x19, 0x61, 0x36, 0xCC, 0xEC, 0x80, 0xF6, 0xF4, 0xCC, 0xB7 };
  2776. SymmetricAlgorithm algo = RC2.Create ();
  2777. algo.Mode = CipherMode.ECB;
  2778. algo.Padding = PaddingMode.PKCS7;
  2779. algo.BlockSize = 64;
  2780. int blockLength = (algo.BlockSize >> 3);
  2781. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2782. byte[] output = new byte [blockLength * 3];
  2783. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2784. Encrypt (encryptor, input, output);
  2785. AssertEquals ("RC2_k120b64_ECB_PKCS7 Encrypt", expected, output);
  2786. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2787. byte[] block1 = new byte[blockLength];
  2788. Array.Copy (output, 0, block1, 0, blockLength);
  2789. byte[] block2 = new byte[blockLength];
  2790. Array.Copy (output, blockLength, block2, 0, blockLength);
  2791. AssertEquals ("RC2_k120b64_ECB_PKCS7 b1==b2", block1, block2);
  2792. byte[] reverse = new byte [blockLength * 3];
  2793. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2794. Decrypt (decryptor, output, reverse);
  2795. byte[] original = new byte [input.Length];
  2796. Array.Copy (reverse, 0, original, 0, original.Length);
  2797. AssertEquals ("RC2_k120b64_ECB_PKCS7 Decrypt", input, original);
  2798. }
  2799. [Test]
  2800. public void TestRC2_k120b64_CBC_None ()
  2801. {
  2802. byte[] key = { 0x12, 0x43, 0xEE, 0x74, 0xE8, 0x4E, 0x3A, 0xF7, 0x24, 0x58, 0x10, 0xC9, 0x41, 0x7E, 0x46 };
  2803. byte[] iv = { 0x7B, 0x57, 0x22, 0x19, 0xFB, 0x30, 0xED, 0x48 };
  2804. byte[] expected = { 0x75, 0xB0, 0x41, 0x19, 0x7F, 0x80, 0x91, 0x4A, 0xCD, 0x03, 0x41, 0x59, 0xE4, 0xC0, 0x92, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2805. SymmetricAlgorithm algo = RC2.Create ();
  2806. algo.Mode = CipherMode.CBC;
  2807. algo.Padding = PaddingMode.None;
  2808. algo.BlockSize = 64;
  2809. int blockLength = (algo.BlockSize >> 3);
  2810. byte[] input = new byte [blockLength * 2];
  2811. byte[] output = new byte [blockLength * 3];
  2812. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2813. Encrypt (encryptor, input, output);
  2814. AssertEquals ("RC2_k120b64_CBC_None Encrypt", expected, output);
  2815. byte[] reverse = new byte [blockLength * 3];
  2816. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2817. Decrypt (decryptor, output, reverse);
  2818. byte[] original = new byte [input.Length];
  2819. Array.Copy (reverse, 0, original, 0, original.Length);
  2820. AssertEquals ("RC2_k120b64_CBC_None Decrypt", input, original);
  2821. }
  2822. [Test]
  2823. public void TestRC2_k120b64_CBC_Zeros ()
  2824. {
  2825. byte[] key = { 0x2A, 0xCC, 0xFF, 0xD0, 0x46, 0xAF, 0x74, 0xB2, 0x0E, 0x64, 0xBD, 0xE9, 0x6D, 0xC5, 0xE8 };
  2826. byte[] iv = { 0x10, 0x21, 0xE3, 0xCB, 0x46, 0x02, 0x33, 0x4F };
  2827. byte[] expected = { 0x88, 0x71, 0x0D, 0x01, 0xE9, 0xD3, 0xC7, 0x3F, 0x7E, 0xCA, 0xA7, 0x9A, 0x2D, 0x95, 0xC6, 0xED, 0xDA, 0xAA, 0xE9, 0x23, 0x01, 0x70, 0x6E, 0x59 };
  2828. SymmetricAlgorithm algo = RC2.Create ();
  2829. algo.Mode = CipherMode.CBC;
  2830. algo.Padding = PaddingMode.Zeros;
  2831. algo.BlockSize = 64;
  2832. int blockLength = (algo.BlockSize >> 3);
  2833. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2834. byte[] output = new byte [blockLength * 3];
  2835. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2836. Encrypt (encryptor, input, output);
  2837. AssertEquals ("RC2_k120b64_CBC_Zeros Encrypt", expected, output);
  2838. byte[] reverse = new byte [blockLength * 3];
  2839. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2840. Decrypt (decryptor, output, reverse);
  2841. byte[] original = new byte [input.Length];
  2842. Array.Copy (reverse, 0, original, 0, original.Length);
  2843. AssertEquals ("RC2_k120b64_CBC_Zeros Decrypt", input, original);
  2844. }
  2845. [Test]
  2846. public void TestRC2_k120b64_CBC_PKCS7 ()
  2847. {
  2848. byte[] key = { 0xE8, 0xE8, 0x44, 0x9D, 0xEA, 0x33, 0x10, 0xCB, 0xEA, 0xEF, 0x69, 0x94, 0xE4, 0x31, 0xF0 };
  2849. byte[] iv = { 0xC7, 0x0F, 0xE1, 0x79, 0x2B, 0x57, 0x5D, 0xA7 };
  2850. byte[] expected = { 0x7E, 0x1F, 0xD6, 0xCF, 0xB1, 0xAE, 0xC0, 0x2C, 0xD6, 0x02, 0x01, 0x62, 0x77, 0x95, 0x02, 0xE8, 0x8D, 0xEC, 0x8D, 0xCC, 0xB2, 0x6B, 0x92, 0x7A };
  2851. SymmetricAlgorithm algo = RC2.Create ();
  2852. algo.Mode = CipherMode.CBC;
  2853. algo.Padding = PaddingMode.PKCS7;
  2854. algo.BlockSize = 64;
  2855. int blockLength = (algo.BlockSize >> 3);
  2856. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2857. byte[] output = new byte [blockLength * 3];
  2858. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2859. Encrypt (encryptor, input, output);
  2860. AssertEquals ("RC2_k120b64_CBC_PKCS7 Encrypt", expected, output);
  2861. byte[] reverse = new byte [blockLength * 3];
  2862. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2863. Decrypt (decryptor, output, reverse);
  2864. byte[] original = new byte [input.Length];
  2865. Array.Copy (reverse, 0, original, 0, original.Length);
  2866. AssertEquals ("RC2_k120b64_CBC_PKCS7 Decrypt", input, original);
  2867. }
  2868. /* Invalid parameters RC2_k120b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  2869. /* Invalid parameters RC2_k120b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  2870. /* Invalid parameters RC2_k120b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  2871. [Test]
  2872. public void TestRC2_k120b64_CFB8_None ()
  2873. {
  2874. byte[] key = { 0x0F, 0x0D, 0x1F, 0x09, 0xC2, 0xEA, 0xC5, 0xFE, 0xD1, 0x5A, 0x4C, 0x39, 0x2E, 0x62, 0xED };
  2875. byte[] iv = { 0xCA, 0x90, 0x74, 0xAD, 0x6B, 0xD5, 0x42, 0xCF };
  2876. byte[] expected = { 0xEB, 0xC3, 0xF4, 0x08, 0xCF, 0x11, 0x3E, 0xC4, 0x98, 0x8A, 0xAB, 0x6F, 0xEE, 0x32, 0xFC, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2877. SymmetricAlgorithm algo = RC2.Create ();
  2878. algo.Mode = CipherMode.CFB;
  2879. algo.Padding = PaddingMode.None;
  2880. algo.BlockSize = 64;
  2881. algo.FeedbackSize = 8;
  2882. int blockLength = (algo.BlockSize >> 3);
  2883. byte[] input = new byte [blockLength * 2];
  2884. byte[] output = new byte [blockLength * 3];
  2885. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2886. Encrypt (encryptor, input, output);
  2887. AssertEquals ("RC2_k120b64_CFB8_None Encrypt", expected, output);
  2888. byte[] reverse = new byte [blockLength * 3];
  2889. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2890. Decrypt (decryptor, output, reverse);
  2891. byte[] original = new byte [input.Length];
  2892. Array.Copy (reverse, 0, original, 0, original.Length);
  2893. AssertEquals ("RC2_k120b64_CFB8_None Decrypt", input, original);
  2894. }
  2895. [Test]
  2896. public void TestRC2_k120b64_CFB8_Zeros ()
  2897. {
  2898. byte[] key = { 0xDA, 0xAD, 0xD7, 0xFB, 0x36, 0x64, 0x3B, 0xE8, 0x35, 0x64, 0xC8, 0xAF, 0x0D, 0xB3, 0xAC };
  2899. byte[] iv = { 0x6B, 0x99, 0x8D, 0xCA, 0x51, 0xD8, 0x26, 0x48 };
  2900. byte[] expected = { 0xDE, 0xED, 0xF4, 0xA8, 0x9D, 0x5C, 0xCE, 0x22, 0x7A, 0xD5, 0x1B, 0x3F, 0x89, 0x6E, 0x91, 0x61, 0xE1, 0x44, 0x1E, 0x5C, 0xFA, 0xC1, 0x40, 0x97 };
  2901. SymmetricAlgorithm algo = RC2.Create ();
  2902. algo.Mode = CipherMode.CFB;
  2903. algo.Padding = PaddingMode.Zeros;
  2904. algo.BlockSize = 64;
  2905. algo.FeedbackSize = 8;
  2906. int blockLength = (algo.BlockSize >> 3);
  2907. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2908. byte[] output = new byte [blockLength * 3];
  2909. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2910. Encrypt (encryptor, input, output);
  2911. AssertEquals ("RC2_k120b64_CFB8_Zeros Encrypt", expected, output);
  2912. byte[] reverse = new byte [blockLength * 3];
  2913. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2914. Decrypt (decryptor, output, reverse);
  2915. byte[] original = new byte [input.Length];
  2916. Array.Copy (reverse, 0, original, 0, original.Length);
  2917. AssertEquals ("RC2_k120b64_CFB8_Zeros Decrypt", input, original);
  2918. }
  2919. [Test]
  2920. public void TestRC2_k120b64_CFB8_PKCS7 ()
  2921. {
  2922. byte[] key = { 0x26, 0xA9, 0xE5, 0xE2, 0xE4, 0x48, 0xB5, 0x9F, 0xAC, 0x3E, 0x77, 0xB0, 0xEF, 0x1B, 0x00 };
  2923. byte[] iv = { 0x0E, 0x98, 0x7F, 0xC4, 0xAC, 0x08, 0x94, 0x03 };
  2924. byte[] expected = { 0xAD, 0xEC, 0xD6, 0x71, 0xDF, 0x36, 0x69, 0x80, 0xE6, 0x74, 0x79, 0xC2, 0xE0, 0xDF, 0xCF, 0xD8, 0xB4, 0x3A, 0x22, 0x6F, 0x41, 0xAD, 0x77, 0x4D };
  2925. SymmetricAlgorithm algo = RC2.Create ();
  2926. algo.Mode = CipherMode.CFB;
  2927. algo.Padding = PaddingMode.PKCS7;
  2928. algo.BlockSize = 64;
  2929. algo.FeedbackSize = 8;
  2930. int blockLength = (algo.BlockSize >> 3);
  2931. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2932. byte[] output = new byte [blockLength * 3];
  2933. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2934. Encrypt (encryptor, input, output);
  2935. AssertEquals ("RC2_k120b64_CFB8_PKCS7 Encrypt", expected, output);
  2936. byte[] reverse = new byte [blockLength * 3];
  2937. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2938. Decrypt (decryptor, output, reverse);
  2939. byte[] original = new byte [input.Length];
  2940. Array.Copy (reverse, 0, original, 0, original.Length);
  2941. AssertEquals ("RC2_k120b64_CFB8_PKCS7 Decrypt", input, original);
  2942. }
  2943. /* Invalid parameters RC2_k120b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  2944. /* Invalid parameters RC2_k120b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  2945. /* Invalid parameters RC2_k120b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  2946. [Test]
  2947. public void TestRC2_k128b64_ECB_None ()
  2948. {
  2949. byte[] key = { 0x4F, 0x02, 0xB1, 0xA6, 0x5E, 0xAE, 0xB9, 0x0C, 0x3A, 0x96, 0xFF, 0x62, 0x90, 0x9A, 0xD8, 0x1B };
  2950. // not used for ECB but make the code more uniform
  2951. byte[] iv = { 0xC7, 0x89, 0x19, 0x4F, 0x3C, 0xC3, 0x05, 0x83 };
  2952. byte[] expected = { 0xC8, 0x83, 0x4D, 0xE2, 0x6A, 0xFA, 0x75, 0x41, 0xC8, 0x83, 0x4D, 0xE2, 0x6A, 0xFA, 0x75, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  2953. SymmetricAlgorithm algo = RC2.Create ();
  2954. algo.Mode = CipherMode.ECB;
  2955. algo.Padding = PaddingMode.None;
  2956. algo.BlockSize = 64;
  2957. int blockLength = (algo.BlockSize >> 3);
  2958. byte[] input = new byte [blockLength * 2];
  2959. byte[] output = new byte [blockLength * 3];
  2960. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2961. Encrypt (encryptor, input, output);
  2962. AssertEquals ("RC2_k128b64_ECB_None Encrypt", expected, output);
  2963. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2964. byte[] block1 = new byte[blockLength];
  2965. Array.Copy (output, 0, block1, 0, blockLength);
  2966. byte[] block2 = new byte[blockLength];
  2967. Array.Copy (output, blockLength, block2, 0, blockLength);
  2968. AssertEquals ("RC2_k128b64_ECB_None b1==b2", block1, block2);
  2969. byte[] reverse = new byte [blockLength * 3];
  2970. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  2971. Decrypt (decryptor, output, reverse);
  2972. byte[] original = new byte [input.Length];
  2973. Array.Copy (reverse, 0, original, 0, original.Length);
  2974. AssertEquals ("RC2_k128b64_ECB_None Decrypt", input, original);
  2975. }
  2976. [Test]
  2977. public void TestRC2_k128b64_ECB_Zeros ()
  2978. {
  2979. byte[] key = { 0x45, 0xBE, 0xD8, 0x8E, 0x0A, 0xE7, 0xF9, 0xE2, 0x3C, 0x33, 0xE7, 0x93, 0xD4, 0x9D, 0xAE, 0x2B };
  2980. // not used for ECB but make the code more uniform
  2981. byte[] iv = { 0x83, 0x27, 0x57, 0x97, 0x06, 0x4F, 0xFE, 0xB3 };
  2982. byte[] expected = { 0x28, 0x59, 0x45, 0xF6, 0x5E, 0x4F, 0x97, 0xF3, 0x28, 0x59, 0x45, 0xF6, 0x5E, 0x4F, 0x97, 0xF3, 0x28, 0x59, 0x45, 0xF6, 0x5E, 0x4F, 0x97, 0xF3 };
  2983. SymmetricAlgorithm algo = RC2.Create ();
  2984. algo.Mode = CipherMode.ECB;
  2985. algo.Padding = PaddingMode.Zeros;
  2986. algo.BlockSize = 64;
  2987. int blockLength = (algo.BlockSize >> 3);
  2988. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  2989. byte[] output = new byte [blockLength * 3];
  2990. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  2991. Encrypt (encryptor, input, output);
  2992. AssertEquals ("RC2_k128b64_ECB_Zeros Encrypt", expected, output);
  2993. // in ECB the first 2 blocks should be equals (as the IV is not used)
  2994. byte[] block1 = new byte[blockLength];
  2995. Array.Copy (output, 0, block1, 0, blockLength);
  2996. byte[] block2 = new byte[blockLength];
  2997. Array.Copy (output, blockLength, block2, 0, blockLength);
  2998. AssertEquals ("RC2_k128b64_ECB_Zeros b1==b2", block1, block2);
  2999. // also if padding is Zeros then all three blocks should be equals
  3000. byte[] block3 = new byte[blockLength];
  3001. Array.Copy (output, blockLength, block3, 0, blockLength);
  3002. AssertEquals ("RC2_k128b64_ECB_Zeros b1==b3", block1, block3);
  3003. byte[] reverse = new byte [blockLength * 3];
  3004. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3005. Decrypt (decryptor, output, reverse);
  3006. byte[] original = new byte [input.Length];
  3007. Array.Copy (reverse, 0, original, 0, original.Length);
  3008. AssertEquals ("RC2_k128b64_ECB_Zeros Decrypt", input, original);
  3009. }
  3010. [Test]
  3011. public void TestRC2_k128b64_ECB_PKCS7 ()
  3012. {
  3013. byte[] key = { 0x6F, 0x04, 0x76, 0x7D, 0x88, 0x01, 0x29, 0x6A, 0xD5, 0x1E, 0x38, 0x9D, 0xED, 0x56, 0xAC, 0x9C };
  3014. // not used for ECB but make the code more uniform
  3015. byte[] iv = { 0x82, 0x74, 0xAC, 0xAA, 0x42, 0x29, 0x35, 0x8D };
  3016. byte[] expected = { 0xCB, 0xE5, 0xBB, 0xCC, 0x99, 0x8D, 0x1D, 0xA6, 0xCB, 0xE5, 0xBB, 0xCC, 0x99, 0x8D, 0x1D, 0xA6, 0x5B, 0x35, 0x28, 0xE7, 0xAC, 0xFE, 0xF0, 0xD1 };
  3017. SymmetricAlgorithm algo = RC2.Create ();
  3018. algo.Mode = CipherMode.ECB;
  3019. algo.Padding = PaddingMode.PKCS7;
  3020. algo.BlockSize = 64;
  3021. int blockLength = (algo.BlockSize >> 3);
  3022. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3023. byte[] output = new byte [blockLength * 3];
  3024. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3025. Encrypt (encryptor, input, output);
  3026. AssertEquals ("RC2_k128b64_ECB_PKCS7 Encrypt", expected, output);
  3027. // in ECB the first 2 blocks should be equals (as the IV is not used)
  3028. byte[] block1 = new byte[blockLength];
  3029. Array.Copy (output, 0, block1, 0, blockLength);
  3030. byte[] block2 = new byte[blockLength];
  3031. Array.Copy (output, blockLength, block2, 0, blockLength);
  3032. AssertEquals ("RC2_k128b64_ECB_PKCS7 b1==b2", block1, block2);
  3033. byte[] reverse = new byte [blockLength * 3];
  3034. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3035. Decrypt (decryptor, output, reverse);
  3036. byte[] original = new byte [input.Length];
  3037. Array.Copy (reverse, 0, original, 0, original.Length);
  3038. AssertEquals ("RC2_k128b64_ECB_PKCS7 Decrypt", input, original);
  3039. }
  3040. [Test]
  3041. public void TestRC2_k128b64_CBC_None ()
  3042. {
  3043. byte[] key = { 0x17, 0x3F, 0x40, 0xF3, 0xDC, 0xFF, 0x8F, 0xF2, 0x71, 0x2E, 0x8B, 0x6A, 0xE0, 0x2E, 0x3F, 0x82 };
  3044. byte[] iv = { 0xFA, 0xB4, 0x41, 0x91, 0x34, 0xFC, 0x9B, 0x49 };
  3045. byte[] expected = { 0x05, 0x1B, 0x27, 0x78, 0xF0, 0x3D, 0xC4, 0x77, 0x9E, 0x59, 0x27, 0xEC, 0x2D, 0x1D, 0x7F, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3046. SymmetricAlgorithm algo = RC2.Create ();
  3047. algo.Mode = CipherMode.CBC;
  3048. algo.Padding = PaddingMode.None;
  3049. algo.BlockSize = 64;
  3050. int blockLength = (algo.BlockSize >> 3);
  3051. byte[] input = new byte [blockLength * 2];
  3052. byte[] output = new byte [blockLength * 3];
  3053. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3054. Encrypt (encryptor, input, output);
  3055. AssertEquals ("RC2_k128b64_CBC_None Encrypt", expected, output);
  3056. byte[] reverse = new byte [blockLength * 3];
  3057. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3058. Decrypt (decryptor, output, reverse);
  3059. byte[] original = new byte [input.Length];
  3060. Array.Copy (reverse, 0, original, 0, original.Length);
  3061. AssertEquals ("RC2_k128b64_CBC_None Decrypt", input, original);
  3062. }
  3063. [Test]
  3064. public void TestRC2_k128b64_CBC_Zeros ()
  3065. {
  3066. byte[] key = { 0x49, 0x89, 0x3E, 0x29, 0xCB, 0xB9, 0x06, 0x85, 0x7F, 0x8B, 0x86, 0xEB, 0xD7, 0x47, 0x91, 0x1D };
  3067. byte[] iv = { 0xCB, 0xA1, 0x0F, 0x53, 0x7B, 0x71, 0x04, 0x89 };
  3068. byte[] expected = { 0x17, 0x58, 0xD1, 0xF4, 0x1E, 0x58, 0xB0, 0x10, 0x31, 0x17, 0x40, 0x3F, 0x40, 0x22, 0x75, 0x32, 0x4F, 0xDE, 0x64, 0xE0, 0x66, 0xF4, 0xF7, 0xA0 };
  3069. SymmetricAlgorithm algo = RC2.Create ();
  3070. algo.Mode = CipherMode.CBC;
  3071. algo.Padding = PaddingMode.Zeros;
  3072. algo.BlockSize = 64;
  3073. int blockLength = (algo.BlockSize >> 3);
  3074. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3075. byte[] output = new byte [blockLength * 3];
  3076. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3077. Encrypt (encryptor, input, output);
  3078. AssertEquals ("RC2_k128b64_CBC_Zeros Encrypt", expected, output);
  3079. byte[] reverse = new byte [blockLength * 3];
  3080. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3081. Decrypt (decryptor, output, reverse);
  3082. byte[] original = new byte [input.Length];
  3083. Array.Copy (reverse, 0, original, 0, original.Length);
  3084. AssertEquals ("RC2_k128b64_CBC_Zeros Decrypt", input, original);
  3085. }
  3086. [Test]
  3087. public void TestRC2_k128b64_CBC_PKCS7 ()
  3088. {
  3089. byte[] key = { 0x22, 0x04, 0xDB, 0x15, 0xD6, 0x2E, 0xEF, 0x6D, 0x5D, 0x6A, 0xDA, 0x55, 0x67, 0x41, 0x4E, 0xFD };
  3090. byte[] iv = { 0xB8, 0xD1, 0xD8, 0x23, 0x00, 0x39, 0x89, 0x83 };
  3091. byte[] expected = { 0xC8, 0x4F, 0xCC, 0x05, 0x7F, 0x44, 0x49, 0xBE, 0x73, 0x78, 0xE8, 0x7B, 0xD9, 0xB1, 0x56, 0xC3, 0x37, 0x1E, 0xBE, 0x4D, 0x2B, 0x2F, 0xC7, 0x9E };
  3092. SymmetricAlgorithm algo = RC2.Create ();
  3093. algo.Mode = CipherMode.CBC;
  3094. algo.Padding = PaddingMode.PKCS7;
  3095. algo.BlockSize = 64;
  3096. int blockLength = (algo.BlockSize >> 3);
  3097. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3098. byte[] output = new byte [blockLength * 3];
  3099. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3100. Encrypt (encryptor, input, output);
  3101. AssertEquals ("RC2_k128b64_CBC_PKCS7 Encrypt", expected, output);
  3102. byte[] reverse = new byte [blockLength * 3];
  3103. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3104. Decrypt (decryptor, output, reverse);
  3105. byte[] original = new byte [input.Length];
  3106. Array.Copy (reverse, 0, original, 0, original.Length);
  3107. AssertEquals ("RC2_k128b64_CBC_PKCS7 Decrypt", input, original);
  3108. }
  3109. /* Invalid parameters RC2_k128b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  3110. /* Invalid parameters RC2_k128b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  3111. /* Invalid parameters RC2_k128b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  3112. [Test]
  3113. public void TestRC2_k128b64_CFB8_None ()
  3114. {
  3115. byte[] key = { 0x61, 0x93, 0x31, 0x3A, 0xC2, 0x9B, 0x53, 0xB1, 0x26, 0x64, 0x36, 0x03, 0x16, 0x4A, 0xE3, 0x99 };
  3116. byte[] iv = { 0xDD, 0xAD, 0xA4, 0x57, 0xC1, 0x21, 0xF1, 0xA8 };
  3117. byte[] expected = { 0x94, 0xD9, 0x62, 0x83, 0x80, 0x4C, 0x91, 0x90, 0x63, 0x41, 0xBC, 0xBD, 0x8B, 0x7F, 0xD9, 0xB1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3118. SymmetricAlgorithm algo = RC2.Create ();
  3119. algo.Mode = CipherMode.CFB;
  3120. algo.Padding = PaddingMode.None;
  3121. algo.BlockSize = 64;
  3122. algo.FeedbackSize = 8;
  3123. int blockLength = (algo.BlockSize >> 3);
  3124. byte[] input = new byte [blockLength * 2];
  3125. byte[] output = new byte [blockLength * 3];
  3126. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3127. Encrypt (encryptor, input, output);
  3128. AssertEquals ("RC2_k128b64_CFB8_None Encrypt", expected, output);
  3129. byte[] reverse = new byte [blockLength * 3];
  3130. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3131. Decrypt (decryptor, output, reverse);
  3132. byte[] original = new byte [input.Length];
  3133. Array.Copy (reverse, 0, original, 0, original.Length);
  3134. AssertEquals ("RC2_k128b64_CFB8_None Decrypt", input, original);
  3135. }
  3136. [Test]
  3137. public void TestRC2_k128b64_CFB8_Zeros ()
  3138. {
  3139. byte[] key = { 0x64, 0x09, 0x9A, 0xF0, 0xD2, 0x52, 0x8C, 0x03, 0xF3, 0xBF, 0x1B, 0x9B, 0x92, 0x0E, 0xBA, 0x33 };
  3140. byte[] iv = { 0x15, 0x64, 0xE4, 0xFA, 0xFA, 0x58, 0x54, 0x7B };
  3141. byte[] expected = { 0xC8, 0x8F, 0xCC, 0x77, 0xA3, 0x82, 0x31, 0xD4, 0x7A, 0x68, 0x05, 0x8F, 0xF2, 0x1B, 0x9E, 0xCC, 0xDA, 0x6F, 0x74, 0x1D, 0x43, 0xE0, 0x90, 0x8B };
  3142. SymmetricAlgorithm algo = RC2.Create ();
  3143. algo.Mode = CipherMode.CFB;
  3144. algo.Padding = PaddingMode.Zeros;
  3145. algo.BlockSize = 64;
  3146. algo.FeedbackSize = 8;
  3147. int blockLength = (algo.BlockSize >> 3);
  3148. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3149. byte[] output = new byte [blockLength * 3];
  3150. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3151. Encrypt (encryptor, input, output);
  3152. AssertEquals ("RC2_k128b64_CFB8_Zeros Encrypt", expected, output);
  3153. byte[] reverse = new byte [blockLength * 3];
  3154. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3155. Decrypt (decryptor, output, reverse);
  3156. byte[] original = new byte [input.Length];
  3157. Array.Copy (reverse, 0, original, 0, original.Length);
  3158. AssertEquals ("RC2_k128b64_CFB8_Zeros Decrypt", input, original);
  3159. }
  3160. [Test]
  3161. public void TestRC2_k128b64_CFB8_PKCS7 ()
  3162. {
  3163. byte[] key = { 0x1F, 0x09, 0xF8, 0x1B, 0xA9, 0xA4, 0x70, 0x8D, 0x53, 0x76, 0x19, 0x4A, 0xAA, 0x62, 0x84, 0x94 };
  3164. byte[] iv = { 0xCC, 0x7B, 0xBE, 0xE9, 0xEE, 0x8E, 0x9C, 0x02 };
  3165. byte[] expected = { 0xA7, 0x1B, 0xD5, 0x4E, 0xDB, 0xF7, 0x84, 0xC2, 0xAA, 0x89, 0xAA, 0x3C, 0x3A, 0x63, 0x8A, 0xB2, 0xEF, 0x0C, 0x5B, 0xB0, 0xF4, 0xD9, 0x0A, 0x46 };
  3166. SymmetricAlgorithm algo = RC2.Create ();
  3167. algo.Mode = CipherMode.CFB;
  3168. algo.Padding = PaddingMode.PKCS7;
  3169. algo.BlockSize = 64;
  3170. algo.FeedbackSize = 8;
  3171. int blockLength = (algo.BlockSize >> 3);
  3172. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3173. byte[] output = new byte [blockLength * 3];
  3174. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3175. Encrypt (encryptor, input, output);
  3176. AssertEquals ("RC2_k128b64_CFB8_PKCS7 Encrypt", expected, output);
  3177. byte[] reverse = new byte [blockLength * 3];
  3178. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3179. Decrypt (decryptor, output, reverse);
  3180. byte[] original = new byte [input.Length];
  3181. Array.Copy (reverse, 0, original, 0, original.Length);
  3182. AssertEquals ("RC2_k128b64_CFB8_PKCS7 Decrypt", input, original);
  3183. }
  3184. /* Invalid parameters RC2_k128b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3185. /* Invalid parameters RC2_k128b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3186. /* Invalid parameters RC2_k128b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3187. [Test]
  3188. public void TestRijndael_k128b128_ECB_None ()
  3189. {
  3190. byte[] key = { 0xAF, 0x4D, 0xFE, 0x58, 0x33, 0xAC, 0x91, 0xB2, 0xFA, 0xA3, 0x96, 0x54, 0x0B, 0x68, 0xDD, 0xA1 };
  3191. // not used for ECB but make the code more uniform
  3192. byte[] iv = { 0xAF, 0x70, 0xC2, 0x2E, 0x2D, 0xF1, 0x0D, 0x7F, 0x52, 0xF4, 0x65, 0x79, 0x78, 0xAC, 0x80, 0xEF };
  3193. byte[] expected = { 0x6D, 0xC2, 0x4A, 0x51, 0x2D, 0xAB, 0x67, 0xCB, 0xD8, 0xD4, 0xD5, 0xE6, 0x0B, 0x24, 0x02, 0x90, 0x6D, 0xC2, 0x4A, 0x51, 0x2D, 0xAB, 0x67, 0xCB, 0xD8, 0xD4, 0xD5, 0xE6, 0x0B, 0x24, 0x02, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3194. SymmetricAlgorithm algo = Rijndael.Create ();
  3195. algo.Mode = CipherMode.ECB;
  3196. algo.Padding = PaddingMode.None;
  3197. algo.BlockSize = 128;
  3198. int blockLength = (algo.BlockSize >> 3);
  3199. byte[] input = new byte [blockLength * 2];
  3200. byte[] output = new byte [blockLength * 3];
  3201. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3202. Encrypt (encryptor, input, output);
  3203. AssertEquals ("Rijndael_k128b128_ECB_None Encrypt", expected, output);
  3204. // in ECB the first 2 blocks should be equals (as the IV is not used)
  3205. byte[] block1 = new byte[blockLength];
  3206. Array.Copy (output, 0, block1, 0, blockLength);
  3207. byte[] block2 = new byte[blockLength];
  3208. Array.Copy (output, blockLength, block2, 0, blockLength);
  3209. AssertEquals ("Rijndael_k128b128_ECB_None b1==b2", block1, block2);
  3210. byte[] reverse = new byte [blockLength * 3];
  3211. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3212. Decrypt (decryptor, output, reverse);
  3213. byte[] original = new byte [input.Length];
  3214. Array.Copy (reverse, 0, original, 0, original.Length);
  3215. AssertEquals ("Rijndael_k128b128_ECB_None Decrypt", input, original);
  3216. }
  3217. [Test]
  3218. public void TestRijndael_k128b128_ECB_Zeros ()
  3219. {
  3220. byte[] key = { 0xA4, 0x39, 0x01, 0x00, 0xDB, 0x0A, 0x47, 0xD8, 0xD8, 0xDC, 0x01, 0xF4, 0xBE, 0x96, 0xF4, 0xBB };
  3221. // not used for ECB but make the code more uniform
  3222. byte[] iv = { 0xEA, 0xBD, 0x55, 0x85, 0x3F, 0xC1, 0x5F, 0xCB, 0x06, 0x26, 0x3F, 0x88, 0x6A, 0x2D, 0x69, 0x45 };
  3223. byte[] expected = { 0x19, 0x32, 0x7E, 0x79, 0xE3, 0xC1, 0xFE, 0xA0, 0xFD, 0x26, 0x27, 0x61, 0xC0, 0xB8, 0x06, 0xC2, 0x19, 0x32, 0x7E, 0x79, 0xE3, 0xC1, 0xFE, 0xA0, 0xFD, 0x26, 0x27, 0x61, 0xC0, 0xB8, 0x06, 0xC2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3224. SymmetricAlgorithm algo = Rijndael.Create ();
  3225. algo.Mode = CipherMode.ECB;
  3226. algo.Padding = PaddingMode.Zeros;
  3227. algo.BlockSize = 128;
  3228. int blockLength = (algo.BlockSize >> 3);
  3229. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3230. byte[] output = new byte [blockLength * 3];
  3231. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3232. // some exception can be normal... other not so!
  3233. try {
  3234. Encrypt (encryptor, input, output);
  3235. }
  3236. catch (Exception e) {
  3237. if (e.Message != "Input buffer contains insufficient data. ")
  3238. Assert.Fail ("Rijndael_k128b128_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
  3239. }
  3240. }
  3241. [Test]
  3242. public void TestRijndael_k128b128_ECB_PKCS7 ()
  3243. {
  3244. byte[] key = { 0x5C, 0x58, 0x03, 0x1D, 0x05, 0x07, 0xDE, 0x93, 0x8D, 0x85, 0xFD, 0x50, 0x68, 0xA3, 0xD7, 0x6B };
  3245. // not used for ECB but make the code more uniform
  3246. byte[] iv = { 0x1C, 0x32, 0xFE, 0x99, 0x95, 0x16, 0x74, 0xC0, 0x6F, 0xE6, 0x01, 0x2C, 0x1F, 0x07, 0x54, 0xE8 };
  3247. byte[] expected = { 0xEE, 0x1C, 0x0B, 0x2F, 0x1E, 0xCE, 0x69, 0xBC, 0xEA, 0xF6, 0xED, 0xA9, 0xF0, 0xE3, 0xE7, 0xC3, 0xEE, 0x1C, 0x0B, 0x2F, 0x1E, 0xCE, 0x69, 0xBC, 0xEA, 0xF6, 0xED, 0xA9, 0xF0, 0xE3, 0xE7, 0xC3, 0x2E, 0xB4, 0x6F, 0x8C, 0xD3, 0x37, 0xF4, 0x8E, 0x6D, 0x08, 0x35, 0x47, 0xD1, 0x1A, 0xB2, 0xA0 };
  3248. SymmetricAlgorithm algo = Rijndael.Create ();
  3249. algo.Mode = CipherMode.ECB;
  3250. algo.Padding = PaddingMode.PKCS7;
  3251. algo.BlockSize = 128;
  3252. int blockLength = (algo.BlockSize >> 3);
  3253. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3254. byte[] output = new byte [blockLength * 3];
  3255. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3256. Encrypt (encryptor, input, output);
  3257. AssertEquals ("Rijndael_k128b128_ECB_PKCS7 Encrypt", expected, output);
  3258. // in ECB the first 2 blocks should be equals (as the IV is not used)
  3259. byte[] block1 = new byte[blockLength];
  3260. Array.Copy (output, 0, block1, 0, blockLength);
  3261. byte[] block2 = new byte[blockLength];
  3262. Array.Copy (output, blockLength, block2, 0, blockLength);
  3263. AssertEquals ("Rijndael_k128b128_ECB_PKCS7 b1==b2", block1, block2);
  3264. byte[] reverse = new byte [blockLength * 3];
  3265. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3266. Decrypt (decryptor, output, reverse);
  3267. byte[] original = new byte [input.Length];
  3268. Array.Copy (reverse, 0, original, 0, original.Length);
  3269. AssertEquals ("Rijndael_k128b128_ECB_PKCS7 Decrypt", input, original);
  3270. }
  3271. [Test]
  3272. public void TestRijndael_k128b128_CBC_None ()
  3273. {
  3274. byte[] key = { 0xED, 0xE4, 0xD9, 0x97, 0x8E, 0x5C, 0xF8, 0x86, 0xFE, 0x6B, 0xF4, 0xA7, 0x26, 0xDA, 0x70, 0x47 };
  3275. byte[] iv = { 0x06, 0xE1, 0xA5, 0x97, 0x7E, 0x20, 0x0C, 0x47, 0xA4, 0xAF, 0xB8, 0xF3, 0x8D, 0x2E, 0xA9, 0xAC };
  3276. byte[] expected = { 0xB1, 0x73, 0xDA, 0x05, 0x4C, 0x0D, 0x6C, 0x5D, 0x60, 0x72, 0x76, 0x79, 0x64, 0xA6, 0x45, 0x89, 0xA5, 0xCD, 0x35, 0x2C, 0x56, 0x12, 0x7D, 0xA6, 0x84, 0x36, 0xEB, 0xCC, 0xDF, 0x5C, 0xCB, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3277. SymmetricAlgorithm algo = Rijndael.Create ();
  3278. algo.Mode = CipherMode.CBC;
  3279. algo.Padding = PaddingMode.None;
  3280. algo.BlockSize = 128;
  3281. int blockLength = (algo.BlockSize >> 3);
  3282. byte[] input = new byte [blockLength * 2];
  3283. byte[] output = new byte [blockLength * 3];
  3284. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3285. Encrypt (encryptor, input, output);
  3286. AssertEquals ("Rijndael_k128b128_CBC_None Encrypt", expected, output);
  3287. byte[] reverse = new byte [blockLength * 3];
  3288. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3289. Decrypt (decryptor, output, reverse);
  3290. byte[] original = new byte [input.Length];
  3291. Array.Copy (reverse, 0, original, 0, original.Length);
  3292. AssertEquals ("Rijndael_k128b128_CBC_None Decrypt", input, original);
  3293. }
  3294. [Test]
  3295. public void TestRijndael_k128b128_CBC_Zeros ()
  3296. {
  3297. byte[] key = { 0x7F, 0x03, 0x95, 0x4E, 0x42, 0x9E, 0x83, 0x85, 0x4B, 0x1A, 0x87, 0x36, 0xA1, 0x5B, 0xA8, 0x24 };
  3298. byte[] iv = { 0x75, 0x49, 0x7B, 0xBE, 0x78, 0x55, 0x5F, 0xE9, 0x67, 0xCB, 0x7E, 0x30, 0x71, 0xD1, 0x36, 0x49 };
  3299. byte[] expected = { 0xC8, 0xE2, 0xE5, 0x14, 0x17, 0x10, 0x14, 0xA5, 0x14, 0x8E, 0x59, 0x82, 0x7C, 0x92, 0x12, 0x91, 0x49, 0xE4, 0x24, 0x2C, 0x38, 0x98, 0x91, 0x0B, 0xD8, 0x5C, 0xD0, 0x79, 0xCD, 0x35, 0x85, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3300. SymmetricAlgorithm algo = Rijndael.Create ();
  3301. algo.Mode = CipherMode.CBC;
  3302. algo.Padding = PaddingMode.Zeros;
  3303. algo.BlockSize = 128;
  3304. int blockLength = (algo.BlockSize >> 3);
  3305. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3306. byte[] output = new byte [blockLength * 3];
  3307. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3308. // some exception can be normal... other not so!
  3309. try {
  3310. Encrypt (encryptor, input, output);
  3311. }
  3312. catch (Exception e) {
  3313. if (e.Message != "Input buffer contains insufficient data. ")
  3314. Assert.Fail ("Rijndael_k128b128_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
  3315. }
  3316. }
  3317. [Test]
  3318. public void TestRijndael_k128b128_CBC_PKCS7 ()
  3319. {
  3320. byte[] key = { 0x02, 0xE6, 0xC1, 0xE2, 0x7E, 0x89, 0xB9, 0x04, 0xE7, 0x9A, 0xB8, 0x83, 0xA4, 0xF8, 0x1B, 0x64 };
  3321. byte[] iv = { 0xBC, 0xE4, 0x47, 0x1E, 0xD0, 0xDD, 0x09, 0x0D, 0xFC, 0xA1, 0x44, 0xCD, 0x88, 0x92, 0x41, 0xA5 };
  3322. byte[] expected = { 0xEA, 0xB3, 0x9D, 0xCC, 0xE6, 0x74, 0x22, 0xE5, 0x15, 0xEE, 0x1C, 0xA9, 0x48, 0xB9, 0x55, 0x01, 0xEA, 0x9F, 0x98, 0x8D, 0x5D, 0x59, 0xB1, 0x1C, 0xEC, 0xE5, 0x68, 0xEE, 0x86, 0x22, 0x17, 0xBA, 0x95, 0x7D, 0xEC, 0x06, 0x4B, 0x48, 0x90, 0x0E, 0x75, 0x38, 0xC0, 0x28, 0x7D, 0x72, 0x32, 0xF8 };
  3323. SymmetricAlgorithm algo = Rijndael.Create ();
  3324. algo.Mode = CipherMode.CBC;
  3325. algo.Padding = PaddingMode.PKCS7;
  3326. algo.BlockSize = 128;
  3327. int blockLength = (algo.BlockSize >> 3);
  3328. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3329. byte[] output = new byte [blockLength * 3];
  3330. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3331. Encrypt (encryptor, input, output);
  3332. AssertEquals ("Rijndael_k128b128_CBC_PKCS7 Encrypt", expected, output);
  3333. byte[] reverse = new byte [blockLength * 3];
  3334. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3335. Decrypt (decryptor, output, reverse);
  3336. byte[] original = new byte [input.Length];
  3337. Array.Copy (reverse, 0, original, 0, original.Length);
  3338. AssertEquals ("Rijndael_k128b128_CBC_PKCS7 Decrypt", input, original);
  3339. }
  3340. /* Invalid parameters Rijndael_k128b128_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  3341. /* Invalid parameters Rijndael_k128b128_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  3342. /* Invalid parameters Rijndael_k128b128_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  3343. /* Invalid parameters Rijndael_k128b128_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3344. /* Invalid parameters Rijndael_k128b128_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3345. /* Invalid parameters Rijndael_k128b128_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3346. /* Invalid parameters Rijndael_k128b128_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3347. /* Invalid parameters Rijndael_k128b128_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3348. /* Invalid parameters Rijndael_k128b128_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3349. [Test]
  3350. public void TestRijndael_k128b192_ECB_None ()
  3351. {
  3352. byte[] key = { 0xA5, 0x7F, 0xA2, 0x9F, 0xDA, 0xEE, 0x56, 0x2E, 0xF9, 0x3A, 0xEE, 0x1E, 0x30, 0x46, 0x80, 0x66 };
  3353. // not used for ECB but make the code more uniform
  3354. byte[] iv = { 0x81, 0xE8, 0x4F, 0x8A, 0xFC, 0xD0, 0x12, 0xB3, 0xF8, 0x1F, 0x30, 0xE2, 0x40, 0x90, 0xFB, 0x96, 0x88, 0xC0, 0xC8, 0xF7, 0x4A, 0x3E, 0xC0, 0x73 };
  3355. byte[] expected = { 0xC1, 0xC5, 0x13, 0x1B, 0x11, 0x93, 0x52, 0xE6, 0x4A, 0xA3, 0xF8, 0xE7, 0x28, 0xDE, 0x02, 0x9A, 0x5D, 0x2B, 0x14, 0x6A, 0x5D, 0x0F, 0x24, 0x8F, 0xC1, 0xC5, 0x13, 0x1B, 0x11, 0x93, 0x52, 0xE6, 0x4A, 0xA3, 0xF8, 0xE7, 0x28, 0xDE, 0x02, 0x9A, 0x5D, 0x2B, 0x14, 0x6A, 0x5D, 0x0F, 0x24, 0x8F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3356. SymmetricAlgorithm algo = Rijndael.Create ();
  3357. algo.Mode = CipherMode.ECB;
  3358. algo.Padding = PaddingMode.None;
  3359. algo.BlockSize = 192;
  3360. int blockLength = (algo.BlockSize >> 3);
  3361. byte[] input = new byte [blockLength * 2];
  3362. byte[] output = new byte [blockLength * 3];
  3363. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3364. Encrypt (encryptor, input, output);
  3365. AssertEquals ("Rijndael_k128b192_ECB_None Encrypt", expected, output);
  3366. // in ECB the first 2 blocks should be equals (as the IV is not used)
  3367. byte[] block1 = new byte[blockLength];
  3368. Array.Copy (output, 0, block1, 0, blockLength);
  3369. byte[] block2 = new byte[blockLength];
  3370. Array.Copy (output, blockLength, block2, 0, blockLength);
  3371. AssertEquals ("Rijndael_k128b192_ECB_None b1==b2", block1, block2);
  3372. byte[] reverse = new byte [blockLength * 3];
  3373. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3374. Decrypt (decryptor, output, reverse);
  3375. byte[] original = new byte [input.Length];
  3376. Array.Copy (reverse, 0, original, 0, original.Length);
  3377. AssertEquals ("Rijndael_k128b192_ECB_None Decrypt", input, original);
  3378. }
  3379. [Test]
  3380. public void TestRijndael_k128b192_ECB_Zeros ()
  3381. {
  3382. byte[] key = { 0xDF, 0x1B, 0x73, 0xA3, 0xE3, 0x53, 0x75, 0x92, 0x2B, 0xD0, 0x44, 0x35, 0x94, 0xF5, 0xB2, 0xE7 };
  3383. // not used for ECB but make the code more uniform
  3384. byte[] iv = { 0x21, 0x82, 0x61, 0x4A, 0x57, 0xC0, 0x7D, 0x96, 0xFF, 0xC2, 0x08, 0xC1, 0x6C, 0xDF, 0x7C, 0x65, 0xC1, 0x8B, 0xFE, 0x5E, 0xD5, 0x82, 0xAD, 0x98 };
  3385. byte[] expected = { 0xC9, 0x4E, 0xE0, 0x8F, 0x95, 0x55, 0x52, 0x1A, 0x75, 0xA9, 0x92, 0x1D, 0xFA, 0x30, 0xBD, 0xB8, 0x55, 0xA7, 0x8B, 0xF9, 0x58, 0xE9, 0x1B, 0x4C, 0xC9, 0x4E, 0xE0, 0x8F, 0x95, 0x55, 0x52, 0x1A, 0x75, 0xA9, 0x92, 0x1D, 0xFA, 0x30, 0xBD, 0xB8, 0x55, 0xA7, 0x8B, 0xF9, 0x58, 0xE9, 0x1B, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3386. SymmetricAlgorithm algo = Rijndael.Create ();
  3387. algo.Mode = CipherMode.ECB;
  3388. algo.Padding = PaddingMode.Zeros;
  3389. algo.BlockSize = 192;
  3390. int blockLength = (algo.BlockSize >> 3);
  3391. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3392. byte[] output = new byte [blockLength * 3];
  3393. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3394. // some exception can be normal... other not so!
  3395. try {
  3396. Encrypt (encryptor, input, output);
  3397. }
  3398. catch (Exception e) {
  3399. if (e.Message != "Input buffer contains insufficient data. ")
  3400. Assert.Fail ("Rijndael_k128b192_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
  3401. }
  3402. }
  3403. [Test]
  3404. public void TestRijndael_k128b192_ECB_PKCS7 ()
  3405. {
  3406. byte[] key = { 0x78, 0x75, 0x1F, 0xE7, 0xFA, 0x1F, 0xF4, 0x2D, 0x31, 0x36, 0x14, 0xA5, 0xB8, 0x31, 0x97, 0x47 };
  3407. // not used for ECB but make the code more uniform
  3408. byte[] iv = { 0x91, 0x2F, 0xDC, 0x19, 0xC7, 0x6C, 0x67, 0x4A, 0x51, 0xE7, 0x08, 0xA5, 0xF9, 0xC6, 0xC3, 0x56, 0xF2, 0xED, 0xBD, 0xC9, 0x71, 0x9F, 0x02, 0xAF };
  3409. byte[] expected = { 0xB1, 0x0D, 0xFD, 0xB0, 0x89, 0x3C, 0xF5, 0x52, 0x62, 0x22, 0x41, 0x20, 0xE4, 0x34, 0x03, 0x78, 0x37, 0xC2, 0xB1, 0xF9, 0x26, 0x0A, 0x7F, 0x0E, 0xB1, 0x0D, 0xFD, 0xB0, 0x89, 0x3C, 0xF5, 0x52, 0x62, 0x22, 0x41, 0x20, 0xE4, 0x34, 0x03, 0x78, 0x37, 0xC2, 0xB1, 0xF9, 0x26, 0x0A, 0x7F, 0x0E, 0xF9, 0x7A, 0x2D, 0xF9, 0x5C, 0xD5, 0xEA, 0x06, 0x18, 0xC9, 0x06, 0xD4, 0xD0, 0x0B, 0xD6, 0x19, 0x4E, 0x7E, 0x9C, 0x5F, 0xDE, 0x3D, 0xB4, 0x2A };
  3410. SymmetricAlgorithm algo = Rijndael.Create ();
  3411. algo.Mode = CipherMode.ECB;
  3412. algo.Padding = PaddingMode.PKCS7;
  3413. algo.BlockSize = 192;
  3414. int blockLength = (algo.BlockSize >> 3);
  3415. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3416. byte[] output = new byte [blockLength * 3];
  3417. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3418. Encrypt (encryptor, input, output);
  3419. AssertEquals ("Rijndael_k128b192_ECB_PKCS7 Encrypt", expected, output);
  3420. // in ECB the first 2 blocks should be equals (as the IV is not used)
  3421. byte[] block1 = new byte[blockLength];
  3422. Array.Copy (output, 0, block1, 0, blockLength);
  3423. byte[] block2 = new byte[blockLength];
  3424. Array.Copy (output, blockLength, block2, 0, blockLength);
  3425. AssertEquals ("Rijndael_k128b192_ECB_PKCS7 b1==b2", block1, block2);
  3426. byte[] reverse = new byte [blockLength * 3];
  3427. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3428. Decrypt (decryptor, output, reverse);
  3429. byte[] original = new byte [input.Length];
  3430. Array.Copy (reverse, 0, original, 0, original.Length);
  3431. AssertEquals ("Rijndael_k128b192_ECB_PKCS7 Decrypt", input, original);
  3432. }
  3433. [Test]
  3434. public void TestRijndael_k128b192_CBC_None ()
  3435. {
  3436. byte[] key = { 0xBD, 0x01, 0x0F, 0x53, 0x53, 0x14, 0x90, 0x58, 0x22, 0x81, 0x6F, 0x79, 0x8C, 0x68, 0x21, 0x21 };
  3437. byte[] iv = { 0xEE, 0x7B, 0xC0, 0x5F, 0x32, 0x59, 0x56, 0xB6, 0x7C, 0x17, 0x04, 0xC5, 0x64, 0x6A, 0xA1, 0x35, 0x6F, 0xAC, 0xB8, 0xCE, 0xFA, 0xCC, 0x76, 0xBE };
  3438. byte[] expected = { 0x5D, 0xF5, 0x03, 0xD7, 0x17, 0xEE, 0x05, 0x18, 0x63, 0x99, 0xAB, 0x58, 0xBB, 0xC0, 0x04, 0x0A, 0x52, 0x1D, 0x4E, 0xA4, 0x8B, 0x68, 0xA3, 0x63, 0x7A, 0xBD, 0xAF, 0x0C, 0x85, 0x5D, 0xF8, 0x0D, 0x7A, 0x01, 0xF0, 0x76, 0x24, 0xF1, 0x8A, 0x95, 0x8B, 0xB2, 0xC0, 0xF7, 0x1D, 0xC5, 0x0E, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3439. SymmetricAlgorithm algo = Rijndael.Create ();
  3440. algo.Mode = CipherMode.CBC;
  3441. algo.Padding = PaddingMode.None;
  3442. algo.BlockSize = 192;
  3443. int blockLength = (algo.BlockSize >> 3);
  3444. byte[] input = new byte [blockLength * 2];
  3445. byte[] output = new byte [blockLength * 3];
  3446. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3447. Encrypt (encryptor, input, output);
  3448. AssertEquals ("Rijndael_k128b192_CBC_None Encrypt", expected, output);
  3449. byte[] reverse = new byte [blockLength * 3];
  3450. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3451. Decrypt (decryptor, output, reverse);
  3452. byte[] original = new byte [input.Length];
  3453. Array.Copy (reverse, 0, original, 0, original.Length);
  3454. AssertEquals ("Rijndael_k128b192_CBC_None Decrypt", input, original);
  3455. }
  3456. [Test]
  3457. public void TestRijndael_k128b192_CBC_Zeros ()
  3458. {
  3459. byte[] key = { 0xE2, 0x9C, 0x2A, 0xAA, 0xD0, 0x02, 0xDD, 0xDF, 0xFE, 0xD7, 0xB0, 0x21, 0x1E, 0x52, 0xE5, 0x25 };
  3460. byte[] iv = { 0xED, 0xF5, 0xD7, 0xF7, 0x8D, 0xB6, 0x91, 0x00, 0x81, 0x88, 0x75, 0x8C, 0x61, 0x13, 0x84, 0x46, 0x2A, 0x53, 0x02, 0xE9, 0xBB, 0x01, 0xF8, 0x24 };
  3461. byte[] expected = { 0x55, 0x48, 0x90, 0x63, 0x5B, 0x93, 0x09, 0xA7, 0xF7, 0xB2, 0xC0, 0x4D, 0xB1, 0x1A, 0xF7, 0xC7, 0xF7, 0xC0, 0xB6, 0x29, 0x7A, 0x50, 0x4E, 0x52, 0x2F, 0x68, 0x49, 0x92, 0x80, 0x0D, 0xBD, 0x89, 0x34, 0x84, 0x60, 0x87, 0x2C, 0x50, 0x65, 0xFF, 0xAE, 0x0E, 0x7B, 0x30, 0x3D, 0xFA, 0x93, 0xE6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3462. SymmetricAlgorithm algo = Rijndael.Create ();
  3463. algo.Mode = CipherMode.CBC;
  3464. algo.Padding = PaddingMode.Zeros;
  3465. algo.BlockSize = 192;
  3466. int blockLength = (algo.BlockSize >> 3);
  3467. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3468. byte[] output = new byte [blockLength * 3];
  3469. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3470. // some exception can be normal... other not so!
  3471. try {
  3472. Encrypt (encryptor, input, output);
  3473. }
  3474. catch (Exception e) {
  3475. if (e.Message != "Input buffer contains insufficient data. ")
  3476. Assert.Fail ("Rijndael_k128b192_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
  3477. }
  3478. }
  3479. [Test]
  3480. public void TestRijndael_k128b192_CBC_PKCS7 ()
  3481. {
  3482. byte[] key = { 0x14, 0x6C, 0x36, 0x5E, 0x22, 0xE9, 0x25, 0x1E, 0xC9, 0x1F, 0xA7, 0xC9, 0xA5, 0x19, 0x2C, 0x09 };
  3483. byte[] iv = { 0xE2, 0x6F, 0xA7, 0xDC, 0x36, 0x32, 0xF7, 0x28, 0x8B, 0x09, 0x78, 0xB9, 0x30, 0x6A, 0x3F, 0xD0, 0xA8, 0x5E, 0x1F, 0x7D, 0x8F, 0xDE, 0x5B, 0xA4 };
  3484. byte[] expected = { 0x9D, 0x08, 0xFD, 0xDE, 0x64, 0x97, 0x1D, 0x88, 0xB4, 0xCD, 0x70, 0xDD, 0xCC, 0x95, 0x1C, 0xAE, 0x01, 0x4B, 0x14, 0x19, 0x69, 0x58, 0xCE, 0x14, 0xA6, 0xF6, 0xD0, 0x25, 0xCE, 0xD6, 0xBB, 0xD5, 0x8C, 0xF6, 0xBF, 0x54, 0x66, 0x1D, 0xAE, 0x03, 0x6C, 0x81, 0xBF, 0xC6, 0x06, 0xB3, 0x64, 0x39, 0x73, 0x0A, 0x54, 0xB8, 0x3F, 0x3D, 0x1D, 0xFA, 0xB8, 0xBB, 0x53, 0x34, 0xEC, 0x69, 0xBD, 0xC3, 0xC1, 0xB2, 0x8D, 0x7D, 0x08, 0xE4, 0xFA, 0x82 };
  3485. SymmetricAlgorithm algo = Rijndael.Create ();
  3486. algo.Mode = CipherMode.CBC;
  3487. algo.Padding = PaddingMode.PKCS7;
  3488. algo.BlockSize = 192;
  3489. int blockLength = (algo.BlockSize >> 3);
  3490. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3491. byte[] output = new byte [blockLength * 3];
  3492. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3493. Encrypt (encryptor, input, output);
  3494. AssertEquals ("Rijndael_k128b192_CBC_PKCS7 Encrypt", expected, output);
  3495. byte[] reverse = new byte [blockLength * 3];
  3496. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3497. Decrypt (decryptor, output, reverse);
  3498. byte[] original = new byte [input.Length];
  3499. Array.Copy (reverse, 0, original, 0, original.Length);
  3500. AssertEquals ("Rijndael_k128b192_CBC_PKCS7 Decrypt", input, original);
  3501. }
  3502. /* Invalid parameters Rijndael_k128b192_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  3503. /* Invalid parameters Rijndael_k128b192_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  3504. /* Invalid parameters Rijndael_k128b192_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  3505. /* Invalid parameters Rijndael_k128b192_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3506. /* Invalid parameters Rijndael_k128b192_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3507. /* Invalid parameters Rijndael_k128b192_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3508. /* Invalid parameters Rijndael_k128b192_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3509. /* Invalid parameters Rijndael_k128b192_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3510. /* Invalid parameters Rijndael_k128b192_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3511. [Test]
  3512. public void TestRijndael_k128b256_ECB_None ()
  3513. {
  3514. byte[] key = { 0xD5, 0xB9, 0x92, 0x27, 0xC0, 0xBB, 0x86, 0x06, 0x19, 0xD9, 0xA4, 0x1B, 0x9E, 0x7A, 0xF0, 0x3D };
  3515. // not used for ECB but make the code more uniform
  3516. byte[] iv = { 0x3C, 0x72, 0xD4, 0xBA, 0xC8, 0xCA, 0xAD, 0x8B, 0x94, 0x00, 0xF3, 0x4E, 0xE9, 0xAC, 0xFB, 0x15, 0xA2, 0x06, 0xFE, 0xA3, 0x33, 0x18, 0x48, 0x55, 0xD5, 0x6B, 0x8F, 0x13, 0xEF, 0xB6, 0x34, 0xF8 };
  3517. byte[] expected = { 0x9A, 0x86, 0x3A, 0xE6, 0x23, 0x50, 0x4D, 0xBD, 0x4B, 0xD3, 0x1A, 0xDE, 0x83, 0x13, 0x4A, 0x82, 0xEF, 0x99, 0x7D, 0x19, 0xB0, 0x01, 0x4E, 0x46, 0x4B, 0xCF, 0x99, 0x66, 0x10, 0x23, 0x6E, 0x6C, 0x9A, 0x86, 0x3A, 0xE6, 0x23, 0x50, 0x4D, 0xBD, 0x4B, 0xD3, 0x1A, 0xDE, 0x83, 0x13, 0x4A, 0x82, 0xEF, 0x99, 0x7D, 0x19, 0xB0, 0x01, 0x4E, 0x46, 0x4B, 0xCF, 0x99, 0x66, 0x10, 0x23, 0x6E, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3518. SymmetricAlgorithm algo = Rijndael.Create ();
  3519. algo.Mode = CipherMode.ECB;
  3520. algo.Padding = PaddingMode.None;
  3521. algo.BlockSize = 256;
  3522. int blockLength = (algo.BlockSize >> 3);
  3523. byte[] input = new byte [blockLength * 2];
  3524. byte[] output = new byte [blockLength * 3];
  3525. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3526. Encrypt (encryptor, input, output);
  3527. AssertEquals ("Rijndael_k128b256_ECB_None Encrypt", expected, output);
  3528. // in ECB the first 2 blocks should be equals (as the IV is not used)
  3529. byte[] block1 = new byte[blockLength];
  3530. Array.Copy (output, 0, block1, 0, blockLength);
  3531. byte[] block2 = new byte[blockLength];
  3532. Array.Copy (output, blockLength, block2, 0, blockLength);
  3533. AssertEquals ("Rijndael_k128b256_ECB_None b1==b2", block1, block2);
  3534. byte[] reverse = new byte [blockLength * 3];
  3535. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3536. Decrypt (decryptor, output, reverse);
  3537. byte[] original = new byte [input.Length];
  3538. Array.Copy (reverse, 0, original, 0, original.Length);
  3539. AssertEquals ("Rijndael_k128b256_ECB_None Decrypt", input, original);
  3540. }
  3541. [Test]
  3542. public void TestRijndael_k128b256_ECB_Zeros ()
  3543. {
  3544. byte[] key = { 0x3C, 0xA6, 0xD7, 0xDA, 0xE3, 0x4D, 0x32, 0x67, 0xA8, 0xF5, 0xFF, 0xFF, 0xEE, 0xE8, 0xD4, 0xB2 };
  3545. // not used for ECB but make the code more uniform
  3546. byte[] iv = { 0xC8, 0x0A, 0x40, 0x30, 0x7C, 0x7E, 0x75, 0xDE, 0x71, 0x64, 0x59, 0xCE, 0x03, 0x40, 0x8F, 0x50, 0xC7, 0x5E, 0xA2, 0x27, 0x5F, 0x12, 0x57, 0xF4, 0xB7, 0xAD, 0x95, 0xAD, 0x95, 0x84, 0xBE, 0x3C };
  3547. byte[] expected = { 0x6D, 0x57, 0xCA, 0xED, 0x29, 0xBA, 0xA6, 0x3A, 0x3D, 0x02, 0xE1, 0x21, 0x39, 0xB0, 0x34, 0x41, 0xFC, 0xAC, 0x55, 0x8C, 0x61, 0xAE, 0x18, 0x7D, 0x7A, 0x41, 0x81, 0x1C, 0x53, 0x5F, 0x3D, 0xB1, 0x6D, 0x57, 0xCA, 0xED, 0x29, 0xBA, 0xA6, 0x3A, 0x3D, 0x02, 0xE1, 0x21, 0x39, 0xB0, 0x34, 0x41, 0xFC, 0xAC, 0x55, 0x8C, 0x61, 0xAE, 0x18, 0x7D, 0x7A, 0x41, 0x81, 0x1C, 0x53, 0x5F, 0x3D, 0xB1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3548. SymmetricAlgorithm algo = Rijndael.Create ();
  3549. algo.Mode = CipherMode.ECB;
  3550. algo.Padding = PaddingMode.Zeros;
  3551. algo.BlockSize = 256;
  3552. int blockLength = (algo.BlockSize >> 3);
  3553. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3554. byte[] output = new byte [blockLength * 3];
  3555. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3556. // some exception can be normal... other not so!
  3557. try {
  3558. Encrypt (encryptor, input, output);
  3559. }
  3560. catch (Exception e) {
  3561. if (e.Message != "Input buffer contains insufficient data. ")
  3562. Assert.Fail ("Rijndael_k128b256_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
  3563. }
  3564. }
  3565. [Test]
  3566. public void TestRijndael_k128b256_ECB_PKCS7 ()
  3567. {
  3568. byte[] key = { 0xED, 0xBA, 0x84, 0x92, 0x50, 0x93, 0x9B, 0xE4, 0xC4, 0x83, 0x31, 0x8E, 0x11, 0x86, 0xAE, 0xC9 };
  3569. // not used for ECB but make the code more uniform
  3570. byte[] iv = { 0x43, 0x98, 0x73, 0xFE, 0x77, 0x4D, 0x75, 0x79, 0xC7, 0xEF, 0x5C, 0x89, 0xFA, 0x5E, 0x07, 0x85, 0x0B, 0x21, 0x59, 0x8B, 0x8A, 0x1D, 0x11, 0x07, 0xA0, 0xC4, 0x3E, 0x11, 0x7F, 0x5D, 0xFE, 0xEE };
  3571. byte[] expected = { 0xA0, 0x56, 0xD6, 0x6B, 0x48, 0x77, 0xCC, 0x51, 0x0F, 0x04, 0x58, 0x16, 0x46, 0x04, 0x36, 0x66, 0xBB, 0x4D, 0x88, 0x71, 0xFF, 0x65, 0x0B, 0xFD, 0x52, 0x8D, 0xE8, 0xAF, 0x97, 0x78, 0xBD, 0x82, 0xA0, 0x56, 0xD6, 0x6B, 0x48, 0x77, 0xCC, 0x51, 0x0F, 0x04, 0x58, 0x16, 0x46, 0x04, 0x36, 0x66, 0xBB, 0x4D, 0x88, 0x71, 0xFF, 0x65, 0x0B, 0xFD, 0x52, 0x8D, 0xE8, 0xAF, 0x97, 0x78, 0xBD, 0x82, 0x66, 0x2C, 0x2B, 0x59, 0xC8, 0x47, 0x3E, 0xE0, 0xC4, 0xA5, 0x22, 0x79, 0x6C, 0xCF, 0x18, 0x10, 0xDA, 0xB5, 0xE9, 0xB1, 0x21, 0xCA, 0xCC, 0xD6, 0xF7, 0xDC, 0xA5, 0xD4, 0x29, 0x10, 0x8A, 0xA4 };
  3572. SymmetricAlgorithm algo = Rijndael.Create ();
  3573. algo.Mode = CipherMode.ECB;
  3574. algo.Padding = PaddingMode.PKCS7;
  3575. algo.BlockSize = 256;
  3576. int blockLength = (algo.BlockSize >> 3);
  3577. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3578. byte[] output = new byte [blockLength * 3];
  3579. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3580. Encrypt (encryptor, input, output);
  3581. AssertEquals ("Rijndael_k128b256_ECB_PKCS7 Encrypt", expected, output);
  3582. // in ECB the first 2 blocks should be equals (as the IV is not used)
  3583. byte[] block1 = new byte[blockLength];
  3584. Array.Copy (output, 0, block1, 0, blockLength);
  3585. byte[] block2 = new byte[blockLength];
  3586. Array.Copy (output, blockLength, block2, 0, blockLength);
  3587. AssertEquals ("Rijndael_k128b256_ECB_PKCS7 b1==b2", block1, block2);
  3588. byte[] reverse = new byte [blockLength * 3];
  3589. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3590. Decrypt (decryptor, output, reverse);
  3591. byte[] original = new byte [input.Length];
  3592. Array.Copy (reverse, 0, original, 0, original.Length);
  3593. AssertEquals ("Rijndael_k128b256_ECB_PKCS7 Decrypt", input, original);
  3594. }
  3595. [Test]
  3596. public void TestRijndael_k128b256_CBC_None ()
  3597. {
  3598. byte[] key = { 0x23, 0x09, 0x30, 0xC7, 0x01, 0x81, 0x1D, 0x2E, 0xD6, 0x6A, 0xC9, 0x99, 0x0D, 0x3D, 0x99, 0x79 };
  3599. byte[] iv = { 0x24, 0x2B, 0xCF, 0xFF, 0x81, 0x8C, 0xBE, 0x55, 0x1D, 0x8A, 0xDA, 0xF8, 0x81, 0xA7, 0x5A, 0xD1, 0xA6, 0x88, 0xC6, 0x90, 0xC4, 0x33, 0xCD, 0x37, 0x11, 0xCC, 0x64, 0x42, 0xD8, 0x2C, 0xA6, 0xE0 };
  3600. byte[] expected = { 0xEF, 0xA5, 0xAB, 0xDB, 0x71, 0xE3, 0x9A, 0x33, 0x45, 0x74, 0xB7, 0x90, 0xED, 0xD8, 0xDE, 0x33, 0x56, 0xEA, 0x75, 0xE0, 0x42, 0x51, 0xAD, 0xEE, 0x9C, 0x74, 0xC8, 0x6B, 0x99, 0x88, 0xD2, 0x13, 0xB2, 0x80, 0x5E, 0xB3, 0xDC, 0xE3, 0x49, 0x43, 0x86, 0x10, 0xC7, 0xCC, 0xE2, 0xE8, 0xCD, 0x79, 0x5C, 0x69, 0x19, 0xD0, 0xE2, 0x70, 0xB1, 0x25, 0x21, 0xB5, 0xC0, 0x69, 0xAB, 0x3D, 0x25, 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3601. SymmetricAlgorithm algo = Rijndael.Create ();
  3602. algo.Mode = CipherMode.CBC;
  3603. algo.Padding = PaddingMode.None;
  3604. algo.BlockSize = 256;
  3605. int blockLength = (algo.BlockSize >> 3);
  3606. byte[] input = new byte [blockLength * 2];
  3607. byte[] output = new byte [blockLength * 3];
  3608. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3609. Encrypt (encryptor, input, output);
  3610. AssertEquals ("Rijndael_k128b256_CBC_None Encrypt", expected, output);
  3611. byte[] reverse = new byte [blockLength * 3];
  3612. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3613. Decrypt (decryptor, output, reverse);
  3614. byte[] original = new byte [input.Length];
  3615. Array.Copy (reverse, 0, original, 0, original.Length);
  3616. AssertEquals ("Rijndael_k128b256_CBC_None Decrypt", input, original);
  3617. }
  3618. [Test]
  3619. public void TestRijndael_k128b256_CBC_Zeros ()
  3620. {
  3621. byte[] key = { 0xB6, 0xE5, 0xA0, 0x6F, 0x35, 0xA9, 0x25, 0x31, 0x5B, 0x8C, 0x52, 0x87, 0x26, 0x80, 0xB1, 0x42 };
  3622. byte[] iv = { 0xFD, 0x8E, 0xD8, 0x17, 0xEB, 0x9F, 0xC6, 0x5B, 0xD7, 0x42, 0xF4, 0x79, 0x68, 0x38, 0xEE, 0xC6, 0x15, 0x83, 0xFF, 0x18, 0xA5, 0x24, 0x80, 0x65, 0xCE, 0xF3, 0xED, 0xA8, 0x0E, 0x60, 0xB4, 0xA0 };
  3623. byte[] expected = { 0xC6, 0x0C, 0xE3, 0x6A, 0x8A, 0x98, 0xC2, 0xF7, 0x77, 0x59, 0x2C, 0x77, 0x88, 0x3F, 0xCE, 0x12, 0xFB, 0xFB, 0xB0, 0x20, 0xE5, 0xBC, 0xDB, 0x30, 0xE8, 0x1C, 0x19, 0xEA, 0x4C, 0x3A, 0x2E, 0xAF, 0x57, 0x4B, 0x05, 0xE8, 0xD4, 0xC9, 0xB2, 0xC4, 0x00, 0x35, 0xE0, 0x57, 0x7D, 0xAF, 0x11, 0xB4, 0xB2, 0x84, 0xCD, 0x7F, 0x6C, 0x6E, 0xD0, 0xDA, 0x58, 0x90, 0xF6, 0x9A, 0x51, 0x2C, 0x74, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3624. SymmetricAlgorithm algo = Rijndael.Create ();
  3625. algo.Mode = CipherMode.CBC;
  3626. algo.Padding = PaddingMode.Zeros;
  3627. algo.BlockSize = 256;
  3628. int blockLength = (algo.BlockSize >> 3);
  3629. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3630. byte[] output = new byte [blockLength * 3];
  3631. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3632. // some exception can be normal... other not so!
  3633. try {
  3634. Encrypt (encryptor, input, output);
  3635. }
  3636. catch (Exception e) {
  3637. if (e.Message != "Input buffer contains insufficient data. ")
  3638. Assert.Fail ("Rijndael_k128b256_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
  3639. }
  3640. }
  3641. [Test]
  3642. public void TestRijndael_k128b256_CBC_PKCS7 ()
  3643. {
  3644. byte[] key = { 0xAE, 0x7A, 0xD9, 0x55, 0xBF, 0x55, 0xB2, 0x40, 0x4A, 0x48, 0x5F, 0x06, 0xAA, 0x04, 0x45, 0x0A };
  3645. byte[] iv = { 0xB9, 0xD7, 0xC5, 0x09, 0x93, 0xED, 0x68, 0xC4, 0x5A, 0x82, 0x8F, 0xBD, 0x2F, 0xB4, 0x3B, 0x84, 0xBA, 0xE4, 0x46, 0x51, 0xAD, 0xAB, 0xA5, 0xCC, 0xB7, 0x59, 0x31, 0x9E, 0xBB, 0xFA, 0x54, 0x10 };
  3646. byte[] expected = { 0xAC, 0xD7, 0x42, 0x01, 0x60, 0x36, 0xD3, 0xE1, 0xAE, 0x60, 0xC1, 0x5E, 0xAD, 0x4E, 0x81, 0xE1, 0x65, 0xFB, 0xF0, 0x06, 0x89, 0xC5, 0xAD, 0x71, 0x62, 0x81, 0x41, 0xC7, 0xC7, 0xC2, 0xAA, 0x1E, 0x76, 0x88, 0x41, 0x23, 0xFB, 0xFF, 0x44, 0x01, 0xA4, 0xB9, 0x61, 0xC0, 0x1B, 0x54, 0x09, 0x45, 0x1C, 0x17, 0xE3, 0x0A, 0x4A, 0x0A, 0xC5, 0x6F, 0x77, 0xB0, 0xDB, 0xE1, 0xD4, 0xCD, 0x28, 0xD6, 0xA6, 0x40, 0x8F, 0x2B, 0x49, 0x2C, 0xDF, 0x4D, 0x6D, 0x78, 0x24, 0x65, 0x37, 0x61, 0x05, 0xCD, 0xBC, 0x15, 0x37, 0x67, 0x65, 0xEF, 0xCB, 0x8A, 0xEE, 0x53, 0x9D, 0x29, 0x62, 0x73, 0x51, 0xD2 };
  3647. SymmetricAlgorithm algo = Rijndael.Create ();
  3648. algo.Mode = CipherMode.CBC;
  3649. algo.Padding = PaddingMode.PKCS7;
  3650. algo.BlockSize = 256;
  3651. int blockLength = (algo.BlockSize >> 3);
  3652. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3653. byte[] output = new byte [blockLength * 3];
  3654. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3655. Encrypt (encryptor, input, output);
  3656. AssertEquals ("Rijndael_k128b256_CBC_PKCS7 Encrypt", expected, output);
  3657. byte[] reverse = new byte [blockLength * 3];
  3658. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3659. Decrypt (decryptor, output, reverse);
  3660. byte[] original = new byte [input.Length];
  3661. Array.Copy (reverse, 0, original, 0, original.Length);
  3662. AssertEquals ("Rijndael_k128b256_CBC_PKCS7 Decrypt", input, original);
  3663. }
  3664. /* Invalid parameters Rijndael_k128b256_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  3665. /* Invalid parameters Rijndael_k128b256_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  3666. /* Invalid parameters Rijndael_k128b256_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  3667. /* Invalid parameters Rijndael_k128b256_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3668. /* Invalid parameters Rijndael_k128b256_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3669. /* Invalid parameters Rijndael_k128b256_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3670. /* Invalid parameters Rijndael_k128b256_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3671. /* Invalid parameters Rijndael_k128b256_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3672. /* Invalid parameters Rijndael_k128b256_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3673. [Test]
  3674. public void TestRijndael_k192b128_ECB_None ()
  3675. {
  3676. byte[] key = { 0xA4, 0x51, 0x15, 0x32, 0xE7, 0xFC, 0x6F, 0x22, 0x73, 0x72, 0xB0, 0xAD, 0x67, 0x4C, 0x84, 0xB4, 0xB2, 0xAF, 0x50, 0x74, 0x5A, 0x4D, 0xB7, 0x2A };
  3677. // not used for ECB but make the code more uniform
  3678. byte[] iv = { 0x83, 0x22, 0x1B, 0x6C, 0x66, 0x1F, 0x4A, 0xB7, 0x55, 0xAF, 0x5B, 0xBF, 0x4A, 0x05, 0x73, 0x24 };
  3679. byte[] expected = { 0x6A, 0x1D, 0xA5, 0xBE, 0x7F, 0x6C, 0x0A, 0x98, 0x2A, 0x09, 0x4B, 0x70, 0xC1, 0xA1, 0xBC, 0x75, 0x6A, 0x1D, 0xA5, 0xBE, 0x7F, 0x6C, 0x0A, 0x98, 0x2A, 0x09, 0x4B, 0x70, 0xC1, 0xA1, 0xBC, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3680. SymmetricAlgorithm algo = Rijndael.Create ();
  3681. algo.Mode = CipherMode.ECB;
  3682. algo.Padding = PaddingMode.None;
  3683. algo.BlockSize = 128;
  3684. int blockLength = (algo.BlockSize >> 3);
  3685. byte[] input = new byte [blockLength * 2];
  3686. byte[] output = new byte [blockLength * 3];
  3687. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3688. Encrypt (encryptor, input, output);
  3689. AssertEquals ("Rijndael_k192b128_ECB_None Encrypt", expected, output);
  3690. // in ECB the first 2 blocks should be equals (as the IV is not used)
  3691. byte[] block1 = new byte[blockLength];
  3692. Array.Copy (output, 0, block1, 0, blockLength);
  3693. byte[] block2 = new byte[blockLength];
  3694. Array.Copy (output, blockLength, block2, 0, blockLength);
  3695. AssertEquals ("Rijndael_k192b128_ECB_None b1==b2", block1, block2);
  3696. byte[] reverse = new byte [blockLength * 3];
  3697. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3698. Decrypt (decryptor, output, reverse);
  3699. byte[] original = new byte [input.Length];
  3700. Array.Copy (reverse, 0, original, 0, original.Length);
  3701. AssertEquals ("Rijndael_k192b128_ECB_None Decrypt", input, original);
  3702. }
  3703. [Test]
  3704. public void TestRijndael_k192b128_ECB_Zeros ()
  3705. {
  3706. byte[] key = { 0xB4, 0x65, 0x79, 0x30, 0x92, 0x6A, 0xEC, 0x78, 0xBA, 0x9B, 0x8B, 0x36, 0x7C, 0x8F, 0x6B, 0x8A, 0x79, 0x7F, 0x8A, 0xDA, 0xB4, 0x06, 0x23, 0x4C };
  3707. // not used for ECB but make the code more uniform
  3708. byte[] iv = { 0x43, 0xBA, 0x1C, 0xFB, 0x33, 0xB4, 0x3B, 0x38, 0x5C, 0x21, 0x13, 0xDD, 0x9A, 0x3A, 0xF1, 0xEE };
  3709. byte[] expected = { 0xB1, 0x45, 0x70, 0xFC, 0xB5, 0x82, 0x49, 0x9F, 0xEA, 0x50, 0x0C, 0xEA, 0xFD, 0x13, 0xA8, 0xE8, 0xB1, 0x45, 0x70, 0xFC, 0xB5, 0x82, 0x49, 0x9F, 0xEA, 0x50, 0x0C, 0xEA, 0xFD, 0x13, 0xA8, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3710. SymmetricAlgorithm algo = Rijndael.Create ();
  3711. algo.Mode = CipherMode.ECB;
  3712. algo.Padding = PaddingMode.Zeros;
  3713. algo.BlockSize = 128;
  3714. int blockLength = (algo.BlockSize >> 3);
  3715. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3716. byte[] output = new byte [blockLength * 3];
  3717. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3718. // some exception can be normal... other not so!
  3719. try {
  3720. Encrypt (encryptor, input, output);
  3721. }
  3722. catch (Exception e) {
  3723. if (e.Message != "Input buffer contains insufficient data. ")
  3724. Assert.Fail ("Rijndael_k192b128_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
  3725. }
  3726. }
  3727. [Test]
  3728. public void TestRijndael_k192b128_ECB_PKCS7 ()
  3729. {
  3730. byte[] key = { 0x06, 0xC3, 0x07, 0x6A, 0x36, 0xE5, 0xF3, 0xCF, 0x33, 0x87, 0x22, 0x03, 0x5A, 0xFA, 0x4F, 0x25, 0x9D, 0xE4, 0x81, 0xA4, 0x9E, 0xB4, 0x5D, 0x84 };
  3731. // not used for ECB but make the code more uniform
  3732. byte[] iv = { 0xB0, 0xF9, 0x9F, 0x2D, 0x8D, 0xD0, 0x2D, 0xA1, 0x51, 0xDB, 0x07, 0xA3, 0x34, 0x28, 0x4F, 0x25 };
  3733. byte[] expected = { 0xE9, 0xB9, 0xE5, 0x89, 0x0E, 0xF7, 0x3C, 0xCF, 0x63, 0x6B, 0xCD, 0x33, 0x85, 0x81, 0x02, 0x75, 0xE9, 0xB9, 0xE5, 0x89, 0x0E, 0xF7, 0x3C, 0xCF, 0x63, 0x6B, 0xCD, 0x33, 0x85, 0x81, 0x02, 0x75, 0xE8, 0x31, 0x03, 0x87, 0xFF, 0x9D, 0x7A, 0xAB, 0x81, 0x82, 0x63, 0x6B, 0xAA, 0x6F, 0x20, 0x21 };
  3734. SymmetricAlgorithm algo = Rijndael.Create ();
  3735. algo.Mode = CipherMode.ECB;
  3736. algo.Padding = PaddingMode.PKCS7;
  3737. algo.BlockSize = 128;
  3738. int blockLength = (algo.BlockSize >> 3);
  3739. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3740. byte[] output = new byte [blockLength * 3];
  3741. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3742. Encrypt (encryptor, input, output);
  3743. AssertEquals ("Rijndael_k192b128_ECB_PKCS7 Encrypt", expected, output);
  3744. // in ECB the first 2 blocks should be equals (as the IV is not used)
  3745. byte[] block1 = new byte[blockLength];
  3746. Array.Copy (output, 0, block1, 0, blockLength);
  3747. byte[] block2 = new byte[blockLength];
  3748. Array.Copy (output, blockLength, block2, 0, blockLength);
  3749. AssertEquals ("Rijndael_k192b128_ECB_PKCS7 b1==b2", block1, block2);
  3750. byte[] reverse = new byte [blockLength * 3];
  3751. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3752. Decrypt (decryptor, output, reverse);
  3753. byte[] original = new byte [input.Length];
  3754. Array.Copy (reverse, 0, original, 0, original.Length);
  3755. AssertEquals ("Rijndael_k192b128_ECB_PKCS7 Decrypt", input, original);
  3756. }
  3757. [Test]
  3758. public void TestRijndael_k192b128_CBC_None ()
  3759. {
  3760. byte[] key = { 0x8F, 0x85, 0x39, 0xC2, 0xAC, 0x25, 0xBD, 0x54, 0xDE, 0x89, 0x2A, 0x67, 0x2C, 0xF0, 0xE5, 0x7E, 0xAA, 0x7E, 0xC4, 0xFB, 0xCD, 0x31, 0xD9, 0xFA };
  3761. byte[] iv = { 0xCA, 0xC4, 0x8D, 0x38, 0x28, 0x29, 0xC2, 0xBF, 0xD8, 0x7A, 0xCA, 0x56, 0xBF, 0x59, 0x6B, 0xCE };
  3762. byte[] expected = { 0x22, 0x66, 0xB0, 0x6C, 0xC1, 0x18, 0xBB, 0x43, 0x6B, 0xB9, 0x42, 0x16, 0x4D, 0xFB, 0x96, 0x7C, 0xEC, 0xCA, 0xB8, 0x09, 0x02, 0x8C, 0x2E, 0x4D, 0x4D, 0x90, 0x03, 0xEA, 0x0F, 0x69, 0x20, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3763. SymmetricAlgorithm algo = Rijndael.Create ();
  3764. algo.Mode = CipherMode.CBC;
  3765. algo.Padding = PaddingMode.None;
  3766. algo.BlockSize = 128;
  3767. int blockLength = (algo.BlockSize >> 3);
  3768. byte[] input = new byte [blockLength * 2];
  3769. byte[] output = new byte [blockLength * 3];
  3770. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3771. Encrypt (encryptor, input, output);
  3772. AssertEquals ("Rijndael_k192b128_CBC_None Encrypt", expected, output);
  3773. byte[] reverse = new byte [blockLength * 3];
  3774. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3775. Decrypt (decryptor, output, reverse);
  3776. byte[] original = new byte [input.Length];
  3777. Array.Copy (reverse, 0, original, 0, original.Length);
  3778. AssertEquals ("Rijndael_k192b128_CBC_None Decrypt", input, original);
  3779. }
  3780. [Test]
  3781. public void TestRijndael_k192b128_CBC_Zeros ()
  3782. {
  3783. byte[] key = { 0xA7, 0x3E, 0xEE, 0x4B, 0xF5, 0x0E, 0x05, 0x03, 0xE2, 0x50, 0xF1, 0xBC, 0xEB, 0x57, 0x60, 0x79, 0x83, 0x5D, 0xFC, 0x42, 0x65, 0x41, 0xCF, 0x48 };
  3784. byte[] iv = { 0xC9, 0x76, 0xCE, 0x21, 0xDF, 0x46, 0xB0, 0x23, 0x19, 0xB6, 0xD5, 0x80, 0x1F, 0xBA, 0x15, 0xDB };
  3785. byte[] expected = { 0x63, 0xED, 0x15, 0xBE, 0xB9, 0x4E, 0x9E, 0x30, 0xB1, 0xC5, 0x31, 0xCB, 0x02, 0x88, 0xB4, 0x8F, 0xF5, 0xB0, 0x53, 0x8D, 0xD1, 0x35, 0xB7, 0x85, 0xED, 0x02, 0x79, 0x03, 0xC1, 0x13, 0xCE, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3786. SymmetricAlgorithm algo = Rijndael.Create ();
  3787. algo.Mode = CipherMode.CBC;
  3788. algo.Padding = PaddingMode.Zeros;
  3789. algo.BlockSize = 128;
  3790. int blockLength = (algo.BlockSize >> 3);
  3791. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3792. byte[] output = new byte [blockLength * 3];
  3793. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3794. // some exception can be normal... other not so!
  3795. try {
  3796. Encrypt (encryptor, input, output);
  3797. }
  3798. catch (Exception e) {
  3799. if (e.Message != "Input buffer contains insufficient data. ")
  3800. Assert.Fail ("Rijndael_k192b128_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
  3801. }
  3802. }
  3803. [Test]
  3804. public void TestRijndael_k192b128_CBC_PKCS7 ()
  3805. {
  3806. byte[] key = { 0x0F, 0x00, 0x54, 0xCD, 0x2A, 0x66, 0x21, 0xF0, 0x74, 0x64, 0x65, 0xC6, 0xE1, 0xC6, 0xCD, 0x11, 0x05, 0x04, 0xA7, 0x23, 0x48, 0x4E, 0xB3, 0x84 };
  3807. byte[] iv = { 0xDA, 0xE6, 0x7F, 0x27, 0x8A, 0xE6, 0x8E, 0x13, 0x9D, 0x15, 0x0D, 0x80, 0x4B, 0xC4, 0x9F, 0x08 };
  3808. byte[] expected = { 0x0D, 0x7E, 0x32, 0xE0, 0xFA, 0x25, 0xB1, 0x52, 0x37, 0x27, 0xF3, 0x99, 0xA7, 0x08, 0x7F, 0x8E, 0xAA, 0x98, 0x36, 0x42, 0x21, 0xCF, 0x3B, 0xF1, 0x95, 0x99, 0xF4, 0x00, 0x36, 0x47, 0x0F, 0x25, 0x43, 0x36, 0x43, 0x68, 0x40, 0xB1, 0x1A, 0xFA, 0xDC, 0x43, 0x94, 0xD7, 0x16, 0x28, 0xFD, 0xDD };
  3809. SymmetricAlgorithm algo = Rijndael.Create ();
  3810. algo.Mode = CipherMode.CBC;
  3811. algo.Padding = PaddingMode.PKCS7;
  3812. algo.BlockSize = 128;
  3813. int blockLength = (algo.BlockSize >> 3);
  3814. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3815. byte[] output = new byte [blockLength * 3];
  3816. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3817. Encrypt (encryptor, input, output);
  3818. AssertEquals ("Rijndael_k192b128_CBC_PKCS7 Encrypt", expected, output);
  3819. byte[] reverse = new byte [blockLength * 3];
  3820. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3821. Decrypt (decryptor, output, reverse);
  3822. byte[] original = new byte [input.Length];
  3823. Array.Copy (reverse, 0, original, 0, original.Length);
  3824. AssertEquals ("Rijndael_k192b128_CBC_PKCS7 Decrypt", input, original);
  3825. }
  3826. /* Invalid parameters Rijndael_k192b128_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  3827. /* Invalid parameters Rijndael_k192b128_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  3828. /* Invalid parameters Rijndael_k192b128_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  3829. /* Invalid parameters Rijndael_k192b128_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3830. /* Invalid parameters Rijndael_k192b128_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3831. /* Invalid parameters Rijndael_k192b128_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3832. /* Invalid parameters Rijndael_k192b128_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3833. /* Invalid parameters Rijndael_k192b128_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3834. /* Invalid parameters Rijndael_k192b128_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3835. [Test]
  3836. public void TestRijndael_k192b192_ECB_None ()
  3837. {
  3838. byte[] key = { 0x33, 0x09, 0x20, 0xF4, 0x69, 0x76, 0x98, 0x57, 0x93, 0x1A, 0x37, 0x31, 0xFA, 0x2D, 0x49, 0xEA, 0xE4, 0xD4, 0x6C, 0xA5, 0x91, 0x2A, 0xD8, 0x54 };
  3839. // not used for ECB but make the code more uniform
  3840. byte[] iv = { 0x7F, 0x2E, 0xE0, 0x80, 0x52, 0x2F, 0x63, 0x3F, 0x8F, 0x09, 0x85, 0x3D, 0x21, 0x73, 0x40, 0x45, 0xB0, 0x85, 0xDE, 0xB9, 0xC0, 0xA1, 0x06, 0xB2 };
  3841. byte[] expected = { 0x93, 0x0B, 0xF0, 0xA0, 0x0C, 0x79, 0x99, 0x40, 0x17, 0x62, 0xD6, 0xD8, 0x1C, 0x3B, 0xB3, 0x18, 0x57, 0xA6, 0x01, 0x68, 0xEA, 0x73, 0x9A, 0x0A, 0x93, 0x0B, 0xF0, 0xA0, 0x0C, 0x79, 0x99, 0x40, 0x17, 0x62, 0xD6, 0xD8, 0x1C, 0x3B, 0xB3, 0x18, 0x57, 0xA6, 0x01, 0x68, 0xEA, 0x73, 0x9A, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3842. SymmetricAlgorithm algo = Rijndael.Create ();
  3843. algo.Mode = CipherMode.ECB;
  3844. algo.Padding = PaddingMode.None;
  3845. algo.BlockSize = 192;
  3846. int blockLength = (algo.BlockSize >> 3);
  3847. byte[] input = new byte [blockLength * 2];
  3848. byte[] output = new byte [blockLength * 3];
  3849. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3850. Encrypt (encryptor, input, output);
  3851. AssertEquals ("Rijndael_k192b192_ECB_None Encrypt", expected, output);
  3852. // in ECB the first 2 blocks should be equals (as the IV is not used)
  3853. byte[] block1 = new byte[blockLength];
  3854. Array.Copy (output, 0, block1, 0, blockLength);
  3855. byte[] block2 = new byte[blockLength];
  3856. Array.Copy (output, blockLength, block2, 0, blockLength);
  3857. AssertEquals ("Rijndael_k192b192_ECB_None b1==b2", block1, block2);
  3858. byte[] reverse = new byte [blockLength * 3];
  3859. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3860. Decrypt (decryptor, output, reverse);
  3861. byte[] original = new byte [input.Length];
  3862. Array.Copy (reverse, 0, original, 0, original.Length);
  3863. AssertEquals ("Rijndael_k192b192_ECB_None Decrypt", input, original);
  3864. }
  3865. [Test]
  3866. public void TestRijndael_k192b192_ECB_Zeros ()
  3867. {
  3868. byte[] key = { 0xB5, 0x06, 0x72, 0x5F, 0x4E, 0x37, 0x62, 0x8F, 0x68, 0xE5, 0x0A, 0x80, 0xC6, 0x39, 0xB9, 0x13, 0xC7, 0xD8, 0x74, 0x1F, 0xE8, 0xD1, 0x99, 0x9E };
  3869. // not used for ECB but make the code more uniform
  3870. byte[] iv = { 0x11, 0x49, 0xA6, 0x58, 0x8F, 0xF1, 0x8E, 0xB3, 0x19, 0x81, 0xFE, 0xB8, 0x09, 0x69, 0x3D, 0x01, 0x21, 0x08, 0xCD, 0x1D, 0xEB, 0x98, 0xA7, 0xF1 };
  3871. byte[] expected = { 0x42, 0xD5, 0xF0, 0x37, 0xFF, 0xBB, 0x81, 0xC1, 0x6F, 0x12, 0xCF, 0x65, 0x29, 0xC5, 0x88, 0xBE, 0x08, 0x88, 0xBF, 0x6F, 0xDF, 0x23, 0x82, 0x5E, 0x42, 0xD5, 0xF0, 0x37, 0xFF, 0xBB, 0x81, 0xC1, 0x6F, 0x12, 0xCF, 0x65, 0x29, 0xC5, 0x88, 0xBE, 0x08, 0x88, 0xBF, 0x6F, 0xDF, 0x23, 0x82, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3872. SymmetricAlgorithm algo = Rijndael.Create ();
  3873. algo.Mode = CipherMode.ECB;
  3874. algo.Padding = PaddingMode.Zeros;
  3875. algo.BlockSize = 192;
  3876. int blockLength = (algo.BlockSize >> 3);
  3877. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3878. byte[] output = new byte [blockLength * 3];
  3879. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3880. // some exception can be normal... other not so!
  3881. try {
  3882. Encrypt (encryptor, input, output);
  3883. }
  3884. catch (Exception e) {
  3885. if (e.Message != "Input buffer contains insufficient data. ")
  3886. Assert.Fail ("Rijndael_k192b192_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
  3887. }
  3888. }
  3889. [Test]
  3890. public void TestRijndael_k192b192_ECB_PKCS7 ()
  3891. {
  3892. byte[] key = { 0x40, 0xE3, 0xF1, 0x90, 0xC2, 0xA9, 0x59, 0xB8, 0x01, 0x72, 0x01, 0x1F, 0x10, 0x11, 0x0E, 0x8F, 0xA1, 0xF2, 0x62, 0xD7, 0x0A, 0x65, 0xCD, 0xC4 };
  3893. // not used for ECB but make the code more uniform
  3894. byte[] iv = { 0x06, 0x08, 0x07, 0xB3, 0x8F, 0x84, 0xD9, 0xB3, 0xF9, 0x11, 0xFC, 0x0B, 0x9C, 0xC4, 0x6E, 0x41, 0xE1, 0xCC, 0x6F, 0x26, 0x6D, 0x70, 0xC6, 0x47 };
  3895. byte[] expected = { 0xCD, 0x70, 0x93, 0x83, 0x82, 0xB1, 0xA3, 0x74, 0x8A, 0xBD, 0x0C, 0x0D, 0x8B, 0x9F, 0x3C, 0xDF, 0xBC, 0x8E, 0x64, 0x6E, 0xF7, 0xF5, 0x10, 0x0E, 0xCD, 0x70, 0x93, 0x83, 0x82, 0xB1, 0xA3, 0x74, 0x8A, 0xBD, 0x0C, 0x0D, 0x8B, 0x9F, 0x3C, 0xDF, 0xBC, 0x8E, 0x64, 0x6E, 0xF7, 0xF5, 0x10, 0x0E, 0x2D, 0xB2, 0xBD, 0xA1, 0x21, 0x56, 0xD1, 0x33, 0x00, 0x1C, 0x71, 0xAF, 0x9A, 0x48, 0x24, 0x00, 0xED, 0xA1, 0xE4, 0x2B, 0xF4, 0xF3, 0xD2, 0x5F };
  3896. SymmetricAlgorithm algo = Rijndael.Create ();
  3897. algo.Mode = CipherMode.ECB;
  3898. algo.Padding = PaddingMode.PKCS7;
  3899. algo.BlockSize = 192;
  3900. int blockLength = (algo.BlockSize >> 3);
  3901. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3902. byte[] output = new byte [blockLength * 3];
  3903. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3904. Encrypt (encryptor, input, output);
  3905. AssertEquals ("Rijndael_k192b192_ECB_PKCS7 Encrypt", expected, output);
  3906. // in ECB the first 2 blocks should be equals (as the IV is not used)
  3907. byte[] block1 = new byte[blockLength];
  3908. Array.Copy (output, 0, block1, 0, blockLength);
  3909. byte[] block2 = new byte[blockLength];
  3910. Array.Copy (output, blockLength, block2, 0, blockLength);
  3911. AssertEquals ("Rijndael_k192b192_ECB_PKCS7 b1==b2", block1, block2);
  3912. byte[] reverse = new byte [blockLength * 3];
  3913. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3914. Decrypt (decryptor, output, reverse);
  3915. byte[] original = new byte [input.Length];
  3916. Array.Copy (reverse, 0, original, 0, original.Length);
  3917. AssertEquals ("Rijndael_k192b192_ECB_PKCS7 Decrypt", input, original);
  3918. }
  3919. [Test]
  3920. public void TestRijndael_k192b192_CBC_None ()
  3921. {
  3922. byte[] key = { 0x21, 0x15, 0x8D, 0x66, 0x7D, 0x81, 0xD6, 0xBD, 0xFF, 0x6D, 0x3F, 0x44, 0x43, 0x0E, 0xD7, 0x07, 0xC9, 0x5F, 0xFF, 0x0A, 0x88, 0x2D, 0xC1, 0xC4 };
  3923. byte[] iv = { 0x43, 0x68, 0xF9, 0x7E, 0xD4, 0x6D, 0xB9, 0xA7, 0x9D, 0xFF, 0x68, 0x7F, 0x4F, 0xBB, 0x14, 0x4D, 0x29, 0x4F, 0x94, 0x8A, 0x83, 0x02, 0x77, 0x1E };
  3924. byte[] expected = { 0x13, 0xD5, 0x9A, 0x4A, 0x96, 0x7E, 0x4F, 0x67, 0x12, 0x31, 0x9B, 0xF5, 0xC5, 0x5A, 0x81, 0xC2, 0x43, 0x51, 0x57, 0x6D, 0xA2, 0xFC, 0x5F, 0x00, 0x49, 0x5A, 0x4E, 0x82, 0x3C, 0xE0, 0x7A, 0x89, 0x2F, 0x36, 0xB3, 0x84, 0x6E, 0x9B, 0x9A, 0xAA, 0x48, 0x1B, 0x0D, 0xA1, 0x42, 0xAD, 0x6F, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3925. SymmetricAlgorithm algo = Rijndael.Create ();
  3926. algo.Mode = CipherMode.CBC;
  3927. algo.Padding = PaddingMode.None;
  3928. algo.BlockSize = 192;
  3929. int blockLength = (algo.BlockSize >> 3);
  3930. byte[] input = new byte [blockLength * 2];
  3931. byte[] output = new byte [blockLength * 3];
  3932. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3933. Encrypt (encryptor, input, output);
  3934. AssertEquals ("Rijndael_k192b192_CBC_None Encrypt", expected, output);
  3935. byte[] reverse = new byte [blockLength * 3];
  3936. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3937. Decrypt (decryptor, output, reverse);
  3938. byte[] original = new byte [input.Length];
  3939. Array.Copy (reverse, 0, original, 0, original.Length);
  3940. AssertEquals ("Rijndael_k192b192_CBC_None Decrypt", input, original);
  3941. }
  3942. [Test]
  3943. public void TestRijndael_k192b192_CBC_Zeros ()
  3944. {
  3945. byte[] key = { 0x81, 0x6F, 0xD7, 0x01, 0xCF, 0x7E, 0x73, 0x8E, 0x18, 0xB7, 0x91, 0x85, 0x70, 0x3B, 0x87, 0xCE, 0xA7, 0xB5, 0xB9, 0xFA, 0x30, 0x3D, 0x26, 0x28 };
  3946. byte[] iv = { 0x5B, 0x34, 0x00, 0xA3, 0x3F, 0xEA, 0x2C, 0xAF, 0x87, 0xA3, 0xB9, 0x15, 0xF8, 0x61, 0x4A, 0x5C, 0x23, 0x2A, 0xF3, 0xA6, 0x7B, 0xFB, 0xEA, 0x1E };
  3947. byte[] expected = { 0xF4, 0x87, 0x7B, 0xC8, 0x41, 0x2C, 0x8E, 0x2C, 0x58, 0x50, 0x6E, 0xE5, 0x79, 0xD1, 0xE8, 0x54, 0xE2, 0x13, 0x55, 0x91, 0x60, 0xF0, 0x35, 0x2D, 0xDB, 0x3A, 0x69, 0x92, 0x3B, 0xD1, 0x6D, 0x89, 0x57, 0x17, 0x2F, 0x31, 0xA1, 0xD9, 0xB1, 0x00, 0x41, 0x54, 0x0C, 0xFC, 0xA4, 0xE0, 0x7F, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  3948. SymmetricAlgorithm algo = Rijndael.Create ();
  3949. algo.Mode = CipherMode.CBC;
  3950. algo.Padding = PaddingMode.Zeros;
  3951. algo.BlockSize = 192;
  3952. int blockLength = (algo.BlockSize >> 3);
  3953. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3954. byte[] output = new byte [blockLength * 3];
  3955. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3956. // some exception can be normal... other not so!
  3957. try {
  3958. Encrypt (encryptor, input, output);
  3959. }
  3960. catch (Exception e) {
  3961. if (e.Message != "Input buffer contains insufficient data. ")
  3962. Assert.Fail ("Rijndael_k192b192_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
  3963. }
  3964. }
  3965. [Test]
  3966. public void TestRijndael_k192b192_CBC_PKCS7 ()
  3967. {
  3968. byte[] key = { 0xF4, 0x68, 0x87, 0x59, 0x32, 0x8D, 0x10, 0xA8, 0xC1, 0x32, 0xD0, 0xEC, 0xE5, 0x4A, 0x8A, 0x11, 0x3E, 0x8E, 0x11, 0x48, 0x88, 0xE9, 0xC1, 0x1A };
  3969. byte[] iv = { 0x72, 0xD8, 0x59, 0x64, 0xD0, 0x23, 0x1E, 0x6F, 0xF9, 0x16, 0x98, 0x61, 0x09, 0xE1, 0x33, 0xE2, 0x62, 0xB7, 0x9D, 0xD2, 0xCD, 0x5B, 0x47, 0xD8 };
  3970. byte[] expected = { 0x0B, 0x3C, 0xDD, 0x1F, 0xCA, 0x36, 0x1C, 0x44, 0x0D, 0xC6, 0xC9, 0xF8, 0xE9, 0x96, 0x33, 0x52, 0x89, 0x66, 0x73, 0x9C, 0x43, 0x27, 0x76, 0xE4, 0x84, 0x4F, 0xEF, 0x68, 0x04, 0x83, 0x68, 0x1A, 0x08, 0xA5, 0x6C, 0x22, 0x83, 0x64, 0xD5, 0x9E, 0x58, 0x00, 0x5F, 0xEB, 0x6A, 0xEF, 0x36, 0xDD, 0xD4, 0xF4, 0x21, 0x9F, 0xAB, 0x87, 0xB3, 0xD0, 0x29, 0x04, 0x19, 0x14, 0xD1, 0xD1, 0x66, 0x37, 0x54, 0xBC, 0x40, 0x43, 0xF6, 0xF1, 0x8A, 0x67 };
  3971. SymmetricAlgorithm algo = Rijndael.Create ();
  3972. algo.Mode = CipherMode.CBC;
  3973. algo.Padding = PaddingMode.PKCS7;
  3974. algo.BlockSize = 192;
  3975. int blockLength = (algo.BlockSize >> 3);
  3976. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  3977. byte[] output = new byte [blockLength * 3];
  3978. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  3979. Encrypt (encryptor, input, output);
  3980. AssertEquals ("Rijndael_k192b192_CBC_PKCS7 Encrypt", expected, output);
  3981. byte[] reverse = new byte [blockLength * 3];
  3982. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  3983. Decrypt (decryptor, output, reverse);
  3984. byte[] original = new byte [input.Length];
  3985. Array.Copy (reverse, 0, original, 0, original.Length);
  3986. AssertEquals ("Rijndael_k192b192_CBC_PKCS7 Decrypt", input, original);
  3987. }
  3988. /* Invalid parameters Rijndael_k192b192_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  3989. /* Invalid parameters Rijndael_k192b192_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  3990. /* Invalid parameters Rijndael_k192b192_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  3991. /* Invalid parameters Rijndael_k192b192_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3992. /* Invalid parameters Rijndael_k192b192_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3993. /* Invalid parameters Rijndael_k192b192_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3994. /* Invalid parameters Rijndael_k192b192_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3995. /* Invalid parameters Rijndael_k192b192_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3996. /* Invalid parameters Rijndael_k192b192_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  3997. [Test]
  3998. public void TestRijndael_k192b256_ECB_None ()
  3999. {
  4000. byte[] key = { 0x07, 0xD5, 0xDE, 0x67, 0xAA, 0x99, 0x89, 0x35, 0x41, 0xAA, 0x04, 0x7B, 0xBB, 0x25, 0x91, 0x88, 0xDA, 0xA9, 0x5F, 0xD6, 0x05, 0xA4, 0xF4, 0x7B };
  4001. // not used for ECB but make the code more uniform
  4002. byte[] iv = { 0x21, 0x43, 0xAF, 0xF7, 0x20, 0x60, 0x95, 0x40, 0x42, 0x57, 0x2E, 0x1D, 0xAC, 0x95, 0x39, 0x71, 0x88, 0xDA, 0xC2, 0x22, 0xF4, 0xEA, 0xC8, 0x6F, 0x3B, 0x73, 0xBC, 0xA5, 0xC9, 0x56, 0x2B, 0x38 };
  4003. byte[] expected = { 0xDA, 0xB8, 0xB7, 0xA7, 0x7D, 0x50, 0x08, 0x6A, 0x57, 0x3C, 0x1E, 0xA4, 0xED, 0xDD, 0x3F, 0x93, 0x99, 0x7E, 0xFC, 0x06, 0x3A, 0x9E, 0xAC, 0x82, 0x16, 0xCA, 0xE5, 0x79, 0x2C, 0xA1, 0xAC, 0x5D, 0xDA, 0xB8, 0xB7, 0xA7, 0x7D, 0x50, 0x08, 0x6A, 0x57, 0x3C, 0x1E, 0xA4, 0xED, 0xDD, 0x3F, 0x93, 0x99, 0x7E, 0xFC, 0x06, 0x3A, 0x9E, 0xAC, 0x82, 0x16, 0xCA, 0xE5, 0x79, 0x2C, 0xA1, 0xAC, 0x5D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4004. SymmetricAlgorithm algo = Rijndael.Create ();
  4005. algo.Mode = CipherMode.ECB;
  4006. algo.Padding = PaddingMode.None;
  4007. algo.BlockSize = 256;
  4008. int blockLength = (algo.BlockSize >> 3);
  4009. byte[] input = new byte [blockLength * 2];
  4010. byte[] output = new byte [blockLength * 3];
  4011. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4012. Encrypt (encryptor, input, output);
  4013. AssertEquals ("Rijndael_k192b256_ECB_None Encrypt", expected, output);
  4014. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4015. byte[] block1 = new byte[blockLength];
  4016. Array.Copy (output, 0, block1, 0, blockLength);
  4017. byte[] block2 = new byte[blockLength];
  4018. Array.Copy (output, blockLength, block2, 0, blockLength);
  4019. AssertEquals ("Rijndael_k192b256_ECB_None b1==b2", block1, block2);
  4020. byte[] reverse = new byte [blockLength * 3];
  4021. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4022. Decrypt (decryptor, output, reverse);
  4023. byte[] original = new byte [input.Length];
  4024. Array.Copy (reverse, 0, original, 0, original.Length);
  4025. AssertEquals ("Rijndael_k192b256_ECB_None Decrypt", input, original);
  4026. }
  4027. [Test]
  4028. public void TestRijndael_k192b256_ECB_Zeros ()
  4029. {
  4030. byte[] key = { 0xE4, 0x87, 0x99, 0x8B, 0xD1, 0x33, 0x03, 0x25, 0x1A, 0xE4, 0x10, 0x6F, 0xC7, 0x7F, 0xC2, 0xDA, 0xAC, 0x99, 0x02, 0xFF, 0x34, 0xEF, 0x10, 0xC0 };
  4031. // not used for ECB but make the code more uniform
  4032. byte[] iv = { 0x67, 0xA7, 0x6E, 0xF5, 0xD8, 0xE2, 0xC3, 0xCB, 0x03, 0xF4, 0x6A, 0x01, 0x71, 0x8E, 0x02, 0xC7, 0x71, 0x73, 0xCF, 0x22, 0x76, 0x15, 0x87, 0x4F, 0x0D, 0x07, 0x43, 0xA6, 0x26, 0xAD, 0x15, 0xDA };
  4033. byte[] expected = { 0xAB, 0x82, 0x14, 0x0D, 0x94, 0x36, 0x61, 0x9D, 0xF9, 0x39, 0xDA, 0x44, 0x34, 0xBA, 0x0D, 0xF5, 0xE6, 0xD2, 0x68, 0x53, 0x60, 0xC6, 0x98, 0x39, 0x4C, 0x90, 0xBE, 0xF6, 0x6E, 0xD8, 0xCB, 0xAA, 0xAB, 0x82, 0x14, 0x0D, 0x94, 0x36, 0x61, 0x9D, 0xF9, 0x39, 0xDA, 0x44, 0x34, 0xBA, 0x0D, 0xF5, 0xE6, 0xD2, 0x68, 0x53, 0x60, 0xC6, 0x98, 0x39, 0x4C, 0x90, 0xBE, 0xF6, 0x6E, 0xD8, 0xCB, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4034. SymmetricAlgorithm algo = Rijndael.Create ();
  4035. algo.Mode = CipherMode.ECB;
  4036. algo.Padding = PaddingMode.Zeros;
  4037. algo.BlockSize = 256;
  4038. int blockLength = (algo.BlockSize >> 3);
  4039. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4040. byte[] output = new byte [blockLength * 3];
  4041. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4042. // some exception can be normal... other not so!
  4043. try {
  4044. Encrypt (encryptor, input, output);
  4045. }
  4046. catch (Exception e) {
  4047. if (e.Message != "Input buffer contains insufficient data. ")
  4048. Assert.Fail ("Rijndael_k192b256_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
  4049. }
  4050. }
  4051. [Test]
  4052. public void TestRijndael_k192b256_ECB_PKCS7 ()
  4053. {
  4054. byte[] key = { 0x15, 0x40, 0x0B, 0xA3, 0xFC, 0x69, 0xF7, 0x2B, 0x55, 0x6F, 0xE9, 0x2C, 0xDA, 0xF8, 0x49, 0xAA, 0x41, 0xB3, 0x3B, 0x61, 0xCA, 0x88, 0x58, 0x19 };
  4055. // not used for ECB but make the code more uniform
  4056. byte[] iv = { 0xCB, 0x37, 0xA1, 0x13, 0x44, 0x0D, 0x72, 0xC0, 0x8B, 0x0E, 0x62, 0xDB, 0xAF, 0x8D, 0x00, 0xC1, 0xF6, 0xF7, 0x2B, 0x60, 0x58, 0x09, 0x46, 0x95, 0x28, 0x9C, 0x87, 0x30, 0xE9, 0xA2, 0x95, 0x80 };
  4057. byte[] expected = { 0xBE, 0x93, 0xB9, 0xEF, 0xC7, 0x57, 0x71, 0xD9, 0xFA, 0x17, 0x6F, 0x9D, 0xBE, 0x2A, 0xF2, 0xE8, 0x17, 0x39, 0x61, 0x6A, 0xEE, 0x51, 0x6D, 0x65, 0xEE, 0x27, 0x50, 0x82, 0xFB, 0x91, 0xFC, 0xDB, 0xBE, 0x93, 0xB9, 0xEF, 0xC7, 0x57, 0x71, 0xD9, 0xFA, 0x17, 0x6F, 0x9D, 0xBE, 0x2A, 0xF2, 0xE8, 0x17, 0x39, 0x61, 0x6A, 0xEE, 0x51, 0x6D, 0x65, 0xEE, 0x27, 0x50, 0x82, 0xFB, 0x91, 0xFC, 0xDB, 0x72, 0x86, 0xCA, 0xC3, 0x5C, 0x0F, 0x55, 0x79, 0x32, 0x96, 0x07, 0x86, 0xD7, 0xF3, 0x23, 0x53, 0xFC, 0x63, 0xBC, 0xD1, 0x76, 0x33, 0x7F, 0x72, 0xF1, 0x0A, 0x60, 0x7F, 0xB2, 0x6A, 0xBA, 0x0B };
  4058. SymmetricAlgorithm algo = Rijndael.Create ();
  4059. algo.Mode = CipherMode.ECB;
  4060. algo.Padding = PaddingMode.PKCS7;
  4061. algo.BlockSize = 256;
  4062. int blockLength = (algo.BlockSize >> 3);
  4063. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4064. byte[] output = new byte [blockLength * 3];
  4065. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4066. Encrypt (encryptor, input, output);
  4067. AssertEquals ("Rijndael_k192b256_ECB_PKCS7 Encrypt", expected, output);
  4068. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4069. byte[] block1 = new byte[blockLength];
  4070. Array.Copy (output, 0, block1, 0, blockLength);
  4071. byte[] block2 = new byte[blockLength];
  4072. Array.Copy (output, blockLength, block2, 0, blockLength);
  4073. AssertEquals ("Rijndael_k192b256_ECB_PKCS7 b1==b2", block1, block2);
  4074. byte[] reverse = new byte [blockLength * 3];
  4075. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4076. Decrypt (decryptor, output, reverse);
  4077. byte[] original = new byte [input.Length];
  4078. Array.Copy (reverse, 0, original, 0, original.Length);
  4079. AssertEquals ("Rijndael_k192b256_ECB_PKCS7 Decrypt", input, original);
  4080. }
  4081. [Test]
  4082. public void TestRijndael_k192b256_CBC_None ()
  4083. {
  4084. byte[] key = { 0x3E, 0xFE, 0x6E, 0xF9, 0x4A, 0xCE, 0x96, 0xB7, 0xDD, 0x34, 0x15, 0x20, 0x85, 0xEA, 0x4B, 0x41, 0xEC, 0xFC, 0xDD, 0x37, 0xD9, 0xF1, 0x9A, 0xE4 };
  4085. byte[] iv = { 0x04, 0x89, 0x29, 0x3F, 0x6A, 0x54, 0xED, 0xF3, 0x8D, 0x1F, 0x62, 0xC8, 0x8C, 0x05, 0x89, 0x62, 0xC2, 0x5E, 0xDB, 0xCA, 0x60, 0xE0, 0x17, 0x03, 0xE5, 0x69, 0x6B, 0x84, 0x44, 0x2C, 0x68, 0xB0 };
  4086. byte[] expected = { 0xA5, 0xCB, 0x68, 0xA8, 0x8A, 0xE0, 0xFD, 0x68, 0xB3, 0x75, 0x51, 0xB8, 0x46, 0x08, 0xEC, 0xE3, 0xDA, 0xE9, 0xBF, 0x49, 0x65, 0x74, 0x84, 0xB7, 0x9A, 0x60, 0x89, 0x43, 0xF2, 0x35, 0xC2, 0xAB, 0x3F, 0xD3, 0x0A, 0x9A, 0x6A, 0x3D, 0xB4, 0x2C, 0xB0, 0x8B, 0x32, 0x28, 0x2B, 0x57, 0x8F, 0x2E, 0xCF, 0x37, 0x24, 0x9B, 0xB5, 0x3B, 0xE6, 0x5E, 0xA7, 0xB9, 0x10, 0x99, 0x36, 0xA7, 0x9C, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4087. SymmetricAlgorithm algo = Rijndael.Create ();
  4088. algo.Mode = CipherMode.CBC;
  4089. algo.Padding = PaddingMode.None;
  4090. algo.BlockSize = 256;
  4091. int blockLength = (algo.BlockSize >> 3);
  4092. byte[] input = new byte [blockLength * 2];
  4093. byte[] output = new byte [blockLength * 3];
  4094. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4095. Encrypt (encryptor, input, output);
  4096. AssertEquals ("Rijndael_k192b256_CBC_None Encrypt", expected, output);
  4097. byte[] reverse = new byte [blockLength * 3];
  4098. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4099. Decrypt (decryptor, output, reverse);
  4100. byte[] original = new byte [input.Length];
  4101. Array.Copy (reverse, 0, original, 0, original.Length);
  4102. AssertEquals ("Rijndael_k192b256_CBC_None Decrypt", input, original);
  4103. }
  4104. [Test]
  4105. public void TestRijndael_k192b256_CBC_Zeros ()
  4106. {
  4107. byte[] key = { 0xB6, 0x93, 0x96, 0xA4, 0xD3, 0xE5, 0x73, 0x81, 0x17, 0x7B, 0x68, 0x92, 0x3A, 0xAF, 0x20, 0x45, 0x75, 0xBA, 0x43, 0x3C, 0x5E, 0x46, 0xF6, 0x15 };
  4108. byte[] iv = { 0x17, 0x23, 0x3C, 0x0C, 0x51, 0xE2, 0x02, 0x8C, 0xC8, 0xD5, 0x5B, 0x00, 0x20, 0xE0, 0x2A, 0xC4, 0x4F, 0xCF, 0x4C, 0x1A, 0xCD, 0x59, 0x6C, 0x2D, 0x50, 0x8E, 0xF9, 0xA0, 0x3F, 0xFD, 0x81, 0xB5 };
  4109. byte[] expected = { 0x93, 0xF0, 0xFC, 0x25, 0x3D, 0x6D, 0x74, 0x1F, 0x88, 0xC9, 0x9F, 0xE6, 0x3A, 0x24, 0x13, 0xE1, 0x7C, 0xEF, 0x79, 0xC6, 0x56, 0x87, 0xCB, 0xD0, 0xB7, 0x15, 0x91, 0x21, 0x7E, 0x17, 0xA2, 0xF1, 0xA6, 0xDA, 0xCA, 0xDF, 0x14, 0x88, 0x5C, 0x35, 0x13, 0x1E, 0xCD, 0x2E, 0xB0, 0xC8, 0x7E, 0x4A, 0xBE, 0xD9, 0x3B, 0x15, 0x8D, 0xC9, 0x2A, 0xC5, 0x2D, 0x7C, 0x24, 0xF3, 0xB4, 0x43, 0xDE, 0xBB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4110. SymmetricAlgorithm algo = Rijndael.Create ();
  4111. algo.Mode = CipherMode.CBC;
  4112. algo.Padding = PaddingMode.Zeros;
  4113. algo.BlockSize = 256;
  4114. int blockLength = (algo.BlockSize >> 3);
  4115. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4116. byte[] output = new byte [blockLength * 3];
  4117. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4118. // some exception can be normal... other not so!
  4119. try {
  4120. Encrypt (encryptor, input, output);
  4121. }
  4122. catch (Exception e) {
  4123. if (e.Message != "Input buffer contains insufficient data. ")
  4124. Assert.Fail ("Rijndael_k192b256_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
  4125. }
  4126. }
  4127. [Test]
  4128. public void TestRijndael_k192b256_CBC_PKCS7 ()
  4129. {
  4130. byte[] key = { 0x5B, 0x58, 0xA2, 0xF7, 0x12, 0x9B, 0xF1, 0x09, 0x14, 0x98, 0x6F, 0x75, 0x69, 0xF0, 0xB5, 0x02, 0xDE, 0x7E, 0xF3, 0xBF, 0x56, 0x69, 0xEC, 0x5C };
  4131. byte[] iv = { 0x2E, 0x75, 0x1D, 0x3D, 0x2C, 0x01, 0x0B, 0x7A, 0xE6, 0x7C, 0x63, 0xB4, 0x1A, 0xF2, 0x48, 0x62, 0xF2, 0x7A, 0xF0, 0xFA, 0xC9, 0xAD, 0xFF, 0x88, 0x45, 0xE4, 0xFE, 0x5A, 0xA2, 0x87, 0x7A, 0x16 };
  4132. byte[] expected = { 0xD2, 0x9B, 0x71, 0x41, 0xAF, 0xD2, 0x66, 0x52, 0xB1, 0x45, 0xEA, 0x7C, 0xFD, 0xF8, 0xD5, 0x13, 0xAE, 0x3E, 0xCE, 0x84, 0x5B, 0x2A, 0xBB, 0xEA, 0x11, 0xFC, 0x45, 0x98, 0x71, 0xC0, 0x2A, 0x9B, 0xD4, 0x4B, 0xDA, 0xC9, 0xED, 0x8A, 0x86, 0x0B, 0xC4, 0x53, 0x32, 0x46, 0x00, 0x59, 0x12, 0x58, 0x12, 0x8E, 0x95, 0x20, 0xA8, 0xE0, 0x96, 0xEB, 0x62, 0xAF, 0x09, 0x04, 0xE7, 0x00, 0xCE, 0x14, 0x7D, 0x62, 0xE2, 0xE8, 0x85, 0x35, 0x7B, 0x11, 0xCD, 0xA9, 0xA4, 0x48, 0x28, 0x9A, 0xA1, 0x5A, 0x3A, 0x0D, 0x24, 0x00, 0x14, 0xEE, 0x1D, 0x99, 0x46, 0x29, 0x57, 0x56, 0x12, 0x63, 0x08, 0xB1 };
  4133. SymmetricAlgorithm algo = Rijndael.Create ();
  4134. algo.Mode = CipherMode.CBC;
  4135. algo.Padding = PaddingMode.PKCS7;
  4136. algo.BlockSize = 256;
  4137. int blockLength = (algo.BlockSize >> 3);
  4138. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4139. byte[] output = new byte [blockLength * 3];
  4140. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4141. Encrypt (encryptor, input, output);
  4142. AssertEquals ("Rijndael_k192b256_CBC_PKCS7 Encrypt", expected, output);
  4143. byte[] reverse = new byte [blockLength * 3];
  4144. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4145. Decrypt (decryptor, output, reverse);
  4146. byte[] original = new byte [input.Length];
  4147. Array.Copy (reverse, 0, original, 0, original.Length);
  4148. AssertEquals ("Rijndael_k192b256_CBC_PKCS7 Decrypt", input, original);
  4149. }
  4150. /* Invalid parameters Rijndael_k192b256_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  4151. /* Invalid parameters Rijndael_k192b256_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  4152. /* Invalid parameters Rijndael_k192b256_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  4153. /* Invalid parameters Rijndael_k192b256_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4154. /* Invalid parameters Rijndael_k192b256_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4155. /* Invalid parameters Rijndael_k192b256_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4156. /* Invalid parameters Rijndael_k192b256_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4157. /* Invalid parameters Rijndael_k192b256_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4158. /* Invalid parameters Rijndael_k192b256_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4159. [Test]
  4160. public void TestRijndael_k256b128_ECB_None ()
  4161. {
  4162. byte[] key = { 0x5B, 0xA0, 0xA9, 0x6B, 0x20, 0x14, 0xF4, 0x4E, 0x2E, 0x9A, 0x34, 0x84, 0xD3, 0xB9, 0x62, 0x45, 0xB1, 0x98, 0x35, 0xAE, 0xA7, 0xED, 0x80, 0x67, 0xE2, 0x77, 0xC4, 0xD5, 0x6B, 0xBD, 0x6E, 0xCF };
  4163. // not used for ECB but make the code more uniform
  4164. byte[] iv = { 0xF5, 0xBD, 0x6D, 0xDF, 0x0C, 0x8E, 0xC5, 0x39, 0x25, 0xBE, 0x1A, 0x80, 0xF8, 0x79, 0xEC, 0x93 };
  4165. byte[] expected = { 0x54, 0xF5, 0x87, 0xE7, 0x73, 0xB7, 0x04, 0xBF, 0xBB, 0x16, 0x3D, 0x5A, 0xC0, 0x68, 0x7C, 0x17, 0x54, 0xF5, 0x87, 0xE7, 0x73, 0xB7, 0x04, 0xBF, 0xBB, 0x16, 0x3D, 0x5A, 0xC0, 0x68, 0x7C, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4166. SymmetricAlgorithm algo = Rijndael.Create ();
  4167. algo.Mode = CipherMode.ECB;
  4168. algo.Padding = PaddingMode.None;
  4169. algo.BlockSize = 128;
  4170. int blockLength = (algo.BlockSize >> 3);
  4171. byte[] input = new byte [blockLength * 2];
  4172. byte[] output = new byte [blockLength * 3];
  4173. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4174. Encrypt (encryptor, input, output);
  4175. AssertEquals ("Rijndael_k256b128_ECB_None Encrypt", expected, output);
  4176. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4177. byte[] block1 = new byte[blockLength];
  4178. Array.Copy (output, 0, block1, 0, blockLength);
  4179. byte[] block2 = new byte[blockLength];
  4180. Array.Copy (output, blockLength, block2, 0, blockLength);
  4181. AssertEquals ("Rijndael_k256b128_ECB_None b1==b2", block1, block2);
  4182. byte[] reverse = new byte [blockLength * 3];
  4183. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4184. Decrypt (decryptor, output, reverse);
  4185. byte[] original = new byte [input.Length];
  4186. Array.Copy (reverse, 0, original, 0, original.Length);
  4187. AssertEquals ("Rijndael_k256b128_ECB_None Decrypt", input, original);
  4188. }
  4189. [Test]
  4190. public void TestRijndael_k256b128_ECB_Zeros ()
  4191. {
  4192. byte[] key = { 0x77, 0xE1, 0xB2, 0xF9, 0x14, 0xF0, 0x77, 0xCE, 0xDB, 0x28, 0xD4, 0xA5, 0x0E, 0xA6, 0x73, 0x23, 0xD8, 0x46, 0xB7, 0x1A, 0x16, 0x92, 0xDB, 0x7E, 0x80, 0xDF, 0x5E, 0x9A, 0x16, 0x08, 0xFF, 0x6D };
  4193. // not used for ECB but make the code more uniform
  4194. byte[] iv = { 0x48, 0xEC, 0x4A, 0x12, 0xAC, 0x9C, 0xB5, 0x72, 0xEB, 0x12, 0x14, 0xFB, 0xE1, 0x6D, 0xCF, 0xA3 };
  4195. byte[] expected = { 0x82, 0x6C, 0xC7, 0xA6, 0xC2, 0x57, 0x07, 0xF9, 0x2F, 0x92, 0x95, 0x90, 0x65, 0xFA, 0x1D, 0xFA, 0x82, 0x6C, 0xC7, 0xA6, 0xC2, 0x57, 0x07, 0xF9, 0x2F, 0x92, 0x95, 0x90, 0x65, 0xFA, 0x1D, 0xFA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4196. SymmetricAlgorithm algo = Rijndael.Create ();
  4197. algo.Mode = CipherMode.ECB;
  4198. algo.Padding = PaddingMode.Zeros;
  4199. algo.BlockSize = 128;
  4200. int blockLength = (algo.BlockSize >> 3);
  4201. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4202. byte[] output = new byte [blockLength * 3];
  4203. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4204. // some exception can be normal... other not so!
  4205. try {
  4206. Encrypt (encryptor, input, output);
  4207. }
  4208. catch (Exception e) {
  4209. if (e.Message != "Input buffer contains insufficient data. ")
  4210. Assert.Fail ("Rijndael_k256b128_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
  4211. }
  4212. }
  4213. [Test]
  4214. public void TestRijndael_k256b128_ECB_PKCS7 ()
  4215. {
  4216. byte[] key = { 0x19, 0xC2, 0x2D, 0x12, 0x57, 0x2B, 0xEF, 0x0C, 0xA2, 0xC7, 0x26, 0x7E, 0x35, 0xAD, 0xC5, 0x12, 0x53, 0x5D, 0xEE, 0xD7, 0x69, 0xC3, 0xB4, 0x0D, 0x9B, 0xEF, 0x36, 0xF7, 0xB2, 0xF2, 0xB0, 0x37 };
  4217. // not used for ECB but make the code more uniform
  4218. byte[] iv = { 0xCF, 0x8D, 0xBE, 0xE0, 0x41, 0xC6, 0xB9, 0xB5, 0x2D, 0x8A, 0x59, 0x92, 0x82, 0xF4, 0xE8, 0x74 };
  4219. byte[] expected = { 0xAD, 0x99, 0x9A, 0xE2, 0x5B, 0xE7, 0xFB, 0x74, 0xE8, 0xAB, 0xEE, 0x5D, 0xCA, 0x0F, 0x0A, 0x7A, 0xAD, 0x99, 0x9A, 0xE2, 0x5B, 0xE7, 0xFB, 0x74, 0xE8, 0xAB, 0xEE, 0x5D, 0xCA, 0x0F, 0x0A, 0x7A, 0x8F, 0xAD, 0xBB, 0xC2, 0x18, 0xB8, 0xF0, 0xFF, 0x59, 0x7D, 0xF8, 0xF1, 0x6A, 0x21, 0x9C, 0xF3 };
  4220. SymmetricAlgorithm algo = Rijndael.Create ();
  4221. algo.Mode = CipherMode.ECB;
  4222. algo.Padding = PaddingMode.PKCS7;
  4223. algo.BlockSize = 128;
  4224. int blockLength = (algo.BlockSize >> 3);
  4225. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4226. byte[] output = new byte [blockLength * 3];
  4227. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4228. Encrypt (encryptor, input, output);
  4229. AssertEquals ("Rijndael_k256b128_ECB_PKCS7 Encrypt", expected, output);
  4230. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4231. byte[] block1 = new byte[blockLength];
  4232. Array.Copy (output, 0, block1, 0, blockLength);
  4233. byte[] block2 = new byte[blockLength];
  4234. Array.Copy (output, blockLength, block2, 0, blockLength);
  4235. AssertEquals ("Rijndael_k256b128_ECB_PKCS7 b1==b2", block1, block2);
  4236. byte[] reverse = new byte [blockLength * 3];
  4237. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4238. Decrypt (decryptor, output, reverse);
  4239. byte[] original = new byte [input.Length];
  4240. Array.Copy (reverse, 0, original, 0, original.Length);
  4241. AssertEquals ("Rijndael_k256b128_ECB_PKCS7 Decrypt", input, original);
  4242. }
  4243. [Test]
  4244. public void TestRijndael_k256b128_CBC_None ()
  4245. {
  4246. byte[] key = { 0xE8, 0x74, 0x24, 0x77, 0x2B, 0xBE, 0x6C, 0x99, 0x2E, 0xFC, 0xB5, 0x85, 0xC9, 0xA1, 0xD7, 0x9C, 0x24, 0xF1, 0x86, 0x0B, 0xEA, 0xAB, 0xCB, 0x06, 0x47, 0x2E, 0x26, 0x6C, 0xAF, 0x24, 0x87, 0xA7 };
  4247. byte[] iv = { 0x15, 0x7E, 0xA5, 0xE5, 0x47, 0xFA, 0x40, 0x30, 0x0A, 0xAA, 0x9E, 0x68, 0x8E, 0x4D, 0x2D, 0xA4 };
  4248. byte[] expected = { 0xEF, 0x05, 0x1C, 0x5C, 0xEA, 0xED, 0x34, 0x28, 0x9E, 0x21, 0x9C, 0x2C, 0x96, 0xF5, 0xF7, 0xDA, 0x55, 0xD4, 0x88, 0x0A, 0x73, 0xF1, 0x8D, 0xBC, 0x8F, 0x17, 0x26, 0x86, 0x8A, 0xC1, 0x4B, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4249. SymmetricAlgorithm algo = Rijndael.Create ();
  4250. algo.Mode = CipherMode.CBC;
  4251. algo.Padding = PaddingMode.None;
  4252. algo.BlockSize = 128;
  4253. int blockLength = (algo.BlockSize >> 3);
  4254. byte[] input = new byte [blockLength * 2];
  4255. byte[] output = new byte [blockLength * 3];
  4256. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4257. Encrypt (encryptor, input, output);
  4258. AssertEquals ("Rijndael_k256b128_CBC_None Encrypt", expected, output);
  4259. byte[] reverse = new byte [blockLength * 3];
  4260. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4261. Decrypt (decryptor, output, reverse);
  4262. byte[] original = new byte [input.Length];
  4263. Array.Copy (reverse, 0, original, 0, original.Length);
  4264. AssertEquals ("Rijndael_k256b128_CBC_None Decrypt", input, original);
  4265. }
  4266. [Test]
  4267. public void TestRijndael_k256b128_CBC_Zeros ()
  4268. {
  4269. byte[] key = { 0x50, 0x54, 0x8C, 0x92, 0xE5, 0xFD, 0x08, 0x03, 0xEA, 0x15, 0xBB, 0xB9, 0x39, 0x8B, 0x6E, 0xF0, 0xF5, 0x64, 0x49, 0x0E, 0x0F, 0x8F, 0x41, 0xF9, 0xA6, 0x1E, 0xD4, 0xD2, 0xB6, 0xF2, 0xB6, 0x4B };
  4270. byte[] iv = { 0x32, 0x9B, 0x60, 0xF7, 0xBE, 0x0F, 0x5F, 0xA5, 0xD2, 0x7A, 0x1F, 0xB4, 0x01, 0x76, 0xD1, 0xCD };
  4271. byte[] expected = { 0x6C, 0x55, 0xAD, 0x57, 0xEE, 0x78, 0x1D, 0x69, 0x82, 0x8D, 0xE5, 0x52, 0x4C, 0x76, 0xD7, 0xF1, 0xFA, 0xFC, 0xD1, 0x2D, 0xDC, 0x0F, 0xE4, 0x4F, 0xF0, 0xE5, 0xB0, 0x2B, 0x28, 0xBF, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4272. SymmetricAlgorithm algo = Rijndael.Create ();
  4273. algo.Mode = CipherMode.CBC;
  4274. algo.Padding = PaddingMode.Zeros;
  4275. algo.BlockSize = 128;
  4276. int blockLength = (algo.BlockSize >> 3);
  4277. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4278. byte[] output = new byte [blockLength * 3];
  4279. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4280. // some exception can be normal... other not so!
  4281. try {
  4282. Encrypt (encryptor, input, output);
  4283. }
  4284. catch (Exception e) {
  4285. if (e.Message != "Input buffer contains insufficient data. ")
  4286. Assert.Fail ("Rijndael_k256b128_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
  4287. }
  4288. }
  4289. [Test]
  4290. public void TestRijndael_k256b128_CBC_PKCS7 ()
  4291. {
  4292. byte[] key = { 0x8B, 0x8B, 0x4C, 0x04, 0x8C, 0x16, 0x16, 0x91, 0xBE, 0x79, 0x35, 0xF6, 0x26, 0x01, 0xF8, 0x06, 0x8F, 0xC7, 0x6D, 0xD6, 0xFE, 0xDE, 0xCF, 0xD8, 0xDC, 0xE1, 0x97, 0x9D, 0xA9, 0xD0, 0x96, 0x86 };
  4293. byte[] iv = { 0xA0, 0xF5, 0x25, 0xE5, 0x17, 0xEA, 0x37, 0x18, 0x17, 0x56, 0x26, 0x1C, 0x63, 0x95, 0xC3, 0xAD };
  4294. byte[] expected = { 0x42, 0x33, 0x8E, 0xDE, 0x2E, 0xDA, 0xC9, 0xC6, 0x97, 0xA2, 0xAE, 0xE1, 0x15, 0x00, 0xDE, 0x4A, 0x39, 0x0B, 0xEB, 0xC8, 0xF9, 0x9F, 0x00, 0x05, 0xCF, 0xB5, 0x32, 0x46, 0x91, 0xFC, 0x28, 0x23, 0xF4, 0xC5, 0xCE, 0x42, 0x63, 0x3F, 0x82, 0x7D, 0x2A, 0xC4, 0xB5, 0x09, 0x67, 0xC7, 0x33, 0x3F };
  4295. SymmetricAlgorithm algo = Rijndael.Create ();
  4296. algo.Mode = CipherMode.CBC;
  4297. algo.Padding = PaddingMode.PKCS7;
  4298. algo.BlockSize = 128;
  4299. int blockLength = (algo.BlockSize >> 3);
  4300. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4301. byte[] output = new byte [blockLength * 3];
  4302. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4303. Encrypt (encryptor, input, output);
  4304. AssertEquals ("Rijndael_k256b128_CBC_PKCS7 Encrypt", expected, output);
  4305. byte[] reverse = new byte [blockLength * 3];
  4306. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4307. Decrypt (decryptor, output, reverse);
  4308. byte[] original = new byte [input.Length];
  4309. Array.Copy (reverse, 0, original, 0, original.Length);
  4310. AssertEquals ("Rijndael_k256b128_CBC_PKCS7 Decrypt", input, original);
  4311. }
  4312. /* Invalid parameters Rijndael_k256b128_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  4313. /* Invalid parameters Rijndael_k256b128_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  4314. /* Invalid parameters Rijndael_k256b128_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  4315. /* Invalid parameters Rijndael_k256b128_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4316. /* Invalid parameters Rijndael_k256b128_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4317. /* Invalid parameters Rijndael_k256b128_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4318. /* Invalid parameters Rijndael_k256b128_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4319. /* Invalid parameters Rijndael_k256b128_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4320. /* Invalid parameters Rijndael_k256b128_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4321. [Test]
  4322. public void TestRijndael_k256b192_ECB_None ()
  4323. {
  4324. byte[] key = { 0xE3, 0x43, 0x35, 0xDB, 0xB7, 0xC8, 0x24, 0xBF, 0x25, 0xD2, 0xA3, 0xCD, 0x70, 0xEB, 0x6B, 0xB7, 0x6D, 0x64, 0xF4, 0xB8, 0xA0, 0x56, 0x52, 0xFB, 0x3A, 0x09, 0xD4, 0xD9, 0x4F, 0x09, 0x19, 0xAF };
  4325. // not used for ECB but make the code more uniform
  4326. byte[] iv = { 0xDB, 0x11, 0xE4, 0x50, 0x12, 0x29, 0xC8, 0x63, 0x61, 0xEC, 0xFE, 0xD3, 0xFE, 0xA2, 0x19, 0xE0, 0xEC, 0x2F, 0x56, 0x69, 0xB7, 0x41, 0x56, 0xB0 };
  4327. byte[] expected = { 0x66, 0xD0, 0x72, 0x3B, 0xFA, 0x3F, 0x27, 0x81, 0xB6, 0x91, 0x78, 0x7A, 0x4C, 0xD0, 0xA0, 0x4C, 0x93, 0x56, 0x51, 0xA3, 0xE0, 0x69, 0x63, 0xAF, 0x66, 0xD0, 0x72, 0x3B, 0xFA, 0x3F, 0x27, 0x81, 0xB6, 0x91, 0x78, 0x7A, 0x4C, 0xD0, 0xA0, 0x4C, 0x93, 0x56, 0x51, 0xA3, 0xE0, 0x69, 0x63, 0xAF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4328. SymmetricAlgorithm algo = Rijndael.Create ();
  4329. algo.Mode = CipherMode.ECB;
  4330. algo.Padding = PaddingMode.None;
  4331. algo.BlockSize = 192;
  4332. int blockLength = (algo.BlockSize >> 3);
  4333. byte[] input = new byte [blockLength * 2];
  4334. byte[] output = new byte [blockLength * 3];
  4335. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4336. Encrypt (encryptor, input, output);
  4337. AssertEquals ("Rijndael_k256b192_ECB_None Encrypt", expected, output);
  4338. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4339. byte[] block1 = new byte[blockLength];
  4340. Array.Copy (output, 0, block1, 0, blockLength);
  4341. byte[] block2 = new byte[blockLength];
  4342. Array.Copy (output, blockLength, block2, 0, blockLength);
  4343. AssertEquals ("Rijndael_k256b192_ECB_None b1==b2", block1, block2);
  4344. byte[] reverse = new byte [blockLength * 3];
  4345. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4346. Decrypt (decryptor, output, reverse);
  4347. byte[] original = new byte [input.Length];
  4348. Array.Copy (reverse, 0, original, 0, original.Length);
  4349. AssertEquals ("Rijndael_k256b192_ECB_None Decrypt", input, original);
  4350. }
  4351. [Test]
  4352. public void TestRijndael_k256b192_ECB_Zeros ()
  4353. {
  4354. byte[] key = { 0xCF, 0xAC, 0xFC, 0x30, 0x6C, 0x01, 0x16, 0x8A, 0x82, 0x52, 0x52, 0xC0, 0xC6, 0xAC, 0x1E, 0x60, 0x93, 0x17, 0x0A, 0x0C, 0x87, 0xE1, 0x4A, 0x78, 0xD9, 0xA6, 0x6B, 0xAF, 0x24, 0xF7, 0x8F, 0xED };
  4355. // not used for ECB but make the code more uniform
  4356. byte[] iv = { 0x99, 0x2B, 0x6B, 0x30, 0x56, 0x13, 0x2E, 0xE3, 0x3B, 0x2B, 0xC1, 0xA9, 0x4B, 0x3B, 0xD9, 0xC3, 0x7B, 0xA7, 0x4F, 0x26, 0xC9, 0x62, 0xC9, 0x66 };
  4357. byte[] expected = { 0x22, 0x6B, 0xFA, 0x34, 0x8E, 0x09, 0xC2, 0xDF, 0xCA, 0x6C, 0xF5, 0x1F, 0xD2, 0xDC, 0x01, 0xC6, 0x3B, 0x73, 0x3F, 0x64, 0x91, 0x9F, 0xF6, 0xD3, 0x22, 0x6B, 0xFA, 0x34, 0x8E, 0x09, 0xC2, 0xDF, 0xCA, 0x6C, 0xF5, 0x1F, 0xD2, 0xDC, 0x01, 0xC6, 0x3B, 0x73, 0x3F, 0x64, 0x91, 0x9F, 0xF6, 0xD3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4358. SymmetricAlgorithm algo = Rijndael.Create ();
  4359. algo.Mode = CipherMode.ECB;
  4360. algo.Padding = PaddingMode.Zeros;
  4361. algo.BlockSize = 192;
  4362. int blockLength = (algo.BlockSize >> 3);
  4363. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4364. byte[] output = new byte [blockLength * 3];
  4365. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4366. // some exception can be normal... other not so!
  4367. try {
  4368. Encrypt (encryptor, input, output);
  4369. }
  4370. catch (Exception e) {
  4371. if (e.Message != "Input buffer contains insufficient data. ")
  4372. Assert.Fail ("Rijndael_k256b192_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
  4373. }
  4374. }
  4375. [Test]
  4376. public void TestRijndael_k256b192_ECB_PKCS7 ()
  4377. {
  4378. byte[] key = { 0x17, 0xF9, 0x4A, 0x56, 0x22, 0x77, 0x20, 0x33, 0x48, 0xCB, 0x06, 0x86, 0x44, 0x02, 0xCF, 0x52, 0xDA, 0x22, 0x36, 0x07, 0xE9, 0x9F, 0x3A, 0x28, 0x3E, 0xCB, 0x49, 0x51, 0xA4, 0x67, 0x60, 0xF3 };
  4379. // not used for ECB but make the code more uniform
  4380. byte[] iv = { 0x07, 0x77, 0x47, 0xC3, 0x49, 0x85, 0x7D, 0xB7, 0xED, 0xF3, 0x0D, 0x3F, 0x0F, 0xDC, 0xA6, 0x3E, 0x01, 0x53, 0x4D, 0x61, 0xEC, 0x06, 0xB4, 0xA0 };
  4381. byte[] expected = { 0xA0, 0x34, 0x6F, 0xFD, 0x84, 0xA3, 0x54, 0xC0, 0x7E, 0xCC, 0x7D, 0x02, 0xE5, 0xDA, 0x79, 0x4E, 0xC6, 0xEB, 0xCE, 0x42, 0xD2, 0xBE, 0x68, 0x0F, 0xA0, 0x34, 0x6F, 0xFD, 0x84, 0xA3, 0x54, 0xC0, 0x7E, 0xCC, 0x7D, 0x02, 0xE5, 0xDA, 0x79, 0x4E, 0xC6, 0xEB, 0xCE, 0x42, 0xD2, 0xBE, 0x68, 0x0F, 0xBC, 0x22, 0x09, 0x5B, 0xFA, 0x92, 0x7E, 0xD8, 0xFF, 0x6A, 0xDD, 0x43, 0x63, 0x72, 0x23, 0xBA, 0xF9, 0xC8, 0x06, 0x3F, 0x51, 0xE8, 0x14, 0xE7 };
  4382. SymmetricAlgorithm algo = Rijndael.Create ();
  4383. algo.Mode = CipherMode.ECB;
  4384. algo.Padding = PaddingMode.PKCS7;
  4385. algo.BlockSize = 192;
  4386. int blockLength = (algo.BlockSize >> 3);
  4387. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4388. byte[] output = new byte [blockLength * 3];
  4389. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4390. Encrypt (encryptor, input, output);
  4391. AssertEquals ("Rijndael_k256b192_ECB_PKCS7 Encrypt", expected, output);
  4392. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4393. byte[] block1 = new byte[blockLength];
  4394. Array.Copy (output, 0, block1, 0, blockLength);
  4395. byte[] block2 = new byte[blockLength];
  4396. Array.Copy (output, blockLength, block2, 0, blockLength);
  4397. AssertEquals ("Rijndael_k256b192_ECB_PKCS7 b1==b2", block1, block2);
  4398. byte[] reverse = new byte [blockLength * 3];
  4399. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4400. Decrypt (decryptor, output, reverse);
  4401. byte[] original = new byte [input.Length];
  4402. Array.Copy (reverse, 0, original, 0, original.Length);
  4403. AssertEquals ("Rijndael_k256b192_ECB_PKCS7 Decrypt", input, original);
  4404. }
  4405. [Test]
  4406. public void TestRijndael_k256b192_CBC_None ()
  4407. {
  4408. byte[] key = { 0x7A, 0x26, 0xAB, 0x32, 0x31, 0x49, 0x69, 0x3D, 0x68, 0x5A, 0xAC, 0x1B, 0x63, 0x85, 0x5A, 0x3D, 0xC4, 0xDE, 0xA8, 0x76, 0x00, 0x26, 0x78, 0x31, 0xB6, 0x30, 0xD8, 0xCB, 0x7E, 0xE7, 0xE9, 0x5B };
  4409. byte[] iv = { 0x9D, 0x7B, 0xD5, 0x59, 0xCA, 0x42, 0xCB, 0x2F, 0x02, 0x65, 0xFE, 0x85, 0x63, 0xAE, 0x14, 0x4F, 0x69, 0xAA, 0xC2, 0xAF, 0x06, 0xF0, 0x48, 0x4F };
  4410. byte[] expected = { 0x6C, 0x03, 0x84, 0x1C, 0x4E, 0xE0, 0x05, 0x67, 0xEA, 0x8D, 0x1C, 0x41, 0xFD, 0xC2, 0x90, 0x0E, 0xB9, 0xAA, 0xE5, 0xA0, 0x41, 0x62, 0xFE, 0xD8, 0x57, 0xA1, 0xCE, 0x33, 0x22, 0x09, 0xDB, 0x3B, 0xD7, 0x0A, 0x68, 0x61, 0x76, 0xB9, 0x8F, 0x7E, 0xE8, 0xD9, 0xA0, 0x46, 0x2B, 0x15, 0xC3, 0xF9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4411. SymmetricAlgorithm algo = Rijndael.Create ();
  4412. algo.Mode = CipherMode.CBC;
  4413. algo.Padding = PaddingMode.None;
  4414. algo.BlockSize = 192;
  4415. int blockLength = (algo.BlockSize >> 3);
  4416. byte[] input = new byte [blockLength * 2];
  4417. byte[] output = new byte [blockLength * 3];
  4418. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4419. Encrypt (encryptor, input, output);
  4420. AssertEquals ("Rijndael_k256b192_CBC_None Encrypt", expected, output);
  4421. byte[] reverse = new byte [blockLength * 3];
  4422. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4423. Decrypt (decryptor, output, reverse);
  4424. byte[] original = new byte [input.Length];
  4425. Array.Copy (reverse, 0, original, 0, original.Length);
  4426. AssertEquals ("Rijndael_k256b192_CBC_None Decrypt", input, original);
  4427. }
  4428. [Test]
  4429. public void TestRijndael_k256b192_CBC_Zeros ()
  4430. {
  4431. byte[] key = { 0x35, 0x14, 0xF8, 0xDB, 0xB0, 0x84, 0x94, 0xD3, 0xDD, 0xE1, 0xB3, 0x21, 0x44, 0xE2, 0x9C, 0x65, 0x0A, 0x4A, 0x28, 0x7C, 0xD7, 0xD4, 0x9F, 0x49, 0x05, 0x23, 0x2C, 0xB2, 0x65, 0x17, 0x44, 0x2E };
  4432. byte[] iv = { 0xD8, 0xA5, 0x77, 0x5C, 0x54, 0x79, 0x57, 0xE2, 0xBD, 0xF7, 0xD1, 0xF1, 0x6F, 0x52, 0x99, 0xBE, 0x04, 0x5E, 0x75, 0x51, 0xA6, 0x7D, 0xB9, 0x88 };
  4433. byte[] expected = { 0xC8, 0x93, 0x1E, 0xED, 0x3F, 0x9F, 0x79, 0x34, 0x6C, 0x3F, 0x99, 0x4A, 0x25, 0xAF, 0x86, 0xDF, 0xDF, 0x19, 0x65, 0xE8, 0xAD, 0x75, 0x43, 0x1B, 0xCD, 0x1B, 0x15, 0x23, 0xC4, 0x49, 0x07, 0x31, 0x3E, 0xA2, 0x34, 0x58, 0xA0, 0x82, 0x9F, 0xF8, 0xB7, 0xB1, 0xBE, 0x59, 0xF1, 0x09, 0x5E, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4434. SymmetricAlgorithm algo = Rijndael.Create ();
  4435. algo.Mode = CipherMode.CBC;
  4436. algo.Padding = PaddingMode.Zeros;
  4437. algo.BlockSize = 192;
  4438. int blockLength = (algo.BlockSize >> 3);
  4439. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4440. byte[] output = new byte [blockLength * 3];
  4441. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4442. // some exception can be normal... other not so!
  4443. try {
  4444. Encrypt (encryptor, input, output);
  4445. }
  4446. catch (Exception e) {
  4447. if (e.Message != "Input buffer contains insufficient data. ")
  4448. Assert.Fail ("Rijndael_k256b192_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
  4449. }
  4450. }
  4451. [Test]
  4452. public void TestRijndael_k256b192_CBC_PKCS7 ()
  4453. {
  4454. byte[] key = { 0x18, 0x60, 0x4C, 0x76, 0x3D, 0x08, 0x05, 0x18, 0x66, 0xA8, 0xA5, 0x59, 0x9E, 0xB1, 0x12, 0x83, 0x70, 0x81, 0x40, 0x82, 0x09, 0xE4, 0x36, 0x41, 0xBB, 0x72, 0x53, 0xF3, 0xB6, 0x23, 0xAE, 0xB9 };
  4455. byte[] iv = { 0xA9, 0xC1, 0x7A, 0x1D, 0xAF, 0x14, 0xFA, 0x7D, 0xEF, 0x7F, 0xDE, 0x9E, 0xE9, 0xD6, 0x1D, 0x61, 0x46, 0x2B, 0xC9, 0x24, 0x40, 0x0A, 0xE9, 0x9C };
  4456. byte[] expected = { 0x9B, 0xE4, 0x1F, 0x94, 0xB2, 0x6B, 0x3E, 0x70, 0x69, 0x18, 0xCD, 0x65, 0xB7, 0xD9, 0xD9, 0x8E, 0xBB, 0xDA, 0xED, 0x5C, 0x84, 0xBA, 0x52, 0x4C, 0xA2, 0x66, 0xB8, 0x20, 0xEC, 0xB4, 0x16, 0xF1, 0x4C, 0xA2, 0xD0, 0x5F, 0x48, 0xDF, 0xA1, 0xDA, 0xEF, 0x75, 0xA8, 0x02, 0xCA, 0x57, 0x2E, 0x61, 0x94, 0x6A, 0x63, 0xFF, 0xBF, 0x2D, 0x44, 0x29, 0x38, 0x24, 0x50, 0x16, 0xE4, 0x41, 0x12, 0xBB, 0xF6, 0x67, 0x0A, 0xCF, 0x0A, 0xC9, 0x89, 0x55 };
  4457. SymmetricAlgorithm algo = Rijndael.Create ();
  4458. algo.Mode = CipherMode.CBC;
  4459. algo.Padding = PaddingMode.PKCS7;
  4460. algo.BlockSize = 192;
  4461. int blockLength = (algo.BlockSize >> 3);
  4462. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4463. byte[] output = new byte [blockLength * 3];
  4464. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4465. Encrypt (encryptor, input, output);
  4466. AssertEquals ("Rijndael_k256b192_CBC_PKCS7 Encrypt", expected, output);
  4467. byte[] reverse = new byte [blockLength * 3];
  4468. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4469. Decrypt (decryptor, output, reverse);
  4470. byte[] original = new byte [input.Length];
  4471. Array.Copy (reverse, 0, original, 0, original.Length);
  4472. AssertEquals ("Rijndael_k256b192_CBC_PKCS7 Decrypt", input, original);
  4473. }
  4474. /* Invalid parameters Rijndael_k256b192_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  4475. /* Invalid parameters Rijndael_k256b192_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  4476. /* Invalid parameters Rijndael_k256b192_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  4477. /* Invalid parameters Rijndael_k256b192_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4478. /* Invalid parameters Rijndael_k256b192_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4479. /* Invalid parameters Rijndael_k256b192_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4480. /* Invalid parameters Rijndael_k256b192_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4481. /* Invalid parameters Rijndael_k256b192_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4482. /* Invalid parameters Rijndael_k256b192_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4483. [Test]
  4484. public void TestRijndael_k256b256_ECB_None ()
  4485. {
  4486. byte[] key = { 0x04, 0x93, 0xC7, 0x1A, 0x3A, 0x62, 0x1E, 0x8B, 0x82, 0x6A, 0x20, 0x26, 0x5E, 0x29, 0x15, 0x0D, 0xCB, 0xD9, 0x49, 0x8A, 0x3E, 0x91, 0xE0, 0x8C, 0xE0, 0x9D, 0x8E, 0x15, 0x43, 0xE3, 0x1F, 0x9A };
  4487. // not used for ECB but make the code more uniform
  4488. byte[] iv = { 0x41, 0x3B, 0xE7, 0x01, 0x40, 0xB6, 0xB9, 0x54, 0x24, 0x38, 0x38, 0xB5, 0x8C, 0x90, 0x8D, 0x90, 0x9D, 0x68, 0xE6, 0x9C, 0x92, 0xCD, 0x95, 0x77, 0x96, 0xC6, 0xE8, 0xD5, 0xA5, 0x3E, 0xBD, 0xB9 };
  4489. byte[] expected = { 0x2F, 0x30, 0x0F, 0xA2, 0x9C, 0x0E, 0xCA, 0x38, 0xD5, 0x43, 0xB6, 0xD4, 0xF9, 0x16, 0x65, 0xB8, 0xAA, 0x29, 0xB8, 0x16, 0xB7, 0x62, 0xE5, 0xFD, 0xC3, 0x4C, 0xA7, 0x7B, 0xC7, 0xF5, 0x5C, 0x1E, 0x2F, 0x30, 0x0F, 0xA2, 0x9C, 0x0E, 0xCA, 0x38, 0xD5, 0x43, 0xB6, 0xD4, 0xF9, 0x16, 0x65, 0xB8, 0xAA, 0x29, 0xB8, 0x16, 0xB7, 0x62, 0xE5, 0xFD, 0xC3, 0x4C, 0xA7, 0x7B, 0xC7, 0xF5, 0x5C, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4490. SymmetricAlgorithm algo = Rijndael.Create ();
  4491. algo.Mode = CipherMode.ECB;
  4492. algo.Padding = PaddingMode.None;
  4493. algo.BlockSize = 256;
  4494. int blockLength = (algo.BlockSize >> 3);
  4495. byte[] input = new byte [blockLength * 2];
  4496. byte[] output = new byte [blockLength * 3];
  4497. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4498. Encrypt (encryptor, input, output);
  4499. AssertEquals ("Rijndael_k256b256_ECB_None Encrypt", expected, output);
  4500. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4501. byte[] block1 = new byte[blockLength];
  4502. Array.Copy (output, 0, block1, 0, blockLength);
  4503. byte[] block2 = new byte[blockLength];
  4504. Array.Copy (output, blockLength, block2, 0, blockLength);
  4505. AssertEquals ("Rijndael_k256b256_ECB_None b1==b2", block1, block2);
  4506. byte[] reverse = new byte [blockLength * 3];
  4507. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4508. Decrypt (decryptor, output, reverse);
  4509. byte[] original = new byte [input.Length];
  4510. Array.Copy (reverse, 0, original, 0, original.Length);
  4511. AssertEquals ("Rijndael_k256b256_ECB_None Decrypt", input, original);
  4512. }
  4513. [Test]
  4514. public void TestRijndael_k256b256_ECB_Zeros ()
  4515. {
  4516. byte[] key = { 0x52, 0x21, 0xDF, 0x3C, 0x96, 0x67, 0x86, 0x28, 0x80, 0x97, 0x12, 0xBB, 0xDD, 0x80, 0xE1, 0x04, 0xC8, 0x4B, 0x12, 0x3E, 0x28, 0x3F, 0x32, 0x38, 0xC8, 0xA0, 0x12, 0xFA, 0xFE, 0x8C, 0x0C, 0xEC };
  4517. // not used for ECB but make the code more uniform
  4518. byte[] iv = { 0xA9, 0x41, 0xB0, 0xE2, 0x23, 0x9A, 0x75, 0x56, 0x5F, 0x5D, 0xB8, 0x0B, 0xB1, 0xF1, 0x0F, 0xC2, 0x50, 0xBF, 0xA7, 0x3B, 0x8A, 0x26, 0xD4, 0x82, 0x33, 0xE1, 0x77, 0x84, 0xCC, 0x47, 0xCB, 0x85 };
  4519. byte[] expected = { 0xB0, 0xC4, 0x5A, 0xDA, 0x21, 0x69, 0x9A, 0x80, 0xFC, 0xF4, 0xD1, 0xA5, 0xEE, 0x43, 0x44, 0x27, 0x4F, 0x42, 0x38, 0xFE, 0xC4, 0x2C, 0x75, 0x00, 0x60, 0x66, 0x1E, 0x86, 0xD0, 0xFC, 0x4B, 0x23, 0xB0, 0xC4, 0x5A, 0xDA, 0x21, 0x69, 0x9A, 0x80, 0xFC, 0xF4, 0xD1, 0xA5, 0xEE, 0x43, 0x44, 0x27, 0x4F, 0x42, 0x38, 0xFE, 0xC4, 0x2C, 0x75, 0x00, 0x60, 0x66, 0x1E, 0x86, 0xD0, 0xFC, 0x4B, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4520. SymmetricAlgorithm algo = Rijndael.Create ();
  4521. algo.Mode = CipherMode.ECB;
  4522. algo.Padding = PaddingMode.Zeros;
  4523. algo.BlockSize = 256;
  4524. int blockLength = (algo.BlockSize >> 3);
  4525. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4526. byte[] output = new byte [blockLength * 3];
  4527. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4528. // some exception can be normal... other not so!
  4529. try {
  4530. Encrypt (encryptor, input, output);
  4531. }
  4532. catch (Exception e) {
  4533. if (e.Message != "Input buffer contains insufficient data. ")
  4534. Assert.Fail ("Rijndael_k256b256_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
  4535. }
  4536. }
  4537. [Test]
  4538. public void TestRijndael_k256b256_ECB_PKCS7 ()
  4539. {
  4540. byte[] key = { 0xC6, 0x74, 0x58, 0xA6, 0xE0, 0xAD, 0xA2, 0x2F, 0x36, 0xC1, 0xD7, 0xAC, 0xAD, 0x8E, 0x66, 0x18, 0x8B, 0xEF, 0xBF, 0x1B, 0x75, 0xF0, 0xB0, 0x96, 0xBB, 0x07, 0xE9, 0x67, 0x25, 0x1B, 0xD0, 0x46 };
  4541. // not used for ECB but make the code more uniform
  4542. byte[] iv = { 0x3B, 0x34, 0x5E, 0x47, 0xE3, 0x51, 0xC4, 0xE4, 0x9A, 0x66, 0xD6, 0x42, 0x1B, 0x45, 0xAB, 0x03, 0x35, 0x9A, 0x52, 0xD8, 0x1E, 0xA3, 0xC8, 0xD8, 0xBB, 0x3E, 0xD1, 0x35, 0x2C, 0x90, 0xB1, 0xC7 };
  4543. byte[] expected = { 0x48, 0xD6, 0xD0, 0x25, 0xC7, 0x71, 0x0E, 0x10, 0xB9, 0x05, 0xE4, 0xC9, 0xEF, 0xAD, 0xB8, 0x2B, 0x14, 0xAF, 0x10, 0x53, 0x27, 0x8F, 0x32, 0x2C, 0x25, 0x9D, 0xCE, 0x64, 0x22, 0x52, 0x29, 0xCB, 0x48, 0xD6, 0xD0, 0x25, 0xC7, 0x71, 0x0E, 0x10, 0xB9, 0x05, 0xE4, 0xC9, 0xEF, 0xAD, 0xB8, 0x2B, 0x14, 0xAF, 0x10, 0x53, 0x27, 0x8F, 0x32, 0x2C, 0x25, 0x9D, 0xCE, 0x64, 0x22, 0x52, 0x29, 0xCB, 0xDF, 0x29, 0xD6, 0xDD, 0xFB, 0x89, 0x4B, 0xD7, 0x24, 0x88, 0x8E, 0x74, 0x95, 0x79, 0xBD, 0xFB, 0x80, 0xCF, 0x34, 0x7C, 0xEC, 0x2A, 0xDF, 0xBB, 0x18, 0xF6, 0xB6, 0x41, 0x00, 0xA5, 0x00, 0x55 };
  4544. SymmetricAlgorithm algo = Rijndael.Create ();
  4545. algo.Mode = CipherMode.ECB;
  4546. algo.Padding = PaddingMode.PKCS7;
  4547. algo.BlockSize = 256;
  4548. int blockLength = (algo.BlockSize >> 3);
  4549. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4550. byte[] output = new byte [blockLength * 3];
  4551. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4552. Encrypt (encryptor, input, output);
  4553. AssertEquals ("Rijndael_k256b256_ECB_PKCS7 Encrypt", expected, output);
  4554. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4555. byte[] block1 = new byte[blockLength];
  4556. Array.Copy (output, 0, block1, 0, blockLength);
  4557. byte[] block2 = new byte[blockLength];
  4558. Array.Copy (output, blockLength, block2, 0, blockLength);
  4559. AssertEquals ("Rijndael_k256b256_ECB_PKCS7 b1==b2", block1, block2);
  4560. byte[] reverse = new byte [blockLength * 3];
  4561. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4562. Decrypt (decryptor, output, reverse);
  4563. byte[] original = new byte [input.Length];
  4564. Array.Copy (reverse, 0, original, 0, original.Length);
  4565. AssertEquals ("Rijndael_k256b256_ECB_PKCS7 Decrypt", input, original);
  4566. }
  4567. [Test]
  4568. public void TestRijndael_k256b256_CBC_None ()
  4569. {
  4570. byte[] key = { 0x2E, 0x1E, 0x55, 0x9B, 0xA8, 0x5A, 0x1D, 0x2A, 0x6B, 0x4D, 0x95, 0x8E, 0x7C, 0xFC, 0x33, 0xCE, 0x00, 0xA3, 0xFA, 0xCE, 0x9F, 0xF6, 0xED, 0x0C, 0xD5, 0x3C, 0xB0, 0xF4, 0x87, 0x26, 0x1E, 0x12 };
  4571. byte[] iv = { 0xB2, 0xCC, 0xA6, 0x99, 0x96, 0x9C, 0xC1, 0x20, 0x2A, 0xB1, 0x00, 0x28, 0x85, 0xE1, 0xB7, 0x74, 0x66, 0x02, 0xF5, 0x69, 0xE3, 0x1F, 0xA4, 0xF4, 0xFB, 0x90, 0x3F, 0xB2, 0x7E, 0x56, 0xC9, 0x6E };
  4572. byte[] expected = { 0x4D, 0x77, 0x53, 0xBE, 0xDB, 0xB7, 0x4D, 0x1B, 0x9B, 0x1F, 0x65, 0x7A, 0xF1, 0x8F, 0x40, 0x0D, 0x60, 0x46, 0x08, 0x8B, 0x36, 0x83, 0x91, 0x8E, 0xDC, 0x23, 0x48, 0x1F, 0x4B, 0xCB, 0x09, 0x31, 0xDB, 0x73, 0xA6, 0xF3, 0xDB, 0x98, 0x06, 0xE9, 0xFA, 0x72, 0x4F, 0xDC, 0x3A, 0xF1, 0x08, 0x7B, 0x42, 0x1E, 0xD3, 0xDB, 0x91, 0xC3, 0x2C, 0x3D, 0xD7, 0x79, 0x17, 0x2A, 0xE1, 0x3C, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4573. SymmetricAlgorithm algo = Rijndael.Create ();
  4574. algo.Mode = CipherMode.CBC;
  4575. algo.Padding = PaddingMode.None;
  4576. algo.BlockSize = 256;
  4577. int blockLength = (algo.BlockSize >> 3);
  4578. byte[] input = new byte [blockLength * 2];
  4579. byte[] output = new byte [blockLength * 3];
  4580. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4581. Encrypt (encryptor, input, output);
  4582. AssertEquals ("Rijndael_k256b256_CBC_None Encrypt", expected, output);
  4583. byte[] reverse = new byte [blockLength * 3];
  4584. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4585. Decrypt (decryptor, output, reverse);
  4586. byte[] original = new byte [input.Length];
  4587. Array.Copy (reverse, 0, original, 0, original.Length);
  4588. AssertEquals ("Rijndael_k256b256_CBC_None Decrypt", input, original);
  4589. }
  4590. [Test]
  4591. public void TestRijndael_k256b256_CBC_Zeros ()
  4592. {
  4593. byte[] key = { 0xEE, 0x9F, 0xAB, 0x79, 0x11, 0x3F, 0x53, 0x56, 0x4C, 0xB4, 0xC3, 0x70, 0x29, 0x03, 0xB8, 0x26, 0x8C, 0x30, 0x2A, 0xD3, 0xF2, 0x1E, 0xA3, 0x42, 0xF4, 0xE6, 0x79, 0x5B, 0x0D, 0x93, 0xCF, 0x1B };
  4594. byte[] iv = { 0xB0, 0x2A, 0x0F, 0x47, 0x4E, 0x47, 0xDB, 0x4A, 0xF2, 0xC7, 0xEB, 0xC3, 0xFA, 0xD3, 0x89, 0x0B, 0x46, 0x17, 0xDE, 0xB9, 0x18, 0x37, 0x6E, 0x83, 0x95, 0xD6, 0xF9, 0x25, 0xB5, 0xAC, 0x86, 0x9B };
  4595. byte[] expected = { 0x6F, 0x0B, 0x2F, 0x3E, 0x9B, 0x07, 0xDE, 0x8B, 0xE9, 0xE7, 0xD7, 0x10, 0x09, 0xAF, 0x8E, 0x84, 0xB7, 0xBA, 0xD1, 0x79, 0x37, 0xF1, 0x25, 0xB6, 0xD7, 0xFC, 0xFB, 0x62, 0x83, 0x86, 0x8A, 0xD1, 0xC6, 0xDD, 0x98, 0x59, 0xE3, 0xEE, 0x9C, 0xA6, 0x73, 0x03, 0xE6, 0xB2, 0x72, 0xD0, 0x35, 0x39, 0xBB, 0x1C, 0x8F, 0x08, 0x8C, 0x70, 0x4C, 0x0C, 0xAD, 0xCB, 0x4F, 0x9D, 0xB7, 0x6A, 0x5F, 0xE9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4596. SymmetricAlgorithm algo = Rijndael.Create ();
  4597. algo.Mode = CipherMode.CBC;
  4598. algo.Padding = PaddingMode.Zeros;
  4599. algo.BlockSize = 256;
  4600. int blockLength = (algo.BlockSize >> 3);
  4601. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4602. byte[] output = new byte [blockLength * 3];
  4603. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4604. // some exception can be normal... other not so!
  4605. try {
  4606. Encrypt (encryptor, input, output);
  4607. }
  4608. catch (Exception e) {
  4609. if (e.Message != "Input buffer contains insufficient data. ")
  4610. Assert.Fail ("Rijndael_k256b256_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
  4611. }
  4612. }
  4613. [Test]
  4614. public void TestRijndael_k256b256_CBC_PKCS7 ()
  4615. {
  4616. byte[] key = { 0x63, 0x95, 0x5F, 0x23, 0xFE, 0x8B, 0x49, 0x09, 0xBD, 0x05, 0x0D, 0x47, 0xCE, 0x48, 0x86, 0x02, 0x58, 0x44, 0x78, 0x21, 0x28, 0x75, 0x2E, 0x3A, 0x80, 0xE4, 0x41, 0x97, 0x0F, 0xB8, 0xA4, 0xB1 };
  4617. byte[] iv = { 0xE1, 0xC3, 0x6B, 0x5D, 0x4F, 0x86, 0x0D, 0x44, 0xD6, 0x73, 0x21, 0x50, 0x11, 0xD3, 0x41, 0x61, 0x33, 0x04, 0x1A, 0xF8, 0x50, 0x33, 0x93, 0x4A, 0x7F, 0x9F, 0x48, 0x27, 0x8C, 0x25, 0x90, 0x93 };
  4618. byte[] expected = { 0x1F, 0x18, 0x81, 0x2B, 0xEA, 0xE1, 0x05, 0x56, 0xF5, 0x71, 0x73, 0x8C, 0x84, 0x9C, 0x46, 0xF9, 0x18, 0xEE, 0x08, 0xB1, 0x4B, 0x96, 0xC9, 0xC9, 0x70, 0xC8, 0x3B, 0xEC, 0x15, 0x40, 0x5C, 0xA0, 0x3A, 0xD1, 0x09, 0x0C, 0xD8, 0x6F, 0xAA, 0xF5, 0x34, 0x52, 0x3A, 0x51, 0x8F, 0x3A, 0xB0, 0x3E, 0xFB, 0x31, 0x43, 0x97, 0xA3, 0x05, 0xC6, 0xF2, 0x7F, 0x2A, 0xF0, 0x4F, 0xA8, 0x64, 0xE7, 0x06, 0xFB, 0x59, 0xD3, 0xFB, 0x9E, 0x72, 0x3B, 0x11, 0xEE, 0x88, 0xEC, 0x29, 0xB2, 0x51, 0xD9, 0x58, 0x42, 0x79, 0xFC, 0x35, 0xE2, 0xF1, 0x81, 0x45, 0x8F, 0x7E, 0xE1, 0xBA, 0x95, 0xC9, 0xDD, 0x76 };
  4619. SymmetricAlgorithm algo = Rijndael.Create ();
  4620. algo.Mode = CipherMode.CBC;
  4621. algo.Padding = PaddingMode.PKCS7;
  4622. algo.BlockSize = 256;
  4623. int blockLength = (algo.BlockSize >> 3);
  4624. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4625. byte[] output = new byte [blockLength * 3];
  4626. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4627. Encrypt (encryptor, input, output);
  4628. AssertEquals ("Rijndael_k256b256_CBC_PKCS7 Encrypt", expected, output);
  4629. byte[] reverse = new byte [blockLength * 3];
  4630. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4631. Decrypt (decryptor, output, reverse);
  4632. byte[] original = new byte [input.Length];
  4633. Array.Copy (reverse, 0, original, 0, original.Length);
  4634. AssertEquals ("Rijndael_k256b256_CBC_PKCS7 Decrypt", input, original);
  4635. }
  4636. /* Invalid parameters Rijndael_k256b256_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  4637. /* Invalid parameters Rijndael_k256b256_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  4638. /* Invalid parameters Rijndael_k256b256_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  4639. /* Invalid parameters Rijndael_k256b256_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4640. /* Invalid parameters Rijndael_k256b256_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4641. /* Invalid parameters Rijndael_k256b256_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4642. /* Invalid parameters Rijndael_k256b256_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4643. /* Invalid parameters Rijndael_k256b256_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4644. /* Invalid parameters Rijndael_k256b256_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4645. [Test]
  4646. public void TestTripleDES_k128b64_ECB_None ()
  4647. {
  4648. byte[] key = { 0x31, 0x29, 0x5A, 0x2D, 0x18, 0xDF, 0x78, 0xB1, 0xB3, 0x30, 0xB4, 0x2E, 0x08, 0x2A, 0xB5, 0x00 };
  4649. // not used for ECB but make the code more uniform
  4650. byte[] iv = { 0xDE, 0x87, 0xFF, 0xA6, 0x30, 0x76, 0x39, 0x89 };
  4651. byte[] expected = { 0x74, 0xD2, 0x61, 0x01, 0xF0, 0x86, 0x74, 0xE8, 0x74, 0xD2, 0x61, 0x01, 0xF0, 0x86, 0x74, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4652. SymmetricAlgorithm algo = TripleDES.Create ();
  4653. algo.Mode = CipherMode.ECB;
  4654. algo.Padding = PaddingMode.None;
  4655. algo.BlockSize = 64;
  4656. int blockLength = (algo.BlockSize >> 3);
  4657. byte[] input = new byte [blockLength * 2];
  4658. byte[] output = new byte [blockLength * 3];
  4659. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4660. Encrypt (encryptor, input, output);
  4661. AssertEquals ("TripleDES_k128b64_ECB_None Encrypt", expected, output);
  4662. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4663. byte[] block1 = new byte[blockLength];
  4664. Array.Copy (output, 0, block1, 0, blockLength);
  4665. byte[] block2 = new byte[blockLength];
  4666. Array.Copy (output, blockLength, block2, 0, blockLength);
  4667. AssertEquals ("TripleDES_k128b64_ECB_None b1==b2", block1, block2);
  4668. byte[] reverse = new byte [blockLength * 3];
  4669. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4670. Decrypt (decryptor, output, reverse);
  4671. byte[] original = new byte [input.Length];
  4672. Array.Copy (reverse, 0, original, 0, original.Length);
  4673. AssertEquals ("TripleDES_k128b64_ECB_None Decrypt", input, original);
  4674. }
  4675. [Test]
  4676. public void TestTripleDES_k128b64_ECB_Zeros ()
  4677. {
  4678. byte[] key = { 0xFB, 0xC1, 0xA8, 0x04, 0x47, 0x10, 0x09, 0x09, 0xA8, 0x3D, 0x97, 0x18, 0x11, 0x3C, 0x28, 0x80 };
  4679. // not used for ECB but make the code more uniform
  4680. byte[] iv = { 0xA2, 0x1F, 0x63, 0x49, 0x33, 0xCA, 0xEE, 0xDA };
  4681. byte[] expected = { 0xDB, 0x4E, 0x92, 0x3D, 0xE3, 0x26, 0x0B, 0x16, 0xDB, 0x4E, 0x92, 0x3D, 0xE3, 0x26, 0x0B, 0x16, 0xDB, 0x4E, 0x92, 0x3D, 0xE3, 0x26, 0x0B, 0x16 };
  4682. SymmetricAlgorithm algo = TripleDES.Create ();
  4683. algo.Mode = CipherMode.ECB;
  4684. algo.Padding = PaddingMode.Zeros;
  4685. algo.BlockSize = 64;
  4686. int blockLength = (algo.BlockSize >> 3);
  4687. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4688. byte[] output = new byte [blockLength * 3];
  4689. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4690. Encrypt (encryptor, input, output);
  4691. AssertEquals ("TripleDES_k128b64_ECB_Zeros Encrypt", expected, output);
  4692. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4693. byte[] block1 = new byte[blockLength];
  4694. Array.Copy (output, 0, block1, 0, blockLength);
  4695. byte[] block2 = new byte[blockLength];
  4696. Array.Copy (output, blockLength, block2, 0, blockLength);
  4697. AssertEquals ("TripleDES_k128b64_ECB_Zeros b1==b2", block1, block2);
  4698. // also if padding is Zeros then all three blocks should be equals
  4699. byte[] block3 = new byte[blockLength];
  4700. Array.Copy (output, blockLength, block3, 0, blockLength);
  4701. AssertEquals ("TripleDES_k128b64_ECB_Zeros b1==b3", block1, block3);
  4702. byte[] reverse = new byte [blockLength * 3];
  4703. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4704. Decrypt (decryptor, output, reverse);
  4705. byte[] original = new byte [input.Length];
  4706. Array.Copy (reverse, 0, original, 0, original.Length);
  4707. AssertEquals ("TripleDES_k128b64_ECB_Zeros Decrypt", input, original);
  4708. }
  4709. [Test]
  4710. public void TestTripleDES_k128b64_ECB_PKCS7 ()
  4711. {
  4712. byte[] key = { 0x78, 0x52, 0xAE, 0x73, 0x24, 0x0A, 0xDF, 0x80, 0x1A, 0xDE, 0x32, 0x90, 0x3C, 0x01, 0xBA, 0x12 };
  4713. // not used for ECB but make the code more uniform
  4714. byte[] iv = { 0xF6, 0x11, 0x79, 0x5E, 0xEC, 0xDC, 0x5E, 0x19 };
  4715. byte[] expected = { 0x83, 0xDE, 0x8A, 0xDA, 0x7A, 0x46, 0xDC, 0x07, 0x83, 0xDE, 0x8A, 0xDA, 0x7A, 0x46, 0xDC, 0x07, 0x4B, 0x79, 0x8C, 0x46, 0x0A, 0xB7, 0x40, 0x6C };
  4716. SymmetricAlgorithm algo = TripleDES.Create ();
  4717. algo.Mode = CipherMode.ECB;
  4718. algo.Padding = PaddingMode.PKCS7;
  4719. algo.BlockSize = 64;
  4720. int blockLength = (algo.BlockSize >> 3);
  4721. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4722. byte[] output = new byte [blockLength * 3];
  4723. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4724. Encrypt (encryptor, input, output);
  4725. AssertEquals ("TripleDES_k128b64_ECB_PKCS7 Encrypt", expected, output);
  4726. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4727. byte[] block1 = new byte[blockLength];
  4728. Array.Copy (output, 0, block1, 0, blockLength);
  4729. byte[] block2 = new byte[blockLength];
  4730. Array.Copy (output, blockLength, block2, 0, blockLength);
  4731. AssertEquals ("TripleDES_k128b64_ECB_PKCS7 b1==b2", block1, block2);
  4732. byte[] reverse = new byte [blockLength * 3];
  4733. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4734. Decrypt (decryptor, output, reverse);
  4735. byte[] original = new byte [input.Length];
  4736. Array.Copy (reverse, 0, original, 0, original.Length);
  4737. AssertEquals ("TripleDES_k128b64_ECB_PKCS7 Decrypt", input, original);
  4738. }
  4739. [Test]
  4740. public void TestTripleDES_k128b64_CBC_None ()
  4741. {
  4742. byte[] key = { 0x9B, 0x97, 0x95, 0xA2, 0x6D, 0x90, 0x1D, 0xAE, 0xE8, 0xFC, 0xA1, 0xA2, 0x06, 0x6E, 0x75, 0xE8 };
  4743. byte[] iv = { 0x52, 0xF8, 0x0E, 0xA9, 0x8C, 0xD9, 0x46, 0x63 };
  4744. byte[] expected = { 0xD3, 0x37, 0x2D, 0x9B, 0x69, 0x35, 0xB7, 0x80, 0xD1, 0x13, 0xBB, 0xEB, 0x47, 0xB6, 0xDA, 0xF2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4745. SymmetricAlgorithm algo = TripleDES.Create ();
  4746. algo.Mode = CipherMode.CBC;
  4747. algo.Padding = PaddingMode.None;
  4748. algo.BlockSize = 64;
  4749. int blockLength = (algo.BlockSize >> 3);
  4750. byte[] input = new byte [blockLength * 2];
  4751. byte[] output = new byte [blockLength * 3];
  4752. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4753. Encrypt (encryptor, input, output);
  4754. AssertEquals ("TripleDES_k128b64_CBC_None Encrypt", expected, output);
  4755. byte[] reverse = new byte [blockLength * 3];
  4756. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4757. Decrypt (decryptor, output, reverse);
  4758. byte[] original = new byte [input.Length];
  4759. Array.Copy (reverse, 0, original, 0, original.Length);
  4760. AssertEquals ("TripleDES_k128b64_CBC_None Decrypt", input, original);
  4761. }
  4762. [Test]
  4763. public void TestTripleDES_k128b64_CBC_Zeros ()
  4764. {
  4765. byte[] key = { 0x21, 0x87, 0x57, 0xF4, 0xE5, 0xE9, 0x91, 0xC7, 0x3A, 0x64, 0x14, 0xF2, 0x2B, 0x06, 0x0E, 0x2E };
  4766. byte[] iv = { 0x23, 0x86, 0x58, 0x7B, 0x49, 0x23, 0xF6, 0x7F };
  4767. byte[] expected = { 0xEF, 0x1B, 0x0B, 0xDD, 0xD0, 0x07, 0x5E, 0x22, 0x9D, 0xB9, 0xCC, 0x52, 0xB4, 0xD9, 0x88, 0x1F, 0x5D, 0xE3, 0x51, 0x51, 0xBF, 0x7C, 0xB5, 0xB3 };
  4768. SymmetricAlgorithm algo = TripleDES.Create ();
  4769. algo.Mode = CipherMode.CBC;
  4770. algo.Padding = PaddingMode.Zeros;
  4771. algo.BlockSize = 64;
  4772. int blockLength = (algo.BlockSize >> 3);
  4773. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4774. byte[] output = new byte [blockLength * 3];
  4775. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4776. Encrypt (encryptor, input, output);
  4777. AssertEquals ("TripleDES_k128b64_CBC_Zeros Encrypt", expected, output);
  4778. byte[] reverse = new byte [blockLength * 3];
  4779. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4780. Decrypt (decryptor, output, reverse);
  4781. byte[] original = new byte [input.Length];
  4782. Array.Copy (reverse, 0, original, 0, original.Length);
  4783. AssertEquals ("TripleDES_k128b64_CBC_Zeros Decrypt", input, original);
  4784. }
  4785. [Test]
  4786. public void TestTripleDES_k128b64_CBC_PKCS7 ()
  4787. {
  4788. byte[] key = { 0x06, 0x33, 0x4B, 0x5A, 0xF0, 0xC6, 0xAE, 0x71, 0x8C, 0x41, 0xB3, 0x72, 0x43, 0x4B, 0x82, 0x31 };
  4789. byte[] iv = { 0x40, 0x7F, 0x60, 0x5B, 0x5C, 0x22, 0x8D, 0x5D };
  4790. byte[] expected = { 0x9C, 0x3F, 0x6A, 0x1D, 0xBD, 0x92, 0x1A, 0xFA, 0xD4, 0xA5, 0xEA, 0xB3, 0x77, 0xA0, 0x8B, 0xB0, 0x7E, 0x11, 0xFA, 0xA9, 0x45, 0x46, 0x16, 0x33 };
  4791. SymmetricAlgorithm algo = TripleDES.Create ();
  4792. algo.Mode = CipherMode.CBC;
  4793. algo.Padding = PaddingMode.PKCS7;
  4794. algo.BlockSize = 64;
  4795. int blockLength = (algo.BlockSize >> 3);
  4796. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4797. byte[] output = new byte [blockLength * 3];
  4798. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4799. Encrypt (encryptor, input, output);
  4800. AssertEquals ("TripleDES_k128b64_CBC_PKCS7 Encrypt", expected, output);
  4801. byte[] reverse = new byte [blockLength * 3];
  4802. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4803. Decrypt (decryptor, output, reverse);
  4804. byte[] original = new byte [input.Length];
  4805. Array.Copy (reverse, 0, original, 0, original.Length);
  4806. AssertEquals ("TripleDES_k128b64_CBC_PKCS7 Decrypt", input, original);
  4807. }
  4808. /* Invalid parameters TripleDES_k128b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  4809. /* Invalid parameters TripleDES_k128b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  4810. /* Invalid parameters TripleDES_k128b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  4811. [Test]
  4812. public void TestTripleDES_k128b64_CFB8_None ()
  4813. {
  4814. byte[] key = { 0x49, 0x9D, 0x94, 0x9C, 0x79, 0xD9, 0xEE, 0x92, 0x75, 0xE8, 0x8C, 0x78, 0xE3, 0xB5, 0x49, 0x81 };
  4815. byte[] iv = { 0x80, 0x0A, 0x45, 0x55, 0xCB, 0xC7, 0x17, 0xA1 };
  4816. byte[] expected = { 0xA5, 0x0F, 0xFF, 0xE6, 0xA0, 0x59, 0x58, 0x81, 0xB0, 0xFE, 0x19, 0x40, 0xF4, 0x04, 0x0B, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4817. SymmetricAlgorithm algo = TripleDES.Create ();
  4818. algo.Mode = CipherMode.CFB;
  4819. algo.Padding = PaddingMode.None;
  4820. algo.BlockSize = 64;
  4821. algo.FeedbackSize = 8;
  4822. int blockLength = (algo.BlockSize >> 3);
  4823. byte[] input = new byte [blockLength * 2];
  4824. byte[] output = new byte [blockLength * 3];
  4825. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4826. Encrypt (encryptor, input, output);
  4827. AssertEquals ("TripleDES_k128b64_CFB8_None Encrypt", expected, output);
  4828. byte[] reverse = new byte [blockLength * 3];
  4829. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4830. Decrypt (decryptor, output, reverse);
  4831. byte[] original = new byte [input.Length];
  4832. Array.Copy (reverse, 0, original, 0, original.Length);
  4833. AssertEquals ("TripleDES_k128b64_CFB8_None Decrypt", input, original);
  4834. }
  4835. [Test]
  4836. public void TestTripleDES_k128b64_CFB8_Zeros ()
  4837. {
  4838. byte[] key = { 0x47, 0xD4, 0x00, 0xC6, 0x0B, 0xCE, 0x0D, 0x6B, 0xD6, 0xEB, 0xBF, 0x74, 0xE3, 0xB9, 0x61, 0x14 };
  4839. byte[] iv = { 0x63, 0xB1, 0xCE, 0xEF, 0x06, 0x14, 0xD6, 0x4B };
  4840. byte[] expected = { 0x02, 0xB8, 0xB8, 0x49, 0xA8, 0x3B, 0x6B, 0x05, 0x74, 0x79, 0x91, 0xFE, 0x7B, 0x74, 0x0A, 0xF8, 0x95, 0x80, 0x5A, 0xF1, 0xE9, 0xD7, 0xD3, 0x32 };
  4841. SymmetricAlgorithm algo = TripleDES.Create ();
  4842. algo.Mode = CipherMode.CFB;
  4843. algo.Padding = PaddingMode.Zeros;
  4844. algo.BlockSize = 64;
  4845. algo.FeedbackSize = 8;
  4846. int blockLength = (algo.BlockSize >> 3);
  4847. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4848. byte[] output = new byte [blockLength * 3];
  4849. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4850. Encrypt (encryptor, input, output);
  4851. AssertEquals ("TripleDES_k128b64_CFB8_Zeros Encrypt", expected, output);
  4852. byte[] reverse = new byte [blockLength * 3];
  4853. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4854. Decrypt (decryptor, output, reverse);
  4855. byte[] original = new byte [input.Length];
  4856. Array.Copy (reverse, 0, original, 0, original.Length);
  4857. AssertEquals ("TripleDES_k128b64_CFB8_Zeros Decrypt", input, original);
  4858. }
  4859. [Test]
  4860. public void TestTripleDES_k128b64_CFB8_PKCS7 ()
  4861. {
  4862. byte[] key = { 0x70, 0x9E, 0x39, 0x1A, 0x45, 0xA4, 0x18, 0x30, 0xAC, 0xE6, 0x1E, 0x0E, 0xD7, 0x43, 0x39, 0x5F };
  4863. byte[] iv = { 0x26, 0xF3, 0x46, 0x6A, 0x35, 0xC8, 0xBF, 0x03 };
  4864. byte[] expected = { 0x88, 0x21, 0x01, 0x82, 0x88, 0x2E, 0x93, 0xC5, 0xCD, 0xA2, 0xC9, 0x38, 0x45, 0x68, 0x91, 0x82, 0xA5, 0x78, 0x6B, 0x08, 0x3F, 0x7C, 0xB8, 0x5F };
  4865. SymmetricAlgorithm algo = TripleDES.Create ();
  4866. algo.Mode = CipherMode.CFB;
  4867. algo.Padding = PaddingMode.PKCS7;
  4868. algo.BlockSize = 64;
  4869. algo.FeedbackSize = 8;
  4870. int blockLength = (algo.BlockSize >> 3);
  4871. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4872. byte[] output = new byte [blockLength * 3];
  4873. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4874. Encrypt (encryptor, input, output);
  4875. AssertEquals ("TripleDES_k128b64_CFB8_PKCS7 Encrypt", expected, output);
  4876. byte[] reverse = new byte [blockLength * 3];
  4877. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4878. Decrypt (decryptor, output, reverse);
  4879. byte[] original = new byte [input.Length];
  4880. Array.Copy (reverse, 0, original, 0, original.Length);
  4881. AssertEquals ("TripleDES_k128b64_CFB8_PKCS7 Decrypt", input, original);
  4882. }
  4883. /* Invalid parameters TripleDES_k128b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4884. /* Invalid parameters TripleDES_k128b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4885. /* Invalid parameters TripleDES_k128b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  4886. [Test]
  4887. public void TestTripleDES_k192b64_ECB_None ()
  4888. {
  4889. byte[] key = { 0x02, 0xFE, 0x15, 0x59, 0xD7, 0xE9, 0xB5, 0x2A, 0xA7, 0x9B, 0xB3, 0xA6, 0xFA, 0xAA, 0xC7, 0x97, 0xD4, 0x1B, 0xE4, 0x2D, 0xE4, 0xC5, 0x89, 0xC2 };
  4890. // not used for ECB but make the code more uniform
  4891. byte[] iv = { 0x13, 0xBF, 0xF3, 0xA0, 0xD3, 0xA1, 0x2F, 0x23 };
  4892. byte[] expected = { 0xC8, 0x09, 0x6E, 0xD6, 0xC8, 0xD8, 0xF3, 0x6A, 0xC8, 0x09, 0x6E, 0xD6, 0xC8, 0xD8, 0xF3, 0x6A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4893. SymmetricAlgorithm algo = TripleDES.Create ();
  4894. algo.Mode = CipherMode.ECB;
  4895. algo.Padding = PaddingMode.None;
  4896. algo.BlockSize = 64;
  4897. int blockLength = (algo.BlockSize >> 3);
  4898. byte[] input = new byte [blockLength * 2];
  4899. byte[] output = new byte [blockLength * 3];
  4900. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4901. Encrypt (encryptor, input, output);
  4902. AssertEquals ("TripleDES_k192b64_ECB_None Encrypt", expected, output);
  4903. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4904. byte[] block1 = new byte[blockLength];
  4905. Array.Copy (output, 0, block1, 0, blockLength);
  4906. byte[] block2 = new byte[blockLength];
  4907. Array.Copy (output, blockLength, block2, 0, blockLength);
  4908. AssertEquals ("TripleDES_k192b64_ECB_None b1==b2", block1, block2);
  4909. byte[] reverse = new byte [blockLength * 3];
  4910. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4911. Decrypt (decryptor, output, reverse);
  4912. byte[] original = new byte [input.Length];
  4913. Array.Copy (reverse, 0, original, 0, original.Length);
  4914. AssertEquals ("TripleDES_k192b64_ECB_None Decrypt", input, original);
  4915. }
  4916. [Test]
  4917. public void TestTripleDES_k192b64_ECB_Zeros ()
  4918. {
  4919. byte[] key = { 0x0B, 0xB5, 0x02, 0xE8, 0xC3, 0x2E, 0x24, 0xD9, 0xF0, 0x29, 0x15, 0x10, 0x19, 0x88, 0xFC, 0xD2, 0x60, 0xCA, 0x30, 0x51, 0x0D, 0xD6, 0x80, 0xAC };
  4920. // not used for ECB but make the code more uniform
  4921. byte[] iv = { 0xF6, 0xC5, 0xBD, 0xA2, 0x4D, 0xA8, 0x19, 0x78 };
  4922. byte[] expected = { 0xE0, 0x52, 0xCB, 0xC6, 0xBB, 0x43, 0x8F, 0x3B, 0xE0, 0x52, 0xCB, 0xC6, 0xBB, 0x43, 0x8F, 0x3B, 0xE0, 0x52, 0xCB, 0xC6, 0xBB, 0x43, 0x8F, 0x3B };
  4923. SymmetricAlgorithm algo = TripleDES.Create ();
  4924. algo.Mode = CipherMode.ECB;
  4925. algo.Padding = PaddingMode.Zeros;
  4926. algo.BlockSize = 64;
  4927. int blockLength = (algo.BlockSize >> 3);
  4928. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4929. byte[] output = new byte [blockLength * 3];
  4930. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4931. Encrypt (encryptor, input, output);
  4932. AssertEquals ("TripleDES_k192b64_ECB_Zeros Encrypt", expected, output);
  4933. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4934. byte[] block1 = new byte[blockLength];
  4935. Array.Copy (output, 0, block1, 0, blockLength);
  4936. byte[] block2 = new byte[blockLength];
  4937. Array.Copy (output, blockLength, block2, 0, blockLength);
  4938. AssertEquals ("TripleDES_k192b64_ECB_Zeros b1==b2", block1, block2);
  4939. // also if padding is Zeros then all three blocks should be equals
  4940. byte[] block3 = new byte[blockLength];
  4941. Array.Copy (output, blockLength, block3, 0, blockLength);
  4942. AssertEquals ("TripleDES_k192b64_ECB_Zeros b1==b3", block1, block3);
  4943. byte[] reverse = new byte [blockLength * 3];
  4944. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4945. Decrypt (decryptor, output, reverse);
  4946. byte[] original = new byte [input.Length];
  4947. Array.Copy (reverse, 0, original, 0, original.Length);
  4948. AssertEquals ("TripleDES_k192b64_ECB_Zeros Decrypt", input, original);
  4949. }
  4950. [Test]
  4951. public void TestTripleDES_k192b64_ECB_PKCS7 ()
  4952. {
  4953. byte[] key = { 0x41, 0xAD, 0x00, 0xE4, 0x53, 0x0A, 0x09, 0x8C, 0x1F, 0x86, 0x91, 0x46, 0x41, 0xEC, 0xE3, 0x70, 0x35, 0xE5, 0x65, 0x10, 0x0D, 0x38, 0x4F, 0xE3 };
  4954. // not used for ECB but make the code more uniform
  4955. byte[] iv = { 0xB0, 0x71, 0x70, 0xFC, 0x57, 0xC2, 0x26, 0xF9 };
  4956. byte[] expected = { 0xA3, 0xB3, 0x91, 0x00, 0x99, 0x7A, 0x15, 0xB4, 0xA3, 0xB3, 0x91, 0x00, 0x99, 0x7A, 0x15, 0xB4, 0x53, 0x35, 0xE6, 0x2D, 0x0D, 0xD1, 0x16, 0xE6 };
  4957. SymmetricAlgorithm algo = TripleDES.Create ();
  4958. algo.Mode = CipherMode.ECB;
  4959. algo.Padding = PaddingMode.PKCS7;
  4960. algo.BlockSize = 64;
  4961. int blockLength = (algo.BlockSize >> 3);
  4962. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  4963. byte[] output = new byte [blockLength * 3];
  4964. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4965. Encrypt (encryptor, input, output);
  4966. AssertEquals ("TripleDES_k192b64_ECB_PKCS7 Encrypt", expected, output);
  4967. // in ECB the first 2 blocks should be equals (as the IV is not used)
  4968. byte[] block1 = new byte[blockLength];
  4969. Array.Copy (output, 0, block1, 0, blockLength);
  4970. byte[] block2 = new byte[blockLength];
  4971. Array.Copy (output, blockLength, block2, 0, blockLength);
  4972. AssertEquals ("TripleDES_k192b64_ECB_PKCS7 b1==b2", block1, block2);
  4973. byte[] reverse = new byte [blockLength * 3];
  4974. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4975. Decrypt (decryptor, output, reverse);
  4976. byte[] original = new byte [input.Length];
  4977. Array.Copy (reverse, 0, original, 0, original.Length);
  4978. AssertEquals ("TripleDES_k192b64_ECB_PKCS7 Decrypt", input, original);
  4979. }
  4980. [Test]
  4981. public void TestTripleDES_k192b64_CBC_None ()
  4982. {
  4983. byte[] key = { 0xA5, 0xA5, 0x3B, 0x8E, 0x59, 0x5B, 0xDD, 0xEC, 0x15, 0x22, 0x95, 0x53, 0xCB, 0xEC, 0xE3, 0x63, 0x78, 0x25, 0xF5, 0xE5, 0x52, 0xAD, 0x50, 0x1A };
  4984. byte[] iv = { 0xBD, 0x69, 0xAC, 0xA6, 0xCF, 0x17, 0xFC, 0x8A };
  4985. byte[] expected = { 0xA6, 0xA8, 0x8E, 0x09, 0xCF, 0xD2, 0x66, 0x4A, 0x20, 0xE8, 0xC3, 0x56, 0x8F, 0x2F, 0x42, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  4986. SymmetricAlgorithm algo = TripleDES.Create ();
  4987. algo.Mode = CipherMode.CBC;
  4988. algo.Padding = PaddingMode.None;
  4989. algo.BlockSize = 64;
  4990. int blockLength = (algo.BlockSize >> 3);
  4991. byte[] input = new byte [blockLength * 2];
  4992. byte[] output = new byte [blockLength * 3];
  4993. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  4994. Encrypt (encryptor, input, output);
  4995. AssertEquals ("TripleDES_k192b64_CBC_None Encrypt", expected, output);
  4996. byte[] reverse = new byte [blockLength * 3];
  4997. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  4998. Decrypt (decryptor, output, reverse);
  4999. byte[] original = new byte [input.Length];
  5000. Array.Copy (reverse, 0, original, 0, original.Length);
  5001. AssertEquals ("TripleDES_k192b64_CBC_None Decrypt", input, original);
  5002. }
  5003. [Test]
  5004. public void TestTripleDES_k192b64_CBC_Zeros ()
  5005. {
  5006. byte[] key = { 0x40, 0x3D, 0xEC, 0xE5, 0xB4, 0x2A, 0x4B, 0x5E, 0x81, 0x88, 0x3A, 0x53, 0x3F, 0xFD, 0xE7, 0x55, 0x50, 0x21, 0xAA, 0x0A, 0xB4, 0x3B, 0x26, 0xC0 };
  5007. byte[] iv = { 0x09, 0x50, 0xF5, 0x6F, 0x18, 0xD1, 0x4C, 0x9E };
  5008. byte[] expected = { 0x85, 0xFA, 0xBF, 0x39, 0x5C, 0x17, 0x13, 0xF1, 0x27, 0x47, 0x17, 0x97, 0xBA, 0xCD, 0x69, 0x8E, 0x0D, 0x7D, 0xC5, 0xE2, 0x8F, 0xDF, 0xFC, 0x2B };
  5009. SymmetricAlgorithm algo = TripleDES.Create ();
  5010. algo.Mode = CipherMode.CBC;
  5011. algo.Padding = PaddingMode.Zeros;
  5012. algo.BlockSize = 64;
  5013. int blockLength = (algo.BlockSize >> 3);
  5014. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  5015. byte[] output = new byte [blockLength * 3];
  5016. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  5017. Encrypt (encryptor, input, output);
  5018. AssertEquals ("TripleDES_k192b64_CBC_Zeros Encrypt", expected, output);
  5019. byte[] reverse = new byte [blockLength * 3];
  5020. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  5021. Decrypt (decryptor, output, reverse);
  5022. byte[] original = new byte [input.Length];
  5023. Array.Copy (reverse, 0, original, 0, original.Length);
  5024. AssertEquals ("TripleDES_k192b64_CBC_Zeros Decrypt", input, original);
  5025. }
  5026. [Test]
  5027. public void TestTripleDES_k192b64_CBC_PKCS7 ()
  5028. {
  5029. byte[] key = { 0x31, 0x9E, 0x55, 0x57, 0x3F, 0x77, 0xBC, 0x27, 0x79, 0x45, 0x7E, 0xAA, 0x4F, 0xF1, 0x2E, 0xBB, 0x98, 0xAE, 0xFD, 0xBE, 0x22, 0xB8, 0x69, 0xD9 };
  5030. byte[] iv = { 0xF7, 0xD8, 0x8E, 0xB2, 0xC5, 0x5F, 0x49, 0x91 };
  5031. byte[] expected = { 0x0D, 0xB8, 0xC7, 0x8F, 0x89, 0x26, 0x42, 0x50, 0x5E, 0x3A, 0x3B, 0x4D, 0xC8, 0x0E, 0x7E, 0x0F, 0xDA, 0x79, 0x37, 0x89, 0x2A, 0xF6, 0x10, 0x76 };
  5032. SymmetricAlgorithm algo = TripleDES.Create ();
  5033. algo.Mode = CipherMode.CBC;
  5034. algo.Padding = PaddingMode.PKCS7;
  5035. algo.BlockSize = 64;
  5036. int blockLength = (algo.BlockSize >> 3);
  5037. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  5038. byte[] output = new byte [blockLength * 3];
  5039. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  5040. Encrypt (encryptor, input, output);
  5041. AssertEquals ("TripleDES_k192b64_CBC_PKCS7 Encrypt", expected, output);
  5042. byte[] reverse = new byte [blockLength * 3];
  5043. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  5044. Decrypt (decryptor, output, reverse);
  5045. byte[] original = new byte [input.Length];
  5046. Array.Copy (reverse, 0, original, 0, original.Length);
  5047. AssertEquals ("TripleDES_k192b64_CBC_PKCS7 Decrypt", input, original);
  5048. }
  5049. /* Invalid parameters TripleDES_k192b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
  5050. /* Invalid parameters TripleDES_k192b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
  5051. /* Invalid parameters TripleDES_k192b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
  5052. [Test]
  5053. public void TestTripleDES_k192b64_CFB8_None ()
  5054. {
  5055. byte[] key = { 0x6C, 0x11, 0xA9, 0xC8, 0x04, 0xB3, 0x74, 0x8A, 0xA0, 0xC7, 0x43, 0x9A, 0x1F, 0x4C, 0x79, 0x08, 0x4D, 0xB4, 0x7B, 0xAC, 0xA2, 0xF8, 0x2C, 0x22 };
  5056. byte[] iv = { 0x2E, 0xF8, 0x02, 0x62, 0x15, 0xE2, 0x8F, 0xB1 };
  5057. byte[] expected = { 0x95, 0x55, 0x48, 0xF1, 0x6D, 0x6F, 0x36, 0x25, 0xAE, 0x02, 0x0B, 0x6E, 0xC3, 0x04, 0xC5, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  5058. SymmetricAlgorithm algo = TripleDES.Create ();
  5059. algo.Mode = CipherMode.CFB;
  5060. algo.Padding = PaddingMode.None;
  5061. algo.BlockSize = 64;
  5062. algo.FeedbackSize = 8;
  5063. int blockLength = (algo.BlockSize >> 3);
  5064. byte[] input = new byte [blockLength * 2];
  5065. byte[] output = new byte [blockLength * 3];
  5066. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  5067. Encrypt (encryptor, input, output);
  5068. AssertEquals ("TripleDES_k192b64_CFB8_None Encrypt", expected, output);
  5069. byte[] reverse = new byte [blockLength * 3];
  5070. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  5071. Decrypt (decryptor, output, reverse);
  5072. byte[] original = new byte [input.Length];
  5073. Array.Copy (reverse, 0, original, 0, original.Length);
  5074. AssertEquals ("TripleDES_k192b64_CFB8_None Decrypt", input, original);
  5075. }
  5076. [Test]
  5077. public void TestTripleDES_k192b64_CFB8_Zeros ()
  5078. {
  5079. byte[] key = { 0x34, 0x38, 0x7F, 0x40, 0xBA, 0x64, 0x88, 0xAC, 0x50, 0xE5, 0x0D, 0x9D, 0xC4, 0x0B, 0xDF, 0xE8, 0xB7, 0xCB, 0x9D, 0x38, 0xFD, 0x4E, 0x17, 0xDA };
  5080. byte[] iv = { 0xC0, 0x32, 0xAE, 0xA8, 0xEB, 0x67, 0x74, 0xC4 };
  5081. byte[] expected = { 0x8A, 0xE3, 0xAD, 0x43, 0x06, 0xAC, 0xC7, 0xE7, 0xCC, 0x03, 0xCE, 0xB1, 0x8F, 0x9F, 0x7A, 0x9E, 0xEB, 0x05, 0x74, 0x04, 0xF4, 0xFD, 0x76, 0x51 };
  5082. SymmetricAlgorithm algo = TripleDES.Create ();
  5083. algo.Mode = CipherMode.CFB;
  5084. algo.Padding = PaddingMode.Zeros;
  5085. algo.BlockSize = 64;
  5086. algo.FeedbackSize = 8;
  5087. int blockLength = (algo.BlockSize >> 3);
  5088. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  5089. byte[] output = new byte [blockLength * 3];
  5090. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  5091. Encrypt (encryptor, input, output);
  5092. AssertEquals ("TripleDES_k192b64_CFB8_Zeros Encrypt", expected, output);
  5093. byte[] reverse = new byte [blockLength * 3];
  5094. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  5095. Decrypt (decryptor, output, reverse);
  5096. byte[] original = new byte [input.Length];
  5097. Array.Copy (reverse, 0, original, 0, original.Length);
  5098. AssertEquals ("TripleDES_k192b64_CFB8_Zeros Decrypt", input, original);
  5099. }
  5100. [Test]
  5101. public void TestTripleDES_k192b64_CFB8_PKCS7 ()
  5102. {
  5103. byte[] key = { 0xBC, 0x48, 0x95, 0x9F, 0x13, 0xFF, 0xCB, 0x33, 0x6D, 0xA5, 0x84, 0x93, 0x33, 0x54, 0xAD, 0xF4, 0x5F, 0x99, 0xA3, 0x0F, 0x0E, 0x91, 0x88, 0x0E };
  5104. byte[] iv = { 0x0E, 0xC5, 0xA8, 0xB2, 0xDD, 0x83, 0xAE, 0x8C };
  5105. byte[] expected = { 0xB5, 0x72, 0x20, 0x82, 0x45, 0x70, 0x83, 0xE5, 0xF0, 0xA6, 0xFC, 0xFC, 0xB6, 0xF4, 0x7D, 0x3B, 0x71, 0x94, 0x2A, 0x9F, 0x01, 0x46, 0x90, 0x56 };
  5106. SymmetricAlgorithm algo = TripleDES.Create ();
  5107. algo.Mode = CipherMode.CFB;
  5108. algo.Padding = PaddingMode.PKCS7;
  5109. algo.BlockSize = 64;
  5110. algo.FeedbackSize = 8;
  5111. int blockLength = (algo.BlockSize >> 3);
  5112. byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
  5113. byte[] output = new byte [blockLength * 3];
  5114. ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
  5115. Encrypt (encryptor, input, output);
  5116. AssertEquals ("TripleDES_k192b64_CFB8_PKCS7 Encrypt", expected, output);
  5117. byte[] reverse = new byte [blockLength * 3];
  5118. ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
  5119. Decrypt (decryptor, output, reverse);
  5120. byte[] original = new byte [input.Length];
  5121. Array.Copy (reverse, 0, original, 0, original.Length);
  5122. AssertEquals ("TripleDES_k192b64_CFB8_PKCS7 Decrypt", input, original);
  5123. }
  5124. /* Invalid parameters TripleDES_k192b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
  5125. /* Invalid parameters TripleDES_k192b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
  5126. /* Invalid parameters TripleDES_k192b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
  5127. // Number of test cases: 189
  5128. // Number of invalid (non-generated) test cases: 171
  5129. }
  5130. }