SymmetricAlgorithmTest.cs 279 KB

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