SymmetricAlgorithmTest.cs 279 KB

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