crypto-js.js 206 KB

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