crypto-js.js 214 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657
  1. ;(function (root, factory) {
  2. if (typeof exports === "object") {
  3. // CommonJS
  4. module.exports = exports = factory();
  5. }
  6. else if (typeof define === "function" && define.amd) {
  7. // AMD
  8. define([], factory);
  9. }
  10. else {
  11. // Global (browser)
  12. root.CryptoJS = factory();
  13. }
  14. }(this, function () {
  15. /*globals window, global, require*/
  16. /**
  17. * CryptoJS core components.
  18. */
  19. var CryptoJS = CryptoJS || (function (Math, undefined) {
  20. var crypto;
  21. // Native crypto from window (Browser)
  22. if (typeof window !== 'undefined' && window.crypto) {
  23. crypto = window.crypto;
  24. }
  25. // Native crypto in web worker (Browser)
  26. if (typeof self !== 'undefined' && self.crypto) {
  27. crypto = self.crypto;
  28. }
  29. // Native crypto from worker
  30. if (typeof globalThis !== 'undefined' && globalThis.crypto) {
  31. crypto = globalThis.crypto;
  32. }
  33. // Native (experimental IE 11) crypto from window (Browser)
  34. if (!crypto && typeof window !== 'undefined' && window.msCrypto) {
  35. crypto = window.msCrypto;
  36. }
  37. // Native crypto from global (NodeJS)
  38. if (!crypto && typeof global !== 'undefined' && global.crypto) {
  39. crypto = global.crypto;
  40. }
  41. // Native crypto import via require (NodeJS)
  42. if (!crypto && typeof require === 'function') {
  43. try {
  44. crypto = require('crypto');
  45. } catch (err) {}
  46. }
  47. /*
  48. * Cryptographically secure pseudorandom number generator
  49. *
  50. * As Math.random() is cryptographically not safe to use
  51. */
  52. var cryptoSecureRandomInt = function () {
  53. if (crypto) {
  54. // Use getRandomValues method (Browser)
  55. if (typeof crypto.getRandomValues === 'function') {
  56. try {
  57. return crypto.getRandomValues(new Uint32Array(1))[0];
  58. } catch (err) {}
  59. }
  60. // Use randomBytes method (NodeJS)
  61. if (typeof crypto.randomBytes === 'function') {
  62. try {
  63. return crypto.randomBytes(4).readInt32LE();
  64. } catch (err) {}
  65. }
  66. }
  67. throw new Error('Native crypto module could not be used to get secure random number.');
  68. };
  69. /*
  70. * Local polyfill of Object.create
  71. */
  72. var create = Object.create || (function () {
  73. function F() {}
  74. return function (obj) {
  75. var subtype;
  76. F.prototype = obj;
  77. subtype = new F();
  78. F.prototype = null;
  79. return subtype;
  80. };
  81. }());
  82. /**
  83. * CryptoJS namespace.
  84. */
  85. var C = {};
  86. /**
  87. * Library namespace.
  88. */
  89. var C_lib = C.lib = {};
  90. /**
  91. * Base object for prototypal inheritance.
  92. */
  93. var Base = C_lib.Base = (function () {
  94. return {
  95. /**
  96. * Creates a new object that inherits from this object.
  97. *
  98. * @param {Object} overrides Properties to copy into the new object.
  99. *
  100. * @return {Object} The new object.
  101. *
  102. * @static
  103. *
  104. * @example
  105. *
  106. * var MyType = CryptoJS.lib.Base.extend({
  107. * field: 'value',
  108. *
  109. * method: function () {
  110. * }
  111. * });
  112. */
  113. extend: function (overrides) {
  114. // Spawn
  115. var subtype = create(this);
  116. // Augment
  117. if (overrides) {
  118. subtype.mixIn(overrides);
  119. }
  120. // Create default initializer
  121. if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
  122. subtype.init = function () {
  123. subtype.$super.init.apply(this, arguments);
  124. };
  125. }
  126. // Initializer's prototype is the subtype object
  127. subtype.init.prototype = subtype;
  128. // Reference supertype
  129. subtype.$super = this;
  130. return subtype;
  131. },
  132. /**
  133. * Extends this object and runs the init method.
  134. * Arguments to create() will be passed to init().
  135. *
  136. * @return {Object} The new object.
  137. *
  138. * @static
  139. *
  140. * @example
  141. *
  142. * var instance = MyType.create();
  143. */
  144. create: function () {
  145. var instance = this.extend();
  146. instance.init.apply(instance, arguments);
  147. return instance;
  148. },
  149. /**
  150. * Initializes a newly created object.
  151. * Override this method to add some logic when your objects are created.
  152. *
  153. * @example
  154. *
  155. * var MyType = CryptoJS.lib.Base.extend({
  156. * init: function () {
  157. * // ...
  158. * }
  159. * });
  160. */
  161. init: function () {
  162. },
  163. /**
  164. * Copies properties into this object.
  165. *
  166. * @param {Object} properties The properties to mix in.
  167. *
  168. * @example
  169. *
  170. * MyType.mixIn({
  171. * field: 'value'
  172. * });
  173. */
  174. mixIn: function (properties) {
  175. for (var propertyName in properties) {
  176. if (properties.hasOwnProperty(propertyName)) {
  177. this[propertyName] = properties[propertyName];
  178. }
  179. }
  180. // IE won't copy toString using the loop above
  181. if (properties.hasOwnProperty('toString')) {
  182. this.toString = properties.toString;
  183. }
  184. },
  185. /**
  186. * Creates a copy of this object.
  187. *
  188. * @return {Object} The clone.
  189. *
  190. * @example
  191. *
  192. * var clone = instance.clone();
  193. */
  194. clone: function () {
  195. return this.init.prototype.extend(this);
  196. }
  197. };
  198. }());
  199. /**
  200. * An array of 32-bit words.
  201. *
  202. * @property {Array} words The array of 32-bit words.
  203. * @property {number} sigBytes The number of significant bytes in this word array.
  204. */
  205. var WordArray = C_lib.WordArray = Base.extend({
  206. /**
  207. * Initializes a newly created word array.
  208. *
  209. * @param {Array} words (Optional) An array of 32-bit words.
  210. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  211. *
  212. * @example
  213. *
  214. * var wordArray = CryptoJS.lib.WordArray.create();
  215. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
  216. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
  217. */
  218. init: function (words, sigBytes) {
  219. words = this.words = words || [];
  220. if (sigBytes != undefined) {
  221. this.sigBytes = sigBytes;
  222. } else {
  223. this.sigBytes = words.length * 4;
  224. }
  225. },
  226. /**
  227. * Converts this word array to a string.
  228. *
  229. * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
  230. *
  231. * @return {string} The stringified word array.
  232. *
  233. * @example
  234. *
  235. * var string = wordArray + '';
  236. * var string = wordArray.toString();
  237. * var string = wordArray.toString(CryptoJS.enc.Utf8);
  238. */
  239. toString: function (encoder) {
  240. return (encoder || Hex).stringify(this);
  241. },
  242. /**
  243. * Concatenates a word array to this word array.
  244. *
  245. * @param {WordArray} wordArray The word array to append.
  246. *
  247. * @return {WordArray} This word array.
  248. *
  249. * @example
  250. *
  251. * wordArray1.concat(wordArray2);
  252. */
  253. concat: function (wordArray) {
  254. // Shortcuts
  255. var thisWords = this.words;
  256. var thatWords = wordArray.words;
  257. var thisSigBytes = this.sigBytes;
  258. var thatSigBytes = wordArray.sigBytes;
  259. // Clamp excess bits
  260. this.clamp();
  261. // Concat
  262. if (thisSigBytes % 4) {
  263. // Copy one byte at a time
  264. for (var i = 0; i < thatSigBytes; i++) {
  265. var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  266. thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
  267. }
  268. } else {
  269. // Copy one word at a time
  270. for (var j = 0; j < thatSigBytes; j += 4) {
  271. thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2];
  272. }
  273. }
  274. this.sigBytes += thatSigBytes;
  275. // Chainable
  276. return this;
  277. },
  278. /**
  279. * Removes insignificant bits.
  280. *
  281. * @example
  282. *
  283. * wordArray.clamp();
  284. */
  285. clamp: function () {
  286. // Shortcuts
  287. var words = this.words;
  288. var sigBytes = this.sigBytes;
  289. // Clamp
  290. words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
  291. words.length = Math.ceil(sigBytes / 4);
  292. },
  293. /**
  294. * Creates a copy of this word array.
  295. *
  296. * @return {WordArray} The clone.
  297. *
  298. * @example
  299. *
  300. * var clone = wordArray.clone();
  301. */
  302. clone: function () {
  303. var clone = Base.clone.call(this);
  304. clone.words = this.words.slice(0);
  305. return clone;
  306. },
  307. /**
  308. * Creates a word array filled with random bytes.
  309. *
  310. * @param {number} nBytes The number of random bytes to generate.
  311. *
  312. * @return {WordArray} The random word array.
  313. *
  314. * @static
  315. *
  316. * @example
  317. *
  318. * var wordArray = CryptoJS.lib.WordArray.random(16);
  319. */
  320. random: function (nBytes) {
  321. var words = [];
  322. for (var i = 0; i < nBytes; i += 4) {
  323. words.push(cryptoSecureRandomInt());
  324. }
  325. return new WordArray.init(words, nBytes);
  326. }
  327. });
  328. /**
  329. * Encoder namespace.
  330. */
  331. var C_enc = C.enc = {};
  332. /**
  333. * Hex encoding strategy.
  334. */
  335. var Hex = C_enc.Hex = {
  336. /**
  337. * Converts a word array to a hex string.
  338. *
  339. * @param {WordArray} wordArray The word array.
  340. *
  341. * @return {string} The hex string.
  342. *
  343. * @static
  344. *
  345. * @example
  346. *
  347. * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
  348. */
  349. stringify: function (wordArray) {
  350. // Shortcuts
  351. var words = wordArray.words;
  352. var sigBytes = wordArray.sigBytes;
  353. // Convert
  354. var hexChars = [];
  355. for (var i = 0; i < sigBytes; i++) {
  356. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  357. hexChars.push((bite >>> 4).toString(16));
  358. hexChars.push((bite & 0x0f).toString(16));
  359. }
  360. return hexChars.join('');
  361. },
  362. /**
  363. * Converts a hex string to a word array.
  364. *
  365. * @param {string} hexStr The hex string.
  366. *
  367. * @return {WordArray} The word array.
  368. *
  369. * @static
  370. *
  371. * @example
  372. *
  373. * var wordArray = CryptoJS.enc.Hex.parse(hexString);
  374. */
  375. parse: function (hexStr) {
  376. // Shortcut
  377. var hexStrLength = hexStr.length;
  378. // Convert
  379. var words = [];
  380. for (var i = 0; i < hexStrLength; i += 2) {
  381. words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
  382. }
  383. return new WordArray.init(words, hexStrLength / 2);
  384. }
  385. };
  386. /**
  387. * Latin1 encoding strategy.
  388. */
  389. var Latin1 = C_enc.Latin1 = {
  390. /**
  391. * Converts a word array to a Latin1 string.
  392. *
  393. * @param {WordArray} wordArray The word array.
  394. *
  395. * @return {string} The Latin1 string.
  396. *
  397. * @static
  398. *
  399. * @example
  400. *
  401. * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
  402. */
  403. stringify: function (wordArray) {
  404. // Shortcuts
  405. var words = wordArray.words;
  406. var sigBytes = wordArray.sigBytes;
  407. // Convert
  408. var latin1Chars = [];
  409. for (var i = 0; i < sigBytes; i++) {
  410. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  411. latin1Chars.push(String.fromCharCode(bite));
  412. }
  413. return latin1Chars.join('');
  414. },
  415. /**
  416. * Converts a Latin1 string to a word array.
  417. *
  418. * @param {string} latin1Str The Latin1 string.
  419. *
  420. * @return {WordArray} The word array.
  421. *
  422. * @static
  423. *
  424. * @example
  425. *
  426. * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
  427. */
  428. parse: function (latin1Str) {
  429. // Shortcut
  430. var latin1StrLength = latin1Str.length;
  431. // Convert
  432. var words = [];
  433. for (var i = 0; i < latin1StrLength; i++) {
  434. words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
  435. }
  436. return new WordArray.init(words, latin1StrLength);
  437. }
  438. };
  439. /**
  440. * UTF-8 encoding strategy.
  441. */
  442. var Utf8 = C_enc.Utf8 = {
  443. /**
  444. * Converts a word array to a UTF-8 string.
  445. *
  446. * @param {WordArray} wordArray The word array.
  447. *
  448. * @return {string} The UTF-8 string.
  449. *
  450. * @static
  451. *
  452. * @example
  453. *
  454. * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
  455. */
  456. stringify: function (wordArray) {
  457. try {
  458. return decodeURIComponent(escape(Latin1.stringify(wordArray)));
  459. } catch (e) {
  460. throw new Error('Malformed UTF-8 data');
  461. }
  462. },
  463. /**
  464. * Converts a UTF-8 string to a word array.
  465. *
  466. * @param {string} utf8Str The UTF-8 string.
  467. *
  468. * @return {WordArray} The word array.
  469. *
  470. * @static
  471. *
  472. * @example
  473. *
  474. * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
  475. */
  476. parse: function (utf8Str) {
  477. return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
  478. }
  479. };
  480. /**
  481. * Abstract buffered block algorithm template.
  482. *
  483. * The property blockSize must be implemented in a concrete subtype.
  484. *
  485. * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
  486. */
  487. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
  488. /**
  489. * Resets this block algorithm's data buffer to its initial state.
  490. *
  491. * @example
  492. *
  493. * bufferedBlockAlgorithm.reset();
  494. */
  495. reset: function () {
  496. // Initial values
  497. this._data = new WordArray.init();
  498. this._nDataBytes = 0;
  499. },
  500. /**
  501. * Adds new data to this block algorithm's buffer.
  502. *
  503. * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
  504. *
  505. * @example
  506. *
  507. * bufferedBlockAlgorithm._append('data');
  508. * bufferedBlockAlgorithm._append(wordArray);
  509. */
  510. _append: function (data) {
  511. // Convert string to WordArray, else assume WordArray already
  512. if (typeof data == 'string') {
  513. data = Utf8.parse(data);
  514. }
  515. // Append
  516. this._data.concat(data);
  517. this._nDataBytes += data.sigBytes;
  518. },
  519. /**
  520. * Processes available data blocks.
  521. *
  522. * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
  523. *
  524. * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
  525. *
  526. * @return {WordArray} The processed data.
  527. *
  528. * @example
  529. *
  530. * var processedData = bufferedBlockAlgorithm._process();
  531. * var processedData = bufferedBlockAlgorithm._process(!!'flush');
  532. */
  533. _process: function (doFlush) {
  534. var processedWords;
  535. // Shortcuts
  536. var data = this._data;
  537. var dataWords = data.words;
  538. var dataSigBytes = data.sigBytes;
  539. var blockSize = this.blockSize;
  540. var blockSizeBytes = blockSize * 4;
  541. // Count blocks ready
  542. var nBlocksReady = dataSigBytes / blockSizeBytes;
  543. if (doFlush) {
  544. // Round up to include partial blocks
  545. nBlocksReady = Math.ceil(nBlocksReady);
  546. } else {
  547. // Round down to include only full blocks,
  548. // less the number of blocks that must remain in the buffer
  549. nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
  550. }
  551. // Count words ready
  552. var nWordsReady = nBlocksReady * blockSize;
  553. // Count bytes ready
  554. var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
  555. // Process blocks
  556. if (nWordsReady) {
  557. for (var offset = 0; offset < nWordsReady; offset += blockSize) {
  558. // Perform concrete-algorithm logic
  559. this._doProcessBlock(dataWords, offset);
  560. }
  561. // Remove processed words
  562. processedWords = dataWords.splice(0, nWordsReady);
  563. data.sigBytes -= nBytesReady;
  564. }
  565. // Return processed words
  566. return new WordArray.init(processedWords, nBytesReady);
  567. },
  568. /**
  569. * Creates a copy of this object.
  570. *
  571. * @return {Object} The clone.
  572. *
  573. * @example
  574. *
  575. * var clone = bufferedBlockAlgorithm.clone();
  576. */
  577. clone: function () {
  578. var clone = Base.clone.call(this);
  579. clone._data = this._data.clone();
  580. return clone;
  581. },
  582. _minBufferSize: 0
  583. });
  584. /**
  585. * Abstract hasher template.
  586. *
  587. * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
  588. */
  589. var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
  590. /**
  591. * Configuration options.
  592. */
  593. cfg: Base.extend(),
  594. /**
  595. * Initializes a newly created hasher.
  596. *
  597. * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
  598. *
  599. * @example
  600. *
  601. * var hasher = CryptoJS.algo.SHA256.create();
  602. */
  603. init: function (cfg) {
  604. // Apply config defaults
  605. this.cfg = this.cfg.extend(cfg);
  606. // Set initial values
  607. this.reset();
  608. },
  609. /**
  610. * Resets this hasher to its initial state.
  611. *
  612. * @example
  613. *
  614. * hasher.reset();
  615. */
  616. reset: function () {
  617. // Reset data buffer
  618. BufferedBlockAlgorithm.reset.call(this);
  619. // Perform concrete-hasher logic
  620. this._doReset();
  621. },
  622. /**
  623. * Updates this hasher with a message.
  624. *
  625. * @param {WordArray|string} messageUpdate The message to append.
  626. *
  627. * @return {Hasher} This hasher.
  628. *
  629. * @example
  630. *
  631. * hasher.update('message');
  632. * hasher.update(wordArray);
  633. */
  634. update: function (messageUpdate) {
  635. // Append
  636. this._append(messageUpdate);
  637. // Update the hash
  638. this._process();
  639. // Chainable
  640. return this;
  641. },
  642. /**
  643. * Finalizes the hash computation.
  644. * Note that the finalize operation is effectively a destructive, read-once operation.
  645. *
  646. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  647. *
  648. * @return {WordArray} The hash.
  649. *
  650. * @example
  651. *
  652. * var hash = hasher.finalize();
  653. * var hash = hasher.finalize('message');
  654. * var hash = hasher.finalize(wordArray);
  655. */
  656. finalize: function (messageUpdate) {
  657. // Final message update
  658. if (messageUpdate) {
  659. this._append(messageUpdate);
  660. }
  661. // Perform concrete-hasher logic
  662. var hash = this._doFinalize();
  663. return hash;
  664. },
  665. blockSize: 512/32,
  666. /**
  667. * Creates a shortcut function to a hasher's object interface.
  668. *
  669. * @param {Hasher} hasher The hasher to create a helper for.
  670. *
  671. * @return {Function} The shortcut function.
  672. *
  673. * @static
  674. *
  675. * @example
  676. *
  677. * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
  678. */
  679. _createHelper: function (hasher) {
  680. return function (message, cfg) {
  681. return new hasher.init(cfg).finalize(message);
  682. };
  683. },
  684. /**
  685. * Creates a shortcut function to the HMAC's object interface.
  686. *
  687. * @param {Hasher} hasher The hasher to use in this HMAC helper.
  688. *
  689. * @return {Function} The shortcut function.
  690. *
  691. * @static
  692. *
  693. * @example
  694. *
  695. * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
  696. */
  697. _createHmacHelper: function (hasher) {
  698. return function (message, key) {
  699. return new C_algo.HMAC.init(hasher, key).finalize(message);
  700. };
  701. }
  702. });
  703. /**
  704. * Algorithm namespace.
  705. */
  706. var C_algo = C.algo = {};
  707. return C;
  708. }(Math));
  709. (function (undefined) {
  710. // Shortcuts
  711. var C = CryptoJS;
  712. var C_lib = C.lib;
  713. var Base = C_lib.Base;
  714. var X32WordArray = C_lib.WordArray;
  715. /**
  716. * x64 namespace.
  717. */
  718. var C_x64 = C.x64 = {};
  719. /**
  720. * A 64-bit word.
  721. */
  722. var X64Word = C_x64.Word = Base.extend({
  723. /**
  724. * Initializes a newly created 64-bit word.
  725. *
  726. * @param {number} high The high 32 bits.
  727. * @param {number} low The low 32 bits.
  728. *
  729. * @example
  730. *
  731. * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
  732. */
  733. init: function (high, low) {
  734. this.high = high;
  735. this.low = low;
  736. }
  737. /**
  738. * Bitwise NOTs this word.
  739. *
  740. * @return {X64Word} A new x64-Word object after negating.
  741. *
  742. * @example
  743. *
  744. * var negated = x64Word.not();
  745. */
  746. // not: function () {
  747. // var high = ~this.high;
  748. // var low = ~this.low;
  749. // return X64Word.create(high, low);
  750. // },
  751. /**
  752. * Bitwise ANDs this word with the passed word.
  753. *
  754. * @param {X64Word} word The x64-Word to AND with this word.
  755. *
  756. * @return {X64Word} A new x64-Word object after ANDing.
  757. *
  758. * @example
  759. *
  760. * var anded = x64Word.and(anotherX64Word);
  761. */
  762. // and: function (word) {
  763. // var high = this.high & word.high;
  764. // var low = this.low & word.low;
  765. // return X64Word.create(high, low);
  766. // },
  767. /**
  768. * Bitwise ORs this word with the passed word.
  769. *
  770. * @param {X64Word} word The x64-Word to OR with this word.
  771. *
  772. * @return {X64Word} A new x64-Word object after ORing.
  773. *
  774. * @example
  775. *
  776. * var ored = x64Word.or(anotherX64Word);
  777. */
  778. // or: function (word) {
  779. // var high = this.high | word.high;
  780. // var low = this.low | word.low;
  781. // return X64Word.create(high, low);
  782. // },
  783. /**
  784. * Bitwise XORs this word with the passed word.
  785. *
  786. * @param {X64Word} word The x64-Word to XOR with this word.
  787. *
  788. * @return {X64Word} A new x64-Word object after XORing.
  789. *
  790. * @example
  791. *
  792. * var xored = x64Word.xor(anotherX64Word);
  793. */
  794. // xor: function (word) {
  795. // var high = this.high ^ word.high;
  796. // var low = this.low ^ word.low;
  797. // return X64Word.create(high, low);
  798. // },
  799. /**
  800. * Shifts this word n bits to the left.
  801. *
  802. * @param {number} n The number of bits to shift.
  803. *
  804. * @return {X64Word} A new x64-Word object after shifting.
  805. *
  806. * @example
  807. *
  808. * var shifted = x64Word.shiftL(25);
  809. */
  810. // shiftL: function (n) {
  811. // if (n < 32) {
  812. // var high = (this.high << n) | (this.low >>> (32 - n));
  813. // var low = this.low << n;
  814. // } else {
  815. // var high = this.low << (n - 32);
  816. // var low = 0;
  817. // }
  818. // return X64Word.create(high, low);
  819. // },
  820. /**
  821. * Shifts this word n bits to the right.
  822. *
  823. * @param {number} n The number of bits to shift.
  824. *
  825. * @return {X64Word} A new x64-Word object after shifting.
  826. *
  827. * @example
  828. *
  829. * var shifted = x64Word.shiftR(7);
  830. */
  831. // shiftR: function (n) {
  832. // if (n < 32) {
  833. // var low = (this.low >>> n) | (this.high << (32 - n));
  834. // var high = this.high >>> n;
  835. // } else {
  836. // var low = this.high >>> (n - 32);
  837. // var high = 0;
  838. // }
  839. // return X64Word.create(high, low);
  840. // },
  841. /**
  842. * Rotates this word n bits to the left.
  843. *
  844. * @param {number} n The number of bits to rotate.
  845. *
  846. * @return {X64Word} A new x64-Word object after rotating.
  847. *
  848. * @example
  849. *
  850. * var rotated = x64Word.rotL(25);
  851. */
  852. // rotL: function (n) {
  853. // return this.shiftL(n).or(this.shiftR(64 - n));
  854. // },
  855. /**
  856. * Rotates this word n bits to the right.
  857. *
  858. * @param {number} n The number of bits to rotate.
  859. *
  860. * @return {X64Word} A new x64-Word object after rotating.
  861. *
  862. * @example
  863. *
  864. * var rotated = x64Word.rotR(7);
  865. */
  866. // rotR: function (n) {
  867. // return this.shiftR(n).or(this.shiftL(64 - n));
  868. // },
  869. /**
  870. * Adds this word with the passed word.
  871. *
  872. * @param {X64Word} word The x64-Word to add with this word.
  873. *
  874. * @return {X64Word} A new x64-Word object after adding.
  875. *
  876. * @example
  877. *
  878. * var added = x64Word.add(anotherX64Word);
  879. */
  880. // add: function (word) {
  881. // var low = (this.low + word.low) | 0;
  882. // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
  883. // var high = (this.high + word.high + carry) | 0;
  884. // return X64Word.create(high, low);
  885. // }
  886. });
  887. /**
  888. * An array of 64-bit words.
  889. *
  890. * @property {Array} words The array of CryptoJS.x64.Word objects.
  891. * @property {number} sigBytes The number of significant bytes in this word array.
  892. */
  893. var X64WordArray = C_x64.WordArray = Base.extend({
  894. /**
  895. * Initializes a newly created word array.
  896. *
  897. * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
  898. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  899. *
  900. * @example
  901. *
  902. * var wordArray = CryptoJS.x64.WordArray.create();
  903. *
  904. * var wordArray = CryptoJS.x64.WordArray.create([
  905. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  906. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  907. * ]);
  908. *
  909. * var wordArray = CryptoJS.x64.WordArray.create([
  910. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  911. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  912. * ], 10);
  913. */
  914. init: function (words, sigBytes) {
  915. words = this.words = words || [];
  916. if (sigBytes != undefined) {
  917. this.sigBytes = sigBytes;
  918. } else {
  919. this.sigBytes = words.length * 8;
  920. }
  921. },
  922. /**
  923. * Converts this 64-bit word array to a 32-bit word array.
  924. *
  925. * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
  926. *
  927. * @example
  928. *
  929. * var x32WordArray = x64WordArray.toX32();
  930. */
  931. toX32: function () {
  932. // Shortcuts
  933. var x64Words = this.words;
  934. var x64WordsLength = x64Words.length;
  935. // Convert
  936. var x32Words = [];
  937. for (var i = 0; i < x64WordsLength; i++) {
  938. var x64Word = x64Words[i];
  939. x32Words.push(x64Word.high);
  940. x32Words.push(x64Word.low);
  941. }
  942. return X32WordArray.create(x32Words, this.sigBytes);
  943. },
  944. /**
  945. * Creates a copy of this word array.
  946. *
  947. * @return {X64WordArray} The clone.
  948. *
  949. * @example
  950. *
  951. * var clone = x64WordArray.clone();
  952. */
  953. clone: function () {
  954. var clone = Base.clone.call(this);
  955. // Clone "words" array
  956. var words = clone.words = this.words.slice(0);
  957. // Clone each X64Word object
  958. var wordsLength = words.length;
  959. for (var i = 0; i < wordsLength; i++) {
  960. words[i] = words[i].clone();
  961. }
  962. return clone;
  963. }
  964. });
  965. }());
  966. (function () {
  967. // Check if typed arrays are supported
  968. if (typeof ArrayBuffer != 'function') {
  969. return;
  970. }
  971. // Shortcuts
  972. var C = CryptoJS;
  973. var C_lib = C.lib;
  974. var WordArray = C_lib.WordArray;
  975. // Reference original init
  976. var superInit = WordArray.init;
  977. // Augment WordArray.init to handle typed arrays
  978. var subInit = WordArray.init = function (typedArray) {
  979. // Convert buffers to uint8
  980. if (typedArray instanceof ArrayBuffer) {
  981. typedArray = new Uint8Array(typedArray);
  982. }
  983. // Convert other array views to uint8
  984. if (
  985. typedArray instanceof Int8Array ||
  986. (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) ||
  987. typedArray instanceof Int16Array ||
  988. typedArray instanceof Uint16Array ||
  989. typedArray instanceof Int32Array ||
  990. typedArray instanceof Uint32Array ||
  991. typedArray instanceof Float32Array ||
  992. typedArray instanceof Float64Array
  993. ) {
  994. typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
  995. }
  996. // Handle Uint8Array
  997. if (typedArray instanceof Uint8Array) {
  998. // Shortcut
  999. var typedArrayByteLength = typedArray.byteLength;
  1000. // Extract bytes
  1001. var words = [];
  1002. for (var i = 0; i < typedArrayByteLength; i++) {
  1003. words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
  1004. }
  1005. // Initialize this word array
  1006. superInit.call(this, words, typedArrayByteLength);
  1007. } else {
  1008. // Else call normal init
  1009. superInit.apply(this, arguments);
  1010. }
  1011. };
  1012. subInit.prototype = WordArray;
  1013. }());
  1014. (function () {
  1015. // Shortcuts
  1016. var C = CryptoJS;
  1017. var C_lib = C.lib;
  1018. var WordArray = C_lib.WordArray;
  1019. var C_enc = C.enc;
  1020. /**
  1021. * UTF-16 BE encoding strategy.
  1022. */
  1023. var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = {
  1024. /**
  1025. * Converts a word array to a UTF-16 BE string.
  1026. *
  1027. * @param {WordArray} wordArray The word array.
  1028. *
  1029. * @return {string} The UTF-16 BE string.
  1030. *
  1031. * @static
  1032. *
  1033. * @example
  1034. *
  1035. * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray);
  1036. */
  1037. stringify: function (wordArray) {
  1038. // Shortcuts
  1039. var words = wordArray.words;
  1040. var sigBytes = wordArray.sigBytes;
  1041. // Convert
  1042. var utf16Chars = [];
  1043. for (var i = 0; i < sigBytes; i += 2) {
  1044. var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff;
  1045. utf16Chars.push(String.fromCharCode(codePoint));
  1046. }
  1047. return utf16Chars.join('');
  1048. },
  1049. /**
  1050. * Converts a UTF-16 BE string to a word array.
  1051. *
  1052. * @param {string} utf16Str The UTF-16 BE string.
  1053. *
  1054. * @return {WordArray} The word array.
  1055. *
  1056. * @static
  1057. *
  1058. * @example
  1059. *
  1060. * var wordArray = CryptoJS.enc.Utf16.parse(utf16String);
  1061. */
  1062. parse: function (utf16Str) {
  1063. // Shortcut
  1064. var utf16StrLength = utf16Str.length;
  1065. // Convert
  1066. var words = [];
  1067. for (var i = 0; i < utf16StrLength; i++) {
  1068. words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16);
  1069. }
  1070. return WordArray.create(words, utf16StrLength * 2);
  1071. }
  1072. };
  1073. /**
  1074. * UTF-16 LE encoding strategy.
  1075. */
  1076. C_enc.Utf16LE = {
  1077. /**
  1078. * Converts a word array to a UTF-16 LE string.
  1079. *
  1080. * @param {WordArray} wordArray The word array.
  1081. *
  1082. * @return {string} The UTF-16 LE string.
  1083. *
  1084. * @static
  1085. *
  1086. * @example
  1087. *
  1088. * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
  1089. */
  1090. stringify: function (wordArray) {
  1091. // Shortcuts
  1092. var words = wordArray.words;
  1093. var sigBytes = wordArray.sigBytes;
  1094. // Convert
  1095. var utf16Chars = [];
  1096. for (var i = 0; i < sigBytes; i += 2) {
  1097. var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff);
  1098. utf16Chars.push(String.fromCharCode(codePoint));
  1099. }
  1100. return utf16Chars.join('');
  1101. },
  1102. /**
  1103. * Converts a UTF-16 LE string to a word array.
  1104. *
  1105. * @param {string} utf16Str The UTF-16 LE string.
  1106. *
  1107. * @return {WordArray} The word array.
  1108. *
  1109. * @static
  1110. *
  1111. * @example
  1112. *
  1113. * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str);
  1114. */
  1115. parse: function (utf16Str) {
  1116. // Shortcut
  1117. var utf16StrLength = utf16Str.length;
  1118. // Convert
  1119. var words = [];
  1120. for (var i = 0; i < utf16StrLength; i++) {
  1121. words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16));
  1122. }
  1123. return WordArray.create(words, utf16StrLength * 2);
  1124. }
  1125. };
  1126. function swapEndian(word) {
  1127. return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff);
  1128. }
  1129. }());
  1130. (function () {
  1131. // Shortcuts
  1132. var C = CryptoJS;
  1133. var C_lib = C.lib;
  1134. var WordArray = C_lib.WordArray;
  1135. var C_enc = C.enc;
  1136. /**
  1137. * Base64 encoding strategy.
  1138. */
  1139. var Base64 = C_enc.Base64 = {
  1140. /**
  1141. * Converts a word array to a Base64 string.
  1142. *
  1143. * @param {WordArray} wordArray The word array.
  1144. *
  1145. * @return {string} The Base64 string.
  1146. *
  1147. * @static
  1148. *
  1149. * @example
  1150. *
  1151. * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
  1152. */
  1153. stringify: function (wordArray) {
  1154. // Shortcuts
  1155. var words = wordArray.words;
  1156. var sigBytes = wordArray.sigBytes;
  1157. var map = this._map;
  1158. // Clamp excess bits
  1159. wordArray.clamp();
  1160. // Convert
  1161. var base64Chars = [];
  1162. for (var i = 0; i < sigBytes; i += 3) {
  1163. var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  1164. var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
  1165. var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
  1166. var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
  1167. for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
  1168. base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
  1169. }
  1170. }
  1171. // Add padding
  1172. var paddingChar = map.charAt(64);
  1173. if (paddingChar) {
  1174. while (base64Chars.length % 4) {
  1175. base64Chars.push(paddingChar);
  1176. }
  1177. }
  1178. return base64Chars.join('');
  1179. },
  1180. /**
  1181. * Converts a Base64 string to a word array.
  1182. *
  1183. * @param {string} base64Str The Base64 string.
  1184. *
  1185. * @return {WordArray} The word array.
  1186. *
  1187. * @static
  1188. *
  1189. * @example
  1190. *
  1191. * var wordArray = CryptoJS.enc.Base64.parse(base64String);
  1192. */
  1193. parse: function (base64Str) {
  1194. // Shortcuts
  1195. var base64StrLength = base64Str.length;
  1196. var map = this._map;
  1197. var reverseMap = this._reverseMap;
  1198. if (!reverseMap) {
  1199. reverseMap = this._reverseMap = [];
  1200. for (var j = 0; j < map.length; j++) {
  1201. reverseMap[map.charCodeAt(j)] = j;
  1202. }
  1203. }
  1204. // Ignore padding
  1205. var paddingChar = map.charAt(64);
  1206. if (paddingChar) {
  1207. var paddingIndex = base64Str.indexOf(paddingChar);
  1208. if (paddingIndex !== -1) {
  1209. base64StrLength = paddingIndex;
  1210. }
  1211. }
  1212. // Convert
  1213. return parseLoop(base64Str, base64StrLength, reverseMap);
  1214. },
  1215. _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
  1216. };
  1217. function parseLoop(base64Str, base64StrLength, reverseMap) {
  1218. var words = [];
  1219. var nBytes = 0;
  1220. for (var i = 0; i < base64StrLength; i++) {
  1221. if (i % 4) {
  1222. var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
  1223. var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
  1224. var bitsCombined = bits1 | bits2;
  1225. words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8);
  1226. nBytes++;
  1227. }
  1228. }
  1229. return WordArray.create(words, nBytes);
  1230. }
  1231. }());
  1232. (function () {
  1233. // Shortcuts
  1234. var C = CryptoJS;
  1235. var C_lib = C.lib;
  1236. var WordArray = C_lib.WordArray;
  1237. var C_enc = C.enc;
  1238. /**
  1239. * Base64url encoding strategy.
  1240. */
  1241. var Base64url = C_enc.Base64url = {
  1242. /**
  1243. * Converts a word array to a Base64url string.
  1244. *
  1245. * @param {WordArray} wordArray The word array.
  1246. *
  1247. * @param {boolean} urlSafe Whether to use url safe
  1248. *
  1249. * @return {string} The Base64url string.
  1250. *
  1251. * @static
  1252. *
  1253. * @example
  1254. *
  1255. * var base64String = CryptoJS.enc.Base64url.stringify(wordArray);
  1256. */
  1257. stringify: function (wordArray, urlSafe) {
  1258. if (urlSafe === undefined) {
  1259. urlSafe = true
  1260. }
  1261. // Shortcuts
  1262. var words = wordArray.words;
  1263. var sigBytes = wordArray.sigBytes;
  1264. var map = urlSafe ? this._safe_map : this._map;
  1265. // Clamp excess bits
  1266. wordArray.clamp();
  1267. // Convert
  1268. var base64Chars = [];
  1269. for (var i = 0; i < sigBytes; i += 3) {
  1270. var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  1271. var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
  1272. var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
  1273. var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
  1274. for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
  1275. base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
  1276. }
  1277. }
  1278. // Add padding
  1279. var paddingChar = map.charAt(64);
  1280. if (paddingChar) {
  1281. while (base64Chars.length % 4) {
  1282. base64Chars.push(paddingChar);
  1283. }
  1284. }
  1285. return base64Chars.join('');
  1286. },
  1287. /**
  1288. * Converts a Base64url string to a word array.
  1289. *
  1290. * @param {string} base64Str The Base64url string.
  1291. *
  1292. * @param {boolean} urlSafe Whether to use url safe
  1293. *
  1294. * @return {WordArray} The word array.
  1295. *
  1296. * @static
  1297. *
  1298. * @example
  1299. *
  1300. * var wordArray = CryptoJS.enc.Base64url.parse(base64String);
  1301. */
  1302. parse: function (base64Str, urlSafe) {
  1303. if (urlSafe === undefined) {
  1304. urlSafe = true
  1305. }
  1306. // Shortcuts
  1307. var base64StrLength = base64Str.length;
  1308. var map = urlSafe ? this._safe_map : this._map;
  1309. var reverseMap = this._reverseMap;
  1310. if (!reverseMap) {
  1311. reverseMap = this._reverseMap = [];
  1312. for (var j = 0; j < map.length; j++) {
  1313. reverseMap[map.charCodeAt(j)] = j;
  1314. }
  1315. }
  1316. // Ignore padding
  1317. var paddingChar = map.charAt(64);
  1318. if (paddingChar) {
  1319. var paddingIndex = base64Str.indexOf(paddingChar);
  1320. if (paddingIndex !== -1) {
  1321. base64StrLength = paddingIndex;
  1322. }
  1323. }
  1324. // Convert
  1325. return parseLoop(base64Str, base64StrLength, reverseMap);
  1326. },
  1327. _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
  1328. _safe_map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
  1329. };
  1330. function parseLoop(base64Str, base64StrLength, reverseMap) {
  1331. var words = [];
  1332. var nBytes = 0;
  1333. for (var i = 0; i < base64StrLength; i++) {
  1334. if (i % 4) {
  1335. var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
  1336. var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
  1337. var bitsCombined = bits1 | bits2;
  1338. words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8);
  1339. nBytes++;
  1340. }
  1341. }
  1342. return WordArray.create(words, nBytes);
  1343. }
  1344. }());
  1345. (function (Math) {
  1346. // Shortcuts
  1347. var C = CryptoJS;
  1348. var C_lib = C.lib;
  1349. var WordArray = C_lib.WordArray;
  1350. var Hasher = C_lib.Hasher;
  1351. var C_algo = C.algo;
  1352. // Constants table
  1353. var T = [];
  1354. // Compute constants
  1355. (function () {
  1356. for (var i = 0; i < 64; i++) {
  1357. T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
  1358. }
  1359. }());
  1360. /**
  1361. * MD5 hash algorithm.
  1362. */
  1363. var MD5 = C_algo.MD5 = Hasher.extend({
  1364. _doReset: function () {
  1365. this._hash = new WordArray.init([
  1366. 0x67452301, 0xefcdab89,
  1367. 0x98badcfe, 0x10325476
  1368. ]);
  1369. },
  1370. _doProcessBlock: function (M, offset) {
  1371. // Swap endian
  1372. for (var i = 0; i < 16; i++) {
  1373. // Shortcuts
  1374. var offset_i = offset + i;
  1375. var M_offset_i = M[offset_i];
  1376. M[offset_i] = (
  1377. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  1378. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  1379. );
  1380. }
  1381. // Shortcuts
  1382. var H = this._hash.words;
  1383. var M_offset_0 = M[offset + 0];
  1384. var M_offset_1 = M[offset + 1];
  1385. var M_offset_2 = M[offset + 2];
  1386. var M_offset_3 = M[offset + 3];
  1387. var M_offset_4 = M[offset + 4];
  1388. var M_offset_5 = M[offset + 5];
  1389. var M_offset_6 = M[offset + 6];
  1390. var M_offset_7 = M[offset + 7];
  1391. var M_offset_8 = M[offset + 8];
  1392. var M_offset_9 = M[offset + 9];
  1393. var M_offset_10 = M[offset + 10];
  1394. var M_offset_11 = M[offset + 11];
  1395. var M_offset_12 = M[offset + 12];
  1396. var M_offset_13 = M[offset + 13];
  1397. var M_offset_14 = M[offset + 14];
  1398. var M_offset_15 = M[offset + 15];
  1399. // Working variables
  1400. var a = H[0];
  1401. var b = H[1];
  1402. var c = H[2];
  1403. var d = H[3];
  1404. // Computation
  1405. a = FF(a, b, c, d, M_offset_0, 7, T[0]);
  1406. d = FF(d, a, b, c, M_offset_1, 12, T[1]);
  1407. c = FF(c, d, a, b, M_offset_2, 17, T[2]);
  1408. b = FF(b, c, d, a, M_offset_3, 22, T[3]);
  1409. a = FF(a, b, c, d, M_offset_4, 7, T[4]);
  1410. d = FF(d, a, b, c, M_offset_5, 12, T[5]);
  1411. c = FF(c, d, a, b, M_offset_6, 17, T[6]);
  1412. b = FF(b, c, d, a, M_offset_7, 22, T[7]);
  1413. a = FF(a, b, c, d, M_offset_8, 7, T[8]);
  1414. d = FF(d, a, b, c, M_offset_9, 12, T[9]);
  1415. c = FF(c, d, a, b, M_offset_10, 17, T[10]);
  1416. b = FF(b, c, d, a, M_offset_11, 22, T[11]);
  1417. a = FF(a, b, c, d, M_offset_12, 7, T[12]);
  1418. d = FF(d, a, b, c, M_offset_13, 12, T[13]);
  1419. c = FF(c, d, a, b, M_offset_14, 17, T[14]);
  1420. b = FF(b, c, d, a, M_offset_15, 22, T[15]);
  1421. a = GG(a, b, c, d, M_offset_1, 5, T[16]);
  1422. d = GG(d, a, b, c, M_offset_6, 9, T[17]);
  1423. c = GG(c, d, a, b, M_offset_11, 14, T[18]);
  1424. b = GG(b, c, d, a, M_offset_0, 20, T[19]);
  1425. a = GG(a, b, c, d, M_offset_5, 5, T[20]);
  1426. d = GG(d, a, b, c, M_offset_10, 9, T[21]);
  1427. c = GG(c, d, a, b, M_offset_15, 14, T[22]);
  1428. b = GG(b, c, d, a, M_offset_4, 20, T[23]);
  1429. a = GG(a, b, c, d, M_offset_9, 5, T[24]);
  1430. d = GG(d, a, b, c, M_offset_14, 9, T[25]);
  1431. c = GG(c, d, a, b, M_offset_3, 14, T[26]);
  1432. b = GG(b, c, d, a, M_offset_8, 20, T[27]);
  1433. a = GG(a, b, c, d, M_offset_13, 5, T[28]);
  1434. d = GG(d, a, b, c, M_offset_2, 9, T[29]);
  1435. c = GG(c, d, a, b, M_offset_7, 14, T[30]);
  1436. b = GG(b, c, d, a, M_offset_12, 20, T[31]);
  1437. a = HH(a, b, c, d, M_offset_5, 4, T[32]);
  1438. d = HH(d, a, b, c, M_offset_8, 11, T[33]);
  1439. c = HH(c, d, a, b, M_offset_11, 16, T[34]);
  1440. b = HH(b, c, d, a, M_offset_14, 23, T[35]);
  1441. a = HH(a, b, c, d, M_offset_1, 4, T[36]);
  1442. d = HH(d, a, b, c, M_offset_4, 11, T[37]);
  1443. c = HH(c, d, a, b, M_offset_7, 16, T[38]);
  1444. b = HH(b, c, d, a, M_offset_10, 23, T[39]);
  1445. a = HH(a, b, c, d, M_offset_13, 4, T[40]);
  1446. d = HH(d, a, b, c, M_offset_0, 11, T[41]);
  1447. c = HH(c, d, a, b, M_offset_3, 16, T[42]);
  1448. b = HH(b, c, d, a, M_offset_6, 23, T[43]);
  1449. a = HH(a, b, c, d, M_offset_9, 4, T[44]);
  1450. d = HH(d, a, b, c, M_offset_12, 11, T[45]);
  1451. c = HH(c, d, a, b, M_offset_15, 16, T[46]);
  1452. b = HH(b, c, d, a, M_offset_2, 23, T[47]);
  1453. a = II(a, b, c, d, M_offset_0, 6, T[48]);
  1454. d = II(d, a, b, c, M_offset_7, 10, T[49]);
  1455. c = II(c, d, a, b, M_offset_14, 15, T[50]);
  1456. b = II(b, c, d, a, M_offset_5, 21, T[51]);
  1457. a = II(a, b, c, d, M_offset_12, 6, T[52]);
  1458. d = II(d, a, b, c, M_offset_3, 10, T[53]);
  1459. c = II(c, d, a, b, M_offset_10, 15, T[54]);
  1460. b = II(b, c, d, a, M_offset_1, 21, T[55]);
  1461. a = II(a, b, c, d, M_offset_8, 6, T[56]);
  1462. d = II(d, a, b, c, M_offset_15, 10, T[57]);
  1463. c = II(c, d, a, b, M_offset_6, 15, T[58]);
  1464. b = II(b, c, d, a, M_offset_13, 21, T[59]);
  1465. a = II(a, b, c, d, M_offset_4, 6, T[60]);
  1466. d = II(d, a, b, c, M_offset_11, 10, T[61]);
  1467. c = II(c, d, a, b, M_offset_2, 15, T[62]);
  1468. b = II(b, c, d, a, M_offset_9, 21, T[63]);
  1469. // Intermediate hash value
  1470. H[0] = (H[0] + a) | 0;
  1471. H[1] = (H[1] + b) | 0;
  1472. H[2] = (H[2] + c) | 0;
  1473. H[3] = (H[3] + d) | 0;
  1474. },
  1475. _doFinalize: function () {
  1476. // Shortcuts
  1477. var data = this._data;
  1478. var dataWords = data.words;
  1479. var nBitsTotal = this._nDataBytes * 8;
  1480. var nBitsLeft = data.sigBytes * 8;
  1481. // Add padding
  1482. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  1483. var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
  1484. var nBitsTotalL = nBitsTotal;
  1485. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
  1486. (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
  1487. (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
  1488. );
  1489. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  1490. (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
  1491. (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
  1492. );
  1493. data.sigBytes = (dataWords.length + 1) * 4;
  1494. // Hash final blocks
  1495. this._process();
  1496. // Shortcuts
  1497. var hash = this._hash;
  1498. var H = hash.words;
  1499. // Swap endian
  1500. for (var i = 0; i < 4; i++) {
  1501. // Shortcut
  1502. var H_i = H[i];
  1503. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  1504. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  1505. }
  1506. // Return final computed hash
  1507. return hash;
  1508. },
  1509. clone: function () {
  1510. var clone = Hasher.clone.call(this);
  1511. clone._hash = this._hash.clone();
  1512. return clone;
  1513. }
  1514. });
  1515. function FF(a, b, c, d, x, s, t) {
  1516. var n = a + ((b & c) | (~b & d)) + x + t;
  1517. return ((n << s) | (n >>> (32 - s))) + b;
  1518. }
  1519. function GG(a, b, c, d, x, s, t) {
  1520. var n = a + ((b & d) | (c & ~d)) + x + t;
  1521. return ((n << s) | (n >>> (32 - s))) + b;
  1522. }
  1523. function HH(a, b, c, d, x, s, t) {
  1524. var n = a + (b ^ c ^ d) + x + t;
  1525. return ((n << s) | (n >>> (32 - s))) + b;
  1526. }
  1527. function II(a, b, c, d, x, s, t) {
  1528. var n = a + (c ^ (b | ~d)) + x + t;
  1529. return ((n << s) | (n >>> (32 - s))) + b;
  1530. }
  1531. /**
  1532. * Shortcut function to the hasher's object interface.
  1533. *
  1534. * @param {WordArray|string} message The message to hash.
  1535. *
  1536. * @return {WordArray} The hash.
  1537. *
  1538. * @static
  1539. *
  1540. * @example
  1541. *
  1542. * var hash = CryptoJS.MD5('message');
  1543. * var hash = CryptoJS.MD5(wordArray);
  1544. */
  1545. C.MD5 = Hasher._createHelper(MD5);
  1546. /**
  1547. * Shortcut function to the HMAC's object interface.
  1548. *
  1549. * @param {WordArray|string} message The message to hash.
  1550. * @param {WordArray|string} key The secret key.
  1551. *
  1552. * @return {WordArray} The HMAC.
  1553. *
  1554. * @static
  1555. *
  1556. * @example
  1557. *
  1558. * var hmac = CryptoJS.HmacMD5(message, key);
  1559. */
  1560. C.HmacMD5 = Hasher._createHmacHelper(MD5);
  1561. }(Math));
  1562. (function () {
  1563. // Shortcuts
  1564. var C = CryptoJS;
  1565. var C_lib = C.lib;
  1566. var WordArray = C_lib.WordArray;
  1567. var Hasher = C_lib.Hasher;
  1568. var C_algo = C.algo;
  1569. // Reusable object
  1570. var W = [];
  1571. /**
  1572. * SHA-1 hash algorithm.
  1573. */
  1574. var SHA1 = C_algo.SHA1 = Hasher.extend({
  1575. _doReset: function () {
  1576. this._hash = new WordArray.init([
  1577. 0x67452301, 0xefcdab89,
  1578. 0x98badcfe, 0x10325476,
  1579. 0xc3d2e1f0
  1580. ]);
  1581. },
  1582. _doProcessBlock: function (M, offset) {
  1583. // Shortcut
  1584. var H = this._hash.words;
  1585. // Working variables
  1586. var a = H[0];
  1587. var b = H[1];
  1588. var c = H[2];
  1589. var d = H[3];
  1590. var e = H[4];
  1591. // Computation
  1592. for (var i = 0; i < 80; i++) {
  1593. if (i < 16) {
  1594. W[i] = M[offset + i] | 0;
  1595. } else {
  1596. var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  1597. W[i] = (n << 1) | (n >>> 31);
  1598. }
  1599. var t = ((a << 5) | (a >>> 27)) + e + W[i];
  1600. if (i < 20) {
  1601. t += ((b & c) | (~b & d)) + 0x5a827999;
  1602. } else if (i < 40) {
  1603. t += (b ^ c ^ d) + 0x6ed9eba1;
  1604. } else if (i < 60) {
  1605. t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
  1606. } else /* if (i < 80) */ {
  1607. t += (b ^ c ^ d) - 0x359d3e2a;
  1608. }
  1609. e = d;
  1610. d = c;
  1611. c = (b << 30) | (b >>> 2);
  1612. b = a;
  1613. a = t;
  1614. }
  1615. // Intermediate hash value
  1616. H[0] = (H[0] + a) | 0;
  1617. H[1] = (H[1] + b) | 0;
  1618. H[2] = (H[2] + c) | 0;
  1619. H[3] = (H[3] + d) | 0;
  1620. H[4] = (H[4] + e) | 0;
  1621. },
  1622. _doFinalize: function () {
  1623. // Shortcuts
  1624. var data = this._data;
  1625. var dataWords = data.words;
  1626. var nBitsTotal = this._nDataBytes * 8;
  1627. var nBitsLeft = data.sigBytes * 8;
  1628. // Add padding
  1629. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  1630. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  1631. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  1632. data.sigBytes = dataWords.length * 4;
  1633. // Hash final blocks
  1634. this._process();
  1635. // Return final computed hash
  1636. return this._hash;
  1637. },
  1638. clone: function () {
  1639. var clone = Hasher.clone.call(this);
  1640. clone._hash = this._hash.clone();
  1641. return clone;
  1642. }
  1643. });
  1644. /**
  1645. * Shortcut function to the hasher's object interface.
  1646. *
  1647. * @param {WordArray|string} message The message to hash.
  1648. *
  1649. * @return {WordArray} The hash.
  1650. *
  1651. * @static
  1652. *
  1653. * @example
  1654. *
  1655. * var hash = CryptoJS.SHA1('message');
  1656. * var hash = CryptoJS.SHA1(wordArray);
  1657. */
  1658. C.SHA1 = Hasher._createHelper(SHA1);
  1659. /**
  1660. * Shortcut function to the HMAC's object interface.
  1661. *
  1662. * @param {WordArray|string} message The message to hash.
  1663. * @param {WordArray|string} key The secret key.
  1664. *
  1665. * @return {WordArray} The HMAC.
  1666. *
  1667. * @static
  1668. *
  1669. * @example
  1670. *
  1671. * var hmac = CryptoJS.HmacSHA1(message, key);
  1672. */
  1673. C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
  1674. }());
  1675. (function (Math) {
  1676. // Shortcuts
  1677. var C = CryptoJS;
  1678. var C_lib = C.lib;
  1679. var WordArray = C_lib.WordArray;
  1680. var Hasher = C_lib.Hasher;
  1681. var C_algo = C.algo;
  1682. // Initialization and round constants tables
  1683. var H = [];
  1684. var K = [];
  1685. // Compute constants
  1686. (function () {
  1687. function isPrime(n) {
  1688. var sqrtN = Math.sqrt(n);
  1689. for (var factor = 2; factor <= sqrtN; factor++) {
  1690. if (!(n % factor)) {
  1691. return false;
  1692. }
  1693. }
  1694. return true;
  1695. }
  1696. function getFractionalBits(n) {
  1697. return ((n - (n | 0)) * 0x100000000) | 0;
  1698. }
  1699. var n = 2;
  1700. var nPrime = 0;
  1701. while (nPrime < 64) {
  1702. if (isPrime(n)) {
  1703. if (nPrime < 8) {
  1704. H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
  1705. }
  1706. K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
  1707. nPrime++;
  1708. }
  1709. n++;
  1710. }
  1711. }());
  1712. // Reusable object
  1713. var W = [];
  1714. /**
  1715. * SHA-256 hash algorithm.
  1716. */
  1717. var SHA256 = C_algo.SHA256 = Hasher.extend({
  1718. _doReset: function () {
  1719. this._hash = new WordArray.init(H.slice(0));
  1720. },
  1721. _doProcessBlock: function (M, offset) {
  1722. // Shortcut
  1723. var H = this._hash.words;
  1724. // Working variables
  1725. var a = H[0];
  1726. var b = H[1];
  1727. var c = H[2];
  1728. var d = H[3];
  1729. var e = H[4];
  1730. var f = H[5];
  1731. var g = H[6];
  1732. var h = H[7];
  1733. // Computation
  1734. for (var i = 0; i < 64; i++) {
  1735. if (i < 16) {
  1736. W[i] = M[offset + i] | 0;
  1737. } else {
  1738. var gamma0x = W[i - 15];
  1739. var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^
  1740. ((gamma0x << 14) | (gamma0x >>> 18)) ^
  1741. (gamma0x >>> 3);
  1742. var gamma1x = W[i - 2];
  1743. var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^
  1744. ((gamma1x << 13) | (gamma1x >>> 19)) ^
  1745. (gamma1x >>> 10);
  1746. W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
  1747. }
  1748. var ch = (e & f) ^ (~e & g);
  1749. var maj = (a & b) ^ (a & c) ^ (b & c);
  1750. var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
  1751. var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
  1752. var t1 = h + sigma1 + ch + K[i] + W[i];
  1753. var t2 = sigma0 + maj;
  1754. h = g;
  1755. g = f;
  1756. f = e;
  1757. e = (d + t1) | 0;
  1758. d = c;
  1759. c = b;
  1760. b = a;
  1761. a = (t1 + t2) | 0;
  1762. }
  1763. // Intermediate hash value
  1764. H[0] = (H[0] + a) | 0;
  1765. H[1] = (H[1] + b) | 0;
  1766. H[2] = (H[2] + c) | 0;
  1767. H[3] = (H[3] + d) | 0;
  1768. H[4] = (H[4] + e) | 0;
  1769. H[5] = (H[5] + f) | 0;
  1770. H[6] = (H[6] + g) | 0;
  1771. H[7] = (H[7] + h) | 0;
  1772. },
  1773. _doFinalize: function () {
  1774. // Shortcuts
  1775. var data = this._data;
  1776. var dataWords = data.words;
  1777. var nBitsTotal = this._nDataBytes * 8;
  1778. var nBitsLeft = data.sigBytes * 8;
  1779. // Add padding
  1780. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  1781. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  1782. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  1783. data.sigBytes = dataWords.length * 4;
  1784. // Hash final blocks
  1785. this._process();
  1786. // Return final computed hash
  1787. return this._hash;
  1788. },
  1789. clone: function () {
  1790. var clone = Hasher.clone.call(this);
  1791. clone._hash = this._hash.clone();
  1792. return clone;
  1793. }
  1794. });
  1795. /**
  1796. * Shortcut function to the hasher's object interface.
  1797. *
  1798. * @param {WordArray|string} message The message to hash.
  1799. *
  1800. * @return {WordArray} The hash.
  1801. *
  1802. * @static
  1803. *
  1804. * @example
  1805. *
  1806. * var hash = CryptoJS.SHA256('message');
  1807. * var hash = CryptoJS.SHA256(wordArray);
  1808. */
  1809. C.SHA256 = Hasher._createHelper(SHA256);
  1810. /**
  1811. * Shortcut function to the HMAC's object interface.
  1812. *
  1813. * @param {WordArray|string} message The message to hash.
  1814. * @param {WordArray|string} key The secret key.
  1815. *
  1816. * @return {WordArray} The HMAC.
  1817. *
  1818. * @static
  1819. *
  1820. * @example
  1821. *
  1822. * var hmac = CryptoJS.HmacSHA256(message, key);
  1823. */
  1824. C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
  1825. }(Math));
  1826. (function () {
  1827. // Shortcuts
  1828. var C = CryptoJS;
  1829. var C_lib = C.lib;
  1830. var WordArray = C_lib.WordArray;
  1831. var C_algo = C.algo;
  1832. var SHA256 = C_algo.SHA256;
  1833. /**
  1834. * SHA-224 hash algorithm.
  1835. */
  1836. var SHA224 = C_algo.SHA224 = SHA256.extend({
  1837. _doReset: function () {
  1838. this._hash = new WordArray.init([
  1839. 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
  1840. 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
  1841. ]);
  1842. },
  1843. _doFinalize: function () {
  1844. var hash = SHA256._doFinalize.call(this);
  1845. hash.sigBytes -= 4;
  1846. return hash;
  1847. }
  1848. });
  1849. /**
  1850. * Shortcut function to the hasher's object interface.
  1851. *
  1852. * @param {WordArray|string} message The message to hash.
  1853. *
  1854. * @return {WordArray} The hash.
  1855. *
  1856. * @static
  1857. *
  1858. * @example
  1859. *
  1860. * var hash = CryptoJS.SHA224('message');
  1861. * var hash = CryptoJS.SHA224(wordArray);
  1862. */
  1863. C.SHA224 = SHA256._createHelper(SHA224);
  1864. /**
  1865. * Shortcut function to the HMAC's object interface.
  1866. *
  1867. * @param {WordArray|string} message The message to hash.
  1868. * @param {WordArray|string} key The secret key.
  1869. *
  1870. * @return {WordArray} The HMAC.
  1871. *
  1872. * @static
  1873. *
  1874. * @example
  1875. *
  1876. * var hmac = CryptoJS.HmacSHA224(message, key);
  1877. */
  1878. C.HmacSHA224 = SHA256._createHmacHelper(SHA224);
  1879. }());
  1880. (function () {
  1881. // Shortcuts
  1882. var C = CryptoJS;
  1883. var C_lib = C.lib;
  1884. var Hasher = C_lib.Hasher;
  1885. var C_x64 = C.x64;
  1886. var X64Word = C_x64.Word;
  1887. var X64WordArray = C_x64.WordArray;
  1888. var C_algo = C.algo;
  1889. function X64Word_create() {
  1890. return X64Word.create.apply(X64Word, arguments);
  1891. }
  1892. // Constants
  1893. var K = [
  1894. X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd),
  1895. X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc),
  1896. X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019),
  1897. X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118),
  1898. X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe),
  1899. X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2),
  1900. X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1),
  1901. X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694),
  1902. X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3),
  1903. X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65),
  1904. X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483),
  1905. X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5),
  1906. X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210),
  1907. X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4),
  1908. X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725),
  1909. X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70),
  1910. X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926),
  1911. X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df),
  1912. X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8),
  1913. X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b),
  1914. X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001),
  1915. X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30),
  1916. X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910),
  1917. X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8),
  1918. X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53),
  1919. X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8),
  1920. X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb),
  1921. X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3),
  1922. X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60),
  1923. X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec),
  1924. X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9),
  1925. X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b),
  1926. X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207),
  1927. X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178),
  1928. X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6),
  1929. X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b),
  1930. X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493),
  1931. X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c),
  1932. X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a),
  1933. X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817)
  1934. ];
  1935. // Reusable objects
  1936. var W = [];
  1937. (function () {
  1938. for (var i = 0; i < 80; i++) {
  1939. W[i] = X64Word_create();
  1940. }
  1941. }());
  1942. /**
  1943. * SHA-512 hash algorithm.
  1944. */
  1945. var SHA512 = C_algo.SHA512 = Hasher.extend({
  1946. _doReset: function () {
  1947. this._hash = new X64WordArray.init([
  1948. new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b),
  1949. new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1),
  1950. new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f),
  1951. new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179)
  1952. ]);
  1953. },
  1954. _doProcessBlock: function (M, offset) {
  1955. // Shortcuts
  1956. var H = this._hash.words;
  1957. var H0 = H[0];
  1958. var H1 = H[1];
  1959. var H2 = H[2];
  1960. var H3 = H[3];
  1961. var H4 = H[4];
  1962. var H5 = H[5];
  1963. var H6 = H[6];
  1964. var H7 = H[7];
  1965. var H0h = H0.high;
  1966. var H0l = H0.low;
  1967. var H1h = H1.high;
  1968. var H1l = H1.low;
  1969. var H2h = H2.high;
  1970. var H2l = H2.low;
  1971. var H3h = H3.high;
  1972. var H3l = H3.low;
  1973. var H4h = H4.high;
  1974. var H4l = H4.low;
  1975. var H5h = H5.high;
  1976. var H5l = H5.low;
  1977. var H6h = H6.high;
  1978. var H6l = H6.low;
  1979. var H7h = H7.high;
  1980. var H7l = H7.low;
  1981. // Working variables
  1982. var ah = H0h;
  1983. var al = H0l;
  1984. var bh = H1h;
  1985. var bl = H1l;
  1986. var ch = H2h;
  1987. var cl = H2l;
  1988. var dh = H3h;
  1989. var dl = H3l;
  1990. var eh = H4h;
  1991. var el = H4l;
  1992. var fh = H5h;
  1993. var fl = H5l;
  1994. var gh = H6h;
  1995. var gl = H6l;
  1996. var hh = H7h;
  1997. var hl = H7l;
  1998. // Rounds
  1999. for (var i = 0; i < 80; i++) {
  2000. var Wil;
  2001. var Wih;
  2002. // Shortcut
  2003. var Wi = W[i];
  2004. // Extend message
  2005. if (i < 16) {
  2006. Wih = Wi.high = M[offset + i * 2] | 0;
  2007. Wil = Wi.low = M[offset + i * 2 + 1] | 0;
  2008. } else {
  2009. // Gamma0
  2010. var gamma0x = W[i - 15];
  2011. var gamma0xh = gamma0x.high;
  2012. var gamma0xl = gamma0x.low;
  2013. var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7);
  2014. var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25));
  2015. // Gamma1
  2016. var gamma1x = W[i - 2];
  2017. var gamma1xh = gamma1x.high;
  2018. var gamma1xl = gamma1x.low;
  2019. var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6);
  2020. var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26));
  2021. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  2022. var Wi7 = W[i - 7];
  2023. var Wi7h = Wi7.high;
  2024. var Wi7l = Wi7.low;
  2025. var Wi16 = W[i - 16];
  2026. var Wi16h = Wi16.high;
  2027. var Wi16l = Wi16.low;
  2028. Wil = gamma0l + Wi7l;
  2029. Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0);
  2030. Wil = Wil + gamma1l;
  2031. Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0);
  2032. Wil = Wil + Wi16l;
  2033. Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0);
  2034. Wi.high = Wih;
  2035. Wi.low = Wil;
  2036. }
  2037. var chh = (eh & fh) ^ (~eh & gh);
  2038. var chl = (el & fl) ^ (~el & gl);
  2039. var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch);
  2040. var majl = (al & bl) ^ (al & cl) ^ (bl & cl);
  2041. var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7));
  2042. var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7));
  2043. var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9));
  2044. var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9));
  2045. // t1 = h + sigma1 + ch + K[i] + W[i]
  2046. var Ki = K[i];
  2047. var Kih = Ki.high;
  2048. var Kil = Ki.low;
  2049. var t1l = hl + sigma1l;
  2050. var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0);
  2051. var t1l = t1l + chl;
  2052. var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0);
  2053. var t1l = t1l + Kil;
  2054. var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0);
  2055. var t1l = t1l + Wil;
  2056. var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0);
  2057. // t2 = sigma0 + maj
  2058. var t2l = sigma0l + majl;
  2059. var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0);
  2060. // Update working variables
  2061. hh = gh;
  2062. hl = gl;
  2063. gh = fh;
  2064. gl = fl;
  2065. fh = eh;
  2066. fl = el;
  2067. el = (dl + t1l) | 0;
  2068. eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0;
  2069. dh = ch;
  2070. dl = cl;
  2071. ch = bh;
  2072. cl = bl;
  2073. bh = ah;
  2074. bl = al;
  2075. al = (t1l + t2l) | 0;
  2076. ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0;
  2077. }
  2078. // Intermediate hash value
  2079. H0l = H0.low = (H0l + al);
  2080. H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0));
  2081. H1l = H1.low = (H1l + bl);
  2082. H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0));
  2083. H2l = H2.low = (H2l + cl);
  2084. H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0));
  2085. H3l = H3.low = (H3l + dl);
  2086. H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0));
  2087. H4l = H4.low = (H4l + el);
  2088. H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0));
  2089. H5l = H5.low = (H5l + fl);
  2090. H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0));
  2091. H6l = H6.low = (H6l + gl);
  2092. H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0));
  2093. H7l = H7.low = (H7l + hl);
  2094. H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0));
  2095. },
  2096. _doFinalize: function () {
  2097. // Shortcuts
  2098. var data = this._data;
  2099. var dataWords = data.words;
  2100. var nBitsTotal = this._nDataBytes * 8;
  2101. var nBitsLeft = data.sigBytes * 8;
  2102. // Add padding
  2103. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  2104. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000);
  2105. dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal;
  2106. data.sigBytes = dataWords.length * 4;
  2107. // Hash final blocks
  2108. this._process();
  2109. // Convert hash to 32-bit word array before returning
  2110. var hash = this._hash.toX32();
  2111. // Return final computed hash
  2112. return hash;
  2113. },
  2114. clone: function () {
  2115. var clone = Hasher.clone.call(this);
  2116. clone._hash = this._hash.clone();
  2117. return clone;
  2118. },
  2119. blockSize: 1024/32
  2120. });
  2121. /**
  2122. * Shortcut function to the hasher's object interface.
  2123. *
  2124. * @param {WordArray|string} message The message to hash.
  2125. *
  2126. * @return {WordArray} The hash.
  2127. *
  2128. * @static
  2129. *
  2130. * @example
  2131. *
  2132. * var hash = CryptoJS.SHA512('message');
  2133. * var hash = CryptoJS.SHA512(wordArray);
  2134. */
  2135. C.SHA512 = Hasher._createHelper(SHA512);
  2136. /**
  2137. * Shortcut function to the HMAC's object interface.
  2138. *
  2139. * @param {WordArray|string} message The message to hash.
  2140. * @param {WordArray|string} key The secret key.
  2141. *
  2142. * @return {WordArray} The HMAC.
  2143. *
  2144. * @static
  2145. *
  2146. * @example
  2147. *
  2148. * var hmac = CryptoJS.HmacSHA512(message, key);
  2149. */
  2150. C.HmacSHA512 = Hasher._createHmacHelper(SHA512);
  2151. }());
  2152. (function () {
  2153. // Shortcuts
  2154. var C = CryptoJS;
  2155. var C_x64 = C.x64;
  2156. var X64Word = C_x64.Word;
  2157. var X64WordArray = C_x64.WordArray;
  2158. var C_algo = C.algo;
  2159. var SHA512 = C_algo.SHA512;
  2160. /**
  2161. * SHA-384 hash algorithm.
  2162. */
  2163. var SHA384 = C_algo.SHA384 = SHA512.extend({
  2164. _doReset: function () {
  2165. this._hash = new X64WordArray.init([
  2166. new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507),
  2167. new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939),
  2168. new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511),
  2169. new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4)
  2170. ]);
  2171. },
  2172. _doFinalize: function () {
  2173. var hash = SHA512._doFinalize.call(this);
  2174. hash.sigBytes -= 16;
  2175. return hash;
  2176. }
  2177. });
  2178. /**
  2179. * Shortcut function to the hasher's object interface.
  2180. *
  2181. * @param {WordArray|string} message The message to hash.
  2182. *
  2183. * @return {WordArray} The hash.
  2184. *
  2185. * @static
  2186. *
  2187. * @example
  2188. *
  2189. * var hash = CryptoJS.SHA384('message');
  2190. * var hash = CryptoJS.SHA384(wordArray);
  2191. */
  2192. C.SHA384 = SHA512._createHelper(SHA384);
  2193. /**
  2194. * Shortcut function to the HMAC's object interface.
  2195. *
  2196. * @param {WordArray|string} message The message to hash.
  2197. * @param {WordArray|string} key The secret key.
  2198. *
  2199. * @return {WordArray} The HMAC.
  2200. *
  2201. * @static
  2202. *
  2203. * @example
  2204. *
  2205. * var hmac = CryptoJS.HmacSHA384(message, key);
  2206. */
  2207. C.HmacSHA384 = SHA512._createHmacHelper(SHA384);
  2208. }());
  2209. (function (Math) {
  2210. // Shortcuts
  2211. var C = CryptoJS;
  2212. var C_lib = C.lib;
  2213. var WordArray = C_lib.WordArray;
  2214. var Hasher = C_lib.Hasher;
  2215. var C_x64 = C.x64;
  2216. var X64Word = C_x64.Word;
  2217. var C_algo = C.algo;
  2218. // Constants tables
  2219. var RHO_OFFSETS = [];
  2220. var PI_INDEXES = [];
  2221. var ROUND_CONSTANTS = [];
  2222. // Compute Constants
  2223. (function () {
  2224. // Compute rho offset constants
  2225. var x = 1, y = 0;
  2226. for (var t = 0; t < 24; t++) {
  2227. RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64;
  2228. var newX = y % 5;
  2229. var newY = (2 * x + 3 * y) % 5;
  2230. x = newX;
  2231. y = newY;
  2232. }
  2233. // Compute pi index constants
  2234. for (var x = 0; x < 5; x++) {
  2235. for (var y = 0; y < 5; y++) {
  2236. PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5;
  2237. }
  2238. }
  2239. // Compute round constants
  2240. var LFSR = 0x01;
  2241. for (var i = 0; i < 24; i++) {
  2242. var roundConstantMsw = 0;
  2243. var roundConstantLsw = 0;
  2244. for (var j = 0; j < 7; j++) {
  2245. if (LFSR & 0x01) {
  2246. var bitPosition = (1 << j) - 1;
  2247. if (bitPosition < 32) {
  2248. roundConstantLsw ^= 1 << bitPosition;
  2249. } else /* if (bitPosition >= 32) */ {
  2250. roundConstantMsw ^= 1 << (bitPosition - 32);
  2251. }
  2252. }
  2253. // Compute next LFSR
  2254. if (LFSR & 0x80) {
  2255. // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1
  2256. LFSR = (LFSR << 1) ^ 0x71;
  2257. } else {
  2258. LFSR <<= 1;
  2259. }
  2260. }
  2261. ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw);
  2262. }
  2263. }());
  2264. // Reusable objects for temporary values
  2265. var T = [];
  2266. (function () {
  2267. for (var i = 0; i < 25; i++) {
  2268. T[i] = X64Word.create();
  2269. }
  2270. }());
  2271. /**
  2272. * SHA-3 hash algorithm.
  2273. */
  2274. var SHA3 = C_algo.SHA3 = Hasher.extend({
  2275. /**
  2276. * Configuration options.
  2277. *
  2278. * @property {number} outputLength
  2279. * The desired number of bits in the output hash.
  2280. * Only values permitted are: 224, 256, 384, 512.
  2281. * Default: 512
  2282. */
  2283. cfg: Hasher.cfg.extend({
  2284. outputLength: 512
  2285. }),
  2286. _doReset: function () {
  2287. var state = this._state = []
  2288. for (var i = 0; i < 25; i++) {
  2289. state[i] = new X64Word.init();
  2290. }
  2291. this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32;
  2292. },
  2293. _doProcessBlock: function (M, offset) {
  2294. // Shortcuts
  2295. var state = this._state;
  2296. var nBlockSizeLanes = this.blockSize / 2;
  2297. // Absorb
  2298. for (var i = 0; i < nBlockSizeLanes; i++) {
  2299. // Shortcuts
  2300. var M2i = M[offset + 2 * i];
  2301. var M2i1 = M[offset + 2 * i + 1];
  2302. // Swap endian
  2303. M2i = (
  2304. (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) |
  2305. (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00)
  2306. );
  2307. M2i1 = (
  2308. (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) |
  2309. (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00)
  2310. );
  2311. // Absorb message into state
  2312. var lane = state[i];
  2313. lane.high ^= M2i1;
  2314. lane.low ^= M2i;
  2315. }
  2316. // Rounds
  2317. for (var round = 0; round < 24; round++) {
  2318. // Theta
  2319. for (var x = 0; x < 5; x++) {
  2320. // Mix column lanes
  2321. var tMsw = 0, tLsw = 0;
  2322. for (var y = 0; y < 5; y++) {
  2323. var lane = state[x + 5 * y];
  2324. tMsw ^= lane.high;
  2325. tLsw ^= lane.low;
  2326. }
  2327. // Temporary values
  2328. var Tx = T[x];
  2329. Tx.high = tMsw;
  2330. Tx.low = tLsw;
  2331. }
  2332. for (var x = 0; x < 5; x++) {
  2333. // Shortcuts
  2334. var Tx4 = T[(x + 4) % 5];
  2335. var Tx1 = T[(x + 1) % 5];
  2336. var Tx1Msw = Tx1.high;
  2337. var Tx1Lsw = Tx1.low;
  2338. // Mix surrounding columns
  2339. var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31));
  2340. var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31));
  2341. for (var y = 0; y < 5; y++) {
  2342. var lane = state[x + 5 * y];
  2343. lane.high ^= tMsw;
  2344. lane.low ^= tLsw;
  2345. }
  2346. }
  2347. // Rho Pi
  2348. for (var laneIndex = 1; laneIndex < 25; laneIndex++) {
  2349. var tMsw;
  2350. var tLsw;
  2351. // Shortcuts
  2352. var lane = state[laneIndex];
  2353. var laneMsw = lane.high;
  2354. var laneLsw = lane.low;
  2355. var rhoOffset = RHO_OFFSETS[laneIndex];
  2356. // Rotate lanes
  2357. if (rhoOffset < 32) {
  2358. tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset));
  2359. tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset));
  2360. } else /* if (rhoOffset >= 32) */ {
  2361. tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset));
  2362. tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset));
  2363. }
  2364. // Transpose lanes
  2365. var TPiLane = T[PI_INDEXES[laneIndex]];
  2366. TPiLane.high = tMsw;
  2367. TPiLane.low = tLsw;
  2368. }
  2369. // Rho pi at x = y = 0
  2370. var T0 = T[0];
  2371. var state0 = state[0];
  2372. T0.high = state0.high;
  2373. T0.low = state0.low;
  2374. // Chi
  2375. for (var x = 0; x < 5; x++) {
  2376. for (var y = 0; y < 5; y++) {
  2377. // Shortcuts
  2378. var laneIndex = x + 5 * y;
  2379. var lane = state[laneIndex];
  2380. var TLane = T[laneIndex];
  2381. var Tx1Lane = T[((x + 1) % 5) + 5 * y];
  2382. var Tx2Lane = T[((x + 2) % 5) + 5 * y];
  2383. // Mix rows
  2384. lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high);
  2385. lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low);
  2386. }
  2387. }
  2388. // Iota
  2389. var lane = state[0];
  2390. var roundConstant = ROUND_CONSTANTS[round];
  2391. lane.high ^= roundConstant.high;
  2392. lane.low ^= roundConstant.low;
  2393. }
  2394. },
  2395. _doFinalize: function () {
  2396. // Shortcuts
  2397. var data = this._data;
  2398. var dataWords = data.words;
  2399. var nBitsTotal = this._nDataBytes * 8;
  2400. var nBitsLeft = data.sigBytes * 8;
  2401. var blockSizeBits = this.blockSize * 32;
  2402. // Add padding
  2403. dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32);
  2404. dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80;
  2405. data.sigBytes = dataWords.length * 4;
  2406. // Hash final blocks
  2407. this._process();
  2408. // Shortcuts
  2409. var state = this._state;
  2410. var outputLengthBytes = this.cfg.outputLength / 8;
  2411. var outputLengthLanes = outputLengthBytes / 8;
  2412. // Squeeze
  2413. var hashWords = [];
  2414. for (var i = 0; i < outputLengthLanes; i++) {
  2415. // Shortcuts
  2416. var lane = state[i];
  2417. var laneMsw = lane.high;
  2418. var laneLsw = lane.low;
  2419. // Swap endian
  2420. laneMsw = (
  2421. (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) |
  2422. (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00)
  2423. );
  2424. laneLsw = (
  2425. (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) |
  2426. (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00)
  2427. );
  2428. // Squeeze state to retrieve hash
  2429. hashWords.push(laneLsw);
  2430. hashWords.push(laneMsw);
  2431. }
  2432. // Return final computed hash
  2433. return new WordArray.init(hashWords, outputLengthBytes);
  2434. },
  2435. clone: function () {
  2436. var clone = Hasher.clone.call(this);
  2437. var state = clone._state = this._state.slice(0);
  2438. for (var i = 0; i < 25; i++) {
  2439. state[i] = state[i].clone();
  2440. }
  2441. return clone;
  2442. }
  2443. });
  2444. /**
  2445. * Shortcut function to the hasher's object interface.
  2446. *
  2447. * @param {WordArray|string} message The message to hash.
  2448. *
  2449. * @return {WordArray} The hash.
  2450. *
  2451. * @static
  2452. *
  2453. * @example
  2454. *
  2455. * var hash = CryptoJS.SHA3('message');
  2456. * var hash = CryptoJS.SHA3(wordArray);
  2457. */
  2458. C.SHA3 = Hasher._createHelper(SHA3);
  2459. /**
  2460. * Shortcut function to the HMAC's object interface.
  2461. *
  2462. * @param {WordArray|string} message The message to hash.
  2463. * @param {WordArray|string} key The secret key.
  2464. *
  2465. * @return {WordArray} The HMAC.
  2466. *
  2467. * @static
  2468. *
  2469. * @example
  2470. *
  2471. * var hmac = CryptoJS.HmacSHA3(message, key);
  2472. */
  2473. C.HmacSHA3 = Hasher._createHmacHelper(SHA3);
  2474. }(Math));
  2475. /** @preserve
  2476. (c) 2012 by Cédric Mesnil. All rights reserved.
  2477. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  2478. - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2479. - 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.
  2480. 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.
  2481. */
  2482. (function (Math) {
  2483. // Shortcuts
  2484. var C = CryptoJS;
  2485. var C_lib = C.lib;
  2486. var WordArray = C_lib.WordArray;
  2487. var Hasher = C_lib.Hasher;
  2488. var C_algo = C.algo;
  2489. // Constants table
  2490. var _zl = WordArray.create([
  2491. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  2492. 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
  2493. 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
  2494. 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
  2495. 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]);
  2496. var _zr = WordArray.create([
  2497. 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
  2498. 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
  2499. 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
  2500. 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
  2501. 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]);
  2502. var _sl = WordArray.create([
  2503. 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
  2504. 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
  2505. 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
  2506. 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
  2507. 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]);
  2508. var _sr = WordArray.create([
  2509. 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
  2510. 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
  2511. 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
  2512. 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
  2513. 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]);
  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 SHA256 = C_algo.SHA256;
  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: SHA256
  2814. * @property {number} iterations The number of iterations to perform. Default: 250000
  2815. */
  2816. cfg: Base.extend({
  2817. keySize: 128/32,
  2818. hasher: SHA256,
  2819. iterations: 250000
  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({ ciphertext: ciphertext, salt: salt });
  3562. }
  3563. };
  3564. /**
  3565. * A cipher wrapper that returns ciphertext as a serializable cipher params object.
  3566. */
  3567. var SerializableCipher = C_lib.SerializableCipher = Base.extend({
  3568. /**
  3569. * Configuration options.
  3570. *
  3571. * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
  3572. */
  3573. cfg: Base.extend({
  3574. format: OpenSSLFormatter
  3575. }),
  3576. /**
  3577. * Encrypts a message.
  3578. *
  3579. * @param {Cipher} cipher The cipher algorithm to use.
  3580. * @param {WordArray|string} message The message to encrypt.
  3581. * @param {WordArray} key The key.
  3582. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3583. *
  3584. * @return {CipherParams} A cipher params object.
  3585. *
  3586. * @static
  3587. *
  3588. * @example
  3589. *
  3590. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
  3591. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
  3592. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  3593. */
  3594. encrypt: function (cipher, message, key, cfg) {
  3595. // Apply config defaults
  3596. cfg = this.cfg.extend(cfg);
  3597. // Encrypt
  3598. var encryptor = cipher.createEncryptor(key, cfg);
  3599. var ciphertext = encryptor.finalize(message);
  3600. // Shortcut
  3601. var cipherCfg = encryptor.cfg;
  3602. // Create and return serializable cipher params
  3603. return CipherParams.create({
  3604. ciphertext: ciphertext,
  3605. key: key,
  3606. iv: cipherCfg.iv,
  3607. algorithm: cipher,
  3608. mode: cipherCfg.mode,
  3609. padding: cipherCfg.padding,
  3610. blockSize: cipher.blockSize,
  3611. formatter: cfg.format
  3612. });
  3613. },
  3614. /**
  3615. * Decrypts serialized ciphertext.
  3616. *
  3617. * @param {Cipher} cipher The cipher algorithm to use.
  3618. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  3619. * @param {WordArray} key The key.
  3620. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3621. *
  3622. * @return {WordArray} The plaintext.
  3623. *
  3624. * @static
  3625. *
  3626. * @example
  3627. *
  3628. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  3629. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  3630. */
  3631. decrypt: function (cipher, ciphertext, key, cfg) {
  3632. // Apply config defaults
  3633. cfg = this.cfg.extend(cfg);
  3634. // Convert string to CipherParams
  3635. ciphertext = this._parse(ciphertext, cfg.format);
  3636. // Decrypt
  3637. var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
  3638. return plaintext;
  3639. },
  3640. /**
  3641. * Converts serialized ciphertext to CipherParams,
  3642. * else assumed CipherParams already and returns ciphertext unchanged.
  3643. *
  3644. * @param {CipherParams|string} ciphertext The ciphertext.
  3645. * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
  3646. *
  3647. * @return {CipherParams} The unserialized ciphertext.
  3648. *
  3649. * @static
  3650. *
  3651. * @example
  3652. *
  3653. * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
  3654. */
  3655. _parse: function (ciphertext, format) {
  3656. if (typeof ciphertext == 'string') {
  3657. return format.parse(ciphertext, this);
  3658. } else {
  3659. return ciphertext;
  3660. }
  3661. }
  3662. });
  3663. /**
  3664. * Key derivation function namespace.
  3665. */
  3666. var C_kdf = C.kdf = {};
  3667. /**
  3668. * OpenSSL key derivation function.
  3669. */
  3670. var OpenSSLKdf = C_kdf.OpenSSL = {
  3671. /**
  3672. * Derives a key and IV from a password.
  3673. *
  3674. * @param {string} password The password to derive from.
  3675. * @param {number} keySize The size in words of the key to generate.
  3676. * @param {number} ivSize The size in words of the IV to generate.
  3677. * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
  3678. *
  3679. * @return {CipherParams} A cipher params object with the key, IV, and salt.
  3680. *
  3681. * @static
  3682. *
  3683. * @example
  3684. *
  3685. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
  3686. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
  3687. */
  3688. execute: function (password, keySize, ivSize, salt, hasher) {
  3689. // Generate random salt
  3690. if (!salt) {
  3691. salt = WordArray.random(64/8);
  3692. }
  3693. // Derive key and IV
  3694. if (!hasher) {
  3695. var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
  3696. } else {
  3697. var key = EvpKDF.create({ keySize: keySize + ivSize, hasher: hasher }).compute(password, salt);
  3698. }
  3699. // Separate key and IV
  3700. var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
  3701. key.sigBytes = keySize * 4;
  3702. // Return params
  3703. return CipherParams.create({ key: key, iv: iv, salt: salt });
  3704. }
  3705. };
  3706. /**
  3707. * A serializable cipher wrapper that derives the key from a password,
  3708. * and returns ciphertext as a serializable cipher params object.
  3709. */
  3710. var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
  3711. /**
  3712. * Configuration options.
  3713. *
  3714. * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
  3715. */
  3716. cfg: SerializableCipher.cfg.extend({
  3717. kdf: OpenSSLKdf
  3718. }),
  3719. /**
  3720. * Encrypts a message using a password.
  3721. *
  3722. * @param {Cipher} cipher The cipher algorithm to use.
  3723. * @param {WordArray|string} message The message to encrypt.
  3724. * @param {string} password The password.
  3725. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3726. *
  3727. * @return {CipherParams} A cipher params object.
  3728. *
  3729. * @static
  3730. *
  3731. * @example
  3732. *
  3733. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
  3734. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
  3735. */
  3736. encrypt: function (cipher, message, password, cfg) {
  3737. // Apply config defaults
  3738. cfg = this.cfg.extend(cfg);
  3739. // Derive key and other params
  3740. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, cfg.salt, cfg.hasher);
  3741. // Add IV to config
  3742. cfg.iv = derivedParams.iv;
  3743. // Encrypt
  3744. var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
  3745. // Mix in derived params
  3746. ciphertext.mixIn(derivedParams);
  3747. return ciphertext;
  3748. },
  3749. /**
  3750. * Decrypts serialized ciphertext using a password.
  3751. *
  3752. * @param {Cipher} cipher The cipher algorithm to use.
  3753. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  3754. * @param {string} password The password.
  3755. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3756. *
  3757. * @return {WordArray} The plaintext.
  3758. *
  3759. * @static
  3760. *
  3761. * @example
  3762. *
  3763. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
  3764. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
  3765. */
  3766. decrypt: function (cipher, ciphertext, password, cfg) {
  3767. // Apply config defaults
  3768. cfg = this.cfg.extend(cfg);
  3769. // Convert string to CipherParams
  3770. ciphertext = this._parse(ciphertext, cfg.format);
  3771. // Derive key and other params
  3772. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt, cfg.hasher);
  3773. // Add IV to config
  3774. cfg.iv = derivedParams.iv;
  3775. // Decrypt
  3776. var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
  3777. return plaintext;
  3778. }
  3779. });
  3780. }());
  3781. /**
  3782. * Cipher Feedback block mode.
  3783. */
  3784. CryptoJS.mode.CFB = (function () {
  3785. var CFB = CryptoJS.lib.BlockCipherMode.extend();
  3786. CFB.Encryptor = CFB.extend({
  3787. processBlock: function (words, offset) {
  3788. // Shortcuts
  3789. var cipher = this._cipher;
  3790. var blockSize = cipher.blockSize;
  3791. generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  3792. // Remember this block to use with next block
  3793. this._prevBlock = words.slice(offset, offset + blockSize);
  3794. }
  3795. });
  3796. CFB.Decryptor = CFB.extend({
  3797. processBlock: function (words, offset) {
  3798. // Shortcuts
  3799. var cipher = this._cipher;
  3800. var blockSize = cipher.blockSize;
  3801. // Remember this block to use with next block
  3802. var thisBlock = words.slice(offset, offset + blockSize);
  3803. generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
  3804. // This block becomes the previous block
  3805. this._prevBlock = thisBlock;
  3806. }
  3807. });
  3808. function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
  3809. var keystream;
  3810. // Shortcut
  3811. var iv = this._iv;
  3812. // Generate keystream
  3813. if (iv) {
  3814. keystream = iv.slice(0);
  3815. // Remove IV for subsequent blocks
  3816. this._iv = undefined;
  3817. } else {
  3818. keystream = this._prevBlock;
  3819. }
  3820. cipher.encryptBlock(keystream, 0);
  3821. // Encrypt
  3822. for (var i = 0; i < blockSize; i++) {
  3823. words[offset + i] ^= keystream[i];
  3824. }
  3825. }
  3826. return CFB;
  3827. }());
  3828. /**
  3829. * Counter block mode.
  3830. */
  3831. CryptoJS.mode.CTR = (function () {
  3832. var CTR = CryptoJS.lib.BlockCipherMode.extend();
  3833. var Encryptor = CTR.Encryptor = CTR.extend({
  3834. processBlock: function (words, offset) {
  3835. // Shortcuts
  3836. var cipher = this._cipher
  3837. var blockSize = cipher.blockSize;
  3838. var iv = this._iv;
  3839. var counter = this._counter;
  3840. // Generate keystream
  3841. if (iv) {
  3842. counter = this._counter = iv.slice(0);
  3843. // Remove IV for subsequent blocks
  3844. this._iv = undefined;
  3845. }
  3846. var keystream = counter.slice(0);
  3847. cipher.encryptBlock(keystream, 0);
  3848. // Increment counter
  3849. counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0
  3850. // Encrypt
  3851. for (var i = 0; i < blockSize; i++) {
  3852. words[offset + i] ^= keystream[i];
  3853. }
  3854. }
  3855. });
  3856. CTR.Decryptor = Encryptor;
  3857. return CTR;
  3858. }());
  3859. /** @preserve
  3860. * Counter block mode compatible with Dr Brian Gladman fileenc.c
  3861. * derived from CryptoJS.mode.CTR
  3862. * Jan Hruby jhruby.web@gmail.com
  3863. */
  3864. CryptoJS.mode.CTRGladman = (function () {
  3865. var CTRGladman = CryptoJS.lib.BlockCipherMode.extend();
  3866. function incWord(word)
  3867. {
  3868. if (((word >> 24) & 0xff) === 0xff) { //overflow
  3869. var b1 = (word >> 16)&0xff;
  3870. var b2 = (word >> 8)&0xff;
  3871. var b3 = word & 0xff;
  3872. if (b1 === 0xff) // overflow b1
  3873. {
  3874. b1 = 0;
  3875. if (b2 === 0xff)
  3876. {
  3877. b2 = 0;
  3878. if (b3 === 0xff)
  3879. {
  3880. b3 = 0;
  3881. }
  3882. else
  3883. {
  3884. ++b3;
  3885. }
  3886. }
  3887. else
  3888. {
  3889. ++b2;
  3890. }
  3891. }
  3892. else
  3893. {
  3894. ++b1;
  3895. }
  3896. word = 0;
  3897. word += (b1 << 16);
  3898. word += (b2 << 8);
  3899. word += b3;
  3900. }
  3901. else
  3902. {
  3903. word += (0x01 << 24);
  3904. }
  3905. return word;
  3906. }
  3907. function incCounter(counter)
  3908. {
  3909. if ((counter[0] = incWord(counter[0])) === 0)
  3910. {
  3911. // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
  3912. counter[1] = incWord(counter[1]);
  3913. }
  3914. return counter;
  3915. }
  3916. var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({
  3917. processBlock: function (words, offset) {
  3918. // Shortcuts
  3919. var cipher = this._cipher
  3920. var blockSize = cipher.blockSize;
  3921. var iv = this._iv;
  3922. var counter = this._counter;
  3923. // Generate keystream
  3924. if (iv) {
  3925. counter = this._counter = iv.slice(0);
  3926. // Remove IV for subsequent blocks
  3927. this._iv = undefined;
  3928. }
  3929. incCounter(counter);
  3930. var keystream = counter.slice(0);
  3931. cipher.encryptBlock(keystream, 0);
  3932. // Encrypt
  3933. for (var i = 0; i < blockSize; i++) {
  3934. words[offset + i] ^= keystream[i];
  3935. }
  3936. }
  3937. });
  3938. CTRGladman.Decryptor = Encryptor;
  3939. return CTRGladman;
  3940. }());
  3941. /**
  3942. * Output Feedback block mode.
  3943. */
  3944. CryptoJS.mode.OFB = (function () {
  3945. var OFB = CryptoJS.lib.BlockCipherMode.extend();
  3946. var Encryptor = OFB.Encryptor = OFB.extend({
  3947. processBlock: function (words, offset) {
  3948. // Shortcuts
  3949. var cipher = this._cipher
  3950. var blockSize = cipher.blockSize;
  3951. var iv = this._iv;
  3952. var keystream = this._keystream;
  3953. // Generate keystream
  3954. if (iv) {
  3955. keystream = this._keystream = iv.slice(0);
  3956. // Remove IV for subsequent blocks
  3957. this._iv = undefined;
  3958. }
  3959. cipher.encryptBlock(keystream, 0);
  3960. // Encrypt
  3961. for (var i = 0; i < blockSize; i++) {
  3962. words[offset + i] ^= keystream[i];
  3963. }
  3964. }
  3965. });
  3966. OFB.Decryptor = Encryptor;
  3967. return OFB;
  3968. }());
  3969. /**
  3970. * Electronic Codebook block mode.
  3971. */
  3972. CryptoJS.mode.ECB = (function () {
  3973. var ECB = CryptoJS.lib.BlockCipherMode.extend();
  3974. ECB.Encryptor = ECB.extend({
  3975. processBlock: function (words, offset) {
  3976. this._cipher.encryptBlock(words, offset);
  3977. }
  3978. });
  3979. ECB.Decryptor = ECB.extend({
  3980. processBlock: function (words, offset) {
  3981. this._cipher.decryptBlock(words, offset);
  3982. }
  3983. });
  3984. return ECB;
  3985. }());
  3986. /**
  3987. * ANSI X.923 padding strategy.
  3988. */
  3989. CryptoJS.pad.AnsiX923 = {
  3990. pad: function (data, blockSize) {
  3991. // Shortcuts
  3992. var dataSigBytes = data.sigBytes;
  3993. var blockSizeBytes = blockSize * 4;
  3994. // Count padding bytes
  3995. var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes;
  3996. // Compute last byte position
  3997. var lastBytePos = dataSigBytes + nPaddingBytes - 1;
  3998. // Pad
  3999. data.clamp();
  4000. data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8);
  4001. data.sigBytes += nPaddingBytes;
  4002. },
  4003. unpad: function (data) {
  4004. // Get number of padding bytes from last byte
  4005. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  4006. // Remove padding
  4007. data.sigBytes -= nPaddingBytes;
  4008. }
  4009. };
  4010. /**
  4011. * ISO 10126 padding strategy.
  4012. */
  4013. CryptoJS.pad.Iso10126 = {
  4014. pad: function (data, blockSize) {
  4015. // Shortcut
  4016. var blockSizeBytes = blockSize * 4;
  4017. // Count padding bytes
  4018. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  4019. // Pad
  4020. data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)).
  4021. concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
  4022. },
  4023. unpad: function (data) {
  4024. // Get number of padding bytes from last byte
  4025. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  4026. // Remove padding
  4027. data.sigBytes -= nPaddingBytes;
  4028. }
  4029. };
  4030. /**
  4031. * ISO/IEC 9797-1 Padding Method 2.
  4032. */
  4033. CryptoJS.pad.Iso97971 = {
  4034. pad: function (data, blockSize) {
  4035. // Add 0x80 byte
  4036. data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1));
  4037. // Zero pad the rest
  4038. CryptoJS.pad.ZeroPadding.pad(data, blockSize);
  4039. },
  4040. unpad: function (data) {
  4041. // Remove zero padding
  4042. CryptoJS.pad.ZeroPadding.unpad(data);
  4043. // Remove one more byte -- the 0x80 byte
  4044. data.sigBytes--;
  4045. }
  4046. };
  4047. /**
  4048. * Zero padding strategy.
  4049. */
  4050. CryptoJS.pad.ZeroPadding = {
  4051. pad: function (data, blockSize) {
  4052. // Shortcut
  4053. var blockSizeBytes = blockSize * 4;
  4054. // Pad
  4055. data.clamp();
  4056. data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes);
  4057. },
  4058. unpad: function (data) {
  4059. // Shortcut
  4060. var dataWords = data.words;
  4061. // Unpad
  4062. var i = data.sigBytes - 1;
  4063. for (var i = data.sigBytes - 1; i >= 0; i--) {
  4064. if (((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) {
  4065. data.sigBytes = i + 1;
  4066. break;
  4067. }
  4068. }
  4069. }
  4070. };
  4071. /**
  4072. * A noop padding strategy.
  4073. */
  4074. CryptoJS.pad.NoPadding = {
  4075. pad: function () {
  4076. },
  4077. unpad: function () {
  4078. }
  4079. };
  4080. (function (undefined) {
  4081. // Shortcuts
  4082. var C = CryptoJS;
  4083. var C_lib = C.lib;
  4084. var CipherParams = C_lib.CipherParams;
  4085. var C_enc = C.enc;
  4086. var Hex = C_enc.Hex;
  4087. var C_format = C.format;
  4088. var HexFormatter = C_format.Hex = {
  4089. /**
  4090. * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
  4091. *
  4092. * @param {CipherParams} cipherParams The cipher params object.
  4093. *
  4094. * @return {string} The hexadecimally encoded string.
  4095. *
  4096. * @static
  4097. *
  4098. * @example
  4099. *
  4100. * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
  4101. */
  4102. stringify: function (cipherParams) {
  4103. return cipherParams.ciphertext.toString(Hex);
  4104. },
  4105. /**
  4106. * Converts a hexadecimally encoded ciphertext string to a cipher params object.
  4107. *
  4108. * @param {string} input The hexadecimally encoded string.
  4109. *
  4110. * @return {CipherParams} The cipher params object.
  4111. *
  4112. * @static
  4113. *
  4114. * @example
  4115. *
  4116. * var cipherParams = CryptoJS.format.Hex.parse(hexString);
  4117. */
  4118. parse: function (input) {
  4119. var ciphertext = Hex.parse(input);
  4120. return CipherParams.create({ ciphertext: ciphertext });
  4121. }
  4122. };
  4123. }());
  4124. (function () {
  4125. // Shortcuts
  4126. var C = CryptoJS;
  4127. var C_lib = C.lib;
  4128. var BlockCipher = C_lib.BlockCipher;
  4129. var C_algo = C.algo;
  4130. // Lookup tables
  4131. var SBOX = [];
  4132. var INV_SBOX = [];
  4133. var SUB_MIX_0 = [];
  4134. var SUB_MIX_1 = [];
  4135. var SUB_MIX_2 = [];
  4136. var SUB_MIX_3 = [];
  4137. var INV_SUB_MIX_0 = [];
  4138. var INV_SUB_MIX_1 = [];
  4139. var INV_SUB_MIX_2 = [];
  4140. var INV_SUB_MIX_3 = [];
  4141. // Compute lookup tables
  4142. (function () {
  4143. // Compute double table
  4144. var d = [];
  4145. for (var i = 0; i < 256; i++) {
  4146. if (i < 128) {
  4147. d[i] = i << 1;
  4148. } else {
  4149. d[i] = (i << 1) ^ 0x11b;
  4150. }
  4151. }
  4152. // Walk GF(2^8)
  4153. var x = 0;
  4154. var xi = 0;
  4155. for (var i = 0; i < 256; i++) {
  4156. // Compute sbox
  4157. var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
  4158. sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
  4159. SBOX[x] = sx;
  4160. INV_SBOX[sx] = x;
  4161. // Compute multiplication
  4162. var x2 = d[x];
  4163. var x4 = d[x2];
  4164. var x8 = d[x4];
  4165. // Compute sub bytes, mix columns tables
  4166. var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
  4167. SUB_MIX_0[x] = (t << 24) | (t >>> 8);
  4168. SUB_MIX_1[x] = (t << 16) | (t >>> 16);
  4169. SUB_MIX_2[x] = (t << 8) | (t >>> 24);
  4170. SUB_MIX_3[x] = t;
  4171. // Compute inv sub bytes, inv mix columns tables
  4172. var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
  4173. INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
  4174. INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
  4175. INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
  4176. INV_SUB_MIX_3[sx] = t;
  4177. // Compute next counter
  4178. if (!x) {
  4179. x = xi = 1;
  4180. } else {
  4181. x = x2 ^ d[d[d[x8 ^ x2]]];
  4182. xi ^= d[d[xi]];
  4183. }
  4184. }
  4185. }());
  4186. // Precomputed Rcon lookup
  4187. var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
  4188. /**
  4189. * AES block cipher algorithm.
  4190. */
  4191. var AES = C_algo.AES = BlockCipher.extend({
  4192. _doReset: function () {
  4193. var t;
  4194. // Skip reset of nRounds has been set before and key did not change
  4195. if (this._nRounds && this._keyPriorReset === this._key) {
  4196. return;
  4197. }
  4198. // Shortcuts
  4199. var key = this._keyPriorReset = this._key;
  4200. var keyWords = key.words;
  4201. var keySize = key.sigBytes / 4;
  4202. // Compute number of rounds
  4203. var nRounds = this._nRounds = keySize + 6;
  4204. // Compute number of key schedule rows
  4205. var ksRows = (nRounds + 1) * 4;
  4206. // Compute key schedule
  4207. var keySchedule = this._keySchedule = [];
  4208. for (var ksRow = 0; ksRow < ksRows; ksRow++) {
  4209. if (ksRow < keySize) {
  4210. keySchedule[ksRow] = keyWords[ksRow];
  4211. } else {
  4212. t = keySchedule[ksRow - 1];
  4213. if (!(ksRow % keySize)) {
  4214. // Rot word
  4215. t = (t << 8) | (t >>> 24);
  4216. // Sub word
  4217. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  4218. // Mix Rcon
  4219. t ^= RCON[(ksRow / keySize) | 0] << 24;
  4220. } else if (keySize > 6 && ksRow % keySize == 4) {
  4221. // Sub word
  4222. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  4223. }
  4224. keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
  4225. }
  4226. }
  4227. // Compute inv key schedule
  4228. var invKeySchedule = this._invKeySchedule = [];
  4229. for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
  4230. var ksRow = ksRows - invKsRow;
  4231. if (invKsRow % 4) {
  4232. var t = keySchedule[ksRow];
  4233. } else {
  4234. var t = keySchedule[ksRow - 4];
  4235. }
  4236. if (invKsRow < 4 || ksRow <= 4) {
  4237. invKeySchedule[invKsRow] = t;
  4238. } else {
  4239. invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
  4240. INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
  4241. }
  4242. }
  4243. },
  4244. encryptBlock: function (M, offset) {
  4245. this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
  4246. },
  4247. decryptBlock: function (M, offset) {
  4248. // Swap 2nd and 4th rows
  4249. var t = M[offset + 1];
  4250. M[offset + 1] = M[offset + 3];
  4251. M[offset + 3] = t;
  4252. this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
  4253. // Inv swap 2nd and 4th rows
  4254. var t = M[offset + 1];
  4255. M[offset + 1] = M[offset + 3];
  4256. M[offset + 3] = t;
  4257. },
  4258. _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
  4259. // Shortcut
  4260. var nRounds = this._nRounds;
  4261. // Get input, add round key
  4262. var s0 = M[offset] ^ keySchedule[0];
  4263. var s1 = M[offset + 1] ^ keySchedule[1];
  4264. var s2 = M[offset + 2] ^ keySchedule[2];
  4265. var s3 = M[offset + 3] ^ keySchedule[3];
  4266. // Key schedule row counter
  4267. var ksRow = 4;
  4268. // Rounds
  4269. for (var round = 1; round < nRounds; round++) {
  4270. // Shift rows, sub bytes, mix columns, add round key
  4271. 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++];
  4272. 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++];
  4273. 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++];
  4274. 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++];
  4275. // Update state
  4276. s0 = t0;
  4277. s1 = t1;
  4278. s2 = t2;
  4279. s3 = t3;
  4280. }
  4281. // Shift rows, sub bytes, add round key
  4282. var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
  4283. var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
  4284. var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
  4285. var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
  4286. // Set output
  4287. M[offset] = t0;
  4288. M[offset + 1] = t1;
  4289. M[offset + 2] = t2;
  4290. M[offset + 3] = t3;
  4291. },
  4292. keySize: 256/32
  4293. });
  4294. /**
  4295. * Shortcut functions to the cipher's object interface.
  4296. *
  4297. * @example
  4298. *
  4299. * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
  4300. * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
  4301. */
  4302. C.AES = BlockCipher._createHelper(AES);
  4303. }());
  4304. (function () {
  4305. // Shortcuts
  4306. var C = CryptoJS;
  4307. var C_lib = C.lib;
  4308. var WordArray = C_lib.WordArray;
  4309. var BlockCipher = C_lib.BlockCipher;
  4310. var C_algo = C.algo;
  4311. // Permuted Choice 1 constants
  4312. var PC1 = [
  4313. 57, 49, 41, 33, 25, 17, 9, 1,
  4314. 58, 50, 42, 34, 26, 18, 10, 2,
  4315. 59, 51, 43, 35, 27, 19, 11, 3,
  4316. 60, 52, 44, 36, 63, 55, 47, 39,
  4317. 31, 23, 15, 7, 62, 54, 46, 38,
  4318. 30, 22, 14, 6, 61, 53, 45, 37,
  4319. 29, 21, 13, 5, 28, 20, 12, 4
  4320. ];
  4321. // Permuted Choice 2 constants
  4322. var PC2 = [
  4323. 14, 17, 11, 24, 1, 5,
  4324. 3, 28, 15, 6, 21, 10,
  4325. 23, 19, 12, 4, 26, 8,
  4326. 16, 7, 27, 20, 13, 2,
  4327. 41, 52, 31, 37, 47, 55,
  4328. 30, 40, 51, 45, 33, 48,
  4329. 44, 49, 39, 56, 34, 53,
  4330. 46, 42, 50, 36, 29, 32
  4331. ];
  4332. // Cumulative bit shift constants
  4333. var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28];
  4334. // SBOXes and round permutation constants
  4335. var SBOX_P = [
  4336. {
  4337. 0x0: 0x808200,
  4338. 0x10000000: 0x8000,
  4339. 0x20000000: 0x808002,
  4340. 0x30000000: 0x2,
  4341. 0x40000000: 0x200,
  4342. 0x50000000: 0x808202,
  4343. 0x60000000: 0x800202,
  4344. 0x70000000: 0x800000,
  4345. 0x80000000: 0x202,
  4346. 0x90000000: 0x800200,
  4347. 0xa0000000: 0x8200,
  4348. 0xb0000000: 0x808000,
  4349. 0xc0000000: 0x8002,
  4350. 0xd0000000: 0x800002,
  4351. 0xe0000000: 0x0,
  4352. 0xf0000000: 0x8202,
  4353. 0x8000000: 0x0,
  4354. 0x18000000: 0x808202,
  4355. 0x28000000: 0x8202,
  4356. 0x38000000: 0x8000,
  4357. 0x48000000: 0x808200,
  4358. 0x58000000: 0x200,
  4359. 0x68000000: 0x808002,
  4360. 0x78000000: 0x2,
  4361. 0x88000000: 0x800200,
  4362. 0x98000000: 0x8200,
  4363. 0xa8000000: 0x808000,
  4364. 0xb8000000: 0x800202,
  4365. 0xc8000000: 0x800002,
  4366. 0xd8000000: 0x8002,
  4367. 0xe8000000: 0x202,
  4368. 0xf8000000: 0x800000,
  4369. 0x1: 0x8000,
  4370. 0x10000001: 0x2,
  4371. 0x20000001: 0x808200,
  4372. 0x30000001: 0x800000,
  4373. 0x40000001: 0x808002,
  4374. 0x50000001: 0x8200,
  4375. 0x60000001: 0x200,
  4376. 0x70000001: 0x800202,
  4377. 0x80000001: 0x808202,
  4378. 0x90000001: 0x808000,
  4379. 0xa0000001: 0x800002,
  4380. 0xb0000001: 0x8202,
  4381. 0xc0000001: 0x202,
  4382. 0xd0000001: 0x800200,
  4383. 0xe0000001: 0x8002,
  4384. 0xf0000001: 0x0,
  4385. 0x8000001: 0x808202,
  4386. 0x18000001: 0x808000,
  4387. 0x28000001: 0x800000,
  4388. 0x38000001: 0x200,
  4389. 0x48000001: 0x8000,
  4390. 0x58000001: 0x800002,
  4391. 0x68000001: 0x2,
  4392. 0x78000001: 0x8202,
  4393. 0x88000001: 0x8002,
  4394. 0x98000001: 0x800202,
  4395. 0xa8000001: 0x202,
  4396. 0xb8000001: 0x808200,
  4397. 0xc8000001: 0x800200,
  4398. 0xd8000001: 0x0,
  4399. 0xe8000001: 0x8200,
  4400. 0xf8000001: 0x808002
  4401. },
  4402. {
  4403. 0x0: 0x40084010,
  4404. 0x1000000: 0x4000,
  4405. 0x2000000: 0x80000,
  4406. 0x3000000: 0x40080010,
  4407. 0x4000000: 0x40000010,
  4408. 0x5000000: 0x40084000,
  4409. 0x6000000: 0x40004000,
  4410. 0x7000000: 0x10,
  4411. 0x8000000: 0x84000,
  4412. 0x9000000: 0x40004010,
  4413. 0xa000000: 0x40000000,
  4414. 0xb000000: 0x84010,
  4415. 0xc000000: 0x80010,
  4416. 0xd000000: 0x0,
  4417. 0xe000000: 0x4010,
  4418. 0xf000000: 0x40080000,
  4419. 0x800000: 0x40004000,
  4420. 0x1800000: 0x84010,
  4421. 0x2800000: 0x10,
  4422. 0x3800000: 0x40004010,
  4423. 0x4800000: 0x40084010,
  4424. 0x5800000: 0x40000000,
  4425. 0x6800000: 0x80000,
  4426. 0x7800000: 0x40080010,
  4427. 0x8800000: 0x80010,
  4428. 0x9800000: 0x0,
  4429. 0xa800000: 0x4000,
  4430. 0xb800000: 0x40080000,
  4431. 0xc800000: 0x40000010,
  4432. 0xd800000: 0x84000,
  4433. 0xe800000: 0x40084000,
  4434. 0xf800000: 0x4010,
  4435. 0x10000000: 0x0,
  4436. 0x11000000: 0x40080010,
  4437. 0x12000000: 0x40004010,
  4438. 0x13000000: 0x40084000,
  4439. 0x14000000: 0x40080000,
  4440. 0x15000000: 0x10,
  4441. 0x16000000: 0x84010,
  4442. 0x17000000: 0x4000,
  4443. 0x18000000: 0x4010,
  4444. 0x19000000: 0x80000,
  4445. 0x1a000000: 0x80010,
  4446. 0x1b000000: 0x40000010,
  4447. 0x1c000000: 0x84000,
  4448. 0x1d000000: 0x40004000,
  4449. 0x1e000000: 0x40000000,
  4450. 0x1f000000: 0x40084010,
  4451. 0x10800000: 0x84010,
  4452. 0x11800000: 0x80000,
  4453. 0x12800000: 0x40080000,
  4454. 0x13800000: 0x4000,
  4455. 0x14800000: 0x40004000,
  4456. 0x15800000: 0x40084010,
  4457. 0x16800000: 0x10,
  4458. 0x17800000: 0x40000000,
  4459. 0x18800000: 0x40084000,
  4460. 0x19800000: 0x40000010,
  4461. 0x1a800000: 0x40004010,
  4462. 0x1b800000: 0x80010,
  4463. 0x1c800000: 0x0,
  4464. 0x1d800000: 0x4010,
  4465. 0x1e800000: 0x40080010,
  4466. 0x1f800000: 0x84000
  4467. },
  4468. {
  4469. 0x0: 0x104,
  4470. 0x100000: 0x0,
  4471. 0x200000: 0x4000100,
  4472. 0x300000: 0x10104,
  4473. 0x400000: 0x10004,
  4474. 0x500000: 0x4000004,
  4475. 0x600000: 0x4010104,
  4476. 0x700000: 0x4010000,
  4477. 0x800000: 0x4000000,
  4478. 0x900000: 0x4010100,
  4479. 0xa00000: 0x10100,
  4480. 0xb00000: 0x4010004,
  4481. 0xc00000: 0x4000104,
  4482. 0xd00000: 0x10000,
  4483. 0xe00000: 0x4,
  4484. 0xf00000: 0x100,
  4485. 0x80000: 0x4010100,
  4486. 0x180000: 0x4010004,
  4487. 0x280000: 0x0,
  4488. 0x380000: 0x4000100,
  4489. 0x480000: 0x4000004,
  4490. 0x580000: 0x10000,
  4491. 0x680000: 0x10004,
  4492. 0x780000: 0x104,
  4493. 0x880000: 0x4,
  4494. 0x980000: 0x100,
  4495. 0xa80000: 0x4010000,
  4496. 0xb80000: 0x10104,
  4497. 0xc80000: 0x10100,
  4498. 0xd80000: 0x4000104,
  4499. 0xe80000: 0x4010104,
  4500. 0xf80000: 0x4000000,
  4501. 0x1000000: 0x4010100,
  4502. 0x1100000: 0x10004,
  4503. 0x1200000: 0x10000,
  4504. 0x1300000: 0x4000100,
  4505. 0x1400000: 0x100,
  4506. 0x1500000: 0x4010104,
  4507. 0x1600000: 0x4000004,
  4508. 0x1700000: 0x0,
  4509. 0x1800000: 0x4000104,
  4510. 0x1900000: 0x4000000,
  4511. 0x1a00000: 0x4,
  4512. 0x1b00000: 0x10100,
  4513. 0x1c00000: 0x4010000,
  4514. 0x1d00000: 0x104,
  4515. 0x1e00000: 0x10104,
  4516. 0x1f00000: 0x4010004,
  4517. 0x1080000: 0x4000000,
  4518. 0x1180000: 0x104,
  4519. 0x1280000: 0x4010100,
  4520. 0x1380000: 0x0,
  4521. 0x1480000: 0x10004,
  4522. 0x1580000: 0x4000100,
  4523. 0x1680000: 0x100,
  4524. 0x1780000: 0x4010004,
  4525. 0x1880000: 0x10000,
  4526. 0x1980000: 0x4010104,
  4527. 0x1a80000: 0x10104,
  4528. 0x1b80000: 0x4000004,
  4529. 0x1c80000: 0x4000104,
  4530. 0x1d80000: 0x4010000,
  4531. 0x1e80000: 0x4,
  4532. 0x1f80000: 0x10100
  4533. },
  4534. {
  4535. 0x0: 0x80401000,
  4536. 0x10000: 0x80001040,
  4537. 0x20000: 0x401040,
  4538. 0x30000: 0x80400000,
  4539. 0x40000: 0x0,
  4540. 0x50000: 0x401000,
  4541. 0x60000: 0x80000040,
  4542. 0x70000: 0x400040,
  4543. 0x80000: 0x80000000,
  4544. 0x90000: 0x400000,
  4545. 0xa0000: 0x40,
  4546. 0xb0000: 0x80001000,
  4547. 0xc0000: 0x80400040,
  4548. 0xd0000: 0x1040,
  4549. 0xe0000: 0x1000,
  4550. 0xf0000: 0x80401040,
  4551. 0x8000: 0x80001040,
  4552. 0x18000: 0x40,
  4553. 0x28000: 0x80400040,
  4554. 0x38000: 0x80001000,
  4555. 0x48000: 0x401000,
  4556. 0x58000: 0x80401040,
  4557. 0x68000: 0x0,
  4558. 0x78000: 0x80400000,
  4559. 0x88000: 0x1000,
  4560. 0x98000: 0x80401000,
  4561. 0xa8000: 0x400000,
  4562. 0xb8000: 0x1040,
  4563. 0xc8000: 0x80000000,
  4564. 0xd8000: 0x400040,
  4565. 0xe8000: 0x401040,
  4566. 0xf8000: 0x80000040,
  4567. 0x100000: 0x400040,
  4568. 0x110000: 0x401000,
  4569. 0x120000: 0x80000040,
  4570. 0x130000: 0x0,
  4571. 0x140000: 0x1040,
  4572. 0x150000: 0x80400040,
  4573. 0x160000: 0x80401000,
  4574. 0x170000: 0x80001040,
  4575. 0x180000: 0x80401040,
  4576. 0x190000: 0x80000000,
  4577. 0x1a0000: 0x80400000,
  4578. 0x1b0000: 0x401040,
  4579. 0x1c0000: 0x80001000,
  4580. 0x1d0000: 0x400000,
  4581. 0x1e0000: 0x40,
  4582. 0x1f0000: 0x1000,
  4583. 0x108000: 0x80400000,
  4584. 0x118000: 0x80401040,
  4585. 0x128000: 0x0,
  4586. 0x138000: 0x401000,
  4587. 0x148000: 0x400040,
  4588. 0x158000: 0x80000000,
  4589. 0x168000: 0x80001040,
  4590. 0x178000: 0x40,
  4591. 0x188000: 0x80000040,
  4592. 0x198000: 0x1000,
  4593. 0x1a8000: 0x80001000,
  4594. 0x1b8000: 0x80400040,
  4595. 0x1c8000: 0x1040,
  4596. 0x1d8000: 0x80401000,
  4597. 0x1e8000: 0x400000,
  4598. 0x1f8000: 0x401040
  4599. },
  4600. {
  4601. 0x0: 0x80,
  4602. 0x1000: 0x1040000,
  4603. 0x2000: 0x40000,
  4604. 0x3000: 0x20000000,
  4605. 0x4000: 0x20040080,
  4606. 0x5000: 0x1000080,
  4607. 0x6000: 0x21000080,
  4608. 0x7000: 0x40080,
  4609. 0x8000: 0x1000000,
  4610. 0x9000: 0x20040000,
  4611. 0xa000: 0x20000080,
  4612. 0xb000: 0x21040080,
  4613. 0xc000: 0x21040000,
  4614. 0xd000: 0x0,
  4615. 0xe000: 0x1040080,
  4616. 0xf000: 0x21000000,
  4617. 0x800: 0x1040080,
  4618. 0x1800: 0x21000080,
  4619. 0x2800: 0x80,
  4620. 0x3800: 0x1040000,
  4621. 0x4800: 0x40000,
  4622. 0x5800: 0x20040080,
  4623. 0x6800: 0x21040000,
  4624. 0x7800: 0x20000000,
  4625. 0x8800: 0x20040000,
  4626. 0x9800: 0x0,
  4627. 0xa800: 0x21040080,
  4628. 0xb800: 0x1000080,
  4629. 0xc800: 0x20000080,
  4630. 0xd800: 0x21000000,
  4631. 0xe800: 0x1000000,
  4632. 0xf800: 0x40080,
  4633. 0x10000: 0x40000,
  4634. 0x11000: 0x80,
  4635. 0x12000: 0x20000000,
  4636. 0x13000: 0x21000080,
  4637. 0x14000: 0x1000080,
  4638. 0x15000: 0x21040000,
  4639. 0x16000: 0x20040080,
  4640. 0x17000: 0x1000000,
  4641. 0x18000: 0x21040080,
  4642. 0x19000: 0x21000000,
  4643. 0x1a000: 0x1040000,
  4644. 0x1b000: 0x20040000,
  4645. 0x1c000: 0x40080,
  4646. 0x1d000: 0x20000080,
  4647. 0x1e000: 0x0,
  4648. 0x1f000: 0x1040080,
  4649. 0x10800: 0x21000080,
  4650. 0x11800: 0x1000000,
  4651. 0x12800: 0x1040000,
  4652. 0x13800: 0x20040080,
  4653. 0x14800: 0x20000000,
  4654. 0x15800: 0x1040080,
  4655. 0x16800: 0x80,
  4656. 0x17800: 0x21040000,
  4657. 0x18800: 0x40080,
  4658. 0x19800: 0x21040080,
  4659. 0x1a800: 0x0,
  4660. 0x1b800: 0x21000000,
  4661. 0x1c800: 0x1000080,
  4662. 0x1d800: 0x40000,
  4663. 0x1e800: 0x20040000,
  4664. 0x1f800: 0x20000080
  4665. },
  4666. {
  4667. 0x0: 0x10000008,
  4668. 0x100: 0x2000,
  4669. 0x200: 0x10200000,
  4670. 0x300: 0x10202008,
  4671. 0x400: 0x10002000,
  4672. 0x500: 0x200000,
  4673. 0x600: 0x200008,
  4674. 0x700: 0x10000000,
  4675. 0x800: 0x0,
  4676. 0x900: 0x10002008,
  4677. 0xa00: 0x202000,
  4678. 0xb00: 0x8,
  4679. 0xc00: 0x10200008,
  4680. 0xd00: 0x202008,
  4681. 0xe00: 0x2008,
  4682. 0xf00: 0x10202000,
  4683. 0x80: 0x10200000,
  4684. 0x180: 0x10202008,
  4685. 0x280: 0x8,
  4686. 0x380: 0x200000,
  4687. 0x480: 0x202008,
  4688. 0x580: 0x10000008,
  4689. 0x680: 0x10002000,
  4690. 0x780: 0x2008,
  4691. 0x880: 0x200008,
  4692. 0x980: 0x2000,
  4693. 0xa80: 0x10002008,
  4694. 0xb80: 0x10200008,
  4695. 0xc80: 0x0,
  4696. 0xd80: 0x10202000,
  4697. 0xe80: 0x202000,
  4698. 0xf80: 0x10000000,
  4699. 0x1000: 0x10002000,
  4700. 0x1100: 0x10200008,
  4701. 0x1200: 0x10202008,
  4702. 0x1300: 0x2008,
  4703. 0x1400: 0x200000,
  4704. 0x1500: 0x10000000,
  4705. 0x1600: 0x10000008,
  4706. 0x1700: 0x202000,
  4707. 0x1800: 0x202008,
  4708. 0x1900: 0x0,
  4709. 0x1a00: 0x8,
  4710. 0x1b00: 0x10200000,
  4711. 0x1c00: 0x2000,
  4712. 0x1d00: 0x10002008,
  4713. 0x1e00: 0x10202000,
  4714. 0x1f00: 0x200008,
  4715. 0x1080: 0x8,
  4716. 0x1180: 0x202000,
  4717. 0x1280: 0x200000,
  4718. 0x1380: 0x10000008,
  4719. 0x1480: 0x10002000,
  4720. 0x1580: 0x2008,
  4721. 0x1680: 0x10202008,
  4722. 0x1780: 0x10200000,
  4723. 0x1880: 0x10202000,
  4724. 0x1980: 0x10200008,
  4725. 0x1a80: 0x2000,
  4726. 0x1b80: 0x202008,
  4727. 0x1c80: 0x200008,
  4728. 0x1d80: 0x0,
  4729. 0x1e80: 0x10000000,
  4730. 0x1f80: 0x10002008
  4731. },
  4732. {
  4733. 0x0: 0x100000,
  4734. 0x10: 0x2000401,
  4735. 0x20: 0x400,
  4736. 0x30: 0x100401,
  4737. 0x40: 0x2100401,
  4738. 0x50: 0x0,
  4739. 0x60: 0x1,
  4740. 0x70: 0x2100001,
  4741. 0x80: 0x2000400,
  4742. 0x90: 0x100001,
  4743. 0xa0: 0x2000001,
  4744. 0xb0: 0x2100400,
  4745. 0xc0: 0x2100000,
  4746. 0xd0: 0x401,
  4747. 0xe0: 0x100400,
  4748. 0xf0: 0x2000000,
  4749. 0x8: 0x2100001,
  4750. 0x18: 0x0,
  4751. 0x28: 0x2000401,
  4752. 0x38: 0x2100400,
  4753. 0x48: 0x100000,
  4754. 0x58: 0x2000001,
  4755. 0x68: 0x2000000,
  4756. 0x78: 0x401,
  4757. 0x88: 0x100401,
  4758. 0x98: 0x2000400,
  4759. 0xa8: 0x2100000,
  4760. 0xb8: 0x100001,
  4761. 0xc8: 0x400,
  4762. 0xd8: 0x2100401,
  4763. 0xe8: 0x1,
  4764. 0xf8: 0x100400,
  4765. 0x100: 0x2000000,
  4766. 0x110: 0x100000,
  4767. 0x120: 0x2000401,
  4768. 0x130: 0x2100001,
  4769. 0x140: 0x100001,
  4770. 0x150: 0x2000400,
  4771. 0x160: 0x2100400,
  4772. 0x170: 0x100401,
  4773. 0x180: 0x401,
  4774. 0x190: 0x2100401,
  4775. 0x1a0: 0x100400,
  4776. 0x1b0: 0x1,
  4777. 0x1c0: 0x0,
  4778. 0x1d0: 0x2100000,
  4779. 0x1e0: 0x2000001,
  4780. 0x1f0: 0x400,
  4781. 0x108: 0x100400,
  4782. 0x118: 0x2000401,
  4783. 0x128: 0x2100001,
  4784. 0x138: 0x1,
  4785. 0x148: 0x2000000,
  4786. 0x158: 0x100000,
  4787. 0x168: 0x401,
  4788. 0x178: 0x2100400,
  4789. 0x188: 0x2000001,
  4790. 0x198: 0x2100000,
  4791. 0x1a8: 0x0,
  4792. 0x1b8: 0x2100401,
  4793. 0x1c8: 0x100401,
  4794. 0x1d8: 0x400,
  4795. 0x1e8: 0x2000400,
  4796. 0x1f8: 0x100001
  4797. },
  4798. {
  4799. 0x0: 0x8000820,
  4800. 0x1: 0x20000,
  4801. 0x2: 0x8000000,
  4802. 0x3: 0x20,
  4803. 0x4: 0x20020,
  4804. 0x5: 0x8020820,
  4805. 0x6: 0x8020800,
  4806. 0x7: 0x800,
  4807. 0x8: 0x8020000,
  4808. 0x9: 0x8000800,
  4809. 0xa: 0x20800,
  4810. 0xb: 0x8020020,
  4811. 0xc: 0x820,
  4812. 0xd: 0x0,
  4813. 0xe: 0x8000020,
  4814. 0xf: 0x20820,
  4815. 0x80000000: 0x800,
  4816. 0x80000001: 0x8020820,
  4817. 0x80000002: 0x8000820,
  4818. 0x80000003: 0x8000000,
  4819. 0x80000004: 0x8020000,
  4820. 0x80000005: 0x20800,
  4821. 0x80000006: 0x20820,
  4822. 0x80000007: 0x20,
  4823. 0x80000008: 0x8000020,
  4824. 0x80000009: 0x820,
  4825. 0x8000000a: 0x20020,
  4826. 0x8000000b: 0x8020800,
  4827. 0x8000000c: 0x0,
  4828. 0x8000000d: 0x8020020,
  4829. 0x8000000e: 0x8000800,
  4830. 0x8000000f: 0x20000,
  4831. 0x10: 0x20820,
  4832. 0x11: 0x8020800,
  4833. 0x12: 0x20,
  4834. 0x13: 0x800,
  4835. 0x14: 0x8000800,
  4836. 0x15: 0x8000020,
  4837. 0x16: 0x8020020,
  4838. 0x17: 0x20000,
  4839. 0x18: 0x0,
  4840. 0x19: 0x20020,
  4841. 0x1a: 0x8020000,
  4842. 0x1b: 0x8000820,
  4843. 0x1c: 0x8020820,
  4844. 0x1d: 0x20800,
  4845. 0x1e: 0x820,
  4846. 0x1f: 0x8000000,
  4847. 0x80000010: 0x20000,
  4848. 0x80000011: 0x800,
  4849. 0x80000012: 0x8020020,
  4850. 0x80000013: 0x20820,
  4851. 0x80000014: 0x20,
  4852. 0x80000015: 0x8020000,
  4853. 0x80000016: 0x8000000,
  4854. 0x80000017: 0x8000820,
  4855. 0x80000018: 0x8020820,
  4856. 0x80000019: 0x8000020,
  4857. 0x8000001a: 0x8000800,
  4858. 0x8000001b: 0x0,
  4859. 0x8000001c: 0x20800,
  4860. 0x8000001d: 0x820,
  4861. 0x8000001e: 0x20020,
  4862. 0x8000001f: 0x8020800
  4863. }
  4864. ];
  4865. // Masks that select the SBOX input
  4866. var SBOX_MASK = [
  4867. 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000,
  4868. 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f
  4869. ];
  4870. /**
  4871. * DES block cipher algorithm.
  4872. */
  4873. var DES = C_algo.DES = BlockCipher.extend({
  4874. _doReset: function () {
  4875. // Shortcuts
  4876. var key = this._key;
  4877. var keyWords = key.words;
  4878. // Select 56 bits according to PC1
  4879. var keyBits = [];
  4880. for (var i = 0; i < 56; i++) {
  4881. var keyBitPos = PC1[i] - 1;
  4882. keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1;
  4883. }
  4884. // Assemble 16 subkeys
  4885. var subKeys = this._subKeys = [];
  4886. for (var nSubKey = 0; nSubKey < 16; nSubKey++) {
  4887. // Create subkey
  4888. var subKey = subKeys[nSubKey] = [];
  4889. // Shortcut
  4890. var bitShift = BIT_SHIFTS[nSubKey];
  4891. // Select 48 bits according to PC2
  4892. for (var i = 0; i < 24; i++) {
  4893. // Select from the left 28 key bits
  4894. subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6);
  4895. // Select from the right 28 key bits
  4896. subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6);
  4897. }
  4898. // Since each subkey is applied to an expanded 32-bit input,
  4899. // the subkey can be broken into 8 values scaled to 32-bits,
  4900. // which allows the key to be used without expansion
  4901. subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31);
  4902. for (var i = 1; i < 7; i++) {
  4903. subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3);
  4904. }
  4905. subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27);
  4906. }
  4907. // Compute inverse subkeys
  4908. var invSubKeys = this._invSubKeys = [];
  4909. for (var i = 0; i < 16; i++) {
  4910. invSubKeys[i] = subKeys[15 - i];
  4911. }
  4912. },
  4913. encryptBlock: function (M, offset) {
  4914. this._doCryptBlock(M, offset, this._subKeys);
  4915. },
  4916. decryptBlock: function (M, offset) {
  4917. this._doCryptBlock(M, offset, this._invSubKeys);
  4918. },
  4919. _doCryptBlock: function (M, offset, subKeys) {
  4920. // Get input
  4921. this._lBlock = M[offset];
  4922. this._rBlock = M[offset + 1];
  4923. // Initial permutation
  4924. exchangeLR.call(this, 4, 0x0f0f0f0f);
  4925. exchangeLR.call(this, 16, 0x0000ffff);
  4926. exchangeRL.call(this, 2, 0x33333333);
  4927. exchangeRL.call(this, 8, 0x00ff00ff);
  4928. exchangeLR.call(this, 1, 0x55555555);
  4929. // Rounds
  4930. for (var round = 0; round < 16; round++) {
  4931. // Shortcuts
  4932. var subKey = subKeys[round];
  4933. var lBlock = this._lBlock;
  4934. var rBlock = this._rBlock;
  4935. // Feistel function
  4936. var f = 0;
  4937. for (var i = 0; i < 8; i++) {
  4938. f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0];
  4939. }
  4940. this._lBlock = rBlock;
  4941. this._rBlock = lBlock ^ f;
  4942. }
  4943. // Undo swap from last round
  4944. var t = this._lBlock;
  4945. this._lBlock = this._rBlock;
  4946. this._rBlock = t;
  4947. // Final permutation
  4948. exchangeLR.call(this, 1, 0x55555555);
  4949. exchangeRL.call(this, 8, 0x00ff00ff);
  4950. exchangeRL.call(this, 2, 0x33333333);
  4951. exchangeLR.call(this, 16, 0x0000ffff);
  4952. exchangeLR.call(this, 4, 0x0f0f0f0f);
  4953. // Set output
  4954. M[offset] = this._lBlock;
  4955. M[offset + 1] = this._rBlock;
  4956. },
  4957. keySize: 64/32,
  4958. ivSize: 64/32,
  4959. blockSize: 64/32
  4960. });
  4961. // Swap bits across the left and right words
  4962. function exchangeLR(offset, mask) {
  4963. var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask;
  4964. this._rBlock ^= t;
  4965. this._lBlock ^= t << offset;
  4966. }
  4967. function exchangeRL(offset, mask) {
  4968. var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask;
  4969. this._lBlock ^= t;
  4970. this._rBlock ^= t << offset;
  4971. }
  4972. /**
  4973. * Shortcut functions to the cipher's object interface.
  4974. *
  4975. * @example
  4976. *
  4977. * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
  4978. * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg);
  4979. */
  4980. C.DES = BlockCipher._createHelper(DES);
  4981. /**
  4982. * Triple-DES block cipher algorithm.
  4983. */
  4984. var TripleDES = C_algo.TripleDES = BlockCipher.extend({
  4985. _doReset: function () {
  4986. // Shortcuts
  4987. var key = this._key;
  4988. var keyWords = key.words;
  4989. // Make sure the key length is valid (64, 128 or >= 192 bit)
  4990. if (keyWords.length !== 2 && keyWords.length !== 4 && keyWords.length < 6) {
  4991. throw new Error('Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192.');
  4992. }
  4993. // Extend the key according to the keying options defined in 3DES standard
  4994. var key1 = keyWords.slice(0, 2);
  4995. var key2 = keyWords.length < 4 ? keyWords.slice(0, 2) : keyWords.slice(2, 4);
  4996. var key3 = keyWords.length < 6 ? keyWords.slice(0, 2) : keyWords.slice(4, 6);
  4997. // Create DES instances
  4998. this._des1 = DES.createEncryptor(WordArray.create(key1));
  4999. this._des2 = DES.createEncryptor(WordArray.create(key2));
  5000. this._des3 = DES.createEncryptor(WordArray.create(key3));
  5001. },
  5002. encryptBlock: function (M, offset) {
  5003. this._des1.encryptBlock(M, offset);
  5004. this._des2.decryptBlock(M, offset);
  5005. this._des3.encryptBlock(M, offset);
  5006. },
  5007. decryptBlock: function (M, offset) {
  5008. this._des3.decryptBlock(M, offset);
  5009. this._des2.encryptBlock(M, offset);
  5010. this._des1.decryptBlock(M, offset);
  5011. },
  5012. keySize: 192/32,
  5013. ivSize: 64/32,
  5014. blockSize: 64/32
  5015. });
  5016. /**
  5017. * Shortcut functions to the cipher's object interface.
  5018. *
  5019. * @example
  5020. *
  5021. * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
  5022. * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);
  5023. */
  5024. C.TripleDES = BlockCipher._createHelper(TripleDES);
  5025. }());
  5026. (function () {
  5027. // Shortcuts
  5028. var C = CryptoJS;
  5029. var C_lib = C.lib;
  5030. var StreamCipher = C_lib.StreamCipher;
  5031. var C_algo = C.algo;
  5032. /**
  5033. * RC4 stream cipher algorithm.
  5034. */
  5035. var RC4 = C_algo.RC4 = StreamCipher.extend({
  5036. _doReset: function () {
  5037. // Shortcuts
  5038. var key = this._key;
  5039. var keyWords = key.words;
  5040. var keySigBytes = key.sigBytes;
  5041. // Init sbox
  5042. var S = this._S = [];
  5043. for (var i = 0; i < 256; i++) {
  5044. S[i] = i;
  5045. }
  5046. // Key setup
  5047. for (var i = 0, j = 0; i < 256; i++) {
  5048. var keyByteIndex = i % keySigBytes;
  5049. var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff;
  5050. j = (j + S[i] + keyByte) % 256;
  5051. // Swap
  5052. var t = S[i];
  5053. S[i] = S[j];
  5054. S[j] = t;
  5055. }
  5056. // Counters
  5057. this._i = this._j = 0;
  5058. },
  5059. _doProcessBlock: function (M, offset) {
  5060. M[offset] ^= generateKeystreamWord.call(this);
  5061. },
  5062. keySize: 256/32,
  5063. ivSize: 0
  5064. });
  5065. function generateKeystreamWord() {
  5066. // Shortcuts
  5067. var S = this._S;
  5068. var i = this._i;
  5069. var j = this._j;
  5070. // Generate keystream word
  5071. var keystreamWord = 0;
  5072. for (var n = 0; n < 4; n++) {
  5073. i = (i + 1) % 256;
  5074. j = (j + S[i]) % 256;
  5075. // Swap
  5076. var t = S[i];
  5077. S[i] = S[j];
  5078. S[j] = t;
  5079. keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8);
  5080. }
  5081. // Update counters
  5082. this._i = i;
  5083. this._j = j;
  5084. return keystreamWord;
  5085. }
  5086. /**
  5087. * Shortcut functions to the cipher's object interface.
  5088. *
  5089. * @example
  5090. *
  5091. * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
  5092. * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg);
  5093. */
  5094. C.RC4 = StreamCipher._createHelper(RC4);
  5095. /**
  5096. * Modified RC4 stream cipher algorithm.
  5097. */
  5098. var RC4Drop = C_algo.RC4Drop = RC4.extend({
  5099. /**
  5100. * Configuration options.
  5101. *
  5102. * @property {number} drop The number of keystream words to drop. Default 192
  5103. */
  5104. cfg: RC4.cfg.extend({
  5105. drop: 192
  5106. }),
  5107. _doReset: function () {
  5108. RC4._doReset.call(this);
  5109. // Drop
  5110. for (var i = this.cfg.drop; i > 0; i--) {
  5111. generateKeystreamWord.call(this);
  5112. }
  5113. }
  5114. });
  5115. /**
  5116. * Shortcut functions to the cipher's object interface.
  5117. *
  5118. * @example
  5119. *
  5120. * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg);
  5121. * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg);
  5122. */
  5123. C.RC4Drop = StreamCipher._createHelper(RC4Drop);
  5124. }());
  5125. (function () {
  5126. // Shortcuts
  5127. var C = CryptoJS;
  5128. var C_lib = C.lib;
  5129. var StreamCipher = C_lib.StreamCipher;
  5130. var C_algo = C.algo;
  5131. // Reusable objects
  5132. var S = [];
  5133. var C_ = [];
  5134. var G = [];
  5135. /**
  5136. * Rabbit stream cipher algorithm
  5137. */
  5138. var Rabbit = C_algo.Rabbit = StreamCipher.extend({
  5139. _doReset: function () {
  5140. // Shortcuts
  5141. var K = this._key.words;
  5142. var iv = this.cfg.iv;
  5143. // Swap endian
  5144. for (var i = 0; i < 4; i++) {
  5145. K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) |
  5146. (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00);
  5147. }
  5148. // Generate initial state values
  5149. var X = this._X = [
  5150. K[0], (K[3] << 16) | (K[2] >>> 16),
  5151. K[1], (K[0] << 16) | (K[3] >>> 16),
  5152. K[2], (K[1] << 16) | (K[0] >>> 16),
  5153. K[3], (K[2] << 16) | (K[1] >>> 16)
  5154. ];
  5155. // Generate initial counter values
  5156. var C = this._C = [
  5157. (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  5158. (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  5159. (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  5160. (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
  5161. ];
  5162. // Carry bit
  5163. this._b = 0;
  5164. // Iterate the system four times
  5165. for (var i = 0; i < 4; i++) {
  5166. nextState.call(this);
  5167. }
  5168. // Modify the counters
  5169. for (var i = 0; i < 8; i++) {
  5170. C[i] ^= X[(i + 4) & 7];
  5171. }
  5172. // IV setup
  5173. if (iv) {
  5174. // Shortcuts
  5175. var IV = iv.words;
  5176. var IV_0 = IV[0];
  5177. var IV_1 = IV[1];
  5178. // Generate four subvectors
  5179. var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  5180. var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  5181. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  5182. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  5183. // Modify counter values
  5184. C[0] ^= i0;
  5185. C[1] ^= i1;
  5186. C[2] ^= i2;
  5187. C[3] ^= i3;
  5188. C[4] ^= i0;
  5189. C[5] ^= i1;
  5190. C[6] ^= i2;
  5191. C[7] ^= i3;
  5192. // Iterate the system four times
  5193. for (var i = 0; i < 4; i++) {
  5194. nextState.call(this);
  5195. }
  5196. }
  5197. },
  5198. _doProcessBlock: function (M, offset) {
  5199. // Shortcut
  5200. var X = this._X;
  5201. // Iterate the system
  5202. nextState.call(this);
  5203. // Generate four keystream words
  5204. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  5205. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  5206. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  5207. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  5208. for (var i = 0; i < 4; i++) {
  5209. // Swap endian
  5210. S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  5211. (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  5212. // Encrypt
  5213. M[offset + i] ^= S[i];
  5214. }
  5215. },
  5216. blockSize: 128/32,
  5217. ivSize: 64/32
  5218. });
  5219. function nextState() {
  5220. // Shortcuts
  5221. var X = this._X;
  5222. var C = this._C;
  5223. // Save old counter values
  5224. for (var i = 0; i < 8; i++) {
  5225. C_[i] = C[i];
  5226. }
  5227. // Calculate new counter values
  5228. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  5229. C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  5230. C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  5231. C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  5232. C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  5233. C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  5234. C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  5235. C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  5236. this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  5237. // Calculate the g-values
  5238. for (var i = 0; i < 8; i++) {
  5239. var gx = X[i] + C[i];
  5240. // Construct high and low argument for squaring
  5241. var ga = gx & 0xffff;
  5242. var gb = gx >>> 16;
  5243. // Calculate high and low result of squaring
  5244. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  5245. var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  5246. // High XOR low
  5247. G[i] = gh ^ gl;
  5248. }
  5249. // Calculate new state values
  5250. X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  5251. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  5252. X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  5253. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  5254. X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  5255. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  5256. X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  5257. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  5258. }
  5259. /**
  5260. * Shortcut functions to the cipher's object interface.
  5261. *
  5262. * @example
  5263. *
  5264. * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg);
  5265. * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg);
  5266. */
  5267. C.Rabbit = StreamCipher._createHelper(Rabbit);
  5268. }());
  5269. (function () {
  5270. // Shortcuts
  5271. var C = CryptoJS;
  5272. var C_lib = C.lib;
  5273. var StreamCipher = C_lib.StreamCipher;
  5274. var C_algo = C.algo;
  5275. // Reusable objects
  5276. var S = [];
  5277. var C_ = [];
  5278. var G = [];
  5279. /**
  5280. * Rabbit stream cipher algorithm.
  5281. *
  5282. * This is a legacy version that neglected to convert the key to little-endian.
  5283. * This error doesn't affect the cipher's security,
  5284. * but it does affect its compatibility with other implementations.
  5285. */
  5286. var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({
  5287. _doReset: function () {
  5288. // Shortcuts
  5289. var K = this._key.words;
  5290. var iv = this.cfg.iv;
  5291. // Generate initial state values
  5292. var X = this._X = [
  5293. K[0], (K[3] << 16) | (K[2] >>> 16),
  5294. K[1], (K[0] << 16) | (K[3] >>> 16),
  5295. K[2], (K[1] << 16) | (K[0] >>> 16),
  5296. K[3], (K[2] << 16) | (K[1] >>> 16)
  5297. ];
  5298. // Generate initial counter values
  5299. var C = this._C = [
  5300. (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
  5301. (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
  5302. (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
  5303. (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
  5304. ];
  5305. // Carry bit
  5306. this._b = 0;
  5307. // Iterate the system four times
  5308. for (var i = 0; i < 4; i++) {
  5309. nextState.call(this);
  5310. }
  5311. // Modify the counters
  5312. for (var i = 0; i < 8; i++) {
  5313. C[i] ^= X[(i + 4) & 7];
  5314. }
  5315. // IV setup
  5316. if (iv) {
  5317. // Shortcuts
  5318. var IV = iv.words;
  5319. var IV_0 = IV[0];
  5320. var IV_1 = IV[1];
  5321. // Generate four subvectors
  5322. var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
  5323. var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
  5324. var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
  5325. var i3 = (i2 << 16) | (i0 & 0x0000ffff);
  5326. // Modify counter values
  5327. C[0] ^= i0;
  5328. C[1] ^= i1;
  5329. C[2] ^= i2;
  5330. C[3] ^= i3;
  5331. C[4] ^= i0;
  5332. C[5] ^= i1;
  5333. C[6] ^= i2;
  5334. C[7] ^= i3;
  5335. // Iterate the system four times
  5336. for (var i = 0; i < 4; i++) {
  5337. nextState.call(this);
  5338. }
  5339. }
  5340. },
  5341. _doProcessBlock: function (M, offset) {
  5342. // Shortcut
  5343. var X = this._X;
  5344. // Iterate the system
  5345. nextState.call(this);
  5346. // Generate four keystream words
  5347. S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
  5348. S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
  5349. S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
  5350. S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
  5351. for (var i = 0; i < 4; i++) {
  5352. // Swap endian
  5353. S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
  5354. (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
  5355. // Encrypt
  5356. M[offset + i] ^= S[i];
  5357. }
  5358. },
  5359. blockSize: 128/32,
  5360. ivSize: 64/32
  5361. });
  5362. function nextState() {
  5363. // Shortcuts
  5364. var X = this._X;
  5365. var C = this._C;
  5366. // Save old counter values
  5367. for (var i = 0; i < 8; i++) {
  5368. C_[i] = C[i];
  5369. }
  5370. // Calculate new counter values
  5371. C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
  5372. C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
  5373. C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
  5374. C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
  5375. C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
  5376. C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
  5377. C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
  5378. C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
  5379. this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
  5380. // Calculate the g-values
  5381. for (var i = 0; i < 8; i++) {
  5382. var gx = X[i] + C[i];
  5383. // Construct high and low argument for squaring
  5384. var ga = gx & 0xffff;
  5385. var gb = gx >>> 16;
  5386. // Calculate high and low result of squaring
  5387. var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
  5388. var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
  5389. // High XOR low
  5390. G[i] = gh ^ gl;
  5391. }
  5392. // Calculate new state values
  5393. X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
  5394. X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
  5395. X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
  5396. X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
  5397. X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
  5398. X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
  5399. X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
  5400. X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
  5401. }
  5402. /**
  5403. * Shortcut functions to the cipher's object interface.
  5404. *
  5405. * @example
  5406. *
  5407. * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg);
  5408. * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg);
  5409. */
  5410. C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy);
  5411. }());
  5412. (function () {
  5413. // Shortcuts
  5414. var C = CryptoJS;
  5415. var C_lib = C.lib;
  5416. var BlockCipher = C_lib.BlockCipher;
  5417. var C_algo = C.algo;
  5418. const N = 16;
  5419. //Origin pbox and sbox, derived from PI
  5420. const ORIG_P = [
  5421. 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
  5422. 0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
  5423. 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
  5424. 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917,
  5425. 0x9216D5D9, 0x8979FB1B
  5426. ];
  5427. const ORIG_S = [
  5428. [ 0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7,
  5429. 0xB8E1AFED, 0x6A267E96, 0xBA7C9045, 0xF12C7F99,
  5430. 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16,
  5431. 0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E,
  5432. 0x0D95748F, 0x728EB658, 0x718BCD58, 0x82154AEE,
  5433. 0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013,
  5434. 0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF,
  5435. 0x8E79DCB0, 0x603A180E, 0x6C9E0E8B, 0xB01E8A3E,
  5436. 0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60,
  5437. 0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440,
  5438. 0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE,
  5439. 0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A,
  5440. 0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E,
  5441. 0xAFD6BA33, 0x6C24CF5C, 0x7A325381, 0x28958677,
  5442. 0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193,
  5443. 0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032,
  5444. 0xEF845D5D, 0xE98575B1, 0xDC262302, 0xEB651B88,
  5445. 0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239,
  5446. 0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E,
  5447. 0x21C66842, 0xF6E96C9A, 0x670C9C61, 0xABD388F0,
  5448. 0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3,
  5449. 0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98,
  5450. 0xA1F1651D, 0x39AF0176, 0x66CA593E, 0x82430E88,
  5451. 0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE,
  5452. 0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6,
  5453. 0x4ED3AA62, 0x363F7706, 0x1BFEDF72, 0x429B023D,
  5454. 0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B,
  5455. 0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7,
  5456. 0xE3FE501A, 0xB6794C3B, 0x976CE0BD, 0x04C006BA,
  5457. 0xC1A94FB6, 0x409F60C4, 0x5E5C9EC2, 0x196A2463,
  5458. 0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F,
  5459. 0x6DFC511F, 0x9B30952C, 0xCC814544, 0xAF5EBD09,
  5460. 0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3,
  5461. 0xC0CBA857, 0x45C8740F, 0xD20B5F39, 0xB9D3FBDB,
  5462. 0x5579C0BD, 0x1A60320A, 0xD6A100C6, 0x402C7279,
  5463. 0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8,
  5464. 0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB,
  5465. 0x323DB5FA, 0xFD238760, 0x53317B48, 0x3E00DF82,
  5466. 0x9E5C57BB, 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB,
  5467. 0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573,
  5468. 0x695B27B0, 0xBBCA58C8, 0xE1FFA35D, 0xB8F011A0,
  5469. 0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B,
  5470. 0x9A53E479, 0xB6F84565, 0xD28E49BC, 0x4BFB9790,
  5471. 0xE1DDF2DA, 0xA4CB7E33, 0x62FB1341, 0xCEE4C6E8,
  5472. 0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4,
  5473. 0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0,
  5474. 0xD08ED1D0, 0xAFC725E0, 0x8E3C5B2F, 0x8E7594B7,
  5475. 0x8FF6E2FB, 0xF2122B64, 0x8888B812, 0x900DF01C,
  5476. 0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD,
  5477. 0x2F2F2218, 0xBE0E1777, 0xEA752DFE, 0x8B021FA1,
  5478. 0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299,
  5479. 0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, 0xD2ADA8D9,
  5480. 0x165FA266, 0x80957705, 0x93CC7314, 0x211A1477,
  5481. 0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF,
  5482. 0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49,
  5483. 0x00250E2D, 0x2071B35E, 0x226800BB, 0x57B8E0AF,
  5484. 0x2464369B, 0xF009B91E, 0x5563911D, 0x59DFA6AA,
  5485. 0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5,
  5486. 0x83260376, 0x6295CFA9, 0x11C81968, 0x4E734A41,
  5487. 0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915,
  5488. 0xD60F573F, 0xBC9BC6E4, 0x2B60A476, 0x81E67400,
  5489. 0x08BA6FB5, 0x571BE91F, 0xF296EC6B, 0x2A0DD915,
  5490. 0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664,
  5491. 0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A ],
  5492. [ 0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623,
  5493. 0xAD6EA6B0, 0x49A7DF7D, 0x9CEE60B8, 0x8FEDB266,
  5494. 0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1,
  5495. 0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E,
  5496. 0x3F54989A, 0x5B429D65, 0x6B8FE4D6, 0x99F73FD6,
  5497. 0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1,
  5498. 0x4CDD2086, 0x8470EB26, 0x6382E9C6, 0x021ECC5E,
  5499. 0x09686B3F, 0x3EBAEFC9, 0x3C971814, 0x6B6A70A1,
  5500. 0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737,
  5501. 0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8,
  5502. 0xB03ADA37, 0xF0500C0D, 0xF01C1F04, 0x0200B3FF,
  5503. 0xAE0CF51A, 0x3CB574B2, 0x25837A58, 0xDC0921BD,
  5504. 0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701,
  5505. 0x3AE5E581, 0x37C2DADC, 0xC8B57634, 0x9AF3DDA7,
  5506. 0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41,
  5507. 0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, 0x183EB331,
  5508. 0x4E548B38, 0x4F6DB908, 0x6F420D03, 0xF60A04BF,
  5509. 0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF,
  5510. 0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E,
  5511. 0x5512721F, 0x2E6B7124, 0x501ADDE6, 0x9F84CD87,
  5512. 0x7A584718, 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C,
  5513. 0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2,
  5514. 0xEF1C1847, 0x3215D908, 0xDD433B37, 0x24C2BA16,
  5515. 0x12A14D43, 0x2A65C451, 0x50940002, 0x133AE4DD,
  5516. 0x71DFF89E, 0x10314E55, 0x81AC77D6, 0x5F11199B,
  5517. 0x043556F1, 0xD7A3C76B, 0x3C11183B, 0x5924A509,
  5518. 0xF28FE6ED, 0x97F1FBFA, 0x9EBABF2C, 0x1E153C6E,
  5519. 0x86E34570, 0xEAE96FB1, 0x860E5E0A, 0x5A3E2AB3,
  5520. 0x771FE71C, 0x4E3D06FA, 0x2965DCB9, 0x99E71D0F,
  5521. 0x803E89D6, 0x5266C825, 0x2E4CC978, 0x9C10B36A,
  5522. 0xC6150EBA, 0x94E2EA78, 0xA5FC3C53, 0x1E0A2DF4,
  5523. 0xF2F74EA7, 0x361D2B3D, 0x1939260F, 0x19C27960,
  5524. 0x5223A708, 0xF71312B6, 0xEBADFE6E, 0xEAC31F66,
  5525. 0xE3BC4595, 0xA67BC883, 0xB17F37D1, 0x018CFF28,
  5526. 0xC332DDEF, 0xBE6C5AA5, 0x65582185, 0x68AB9802,
  5527. 0xEECEA50F, 0xDB2F953B, 0x2AEF7DAD, 0x5B6E2F84,
  5528. 0x1521B628, 0x29076170, 0xECDD4775, 0x619F1510,
  5529. 0x13CCA830, 0xEB61BD96, 0x0334FE1E, 0xAA0363CF,
  5530. 0xB5735C90, 0x4C70A239, 0xD59E9E0B, 0xCBAADE14,
  5531. 0xEECC86BC, 0x60622CA7, 0x9CAB5CAB, 0xB2F3846E,
  5532. 0x648B1EAF, 0x19BDF0CA, 0xA02369B9, 0x655ABB50,
  5533. 0x40685A32, 0x3C2AB4B3, 0x319EE9D5, 0xC021B8F7,
  5534. 0x9B540B19, 0x875FA099, 0x95F7997E, 0x623D7DA8,
  5535. 0xF837889A, 0x97E32D77, 0x11ED935F, 0x16681281,
  5536. 0x0E358829, 0xC7E61FD6, 0x96DEDFA1, 0x7858BA99,
  5537. 0x57F584A5, 0x1B227263, 0x9B83C3FF, 0x1AC24696,
  5538. 0xCDB30AEB, 0x532E3054, 0x8FD948E4, 0x6DBC3128,
  5539. 0x58EBF2EF, 0x34C6FFEA, 0xFE28ED61, 0xEE7C3C73,
  5540. 0x5D4A14D9, 0xE864B7E3, 0x42105D14, 0x203E13E0,
  5541. 0x45EEE2B6, 0xA3AAABEA, 0xDB6C4F15, 0xFACB4FD0,
  5542. 0xC742F442, 0xEF6ABBB5, 0x654F3B1D, 0x41CD2105,
  5543. 0xD81E799E, 0x86854DC7, 0xE44B476A, 0x3D816250,
  5544. 0xCF62A1F2, 0x5B8D2646, 0xFC8883A0, 0xC1C7B6A3,
  5545. 0x7F1524C3, 0x69CB7492, 0x47848A0B, 0x5692B285,
  5546. 0x095BBF00, 0xAD19489D, 0x1462B174, 0x23820E00,
  5547. 0x58428D2A, 0x0C55F5EA, 0x1DADF43E, 0x233F7061,
  5548. 0x3372F092, 0x8D937E41, 0xD65FECF1, 0x6C223BDB,
  5549. 0x7CDE3759, 0xCBEE7460, 0x4085F2A7, 0xCE77326E,
  5550. 0xA6078084, 0x19F8509E, 0xE8EFD855, 0x61D99735,
  5551. 0xA969A7AA, 0xC50C06C2, 0x5A04ABFC, 0x800BCADC,
  5552. 0x9E447A2E, 0xC3453484, 0xFDD56705, 0x0E1E9EC9,
  5553. 0xDB73DBD3, 0x105588CD, 0x675FDA79, 0xE3674340,
  5554. 0xC5C43465, 0x713E38D8, 0x3D28F89E, 0xF16DFF20,
  5555. 0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7 ],
  5556. [ 0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934,
  5557. 0x411520F7, 0x7602D4F7, 0xBCF46B2E, 0xD4A20068,
  5558. 0xD4082471, 0x3320F46A, 0x43B7D4B7, 0x500061AF,
  5559. 0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840,
  5560. 0x4D95FC1D, 0x96B591AF, 0x70F4DDD3, 0x66A02F45,
  5561. 0xBFBC09EC, 0x03BD9785, 0x7FAC6DD0, 0x31CB8504,
  5562. 0x96EB27B3, 0x55FD3941, 0xDA2547E6, 0xABCA0A9A,
  5563. 0x28507825, 0x530429F4, 0x0A2C86DA, 0xE9B66DFB,
  5564. 0x68DC1462, 0xD7486900, 0x680EC0A4, 0x27A18DEE,
  5565. 0x4F3FFEA2, 0xE887AD8C, 0xB58CE006, 0x7AF4D6B6,
  5566. 0xAACE1E7C, 0xD3375FEC, 0xCE78A399, 0x406B2A42,
  5567. 0x20FE9E35, 0xD9F385B9, 0xEE39D7AB, 0x3B124E8B,
  5568. 0x1DC9FAF7, 0x4B6D1856, 0x26A36631, 0xEAE397B2,
  5569. 0x3A6EFA74, 0xDD5B4332, 0x6841E7F7, 0xCA7820FB,
  5570. 0xFB0AF54E, 0xD8FEB397, 0x454056AC, 0xBA489527,
  5571. 0x55533A3A, 0x20838D87, 0xFE6BA9B7, 0xD096954B,
  5572. 0x55A867BC, 0xA1159A58, 0xCCA92963, 0x99E1DB33,
  5573. 0xA62A4A56, 0x3F3125F9, 0x5EF47E1C, 0x9029317C,
  5574. 0xFDF8E802, 0x04272F70, 0x80BB155C, 0x05282CE3,
  5575. 0x95C11548, 0xE4C66D22, 0x48C1133F, 0xC70F86DC,
  5576. 0x07F9C9EE, 0x41041F0F, 0x404779A4, 0x5D886E17,
  5577. 0x325F51EB, 0xD59BC0D1, 0xF2BCC18F, 0x41113564,
  5578. 0x257B7834, 0x602A9C60, 0xDFF8E8A3, 0x1F636C1B,
  5579. 0x0E12B4C2, 0x02E1329E, 0xAF664FD1, 0xCAD18115,
  5580. 0x6B2395E0, 0x333E92E1, 0x3B240B62, 0xEEBEB922,
  5581. 0x85B2A20E, 0xE6BA0D99, 0xDE720C8C, 0x2DA2F728,
  5582. 0xD0127845, 0x95B794FD, 0x647D0862, 0xE7CCF5F0,
  5583. 0x5449A36F, 0x877D48FA, 0xC39DFD27, 0xF33E8D1E,
  5584. 0x0A476341, 0x992EFF74, 0x3A6F6EAB, 0xF4F8FD37,
  5585. 0xA812DC60, 0xA1EBDDF8, 0x991BE14C, 0xDB6E6B0D,
  5586. 0xC67B5510, 0x6D672C37, 0x2765D43B, 0xDCD0E804,
  5587. 0xF1290DC7, 0xCC00FFA3, 0xB5390F92, 0x690FED0B,
  5588. 0x667B9FFB, 0xCEDB7D9C, 0xA091CF0B, 0xD9155EA3,
  5589. 0xBB132F88, 0x515BAD24, 0x7B9479BF, 0x763BD6EB,
  5590. 0x37392EB3, 0xCC115979, 0x8026E297, 0xF42E312D,
  5591. 0x6842ADA7, 0xC66A2B3B, 0x12754CCC, 0x782EF11C,
  5592. 0x6A124237, 0xB79251E7, 0x06A1BBE6, 0x4BFB6350,
  5593. 0x1A6B1018, 0x11CAEDFA, 0x3D25BDD8, 0xE2E1C3C9,
  5594. 0x44421659, 0x0A121386, 0xD90CEC6E, 0xD5ABEA2A,
  5595. 0x64AF674E, 0xDA86A85F, 0xBEBFE988, 0x64E4C3FE,
  5596. 0x9DBC8057, 0xF0F7C086, 0x60787BF8, 0x6003604D,
  5597. 0xD1FD8346, 0xF6381FB0, 0x7745AE04, 0xD736FCCC,
  5598. 0x83426B33, 0xF01EAB71, 0xB0804187, 0x3C005E5F,
  5599. 0x77A057BE, 0xBDE8AE24, 0x55464299, 0xBF582E61,
  5600. 0x4E58F48F, 0xF2DDFDA2, 0xF474EF38, 0x8789BDC2,
  5601. 0x5366F9C3, 0xC8B38E74, 0xB475F255, 0x46FCD9B9,
  5602. 0x7AEB2661, 0x8B1DDF84, 0x846A0E79, 0x915F95E2,
  5603. 0x466E598E, 0x20B45770, 0x8CD55591, 0xC902DE4C,
  5604. 0xB90BACE1, 0xBB8205D0, 0x11A86248, 0x7574A99E,
  5605. 0xB77F19B6, 0xE0A9DC09, 0x662D09A1, 0xC4324633,
  5606. 0xE85A1F02, 0x09F0BE8C, 0x4A99A025, 0x1D6EFE10,
  5607. 0x1AB93D1D, 0x0BA5A4DF, 0xA186F20F, 0x2868F169,
  5608. 0xDCB7DA83, 0x573906FE, 0xA1E2CE9B, 0x4FCD7F52,
  5609. 0x50115E01, 0xA70683FA, 0xA002B5C4, 0x0DE6D027,
  5610. 0x9AF88C27, 0x773F8641, 0xC3604C06, 0x61A806B5,
  5611. 0xF0177A28, 0xC0F586E0, 0x006058AA, 0x30DC7D62,
  5612. 0x11E69ED7, 0x2338EA63, 0x53C2DD94, 0xC2C21634,
  5613. 0xBBCBEE56, 0x90BCB6DE, 0xEBFC7DA1, 0xCE591D76,
  5614. 0x6F05E409, 0x4B7C0188, 0x39720A3D, 0x7C927C24,
  5615. 0x86E3725F, 0x724D9DB9, 0x1AC15BB4, 0xD39EB8FC,
  5616. 0xED545578, 0x08FCA5B5, 0xD83D7CD3, 0x4DAD0FC4,
  5617. 0x1E50EF5E, 0xB161E6F8, 0xA28514D9, 0x6C51133C,
  5618. 0x6FD5C7E7, 0x56E14EC4, 0x362ABFCE, 0xDDC6C837,
  5619. 0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0 ],
  5620. [ 0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B,
  5621. 0x5CB0679E, 0x4FA33742, 0xD3822740, 0x99BC9BBE,
  5622. 0xD5118E9D, 0xBF0F7315, 0xD62D1C7E, 0xC700C47B,
  5623. 0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4,
  5624. 0x5748AB2F, 0xBC946E79, 0xC6A376D2, 0x6549C2C8,
  5625. 0x530FF8EE, 0x468DDE7D, 0xD5730A1D, 0x4CD04DC6,
  5626. 0x2939BBDB, 0xA9BA4650, 0xAC9526E8, 0xBE5EE304,
  5627. 0xA1FAD5F0, 0x6A2D519A, 0x63EF8CE2, 0x9A86EE22,
  5628. 0xC089C2B8, 0x43242EF6, 0xA51E03AA, 0x9CF2D0A4,
  5629. 0x83C061BA, 0x9BE96A4D, 0x8FE51550, 0xBA645BD6,
  5630. 0x2826A2F9, 0xA73A3AE1, 0x4BA99586, 0xEF5562E9,
  5631. 0xC72FEFD3, 0xF752F7DA, 0x3F046F69, 0x77FA0A59,
  5632. 0x80E4A915, 0x87B08601, 0x9B09E6AD, 0x3B3EE593,
  5633. 0xE990FD5A, 0x9E34D797, 0x2CF0B7D9, 0x022B8B51,
  5634. 0x96D5AC3A, 0x017DA67D, 0xD1CF3ED6, 0x7C7D2D28,
  5635. 0x1F9F25CF, 0xADF2B89B, 0x5AD6B472, 0x5A88F54C,
  5636. 0xE029AC71, 0xE019A5E6, 0x47B0ACFD, 0xED93FA9B,
  5637. 0xE8D3C48D, 0x283B57CC, 0xF8D56629, 0x79132E28,
  5638. 0x785F0191, 0xED756055, 0xF7960E44, 0xE3D35E8C,
  5639. 0x15056DD4, 0x88F46DBA, 0x03A16125, 0x0564F0BD,
  5640. 0xC3EB9E15, 0x3C9057A2, 0x97271AEC, 0xA93A072A,
  5641. 0x1B3F6D9B, 0x1E6321F5, 0xF59C66FB, 0x26DCF319,
  5642. 0x7533D928, 0xB155FDF5, 0x03563482, 0x8ABA3CBB,
  5643. 0x28517711, 0xC20AD9F8, 0xABCC5167, 0xCCAD925F,
  5644. 0x4DE81751, 0x3830DC8E, 0x379D5862, 0x9320F991,
  5645. 0xEA7A90C2, 0xFB3E7BCE, 0x5121CE64, 0x774FBE32,
  5646. 0xA8B6E37E, 0xC3293D46, 0x48DE5369, 0x6413E680,
  5647. 0xA2AE0810, 0xDD6DB224, 0x69852DFD, 0x09072166,
  5648. 0xB39A460A, 0x6445C0DD, 0x586CDECF, 0x1C20C8AE,
  5649. 0x5BBEF7DD, 0x1B588D40, 0xCCD2017F, 0x6BB4E3BB,
  5650. 0xDDA26A7E, 0x3A59FF45, 0x3E350A44, 0xBCB4CDD5,
  5651. 0x72EACEA8, 0xFA6484BB, 0x8D6612AE, 0xBF3C6F47,
  5652. 0xD29BE463, 0x542F5D9E, 0xAEC2771B, 0xF64E6370,
  5653. 0x740E0D8D, 0xE75B1357, 0xF8721671, 0xAF537D5D,
  5654. 0x4040CB08, 0x4EB4E2CC, 0x34D2466A, 0x0115AF84,
  5655. 0xE1B00428, 0x95983A1D, 0x06B89FB4, 0xCE6EA048,
  5656. 0x6F3F3B82, 0x3520AB82, 0x011A1D4B, 0x277227F8,
  5657. 0x611560B1, 0xE7933FDC, 0xBB3A792B, 0x344525BD,
  5658. 0xA08839E1, 0x51CE794B, 0x2F32C9B7, 0xA01FBAC9,
  5659. 0xE01CC87E, 0xBCC7D1F6, 0xCF0111C3, 0xA1E8AAC7,
  5660. 0x1A908749, 0xD44FBD9A, 0xD0DADECB, 0xD50ADA38,
  5661. 0x0339C32A, 0xC6913667, 0x8DF9317C, 0xE0B12B4F,
  5662. 0xF79E59B7, 0x43F5BB3A, 0xF2D519FF, 0x27D9459C,
  5663. 0xBF97222C, 0x15E6FC2A, 0x0F91FC71, 0x9B941525,
  5664. 0xFAE59361, 0xCEB69CEB, 0xC2A86459, 0x12BAA8D1,
  5665. 0xB6C1075E, 0xE3056A0C, 0x10D25065, 0xCB03A442,
  5666. 0xE0EC6E0E, 0x1698DB3B, 0x4C98A0BE, 0x3278E964,
  5667. 0x9F1F9532, 0xE0D392DF, 0xD3A0342B, 0x8971F21E,
  5668. 0x1B0A7441, 0x4BA3348C, 0xC5BE7120, 0xC37632D8,
  5669. 0xDF359F8D, 0x9B992F2E, 0xE60B6F47, 0x0FE3F11D,
  5670. 0xE54CDA54, 0x1EDAD891, 0xCE6279CF, 0xCD3E7E6F,
  5671. 0x1618B166, 0xFD2C1D05, 0x848FD2C5, 0xF6FB2299,
  5672. 0xF523F357, 0xA6327623, 0x93A83531, 0x56CCCD02,
  5673. 0xACF08162, 0x5A75EBB5, 0x6E163697, 0x88D273CC,
  5674. 0xDE966292, 0x81B949D0, 0x4C50901B, 0x71C65614,
  5675. 0xE6C6C7BD, 0x327A140A, 0x45E1D006, 0xC3F27B9A,
  5676. 0xC9AA53FD, 0x62A80F00, 0xBB25BFE2, 0x35BDD2F6,
  5677. 0x71126905, 0xB2040222, 0xB6CBCF7C, 0xCD769C2B,
  5678. 0x53113EC0, 0x1640E3D3, 0x38ABBD60, 0x2547ADF0,
  5679. 0xBA38209C, 0xF746CE76, 0x77AFA1C5, 0x20756060,
  5680. 0x85CBFE4E, 0x8AE88DD8, 0x7AAAF9B0, 0x4CF9AA7E,
  5681. 0x1948C25C, 0x02FB8A8C, 0x01C36AE4, 0xD6EBE1F9,
  5682. 0x90D4F869, 0xA65CDEA0, 0x3F09252D, 0xC208E69F,
  5683. 0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6 ]
  5684. ];
  5685. var BLOWFISH_CTX = {
  5686. pbox: [],
  5687. sbox: []
  5688. }
  5689. function F(ctx, x){
  5690. let a = (x >> 24) & 0xFF;
  5691. let b = (x >> 16) & 0xFF;
  5692. let c = (x >> 8) & 0xFF;
  5693. let d = x & 0xFF;
  5694. let y = ctx.sbox[0][a] + ctx.sbox[1][b];
  5695. y = y ^ ctx.sbox[2][c];
  5696. y = y + ctx.sbox[3][d];
  5697. return y;
  5698. }
  5699. function BlowFish_Encrypt(ctx, left, right){
  5700. let Xl = left;
  5701. let Xr = right;
  5702. let temp;
  5703. for(let i = 0; i < N; ++i){
  5704. Xl = Xl ^ ctx.pbox[i];
  5705. Xr = F(ctx, Xl) ^ Xr;
  5706. temp = Xl;
  5707. Xl = Xr;
  5708. Xr = temp;
  5709. }
  5710. temp = Xl;
  5711. Xl = Xr;
  5712. Xr = temp;
  5713. Xr = Xr ^ ctx.pbox[N];
  5714. Xl = Xl ^ ctx.pbox[N + 1];
  5715. return {left: Xl, right: Xr};
  5716. }
  5717. function BlowFish_Decrypt(ctx, left, right){
  5718. let Xl = left;
  5719. let Xr = right;
  5720. let temp;
  5721. for(let i = N + 1; i > 1; --i){
  5722. Xl = Xl ^ ctx.pbox[i];
  5723. Xr = F(ctx, Xl) ^ Xr;
  5724. temp = Xl;
  5725. Xl = Xr;
  5726. Xr = temp;
  5727. }
  5728. temp = Xl;
  5729. Xl = Xr;
  5730. Xr = temp;
  5731. Xr = Xr ^ ctx.pbox[1];
  5732. Xl = Xl ^ ctx.pbox[0];
  5733. return {left: Xl, right: Xr};
  5734. }
  5735. /**
  5736. * Initialization ctx's pbox and sbox.
  5737. *
  5738. * @param {Object} ctx The object has pbox and sbox.
  5739. * @param {Array} key An array of 32-bit words.
  5740. * @param {int} keysize The length of the key.
  5741. *
  5742. * @example
  5743. *
  5744. * BlowFishInit(BLOWFISH_CTX, key, 128/32);
  5745. */
  5746. function BlowFishInit(ctx, key, keysize)
  5747. {
  5748. for(let Row = 0; Row < 4; Row++)
  5749. {
  5750. ctx.sbox[Row] = [];
  5751. for(let Col = 0; Col < 256; Col++)
  5752. {
  5753. ctx.sbox[Row][Col] = ORIG_S[Row][Col];
  5754. }
  5755. }
  5756. let keyIndex = 0;
  5757. for(let index = 0; index < N + 2; index++)
  5758. {
  5759. ctx.pbox[index] = ORIG_P[index] ^ key[keyIndex];
  5760. keyIndex++;
  5761. if(keyIndex >= keysize)
  5762. {
  5763. keyIndex = 0;
  5764. }
  5765. }
  5766. let Data1 = 0;
  5767. let Data2 = 0;
  5768. let res = 0;
  5769. for(let i = 0; i < N + 2; i += 2)
  5770. {
  5771. res = BlowFish_Encrypt(ctx, Data1, Data2);
  5772. Data1 = res.left;
  5773. Data2 = res.right;
  5774. ctx.pbox[i] = Data1;
  5775. ctx.pbox[i + 1] = Data2;
  5776. }
  5777. for(let i = 0; i < 4; i++)
  5778. {
  5779. for(let j = 0; j < 256; j += 2)
  5780. {
  5781. res = BlowFish_Encrypt(ctx, Data1, Data2);
  5782. Data1 = res.left;
  5783. Data2 = res.right;
  5784. ctx.sbox[i][j] = Data1;
  5785. ctx.sbox[i][j + 1] = Data2;
  5786. }
  5787. }
  5788. return true;
  5789. }
  5790. /**
  5791. * Blowfish block cipher algorithm.
  5792. */
  5793. var Blowfish = C_algo.Blowfish = BlockCipher.extend({
  5794. _doReset: function () {
  5795. // Skip reset of nRounds has been set before and key did not change
  5796. if (this._keyPriorReset === this._key) {
  5797. return;
  5798. }
  5799. // Shortcuts
  5800. var key = this._keyPriorReset = this._key;
  5801. var keyWords = key.words;
  5802. var keySize = key.sigBytes / 4;
  5803. //Initialization pbox and sbox
  5804. BlowFishInit(BLOWFISH_CTX, keyWords, keySize);
  5805. },
  5806. encryptBlock: function (M, offset) {
  5807. var res = BlowFish_Encrypt(BLOWFISH_CTX, M[offset], M[offset + 1]);
  5808. M[offset] = res.left;
  5809. M[offset + 1] = res.right;
  5810. },
  5811. decryptBlock: function (M, offset) {
  5812. var res = BlowFish_Decrypt(BLOWFISH_CTX, M[offset], M[offset + 1]);
  5813. M[offset] = res.left;
  5814. M[offset + 1] = res.right;
  5815. },
  5816. blockSize: 64/32,
  5817. keySize: 128/32,
  5818. ivSize: 64/32
  5819. });
  5820. /**
  5821. * Shortcut functions to the cipher's object interface.
  5822. *
  5823. * @example
  5824. *
  5825. * var ciphertext = CryptoJS.Blowfish.encrypt(message, key, cfg);
  5826. * var plaintext = CryptoJS.Blowfish.decrypt(ciphertext, key, cfg);
  5827. */
  5828. C.Blowfish = BlockCipher._createHelper(Blowfish);
  5829. }());
  5830. return CryptoJS;
  5831. }));