├── .gitignore ├── package.json ├── LICENSE ├── README.md ├── upclient.js └── sjcl.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "upclient", 3 | "version": "0.0.1", 4 | "description": "Command-line client to the upload pastebin", 5 | "main": "upclient.js", 6 | "preferGlobal": "true", 7 | "bin": { 8 | "up": "upclient.js" 9 | }, 10 | "author": "Keith Morrow", 11 | "dependencies": { 12 | "form-data": "*", 13 | "mime": "*", 14 | "mmmagic": "*", 15 | "snack-cli": "*", 16 | "string": "*" 17 | }, 18 | "engines": { 19 | "node": "*" 20 | }, 21 | "license": "MIT" 22 | } 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Keith Morrow 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Up, the Up1 command-line client 2 | 3 | Usage: up [options] [files] 4 | 5 | Upload files and text to an Up1 based pastebin. If no argument is specified, stdin is assumed. 6 | 7 | Options: 8 | -b, --binary force application/octet-stream (for downloadable file) 9 | -t, --text force text/plain (for pastebin) 10 | -f, --file force file name for stdin based inputs 11 | -m, --mime force given mime type (default: detect) 12 | -s, --server specify Up1 server (default: https://up1.ca) 13 | -k, --apikey specify server api key (default: c61540b5ceecd05092799f936e27755f) 14 | -d, --delurl print the deletion url 15 | --version display version information and exit 16 | --help display this help and exit 17 | 18 | 19 | ### Usage examples 20 | 21 | Paste command output to Up1: 22 | 23 | ps aux | up 24 | 25 | Copy an image file to Up1: 26 | 27 | up image.png 28 | 29 | Take a screenshot (using a selection rectangle), send it to Up1, and put the result link on the clipboard: 30 | 31 | import png:- | up | xsel -b 32 | 33 | Do the same as above, but also notify when complete: 34 | 35 | import png:- | up | tee >(xsel -b) >(xargs notify-send "Upload Complete") 36 | 37 | ### Environment Variables 38 | 39 | Some options can also be configured via environment variables. Command line options take precedence over environment variables. 40 | 41 | UP1_SERVER: equivalent to --server 42 | UP1_APIKEY: equivalent to --apikey 43 | UP1_DELURL: equivalent to --delurl when set to "1" 44 | 45 | For example, the following in a bash shell: 46 | 47 | export UP1_SERVER="https://example.com" 48 | export UP1_DELURL=1 49 | echo foo bar | up 50 | 51 | is equivalent to: 52 | 53 | echo foo bar | up -s "https://example.com" -d 54 | 55 | ### Up1 56 | 57 | For more information on Up1, view the README at https://github.com/Upload/Up1 58 | -------------------------------------------------------------------------------- /upclient.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | "use strict"; 3 | var sjcl = require('./sjcl.js'); 4 | var https = require('https'); 5 | var http = require('http'); 6 | var crypto = require('crypto'); 7 | var FormData = require('form-data'); 8 | var mmm = require('mmmagic'); 9 | var mime = require('mime'); 10 | var fs = require('fs'); 11 | var cli = require('snack-cli'); 12 | var path = require('path'); 13 | var S = require('string'); 14 | S.extendPrototype(); 15 | const { URL } = require('url'); 16 | 17 | const up1_server_default = "https://up1.ca"; 18 | const up1_apikey_default = "c61540b5ceecd05092799f936e27755f"; 19 | 20 | var argv = cli 21 | .name('up') 22 | .version('0.1') 23 | .usage('[options] [files]') 24 | .description('Upload files and text to an Up1 based pastebin. If no argument is specified, stdin is assumed.') 25 | .option('-b, --binary', 'force application/octet-stream', false) 26 | .option('-t, --text', 'force text/plain', false) 27 | .option('-f, --file ', 'force file name for stdin based inputs', false) 28 | .option('-m, --mime ', 'force given mime type', 'detect') 29 | .option('-s, --server ', 'specify Up1 server', (process.env.UP1_SERVER || up1_server_default) ) 30 | .option('-k, --apikey ', 'specify server api key', (process.env.UP1_APIKEY || up1_apikey_default) ) 31 | .option('-d, --delurl', 'print the deletion url', ((process.env.UP1_DELURL == 1) || false) ) 32 | .parse(); 33 | 34 | const uphost = new URL(argv.server); 35 | 36 | function parametersfrombits(seed) { 37 | var out = sjcl.hash.sha512.hash(seed) 38 | return { 39 | 'seed': seed, 40 | 'key': sjcl.bitArray.bitSlice(out, 0, 256), 41 | 'iv': sjcl.bitArray.bitSlice(out, 256, 384), 42 | 'ident': sjcl.bitArray.bitSlice(out, 384, 512) 43 | } 44 | } 45 | 46 | function parameters(seed) { 47 | if (typeof seed == 'string') { 48 | seed = sjcl.codec.base64url.toBits(seed) 49 | } else { 50 | seed = sjcl.codec.bytes.toBits(seed) 51 | } 52 | return parametersfrombits(seed) 53 | } 54 | 55 | function encrypt(file, seed, id) { 56 | var params = parameters(seed) 57 | var uarr = new Uint8Array(file) 58 | var before = sjcl.codec.bytes.toBits(uarr) 59 | var prp = new sjcl.cipher.aes(params.key) 60 | var after = sjcl.arrayBuffer.ccm.compat_encrypt(prp, before, params.iv) 61 | var afterarray = new Buffer(sjcl.codec.bytes.fromBits(after)) 62 | return { 63 | 'id': id, 64 | 'seed': sjcl.codec.base64url.fromBits(params.seed), 65 | 'ident': sjcl.codec.base64url.fromBits(params.ident), 66 | 'encrypted': afterarray 67 | }; 68 | } 69 | 70 | function decrypt(file, seed, id) { 71 | var params = parameters(seed) 72 | var uarr = new Uint8Array(file) 73 | var before = sjcl.codec.bytes.toBits(uarr); 74 | var prp = new sjcl.cipher.aes(params.key); 75 | var after = sjcl.arrayBuffer.ccm.compat_decrypt(prp, before, params.iv); 76 | var afterarray = new Uint8Array(sjcl.codec.bytes.fromBits(after)); 77 | 78 | var header = '' 79 | 80 | var headerview = new DataView(afterarray.buffer) 81 | 82 | var i = 0; 83 | for (; ; i++) { 84 | var num = headerview.getUint16(i * 2, false) 85 | if (num == 0) { 86 | break; 87 | } 88 | header += String.fromCharCode(num); 89 | } 90 | 91 | console.log(header) 92 | 93 | var header = JSON.parse(header) 94 | 95 | var data = new Blob([afterarray]) 96 | 97 | postMessage({ 98 | 'id': id, 99 | 'header': header, 100 | 'decrypted': data.slice((i * 2) + 2, data.size, header.mime) 101 | }) 102 | } 103 | 104 | function ident(seed, id) { 105 | var params = parameters(seed) 106 | postMessage({ 107 | 'id': id, 108 | 'ident': sjcl.codec.base64url.fromBits(params.ident) 109 | }) 110 | } 111 | 112 | 113 | function str2ab(str) { 114 | var buf = new Buffer(str.length*2); 115 | for (var i = 0, strLen = str.length; i < strLen; i++) { 116 | buf.writeUInt16BE(str.charCodeAt(i), i*2); 117 | } 118 | return buf; 119 | } 120 | 121 | function doUpload(data, name, type) { 122 | var seed = new Uint8Array(16); 123 | seed.set(crypto.randomBytes(seed.length)); 124 | 125 | var header = JSON.stringify({ 126 | 'mime': type, 127 | 'name': name 128 | }) 129 | 130 | var zero = new Buffer([0,0]); 131 | var blob = Buffer.concat([str2ab(header), zero, Buffer(data)]) 132 | 133 | var result = encrypt(blob, seed, 0); 134 | 135 | 136 | var formdata = new FormData() 137 | formdata.append('api_key', argv.apikey) 138 | formdata.append('ident', result.ident) 139 | formdata.append('file', result.encrypted, {filename: 'file', contentType: 'text/plain'}) 140 | 141 | if ( uphost.protocol === "https:" ) { 142 | var req = https.request({ 143 | host: uphost.hostname, 144 | port: uphost.port, 145 | path: '/up', 146 | method: 'POST', 147 | headers: formdata.getHeaders() 148 | }); 149 | } else if ( uphost.protocol === "http:" ) { 150 | var req = http.request({ 151 | host: uphost.hostname, 152 | port: uphost.port, 153 | path: '/up', 154 | method: 'POST', 155 | headers: formdata.getHeaders() 156 | }); 157 | } 158 | 159 | 160 | formdata.pipe(req); 161 | 162 | req.on('error', (err) => { 163 | console.error(err); 164 | }); 165 | 166 | req.on('response', function(res) { 167 | res.setEncoding('utf8'); 168 | var data_out = ''; 169 | res.on('data', function(chunk) { 170 | data_out += chunk; 171 | }); 172 | res.on('end', function() { 173 | data_out = JSON.parse(data_out); 174 | var res_url = uphost.origin+"/#"+result.seed; 175 | var del_url = uphost.origin+"/del?delkey="+data_out.delkey+"&ident="+result.ident; 176 | console.log(res_url); 177 | argv.delurl && console.log(del_url); 178 | }); 179 | }); 180 | 181 | req.end(); 182 | } 183 | 184 | function validateMimeType(type, buf, cb) { 185 | var guess = null; 186 | if (argv.binary) 187 | guess = "application/octet-stream"; 188 | else if (argv.text) 189 | guess = "text/plain"; 190 | else if (argv.mime != "detect") 191 | guess = argv.mime; 192 | else if (type.startsWith("audio") || type.startsWith("video") || type.startsWith("text") || type.startsWith("image")) 193 | guess = type; 194 | 195 | if (guess != null) { 196 | cb(guess); 197 | return; 198 | } 199 | var magic = new mmm.Magic(mmm.MAGIC_MIME_ENCODING); 200 | magic.detect(buf, function(err, result) { 201 | cb(result == "binary" ? "application/octet-stream" : "text/plain"); 202 | }); 203 | } 204 | 205 | var rndbuf = crypto.prng(1024); 206 | for (var i = 0; i < 256; i++) { 207 | sjcl.random.addEntropy(rndbuf.readInt32LE(i*4), 32, "prng"); 208 | } 209 | 210 | if (argv.args.length > 0) { 211 | argv.args.forEach(function (val, idx, arr) { 212 | var buffer = fs.readFileSync(val); 213 | validateMimeType(mime.lookup(val), buffer, function(mimeType) { 214 | doUpload(buffer, path.basename(val), mimeType); 215 | }); 216 | }); 217 | } else { 218 | var buffer = fs.readFileSync('/dev/stdin'); 219 | var magic = new mmm.Magic(mmm.MAGIC_MIME_TYPE); 220 | 221 | magic.detect(buffer, function (err, result) { 222 | validateMimeType(result, buffer, function(mimeType) { 223 | var ext = mime.extension(result); 224 | doUpload(buffer, argv.file ? argv.file : "Pasted." + ext, mimeType); 225 | }); 226 | 227 | }); 228 | } 229 | -------------------------------------------------------------------------------- /sjcl.js: -------------------------------------------------------------------------------- 1 | "use strict";function r(a){throw a;}var s=void 0,v=!1;function H(){return function(){}} 2 | var sjcl={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(a){this.toString=function(){return"CORRUPT: "+this.message};this.message=a},invalid:function(a){this.toString=function(){return"INVALID: "+this.message};this.message=a},bug:function(a){this.toString=function(){return"BUG: "+this.message};this.message=a},notReady:function(a){this.toString=function(){return"NOT READY: "+this.message};this.message=a}}}; 3 | "undefined"!==typeof module&&module.exports&&(module.exports=sjcl);"function"===typeof define&&define([],function(){return sjcl}); 4 | sjcl.cipher.aes=function(a){this.l[0][0][0]||this.q();var b,c,d,e,g=this.l[0][4],f=this.l[1];b=a.length;var h=1;4!==b&&(6!==b&&8!==b)&&r(new sjcl.exception.invalid("invalid aes key size"));this.b=[d=a.slice(0),e=[]];for(a=b;a<4*b+28;a++){c=d[a-1];if(0===a%b||8===b&&4===a%b)c=g[c>>>24]<<24^g[c>>16&255]<<16^g[c>>8&255]<<8^g[c&255],0===a%b&&(c=c<<8^c>>>24^h<<24,h=h<<1^283*(h>>7));d[a]=d[a-b]^c}for(b=0;a;b++,a--)c=d[b&3?a:a-4],e[b]=4>=a||4>b?c:f[0][g[c>>>24]]^f[1][g[c>>16&255]]^f[2][g[c>>8&255]]^f[3][g[c& 5 | 255]]}; 6 | sjcl.cipher.aes.prototype={encrypt:function(a){return aa(this,a,0)},decrypt:function(a){return aa(this,a,1)},l:[[[],[],[],[],[]],[[],[],[],[],[]]],q:function(){var a=this.l[0],b=this.l[1],c=a[4],d=b[4],e,g,f,h=[],k=[],n,l,m,p;for(e=0;0x100>e;e++)k[(h[e]=e<<1^283*(e>>7))^e]=e;for(g=f=0;!c[g];g^=n||1,f=k[f]||1){m=f^f<<1^f<<2^f<<3^f<<4;m=m>>8^m&255^99;c[g]=m;d[m]=g;l=h[e=h[n=h[g]]];p=0x1010101*l^0x10001*e^0x101*n^0x1010100*g;l=0x101*h[m]^0x1010100*m;for(e=0;4>e;e++)a[e][g]=l=l<<24^l>>>8,b[e][m]=p=p<<24^p>>>8}for(e= 7 | 0;5>e;e++)a[e]=a[e].slice(0),b[e]=b[e].slice(0)}}; 8 | function aa(a,b,c){4!==b.length&&r(new sjcl.exception.invalid("invalid aes block size"));var d=a.b[c],e=b[0]^d[0],g=b[c?3:1]^d[1],f=b[2]^d[2];b=b[c?1:3]^d[3];var h,k,n,l=d.length/4-2,m,p=4,w=[0,0,0,0];h=a.l[c];a=h[0];var D=h[1],B=h[2],E=h[3],C=h[4];for(m=0;m>>24]^D[g>>16&255]^B[f>>8&255]^E[b&255]^d[p],k=a[g>>>24]^D[f>>16&255]^B[b>>8&255]^E[e&255]^d[p+1],n=a[f>>>24]^D[b>>16&255]^B[e>>8&255]^E[g&255]^d[p+2],b=a[b>>>24]^D[e>>16&255]^B[g>>8&255]^E[f&255]^d[p+3],p+=4,e=h,g=k,f=n;for(m=0;4> 9 | m;m++)w[c?3&-m:m]=C[e>>>24]<<24^C[g>>16&255]<<16^C[f>>8&255]<<8^C[b&255]^d[p++],h=e,e=g,g=f,f=b,b=h;return w} 10 | sjcl.bitArray={bitSlice:function(a,b,c){a=sjcl.bitArray.M(a.slice(b/32),32-(b&31)).slice(1);return c===s?a:sjcl.bitArray.clamp(a,c-b)},extract:function(a,b,c){var d=Math.floor(-b-c&31);return((b+c-1^b)&-32?a[b/32|0]<<32-d^a[b/32+1|0]>>>d:a[b/32|0]>>>d)&(1<>b-1,1));return a},partial:function(a,b,c){return 32===a?b:(c?b|0:b<<32-a)+0x10000000000*a},getPartial:function(a){return Math.round(a/0x10000000000)||32},equal:function(a,b){if(sjcl.bitArray.bitLength(a)!==sjcl.bitArray.bitLength(b))return v;var c=0,d;for(d=0;d>>b),c=a[e]<<32-b;e=a.length?a[a.length-1]:0;a=sjcl.bitArray.getPartial(e);d.push(sjcl.bitArray.partial(b+a&31,32>>24|c>>>8&0xff00|(c&0xff00)<<8|c<<24;return a}}; 13 | sjcl.codec.utf8String={fromBits:function(a){var b="",c=sjcl.bitArray.bitLength(a),d,e;for(d=0;d>>24),e<<=8;return decodeURIComponent(escape(b))},toBits:function(a){a=unescape(encodeURIComponent(a));var b=[],c,d=0;for(c=0;c>>e)>>>26),6>e?(f=a[c]<<6-e,e+=26,c++):(f<<=6,e-=6);for(;d.length&3&&!b;)d+="=";return d},toBits:function(a,b){a=a.replace(/\s|=/g,"");var c=[],d,e=0,g=sjcl.codec.base64.I,f=0,h;b&&(g=g.substr(0,62)+"-_");for(d=0;dh&&r(new sjcl.exception.invalid("this isn't base64!")),26>>e),f=h<<32-e):(e+=6,f^=h<<32-e);e&56&&c.push(sjcl.bitArray.partial(e&56,f,1));return c}};sjcl.codec.base64url={fromBits:function(a){return sjcl.codec.base64.fromBits(a,1,1)},toBits:function(a){return sjcl.codec.base64.toBits(a,1)}}; 16 | sjcl.codec.bytes={fromBits:function(a){var b=[],c=sjcl.bitArray.bitLength(a),d,e;for(d=0;d>>24),e<<=8;return b},toBits:function(a){var b=[],c,d=0;for(c=0;cb;c++){for(d=2;d*d<=c;d++)if(0===c%d)continue a;8>b&&(this.i[b]=a(Math.pow(c,0.5)));this.b[b]=a(Math.pow(c,1/3));b++}},n:function(a){var b,c,d=a.slice(0),e=this.e,g=this.b,f=e[0],h=e[1],k=e[2],n=e[3],l=e[4],m=e[5],p=e[6],w=e[7];for(a=0;64>a;a++)16>a?b=d[a]:(b=d[a+1&15],c=d[a+14&15],b=d[a&15]=(b>>>7^b>>>18^b>>>3^ 19 | b<<25^b<<14)+(c>>>17^c>>>19^c>>>10^c<<15^c<<13)+d[a&15]+d[a+9&15]|0),b=b+w+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(p^l&(m^p))+g[a],w=p,p=m,m=l,l=n+b|0,n=k,k=h,h=f,f=b+(h&k^n&(h^k))+(h>>>2^h>>>13^h>>>22^h<<30^h<<19^h<<10)|0;e[0]=e[0]+f|0;e[1]=e[1]+h|0;e[2]=e[2]+k|0;e[3]=e[3]+n|0;e[4]=e[4]+l|0;e[5]=e[5]+m|0;e[6]=e[6]+p|0;e[7]=e[7]+w|0}};sjcl.hash.sha512=function(a){this.b[0]||this.q();a?(this.e=a.e.slice(0),this.d=a.d.slice(0),this.c=a.c):this.reset()};sjcl.hash.sha512.hash=function(a){return(new sjcl.hash.sha512).update(a).finalize()}; 20 | sjcl.hash.sha512.prototype={blockSize:1024,reset:function(){this.e=this.i.slice(0);this.d=[];this.c=0;return this},update:function(a){"string"===typeof a&&(a=sjcl.codec.utf8String.toBits(a));var b,c=this.d=sjcl.bitArray.concat(this.d,a);b=this.c;a=this.c=b+sjcl.bitArray.bitLength(a);for(b=1024+b&-1024;b<=a;b+=1024)this.n(c.splice(0,32));return this},finalize:function(){var a,b=this.d,c=this.e,b=sjcl.bitArray.concat(b,[sjcl.bitArray.partial(1,1)]);for(a=b.length+4;a&31;a++)b.push(0);b.push(0);b.push(0); 21 | b.push(Math.floor(this.c/0x100000000));for(b.push(this.c|0);b.length;)this.n(b.splice(0,32));this.reset();return c},i:[],T:[12372232,13281083,9762859,1914609,15106769,4090911,4308331,8266105],b:[],V:[2666018,15689165,5061423,9034684,4764984,380953,1658779,7176472,197186,7368638,14987916,16757986,8096111,1480369,13046325,6891156,15813330,5187043,9229749,11312229,2818677,10937475,4324308,1135541,6741931,11809296,16458047,15666916,11046850,698149,229999,945776,13774844,2541862,12856045,9810911,11494366, 22 | 7844520,15576806,8533307,15795044,4337665,16291729,5553712,15684120,6662416,7413802,12308920,13816008,4303699,9366425,10176680,13195875,4295371,6546291,11712675,15708924,1519456,15772530,6568428,6495784,8568297,13007125,7492395,2515356,12632583,14740254,7262584,1535930,13146278,16321966,1853211,294276,13051027,13221564,1051980,4080310,6651434,14088940,4675607],q:function(){function a(a){return 0x100000000*(a-Math.floor(a))|0}function b(a){return 0x10000000000*(a-Math.floor(a))&255}var c=0,d=2,e;a:for(;80> 23 | c;d++){for(e=2;e*e<=d;e++)if(0===d%e)continue a;8>c&&(this.i[2*c]=a(Math.pow(d,0.5)),this.i[2*c+1]=b(Math.pow(d,0.5))<<24|this.T[c]);this.b[2*c]=a(Math.pow(d,1/3));this.b[2*c+1]=b(Math.pow(d,1/3))<<24|this.V[c];c++}},n:function(a){var b,c,d=a.slice(0),e=this.e,g=this.b,f=e[0],h=e[1],k=e[2],n=e[3],l=e[4],m=e[5],p=e[6],w=e[7],D=e[8],B=e[9],E=e[10],C=e[11],ga=e[12],R=e[13],ha=e[14],S=e[15],x=f,t=h,I=k,F=n,J=l,G=m,X=p,K=w,y=D,u=B,T=E,L=C,U=ga,M=R,Y=ha,N=S;for(a=0;80>a;a++){if(16>a)b=d[2*a],c=d[2*a+1]; 24 | else{c=d[2*(a-15)];var q=d[2*(a-15)+1];b=(q<<31|c>>>1)^(q<<24|c>>>8)^c>>>7;var z=(c<<31|q>>>1)^(c<<24|q>>>8)^(c<<25|q>>>7);c=d[2*(a-2)];var A=d[2*(a-2)+1],q=(A<<13|c>>>19)^(c<<3|A>>>29)^c>>>6,A=(c<<13|A>>>19)^(A<<3|c>>>29)^(c<<26|A>>>6),Z=d[2*(a-7)],$=d[2*(a-16)],O=d[2*(a-16)+1];c=z+d[2*(a-7)+1];b=b+Z+(c>>>0>>0?1:0);c+=A;b+=q+(c>>>0>>0?1:0);c+=O;b+=$+(c>>>0>>0?1:0)}d[2*a]=b|=0;d[2*a+1]=c|=0;var Z=y&T^~y&U,ia=u&L^~u&M,A=x&I^x&J^I&J,ma=t&F^t&G^F&G,$=(t<<4|x>>>28)^(x<<30|t>>>2)^(x<<25|t>>>7), 25 | O=(x<<4|t>>>28)^(t<<30|x>>>2)^(t<<25|x>>>7),na=g[2*a],ja=g[2*a+1],q=N+((y<<18|u>>>14)^(y<<14|u>>>18)^(u<<23|y>>>9)),z=Y+((u<<18|y>>>14)^(u<<14|y>>>18)^(y<<23|u>>>9))+(q>>>0>>0?1:0),q=q+ia,z=z+(Z+(q>>>0>>0?1:0)),q=q+ja,z=z+(na+(q>>>0>>0?1:0)),q=q+c|0,z=z+(b+(q>>>0>>0?1:0));c=O+ma;b=$+A+(c>>>0>>0?1:0);Y=U;N=M;U=T;M=L;T=y;L=u;u=K+q|0;y=X+z+(u>>>0>>0?1:0)|0;X=J;K=G;J=I;G=F;I=x;F=t;t=q+c|0;x=z+b+(t>>>0>>0?1:0)|0}h=e[1]=h+t|0;e[0]=f+x+(h>>>0>>0?1:0)|0;n=e[3]=n+F|0;e[2]=k+I+(n>>> 26 | 0>>0?1:0)|0;m=e[5]=m+G|0;e[4]=l+J+(m>>>0>>0?1:0)|0;w=e[7]=w+K|0;e[6]=p+X+(w>>>0>>0?1:0)|0;B=e[9]=B+u|0;e[8]=D+y+(B>>>0>>0?1:0)|0;C=e[11]=C+L|0;e[10]=E+T+(C>>>0>>0?1:0)|0;R=e[13]=R+M|0;e[12]=ga+U+(R>>>0>>0?1:0)|0;S=e[15]=S+N|0;e[14]=ha+Y+(S>>>0>>0?1:0)|0}}; 27 | sjcl.mode.ccm={name:"ccm",s:[],listenProgress:function(a){sjcl.mode.ccm.s.push(a)},unListenProgress:function(a){a=sjcl.mode.ccm.s.indexOf(a);-1k&&r(new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"));for(g=2;4>g&&n>>>8*g;g++);g<15-k&&(g=15-k);c=h.clamp(c,8*(15- 28 | g));b=sjcl.mode.ccm.o(a,b,c,d,e,g);f=sjcl.mode.ccm.p(a,f,c,b,e,g);return h.concat(f.data,f.tag)},decrypt:function(a,b,c,d,e){e=e||64;d=d||[];var g=sjcl.bitArray,f=g.bitLength(c)/8,h=g.bitLength(b),k=g.clamp(b,h-e),n=g.bitSlice(b,h-e),h=(h-e)/8;7>f&&r(new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"));for(b=2;4>b&&h>>>8*b;b++);b<15-f&&(b=15-f);c=g.clamp(c,8*(15-b));k=sjcl.mode.ccm.p(a,k,c,n,e,b);a=sjcl.mode.ccm.o(a,k.data,c,d,e,b);g.equal(k.tag,a)||r(new sjcl.exception.corrupt("ccm: tag doesn't match")); 29 | return k.data},K:function(a,b,c,d,e,g){var f=[],h=sjcl.bitArray,k=h.u;d=[h.partial(8,(b.length?64:0)|d-2<<2|g-1)];d=h.concat(d,c);d[3]|=e;d=a.encrypt(d);if(b.length){c=h.bitLength(b)/8;65279>=c?f=[h.partial(16,c)]:0xffffffff>=c&&(f=h.concat([h.partial(16,65534)],[c]));f=h.concat(f,b);for(b=0;be||16l&&(sjcl.mode.ccm.H(f/ 31 | k),l+=m),c[3]++,e=a.encrypt(c),b[f]^=e[0],b[f+1]^=e[1],b[f+2]^=e[2],b[f+3]^=e[3];return{tag:d,data:h.clamp(b,n)}}};sjcl.prng=function(a){this.f=[new sjcl.hash.sha256];this.j=[0];this.F=0;this.t={};this.D=0;this.J={};this.L=this.g=this.k=this.S=0;this.b=[0,0,0,0,0,0,0,0];this.h=[0,0,0,0];this.B=s;this.C=a;this.r=v;this.A={progress:{},seeded:{}};this.m=this.R=0;this.v=1;this.w=2;this.O=0x10000;this.G=[0,48,64,96,128,192,0x100,384,512,768,1024];this.P=3E4;this.N=80}; 32 | sjcl.prng.prototype={randomWords:function(a,b){var c=[],d;d=this.isReady(b);var e;d===this.m&&r(new sjcl.exception.notReady("generator isn't seeded"));if(d&this.w){d=!(d&this.v);e=[];var g=0,f;this.L=e[0]=(new Date).valueOf()+this.P;for(f=0;16>f;f++)e.push(0x100000000*Math.random()|0);for(f=0;f=1<this.k&&(this.k=g);this.F++; 33 | this.b=sjcl.hash.sha256.hash(this.b.concat(e));this.B=new sjcl.cipher.aes(this.b);for(d=0;4>d&&!(this.h[d]=this.h[d]+1|0,this.h[d]);d++);}for(d=0;d>>=1;this.f[f].update([d,this.D++,2,b,g,a.length].concat(a))}break;case "string":b===s&&(b=a.length);this.f[f].update([d,this.D++,3,b,g,a.length]);this.f[f].update(a);break;default:k=1}k&&r(new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string"));this.j[f]+=b;this.g+=b;h===this.m&&(this.isReady()!==this.m&&da("seeded",Math.max(this.k,this.g)),da("progress",this.getProgress()))},isReady:function(a){a=this.G[a!==s?a:this.C];return this.k&&this.k>=a?this.j[0]> 36 | this.N&&(new Date).valueOf()>this.L?this.w|this.v:this.v:this.g>=a?this.w|this.m:this.m},getProgress:function(a){a=this.G[a?a:this.C];return this.k>=a?1:this.g>a?1:this.g/a},startCollectors:function(){this.r||(this.a={loadTimeCollector:P(this,this.W),mouseCollector:P(this,this.X),keyboardCollector:P(this,this.U),accelerometerCollector:P(this,this.Q),touchCollector:P(this,this.Y)},window.addEventListener?(window.addEventListener("load",this.a.loadTimeCollector,v),window.addEventListener("mousemove", 37 | this.a.mouseCollector,v),window.addEventListener("keypress",this.a.keyboardCollector,v),window.addEventListener("devicemotion",this.a.accelerometerCollector,v),window.addEventListener("touchmove",this.a.touchCollector,v)):document.attachEvent?(document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector)):r(new sjcl.exception.bug("can't attach event")),this.r=!0)},stopCollectors:function(){this.r&& 38 | (window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,v),window.removeEventListener("mousemove",this.a.mouseCollector,v),window.removeEventListener("keypress",this.a.keyboardCollector,v),window.removeEventListener("devicemotion",this.a.accelerometerCollector,v),window.removeEventListener("touchmove",this.a.touchCollector,v)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress", 39 | this.a.keyboardCollector)),this.r=v)},addEventListener:function(a,b){this.A[a][this.R++]=b},removeEventListener:function(a,b){var c,d,e=this.A[a],g=[];for(d in e)e.hasOwnProperty(d)&&e[d]===b&&g.push(d);for(c=0;cb&&!(a.h[b]=a.h[b]+1|0,a.h[b]);b++);return a.B.encrypt(a.h)}function P(a,b){return function(){b.apply(a,arguments)}}sjcl.random=new sjcl.prng(6); 42 | a:try{var V,ea,W,fa;if(fa="undefined"!==typeof module){var ka;if(ka=module.exports){var la;try{la=require("crypto")}catch(oa){la=null}ka=(ea=la)&&ea.randomBytes}fa=ka}if(fa)V=ea.randomBytes(128),V=new Uint32Array((new Uint8Array(V)).buffer),sjcl.random.addEntropy(V,1024,"crypto['randomBytes']");else if("undefined"!==typeof window&&"undefined"!==typeof Uint32Array){W=new Uint32Array(32);if(window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(W);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(W); 43 | else break a;sjcl.random.addEntropy(W,1024,"crypto['getRandomValues']")}}catch(pa){"undefined"!==typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(pa))}sjcl.arrayBuffer=sjcl.arrayBuffer||{};"undefined"===typeof ArrayBuffer&&function(a){a.ArrayBuffer=H();a.DataView=H()}(this); 44 | sjcl.arrayBuffer.ccm={mode:"ccm",defaults:{tlen:128},compat_encrypt:function(a,b,c,d,e){var g=sjcl.codec.arrayBuffer.fromBits(b,!0,16);b=sjcl.bitArray.bitLength(b)/8;d=d||[];a=sjcl.arrayBuffer.ccm.encrypt(a,g,c,d,e||64,b);c=sjcl.codec.arrayBuffer.toBits(a.ciphertext_buffer);c=sjcl.bitArray.clamp(c,8*b);return sjcl.bitArray.concat(c,a.tag)},compat_decrypt:function(a,b,c,d,e){e=e||64;d=d||[];var g=sjcl.bitArray,f=g.bitLength(b),h=g.clamp(b,f-e);b=g.bitSlice(b,f-e);h=sjcl.codec.arrayBuffer.fromBits(h, 45 | !0,16);a=sjcl.arrayBuffer.ccm.decrypt(a,h,c,b,d,e,(f-e)/8);return sjcl.bitArray.clamp(sjcl.codec.arrayBuffer.toBits(a),f-e)},encrypt:function(a,b,c,d,e,g){var f,h=sjcl.bitArray,k=h.bitLength(c)/8;d=d||[];e=e||sjcl.arrayBuffer.ccm.defaults.tlen;g=g||b.byteLength;e=Math.ceil(e/8);for(f=2;4>f&&g>>>8*f;f++);f<15-k&&(f=15-k);c=h.clamp(c,8*(15-f));d=sjcl.arrayBuffer.ccm.o(a,b,c,d,e,g,f);d=sjcl.arrayBuffer.ccm.p(a,b,c,d,e,f);return{ciphertext_buffer:b,tag:d}},decrypt:function(a,b,c,d,e,g,f){var h,k=sjcl.bitArray, 46 | n=k.bitLength(c)/8;e=e||[];g=g||sjcl.arrayBuffer.ccm.defaults.tlen;f=f||b.byteLength;g=Math.ceil(g/8);for(h=2;4>h&&f>>>8*h;h++);h<15-n&&(h=15-n);c=k.clamp(c,8*(15-h));d=sjcl.arrayBuffer.ccm.p(a,b,c,d,g,h);a=sjcl.arrayBuffer.ccm.o(a,b,c,e,g,f,h);sjcl.bitArray.equal(d,a)||r(new sjcl.exception.corrupt("ccm: tag doesn't match"));return b},o:function(a,b,c,d,e,g,f){c=sjcl.mode.ccm.K(a,d,c,e,g,f);if(0!==b.byteLength){for(d=new DataView(b);gm&&(sjcl.mode.ccm.H(l/b.byteLength),m+=p),n=a.encrypt(c), 48 | f=e.getUint32(l),h=e.getUint32(l+4),g=e.getUint32(l+8),k=e.getUint32(l+12),e.setUint32(l,f^n[0]),e.setUint32(l+4,h^n[1]),e.setUint32(l+8,g^n[2]),e.setUint32(l+12,k^n[3]),c[3]++,0===c[3]&&c[2]++}return d}};"undefined"===typeof ArrayBuffer&&function(a){a.ArrayBuffer=H();a.DataView=H()}(this); 49 | sjcl.codec.arrayBuffer={fromBits:function(a,b,c){var d;b=b==s?!0:b;c=c||8;if(0===a.length)return new ArrayBuffer(0);d=sjcl.bitArray.bitLength(a)/8;0!==sjcl.bitArray.bitLength(a)%8&&r(new sjcl.exception.invalid("Invalid bit size, must be divisble by 8 to fit in an arraybuffer correctly"));b&&0!==d%c&&(d+=c-d%c);c=new DataView(new ArrayBuffer(4*a.length));for(b=0;b