crypto-js.js 209 KB

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