crypto-js.js 185 KB

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