crypto-js.js 212 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124
  1. ;
  2. (function(root, factory) {
  3. if (typeof exports === "object") {
  4. // CommonJS
  5. module.exports = exports = factory();
  6. } else if (typeof define === "function" && define.amd) {
  7. // AMD
  8. define([], factory);
  9. } else {
  10. // Global (browser)
  11. globalThis.CryptoJS = factory();
  12. }
  13. }(this, function() {
  14. /*globals window, global, require*/
  15. /**
  16. * CryptoJS core components.
  17. */
  18. var CryptoJS = CryptoJS || (function(Math, undefined) {
  19. var crypto;
  20. // Native crypto from window (Browser)
  21. if (typeof window !== 'undefined' && window.crypto) {
  22. crypto = window.crypto;
  23. }
  24. // Native crypto in web worker (Browser)
  25. if (typeof self !== 'undefined' && self.crypto) {
  26. crypto = self.crypto;
  27. }
  28. // Native crypto from worker
  29. if (typeof globalThis !== 'undefined' && globalThis.crypto) {
  30. crypto = globalThis.crypto;
  31. }
  32. // Native (experimental IE 11) crypto from window (Browser)
  33. if (!crypto && typeof window !== 'undefined' && window.msCrypto) {
  34. crypto = window.msCrypto;
  35. }
  36. // Native crypto from global (NodeJS)
  37. if (!crypto && typeof global !== 'undefined' && global.crypto) {
  38. crypto = global.crypto;
  39. }
  40. // Native crypto import via require (NodeJS)
  41. if (!crypto && typeof require === 'function') {
  42. try {
  43. crypto = require('crypto');
  44. } catch (err) {}
  45. }
  46. /*
  47. * Cryptographically secure pseudorandom number generator
  48. *
  49. * As Math.random() is cryptographically not safe to use
  50. */
  51. var cryptoSecureRandomInt = function() {
  52. if (crypto) {
  53. // Use getRandomValues method (Browser)
  54. if (typeof crypto.getRandomValues === 'function') {
  55. try {
  56. return crypto.getRandomValues(new Uint32Array(1))[0];
  57. } catch (err) {}
  58. }
  59. // Use randomBytes method (NodeJS)
  60. if (typeof crypto.randomBytes === 'function') {
  61. try {
  62. return crypto.randomBytes(4).readInt32LE();
  63. } catch (err) {}
  64. }
  65. }
  66. throw new Error('Native crypto module could not be used to get secure random number.');
  67. };
  68. /*
  69. * Local polyfill of Object.create
  70. */
  71. var create = Object.create || (function() {
  72. function F() {}
  73. return function(obj) {
  74. var subtype;
  75. F.prototype = obj;
  76. subtype = new F();
  77. F.prototype = null;
  78. return subtype;
  79. };
  80. }());
  81. /**
  82. * CryptoJS namespace.
  83. */
  84. var C = {};
  85. /**
  86. * Library namespace.
  87. */
  88. var C_lib = C.lib = {};
  89. /**
  90. * Base object for prototypal inheritance.
  91. */
  92. var Base = C_lib.Base = (function() {
  93. return {
  94. /**
  95. * Creates a new object that inherits from this object.
  96. *
  97. * @param {Object} overrides Properties to copy into the new object.
  98. *
  99. * @return {Object} The new object.
  100. *
  101. * @static
  102. *
  103. * @example
  104. *
  105. * var MyType = CryptoJS.lib.Base.extend({
  106. * field: 'value',
  107. *
  108. * method: function () {
  109. * }
  110. * });
  111. */
  112. extend: function(overrides) {
  113. // Spawn
  114. var subtype = create(this);
  115. // Augment
  116. if (overrides) {
  117. subtype.mixIn(overrides);
  118. }
  119. // Create default initializer
  120. if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
  121. subtype.init = function() {
  122. subtype.$super.init.apply(this, arguments);
  123. };
  124. }
  125. // Initializer's prototype is the subtype object
  126. subtype.init.prototype = subtype;
  127. // Reference supertype
  128. subtype.$super = this;
  129. return subtype;
  130. },
  131. /**
  132. * Extends this object and runs the init method.
  133. * Arguments to create() will be passed to init().
  134. *
  135. * @return {Object} The new object.
  136. *
  137. * @static
  138. *
  139. * @example
  140. *
  141. * var instance = MyType.create();
  142. */
  143. create: function() {
  144. var instance = this.extend();
  145. instance.init.apply(instance, arguments);
  146. return instance;
  147. },
  148. /**
  149. * Initializes a newly created object.
  150. * Override this method to add some logic when your objects are created.
  151. *
  152. * @example
  153. *
  154. * var MyType = CryptoJS.lib.Base.extend({
  155. * init: function () {
  156. * // ...
  157. * }
  158. * });
  159. */
  160. init: function() {},
  161. /**
  162. * Copies properties into this object.
  163. *
  164. * @param {Object} properties The properties to mix in.
  165. *
  166. * @example
  167. *
  168. * MyType.mixIn({
  169. * field: 'value'
  170. * });
  171. */
  172. mixIn: function(properties) {
  173. for (var propertyName in properties) {
  174. if (properties.hasOwnProperty(propertyName)) {
  175. this[propertyName] = properties[propertyName];
  176. }
  177. }
  178. // IE won't copy toString using the loop above
  179. if (properties.hasOwnProperty('toString')) {
  180. this.toString = properties.toString;
  181. }
  182. },
  183. /**
  184. * Creates a copy of this object.
  185. *
  186. * @return {Object} The clone.
  187. *
  188. * @example
  189. *
  190. * var clone = instance.clone();
  191. */
  192. clone: function() {
  193. return this.init.prototype.extend(this);
  194. }
  195. };
  196. }());
  197. /**
  198. * An array of 32-bit words.
  199. *
  200. * @property {Array} words The array of 32-bit words.
  201. * @property {number} sigBytes The number of significant bytes in this word array.
  202. */
  203. var WordArray = C_lib.WordArray = Base.extend({
  204. /**
  205. * Initializes a newly created word array.
  206. *
  207. * @param {Array} words (Optional) An array of 32-bit words.
  208. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  209. *
  210. * @example
  211. *
  212. * var wordArray = CryptoJS.lib.WordArray.create();
  213. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
  214. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
  215. */
  216. init: function(words, sigBytes) {
  217. words = this.words = words || [];
  218. if (sigBytes != undefined) {
  219. this.sigBytes = sigBytes;
  220. } else {
  221. this.sigBytes = words.length * 4;
  222. }
  223. },
  224. /**
  225. * Converts this word array to a string.
  226. *
  227. * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
  228. *
  229. * @return {string} The stringified word array.
  230. *
  231. * @example
  232. *
  233. * var string = wordArray + '';
  234. * var string = wordArray.toString();
  235. * var string = wordArray.toString(CryptoJS.enc.Utf8);
  236. */
  237. toString: function(encoder) {
  238. return (encoder || Hex).stringify(this);
  239. },
  240. /**
  241. * Concatenates a word array to this word array.
  242. *
  243. * @param {WordArray} wordArray The word array to append.
  244. *
  245. * @return {WordArray} This word array.
  246. *
  247. * @example
  248. *
  249. * wordArray1.concat(wordArray2);
  250. */
  251. concat: function(wordArray) {
  252. // Shortcuts
  253. var thisWords = this.words;
  254. var thatWords = wordArray.words;
  255. var thisSigBytes = this.sigBytes;
  256. var thatSigBytes = wordArray.sigBytes;
  257. // Clamp excess bits
  258. this.clamp();
  259. // Concat
  260. if (thisSigBytes % 4) {
  261. // Copy one byte at a time
  262. for (var i = 0; i < thatSigBytes; i++) {
  263. var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  264. thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
  265. }
  266. } else {
  267. // Copy one word at a time
  268. for (var j = 0; j < thatSigBytes; j += 4) {
  269. thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2];
  270. }
  271. }
  272. this.sigBytes += thatSigBytes;
  273. // Chainable
  274. return this;
  275. },
  276. /**
  277. * Removes insignificant bits.
  278. *
  279. * @example
  280. *
  281. * wordArray.clamp();
  282. */
  283. clamp: function() {
  284. // Shortcuts
  285. var words = this.words;
  286. var sigBytes = this.sigBytes;
  287. // Clamp
  288. words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
  289. words.length = Math.ceil(sigBytes / 4);
  290. },
  291. /**
  292. * Creates a copy of this word array.
  293. *
  294. * @return {WordArray} The clone.
  295. *
  296. * @example
  297. *
  298. * var clone = wordArray.clone();
  299. */
  300. clone: function() {
  301. var clone = Base.clone.call(this);
  302. clone.words = this.words.slice(0);
  303. return clone;
  304. },
  305. /**
  306. * Creates a word array filled with random bytes.
  307. *
  308. * @param {number} nBytes The number of random bytes to generate.
  309. *
  310. * @return {WordArray} The random word array.
  311. *
  312. * @static
  313. *
  314. * @example
  315. *
  316. * var wordArray = CryptoJS.lib.WordArray.random(16);
  317. */
  318. random: function(nBytes) {
  319. var words = [];
  320. for (var i = 0; i < nBytes; i += 4) {
  321. words.push(cryptoSecureRandomInt());
  322. }
  323. return new WordArray.init(words, nBytes);
  324. }
  325. });
  326. /**
  327. * Encoder namespace.
  328. */
  329. var C_enc = C.enc = {};
  330. /**
  331. * Hex encoding strategy.
  332. */
  333. var Hex = C_enc.Hex = {
  334. /**
  335. * Converts a word array to a hex string.
  336. *
  337. * @param {WordArray} wordArray The word array.
  338. *
  339. * @return {string} The hex string.
  340. *
  341. * @static
  342. *
  343. * @example
  344. *
  345. * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
  346. */
  347. stringify: function(wordArray) {
  348. // Shortcuts
  349. var words = wordArray.words;
  350. var sigBytes = wordArray.sigBytes;
  351. // Convert
  352. var hexChars = [];
  353. for (var i = 0; i < sigBytes; i++) {
  354. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  355. hexChars.push((bite >>> 4).toString(16));
  356. hexChars.push((bite & 0x0f).toString(16));
  357. }
  358. return hexChars.join('');
  359. },
  360. /**
  361. * Converts a hex string to a word array.
  362. *
  363. * @param {string} hexStr The hex string.
  364. *
  365. * @return {WordArray} The word array.
  366. *
  367. * @static
  368. *
  369. * @example
  370. *
  371. * var wordArray = CryptoJS.enc.Hex.parse(hexString);
  372. */
  373. parse: function(hexStr) {
  374. // Shortcut
  375. var hexStrLength = hexStr.length;
  376. // Convert
  377. var words = [];
  378. for (var i = 0; i < hexStrLength; i += 2) {
  379. words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
  380. }
  381. return new WordArray.init(words, hexStrLength / 2);
  382. }
  383. };
  384. /**
  385. * Latin1 encoding strategy.
  386. */
  387. var Latin1 = C_enc.Latin1 = {
  388. /**
  389. * Converts a word array to a Latin1 string.
  390. *
  391. * @param {WordArray} wordArray The word array.
  392. *
  393. * @return {string} The Latin1 string.
  394. *
  395. * @static
  396. *
  397. * @example
  398. *
  399. * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
  400. */
  401. stringify: function(wordArray) {
  402. // Shortcuts
  403. var words = wordArray.words;
  404. var sigBytes = wordArray.sigBytes;
  405. // Convert
  406. var latin1Chars = [];
  407. for (var i = 0; i < sigBytes; i++) {
  408. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  409. latin1Chars.push(String.fromCharCode(bite));
  410. }
  411. return latin1Chars.join('');
  412. },
  413. /**
  414. * Converts a Latin1 string to a word array.
  415. *
  416. * @param {string} latin1Str The Latin1 string.
  417. *
  418. * @return {WordArray} The word array.
  419. *
  420. * @static
  421. *
  422. * @example
  423. *
  424. * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
  425. */
  426. parse: function(latin1Str) {
  427. // Shortcut
  428. var latin1StrLength = latin1Str.length;
  429. // Convert
  430. var words = [];
  431. for (var i = 0; i < latin1StrLength; i++) {
  432. words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
  433. }
  434. return new WordArray.init(words, latin1StrLength);
  435. }
  436. };
  437. /**
  438. * UTF-8 encoding strategy.
  439. */
  440. var Utf8 = C_enc.Utf8 = {
  441. /**
  442. * Converts a word array to a UTF-8 string.
  443. *
  444. * @param {WordArray} wordArray The word array.
  445. *
  446. * @return {string} The UTF-8 string.
  447. *
  448. * @static
  449. *
  450. * @example
  451. *
  452. * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
  453. */
  454. stringify: function(wordArray) {
  455. try {
  456. return decodeURIComponent(escape(Latin1.stringify(wordArray)));
  457. } catch (e) {
  458. throw new Error('Malformed UTF-8 data');
  459. }
  460. },
  461. /**
  462. * Converts a UTF-8 string to a word array.
  463. *
  464. * @param {string} utf8Str The UTF-8 string.
  465. *
  466. * @return {WordArray} The word array.
  467. *
  468. * @static
  469. *
  470. * @example
  471. *
  472. * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
  473. */
  474. parse: function(utf8Str) {
  475. return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
  476. }
  477. };
  478. /**
  479. * Abstract buffered block algorithm template.
  480. *
  481. * The property blockSize must be implemented in a concrete subtype.
  482. *
  483. * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
  484. */
  485. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
  486. /**
  487. * Resets this block algorithm's data buffer to its initial state.
  488. *
  489. * @example
  490. *
  491. * bufferedBlockAlgorithm.reset();
  492. */
  493. reset: function() {
  494. // Initial values
  495. this._data = new WordArray.init();
  496. this._nDataBytes = 0;
  497. },
  498. /**
  499. * Adds new data to this block algorithm's buffer.
  500. *
  501. * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
  502. *
  503. * @example
  504. *
  505. * bufferedBlockAlgorithm._append('data');
  506. * bufferedBlockAlgorithm._append(wordArray);
  507. */
  508. _append: function(data) {
  509. // Convert string to WordArray, else assume WordArray already
  510. if (typeof data == 'string') {
  511. data = Utf8.parse(data);
  512. }
  513. // Append
  514. this._data.concat(data);
  515. this._nDataBytes += data.sigBytes;
  516. },
  517. /**
  518. * Processes available data blocks.
  519. *
  520. * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
  521. *
  522. * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
  523. *
  524. * @return {WordArray} The processed data.
  525. *
  526. * @example
  527. *
  528. * var processedData = bufferedBlockAlgorithm._process();
  529. * var processedData = bufferedBlockAlgorithm._process(!!'flush');
  530. */
  531. _process: function(doFlush) {
  532. var processedWords;
  533. // Shortcuts
  534. var data = this._data;
  535. var dataWords = data.words;
  536. var dataSigBytes = data.sigBytes;
  537. var blockSize = this.blockSize;
  538. var blockSizeBytes = blockSize * 4;
  539. // Count blocks ready
  540. var nBlocksReady = dataSigBytes / blockSizeBytes;
  541. if (doFlush) {
  542. // Round up to include partial blocks
  543. nBlocksReady = Math.ceil(nBlocksReady);
  544. } else {
  545. // Round down to include only full blocks,
  546. // less the number of blocks that must remain in the buffer
  547. nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
  548. }
  549. // Count words ready
  550. var nWordsReady = nBlocksReady * blockSize;
  551. // Count bytes ready
  552. var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
  553. // Process blocks
  554. if (nWordsReady) {
  555. for (var offset = 0; offset < nWordsReady; offset += blockSize) {
  556. // Perform concrete-algorithm logic
  557. this._doProcessBlock(dataWords, offset);
  558. }
  559. // Remove processed words
  560. processedWords = dataWords.splice(0, nWordsReady);
  561. data.sigBytes -= nBytesReady;
  562. }
  563. // Return processed words
  564. return new WordArray.init(processedWords, nBytesReady);
  565. },
  566. /**
  567. * Creates a copy of this object.
  568. *
  569. * @return {Object} The clone.
  570. *
  571. * @example
  572. *
  573. * var clone = bufferedBlockAlgorithm.clone();
  574. */
  575. clone: function() {
  576. var clone = Base.clone.call(this);
  577. clone._data = this._data.clone();
  578. return clone;
  579. },
  580. _minBufferSize: 0
  581. });
  582. /**
  583. * Abstract hasher template.
  584. *
  585. * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
  586. */
  587. var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
  588. /**
  589. * Configuration options.
  590. */
  591. cfg: Base.extend(),
  592. /**
  593. * Initializes a newly created hasher.
  594. *
  595. * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
  596. *
  597. * @example
  598. *
  599. * var hasher = CryptoJS.algo.SHA256.create();
  600. */
  601. init: function(cfg) {
  602. // Apply config defaults
  603. this.cfg = this.cfg.extend(cfg);
  604. // Set initial values
  605. this.reset();
  606. },
  607. /**
  608. * Resets this hasher to its initial state.
  609. *
  610. * @example
  611. *
  612. * hasher.reset();
  613. */
  614. reset: function() {
  615. // Reset data buffer
  616. BufferedBlockAlgorithm.reset.call(this);
  617. // Perform concrete-hasher logic
  618. this._doReset();
  619. },
  620. /**
  621. * Updates this hasher with a message.
  622. *
  623. * @param {WordArray|string} messageUpdate The message to append.
  624. *
  625. * @return {Hasher} This hasher.
  626. *
  627. * @example
  628. *
  629. * hasher.update('message');
  630. * hasher.update(wordArray);
  631. */
  632. update: function(messageUpdate) {
  633. // Append
  634. this._append(messageUpdate);
  635. // Update the hash
  636. this._process();
  637. // Chainable
  638. return this;
  639. },
  640. /**
  641. * Finalizes the hash computation.
  642. * Note that the finalize operation is effectively a destructive, read-once operation.
  643. *
  644. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  645. *
  646. * @return {WordArray} The hash.
  647. *
  648. * @example
  649. *
  650. * var hash = hasher.finalize();
  651. * var hash = hasher.finalize('message');
  652. * var hash = hasher.finalize(wordArray);
  653. */
  654. finalize: function(messageUpdate) {
  655. // Final message update
  656. if (messageUpdate) {
  657. this._append(messageUpdate);
  658. }
  659. // Perform concrete-hasher logic
  660. var hash = this._doFinalize();
  661. return hash;
  662. },
  663. blockSize: 512 / 32,
  664. /**
  665. * Creates a shortcut function to a hasher's object interface.
  666. *
  667. * @param {Hasher} hasher The hasher to create a helper for.
  668. *
  669. * @return {Function} The shortcut function.
  670. *
  671. * @static
  672. *
  673. * @example
  674. *
  675. * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
  676. */
  677. _createHelper: function(hasher) {
  678. return function(message, cfg) {
  679. return new hasher.init(cfg).finalize(message);
  680. };
  681. },
  682. /**
  683. * Creates a shortcut function to the HMAC's object interface.
  684. *
  685. * @param {Hasher} hasher The hasher to use in this HMAC helper.
  686. *
  687. * @return {Function} The shortcut function.
  688. *
  689. * @static
  690. *
  691. * @example
  692. *
  693. * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
  694. */
  695. _createHmacHelper: function(hasher) {
  696. return function(message, key) {
  697. return new C_algo.HMAC.init(hasher, key).finalize(message);
  698. };
  699. }
  700. });
  701. /**
  702. * Algorithm namespace.
  703. */
  704. var C_algo = C.algo = {};
  705. return C;
  706. }(Math));
  707. (function(undefined) {
  708. // Shortcuts
  709. var C = CryptoJS;
  710. var C_lib = C.lib;
  711. var Base = C_lib.Base;
  712. var X32WordArray = C_lib.WordArray;
  713. /**
  714. * x64 namespace.
  715. */
  716. var C_x64 = C.x64 = {};
  717. /**
  718. * A 64-bit word.
  719. */
  720. var X64Word = C_x64.Word = Base.extend({
  721. /**
  722. * Initializes a newly created 64-bit word.
  723. *
  724. * @param {number} high The high 32 bits.
  725. * @param {number} low The low 32 bits.
  726. *
  727. * @example
  728. *
  729. * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
  730. */
  731. init: function(high, low) {
  732. this.high = high;
  733. this.low = low;
  734. }
  735. /**
  736. * Bitwise NOTs this word.
  737. *
  738. * @return {X64Word} A new x64-Word object after negating.
  739. *
  740. * @example
  741. *
  742. * var negated = x64Word.not();
  743. */
  744. // not: function () {
  745. // var high = ~this.high;
  746. // var low = ~this.low;
  747. // return X64Word.create(high, low);
  748. // },
  749. /**
  750. * Bitwise ANDs this word with the passed word.
  751. *
  752. * @param {X64Word} word The x64-Word to AND with this word.
  753. *
  754. * @return {X64Word} A new x64-Word object after ANDing.
  755. *
  756. * @example
  757. *
  758. * var anded = x64Word.and(anotherX64Word);
  759. */
  760. // and: function (word) {
  761. // var high = this.high & word.high;
  762. // var low = this.low & word.low;
  763. // return X64Word.create(high, low);
  764. // },
  765. /**
  766. * Bitwise ORs this word with the passed word.
  767. *
  768. * @param {X64Word} word The x64-Word to OR with this word.
  769. *
  770. * @return {X64Word} A new x64-Word object after ORing.
  771. *
  772. * @example
  773. *
  774. * var ored = x64Word.or(anotherX64Word);
  775. */
  776. // or: function (word) {
  777. // var high = this.high | word.high;
  778. // var low = this.low | word.low;
  779. // return X64Word.create(high, low);
  780. // },
  781. /**
  782. * Bitwise XORs this word with the passed word.
  783. *
  784. * @param {X64Word} word The x64-Word to XOR with this word.
  785. *
  786. * @return {X64Word} A new x64-Word object after XORing.
  787. *
  788. * @example
  789. *
  790. * var xored = x64Word.xor(anotherX64Word);
  791. */
  792. // xor: function (word) {
  793. // var high = this.high ^ word.high;
  794. // var low = this.low ^ word.low;
  795. // return X64Word.create(high, low);
  796. // },
  797. /**
  798. * Shifts this word n bits to the left.
  799. *
  800. * @param {number} n The number of bits to shift.
  801. *
  802. * @return {X64Word} A new x64-Word object after shifting.
  803. *
  804. * @example
  805. *
  806. * var shifted = x64Word.shiftL(25);
  807. */
  808. // shiftL: function (n) {
  809. // if (n < 32) {
  810. // var high = (this.high << n) | (this.low >>> (32 - n));
  811. // var low = this.low << n;
  812. // } else {
  813. // var high = this.low << (n - 32);
  814. // var low = 0;
  815. // }
  816. // return X64Word.create(high, low);
  817. // },
  818. /**
  819. * Shifts this word n bits to the right.
  820. *
  821. * @param {number} n The number of bits to shift.
  822. *
  823. * @return {X64Word} A new x64-Word object after shifting.
  824. *
  825. * @example
  826. *
  827. * var shifted = x64Word.shiftR(7);
  828. */
  829. // shiftR: function (n) {
  830. // if (n < 32) {
  831. // var low = (this.low >>> n) | (this.high << (32 - n));
  832. // var high = this.high >>> n;
  833. // } else {
  834. // var low = this.high >>> (n - 32);
  835. // var high = 0;
  836. // }
  837. // return X64Word.create(high, low);
  838. // },
  839. /**
  840. * Rotates this word n bits to the left.
  841. *
  842. * @param {number} n The number of bits to rotate.
  843. *
  844. * @return {X64Word} A new x64-Word object after rotating.
  845. *
  846. * @example
  847. *
  848. * var rotated = x64Word.rotL(25);
  849. */
  850. // rotL: function (n) {
  851. // return this.shiftL(n).or(this.shiftR(64 - n));
  852. // },
  853. /**
  854. * Rotates this word n bits to the right.
  855. *
  856. * @param {number} n The number of bits to rotate.
  857. *
  858. * @return {X64Word} A new x64-Word object after rotating.
  859. *
  860. * @example
  861. *
  862. * var rotated = x64Word.rotR(7);
  863. */
  864. // rotR: function (n) {
  865. // return this.shiftR(n).or(this.shiftL(64 - n));
  866. // },
  867. /**
  868. * Adds this word with the passed word.
  869. *
  870. * @param {X64Word} word The x64-Word to add with this word.
  871. *
  872. * @return {X64Word} A new x64-Word object after adding.
  873. *
  874. * @example
  875. *
  876. * var added = x64Word.add(anotherX64Word);
  877. */
  878. // add: function (word) {
  879. // var low = (this.low + word.low) | 0;
  880. // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
  881. // var high = (this.high + word.high + carry) | 0;
  882. // return X64Word.create(high, low);
  883. // }
  884. });
  885. /**
  886. * An array of 64-bit words.
  887. *
  888. * @property {Array} words The array of CryptoJS.x64.Word objects.
  889. * @property {number} sigBytes The number of significant bytes in this word array.
  890. */
  891. var X64WordArray = C_x64.WordArray = Base.extend({
  892. /**
  893. * Initializes a newly created word array.
  894. *
  895. * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
  896. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  897. *
  898. * @example
  899. *
  900. * var wordArray = CryptoJS.x64.WordArray.create();
  901. *
  902. * var wordArray = CryptoJS.x64.WordArray.create([
  903. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  904. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  905. * ]);
  906. *
  907. * var wordArray = CryptoJS.x64.WordArray.create([
  908. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  909. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  910. * ], 10);
  911. */
  912. init: function(words, sigBytes) {
  913. words = this.words = words || [];
  914. if (sigBytes != undefined) {
  915. this.sigBytes = sigBytes;
  916. } else {
  917. this.sigBytes = words.length * 8;
  918. }
  919. },
  920. /**
  921. * Converts this 64-bit word array to a 32-bit word array.
  922. *
  923. * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
  924. *
  925. * @example
  926. *
  927. * var x32WordArray = x64WordArray.toX32();
  928. */
  929. toX32: function() {
  930. // Shortcuts
  931. var x64Words = this.words;
  932. var x64WordsLength = x64Words.length;
  933. // Convert
  934. var x32Words = [];
  935. for (var i = 0; i < x64WordsLength; i++) {
  936. var x64Word = x64Words[i];
  937. x32Words.push(x64Word.high);
  938. x32Words.push(x64Word.low);
  939. }
  940. return X32WordArray.create(x32Words, this.sigBytes);
  941. },
  942. /**
  943. * Creates a copy of this word array.
  944. *
  945. * @return {X64WordArray} The clone.
  946. *
  947. * @example
  948. *
  949. * var clone = x64WordArray.clone();
  950. */
  951. clone: function() {
  952. var clone = Base.clone.call(this);
  953. // Clone "words" array
  954. var words = clone.words = this.words.slice(0);
  955. // Clone each X64Word object
  956. var wordsLength = words.length;
  957. for (var i = 0; i < wordsLength; i++) {
  958. words[i] = words[i].clone();
  959. }
  960. return clone;
  961. }
  962. });
  963. }());
  964. (function() {
  965. // Check if typed arrays are supported
  966. if (typeof ArrayBuffer != 'function') {
  967. return;
  968. }
  969. // Shortcuts
  970. var C = CryptoJS;
  971. var C_lib = C.lib;
  972. var WordArray = C_lib.WordArray;
  973. // Reference original init
  974. var superInit = WordArray.init;
  975. // Augment WordArray.init to handle typed arrays
  976. var subInit = WordArray.init = function(typedArray) {
  977. // Convert buffers to uint8
  978. if (typedArray instanceof ArrayBuffer) {
  979. typedArray = new Uint8Array(typedArray);
  980. }
  981. // Convert other array views to uint8
  982. if (
  983. typedArray instanceof Int8Array || (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || typedArray instanceof Int16Array || typedArray instanceof Uint16Array || typedArray instanceof Int32Array || typedArray instanceof Uint32Array || typedArray instanceof Float32Array || typedArray instanceof Float64Array) {
  984. typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
  985. }
  986. // Handle Uint8Array
  987. if (typedArray instanceof Uint8Array) {
  988. // Shortcut
  989. var typedArrayByteLength = typedArray.byteLength;
  990. // Extract bytes
  991. var words = [];
  992. for (var i = 0; i < typedArrayByteLength; i++) {
  993. words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
  994. }
  995. // Initialize this word array
  996. superInit.call(this, words, typedArrayByteLength);
  997. } else {
  998. // Else call normal init
  999. superInit.apply(this, arguments);
  1000. }
  1001. };
  1002. subInit.prototype = WordArray;
  1003. }());
  1004. (function() {
  1005. // Shortcuts
  1006. var C = CryptoJS;
  1007. var C_lib = C.lib;
  1008. var WordArray = C_lib.WordArray;
  1009. var C_enc = C.enc;
  1010. /**
  1011. * UTF-16 BE encoding strategy.
  1012. */
  1013. var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = {
  1014. /**
  1015. * Converts a word array to a UTF-16 BE string.
  1016. *
  1017. * @param {WordArray} wordArray The word array.
  1018. *
  1019. * @return {string} The UTF-16 BE string.
  1020. *
  1021. * @static
  1022. *
  1023. * @example
  1024. *
  1025. * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray);
  1026. */
  1027. stringify: function(wordArray) {
  1028. // Shortcuts
  1029. var words = wordArray.words;
  1030. var sigBytes = wordArray.sigBytes;
  1031. // Convert
  1032. var utf16Chars = [];
  1033. for (var i = 0; i < sigBytes; i += 2) {
  1034. var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff;
  1035. utf16Chars.push(String.fromCharCode(codePoint));
  1036. }
  1037. return utf16Chars.join('');
  1038. },
  1039. /**
  1040. * Converts a UTF-16 BE string to a word array.
  1041. *
  1042. * @param {string} utf16Str The UTF-16 BE string.
  1043. *
  1044. * @return {WordArray} The word array.
  1045. *
  1046. * @static
  1047. *
  1048. * @example
  1049. *
  1050. * var wordArray = CryptoJS.enc.Utf16.parse(utf16String);
  1051. */
  1052. parse: function(utf16Str) {
  1053. // Shortcut
  1054. var utf16StrLength = utf16Str.length;
  1055. // Convert
  1056. var words = [];
  1057. for (var i = 0; i < utf16StrLength; i++) {
  1058. words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16);
  1059. }
  1060. return WordArray.create(words, utf16StrLength * 2);
  1061. }
  1062. };
  1063. /**
  1064. * UTF-16 LE encoding strategy.
  1065. */
  1066. C_enc.Utf16LE = {
  1067. /**
  1068. * Converts a word array to a UTF-16 LE string.
  1069. *
  1070. * @param {WordArray} wordArray The word array.
  1071. *
  1072. * @return {string} The UTF-16 LE string.
  1073. *
  1074. * @static
  1075. *
  1076. * @example
  1077. *
  1078. * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
  1079. */
  1080. stringify: function(wordArray) {
  1081. // Shortcuts
  1082. var words = wordArray.words;
  1083. var sigBytes = wordArray.sigBytes;
  1084. // Convert
  1085. var utf16Chars = [];
  1086. for (var i = 0; i < sigBytes; i += 2) {
  1087. var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff);
  1088. utf16Chars.push(String.fromCharCode(codePoint));
  1089. }
  1090. return utf16Chars.join('');
  1091. },
  1092. /**
  1093. * Converts a UTF-16 LE string to a word array.
  1094. *
  1095. * @param {string} utf16Str The UTF-16 LE string.
  1096. *
  1097. * @return {WordArray} The word array.
  1098. *
  1099. * @static
  1100. *
  1101. * @example
  1102. *
  1103. * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str);
  1104. */
  1105. parse: function(utf16Str) {
  1106. // Shortcut
  1107. var utf16StrLength = utf16Str.length;
  1108. // Convert
  1109. var words = [];
  1110. for (var i = 0; i < utf16StrLength; i++) {
  1111. words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16));
  1112. }
  1113. return WordArray.create(words, utf16StrLength * 2);
  1114. }
  1115. };
  1116. function swapEndian(word) {
  1117. return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff);
  1118. }
  1119. }());
  1120. (function() {
  1121. // Shortcuts
  1122. var C = CryptoJS;
  1123. var C_lib = C.lib;
  1124. var WordArray = C_lib.WordArray;
  1125. var C_enc = C.enc;
  1126. /**
  1127. * Base64 encoding strategy.
  1128. */
  1129. var Base64 = C_enc.Base64 = {
  1130. /**
  1131. * Converts a word array to a Base64 string.
  1132. *
  1133. * @param {WordArray} wordArray The word array.
  1134. *
  1135. * @return {string} The Base64 string.
  1136. *
  1137. * @static
  1138. *
  1139. * @example
  1140. *
  1141. * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
  1142. */
  1143. stringify: function(wordArray) {
  1144. // Shortcuts
  1145. var words = wordArray.words;
  1146. var sigBytes = wordArray.sigBytes;
  1147. var map = this._map;
  1148. // Clamp excess bits
  1149. wordArray.clamp();
  1150. // Convert
  1151. var base64Chars = [];
  1152. for (var i = 0; i < sigBytes; i += 3) {
  1153. var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  1154. var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
  1155. var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
  1156. var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
  1157. for (var j = 0;
  1158. (j < 4) && (i + j * 0.75 < sigBytes); j++) {
  1159. base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
  1160. }
  1161. }
  1162. // Add padding
  1163. var paddingChar = map.charAt(64);
  1164. if (paddingChar) {
  1165. while (base64Chars.length % 4) {
  1166. base64Chars.push(paddingChar);
  1167. }
  1168. }
  1169. return base64Chars.join('');
  1170. },
  1171. /**
  1172. * Converts a Base64 string to a word array.
  1173. *
  1174. * @param {string} base64Str The Base64 string.
  1175. *
  1176. * @return {WordArray} The word array.
  1177. *
  1178. * @static
  1179. *
  1180. * @example
  1181. *
  1182. * var wordArray = CryptoJS.enc.Base64.parse(base64String);
  1183. */
  1184. parse: function(base64Str) {
  1185. // Shortcuts
  1186. var base64StrLength = base64Str.length;
  1187. var map = this._map;
  1188. var reverseMap = this._reverseMap;
  1189. if (!reverseMap) {
  1190. reverseMap = this._reverseMap = [];
  1191. for (var j = 0; j < map.length; j++) {
  1192. reverseMap[map.charCodeAt(j)] = j;
  1193. }
  1194. }
  1195. // Ignore padding
  1196. var paddingChar = map.charAt(64);
  1197. if (paddingChar) {
  1198. var paddingIndex = base64Str.indexOf(paddingChar);
  1199. if (paddingIndex !== -1) {
  1200. base64StrLength = paddingIndex;
  1201. }
  1202. }
  1203. // Convert
  1204. return parseLoop(base64Str, base64StrLength, reverseMap);
  1205. },
  1206. _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
  1207. };
  1208. function parseLoop(base64Str, base64StrLength, reverseMap) {
  1209. var words = [];
  1210. var nBytes = 0;
  1211. for (var i = 0; i < base64StrLength; i++) {
  1212. if (i % 4) {
  1213. var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
  1214. var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
  1215. var bitsCombined = bits1 | bits2;
  1216. words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8);
  1217. nBytes++;
  1218. }
  1219. }
  1220. return WordArray.create(words, nBytes);
  1221. }
  1222. }());
  1223. (function() {
  1224. // Shortcuts
  1225. var C = CryptoJS;
  1226. var C_lib = C.lib;
  1227. var WordArray = C_lib.WordArray;
  1228. var C_enc = C.enc;
  1229. /**
  1230. * Base64url encoding strategy.
  1231. */
  1232. var Base64url = C_enc.Base64url = {
  1233. /**
  1234. * Converts a word array to a Base64url string.
  1235. *
  1236. * @param {WordArray} wordArray The word array.
  1237. *
  1238. * @param {boolean} urlSafe Whether to use url safe
  1239. *
  1240. * @return {string} The Base64url string.
  1241. *
  1242. * @static
  1243. *
  1244. * @example
  1245. *
  1246. * var base64String = CryptoJS.enc.Base64url.stringify(wordArray);
  1247. */
  1248. stringify: function(wordArray, urlSafe = true) {
  1249. // Shortcuts
  1250. var words = wordArray.words;
  1251. var sigBytes = wordArray.sigBytes;
  1252. var map = urlSafe ? this._safe_map : this._map;
  1253. // Clamp excess bits
  1254. wordArray.clamp();
  1255. // Convert
  1256. var base64Chars = [];
  1257. for (var i = 0; i < sigBytes; i += 3) {
  1258. var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  1259. var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
  1260. var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
  1261. var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
  1262. for (var j = 0;
  1263. (j < 4) && (i + j * 0.75 < sigBytes); j++) {
  1264. base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
  1265. }
  1266. }
  1267. // Add padding
  1268. var paddingChar = map.charAt(64);
  1269. if (paddingChar) {
  1270. while (base64Chars.length % 4) {
  1271. base64Chars.push(paddingChar);
  1272. }
  1273. }
  1274. return base64Chars.join('');
  1275. },
  1276. /**
  1277. * Converts a Base64url string to a word array.
  1278. *
  1279. * @param {string} base64Str The Base64url string.
  1280. *
  1281. * @param {boolean} urlSafe Whether to use url safe
  1282. *
  1283. * @return {WordArray} The word array.
  1284. *
  1285. * @static
  1286. *
  1287. * @example
  1288. *
  1289. * var wordArray = CryptoJS.enc.Base64url.parse(base64String);
  1290. */
  1291. parse: function(base64Str, urlSafe = true) {
  1292. // Shortcuts
  1293. var base64StrLength = base64Str.length;
  1294. var map = urlSafe ? this._safe_map : this._map;
  1295. var reverseMap = this._reverseMap;
  1296. if (!reverseMap) {
  1297. reverseMap = this._reverseMap = [];
  1298. for (var j = 0; j < map.length; j++) {
  1299. reverseMap[map.charCodeAt(j)] = j;
  1300. }
  1301. }
  1302. // Ignore padding
  1303. var paddingChar = map.charAt(64);
  1304. if (paddingChar) {
  1305. var paddingIndex = base64Str.indexOf(paddingChar);
  1306. if (paddingIndex !== -1) {
  1307. base64StrLength = paddingIndex;
  1308. }
  1309. }
  1310. // Convert
  1311. return parseLoop(base64Str, base64StrLength, reverseMap);
  1312. },
  1313. _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
  1314. _safe_map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
  1315. };
  1316. function parseLoop(base64Str, base64StrLength, reverseMap) {
  1317. var words = [];
  1318. var nBytes = 0;
  1319. for (var i = 0; i < base64StrLength; i++) {
  1320. if (i % 4) {
  1321. var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
  1322. var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
  1323. var bitsCombined = bits1 | bits2;
  1324. words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8);
  1325. nBytes++;
  1326. }
  1327. }
  1328. return WordArray.create(words, nBytes);
  1329. }
  1330. }());
  1331. (function(Math) {
  1332. // Shortcuts
  1333. var C = CryptoJS;
  1334. var C_lib = C.lib;
  1335. var WordArray = C_lib.WordArray;
  1336. var Hasher = C_lib.Hasher;
  1337. var C_algo = C.algo;
  1338. // Constants table
  1339. var T = [];
  1340. // Compute constants
  1341. (function() {
  1342. for (var i = 0; i < 64; i++) {
  1343. T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
  1344. }
  1345. }());
  1346. /**
  1347. * MD5 hash algorithm.
  1348. */
  1349. var MD5 = C_algo.MD5 = Hasher.extend({
  1350. _doReset: function() {
  1351. this._hash = new WordArray.init([
  1352. 0x67452301, 0xefcdab89,
  1353. 0x98badcfe, 0x10325476]);
  1354. },
  1355. _doProcessBlock: function(M, offset) {
  1356. // Swap endian
  1357. for (var i = 0; i < 16; i++) {
  1358. // Shortcuts
  1359. var offset_i = offset + i;
  1360. var M_offset_i = M[offset_i];
  1361. M[offset_i] = (
  1362. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00));
  1363. }
  1364. // Shortcuts
  1365. var H = this._hash.words;
  1366. var M_offset_0 = M[offset + 0];
  1367. var M_offset_1 = M[offset + 1];
  1368. var M_offset_2 = M[offset + 2];
  1369. var M_offset_3 = M[offset + 3];
  1370. var M_offset_4 = M[offset + 4];
  1371. var M_offset_5 = M[offset + 5];
  1372. var M_offset_6 = M[offset + 6];
  1373. var M_offset_7 = M[offset + 7];
  1374. var M_offset_8 = M[offset + 8];
  1375. var M_offset_9 = M[offset + 9];
  1376. var M_offset_10 = M[offset + 10];
  1377. var M_offset_11 = M[offset + 11];
  1378. var M_offset_12 = M[offset + 12];
  1379. var M_offset_13 = M[offset + 13];
  1380. var M_offset_14 = M[offset + 14];
  1381. var M_offset_15 = M[offset + 15];
  1382. // Working varialbes
  1383. var a = H[0];
  1384. var b = H[1];
  1385. var c = H[2];
  1386. var d = H[3];
  1387. // Computation
  1388. a = FF(a, b, c, d, M_offset_0, 7, T[0]);
  1389. d = FF(d, a, b, c, M_offset_1, 12, T[1]);
  1390. c = FF(c, d, a, b, M_offset_2, 17, T[2]);
  1391. b = FF(b, c, d, a, M_offset_3, 22, T[3]);
  1392. a = FF(a, b, c, d, M_offset_4, 7, T[4]);
  1393. d = FF(d, a, b, c, M_offset_5, 12, T[5]);
  1394. c = FF(c, d, a, b, M_offset_6, 17, T[6]);
  1395. b = FF(b, c, d, a, M_offset_7, 22, T[7]);
  1396. a = FF(a, b, c, d, M_offset_8, 7, T[8]);
  1397. d = FF(d, a, b, c, M_offset_9, 12, T[9]);
  1398. c = FF(c, d, a, b, M_offset_10, 17, T[10]);
  1399. b = FF(b, c, d, a, M_offset_11, 22, T[11]);
  1400. a = FF(a, b, c, d, M_offset_12, 7, T[12]);
  1401. d = FF(d, a, b, c, M_offset_13, 12, T[13]);
  1402. c = FF(c, d, a, b, M_offset_14, 17, T[14]);
  1403. b = FF(b, c, d, a, M_offset_15, 22, T[15]);
  1404. a = GG(a, b, c, d, M_offset_1, 5, T[16]);
  1405. d = GG(d, a, b, c, M_offset_6, 9, T[17]);
  1406. c = GG(c, d, a, b, M_offset_11, 14, T[18]);
  1407. b = GG(b, c, d, a, M_offset_0, 20, T[19]);
  1408. a = GG(a, b, c, d, M_offset_5, 5, T[20]);
  1409. d = GG(d, a, b, c, M_offset_10, 9, T[21]);
  1410. c = GG(c, d, a, b, M_offset_15, 14, T[22]);
  1411. b = GG(b, c, d, a, M_offset_4, 20, T[23]);
  1412. a = GG(a, b, c, d, M_offset_9, 5, T[24]);
  1413. d = GG(d, a, b, c, M_offset_14, 9, T[25]);
  1414. c = GG(c, d, a, b, M_offset_3, 14, T[26]);
  1415. b = GG(b, c, d, a, M_offset_8, 20, T[27]);
  1416. a = GG(a, b, c, d, M_offset_13, 5, T[28]);
  1417. d = GG(d, a, b, c, M_offset_2, 9, T[29]);
  1418. c = GG(c, d, a, b, M_offset_7, 14, T[30]);
  1419. b = GG(b, c, d, a, M_offset_12, 20, T[31]);
  1420. a = HH(a, b, c, d, M_offset_5, 4, T[32]);
  1421. d = HH(d, a, b, c, M_offset_8, 11, T[33]);
  1422. c = HH(c, d, a, b, M_offset_11, 16, T[34]);
  1423. b = HH(b, c, d, a, M_offset_14, 23, T[35]);
  1424. a = HH(a, b, c, d, M_offset_1, 4, T[36]);
  1425. d = HH(d, a, b, c, M_offset_4, 11, T[37]);
  1426. c = HH(c, d, a, b, M_offset_7, 16, T[38]);
  1427. b = HH(b, c, d, a, M_offset_10, 23, T[39]);
  1428. a = HH(a, b, c, d, M_offset_13, 4, T[40]);
  1429. d = HH(d, a, b, c, M_offset_0, 11, T[41]);
  1430. c = HH(c, d, a, b, M_offset_3, 16, T[42]);
  1431. b = HH(b, c, d, a, M_offset_6, 23, T[43]);
  1432. a = HH(a, b, c, d, M_offset_9, 4, T[44]);
  1433. d = HH(d, a, b, c, M_offset_12, 11, T[45]);
  1434. c = HH(c, d, a, b, M_offset_15, 16, T[46]);
  1435. b = HH(b, c, d, a, M_offset_2, 23, T[47]);
  1436. a = II(a, b, c, d, M_offset_0, 6, T[48]);
  1437. d = II(d, a, b, c, M_offset_7, 10, T[49]);
  1438. c = II(c, d, a, b, M_offset_14, 15, T[50]);
  1439. b = II(b, c, d, a, M_offset_5, 21, T[51]);
  1440. a = II(a, b, c, d, M_offset_12, 6, T[52]);
  1441. d = II(d, a, b, c, M_offset_3, 10, T[53]);
  1442. c = II(c, d, a, b, M_offset_10, 15, T[54]);
  1443. b = II(b, c, d, a, M_offset_1, 21, T[55]);
  1444. a = II(a, b, c, d, M_offset_8, 6, T[56]);
  1445. d = II(d, a, b, c, M_offset_15, 10, T[57]);
  1446. c = II(c, d, a, b, M_offset_6, 15, T[58]);
  1447. b = II(b, c, d, a, M_offset_13, 21, T[59]);
  1448. a = II(a, b, c, d, M_offset_4, 6, T[60]);
  1449. d = II(d, a, b, c, M_offset_11, 10, T[61]);
  1450. c = II(c, d, a, b, M_offset_2, 15, T[62]);
  1451. b = II(b, c, d, a, M_offset_9, 21, T[63]);
  1452. // Intermediate hash value
  1453. H[0] = (H[0] + a) | 0;
  1454. H[1] = (H[1] + b) | 0;
  1455. H[2] = (H[2] + c) | 0;
  1456. H[3] = (H[3] + d) | 0;
  1457. },
  1458. _doFinalize: function() {
  1459. // Shortcuts
  1460. var data = this._data;
  1461. var dataWords = data.words;
  1462. var nBitsTotal = this._nDataBytes * 8;
  1463. var nBitsLeft = data.sigBytes * 8;
  1464. // Add padding
  1465. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  1466. var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
  1467. var nBitsTotalL = nBitsTotal;
  1468. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
  1469. (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00));
  1470. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  1471. (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00));
  1472. data.sigBytes = (dataWords.length + 1) * 4;
  1473. // Hash final blocks
  1474. this._process();
  1475. // Shortcuts
  1476. var hash = this._hash;
  1477. var H = hash.words;
  1478. // Swap endian
  1479. for (var i = 0; i < 4; i++) {
  1480. // Shortcut
  1481. var H_i = H[i];
  1482. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  1483. }
  1484. // Return final computed hash
  1485. return hash;
  1486. },
  1487. clone: function() {
  1488. var clone = Hasher.clone.call(this);
  1489. clone._hash = this._hash.clone();
  1490. return clone;
  1491. }
  1492. });
  1493. function FF(a, b, c, d, x, s, t) {
  1494. var n = a + ((b & c) | (~b & d)) + x + t;
  1495. return ((n << s) | (n >>> (32 - s))) + b;
  1496. }
  1497. function GG(a, b, c, d, x, s, t) {
  1498. var n = a + ((b & d) | (c & ~d)) + x + t;
  1499. return ((n << s) | (n >>> (32 - s))) + b;
  1500. }
  1501. function HH(a, b, c, d, x, s, t) {
  1502. var n = a + (b ^ c ^ d) + x + t;
  1503. return ((n << s) | (n >>> (32 - s))) + b;
  1504. }
  1505. function II(a, b, c, d, x, s, t) {
  1506. var n = a + (c ^ (b | ~d)) + x + t;
  1507. return ((n << s) | (n >>> (32 - s))) + b;
  1508. }
  1509. /**
  1510. * Shortcut function to the hasher's object interface.
  1511. *
  1512. * @param {WordArray|string} message The message to hash.
  1513. *
  1514. * @return {WordArray} The hash.
  1515. *
  1516. * @static
  1517. *
  1518. * @example
  1519. *
  1520. * var hash = CryptoJS.MD5('message');
  1521. * var hash = CryptoJS.MD5(wordArray);
  1522. */
  1523. C.MD5 = Hasher._createHelper(MD5);
  1524. /**
  1525. * Shortcut function to the HMAC's object interface.
  1526. *
  1527. * @param {WordArray|string} message The message to hash.
  1528. * @param {WordArray|string} key The secret key.
  1529. *
  1530. * @return {WordArray} The HMAC.
  1531. *
  1532. * @static
  1533. *
  1534. * @example
  1535. *
  1536. * var hmac = CryptoJS.HmacMD5(message, key);
  1537. */
  1538. C.HmacMD5 = Hasher._createHmacHelper(MD5);
  1539. }(Math));
  1540. (function() {
  1541. // Shortcuts
  1542. var C = CryptoJS;
  1543. var C_lib = C.lib;
  1544. var WordArray = C_lib.WordArray;
  1545. var Hasher = C_lib.Hasher;
  1546. var C_algo = C.algo;
  1547. // Reusable object
  1548. var W = [];
  1549. /**
  1550. * SHA-1 hash algorithm.
  1551. */
  1552. var SHA1 = C_algo.SHA1 = Hasher.extend({
  1553. _doReset: function() {
  1554. this._hash = new WordArray.init([
  1555. 0x67452301, 0xefcdab89,
  1556. 0x98badcfe, 0x10325476,
  1557. 0xc3d2e1f0]);
  1558. },
  1559. _doProcessBlock: function(M, offset) {
  1560. // Shortcut
  1561. var H = this._hash.words;
  1562. // Working variables
  1563. var a = H[0];
  1564. var b = H[1];
  1565. var c = H[2];
  1566. var d = H[3];
  1567. var e = H[4];
  1568. // Computation
  1569. for (var i = 0; i < 80; i++) {
  1570. if (i < 16) {
  1571. W[i] = M[offset + i] | 0;
  1572. } else {
  1573. var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  1574. W[i] = (n << 1) | (n >>> 31);
  1575. }
  1576. var t = ((a << 5) | (a >>> 27)) + e + W[i];
  1577. if (i < 20) {
  1578. t += ((b & c) | (~b & d)) + 0x5a827999;
  1579. } else if (i < 40) {
  1580. t += (b ^ c ^ d) + 0x6ed9eba1;
  1581. } else if (i < 60) {
  1582. t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
  1583. } else /* if (i < 80) */ {
  1584. t += (b ^ c ^ d) - 0x359d3e2a;
  1585. }
  1586. e = d;
  1587. d = c;
  1588. c = (b << 30) | (b >>> 2);
  1589. b = a;
  1590. a = t;
  1591. }
  1592. // Intermediate hash value
  1593. H[0] = (H[0] + a) | 0;
  1594. H[1] = (H[1] + b) | 0;
  1595. H[2] = (H[2] + c) | 0;
  1596. H[3] = (H[3] + d) | 0;
  1597. H[4] = (H[4] + e) | 0;
  1598. },
  1599. _doFinalize: function() {
  1600. // Shortcuts
  1601. var data = this._data;
  1602. var dataWords = data.words;
  1603. var nBitsTotal = this._nDataBytes * 8;
  1604. var nBitsLeft = data.sigBytes * 8;
  1605. // Add padding
  1606. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  1607. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  1608. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  1609. data.sigBytes = dataWords.length * 4;
  1610. // Hash final blocks
  1611. this._process();
  1612. // Return final computed hash
  1613. return this._hash;
  1614. },
  1615. clone: function() {
  1616. var clone = Hasher.clone.call(this);
  1617. clone._hash = this._hash.clone();
  1618. return clone;
  1619. }
  1620. });
  1621. /**
  1622. * Shortcut function to the hasher's object interface.
  1623. *
  1624. * @param {WordArray|string} message The message to hash.
  1625. *
  1626. * @return {WordArray} The hash.
  1627. *
  1628. * @static
  1629. *
  1630. * @example
  1631. *
  1632. * var hash = CryptoJS.SHA1('message');
  1633. * var hash = CryptoJS.SHA1(wordArray);
  1634. */
  1635. C.SHA1 = Hasher._createHelper(SHA1);
  1636. /**
  1637. * Shortcut function to the HMAC's object interface.
  1638. *
  1639. * @param {WordArray|string} message The message to hash.
  1640. * @param {WordArray|string} key The secret key.
  1641. *
  1642. * @return {WordArray} The HMAC.
  1643. *
  1644. * @static
  1645. *
  1646. * @example
  1647. *
  1648. * var hmac = CryptoJS.HmacSHA1(message, key);
  1649. */
  1650. C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
  1651. }());
  1652. (function(Math) {
  1653. // Shortcuts
  1654. var C = CryptoJS;
  1655. var C_lib = C.lib;
  1656. var WordArray = C_lib.WordArray;
  1657. var Hasher = C_lib.Hasher;
  1658. var C_algo = C.algo;
  1659. // Initialization and round constants tables
  1660. var H = [];
  1661. var K = [];
  1662. // Compute constants
  1663. (function() {
  1664. function isPrime(n) {
  1665. var sqrtN = Math.sqrt(n);
  1666. for (var factor = 2; factor <= sqrtN; factor++) {
  1667. if (!(n % factor)) {
  1668. return false;
  1669. }
  1670. }
  1671. return true;
  1672. }
  1673. function getFractionalBits(n) {
  1674. return ((n - (n | 0)) * 0x100000000) | 0;
  1675. }
  1676. var n = 2;
  1677. var nPrime = 0;
  1678. while (nPrime < 64) {
  1679. if (isPrime(n)) {
  1680. if (nPrime < 8) {
  1681. H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
  1682. }
  1683. K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
  1684. nPrime++;
  1685. }
  1686. n++;
  1687. }
  1688. }());
  1689. // Reusable object
  1690. var W = [];
  1691. /**
  1692. * SHA-256 hash algorithm.
  1693. */
  1694. var SHA256 = C_algo.SHA256 = Hasher.extend({
  1695. _doReset: function() {
  1696. this._hash = new WordArray.init(H.slice(0));
  1697. },
  1698. _doProcessBlock: function(M, offset) {
  1699. // Shortcut
  1700. var H = this._hash.words;
  1701. // Working variables
  1702. var a = H[0];
  1703. var b = H[1];
  1704. var c = H[2];
  1705. var d = H[3];
  1706. var e = H[4];
  1707. var f = H[5];
  1708. var g = H[6];
  1709. var h = H[7];
  1710. // Computation
  1711. for (var i = 0; i < 64; i++) {
  1712. if (i < 16) {
  1713. W[i] = M[offset + i] | 0;
  1714. } else {
  1715. var gamma0x = W[i - 15];
  1716. var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ ((gamma0x << 14) | (gamma0x >>> 18)) ^ (gamma0x >>> 3);
  1717. var gamma1x = W[i - 2];
  1718. var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ ((gamma1x << 13) | (gamma1x >>> 19)) ^ (gamma1x >>> 10);
  1719. W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
  1720. }
  1721. var ch = (e & f) ^ (~e & g);
  1722. var maj = (a & b) ^ (a & c) ^ (b & c);
  1723. var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
  1724. var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
  1725. var t1 = h + sigma1 + ch + K[i] + W[i];
  1726. var t2 = sigma0 + maj;
  1727. h = g;
  1728. g = f;
  1729. f = e;
  1730. e = (d + t1) | 0;
  1731. d = c;
  1732. c = b;
  1733. b = a;
  1734. a = (t1 + t2) | 0;
  1735. }
  1736. // Intermediate hash value
  1737. H[0] = (H[0] + a) | 0;
  1738. H[1] = (H[1] + b) | 0;
  1739. H[2] = (H[2] + c) | 0;
  1740. H[3] = (H[3] + d) | 0;
  1741. H[4] = (H[4] + e) | 0;
  1742. H[5] = (H[5] + f) | 0;
  1743. H[6] = (H[6] + g) | 0;
  1744. H[7] = (H[7] + h) | 0;
  1745. },
  1746. _doFinalize: function() {
  1747. // Shortcuts
  1748. var data = this._data;
  1749. var dataWords = data.words;
  1750. var nBitsTotal = this._nDataBytes * 8;
  1751. var nBitsLeft = data.sigBytes * 8;
  1752. // Add padding
  1753. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  1754. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  1755. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  1756. data.sigBytes = dataWords.length * 4;
  1757. // Hash final blocks
  1758. this._process();
  1759. // Return final computed hash
  1760. return this._hash;
  1761. },
  1762. clone: function() {
  1763. var clone = Hasher.clone.call(this);
  1764. clone._hash = this._hash.clone();
  1765. return clone;
  1766. }
  1767. });
  1768. /**
  1769. * Shortcut function to the hasher's object interface.
  1770. *
  1771. * @param {WordArray|string} message The message to hash.
  1772. *
  1773. * @return {WordArray} The hash.
  1774. *
  1775. * @static
  1776. *
  1777. * @example
  1778. *
  1779. * var hash = CryptoJS.SHA256('message');
  1780. * var hash = CryptoJS.SHA256(wordArray);
  1781. */
  1782. C.SHA256 = Hasher._createHelper(SHA256);
  1783. /**
  1784. * Shortcut function to the HMAC's object interface.
  1785. *
  1786. * @param {WordArray|string} message The message to hash.
  1787. * @param {WordArray|string} key The secret key.
  1788. *
  1789. * @return {WordArray} The HMAC.
  1790. *
  1791. * @static
  1792. *
  1793. * @example
  1794. *
  1795. * var hmac = CryptoJS.HmacSHA256(message, key);
  1796. */
  1797. C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
  1798. }(Math));
  1799. (function() {
  1800. // Shortcuts
  1801. var C = CryptoJS;
  1802. var C_lib = C.lib;
  1803. var WordArray = C_lib.WordArray;
  1804. var C_algo = C.algo;
  1805. var SHA256 = C_algo.SHA256;
  1806. /**
  1807. * SHA-224 hash algorithm.
  1808. */
  1809. var SHA224 = C_algo.SHA224 = SHA256.extend({
  1810. _doReset: function() {
  1811. this._hash = new WordArray.init([
  1812. 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
  1813. 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4]);
  1814. },
  1815. _doFinalize: function() {
  1816. var hash = SHA256._doFinalize.call(this);
  1817. hash.sigBytes -= 4;
  1818. return hash;
  1819. }
  1820. });
  1821. /**
  1822. * Shortcut function to the hasher's object interface.
  1823. *
  1824. * @param {WordArray|string} message The message to hash.
  1825. *
  1826. * @return {WordArray} The hash.
  1827. *
  1828. * @static
  1829. *
  1830. * @example
  1831. *
  1832. * var hash = CryptoJS.SHA224('message');
  1833. * var hash = CryptoJS.SHA224(wordArray);
  1834. */
  1835. C.SHA224 = SHA256._createHelper(SHA224);
  1836. /**
  1837. * Shortcut function to the HMAC's object interface.
  1838. *
  1839. * @param {WordArray|string} message The message to hash.
  1840. * @param {WordArray|string} key The secret key.
  1841. *
  1842. * @return {WordArray} The HMAC.
  1843. *
  1844. * @static
  1845. *
  1846. * @example
  1847. *
  1848. * var hmac = CryptoJS.HmacSHA224(message, key);
  1849. */
  1850. C.HmacSHA224 = SHA256._createHmacHelper(SHA224);
  1851. }());
  1852. (function() {
  1853. // Shortcuts
  1854. var C = CryptoJS;
  1855. var C_lib = C.lib;
  1856. var Hasher = C_lib.Hasher;
  1857. var C_x64 = C.x64;
  1858. var X64Word = C_x64.Word;
  1859. var X64WordArray = C_x64.WordArray;
  1860. var C_algo = C.algo;
  1861. function X64Word_create() {
  1862. return X64Word.create.apply(X64Word, arguments);
  1863. }
  1864. // Constants
  1865. var K = [
  1866. X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd),
  1867. X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc),
  1868. X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019),
  1869. X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118),
  1870. X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe),
  1871. X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2),
  1872. X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1),
  1873. X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694),
  1874. X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3),
  1875. X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65),
  1876. X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483),
  1877. X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5),
  1878. X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210),
  1879. X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4),
  1880. X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725),
  1881. X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70),
  1882. X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926),
  1883. X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df),
  1884. X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8),
  1885. X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b),
  1886. X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001),
  1887. X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30),
  1888. X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910),
  1889. X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8),
  1890. X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53),
  1891. X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8),
  1892. X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb),
  1893. X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3),
  1894. X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60),
  1895. X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec),
  1896. X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9),
  1897. X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b),
  1898. X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207),
  1899. X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178),
  1900. X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6),
  1901. X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b),
  1902. X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493),
  1903. X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c),
  1904. X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a),
  1905. X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817)];
  1906. // Reusable objects
  1907. var W = [];
  1908. (function() {
  1909. for (var i = 0; i < 80; i++) {
  1910. W[i] = X64Word_create();
  1911. }
  1912. }());
  1913. /**
  1914. * SHA-512 hash algorithm.
  1915. */
  1916. var SHA512 = C_algo.SHA512 = Hasher.extend({
  1917. _doReset: function() {
  1918. this._hash = new X64WordArray.init([
  1919. new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b),
  1920. new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1),
  1921. new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f),
  1922. new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179)]);
  1923. },
  1924. _doProcessBlock: function(M, offset) {
  1925. // Shortcuts
  1926. var H = this._hash.words;
  1927. var H0 = H[0];
  1928. var H1 = H[1];
  1929. var H2 = H[2];
  1930. var H3 = H[3];
  1931. var H4 = H[4];
  1932. var H5 = H[5];
  1933. var H6 = H[6];
  1934. var H7 = H[7];
  1935. var H0h = H0.high;
  1936. var H0l = H0.low;
  1937. var H1h = H1.high;
  1938. var H1l = H1.low;
  1939. var H2h = H2.high;
  1940. var H2l = H2.low;
  1941. var H3h = H3.high;
  1942. var H3l = H3.low;
  1943. var H4h = H4.high;
  1944. var H4l = H4.low;
  1945. var H5h = H5.high;
  1946. var H5l = H5.low;
  1947. var H6h = H6.high;
  1948. var H6l = H6.low;
  1949. var H7h = H7.high;
  1950. var H7l = H7.low;
  1951. // Working variables
  1952. var ah = H0h;
  1953. var al = H0l;
  1954. var bh = H1h;
  1955. var bl = H1l;
  1956. var ch = H2h;
  1957. var cl = H2l;
  1958. var dh = H3h;
  1959. var dl = H3l;
  1960. var eh = H4h;
  1961. var el = H4l;
  1962. var fh = H5h;
  1963. var fl = H5l;
  1964. var gh = H6h;
  1965. var gl = H6l;
  1966. var hh = H7h;
  1967. var hl = H7l;
  1968. // Rounds
  1969. for (var i = 0; i < 80; i++) {
  1970. var Wil;
  1971. var Wih;
  1972. // Shortcut
  1973. var Wi = W[i];
  1974. // Extend message
  1975. if (i < 16) {
  1976. Wih = Wi.high = M[offset + i * 2] | 0;
  1977. Wil = Wi.low = M[offset + i * 2 + 1] | 0;
  1978. } else {
  1979. // Gamma0
  1980. var gamma0x = W[i - 15];
  1981. var gamma0xh = gamma0x.high;
  1982. var gamma0xl = gamma0x.low;
  1983. var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7);
  1984. var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25));
  1985. // Gamma1
  1986. var gamma1x = W[i - 2];
  1987. var gamma1xh = gamma1x.high;
  1988. var gamma1xl = gamma1x.low;
  1989. var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6);
  1990. var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26));
  1991. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  1992. var Wi7 = W[i - 7];
  1993. var Wi7h = Wi7.high;
  1994. var Wi7l = Wi7.low;
  1995. var Wi16 = W[i - 16];
  1996. var Wi16h = Wi16.high;
  1997. var Wi16l = Wi16.low;
  1998. Wil = gamma0l + Wi7l;
  1999. Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0);
  2000. Wil = Wil + gamma1l;
  2001. Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0);
  2002. Wil = Wil + Wi16l;
  2003. Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0);
  2004. Wi.high = Wih;
  2005. Wi.low = Wil;
  2006. }
  2007. var chh = (eh & fh) ^ (~eh & gh);
  2008. var chl = (el & fl) ^ (~el & gl);
  2009. var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch);
  2010. var majl = (al & bl) ^ (al & cl) ^ (bl & cl);
  2011. var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7));
  2012. var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7));
  2013. var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9));
  2014. var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9));
  2015. // t1 = h + sigma1 + ch + K[i] + W[i]
  2016. var Ki = K[i];
  2017. var Kih = Ki.high;
  2018. var Kil = Ki.low;
  2019. var t1l = hl + sigma1l;
  2020. var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0);
  2021. var t1l = t1l + chl;
  2022. var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0);
  2023. var t1l = t1l + Kil;
  2024. var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0);
  2025. var t1l = t1l + Wil;
  2026. var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0);
  2027. // t2 = sigma0 + maj
  2028. var t2l = sigma0l + majl;
  2029. var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0);
  2030. // Update working variables
  2031. hh = gh;
  2032. hl = gl;
  2033. gh = fh;
  2034. gl = fl;
  2035. fh = eh;
  2036. fl = el;
  2037. el = (dl + t1l) | 0;
  2038. eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0;
  2039. dh = ch;
  2040. dl = cl;
  2041. ch = bh;
  2042. cl = bl;
  2043. bh = ah;
  2044. bl = al;
  2045. al = (t1l + t2l) | 0;
  2046. ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0;
  2047. }
  2048. // Intermediate hash value
  2049. H0l = H0.low = (H0l + al);
  2050. H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0));
  2051. H1l = H1.low = (H1l + bl);
  2052. H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0));
  2053. H2l = H2.low = (H2l + cl);
  2054. H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0));
  2055. H3l = H3.low = (H3l + dl);
  2056. H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0));
  2057. H4l = H4.low = (H4l + el);
  2058. H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0));
  2059. H5l = H5.low = (H5l + fl);
  2060. H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0));
  2061. H6l = H6.low = (H6l + gl);
  2062. H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0));
  2063. H7l = H7.low = (H7l + hl);
  2064. H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0));
  2065. },
  2066. _doFinalize: function() {
  2067. // Shortcuts
  2068. var data = this._data;
  2069. var dataWords = data.words;
  2070. var nBitsTotal = this._nDataBytes * 8;
  2071. var nBitsLeft = data.sigBytes * 8;
  2072. // Add padding
  2073. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  2074. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000);
  2075. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal;
  2076. data.sigBytes = dataWords.length * 4;
  2077. // Hash final blocks
  2078. this._process();
  2079. // Convert hash to 32-bit word array before returning
  2080. var hash = this._hash.toX32();
  2081. // Return final computed hash
  2082. return hash;
  2083. },
  2084. clone: function() {
  2085. var clone = Hasher.clone.call(this);
  2086. clone._hash = this._hash.clone();
  2087. return clone;
  2088. },
  2089. blockSize: 1024 / 32
  2090. });
  2091. /**
  2092. * Shortcut function to the hasher's object interface.
  2093. *
  2094. * @param {WordArray|string} message The message to hash.
  2095. *
  2096. * @return {WordArray} The hash.
  2097. *
  2098. * @static
  2099. *
  2100. * @example
  2101. *
  2102. * var hash = CryptoJS.SHA512('message');
  2103. * var hash = CryptoJS.SHA512(wordArray);
  2104. */
  2105. C.SHA512 = Hasher._createHelper(SHA512);
  2106. /**
  2107. * Shortcut function to the HMAC's object interface.
  2108. *
  2109. * @param {WordArray|string} message The message to hash.
  2110. * @param {WordArray|string} key The secret key.
  2111. *
  2112. * @return {WordArray} The HMAC.
  2113. *
  2114. * @static
  2115. *
  2116. * @example
  2117. *
  2118. * var hmac = CryptoJS.HmacSHA512(message, key);
  2119. */
  2120. C.HmacSHA512 = Hasher._createHmacHelper(SHA512);
  2121. }());
  2122. (function() {
  2123. // Shortcuts
  2124. var C = CryptoJS;
  2125. var C_x64 = C.x64;
  2126. var X64Word = C_x64.Word;
  2127. var X64WordArray = C_x64.WordArray;
  2128. var C_algo = C.algo;
  2129. var SHA512 = C_algo.SHA512;
  2130. /**
  2131. * SHA-384 hash algorithm.
  2132. */
  2133. var SHA384 = C_algo.SHA384 = SHA512.extend({
  2134. _doReset: function() {
  2135. this._hash = new X64WordArray.init([
  2136. new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507),
  2137. new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939),
  2138. new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511),
  2139. new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4)]);
  2140. },
  2141. _doFinalize: function() {
  2142. var hash = SHA512._doFinalize.call(this);
  2143. hash.sigBytes -= 16;
  2144. return hash;
  2145. }
  2146. });
  2147. /**
  2148. * Shortcut function to the hasher's object interface.
  2149. *
  2150. * @param {WordArray|string} message The message to hash.
  2151. *
  2152. * @return {WordArray} The hash.
  2153. *
  2154. * @static
  2155. *
  2156. * @example
  2157. *
  2158. * var hash = CryptoJS.SHA384('message');
  2159. * var hash = CryptoJS.SHA384(wordArray);
  2160. */
  2161. C.SHA384 = SHA512._createHelper(SHA384);
  2162. /**
  2163. * Shortcut function to the HMAC's object interface.
  2164. *
  2165. * @param {WordArray|string} message The message to hash.
  2166. * @param {WordArray|string} key The secret key.
  2167. *
  2168. * @return {WordArray} The HMAC.
  2169. *
  2170. * @static
  2171. *
  2172. * @example
  2173. *
  2174. * var hmac = CryptoJS.HmacSHA384(message, key);
  2175. */
  2176. C.HmacSHA384 = SHA512._createHmacHelper(SHA384);
  2177. }());
  2178. (function(Math) {
  2179. // Shortcuts
  2180. var C = CryptoJS;
  2181. var C_lib = C.lib;
  2182. var WordArray = C_lib.WordArray;
  2183. var Hasher = C_lib.Hasher;
  2184. var C_x64 = C.x64;
  2185. var X64Word = C_x64.Word;
  2186. var C_algo = C.algo;
  2187. // Constants tables
  2188. var RHO_OFFSETS = [];
  2189. var PI_INDEXES = [];
  2190. var ROUND_CONSTANTS = [];
  2191. // Compute Constants
  2192. (function() {
  2193. // Compute rho offset constants
  2194. var x = 1,
  2195. y = 0;
  2196. for (var t = 0; t < 24; t++) {
  2197. RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64;
  2198. var newX = y % 5;
  2199. var newY = (2 * x + 3 * y) % 5;
  2200. x = newX;
  2201. y = newY;
  2202. }
  2203. // Compute pi index constants
  2204. for (var x = 0; x < 5; x++) {
  2205. for (var y = 0; y < 5; y++) {
  2206. PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5;
  2207. }
  2208. }
  2209. // Compute round constants
  2210. var LFSR = 0x01;
  2211. for (var i = 0; i < 24; i++) {
  2212. var roundConstantMsw = 0;
  2213. var roundConstantLsw = 0;
  2214. for (var j = 0; j < 7; j++) {
  2215. if (LFSR & 0x01) {
  2216. var bitPosition = (1 << j) - 1;
  2217. if (bitPosition < 32) {
  2218. roundConstantLsw ^= 1 << bitPosition;
  2219. } else /* if (bitPosition >= 32) */ {
  2220. roundConstantMsw ^= 1 << (bitPosition - 32);
  2221. }
  2222. }
  2223. // Compute next LFSR
  2224. if (LFSR & 0x80) {
  2225. // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1
  2226. LFSR = (LFSR << 1) ^ 0x71;
  2227. } else {
  2228. LFSR <<= 1;
  2229. }
  2230. }
  2231. ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw);
  2232. }
  2233. }());
  2234. // Reusable objects for temporary values
  2235. var T = [];
  2236. (function() {
  2237. for (var i = 0; i < 25; i++) {
  2238. T[i] = X64Word.create();
  2239. }
  2240. }());
  2241. /**
  2242. * SHA-3 hash algorithm.
  2243. */
  2244. var SHA3 = C_algo.SHA3 = Hasher.extend({
  2245. /**
  2246. * Configuration options.
  2247. *
  2248. * @property {number} outputLength
  2249. * The desired number of bits in the output hash.
  2250. * Only values permitted are: 224, 256, 384, 512.
  2251. * Default: 512
  2252. */
  2253. cfg: Hasher.cfg.extend({
  2254. outputLength: 512
  2255. }),
  2256. _doReset: function() {
  2257. var state = this._state = []
  2258. for (var i = 0; i < 25; i++) {
  2259. state[i] = new X64Word.init();
  2260. }
  2261. this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32;
  2262. },
  2263. _doProcessBlock: function(M, offset) {
  2264. // Shortcuts
  2265. var state = this._state;
  2266. var nBlockSizeLanes = this.blockSize / 2;
  2267. // Absorb
  2268. for (var i = 0; i < nBlockSizeLanes; i++) {
  2269. // Shortcuts
  2270. var M2i = M[offset + 2 * i];
  2271. var M2i1 = M[offset + 2 * i + 1];
  2272. // Swap endian
  2273. M2i = (
  2274. (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00));
  2275. M2i1 = (
  2276. (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00));
  2277. // Absorb message into state
  2278. var lane = state[i];
  2279. lane.high ^= M2i1;
  2280. lane.low ^= M2i;
  2281. }
  2282. // Rounds
  2283. for (var round = 0; round < 24; round++) {
  2284. // Theta
  2285. for (var x = 0; x < 5; x++) {
  2286. // Mix column lanes
  2287. var tMsw = 0,
  2288. tLsw = 0;
  2289. for (var y = 0; y < 5; y++) {
  2290. var lane = state[x + 5 * y];
  2291. tMsw ^= lane.high;
  2292. tLsw ^= lane.low;
  2293. }
  2294. // Temporary values
  2295. var Tx = T[x];
  2296. Tx.high = tMsw;
  2297. Tx.low = tLsw;
  2298. }
  2299. for (var x = 0; x < 5; x++) {
  2300. // Shortcuts
  2301. var Tx4 = T[(x + 4) % 5];
  2302. var Tx1 = T[(x + 1) % 5];
  2303. var Tx1Msw = Tx1.high;
  2304. var Tx1Lsw = Tx1.low;
  2305. // Mix surrounding columns
  2306. var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31));
  2307. var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31));
  2308. for (var y = 0; y < 5; y++) {
  2309. var lane = state[x + 5 * y];
  2310. lane.high ^= tMsw;
  2311. lane.low ^= tLsw;
  2312. }
  2313. }
  2314. // Rho Pi
  2315. for (var laneIndex = 1; laneIndex < 25; laneIndex++) {
  2316. var tMsw;
  2317. var tLsw;
  2318. // Shortcuts
  2319. var lane = state[laneIndex];
  2320. var laneMsw = lane.high;
  2321. var laneLsw = lane.low;
  2322. var rhoOffset = RHO_OFFSETS[laneIndex];
  2323. // Rotate lanes
  2324. if (rhoOffset < 32) {
  2325. tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset));
  2326. tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset));
  2327. } else /* if (rhoOffset >= 32) */ {
  2328. tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset));
  2329. tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset));
  2330. }
  2331. // Transpose lanes
  2332. var TPiLane = T[PI_INDEXES[laneIndex]];
  2333. TPiLane.high = tMsw;
  2334. TPiLane.low = tLsw;
  2335. }
  2336. // Rho pi at x = y = 0
  2337. var T0 = T[0];
  2338. var state0 = state[0];
  2339. T0.high = state0.high;
  2340. T0.low = state0.low;
  2341. // Chi
  2342. for (var x = 0; x < 5; x++) {
  2343. for (var y = 0; y < 5; y++) {
  2344. // Shortcuts
  2345. var laneIndex = x + 5 * y;
  2346. var lane = state[laneIndex];
  2347. var TLane = T[laneIndex];
  2348. var Tx1Lane = T[((x + 1) % 5) + 5 * y];
  2349. var Tx2Lane = T[((x + 2) % 5) + 5 * y];
  2350. // Mix rows
  2351. lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high);
  2352. lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low);
  2353. }
  2354. }
  2355. // Iota
  2356. var lane = state[0];
  2357. var roundConstant = ROUND_CONSTANTS[round];
  2358. lane.high ^= roundConstant.high;
  2359. lane.low ^= roundConstant.low;
  2360. }
  2361. },
  2362. _doFinalize: function() {
  2363. // Shortcuts
  2364. var data = this._data;
  2365. var dataWords = data.words;
  2366. var nBitsTotal = this._nDataBytes * 8;
  2367. var nBitsLeft = data.sigBytes * 8;
  2368. var blockSizeBits = this.blockSize * 32;
  2369. // Add padding
  2370. dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32);
  2371. dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80;
  2372. data.sigBytes = dataWords.length * 4;
  2373. // Hash final blocks
  2374. this._process();
  2375. // Shortcuts
  2376. var state = this._state;
  2377. var outputLengthBytes = this.cfg.outputLength / 8;
  2378. var outputLengthLanes = outputLengthBytes / 8;
  2379. // Squeeze
  2380. var hashWords = [];
  2381. for (var i = 0; i < outputLengthLanes; i++) {
  2382. // Shortcuts
  2383. var lane = state[i];
  2384. var laneMsw = lane.high;
  2385. var laneLsw = lane.low;
  2386. // Swap endian
  2387. laneMsw = (
  2388. (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00));
  2389. laneLsw = (
  2390. (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00));
  2391. // Squeeze state to retrieve hash
  2392. hashWords.push(laneLsw);
  2393. hashWords.push(laneMsw);
  2394. }
  2395. // Return final computed hash
  2396. return new WordArray.init(hashWords, outputLengthBytes);
  2397. },
  2398. clone: function() {
  2399. var clone = Hasher.clone.call(this);
  2400. var state = clone._state = this._state.slice(0);
  2401. for (var i = 0; i < 25; i++) {
  2402. state[i] = state[i].clone();
  2403. }
  2404. return clone;
  2405. }
  2406. });
  2407. /**
  2408. * Shortcut function to the hasher's object interface.
  2409. *
  2410. * @param {WordArray|string} message The message to hash.
  2411. *
  2412. * @return {WordArray} The hash.
  2413. *
  2414. * @static
  2415. *
  2416. * @example
  2417. *
  2418. * var hash = CryptoJS.SHA3('message');
  2419. * var hash = CryptoJS.SHA3(wordArray);
  2420. */
  2421. C.SHA3 = Hasher._createHelper(SHA3);
  2422. /**
  2423. * Shortcut function to the HMAC's object interface.
  2424. *
  2425. * @param {WordArray|string} message The message to hash.
  2426. * @param {WordArray|string} key The secret key.
  2427. *
  2428. * @return {WordArray} The HMAC.
  2429. *
  2430. * @static
  2431. *
  2432. * @example
  2433. *
  2434. * var hmac = CryptoJS.HmacSHA3(message, key);
  2435. */
  2436. C.HmacSHA3 = Hasher._createHmacHelper(SHA3);
  2437. }(Math));
  2438. /** @preserve
  2439. (c) 2012 by Cédric Mesnil. All rights reserved.
  2440. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  2441. - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2442. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  2443. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2444. */
  2445. (function(Math) {
  2446. // Shortcuts
  2447. var C = CryptoJS;
  2448. var C_lib = C.lib;
  2449. var WordArray = C_lib.WordArray;
  2450. var Hasher = C_lib.Hasher;
  2451. var C_algo = C.algo;
  2452. // Constants table
  2453. var _zl = WordArray.create([
  2454. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  2455. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  2456. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  2457. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  2458. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]);
  2459. var _zr = WordArray.create([
  2460. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  2461. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  2462. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  2463. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  2464. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]);
  2465. var _sl = WordArray.create([
  2466. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  2467. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  2468. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  2469. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  2470. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6]);
  2471. var _sr = WordArray.create([
  2472. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  2473. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  2474. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  2475. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  2476. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]);
  2477. var _hl = WordArray.create([0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]);
  2478. var _hr = WordArray.create([0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]);
  2479. /**
  2480. * RIPEMD160 hash algorithm.
  2481. */
  2482. var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({
  2483. _doReset: function() {
  2484. this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]);
  2485. },
  2486. _doProcessBlock: function(M, offset) {
  2487. // Swap endian
  2488. for (var i = 0; i < 16; i++) {
  2489. // Shortcuts
  2490. var offset_i = offset + i;
  2491. var M_offset_i = M[offset_i];
  2492. // Swap
  2493. M[offset_i] = (
  2494. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00));
  2495. }
  2496. // Shortcut
  2497. var H = this._hash.words;
  2498. var hl = _hl.words;
  2499. var hr = _hr.words;
  2500. var zl = _zl.words;
  2501. var zr = _zr.words;
  2502. var sl = _sl.words;
  2503. var sr = _sr.words;
  2504. // Working variables
  2505. var al, bl, cl, dl, el;
  2506. var ar, br, cr, dr, er;
  2507. ar = al = H[0];
  2508. br = bl = H[1];
  2509. cr = cl = H[2];
  2510. dr = dl = H[3];
  2511. er = el = H[4];
  2512. // Computation
  2513. var t;
  2514. for (var i = 0; i < 80; i += 1) {
  2515. t = (al + M[offset + zl[i]]) | 0;
  2516. if (i < 16) {
  2517. t += f1(bl, cl, dl) + hl[0];
  2518. } else if (i < 32) {
  2519. t += f2(bl, cl, dl) + hl[1];
  2520. } else if (i < 48) {
  2521. t += f3(bl, cl, dl) + hl[2];
  2522. } else if (i < 64) {
  2523. t += f4(bl, cl, dl) + hl[3];
  2524. } else { // if (i<80) {
  2525. t += f5(bl, cl, dl) + hl[4];
  2526. }
  2527. t = t | 0;
  2528. t = rotl(t, sl[i]);
  2529. t = (t + el) | 0;
  2530. al = el;
  2531. el = dl;
  2532. dl = rotl(cl, 10);
  2533. cl = bl;
  2534. bl = t;
  2535. t = (ar + M[offset + zr[i]]) | 0;
  2536. if (i < 16) {
  2537. t += f5(br, cr, dr) + hr[0];
  2538. } else if (i < 32) {
  2539. t += f4(br, cr, dr) + hr[1];
  2540. } else if (i < 48) {
  2541. t += f3(br, cr, dr) + hr[2];
  2542. } else if (i < 64) {
  2543. t += f2(br, cr, dr) + hr[3];
  2544. } else { // if (i<80) {
  2545. t += f1(br, cr, dr) + hr[4];
  2546. }
  2547. t = t | 0;
  2548. t = rotl(t, sr[i]);
  2549. t = (t + er) | 0;
  2550. ar = er;
  2551. er = dr;
  2552. dr = rotl(cr, 10);
  2553. cr = br;
  2554. br = t;
  2555. }
  2556. // Intermediate hash value
  2557. t = (H[1] + cl + dr) | 0;
  2558. H[1] = (H[2] + dl + er) | 0;
  2559. H[2] = (H[3] + el + ar) | 0;
  2560. H[3] = (H[4] + al + br) | 0;
  2561. H[4] = (H[0] + bl + cr) | 0;
  2562. H[0] = t;
  2563. },
  2564. _doFinalize: function() {
  2565. // Shortcuts
  2566. var data = this._data;
  2567. var dataWords = data.words;
  2568. var nBitsTotal = this._nDataBytes * 8;
  2569. var nBitsLeft = data.sigBytes * 8;
  2570. // Add padding
  2571. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  2572. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  2573. (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00));
  2574. data.sigBytes = (dataWords.length + 1) * 4;
  2575. // Hash final blocks
  2576. this._process();
  2577. // Shortcuts
  2578. var hash = this._hash;
  2579. var H = hash.words;
  2580. // Swap endian
  2581. for (var i = 0; i < 5; i++) {
  2582. // Shortcut
  2583. var H_i = H[i];
  2584. // Swap
  2585. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  2586. }
  2587. // Return final computed hash
  2588. return hash;
  2589. },
  2590. clone: function() {
  2591. var clone = Hasher.clone.call(this);
  2592. clone._hash = this._hash.clone();
  2593. return clone;
  2594. }
  2595. });
  2596. function f1(x, y, z) {
  2597. return ((x) ^ (y) ^ (z));
  2598. }
  2599. function f2(x, y, z) {
  2600. return (((x) & (y)) | ((~x) & (z)));
  2601. }
  2602. function f3(x, y, z) {
  2603. return (((x) | (~ (y))) ^ (z));
  2604. }
  2605. function f4(x, y, z) {
  2606. return (((x) & (z)) | ((y) & (~ (z))));
  2607. }
  2608. function f5(x, y, z) {
  2609. return ((x) ^ ((y) | (~ (z))));
  2610. }
  2611. function rotl(x, n) {
  2612. return (x << n) | (x >>> (32 - n));
  2613. }
  2614. /**
  2615. * Shortcut function to the hasher's object interface.
  2616. *
  2617. * @param {WordArray|string} message The message to hash.
  2618. *
  2619. * @return {WordArray} The hash.
  2620. *
  2621. * @static
  2622. *
  2623. * @example
  2624. *
  2625. * var hash = CryptoJS.RIPEMD160('message');
  2626. * var hash = CryptoJS.RIPEMD160(wordArray);
  2627. */
  2628. C.RIPEMD160 = Hasher._createHelper(RIPEMD160);
  2629. /**
  2630. * Shortcut function to the HMAC's object interface.
  2631. *
  2632. * @param {WordArray|string} message The message to hash.
  2633. * @param {WordArray|string} key The secret key.
  2634. *
  2635. * @return {WordArray} The HMAC.
  2636. *
  2637. * @static
  2638. *
  2639. * @example
  2640. *
  2641. * var hmac = CryptoJS.HmacRIPEMD160(message, key);
  2642. */
  2643. C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160);
  2644. }(Math));
  2645. (function() {
  2646. // Shortcuts
  2647. var C = CryptoJS;
  2648. var C_lib = C.lib;
  2649. var Base = C_lib.Base;
  2650. var C_enc = C.enc;
  2651. var Utf8 = C_enc.Utf8;
  2652. var C_algo = C.algo;
  2653. /**
  2654. * HMAC algorithm.
  2655. */
  2656. var HMAC = C_algo.HMAC = Base.extend({
  2657. /**
  2658. * Initializes a newly created HMAC.
  2659. *
  2660. * @param {Hasher} hasher The hash algorithm to use.
  2661. * @param {WordArray|string} key The secret key.
  2662. *
  2663. * @example
  2664. *
  2665. * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
  2666. */
  2667. init: function(hasher, key) {
  2668. // Init hasher
  2669. hasher = this._hasher = new hasher.init();
  2670. // Convert string to WordArray, else assume WordArray already
  2671. if (typeof key == 'string') {
  2672. key = Utf8.parse(key);
  2673. }
  2674. // Shortcuts
  2675. var hasherBlockSize = hasher.blockSize;
  2676. var hasherBlockSizeBytes = hasherBlockSize * 4;
  2677. // Allow arbitrary length keys
  2678. if (key.sigBytes > hasherBlockSizeBytes) {
  2679. key = hasher.finalize(key);
  2680. }
  2681. // Clamp excess bits
  2682. key.clamp();
  2683. // Clone key for inner and outer pads
  2684. var oKey = this._oKey = key.clone();
  2685. var iKey = this._iKey = key.clone();
  2686. // Shortcuts
  2687. var oKeyWords = oKey.words;
  2688. var iKeyWords = iKey.words;
  2689. // XOR keys with pad constants
  2690. for (var i = 0; i < hasherBlockSize; i++) {
  2691. oKeyWords[i] ^= 0x5c5c5c5c;
  2692. iKeyWords[i] ^= 0x36363636;
  2693. }
  2694. oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
  2695. // Set initial values
  2696. this.reset();
  2697. },
  2698. /**
  2699. * Resets this HMAC to its initial state.
  2700. *
  2701. * @example
  2702. *
  2703. * hmacHasher.reset();
  2704. */
  2705. reset: function() {
  2706. // Shortcut
  2707. var hasher = this._hasher;
  2708. // Reset
  2709. hasher.reset();
  2710. hasher.update(this._iKey);
  2711. },
  2712. /**
  2713. * Updates this HMAC with a message.
  2714. *
  2715. * @param {WordArray|string} messageUpdate The message to append.
  2716. *
  2717. * @return {HMAC} This HMAC instance.
  2718. *
  2719. * @example
  2720. *
  2721. * hmacHasher.update('message');
  2722. * hmacHasher.update(wordArray);
  2723. */
  2724. update: function(messageUpdate) {
  2725. this._hasher.update(messageUpdate);
  2726. // Chainable
  2727. return this;
  2728. },
  2729. /**
  2730. * Finalizes the HMAC computation.
  2731. * Note that the finalize operation is effectively a destructive, read-once operation.
  2732. *
  2733. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  2734. *
  2735. * @return {WordArray} The HMAC.
  2736. *
  2737. * @example
  2738. *
  2739. * var hmac = hmacHasher.finalize();
  2740. * var hmac = hmacHasher.finalize('message');
  2741. * var hmac = hmacHasher.finalize(wordArray);
  2742. */
  2743. finalize: function(messageUpdate) {
  2744. // Shortcut
  2745. var hasher = this._hasher;
  2746. // Compute HMAC
  2747. var innerHash = hasher.finalize(messageUpdate);
  2748. hasher.reset();
  2749. var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
  2750. return hmac;
  2751. }
  2752. });
  2753. }());
  2754. (function() {
  2755. // Shortcuts
  2756. var C = CryptoJS;
  2757. var C_lib = C.lib;
  2758. var Base = C_lib.Base;
  2759. var WordArray = C_lib.WordArray;
  2760. var C_algo = C.algo;
  2761. var SHA1 = C_algo.SHA1;
  2762. var HMAC = C_algo.HMAC;
  2763. /**
  2764. * Password-Based Key Derivation Function 2 algorithm.
  2765. */
  2766. var PBKDF2 = C_algo.PBKDF2 = Base.extend({
  2767. /**
  2768. * Configuration options.
  2769. *
  2770. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  2771. * @property {Hasher} hasher The hasher to use. Default: SHA1
  2772. * @property {number} iterations The number of iterations to perform. Default: 1
  2773. */
  2774. cfg: Base.extend({
  2775. keySize: 128 / 32,
  2776. hasher: SHA1,
  2777. iterations: 1
  2778. }),
  2779. /**
  2780. * Initializes a newly created key derivation function.
  2781. *
  2782. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  2783. *
  2784. * @example
  2785. *
  2786. * var kdf = CryptoJS.algo.PBKDF2.create();
  2787. * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
  2788. * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
  2789. */
  2790. init: function(cfg) {
  2791. this.cfg = this.cfg.extend(cfg);
  2792. },
  2793. /**
  2794. * Computes the Password-Based Key Derivation Function 2.
  2795. *
  2796. * @param {WordArray|string} password The password.
  2797. * @param {WordArray|string} salt A salt.
  2798. *
  2799. * @return {WordArray} The derived key.
  2800. *
  2801. * @example
  2802. *
  2803. * var key = kdf.compute(password, salt);
  2804. */
  2805. compute: function(password, salt) {
  2806. // Shortcut
  2807. var cfg = this.cfg;
  2808. // Init HMAC
  2809. var hmac = HMAC.create(cfg.hasher, password);
  2810. // Initial values
  2811. var derivedKey = WordArray.create();
  2812. var blockIndex = WordArray.create([0x00000001]);
  2813. // Shortcuts
  2814. var derivedKeyWords = derivedKey.words;
  2815. var blockIndexWords = blockIndex.words;
  2816. var keySize = cfg.keySize;
  2817. var iterations = cfg.iterations;
  2818. // Generate key
  2819. while (derivedKeyWords.length < keySize) {
  2820. var block = hmac.update(salt).finalize(blockIndex);
  2821. hmac.reset();
  2822. // Shortcuts
  2823. var blockWords = block.words;
  2824. var blockWordsLength = blockWords.length;
  2825. // Iterations
  2826. var intermediate = block;
  2827. for (var i = 1; i < iterations; i++) {
  2828. intermediate = hmac.finalize(intermediate);
  2829. hmac.reset();
  2830. // Shortcut
  2831. var intermediateWords = intermediate.words;
  2832. // XOR intermediate with block
  2833. for (var j = 0; j < blockWordsLength; j++) {
  2834. blockWords[j] ^= intermediateWords[j];
  2835. }
  2836. }
  2837. derivedKey.concat(block);
  2838. blockIndexWords[0]++;
  2839. }
  2840. derivedKey.sigBytes = keySize * 4;
  2841. return derivedKey;
  2842. }
  2843. });
  2844. /**
  2845. * Computes the Password-Based Key Derivation Function 2.
  2846. *
  2847. * @param {WordArray|string} password The password.
  2848. * @param {WordArray|string} salt A salt.
  2849. * @param {Object} cfg (Optional) The configuration options to use for this computation.
  2850. *
  2851. * @return {WordArray} The derived key.
  2852. *
  2853. * @static
  2854. *
  2855. * @example
  2856. *
  2857. * var key = CryptoJS.PBKDF2(password, salt);
  2858. * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
  2859. * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
  2860. */
  2861. C.PBKDF2 = function(password, salt, cfg) {
  2862. return PBKDF2.create(cfg).compute(password, salt);
  2863. };
  2864. }());
  2865. (function() {
  2866. // Shortcuts
  2867. var C = CryptoJS;
  2868. var C_lib = C.lib;
  2869. var Base = C_lib.Base;
  2870. var WordArray = C_lib.WordArray;
  2871. var C_algo = C.algo;
  2872. var MD5 = C_algo.MD5;
  2873. /**
  2874. * This key derivation function is meant to conform with EVP_BytesToKey.
  2875. * www.openssl.org/docs/crypto/EVP_BytesToKey.html
  2876. */
  2877. var EvpKDF = C_algo.EvpKDF = Base.extend({
  2878. /**
  2879. * Configuration options.
  2880. *
  2881. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  2882. * @property {Hasher} hasher The hash algorithm to use. Default: MD5
  2883. * @property {number} iterations The number of iterations to perform. Default: 1
  2884. */
  2885. cfg: Base.extend({
  2886. keySize: 128 / 32,
  2887. hasher: MD5,
  2888. iterations: 1
  2889. }),
  2890. /**
  2891. * Initializes a newly created key derivation function.
  2892. *
  2893. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  2894. *
  2895. * @example
  2896. *
  2897. * var kdf = CryptoJS.algo.EvpKDF.create();
  2898. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
  2899. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
  2900. */
  2901. init: function(cfg) {
  2902. this.cfg = this.cfg.extend(cfg);
  2903. },
  2904. /**
  2905. * Derives a key from a password.
  2906. *
  2907. * @param {WordArray|string} password The password.
  2908. * @param {WordArray|string} salt A salt.
  2909. *
  2910. * @return {WordArray} The derived key.
  2911. *
  2912. * @example
  2913. *
  2914. * var key = kdf.compute(password, salt);
  2915. */
  2916. compute: function(password, salt) {
  2917. var block;
  2918. // Shortcut
  2919. var cfg = this.cfg;
  2920. // Init hasher
  2921. var hasher = cfg.hasher.create();
  2922. // Initial values
  2923. var derivedKey = WordArray.create();
  2924. // Shortcuts
  2925. var derivedKeyWords = derivedKey.words;
  2926. var keySize = cfg.keySize;
  2927. var iterations = cfg.iterations;
  2928. // Generate key
  2929. while (derivedKeyWords.length < keySize) {
  2930. if (block) {
  2931. hasher.update(block);
  2932. }
  2933. block = hasher.update(password).finalize(salt);
  2934. hasher.reset();
  2935. // Iterations
  2936. for (var i = 1; i < iterations; i++) {
  2937. block = hasher.finalize(block);
  2938. hasher.reset();
  2939. }
  2940. derivedKey.concat(block);
  2941. }
  2942. derivedKey.sigBytes = keySize * 4;
  2943. return derivedKey;
  2944. }
  2945. });
  2946. /**
  2947. * Derives a key from a password.
  2948. *
  2949. * @param {WordArray|string} password The password.
  2950. * @param {WordArray|string} salt A salt.
  2951. * @param {Object} cfg (Optional) The configuration options to use for this computation.
  2952. *
  2953. * @return {WordArray} The derived key.
  2954. *
  2955. * @static
  2956. *
  2957. * @example
  2958. *
  2959. * var key = CryptoJS.EvpKDF(password, salt);
  2960. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
  2961. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
  2962. */
  2963. C.EvpKDF = function(password, salt, cfg) {
  2964. return EvpKDF.create(cfg).compute(password, salt);
  2965. };
  2966. }());
  2967. /**
  2968. * Cipher core components.
  2969. */
  2970. CryptoJS.lib.Cipher || (function(undefined) {
  2971. // Shortcuts
  2972. var C = CryptoJS;
  2973. var C_lib = C.lib;
  2974. var Base = C_lib.Base;
  2975. var WordArray = C_lib.WordArray;
  2976. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
  2977. var C_enc = C.enc;
  2978. var Utf8 = C_enc.Utf8;
  2979. var Base64 = C_enc.Base64;
  2980. var C_algo = C.algo;
  2981. var EvpKDF = C_algo.EvpKDF;
  2982. /**
  2983. * Abstract base cipher template.
  2984. *
  2985. * @property {number} keySize This cipher's key size. Default: 4 (128 bits)
  2986. * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
  2987. * @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
  2988. * @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
  2989. */
  2990. var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
  2991. /**
  2992. * Configuration options.
  2993. *
  2994. * @property {WordArray} iv The IV to use for this operation.
  2995. */
  2996. cfg: Base.extend(),
  2997. /**
  2998. * Creates this cipher in encryption mode.
  2999. *
  3000. * @param {WordArray} key The key.
  3001. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3002. *
  3003. * @return {Cipher} A cipher instance.
  3004. *
  3005. * @static
  3006. *
  3007. * @example
  3008. *
  3009. * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
  3010. */
  3011. createEncryptor: function(key, cfg) {
  3012. return this.create(this._ENC_XFORM_MODE, key, cfg);
  3013. },
  3014. /**
  3015. * Creates this cipher in decryption mode.
  3016. *
  3017. * @param {WordArray} key The key.
  3018. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3019. *
  3020. * @return {Cipher} A cipher instance.
  3021. *
  3022. * @static
  3023. *
  3024. * @example
  3025. *
  3026. * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
  3027. */
  3028. createDecryptor: function(key, cfg) {
  3029. return this.create(this._DEC_XFORM_MODE, key, cfg);
  3030. },
  3031. /**
  3032. * Initializes a newly created cipher.
  3033. *
  3034. * @param {number} xformMode Either the encryption or decryption transormation mode constant.
  3035. * @param {WordArray} key The key.
  3036. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3037. *
  3038. * @example
  3039. *
  3040. * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
  3041. */
  3042. init: function(xformMode, key, cfg) {
  3043. // Apply config defaults
  3044. this.cfg = this.cfg.extend(cfg);
  3045. // Store transform mode and key
  3046. this._xformMode = xformMode;
  3047. this._key = key;
  3048. // Set initial values
  3049. this.reset();
  3050. },
  3051. /**
  3052. * Resets this cipher to its initial state.
  3053. *
  3054. * @example
  3055. *
  3056. * cipher.reset();
  3057. */
  3058. reset: function() {
  3059. // Reset data buffer
  3060. BufferedBlockAlgorithm.reset.call(this);
  3061. // Perform concrete-cipher logic
  3062. this._doReset();
  3063. },
  3064. /**
  3065. * Adds data to be encrypted or decrypted.
  3066. *
  3067. * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
  3068. *
  3069. * @return {WordArray} The data after processing.
  3070. *
  3071. * @example
  3072. *
  3073. * var encrypted = cipher.process('data');
  3074. * var encrypted = cipher.process(wordArray);
  3075. */
  3076. process: function(dataUpdate) {
  3077. // Append
  3078. this._append(dataUpdate);
  3079. // Process available blocks
  3080. return this._process();
  3081. },
  3082. /**
  3083. * Finalizes the encryption or decryption process.
  3084. * Note that the finalize operation is effectively a destructive, read-once operation.
  3085. *
  3086. * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
  3087. *
  3088. * @return {WordArray} The data after final processing.
  3089. *
  3090. * @example
  3091. *
  3092. * var encrypted = cipher.finalize();
  3093. * var encrypted = cipher.finalize('data');
  3094. * var encrypted = cipher.finalize(wordArray);
  3095. */
  3096. finalize: function(dataUpdate) {
  3097. // Final data update
  3098. if (dataUpdate) {
  3099. this._append(dataUpdate);
  3100. }
  3101. // Perform concrete-cipher logic
  3102. var finalProcessedData = this._doFinalize();
  3103. return finalProcessedData;
  3104. },
  3105. keySize: 128 / 32,
  3106. ivSize: 128 / 32,
  3107. _ENC_XFORM_MODE: 1,
  3108. _DEC_XFORM_MODE: 2,
  3109. /**
  3110. * Creates shortcut functions to a cipher's object interface.
  3111. *
  3112. * @param {Cipher} cipher The cipher to create a helper for.
  3113. *
  3114. * @return {Object} An object with encrypt and decrypt shortcut functions.
  3115. *
  3116. * @static
  3117. *
  3118. * @example
  3119. *
  3120. * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
  3121. */
  3122. _createHelper: (function() {
  3123. function selectCipherStrategy(key) {
  3124. if (typeof key == 'string') {
  3125. return PasswordBasedCipher;
  3126. } else {
  3127. return SerializableCipher;
  3128. }
  3129. }
  3130. return function(cipher) {
  3131. return {
  3132. encrypt: function(message, key, cfg) {
  3133. return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
  3134. },
  3135. decrypt: function(ciphertext, key, cfg) {
  3136. return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
  3137. }
  3138. };
  3139. };
  3140. }())
  3141. });
  3142. /**
  3143. * Abstract base stream cipher template.
  3144. *
  3145. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
  3146. */
  3147. var StreamCipher = C_lib.StreamCipher = Cipher.extend({
  3148. _doFinalize: function() {
  3149. // Process partial blocks
  3150. var finalProcessedBlocks = this._process( !! 'flush');
  3151. return finalProcessedBlocks;
  3152. },
  3153. blockSize: 1
  3154. });
  3155. /**
  3156. * Mode namespace.
  3157. */
  3158. var C_mode = C.mode = {};
  3159. /**
  3160. * Abstract base block cipher mode template.
  3161. */
  3162. var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
  3163. /**
  3164. * Creates this mode for encryption.
  3165. *
  3166. * @param {Cipher} cipher A block cipher instance.
  3167. * @param {Array} iv The IV words.
  3168. *
  3169. * @static
  3170. *
  3171. * @example
  3172. *
  3173. * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
  3174. */
  3175. createEncryptor: function(cipher, iv) {
  3176. return this.Encryptor.create(cipher, iv);
  3177. },
  3178. /**
  3179. * Creates this mode for decryption.
  3180. *
  3181. * @param {Cipher} cipher A block cipher instance.
  3182. * @param {Array} iv The IV words.
  3183. *
  3184. * @static
  3185. *
  3186. * @example
  3187. *
  3188. * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
  3189. */
  3190. createDecryptor: function(cipher, iv) {
  3191. return this.Decryptor.create(cipher, iv);
  3192. },
  3193. /**
  3194. * Initializes a newly created mode.
  3195. *
  3196. * @param {Cipher} cipher A block cipher instance.
  3197. * @param {Array} iv The IV words.
  3198. *
  3199. * @example
  3200. *
  3201. * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
  3202. */
  3203. init: function(cipher, iv) {
  3204. this._cipher = cipher;
  3205. this._iv = iv;
  3206. }
  3207. });
  3208. /**
  3209. * Cipher Block Chaining mode.
  3210. */
  3211. var CBC = C_mode.CBC = (function() {
  3212. /**
  3213. * Abstract base CBC mode.
  3214. */
  3215. var CBC = BlockCipherMode.extend();
  3216. /**
  3217. * CBC encryptor.
  3218. */
  3219. CBC.Encryptor = CBC.extend({
  3220. /**
  3221. * Processes the data block at offset.
  3222. *
  3223. * @param {Array} words The data words to operate on.
  3224. * @param {number} offset The offset where the block starts.
  3225. *
  3226. * @example
  3227. *
  3228. * mode.processBlock(data.words, offset);
  3229. */
  3230. processBlock: function(words, offset) {
  3231. // Shortcuts
  3232. var cipher = this._cipher;
  3233. var blockSize = cipher.blockSize;
  3234. // XOR and encrypt
  3235. xorBlock.call(this, words, offset, blockSize);
  3236. cipher.encryptBlock(words, offset);
  3237. // Remember this block to use with next block
  3238. this._prevBlock = words.slice(offset, offset + blockSize);
  3239. }
  3240. });
  3241. /**
  3242. * CBC decryptor.
  3243. */
  3244. CBC.Decryptor = CBC.extend({
  3245. /**
  3246. * Processes the data block at offset.
  3247. *
  3248. * @param {Array} words The data words to operate on.
  3249. * @param {number} offset The offset where the block starts.
  3250. *
  3251. * @example
  3252. *
  3253. * mode.processBlock(data.words, offset);
  3254. */
  3255. processBlock: function(words, offset) {
  3256. // Shortcuts
  3257. var cipher = this._cipher;
  3258. var blockSize = cipher.blockSize;
  3259. // Remember this block to use with next block
  3260. var thisBlock = words.slice(offset, offset + blockSize);
  3261. // Decrypt and XOR
  3262. cipher.decryptBlock(words, offset);
  3263. xorBlock.call(this, words, offset, blockSize);
  3264. // This block becomes the previous block
  3265. this._prevBlock = thisBlock;
  3266. }
  3267. });
  3268. function xorBlock(words, offset, blockSize) {
  3269. var block;
  3270. // Shortcut
  3271. var iv = this._iv;
  3272. // Choose mixing block
  3273. if (iv) {
  3274. block = iv;
  3275. // Remove IV for subsequent blocks
  3276. this._iv = undefined;
  3277. } else {
  3278. block = this._prevBlock;
  3279. }
  3280. // XOR blocks
  3281. for (var i = 0; i < blockSize; i++) {
  3282. words[offset + i] ^= block[i];
  3283. }
  3284. }
  3285. return CBC;
  3286. }());
  3287. /**
  3288. * Padding namespace.
  3289. */
  3290. var C_pad = C.pad = {};
  3291. /**
  3292. * PKCS #5/7 padding strategy.
  3293. */
  3294. var Pkcs7 = C_pad.Pkcs7 = {
  3295. /**
  3296. * Pads data using the algorithm defined in PKCS #5/7.
  3297. *
  3298. * @param {WordArray} data The data to pad.
  3299. * @param {number} blockSize The multiple that the data should be padded to.
  3300. *
  3301. * @static
  3302. *
  3303. * @example
  3304. *
  3305. * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
  3306. */
  3307. pad: function(data, blockSize) {
  3308. // Shortcut
  3309. var blockSizeBytes = blockSize * 4;
  3310. // Count padding bytes
  3311. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  3312. // Create padding word
  3313. var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes;
  3314. // Create padding
  3315. var paddingWords = [];
  3316. for (var i = 0; i < nPaddingBytes; i += 4) {
  3317. paddingWords.push(paddingWord);
  3318. }
  3319. var padding = WordArray.create(paddingWords, nPaddingBytes);
  3320. // Add padding
  3321. data.concat(padding);
  3322. },
  3323. /**
  3324. * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
  3325. *
  3326. * @param {WordArray} data The data to unpad.
  3327. *
  3328. * @static
  3329. *
  3330. * @example
  3331. *
  3332. * CryptoJS.pad.Pkcs7.unpad(wordArray);
  3333. */
  3334. unpad: function(data) {
  3335. // Get number of padding bytes from last byte
  3336. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  3337. // Remove padding
  3338. data.sigBytes -= nPaddingBytes;
  3339. }
  3340. };
  3341. /**
  3342. * Abstract base block cipher template.
  3343. *
  3344. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
  3345. */
  3346. var BlockCipher = C_lib.BlockCipher = Cipher.extend({
  3347. /**
  3348. * Configuration options.
  3349. *
  3350. * @property {Mode} mode The block mode to use. Default: CBC
  3351. * @property {Padding} padding The padding strategy to use. Default: Pkcs7
  3352. */
  3353. cfg: Cipher.cfg.extend({
  3354. mode: CBC,
  3355. padding: Pkcs7
  3356. }),
  3357. reset: function() {
  3358. var modeCreator;
  3359. // Reset cipher
  3360. Cipher.reset.call(this);
  3361. // Shortcuts
  3362. var cfg = this.cfg;
  3363. var iv = cfg.iv;
  3364. var mode = cfg.mode;
  3365. // Reset block mode
  3366. if (this._xformMode == this._ENC_XFORM_MODE) {
  3367. modeCreator = mode.createEncryptor;
  3368. } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  3369. modeCreator = mode.createDecryptor;
  3370. // Keep at least one block in the buffer for unpadding
  3371. this._minBufferSize = 1;
  3372. }
  3373. if (this._mode && this._mode.__creator == modeCreator) {
  3374. this._mode.init(this, iv && iv.words);
  3375. } else {
  3376. this._mode = modeCreator.call(mode, this, iv && iv.words);
  3377. this._mode.__creator = modeCreator;
  3378. }
  3379. },
  3380. _doProcessBlock: function(words, offset) {
  3381. this._mode.processBlock(words, offset);
  3382. },
  3383. _doFinalize: function() {
  3384. var finalProcessedBlocks;
  3385. // Shortcut
  3386. var padding = this.cfg.padding;
  3387. // Finalize
  3388. if (this._xformMode == this._ENC_XFORM_MODE) {
  3389. // Pad data
  3390. padding.pad(this._data, this.blockSize);
  3391. // Process final blocks
  3392. finalProcessedBlocks = this._process( !! 'flush');
  3393. } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  3394. // Process final blocks
  3395. finalProcessedBlocks = this._process( !! 'flush');
  3396. // Unpad data
  3397. padding.unpad(finalProcessedBlocks);
  3398. }
  3399. return finalProcessedBlocks;
  3400. },
  3401. blockSize: 128 / 32
  3402. });
  3403. /**
  3404. * A collection of cipher parameters.
  3405. *
  3406. * @property {WordArray} ciphertext The raw ciphertext.
  3407. * @property {WordArray} key The key to this ciphertext.
  3408. * @property {WordArray} iv The IV used in the ciphering operation.
  3409. * @property {WordArray} salt The salt used with a key derivation function.
  3410. * @property {Cipher} algorithm The cipher algorithm.
  3411. * @property {Mode} mode The block mode used in the ciphering operation.
  3412. * @property {Padding} padding The padding scheme used in the ciphering operation.
  3413. * @property {number} blockSize The block size of the cipher.
  3414. * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
  3415. */
  3416. var CipherParams = C_lib.CipherParams = Base.extend({
  3417. /**
  3418. * Initializes a newly created cipher params object.
  3419. *
  3420. * @param {Object} cipherParams An object with any of the possible cipher parameters.
  3421. *
  3422. * @example
  3423. *
  3424. * var cipherParams = CryptoJS.lib.CipherParams.create({
  3425. * ciphertext: ciphertextWordArray,
  3426. * key: keyWordArray,
  3427. * iv: ivWordArray,
  3428. * salt: saltWordArray,
  3429. * algorithm: CryptoJS.algo.AES,
  3430. * mode: CryptoJS.mode.CBC,
  3431. * padding: CryptoJS.pad.PKCS7,
  3432. * blockSize: 4,
  3433. * formatter: CryptoJS.format.OpenSSL
  3434. * });
  3435. */
  3436. init: function(cipherParams) {
  3437. this.mixIn(cipherParams);
  3438. },
  3439. /**
  3440. * Converts this cipher params object to a string.
  3441. *
  3442. * @param {Format} formatter (Optional) The formatting strategy to use.
  3443. *
  3444. * @return {string} The stringified cipher params.
  3445. *
  3446. * @throws Error If neither the formatter nor the default formatter is set.
  3447. *
  3448. * @example
  3449. *
  3450. * var string = cipherParams + '';
  3451. * var string = cipherParams.toString();
  3452. * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
  3453. */
  3454. toString: function(formatter) {
  3455. return (formatter || this.formatter).stringify(this);
  3456. }
  3457. });
  3458. /**
  3459. * Format namespace.
  3460. */
  3461. var C_format = C.format = {};
  3462. /**
  3463. * OpenSSL formatting strategy.
  3464. */
  3465. var OpenSSLFormatter = C_format.OpenSSL = {
  3466. /**
  3467. * Converts a cipher params object to an OpenSSL-compatible string.
  3468. *
  3469. * @param {CipherParams} cipherParams The cipher params object.
  3470. *
  3471. * @return {string} The OpenSSL-compatible string.
  3472. *
  3473. * @static
  3474. *
  3475. * @example
  3476. *
  3477. * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
  3478. */
  3479. stringify: function(cipherParams) {
  3480. var wordArray;
  3481. // Shortcuts
  3482. var ciphertext = cipherParams.ciphertext;
  3483. var salt = cipherParams.salt;
  3484. // Format
  3485. if (salt) {
  3486. wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
  3487. } else {
  3488. wordArray = ciphertext;
  3489. }
  3490. return wordArray.toString(Base64);
  3491. },
  3492. /**
  3493. * Converts an OpenSSL-compatible string to a cipher params object.
  3494. *
  3495. * @param {string} openSSLStr The OpenSSL-compatible string.
  3496. *
  3497. * @return {CipherParams} The cipher params object.
  3498. *
  3499. * @static
  3500. *
  3501. * @example
  3502. *
  3503. * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
  3504. */
  3505. parse: function(openSSLStr) {
  3506. var salt;
  3507. // Parse base64
  3508. var ciphertext = Base64.parse(openSSLStr);
  3509. // Shortcut
  3510. var ciphertextWords = ciphertext.words;
  3511. // Test for salt
  3512. if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
  3513. // Extract salt
  3514. salt = WordArray.create(ciphertextWords.slice(2, 4));
  3515. // Remove salt from ciphertext
  3516. ciphertextWords.splice(0, 4);
  3517. ciphertext.sigBytes -= 16;
  3518. }
  3519. return CipherParams.create({
  3520. ciphertext: ciphertext,
  3521. salt: salt
  3522. });
  3523. }
  3524. };
  3525. /**
  3526. * A cipher wrapper that returns ciphertext as a serializable cipher params object.
  3527. */
  3528. var SerializableCipher = C_lib.SerializableCipher = Base.extend({
  3529. /**
  3530. * Configuration options.
  3531. *
  3532. * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
  3533. */
  3534. cfg: Base.extend({
  3535. format: OpenSSLFormatter
  3536. }),
  3537. /**
  3538. * Encrypts a message.
  3539. *
  3540. * @param {Cipher} cipher The cipher algorithm to use.
  3541. * @param {WordArray|string} message The message to encrypt.
  3542. * @param {WordArray} key The key.
  3543. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3544. *
  3545. * @return {CipherParams} A cipher params object.
  3546. *
  3547. * @static
  3548. *
  3549. * @example
  3550. *
  3551. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
  3552. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
  3553. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  3554. */
  3555. encrypt: function(cipher, message, key, cfg) {
  3556. // Apply config defaults
  3557. cfg = this.cfg.extend(cfg);
  3558. // Encrypt
  3559. var encryptor = cipher.createEncryptor(key, cfg);
  3560. var ciphertext = encryptor.finalize(message);
  3561. // Shortcut
  3562. var cipherCfg = encryptor.cfg;
  3563. // Create and return serializable cipher params
  3564. return CipherParams.create({
  3565. ciphertext: ciphertext,
  3566. key: key,
  3567. iv: cipherCfg.iv,
  3568. algorithm: cipher,
  3569. mode: cipherCfg.mode,
  3570. padding: cipherCfg.padding,
  3571. blockSize: cipher.blockSize,
  3572. formatter: cfg.format
  3573. });
  3574. },
  3575. /**
  3576. * Decrypts serialized ciphertext.
  3577. *
  3578. * @param {Cipher} cipher The cipher algorithm to use.
  3579. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  3580. * @param {WordArray} key The key.
  3581. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3582. *
  3583. * @return {WordArray} The plaintext.
  3584. *
  3585. * @static
  3586. *
  3587. * @example
  3588. *
  3589. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  3590. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  3591. */
  3592. decrypt: function(cipher, ciphertext, key, cfg) {
  3593. // Apply config defaults
  3594. cfg = this.cfg.extend(cfg);
  3595. // Convert string to CipherParams
  3596. ciphertext = this._parse(ciphertext, cfg.format);
  3597. // Decrypt
  3598. var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
  3599. return plaintext;
  3600. },
  3601. /**
  3602. * Converts serialized ciphertext to CipherParams,
  3603. * else assumed CipherParams already and returns ciphertext unchanged.
  3604. *
  3605. * @param {CipherParams|string} ciphertext The ciphertext.
  3606. * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
  3607. *
  3608. * @return {CipherParams} The unserialized ciphertext.
  3609. *
  3610. * @static
  3611. *
  3612. * @example
  3613. *
  3614. * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
  3615. */
  3616. _parse: function(ciphertext, format) {
  3617. if (typeof ciphertext == 'string') {
  3618. return format.parse(ciphertext, this);
  3619. } else {
  3620. return ciphertext;
  3621. }
  3622. }
  3623. });
  3624. /**
  3625. * Key derivation function namespace.
  3626. */
  3627. var C_kdf = C.kdf = {};
  3628. /**
  3629. * OpenSSL key derivation function.
  3630. */
  3631. var OpenSSLKdf = C_kdf.OpenSSL = {
  3632. /**
  3633. * Derives a key and IV from a password.
  3634. *
  3635. * @param {string} password The password to derive from.
  3636. * @param {number} keySize The size in words of the key to generate.
  3637. * @param {number} ivSize The size in words of the IV to generate.
  3638. * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
  3639. *
  3640. * @return {CipherParams} A cipher params object with the key, IV, and salt.
  3641. *
  3642. * @static
  3643. *
  3644. * @example
  3645. *
  3646. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
  3647. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
  3648. */
  3649. execute: function(password, keySize, ivSize, salt) {
  3650. // Generate random salt
  3651. if (!salt) {
  3652. salt = WordArray.random(64 / 8);
  3653. }
  3654. // Derive key and IV
  3655. var key = EvpKDF.create({
  3656. keySize: keySize + ivSize
  3657. }).compute(password, salt);
  3658. // Separate key and IV
  3659. var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
  3660. key.sigBytes = keySize * 4;
  3661. // Return params
  3662. return CipherParams.create({
  3663. key: key,
  3664. iv: iv,
  3665. salt: salt
  3666. });
  3667. }
  3668. };
  3669. /**
  3670. * A serializable cipher wrapper that derives the key from a password,
  3671. * and returns ciphertext as a serializable cipher params object.
  3672. */
  3673. var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
  3674. /**
  3675. * Configuration options.
  3676. *
  3677. * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
  3678. */
  3679. cfg: SerializableCipher.cfg.extend({
  3680. kdf: OpenSSLKdf
  3681. }),
  3682. /**
  3683. * Encrypts a message using a password.
  3684. *
  3685. * @param {Cipher} cipher The cipher algorithm to use.
  3686. * @param {WordArray|string} message The message to encrypt.
  3687. * @param {string} password The password.
  3688. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3689. *
  3690. * @return {CipherParams} A cipher params object.
  3691. *
  3692. * @static
  3693. *
  3694. * @example
  3695. *
  3696. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
  3697. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
  3698. */
  3699. encrypt: function(cipher, message, password, cfg) {
  3700. // Apply config defaults
  3701. cfg = this.cfg.extend(cfg);
  3702. // Derive key and other params
  3703. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
  3704. // Add IV to config
  3705. cfg.iv = derivedParams.iv;
  3706. // Encrypt
  3707. var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
  3708. // Mix in derived params
  3709. ciphertext.mixIn(derivedParams);
  3710. return ciphertext;
  3711. },
  3712. /**
  3713. * Decrypts serialized ciphertext using a password.
  3714. *
  3715. * @param {Cipher} cipher The cipher algorithm to use.
  3716. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  3717. * @param {string} password The password.
  3718. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3719. *
  3720. * @return {WordArray} The plaintext.
  3721. *
  3722. * @static
  3723. *
  3724. * @example
  3725. *
  3726. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
  3727. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
  3728. */
  3729. decrypt: function(cipher, ciphertext, password, cfg) {
  3730. // Apply config defaults
  3731. cfg = this.cfg.extend(cfg);
  3732. // Convert string to CipherParams
  3733. ciphertext = this._parse(ciphertext, cfg.format);
  3734. // Derive key and other params
  3735. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
  3736. // Add IV to config
  3737. cfg.iv = derivedParams.iv;
  3738. // Decrypt
  3739. var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
  3740. return plaintext;
  3741. }
  3742. });
  3743. }());
  3744. /**
  3745. * Cipher Feedback block mode.
  3746. */
  3747. CryptoJS.mode.CFB = (function() {
  3748. var CFB = CryptoJS.lib.BlockCipherMode.extend();
  3749. CFB.Encryptor = CFB.extend({
  3750. processBlock: function(words, offset) {
  3751. // Shortcuts
  3752. var cipher = this._cipher;
  3753. var blockSize = cipher.blockSize;
  3754. generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  3755. // Remember this block to use with next block
  3756. this._prevBlock = words.slice(offset, offset + blockSize);
  3757. }
  3758. });
  3759. CFB.Decryptor = CFB.extend({
  3760. processBlock: function(words, offset) {
  3761. // Shortcuts
  3762. var cipher = this._cipher;
  3763. var blockSize = cipher.blockSize;
  3764. // Remember this block to use with next block
  3765. var thisBlock = words.slice(offset, offset + blockSize);
  3766. generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  3767. // This block becomes the previous block
  3768. this._prevBlock = thisBlock;
  3769. }
  3770. });
  3771. function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
  3772. var keystream;
  3773. // Shortcut
  3774. var iv = this._iv;
  3775. // Generate keystream
  3776. if (iv) {
  3777. keystream = iv.slice(0);
  3778. // Remove IV for subsequent blocks
  3779. this._iv = undefined;
  3780. } else {
  3781. keystream = this._prevBlock;
  3782. }
  3783. cipher.encryptBlock(keystream, 0);
  3784. // Encrypt
  3785. for (var i = 0; i < blockSize; i++) {
  3786. words[offset + i] ^= keystream[i];
  3787. }
  3788. }
  3789. return CFB;
  3790. }());
  3791. /**
  3792. * Counter block mode.
  3793. */
  3794. CryptoJS.mode.CTR = (function() {
  3795. var CTR = CryptoJS.lib.BlockCipherMode.extend();
  3796. var Encryptor = CTR.Encryptor = CTR.extend({
  3797. processBlock: function(words, offset) {
  3798. // Shortcuts
  3799. var cipher = this._cipher
  3800. var blockSize = cipher.blockSize;
  3801. var iv = this._iv;
  3802. var counter = this._counter;
  3803. // Generate keystream
  3804. if (iv) {
  3805. counter = this._counter = iv.slice(0);
  3806. // Remove IV for subsequent blocks
  3807. this._iv = undefined;
  3808. }
  3809. var keystream = counter.slice(0);
  3810. cipher.encryptBlock(keystream, 0);
  3811. // Increment counter
  3812. counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0
  3813. // Encrypt
  3814. for (var i = 0; i < blockSize; i++) {
  3815. words[offset + i] ^= keystream[i];
  3816. }
  3817. }
  3818. });
  3819. CTR.Decryptor = Encryptor;
  3820. return CTR;
  3821. }());
  3822. /** @preserve
  3823. * Counter block mode compatible with Dr Brian Gladman fileenc.c
  3824. * derived from CryptoJS.mode.CTR
  3825. * Jan Hruby jhruby.web@gmail.com
  3826. */
  3827. CryptoJS.mode.CTRGladman = (function() {
  3828. var CTRGladman = CryptoJS.lib.BlockCipherMode.extend();
  3829. function incWord(word) {
  3830. if (((word >> 24) & 0xff) === 0xff) { //overflow
  3831. var b1 = (word >> 16) & 0xff;
  3832. var b2 = (word >> 8) & 0xff;
  3833. var b3 = word & 0xff;
  3834. if (b1 === 0xff) // overflow b1
  3835. {
  3836. b1 = 0;
  3837. if (b2 === 0xff) {
  3838. b2 = 0;
  3839. if (b3 === 0xff) {
  3840. b3 = 0;
  3841. } else {
  3842. ++b3;
  3843. }
  3844. } else {
  3845. ++b2;
  3846. }
  3847. } else {
  3848. ++b1;
  3849. }
  3850. word = 0;
  3851. word += (b1 << 16);
  3852. word += (b2 << 8);
  3853. word += b3;
  3854. } else {
  3855. word += (0x01 << 24);
  3856. }
  3857. return word;
  3858. }
  3859. function incCounter(counter) {
  3860. if ((counter[0] = incWord(counter[0])) === 0) {
  3861. // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
  3862. counter[1] = incWord(counter[1]);
  3863. }
  3864. return counter;
  3865. }
  3866. var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({
  3867. processBlock: function(words, offset) {
  3868. // Shortcuts
  3869. var cipher = this._cipher
  3870. var blockSize = cipher.blockSize;
  3871. var iv = this._iv;
  3872. var counter = this._counter;
  3873. // Generate keystream
  3874. if (iv) {
  3875. counter = this._counter = iv.slice(0);
  3876. // Remove IV for subsequent blocks
  3877. this._iv = undefined;
  3878. }
  3879. incCounter(counter);
  3880. var keystream = counter.slice(0);
  3881. cipher.encryptBlock(keystream, 0);
  3882. // Encrypt
  3883. for (var i = 0; i < blockSize; i++) {
  3884. words[offset + i] ^= keystream[i];
  3885. }
  3886. }
  3887. });
  3888. CTRGladman.Decryptor = Encryptor;
  3889. return CTRGladman;
  3890. }());
  3891. /**
  3892. * Output Feedback block mode.
  3893. */
  3894. CryptoJS.mode.OFB = (function() {
  3895. var OFB = CryptoJS.lib.BlockCipherMode.extend();
  3896. var Encryptor = OFB.Encryptor = OFB.extend({
  3897. processBlock: function(words, offset) {
  3898. // Shortcuts
  3899. var cipher = this._cipher
  3900. var blockSize = cipher.blockSize;
  3901. var iv = this._iv;
  3902. var keystream = this._keystream;
  3903. // Generate keystream
  3904. if (iv) {
  3905. keystream = this._keystream = iv.slice(0);
  3906. // Remove IV for subsequent blocks
  3907. this._iv = undefined;
  3908. }
  3909. cipher.encryptBlock(keystream, 0);
  3910. // Encrypt
  3911. for (var i = 0; i < blockSize; i++) {
  3912. words[offset + i] ^= keystream[i];
  3913. }
  3914. }
  3915. });
  3916. OFB.Decryptor = Encryptor;
  3917. return OFB;
  3918. }());
  3919. /**
  3920. * Electronic Codebook block mode.
  3921. */
  3922. CryptoJS.mode.ECB = (function() {
  3923. var ECB = CryptoJS.lib.BlockCipherMode.extend();
  3924. ECB.Encryptor = ECB.extend({
  3925. processBlock: function(words, offset) {
  3926. this._cipher.encryptBlock(words, offset);
  3927. }
  3928. });
  3929. ECB.Decryptor = ECB.extend({
  3930. processBlock: function(words, offset) {
  3931. this._cipher.decryptBlock(words, offset);
  3932. }
  3933. });
  3934. return ECB;
  3935. }());
  3936. /**
  3937. * ANSI X.923 padding strategy.
  3938. */
  3939. CryptoJS.pad.AnsiX923 = {
  3940. pad: function(data, blockSize) {
  3941. // Shortcuts
  3942. var dataSigBytes = data.sigBytes;
  3943. var blockSizeBytes = blockSize * 4;
  3944. // Count padding bytes
  3945. var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes;
  3946. // Compute last byte position
  3947. var lastBytePos = dataSigBytes + nPaddingBytes - 1;
  3948. // Pad
  3949. data.clamp();
  3950. data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8);
  3951. data.sigBytes += nPaddingBytes;
  3952. },
  3953. unpad: function(data) {
  3954. // Get number of padding bytes from last byte
  3955. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  3956. // Remove padding
  3957. data.sigBytes -= nPaddingBytes;
  3958. }
  3959. };
  3960. /**
  3961. * ISO 10126 padding strategy.
  3962. */
  3963. CryptoJS.pad.Iso10126 = {
  3964. pad: function(data, blockSize) {
  3965. // Shortcut
  3966. var blockSizeBytes = blockSize * 4;
  3967. // Count padding bytes
  3968. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  3969. // Pad
  3970. data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)).
  3971. concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
  3972. },
  3973. unpad: function(data) {
  3974. // Get number of padding bytes from last byte
  3975. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  3976. // Remove padding
  3977. data.sigBytes -= nPaddingBytes;
  3978. }
  3979. };
  3980. /**
  3981. * ISO/IEC 9797-1 Padding Method 2.
  3982. */
  3983. CryptoJS.pad.Iso97971 = {
  3984. pad: function(data, blockSize) {
  3985. // Add 0x80 byte
  3986. data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1));
  3987. // Zero pad the rest
  3988. CryptoJS.pad.ZeroPadding.pad(data, blockSize);
  3989. },
  3990. unpad: function(data) {
  3991. // Remove zero padding
  3992. CryptoJS.pad.ZeroPadding.unpad(data);
  3993. // Remove one more byte -- the 0x80 byte
  3994. data.sigBytes--;
  3995. }
  3996. };
  3997. /**
  3998. * Zero padding strategy.
  3999. */
  4000. CryptoJS.pad.ZeroPadding = {
  4001. pad: function(data, blockSize) {
  4002. // Shortcut
  4003. var blockSizeBytes = blockSize * 4;
  4004. // Pad
  4005. data.clamp();
  4006. data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes);
  4007. },
  4008. unpad: function(data) {
  4009. // Shortcut
  4010. var dataWords = data.words;
  4011. // Unpad
  4012. var i = data.sigBytes - 1;
  4013. for (var i = data.sigBytes - 1; i >= 0; i--) {
  4014. if (((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) {
  4015. data.sigBytes = i + 1;
  4016. break;
  4017. }
  4018. }
  4019. }
  4020. };
  4021. /**
  4022. * A noop padding strategy.
  4023. */
  4024. CryptoJS.pad.NoPadding = {
  4025. pad: function() {},
  4026. unpad: function() {}
  4027. };
  4028. (function(undefined) {
  4029. // Shortcuts
  4030. var C = CryptoJS;
  4031. var C_lib = C.lib;
  4032. var CipherParams = C_lib.CipherParams;
  4033. var C_enc = C.enc;
  4034. var Hex = C_enc.Hex;
  4035. var C_format = C.format;
  4036. var HexFormatter = C_format.Hex = {
  4037. /**
  4038. * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
  4039. *
  4040. * @param {CipherParams} cipherParams The cipher params object.
  4041. *
  4042. * @return {string} The hexadecimally encoded string.
  4043. *
  4044. * @static
  4045. *
  4046. * @example
  4047. *
  4048. * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
  4049. */
  4050. stringify: function(cipherParams) {
  4051. return cipherParams.ciphertext.toString(Hex);
  4052. },
  4053. /**
  4054. * Converts a hexadecimally encoded ciphertext string to a cipher params object.
  4055. *
  4056. * @param {string} input The hexadecimally encoded string.
  4057. *
  4058. * @return {CipherParams} The cipher params object.
  4059. *
  4060. * @static
  4061. *
  4062. * @example
  4063. *
  4064. * var cipherParams = CryptoJS.format.Hex.parse(hexString);
  4065. */
  4066. parse: function(input) {
  4067. var ciphertext = Hex.parse(input);
  4068. return CipherParams.create({
  4069. ciphertext: ciphertext
  4070. });
  4071. }
  4072. };
  4073. }());
  4074. (function() {
  4075. // Shortcuts
  4076. var C = CryptoJS;
  4077. var C_lib = C.lib;
  4078. var BlockCipher = C_lib.BlockCipher;
  4079. var C_algo = C.algo;
  4080. // Lookup tables
  4081. var SBOX = [];
  4082. var INV_SBOX = [];
  4083. var SUB_MIX_0 = [];
  4084. var SUB_MIX_1 = [];
  4085. var SUB_MIX_2 = [];
  4086. var SUB_MIX_3 = [];
  4087. var INV_SUB_MIX_0 = [];
  4088. var INV_SUB_MIX_1 = [];
  4089. var INV_SUB_MIX_2 = [];
  4090. var INV_SUB_MIX_3 = [];
  4091. // Compute lookup tables
  4092. (function() {
  4093. // Compute double table
  4094. var d = [];
  4095. for (var i = 0; i < 256; i++) {
  4096. if (i < 128) {
  4097. d[i] = i << 1;
  4098. } else {
  4099. d[i] = (i << 1) ^ 0x11b;
  4100. }
  4101. }
  4102. // Walk GF(2^8)
  4103. var x = 0;
  4104. var xi = 0;
  4105. for (var i = 0; i < 256; i++) {
  4106. // Compute sbox
  4107. var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
  4108. sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
  4109. SBOX[x] = sx;
  4110. INV_SBOX[sx] = x;
  4111. // Compute multiplication
  4112. var x2 = d[x];
  4113. var x4 = d[x2];
  4114. var x8 = d[x4];
  4115. // Compute sub bytes, mix columns tables
  4116. var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
  4117. SUB_MIX_0[x] = (t << 24) | (t >>> 8);
  4118. SUB_MIX_1[x] = (t << 16) | (t >>> 16);
  4119. SUB_MIX_2[x] = (t << 8) | (t >>> 24);
  4120. SUB_MIX_3[x] = t;
  4121. // Compute inv sub bytes, inv mix columns tables
  4122. var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
  4123. INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
  4124. INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
  4125. INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
  4126. INV_SUB_MIX_3[sx] = t;
  4127. // Compute next counter
  4128. if (!x) {
  4129. x = xi = 1;
  4130. } else {
  4131. x = x2 ^ d[d[d[x8 ^ x2]]];
  4132. xi ^= d[d[xi]];
  4133. }
  4134. }
  4135. }());
  4136. // Precomputed Rcon lookup
  4137. var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
  4138. /**
  4139. * AES block cipher algorithm.
  4140. */
  4141. var AES = C_algo.AES = BlockCipher.extend({
  4142. _doReset: function() {
  4143. var t;
  4144. // Skip reset of nRounds has been set before and key did not change
  4145. if (this._nRounds && this._keyPriorReset === this._key) {
  4146. return;
  4147. }
  4148. // Shortcuts
  4149. var key = this._keyPriorReset = this._key;
  4150. var keyWords = key.words;
  4151. var keySize = key.sigBytes / 4;
  4152. // Compute number of rounds
  4153. var nRounds = this._nRounds = keySize + 6;
  4154. // Compute number of key schedule rows
  4155. var ksRows = (nRounds + 1) * 4;
  4156. // Compute key schedule
  4157. var keySchedule = this._keySchedule = [];
  4158. for (var ksRow = 0; ksRow < ksRows; ksRow++) {
  4159. if (ksRow < keySize) {
  4160. keySchedule[ksRow] = keyWords[ksRow];
  4161. } else {
  4162. t = keySchedule[ksRow - 1];
  4163. if (!(ksRow % keySize)) {
  4164. // Rot word
  4165. t = (t << 8) | (t >>> 24);
  4166. // Sub word
  4167. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  4168. // Mix Rcon
  4169. t ^= RCON[(ksRow / keySize) | 0] << 24;
  4170. } else if (keySize > 6 && ksRow % keySize == 4) {
  4171. // Sub word
  4172. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  4173. }
  4174. keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
  4175. }
  4176. }
  4177. // Compute inv key schedule
  4178. var invKeySchedule = this._invKeySchedule = [];
  4179. for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
  4180. var ksRow = ksRows - invKsRow;
  4181. if (invKsRow % 4) {
  4182. var t = keySchedule[ksRow];
  4183. } else {
  4184. var t = keySchedule[ksRow - 4];
  4185. }
  4186. if (invKsRow < 4 || ksRow <= 4) {
  4187. invKeySchedule[invKsRow] = t;
  4188. } else {
  4189. invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
  4190. }
  4191. }
  4192. },
  4193. encryptBlock: function(M, offset) {
  4194. this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
  4195. },
  4196. decryptBlock: function(M, offset) {
  4197. // Swap 2nd and 4th rows
  4198. var t = M[offset + 1];
  4199. M[offset + 1] = M[offset + 3];
  4200. M[offset + 3] = t;
  4201. this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
  4202. // Inv swap 2nd and 4th rows
  4203. var t = M[offset + 1];
  4204. M[offset + 1] = M[offset + 3];
  4205. M[offset + 3] = t;
  4206. },
  4207. _doCryptBlock: function(M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
  4208. // Shortcut
  4209. var nRounds = this._nRounds;
  4210. // Get input, add round key
  4211. var s0 = M[offset] ^ keySchedule[0];
  4212. var s1 = M[offset + 1] ^ keySchedule[1];
  4213. var s2 = M[offset + 2] ^ keySchedule[2];
  4214. var s3 = M[offset + 3] ^ keySchedule[3];
  4215. // Key schedule row counter
  4216. var ksRow = 4;
  4217. // Rounds
  4218. for (var round = 1; round < nRounds; round++) {
  4219. // Shift rows, sub bytes, mix columns, add round key
  4220. var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++];
  4221. var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++];
  4222. var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++];
  4223. var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++];
  4224. // Update state
  4225. s0 = t0;
  4226. s1 = t1;
  4227. s2 = t2;
  4228. s3 = t3;
  4229. }
  4230. // Shift rows, sub bytes, add round key
  4231. var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
  4232. var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
  4233. var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
  4234. var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
  4235. // Set output
  4236. M[offset] = t0;
  4237. M[offset + 1] = t1;
  4238. M[offset + 2] = t2;
  4239. M[offset + 3] = t3;
  4240. },
  4241. keySize: 256 / 32
  4242. });
  4243. /**
  4244. * Shortcut functions to the cipher's object interface.
  4245. *
  4246. * @example
  4247. *
  4248. * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
  4249. * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
  4250. */
  4251. C.AES = BlockCipher._createHelper(AES);
  4252. }());
  4253. (function() {
  4254. // Shortcuts
  4255. var C = CryptoJS;
  4256. var C_lib = C.lib;
  4257. var WordArray = C_lib.WordArray;
  4258. var BlockCipher = C_lib.BlockCipher;
  4259. var C_algo = C.algo;
  4260. // Permuted Choice 1 constants
  4261. var PC1 = [
  4262. 57, 49, 41, 33, 25, 17, 9, 1,
  4263. 58, 50, 42, 34, 26, 18, 10, 2,
  4264. 59, 51, 43, 35, 27, 19, 11, 3,
  4265. 60, 52, 44, 36, 63, 55, 47, 39,
  4266. 31, 23, 15, 7, 62, 54, 46, 38,
  4267. 30, 22, 14, 6, 61, 53, 45, 37,
  4268. 29, 21, 13, 5, 28, 20, 12, 4];
  4269. // Permuted Choice 2 constants
  4270. var PC2 = [
  4271. 14, 17, 11, 24, 1, 5,
  4272. 3, 28, 15, 6, 21, 10,
  4273. 23, 19, 12, 4, 26, 8,
  4274. 16, 7, 27, 20, 13, 2,
  4275. 41, 52, 31, 37, 47, 55,
  4276. 30, 40, 51, 45, 33, 48,
  4277. 44, 49, 39, 56, 34, 53,
  4278. 46, 42, 50, 36, 29, 32];
  4279. // Cumulative bit shift constants
  4280. var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28];
  4281. // SBOXes and round permutation constants
  4282. var SBOX_P = [{
  4283. 0x0: 0x808200,
  4284. 0x10000000: 0x8000,
  4285. 0x20000000: 0x808002,
  4286. 0x30000000: 0x2,
  4287. 0x40000000: 0x200,
  4288. 0x50000000: 0x808202,
  4289. 0x60000000: 0x800202,
  4290. 0x70000000: 0x800000,
  4291. 0x80000000: 0x202,
  4292. 0x90000000: 0x800200,
  4293. 0xa0000000: 0x8200,
  4294. 0xb0000000: 0x808000,
  4295. 0xc0000000: 0x8002,
  4296. 0xd0000000: 0x800002,
  4297. 0xe0000000: 0x0,
  4298. 0xf0000000: 0x8202,
  4299. 0x8000000: 0x0,
  4300. 0x18000000: 0x808202,
  4301. 0x28000000: 0x8202,
  4302. 0x38000000: 0x8000,
  4303. 0x48000000: 0x808200,
  4304. 0x58000000: 0x200,
  4305. 0x68000000: 0x808002,
  4306. 0x78000000: 0x2,
  4307. 0x88000000: 0x800200,
  4308. 0x98000000: 0x8200,
  4309. 0xa8000000: 0x808000,
  4310. 0xb8000000: 0x800202,
  4311. 0xc8000000: 0x800002,
  4312. 0xd8000000: 0x8002,
  4313. 0xe8000000: 0x202,
  4314. 0xf8000000: 0x800000,
  4315. 0x1: 0x8000,
  4316. 0x10000001: 0x2,
  4317. 0x20000001: 0x808200,
  4318. 0x30000001: 0x800000,
  4319. 0x40000001: 0x808002,
  4320. 0x50000001: 0x8200,
  4321. 0x60000001: 0x200,
  4322. 0x70000001: 0x800202,
  4323. 0x80000001: 0x808202,
  4324. 0x90000001: 0x808000,
  4325. 0xa0000001: 0x800002,
  4326. 0xb0000001: 0x8202,
  4327. 0xc0000001: 0x202,
  4328. 0xd0000001: 0x800200,
  4329. 0xe0000001: 0x8002,
  4330. 0xf0000001: 0x0,
  4331. 0x8000001: 0x808202,
  4332. 0x18000001: 0x808000,
  4333. 0x28000001: 0x800000,
  4334. 0x38000001: 0x200,
  4335. 0x48000001: 0x8000,
  4336. 0x58000001: 0x800002,
  4337. 0x68000001: 0x2,
  4338. 0x78000001: 0x8202,
  4339. 0x88000001: 0x8002,
  4340. 0x98000001: 0x800202,
  4341. 0xa8000001: 0x202,
  4342. 0xb8000001: 0x808200,
  4343. 0xc8000001: 0x800200,
  4344. 0xd8000001: 0x0,
  4345. 0xe8000001: 0x8200,
  4346. 0xf8000001: 0x808002
  4347. }, {
  4348. 0x0: 0x40084010,
  4349. 0x1000000: 0x4000,
  4350. 0x2000000: 0x80000,
  4351. 0x3000000: 0x40080010,
  4352. 0x4000000: 0x40000010,
  4353. 0x5000000: 0x40084000,
  4354. 0x6000000: 0x40004000,
  4355. 0x7000000: 0x10,
  4356. 0x8000000: 0x84000,
  4357. 0x9000000: 0x40004010,
  4358. 0xa000000: 0x40000000,
  4359. 0xb000000: 0x84010,
  4360. 0xc000000: 0x80010,
  4361. 0xd000000: 0x0,
  4362. 0xe000000: 0x4010,
  4363. 0xf000000: 0x40080000,
  4364. 0x800000: 0x40004000,
  4365. 0x1800000: 0x84010,
  4366. 0x2800000: 0x10,
  4367. 0x3800000: 0x40004010,
  4368. 0x4800000: 0x40084010,
  4369. 0x5800000: 0x40000000,
  4370. 0x6800000: 0x80000,
  4371. 0x7800000: 0x40080010,
  4372. 0x8800000: 0x80010,
  4373. 0x9800000: 0x0,
  4374. 0xa800000: 0x4000,
  4375. 0xb800000: 0x40080000,
  4376. 0xc800000: 0x40000010,
  4377. 0xd800000: 0x84000,
  4378. 0xe800000: 0x40084000,
  4379. 0xf800000: 0x4010,
  4380. 0x10000000: 0x0,
  4381. 0x11000000: 0x40080010,
  4382. 0x12000000: 0x40004010,
  4383. 0x13000000: 0x40084000,
  4384. 0x14000000: 0x40080000,
  4385. 0x15000000: 0x10,
  4386. 0x16000000: 0x84010,
  4387. 0x17000000: 0x4000,
  4388. 0x18000000: 0x4010,
  4389. 0x19000000: 0x80000,
  4390. 0x1a000000: 0x80010,
  4391. 0x1b000000: 0x40000010,
  4392. 0x1c000000: 0x84000,
  4393. 0x1d000000: 0x40004000,
  4394. 0x1e000000: 0x40000000,
  4395. 0x1f000000: 0x40084010,
  4396. 0x10800000: 0x84010,
  4397. 0x11800000: 0x80000,
  4398. 0x12800000: 0x40080000,
  4399. 0x13800000: 0x4000,
  4400. 0x14800000: 0x40004000,
  4401. 0x15800000: 0x40084010,
  4402. 0x16800000: 0x10,
  4403. 0x17800000: 0x40000000,
  4404. 0x18800000: 0x40084000,
  4405. 0x19800000: 0x40000010,
  4406. 0x1a800000: 0x40004010,
  4407. 0x1b800000: 0x80010,
  4408. 0x1c800000: 0x0,
  4409. 0x1d800000: 0x4010,
  4410. 0x1e800000: 0x40080010,
  4411. 0x1f800000: 0x84000
  4412. }, {
  4413. 0x0: 0x104,
  4414. 0x100000: 0x0,
  4415. 0x200000: 0x4000100,
  4416. 0x300000: 0x10104,
  4417. 0x400000: 0x10004,
  4418. 0x500000: 0x4000004,
  4419. 0x600000: 0x4010104,
  4420. 0x700000: 0x4010000,
  4421. 0x800000: 0x4000000,
  4422. 0x900000: 0x4010100,
  4423. 0xa00000: 0x10100,
  4424. 0xb00000: 0x4010004,
  4425. 0xc00000: 0x4000104,
  4426. 0xd00000: 0x10000,
  4427. 0xe00000: 0x4,
  4428. 0xf00000: 0x100,
  4429. 0x80000: 0x4010100,
  4430. 0x180000: 0x4010004,
  4431. 0x280000: 0x0,
  4432. 0x380000: 0x4000100,
  4433. 0x480000: 0x4000004,
  4434. 0x580000: 0x10000,
  4435. 0x680000: 0x10004,
  4436. 0x780000: 0x104,
  4437. 0x880000: 0x4,
  4438. 0x980000: 0x100,
  4439. 0xa80000: 0x4010000,
  4440. 0xb80000: 0x10104,
  4441. 0xc80000: 0x10100,
  4442. 0xd80000: 0x4000104,
  4443. 0xe80000: 0x4010104,
  4444. 0xf80000: 0x4000000,
  4445. 0x1000000: 0x4010100,
  4446. 0x1100000: 0x10004,
  4447. 0x1200000: 0x10000,
  4448. 0x1300000: 0x4000100,
  4449. 0x1400000: 0x100,
  4450. 0x1500000: 0x4010104,
  4451. 0x1600000: 0x4000004,
  4452. 0x1700000: 0x0,
  4453. 0x1800000: 0x4000104,
  4454. 0x1900000: 0x4000000,
  4455. 0x1a00000: 0x4,
  4456. 0x1b00000: 0x10100,
  4457. 0x1c00000: 0x4010000,
  4458. 0x1d00000: 0x104,
  4459. 0x1e00000: 0x10104,
  4460. 0x1f00000: 0x4010004,
  4461. 0x1080000: 0x4000000,
  4462. 0x1180000: 0x104,
  4463. 0x1280000: 0x4010100,
  4464. 0x1380000: 0x0,
  4465. 0x1480000: 0x10004,
  4466. 0x1580000: 0x4000100,
  4467. 0x1680000: 0x100,
  4468. 0x1780000: 0x4010004,
  4469. 0x1880000: 0x10000,
  4470. 0x1980000: 0x4010104,
  4471. 0x1a80000: 0x10104,
  4472. 0x1b80000: 0x4000004,
  4473. 0x1c80000: 0x4000104,
  4474. 0x1d80000: 0x4010000,
  4475. 0x1e80000: 0x4,
  4476. 0x1f80000: 0x10100
  4477. }, {
  4478. 0x0: 0x80401000,
  4479. 0x10000: 0x80001040,
  4480. 0x20000: 0x401040,
  4481. 0x30000: 0x80400000,
  4482. 0x40000: 0x0,
  4483. 0x50000: 0x401000,
  4484. 0x60000: 0x80000040,
  4485. 0x70000: 0x400040,
  4486. 0x80000: 0x80000000,
  4487. 0x90000: 0x400000,
  4488. 0xa0000: 0x40,
  4489. 0xb0000: 0x80001000,
  4490. 0xc0000: 0x80400040,
  4491. 0xd0000: 0x1040,
  4492. 0xe0000: 0x1000,
  4493. 0xf0000: 0x80401040,
  4494. 0x8000: 0x80001040,
  4495. 0x18000: 0x40,
  4496. 0x28000: 0x80400040,
  4497. 0x38000: 0x80001000,
  4498. 0x48000: 0x401000,
  4499. 0x58000: 0x80401040,
  4500. 0x68000: 0x0,
  4501. 0x78000: 0x80400000,
  4502. 0x88000: 0x1000,
  4503. 0x98000: 0x80401000,
  4504. 0xa8000: 0x400000,
  4505. 0xb8000: 0x1040,
  4506. 0xc8000: 0x80000000,
  4507. 0xd8000: 0x400040,
  4508. 0xe8000: 0x401040,
  4509. 0xf8000: 0x80000040,
  4510. 0x100000: 0x400040,
  4511. 0x110000: 0x401000,
  4512. 0x120000: 0x80000040,
  4513. 0x130000: 0x0,
  4514. 0x140000: 0x1040,
  4515. 0x150000: 0x80400040,
  4516. 0x160000: 0x80401000,
  4517. 0x170000: 0x80001040,
  4518. 0x180000: 0x80401040,
  4519. 0x190000: 0x80000000,
  4520. 0x1a0000: 0x80400000,
  4521. 0x1b0000: 0x401040,
  4522. 0x1c0000: 0x80001000,
  4523. 0x1d0000: 0x400000,
  4524. 0x1e0000: 0x40,
  4525. 0x1f0000: 0x1000,
  4526. 0x108000: 0x80400000,
  4527. 0x118000: 0x80401040,
  4528. 0x128000: 0x0,
  4529. 0x138000: 0x401000,
  4530. 0x148000: 0x400040,
  4531. 0x158000: 0x80000000,
  4532. 0x168000: 0x80001040,
  4533. 0x178000: 0x40,
  4534. 0x188000: 0x80000040,
  4535. 0x198000: 0x1000,
  4536. 0x1a8000: 0x80001000,
  4537. 0x1b8000: 0x80400040,
  4538. 0x1c8000: 0x1040,
  4539. 0x1d8000: 0x80401000,
  4540. 0x1e8000: 0x400000,
  4541. 0x1f8000: 0x401040
  4542. }, {
  4543. 0x0: 0x80,
  4544. 0x1000: 0x1040000,
  4545. 0x2000: 0x40000,
  4546. 0x3000: 0x20000000,
  4547. 0x4000: 0x20040080,
  4548. 0x5000: 0x1000080,
  4549. 0x6000: 0x21000080,
  4550. 0x7000: 0x40080,
  4551. 0x8000: 0x1000000,
  4552. 0x9000: 0x20040000,
  4553. 0xa000: 0x20000080,
  4554. 0xb000: 0x21040080,
  4555. 0xc000: 0x21040000,
  4556. 0xd000: 0x0,
  4557. 0xe000: 0x1040080,
  4558. 0xf000: 0x21000000,
  4559. 0x800: 0x1040080,
  4560. 0x1800: 0x21000080,
  4561. 0x2800: 0x80,
  4562. 0x3800: 0x1040000,
  4563. 0x4800: 0x40000,
  4564. 0x5800: 0x20040080,
  4565. 0x6800: 0x21040000,
  4566. 0x7800: 0x20000000,
  4567. 0x8800: 0x20040000,
  4568. 0x9800: 0x0,
  4569. 0xa800: 0x21040080,
  4570. 0xb800: 0x1000080,
  4571. 0xc800: 0x20000080,
  4572. 0xd800: 0x21000000,
  4573. 0xe800: 0x1000000,
  4574. 0xf800: 0x40080,
  4575. 0x10000: 0x40000,
  4576. 0x11000: 0x80,
  4577. 0x12000: 0x20000000,
  4578. 0x13000: 0x21000080,
  4579. 0x14000: 0x1000080,
  4580. 0x15000: 0x21040000,
  4581. 0x16000: 0x20040080,
  4582. 0x17000: 0x1000000,
  4583. 0x18000: 0x21040080,
  4584. 0x19000: 0x21000000,
  4585. 0x1a000: 0x1040000,
  4586. 0x1b000: 0x20040000,
  4587. 0x1c000: 0x40080,
  4588. 0x1d000: 0x20000080,
  4589. 0x1e000: 0x0,
  4590. 0x1f000: 0x1040080,
  4591. 0x10800: 0x21000080,
  4592. 0x11800: 0x1000000,
  4593. 0x12800: 0x1040000,
  4594. 0x13800: 0x20040080,
  4595. 0x14800: 0x20000000,
  4596. 0x15800: 0x1040080,
  4597. 0x16800: 0x80,
  4598. 0x17800: 0x21040000,
  4599. 0x18800: 0x40080,
  4600. 0x19800: 0x21040080,
  4601. 0x1a800: 0x0,
  4602. 0x1b800: 0x21000000,
  4603. 0x1c800: 0x1000080,
  4604. 0x1d800: 0x40000,
  4605. 0x1e800: 0x20040000,
  4606. 0x1f800: 0x20000080
  4607. }, {
  4608. 0x0: 0x10000008,
  4609. 0x100: 0x2000,
  4610. 0x200: 0x10200000,
  4611. 0x300: 0x10202008,
  4612. 0x400: 0x10002000,
  4613. 0x500: 0x200000,
  4614. 0x600: 0x200008,
  4615. 0x700: 0x10000000,
  4616. 0x800: 0x0,
  4617. 0x900: 0x10002008,
  4618. 0xa00: 0x202000,
  4619. 0xb00: 0x8,
  4620. 0xc00: 0x10200008,
  4621. 0xd00: 0x202008,
  4622. 0xe00: 0x2008,
  4623. 0xf00: 0x10202000,
  4624. 0x80: 0x10200000,
  4625. 0x180: 0x10202008,
  4626. 0x280: 0x8,
  4627. 0x380: 0x200000,
  4628. 0x480: 0x202008,
  4629. 0x580: 0x10000008,
  4630. 0x680: 0x10002000,
  4631. 0x780: 0x2008,
  4632. 0x880: 0x200008,
  4633. 0x980: 0x2000,
  4634. 0xa80: 0x10002008,
  4635. 0xb80: 0x10200008,
  4636. 0xc80: 0x0,
  4637. 0xd80: 0x10202000,
  4638. 0xe80: 0x202000,
  4639. 0xf80: 0x10000000,
  4640. 0x1000: 0x10002000,
  4641. 0x1100: 0x10200008,
  4642. 0x1200: 0x10202008,
  4643. 0x1300: 0x2008,
  4644. 0x1400: 0x200000,
  4645. 0x1500: 0x10000000,
  4646. 0x1600: 0x10000008,
  4647. 0x1700: 0x202000,
  4648. 0x1800: 0x202008,
  4649. 0x1900: 0x0,
  4650. 0x1a00: 0x8,
  4651. 0x1b00: 0x10200000,
  4652. 0x1c00: 0x2000,
  4653. 0x1d00: 0x10002008,
  4654. 0x1e00: 0x10202000,
  4655. 0x1f00: 0x200008,
  4656. 0x1080: 0x8,
  4657. 0x1180: 0x202000,
  4658. 0x1280: 0x200000,
  4659. 0x1380: 0x10000008,
  4660. 0x1480: 0x10002000,
  4661. 0x1580: 0x2008,
  4662. 0x1680: 0x10202008,
  4663. 0x1780: 0x10200000,
  4664. 0x1880: 0x10202000,
  4665. 0x1980: 0x10200008,
  4666. 0x1a80: 0x2000,
  4667. 0x1b80: 0x202008,
  4668. 0x1c80: 0x200008,
  4669. 0x1d80: 0x0,
  4670. 0x1e80: 0x10000000,
  4671. 0x1f80: 0x10002008
  4672. }, {
  4673. 0x0: 0x100000,
  4674. 0x10: 0x2000401,
  4675. 0x20: 0x400,
  4676. 0x30: 0x100401,
  4677. 0x40: 0x2100401,
  4678. 0x50: 0x0,
  4679. 0x60: 0x1,
  4680. 0x70: 0x2100001,
  4681. 0x80: 0x2000400,
  4682. 0x90: 0x100001,
  4683. 0xa0: 0x2000001,
  4684. 0xb0: 0x2100400,
  4685. 0xc0: 0x2100000,
  4686. 0xd0: 0x401,
  4687. 0xe0: 0x100400,
  4688. 0xf0: 0x2000000,
  4689. 0x8: 0x2100001,
  4690. 0x18: 0x0,
  4691. 0x28: 0x2000401,
  4692. 0x38: 0x2100400,
  4693. 0x48: 0x100000,
  4694. 0x58: 0x2000001,
  4695. 0x68: 0x2000000,
  4696. 0x78: 0x401,
  4697. 0x88: 0x100401,
  4698. 0x98: 0x2000400,
  4699. 0xa8: 0x2100000,
  4700. 0xb8: 0x100001,
  4701. 0xc8: 0x400,
  4702. 0xd8: 0x2100401,
  4703. 0xe8: 0x1,
  4704. 0xf8: 0x100400,
  4705. 0x100: 0x2000000,
  4706. 0x110: 0x100000,
  4707. 0x120: 0x2000401,
  4708. 0x130: 0x2100001,
  4709. 0x140: 0x100001,
  4710. 0x150: 0x2000400,
  4711. 0x160: 0x2100400,
  4712. 0x170: 0x100401,
  4713. 0x180: 0x401,
  4714. 0x190: 0x2100401,
  4715. 0x1a0: 0x100400,
  4716. 0x1b0: 0x1,
  4717. 0x1c0: 0x0,
  4718. 0x1d0: 0x2100000,
  4719. 0x1e0: 0x2000001,
  4720. 0x1f0: 0x400,
  4721. 0x108: 0x100400,
  4722. 0x118: 0x2000401,
  4723. 0x128: 0x2100001,
  4724. 0x138: 0x1,
  4725. 0x148: 0x2000000,
  4726. 0x158: 0x100000,
  4727. 0x168: 0x401,
  4728. 0x178: 0x2100400,
  4729. 0x188: 0x2000001,
  4730. 0x198: 0x2100000,
  4731. 0x1a8: 0x0,
  4732. 0x1b8: 0x2100401,
  4733. 0x1c8: 0x100401,
  4734. 0x1d8: 0x400,
  4735. 0x1e8: 0x2000400,
  4736. 0x1f8: 0x100001
  4737. }, {
  4738. 0x0: 0x8000820,
  4739. 0x1: 0x20000,
  4740. 0x2: 0x8000000,
  4741. 0x3: 0x20,
  4742. 0x4: 0x20020,
  4743. 0x5: 0x8020820,
  4744. 0x6: 0x8020800,
  4745. 0x7: 0x800,
  4746. 0x8: 0x8020000,
  4747. 0x9: 0x8000800,
  4748. 0xa: 0x20800,
  4749. 0xb: 0x8020020,
  4750. 0xc: 0x820,
  4751. 0xd: 0x0,
  4752. 0xe: 0x8000020,
  4753. 0xf: 0x20820,
  4754. 0x80000000: 0x800,
  4755. 0x80000001: 0x8020820,
  4756. 0x80000002: 0x8000820,
  4757. 0x80000003: 0x8000000,
  4758. 0x80000004: 0x8020000,
  4759. 0x80000005: 0x20800,
  4760. 0x80000006: 0x20820,
  4761. 0x80000007: 0x20,
  4762. 0x80000008: 0x8000020,
  4763. 0x80000009: 0x820,
  4764. 0x8000000a: 0x20020,
  4765. 0x8000000b: 0x8020800,
  4766. 0x8000000c: 0x0,
  4767. 0x8000000d: 0x8020020,
  4768. 0x8000000e: 0x8000800,
  4769. 0x8000000f: 0x20000,
  4770. 0x10: 0x20820,
  4771. 0x11: 0x8020800,
  4772. 0x12: 0x20,
  4773. 0x13: 0x800,
  4774. 0x14: 0x8000800,
  4775. 0x15: 0x8000020,
  4776. 0x16: 0x8020020,
  4777. 0x17: 0x20000,
  4778. 0x18: 0x0,
  4779. 0x19: 0x20020,
  4780. 0x1a: 0x8020000,
  4781. 0x1b: 0x8000820,
  4782. 0x1c: 0x8020820,
  4783. 0x1d: 0x20800,
  4784. 0x1e: 0x820,
  4785. 0x1f: 0x8000000,
  4786. 0x80000010: 0x20000,
  4787. 0x80000011: 0x800,
  4788. 0x80000012: 0x8020020,
  4789. 0x80000013: 0x20820,
  4790. 0x80000014: 0x20,
  4791. 0x80000015: 0x8020000,
  4792. 0x80000016: 0x8000000,
  4793. 0x80000017: 0x8000820,
  4794. 0x80000018: 0x8020820,
  4795. 0x80000019: 0x8000020,
  4796. 0x8000001a: 0x8000800,
  4797. 0x8000001b: 0x0,
  4798. 0x8000001c: 0x20800,
  4799. 0x8000001d: 0x820,
  4800. 0x8000001e: 0x20020,
  4801. 0x8000001f: 0x8020800
  4802. }];
  4803. // Masks that select the SBOX input
  4804. var SBOX_MASK = [
  4805. 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000,
  4806. 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f];
  4807. /**
  4808. * DES block cipher algorithm.
  4809. */
  4810. var DES = C_algo.DES = BlockCipher.extend({
  4811. _doReset: function() {
  4812. // Shortcuts
  4813. var key = this._key;
  4814. var keyWords = key.words;
  4815. // Select 56 bits according to PC1
  4816. var keyBits = [];
  4817. for (var i = 0; i < 56; i++) {
  4818. var keyBitPos = PC1[i] - 1;
  4819. keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1;
  4820. }
  4821. // Assemble 16 subkeys
  4822. var subKeys = this._subKeys = [];
  4823. for (var nSubKey = 0; nSubKey < 16; nSubKey++) {
  4824. // Create subkey
  4825. var subKey = subKeys[nSubKey] = [];
  4826. // Shortcut
  4827. var bitShift = BIT_SHIFTS[nSubKey];
  4828. // Select 48 bits according to PC2
  4829. for (var i = 0; i < 24; i++) {
  4830. // Select from the left 28 key bits
  4831. subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6);
  4832. // Select from the right 28 key bits
  4833. subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6);
  4834. }
  4835. // Since each subkey is applied to an expanded 32-bit input,
  4836. // the subkey can be broken into 8 values scaled to 32-bits,
  4837. // which allows the key to be used without expansion
  4838. subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31);
  4839. for (var i = 1; i < 7; i++) {
  4840. subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3);
  4841. }
  4842. subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27);
  4843. }
  4844. // Compute inverse subkeys
  4845. var invSubKeys = this._invSubKeys = [];
  4846. for (var i = 0; i < 16; i++) {
  4847. invSubKeys[i] = subKeys[15 - i];
  4848. }
  4849. },
  4850. encryptBlock: function(M, offset) {
  4851. this._doCryptBlock(M, offset, this._subKeys);
  4852. },
  4853. decryptBlock: function(M, offset) {
  4854. this._doCryptBlock(M, offset, this._invSubKeys);
  4855. },
  4856. _doCryptBlock: function(M, offset, subKeys) {
  4857. // Get input
  4858. this._lBlock = M[offset];
  4859. this._rBlock = M[offset + 1];
  4860. // Initial permutation
  4861. exchangeLR.call(this, 4, 0x0f0f0f0f);
  4862. exchangeLR.call(this, 16, 0x0000ffff);
  4863. exchangeRL.call(this, 2, 0x33333333);
  4864. exchangeRL.call(this, 8, 0x00ff00ff);
  4865. exchangeLR.call(this, 1, 0x55555555);
  4866. // Rounds
  4867. for (var round = 0; round < 16; round++) {
  4868. // Shortcuts
  4869. var subKey = subKeys[round];
  4870. var lBlock = this._lBlock;
  4871. var rBlock = this._rBlock;
  4872. // Feistel function
  4873. var f = 0;
  4874. for (var i = 0; i < 8; i++) {
  4875. f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0];
  4876. }
  4877. this._lBlock = rBlock;
  4878. this._rBlock = lBlock ^ f;
  4879. }
  4880. // Undo swap from last round
  4881. var t = this._lBlock;
  4882. this._lBlock = this._rBlock;
  4883. this._rBlock = t;
  4884. // Final permutation
  4885. exchangeLR.call(this, 1, 0x55555555);
  4886. exchangeRL.call(this, 8, 0x00ff00ff);
  4887. exchangeRL.call(this, 2, 0x33333333);
  4888. exchangeLR.call(this, 16, 0x0000ffff);
  4889. exchangeLR.call(this, 4, 0x0f0f0f0f);
  4890. // Set output
  4891. M[offset] = this._lBlock;
  4892. M[offset + 1] = this._rBlock;
  4893. },
  4894. keySize: 64 / 32,
  4895. ivSize: 64 / 32,
  4896. blockSize: 64 / 32
  4897. });
  4898. // Swap bits across the left and right words
  4899. function exchangeLR(offset, mask) {
  4900. var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask;
  4901. this._rBlock ^= t;
  4902. this._lBlock ^= t << offset;
  4903. }
  4904. function exchangeRL(offset, mask) {
  4905. var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask;
  4906. this._lBlock ^= t;
  4907. this._rBlock ^= t << offset;
  4908. }
  4909. /**
  4910. * Shortcut functions to the cipher's object interface.
  4911. *
  4912. * @example
  4913. *
  4914. * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
  4915. * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg);
  4916. */
  4917. C.DES = BlockCipher._createHelper(DES);
  4918. /**
  4919. * Triple-DES block cipher algorithm.
  4920. */
  4921. var TripleDES = C_algo.TripleDES = BlockCipher.extend({
  4922. _doReset: function() {
  4923. // Shortcuts
  4924. var key = this._key;
  4925. var keyWords = key.words;
  4926. // Make sure the key length is valid (64, 128 or >= 192 bit)
  4927. if (keyWords.length !== 2 && keyWords.length !== 4 && keyWords.length < 6) {
  4928. throw new Error('Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192.');
  4929. }
  4930. // Extend the key according to the keying options defined in 3DES standard
  4931. var key1 = keyWords.slice(0, 2);
  4932. var key2 = keyWords.length < 4 ? keyWords.slice(0, 2) : keyWords.slice(2, 4);
  4933. var key3 = keyWords.length < 6 ? keyWords.slice(0, 2) : keyWords.slice(4, 6);
  4934. // Create DES instances
  4935. this._des1 = DES.createEncryptor(WordArray.create(key1));
  4936. this._des2 = DES.createEncryptor(WordArray.create(key2));
  4937. this._des3 = DES.createEncryptor(WordArray.create(key3));
  4938. },
  4939. encryptBlock: function(M, offset) {
  4940. this._des1.encryptBlock(M, offset);
  4941. this._des2.decryptBlock(M, offset);
  4942. this._des3.encryptBlock(M, offset);
  4943. },
  4944. decryptBlock: function(M, offset) {
  4945. this._des3.decryptBlock(M, offset);
  4946. this._des2.encryptBlock(M, offset);
  4947. this._des1.decryptBlock(M, offset);
  4948. },
  4949. keySize: 192 / 32,
  4950. ivSize: 64 / 32,
  4951. blockSize: 64 / 32
  4952. });
  4953. /**
  4954. * Shortcut functions to the cipher's object interface.
  4955. *
  4956. * @example
  4957. *
  4958. * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
  4959. * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);
  4960. */
  4961. C.TripleDES = BlockCipher._createHelper(TripleDES);
  4962. }());
  4963. (function() {
  4964. // Shortcuts
  4965. var C = CryptoJS;
  4966. var C_lib = C.lib;
  4967. var StreamCipher = C_lib.StreamCipher;
  4968. var C_algo = C.algo;
  4969. /**
  4970. * RC4 stream cipher algorithm.
  4971. */
  4972. var RC4 = C_algo.RC4 = StreamCipher.extend({
  4973. _doReset: function() {
  4974. // Shortcuts
  4975. var key = this._key;
  4976. var keyWords = key.words;
  4977. var keySigBytes = key.sigBytes;
  4978. // Init sbox
  4979. var S = this._S = [];
  4980. for (var i = 0; i < 256; i++) {
  4981. S[i] = i;
  4982. }
  4983. // Key setup
  4984. for (var i = 0, j = 0; i < 256; i++) {
  4985. var keyByteIndex = i % keySigBytes;
  4986. var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff;
  4987. j = (j + S[i] + keyByte) % 256;
  4988. // Swap
  4989. var t = S[i];
  4990. S[i] = S[j];
  4991. S[j] = t;
  4992. }
  4993. // Counters
  4994. this._i = this._j = 0;
  4995. },
  4996. _doProcessBlock: function(M, offset) {
  4997. M[offset] ^= generateKeystreamWord.call(this);
  4998. },
  4999. keySize: 256 / 32,
  5000. ivSize: 0
  5001. });
  5002. function generateKeystreamWord() {
  5003. // Shortcuts
  5004. var S = this._S;
  5005. var i = this._i;
  5006. var j = this._j;
  5007. // Generate keystream word
  5008. var keystreamWord = 0;
  5009. for (var n = 0; n < 4; n++) {
  5010. i = (i + 1) % 256;
  5011. j = (j + S[i]) % 256;
  5012. // Swap
  5013. var t = S[i];
  5014. S[i] = S[j];
  5015. S[j] = t;
  5016. keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8);
  5017. }
  5018. // Update counters
  5019. this._i = i;
  5020. this._j = j;
  5021. return keystreamWord;
  5022. }
  5023. /**
  5024. * Shortcut functions to the cipher's object interface.
  5025. *
  5026. * @example
  5027. *
  5028. * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
  5029. * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg);
  5030. */
  5031. C.RC4 = StreamCipher._createHelper(RC4);
  5032. /**
  5033. * Modified RC4 stream cipher algorithm.
  5034. */
  5035. var RC4Drop = C_algo.RC4Drop = RC4.extend({
  5036. /**
  5037. * Configuration options.
  5038. *
  5039. * @property {number} drop The number of keystream words to drop. Default 192
  5040. */
  5041. cfg: RC4.cfg.extend({
  5042. drop: 192
  5043. }),
  5044. _doReset: function() {
  5045. RC4._doReset.call(this);
  5046. // Drop
  5047. for (var i = this.cfg.drop; i > 0; i--) {
  5048. generateKeystreamWord.call(this);
  5049. }
  5050. }
  5051. });
  5052. /**
  5053. * Shortcut functions to the cipher's object interface.
  5054. *
  5055. * @example
  5056. *
  5057. * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg);
  5058. * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg);
  5059. */
  5060. C.RC4Drop = StreamCipher._createHelper(RC4Drop);
  5061. }());
  5062. (function() {
  5063. // Shortcuts
  5064. var C = CryptoJS;
  5065. var C_lib = C.lib;
  5066. var StreamCipher = C_lib.StreamCipher;
  5067. var C_algo = C.algo;
  5068. // Reusable objects
  5069. var S = [];
  5070. var C_ = [];
  5071. var G = [];
  5072. /**
  5073. * Rabbit stream cipher algorithm
  5074. */
  5075. var Rabbit = C_algo.Rabbit = StreamCipher.extend({
  5076. _doReset: function() {
  5077. // Shortcuts
  5078. var K = this._key.words;
  5079. var iv = this.cfg.iv;
  5080. // Swap endian
  5081. for (var i = 0; i < 4; i++) {
  5082. K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00);
  5083. }
  5084. // Generate initial state values
  5085. var X = this._X = [
  5086. K[0], (K[3] << 16) | (K[2] >>> 16),
  5087. K[1], (K[0] << 16) | (K[3] >>> 16),
  5088. K[2], (K[1] << 16) | (K[0] >>> 16),
  5089. K[3], (K[2] << 16) | (K[1] >>> 16)];
  5090. // Generate initial counter values
  5091. var C = this._C = [
  5092. (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)];
  5093. // Carry bit
  5094. this._b = 0;
  5095. // Iterate the system four times
  5096. for (var i = 0; i < 4; i++) {
  5097. nextState.call(this);
  5098. }
  5099. // Modify the counters
  5100. for (var i = 0; i < 8; i++) {
  5101. C[i] ^= X[(i + 4) & 7];
  5102. }
  5103. // IV setup
  5104. if (iv) {
  5105. // Shortcuts
  5106. var IV = iv.words;
  5107. var IV_0 = IV[0];
  5108. var IV_1 = IV[1];
  5109. // Generate four subvectors
  5110. var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  5111. var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  5112. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  5113. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  5114. // Modify counter values
  5115. C[0] ^= i0;
  5116. C[1] ^= i1;
  5117. C[2] ^= i2;
  5118. C[3] ^= i3;
  5119. C[4] ^= i0;
  5120. C[5] ^= i1;
  5121. C[6] ^= i2;
  5122. C[7] ^= i3;
  5123. // Iterate the system four times
  5124. for (var i = 0; i < 4; i++) {
  5125. nextState.call(this);
  5126. }
  5127. }
  5128. },
  5129. _doProcessBlock: function(M, offset) {
  5130. // Shortcut
  5131. var X = this._X;
  5132. // Iterate the system
  5133. nextState.call(this);
  5134. // Generate four keystream words
  5135. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  5136. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  5137. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  5138. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  5139. for (var i = 0; i < 4; i++) {
  5140. // Swap endian
  5141. S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  5142. // Encrypt
  5143. M[offset + i] ^= S[i];
  5144. }
  5145. },
  5146. blockSize: 128 / 32,
  5147. ivSize: 64 / 32
  5148. });
  5149. function nextState() {
  5150. // Shortcuts
  5151. var X = this._X;
  5152. var C = this._C;
  5153. // Save old counter values
  5154. for (var i = 0; i < 8; i++) {
  5155. C_[i] = C[i];
  5156. }
  5157. // Calculate new counter values
  5158. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  5159. C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  5160. C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  5161. C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  5162. C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  5163. C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  5164. C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  5165. C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  5166. this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  5167. // Calculate the g-values
  5168. for (var i = 0; i < 8; i++) {
  5169. var gx = X[i] + C[i];
  5170. // Construct high and low argument for squaring
  5171. var ga = gx & 0xffff;
  5172. var gb = gx >>> 16;
  5173. // Calculate high and low result of squaring
  5174. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  5175. var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  5176. // High XOR low
  5177. G[i] = gh ^ gl;
  5178. }
  5179. // Calculate new state values
  5180. X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  5181. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  5182. X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  5183. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  5184. X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  5185. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  5186. X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  5187. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  5188. }
  5189. /**
  5190. * Shortcut functions to the cipher's object interface.
  5191. *
  5192. * @example
  5193. *
  5194. * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg);
  5195. * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg);
  5196. */
  5197. C.Rabbit = StreamCipher._createHelper(Rabbit);
  5198. }());
  5199. (function() {
  5200. // Shortcuts
  5201. var C = CryptoJS;
  5202. var C_lib = C.lib;
  5203. var StreamCipher = C_lib.StreamCipher;
  5204. var C_algo = C.algo;
  5205. // Reusable objects
  5206. var S = [];
  5207. var C_ = [];
  5208. var G = [];
  5209. /**
  5210. * Rabbit stream cipher algorithm.
  5211. *
  5212. * This is a legacy version that neglected to convert the key to little-endian.
  5213. * This error doesn't affect the cipher's security,
  5214. * but it does affect its compatibility with other implementations.
  5215. */
  5216. var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({
  5217. _doReset: function() {
  5218. // Shortcuts
  5219. var K = this._key.words;
  5220. var iv = this.cfg.iv;
  5221. // Generate initial state values
  5222. var X = this._X = [
  5223. K[0], (K[3] << 16) | (K[2] >>> 16),
  5224. K[1], (K[0] << 16) | (K[3] >>> 16),
  5225. K[2], (K[1] << 16) | (K[0] >>> 16),
  5226. K[3], (K[2] << 16) | (K[1] >>> 16)];
  5227. // Generate initial counter values
  5228. var C = this._C = [
  5229. (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)];
  5230. // Carry bit
  5231. this._b = 0;
  5232. // Iterate the system four times
  5233. for (var i = 0; i < 4; i++) {
  5234. nextState.call(this);
  5235. }
  5236. // Modify the counters
  5237. for (var i = 0; i < 8; i++) {
  5238. C[i] ^= X[(i + 4) & 7];
  5239. }
  5240. // IV setup
  5241. if (iv) {
  5242. // Shortcuts
  5243. var IV = iv.words;
  5244. var IV_0 = IV[0];
  5245. var IV_1 = IV[1];
  5246. // Generate four subvectors
  5247. var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  5248. var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  5249. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  5250. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  5251. // Modify counter values
  5252. C[0] ^= i0;
  5253. C[1] ^= i1;
  5254. C[2] ^= i2;
  5255. C[3] ^= i3;
  5256. C[4] ^= i0;
  5257. C[5] ^= i1;
  5258. C[6] ^= i2;
  5259. C[7] ^= i3;
  5260. // Iterate the system four times
  5261. for (var i = 0; i < 4; i++) {
  5262. nextState.call(this);
  5263. }
  5264. }
  5265. },
  5266. _doProcessBlock: function(M, offset) {
  5267. // Shortcut
  5268. var X = this._X;
  5269. // Iterate the system
  5270. nextState.call(this);
  5271. // Generate four keystream words
  5272. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  5273. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  5274. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  5275. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  5276. for (var i = 0; i < 4; i++) {
  5277. // Swap endian
  5278. S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  5279. // Encrypt
  5280. M[offset + i] ^= S[i];
  5281. }
  5282. },
  5283. blockSize: 128 / 32,
  5284. ivSize: 64 / 32
  5285. });
  5286. function nextState() {
  5287. // Shortcuts
  5288. var X = this._X;
  5289. var C = this._C;
  5290. // Save old counter values
  5291. for (var i = 0; i < 8; i++) {
  5292. C_[i] = C[i];
  5293. }
  5294. // Calculate new counter values
  5295. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  5296. C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  5297. C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  5298. C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  5299. C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  5300. C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  5301. C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  5302. C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  5303. this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  5304. // Calculate the g-values
  5305. for (var i = 0; i < 8; i++) {
  5306. var gx = X[i] + C[i];
  5307. // Construct high and low argument for squaring
  5308. var ga = gx & 0xffff;
  5309. var gb = gx >>> 16;
  5310. // Calculate high and low result of squaring
  5311. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  5312. var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  5313. // High XOR low
  5314. G[i] = gh ^ gl;
  5315. }
  5316. // Calculate new state values
  5317. X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  5318. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  5319. X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  5320. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  5321. X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  5322. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  5323. X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  5324. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  5325. }
  5326. /**
  5327. * Shortcut functions to the cipher's object interface.
  5328. *
  5329. * @example
  5330. *
  5331. * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg);
  5332. * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg);
  5333. */
  5334. C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy);
  5335. }());
  5336. return CryptoJS;
  5337. }));