星火管控前端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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