18035d2319d076299959b31ece20c3f1eb7c73d7.svn-base 158 KB

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