crypto-js.js 215 KB

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