Commit cad9843a authored by Sascha Pfeiffer's avatar Sascha Pfeiffer

some more progress

Signed-off-by: default avatarSascha Pfeiffer <[email protected]>
parent 96349e0c
......@@ -245,14 +245,6 @@
----
## blakejs: Creative Commons CC0
Source: https://github.com/dcposch/blakejs
Creative Commons CC0. Ported from the reference C implementation in RFC 7693.
----
## js-sha512: MIT
Copyright 2014-2015 [email protected]
......
......@@ -105,7 +105,6 @@ var build = function(build_path, type) {
gulp.src([
"src/common/data/js/lib/ecma-nacl.min.js",
"src/common/data/js/lib/blake2b.js",
"src/common/data/js/lib/openpgp.min.js",
"src/common/data/js/lib/sha512.min.js",
"src/common/data/js/lib/sha256.min.js",
......@@ -150,6 +149,7 @@ var build = function(build_path, type) {
"src/common/data/js/main.js",
"src/webclient/data/js/service-worker-load.js",
"src/webclient/data/js/crypto-worker.js",
"src/common/data/js/directive/fileReader.js",
"src/common/data/js/directive/treeView.js",
......@@ -293,6 +293,7 @@ var build = function(build_path, type) {
'src/common/data/js/**/*',
'!src/common/data/js/google-analytics.js',
'!src/common/data/js/service-worker-load.js',
'!src/common/data/js/crypto-worker.js',
'!src/common/data/js/service/browser-client.js'
])
.pipe(gulp.dest(path.join(build_path, 'js')));
......
......@@ -98,7 +98,6 @@
<!-- build:build_min_js -->
<!-- Start of scripts -->
<script src="js/lib/ecma-nacl.min.js" type="text/javascript"></script>
<script src="js/lib/blake2b.js" type="text/javascript"></script>
<script src="js/lib/openpgp.min.js" type="text/javascript"></script>
<script src="js/lib/sha512.min.js" type="text/javascript"></script>
<script src="js/lib/sha256.min.js" type="text/javascript"></script>
......@@ -146,6 +145,7 @@
<script src="js/main.js" type="application/javascript"></script>
<script src="js/service-worker-load.js" type="application/javascript"></script>
<script src="js/crypto-worker.js" type="application/javascript"></script>
<script src="js/directive/fileReader.js" type="application/javascript"></script>
<script src="js/directive/treeView.js" type="application/javascript"></script>
......
......@@ -25,7 +25,6 @@
<!-- build:build_min_js -->
<!-- Start of scripts -->
<script src="js/lib/ecma-nacl.min.js" type="text/javascript"></script>
<script src="js/lib/blake2b.js" type="text/javascript"></script>
<script src="js/lib/openpgp.min.js" type="text/javascript"></script>
<script src="js/lib/sha512.min.js" type="text/javascript"></script>
<script src="js/lib/sha256.min.js" type="text/javascript"></script>
......@@ -73,6 +72,7 @@
<script src="js/main.js" type="application/javascript"></script>
<script src="js/service-worker-load.js" type="application/javascript"></script>
<script src="js/crypto-worker.js" type="application/javascript"></script>
<script src="js/directive/fileReader.js" type="application/javascript"></script>
<script src="js/directive/treeView.js" type="application/javascript"></script>
......
......@@ -331,7 +331,6 @@
<!-- build:build_min_js -->
<!-- Start of scripts -->
<script src="js/lib/ecma-nacl.min.js" type="text/javascript"></script>
<script src="js/lib/blake2b.js" type="text/javascript"></script>
<script src="js/lib/openpgp.min.js" type="text/javascript"></script>
<script src="js/lib/sha512.min.js" type="text/javascript"></script>
<script src="js/lib/sha256.min.js" type="text/javascript"></script>
......@@ -379,6 +378,7 @@
<script src="js/main.js" type="application/javascript"></script>
<script src="js/service-worker-load.js" type="application/javascript"></script>
<script src="js/crypto-worker.js" type="application/javascript"></script>
<script src="js/directive/fileReader.js" type="application/javascript"></script>
<script src="js/directive/treeView.js" type="application/javascript"></script>
......
......@@ -70,7 +70,6 @@
<!-- build:build_min_js -->
<!-- Start of scripts -->
<script src="js/lib/ecma-nacl.min.js" type="text/javascript"></script>
<script src="js/lib/blake2b.js" type="text/javascript"></script>
<script src="js/lib/openpgp.min.js" type="text/javascript"></script>
<script src="js/lib/sha512.min.js" type="text/javascript"></script>
<script src="js/lib/sha256.min.js" type="text/javascript"></script>
......@@ -118,6 +117,7 @@
<script src="js/main.js" type="application/javascript"></script>
<script src="js/service-worker-load.js" type="application/javascript"></script>
<script src="js/crypto-worker.js" type="application/javascript"></script>
<script src="js/directive/fileReader.js" type="application/javascript"></script>
<script src="js/directive/treeView.js" type="application/javascript"></script>
......
......@@ -252,6 +252,7 @@
<script src="js/main.js" type="application/javascript"></script>
<script src="js/service-worker-load.js" type="application/javascript"></script>
<script src="js/crypto-worker.js" type="application/javascript"></script>
<script src="js/directive/fileReader.js" type="application/javascript"></script>
<script src="js/directive/treeView.js" type="application/javascript"></script>
......
......@@ -98,7 +98,6 @@
<!-- build:build_min_js -->
<!-- Start of scripts -->
<script src="js/lib/ecma-nacl.min.js" type="text/javascript"></script>
<script src="js/lib/blake2b.js" type="text/javascript"></script>
<script src="js/lib/openpgp.min.js" type="text/javascript"></script>
<script src="js/lib/sha512.min.js" type="text/javascript"></script>
<script src="js/lib/sha256.min.js" type="text/javascript"></script>
......@@ -146,6 +145,7 @@
<script src="js/main.js" type="application/javascript"></script>
<script src="js/service-worker-load.js" type="application/javascript"></script>
<script src="js/crypto-worker.js" type="application/javascript"></script>
<script src="js/directive/fileReader.js" type="application/javascript"></script>
<script src="js/directive/treeView.js" type="application/javascript"></script>
......
......@@ -415,7 +415,6 @@
<!-- build:build_min_js -->
<!-- Start of scripts -->
<script src="js/lib/ecma-nacl.min.js" type="text/javascript"></script>
<script src="js/lib/blake2b.js" type="text/javascript"></script>
<script src="js/lib/openpgp.min.js" type="text/javascript"></script>
<script src="js/lib/sha512.min.js" type="text/javascript"></script>
<script src="js/lib/sha256.min.js" type="text/javascript"></script>
......@@ -463,6 +462,7 @@
<script src="js/main.js" type="application/javascript"></script>
<script src="js/service-worker-load.js" type="application/javascript"></script>
<script src="js/crypto-worker.js" type="application/javascript"></script>
<script src="js/directive/fileReader.js" type="application/javascript"></script>
<script src="js/directive/treeView.js" type="application/javascript"></script>
......
......@@ -26,6 +26,7 @@
$scope.state = {
open_requests: 0,
closed_request: 0,
percentage_complete: 0,
next_step: '',
processing: false
};
......@@ -54,8 +55,6 @@
}
});
console.log("activate");
itemBlueprint.register('upload_started', function(max){
$scope.state.processing = true;
$scope.state.open_requests = max;
......@@ -63,6 +62,7 @@
itemBlueprint.register('upload_step_complete', function(next_step){
$scope.state.closed_request = $scope.state.closed_request + 1;
$scope.state.percentage_complete = Math.round($scope.state.closed_request / $scope.state.open_requests * 1000) / 10;
$scope.state.next_step = next_step;
console.log("REGISTERED: " + next_step);
});
......@@ -82,6 +82,7 @@
$scope.submitted = false;
$scope.state.open_requests = 0;
$scope.state.closed_request = 0;
$scope.state.percentage_complete = 0;
$scope.state.next_step ='';
$scope.state.processing = false;
}
......
self.importScripts('lib/ecma-nacl.min.js');
var nacl = require('ecma-nacl');
function encrypt_file (data, k, n) {
data = new Uint8Array(data);
k = new Uint8Array(k);
n = new Uint8Array(n);
var encrypted_data = nacl.secret_box.formatWN.pack(data, n, k);
var encrypted_buffer = encrypted_data.buffer;
self.postMessage({kwargs: encrypted_buffer}, [encrypted_buffer]);
}
function decrypt_file(text, k) {
text = new Uint8Array(text);
k = new Uint8Array(k);
var decrypted_data = nacl.secret_box.formatWN.open(text, k);
var decrypted_buffer = decrypted_data.buffer;
decrypted_buffer = decrypted_buffer.slice(32,decrypted_buffer.byteLength);
self.postMessage({kwargs: decrypted_buffer}, [decrypted_buffer]);
}
self.onmessage = function (msg) {
switch (msg.data.job) {
case 'encrypt_file':
encrypt_file(msg.data.kwargs.data, msg.data.kwargs.k, msg.data.kwargs.n);
break;
case 'decrypt_file':
decrypt_file(msg.data.kwargs.text, msg.data.kwargs.k);
break;
default:
throw 'job could not be handled: ' + msg.data.job;
}
};
\ No newline at end of file
// Blake2B in pure Javascript
// Adapted from the reference implementation in RFC7693
// Ported to Javascript by DC - https://github.com/dcposch
(function() {
var _global = this;
// 64-bit unsigned addition
// Sets v[a,a+1] += v[b,b+1]
// v should be a Uint32Array
function ADD64AA(v, a, b) {
var o0 = v[a] + v[b];
var o1 = v[a + 1] + v[b + 1];
if (o0 >= 0x100000000) {
o1++
}
v[a] = o0;
v[a + 1] = o1
}
// 64-bit unsigned addition
// Sets v[a,a+1] += b
// b0 is the low 32 bits of b, b1 represents the high 32 bits
function ADD64AC(v, a, b0, b1) {
var o0 = v[a] + b0;
if (b0 < 0) {
o0 += 0x100000000
}
var o1 = v[a + 1] + b1;
if (o0 >= 0x100000000) {
o1++
}
v[a] = o0;
v[a + 1] = o1
}
// Little-endian byte access
function B2B_GET32(arr, i) {
return (arr[i] ^
(arr[i + 1] << 8) ^
(arr[i + 2] << 16) ^
(arr[i + 3] << 24))
}
// G Mixing function
// The ROTRs are inlined for speed
function B2B_G(a, b, c, d, ix, iy) {
var x0 = m[ix];
var x1 = m[ix + 1];
var y0 = m[iy];
var y1 = m[iy + 1];
ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s
ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits
var xor0 = v[d] ^ v[a];
var xor1 = v[d + 1] ^ v[a + 1];
v[d] = xor1;
v[d + 1] = xor0;
ADD64AA(v, c, d);
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits
xor0 = v[b] ^ v[c];
xor1 = v[b + 1] ^ v[c + 1];
v[b] = (xor0 >>> 24) ^ (xor1 << 8);
v[b + 1] = (xor1 >>> 24) ^ (xor0 << 8);
ADD64AA(v, a, b);
ADD64AC(v, a, y0, y1);
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits
xor0 = v[d] ^ v[a];
xor1 = v[d + 1] ^ v[a + 1];
v[d] = (xor0 >>> 16) ^ (xor1 << 16);
v[d + 1] = (xor1 >>> 16) ^ (xor0 << 16);
ADD64AA(v, c, d);
// v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits
xor0 = v[b] ^ v[c];
xor1 = v[b + 1] ^ v[c + 1];
v[b] = (xor1 >>> 31) ^ (xor0 << 1);
v[b + 1] = (xor0 >>> 31) ^ (xor1 << 1)
}
// Initialization Vector
var BLAKE2B_IV32 = new Uint32Array([
0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85,
0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A,
0xADE682D1, 0x510E527F, 0x2B3E6C1F, 0x9B05688C,
0xFB41BD6B, 0x1F83D9AB, 0x137E2179, 0x5BE0CD19
]);
var SIGMA8 = [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3
];
// These are offsets into a uint64 buffer.
// Multiply them all by 2 to make them offsets into a uint32 buffer,
// because this is Javascript and we don't have uint64s
var SIGMA82 = new Uint8Array(SIGMA8.map(function (x) {
return x * 2
}))
// Compression function. 'last' flag indicates last block.
// Note we're representing 16 uint64s as 32 uint32s
var v = new Uint32Array(32);
var m = new Uint32Array(32);
function blake2bCompress(ctx, last) {
var i = 0;
// init work variables
for (i = 0; i < 16; i++) {
v[i] = ctx.h[i];
v[i + 16] = BLAKE2B_IV32[i]
}
// low 64 bits of offset
v[24] = v[24] ^ ctx.t;
v[25] = v[25] ^ (ctx.t / 0x100000000);
// high 64 bits not supported, offset may not be higher than 2**53-1
// last block flag set ?
if (last) {
v[28] = ~v[28];
v[29] = ~v[29]
}
// get little-endian words
for (i = 0; i < 32; i++) {
m[i] = B2B_GET32(ctx.b, 4 * i)
}
// twelve rounds of mixing
// uncomment the DebugPrint calls to log the computation
// and match the RFC sample documentation
for (i = 0; i < 12; i++) {
B2B_G(0, 8, 16, 24, SIGMA82[i * 16], SIGMA82[i * 16 + 1]);
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
}
for (i = 0; i < 16; i++) {
ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16]
}
}
// Creates a BLAKE2b hashing context
// Requires an output length between 1 and 64 bytes
// Takes an optional Uint8Array key
function blake2bInit(outlen, key) {
if (outlen === 0 || outlen > 64) {
throw new Error('Illegal output length, expected 0 < length <= 64')
}
if (key && key.length > 64) {
throw new Error('Illegal key, expected Uint8Array with 0 < length <= 64')
}
// state, 'param block'
var ctx = {
b: new Uint8Array(128),
h: new Uint32Array(16),
t: 0, // input count
c: 0, // pointer within buffer
outlen: outlen // output length in bytes
};
// initialize hash state
for (var i = 0; i < 16; i++) {
ctx.h[i] = BLAKE2B_IV32[i];
}
var keylen = key ? key.length : 0;
ctx.h[0] ^= 0x01010000 ^ (keylen << 8) ^ outlen;
// key the hash, if applicable
if (key) {
blake2bUpdate(ctx, key);
// at the end
ctx.c = 128
}
return ctx
}
// Updates a BLAKE2b streaming hash
// Requires hash context and Uint8Array (byte array)
function blake2bUpdate(ctx, input) {
for (var i = 0; i < input.length; i++) {
if (ctx.c === 128) { // buffer full ?
ctx.t += ctx.c; // add counters
blake2bCompress(ctx, false); // compress (not last)
ctx.c = 0 // counter to zero
}
ctx.b[ctx.c++] = input[i]
}
}
// Completes a BLAKE2b streaming hash
// Returns a Uint8Array containing the message digest
function blake2bFinal(ctx) {
ctx.t += ctx.c; // mark last block offset
while (ctx.c < 128) { // fill up with zeros
ctx.b[ctx.c++] = 0
}
blake2bCompress(ctx, true); // final block flag = 1
// little endian convert and store
var out = new Uint8Array(ctx.outlen);
for (var i = 0; i < ctx.outlen; i++) {
out[i] = ctx.h[i >> 2] >> (8 * (i & 3))
}
return out
}
// Computes the BLAKE2B hash of a string or byte array, and returns a Uint8Array
//
// Returns a n-byte Uint8Array
//
// Parameters:
// - input - the input bytes, as a string, Buffer or Uint8Array
// - key - optional key Uint8Array, up to 64 bytes
// - outlen - optional output length in bytes, default 64
function blake2b(input, key, outlen) {
// preprocess inputs
outlen = outlen || 64;
// do the math
var ctx = blake2bInit(outlen, key);
blake2bUpdate(ctx, input);
return blake2bFinal(ctx)
}
var blake = {
blake2b: blake2b,
blake2bInit: blake2bInit,
blake2bUpdate: blake2bUpdate,
blake2bFinal: blake2bFinal
};
if (typeof(module) !== 'undefined' && module.exports) {
// Publish as node.js module
module.exports = blake;
} else if (typeof define === 'function' && define.amd) {
// Publish as AMD module
define(function() {return blake;});
} else {
// Publish as global (in browsers)
var _previousRoot = _global.blake;
// **`noConflict()` - (browser only) to reset global 'blake' var**
blake.noConflict = function() {
_global.blake = _previousRoot;
return blake;
};
_global.blake = blake;
}
}).call(this);
\ No newline at end of file
......@@ -214,6 +214,7 @@
}])
.run(['$rootScope', '$location', '$routeParams', '$http', '$templateCache', 'managerSecret', 'managerFileTransfer', 'offlineCache', 'managerStatus',
function ($rootScope, $location, $routeParams, $http, $templateCache, managerSecret, managerFileTransfer, offlineCache, managerStatus) {
$rootScope.entity = 'main_thread';
$rootScope.$on( "$routeChangeStart", function(event, next, current) {
var offline_redirect_urls = [
......
(function(angular, require, sha512, sha256, sha1, uuid, blake) {
(function(angular, require, sha512, sha256, sha1, uuid) {
'use strict';
/**
......@@ -17,7 +17,7 @@
this.name = "InvalidRecoveryCodeException";
}
var cryptoLibrary = function($window, $timeout, converter, helper) {
var cryptoLibrary = function($q, $window, $timeout, converter, helper) {
var nacl = require('ecma-nacl');
......@@ -71,25 +71,6 @@
}, 60000);
}
/**
* @ngdoc
* @name psonocli.cryptoLibrary#blake2b
* @methodOf psonocli.cryptoLibrary
*
* @description
* Returns the blake2b hash
* Base: https://github.com/dcposch/blakejs
*
* @param {Uint8Array} input The input data
* @param {Uint8Array} key (optional) key Uint8Array, up to 64 bytes
* @param {Uint8Array} outlen (optional) output length in bytes, default 64
*
* @returns {String} Returns the hex representation of the hash
*/
var blake2b = function (input, key, outlen) {
return converter.to_hex(blake.blake2b(input, key, outlen))
};
/**
* @ngdoc
......@@ -253,6 +234,42 @@
return converter.decode_utf8(m1);
}
/**
* @ngdoc
* @name psonocli.cryptoLibrary#run_crypto_work_async
* @methodOf psonocli.cryptoLibrary
*
* @description
* runs async jobs
*
* @param job
* @param kwargs
* @param transfers
*
* @returns {PromiseLike<any> | f | * | e | promise}
*/
var run_crypto_work_async = function(job, kwargs, transfers) {
var defer = $q.defer();
var crypto_worker = new Worker('js/crypto-worker.js');
function handle_message_from_worker(msg) {
crypto_worker.terminate();
defer.resolve(msg.data.kwargs);
}
crypto_worker.addEventListener('message', handle_message_from_worker);
crypto_worker.postMessage(
{
job: job,
kwargs: kwargs
},
transfers
);
return defer.promise;
};
/**
* @ngdoc
* @name psonocli.cryptoLibrary#encrypt_file
......@@ -264,13 +281,26 @@
* @param {Uint8Array} data The data of the file in Uint8Array encoding
* @param {string} secret_key The secret key you want to use to encrypt the data
*
* @returns {Uint8Array} The encrypted text prepended with the nonce
* @returns {promise} A promise that will return the encrypted file with the nonce as Uint8Array
*/
var encrypt_file = function (data, secret_key) {
var k = converter.from_hex(secret_key);
var n = randomBytes(24);
return nacl.secret_box.formatWN.pack(data, n, k);
// sync code
// var k = converter.from_hex(secret_key);
// var n = randomBytes(24);
//
// return nacl.secret_box.formatWN.pack(data, n, k);
var k = converter.from_hex(secret_key).buffer;
var n = randomBytes(24).buffer;
var arrayBuffer = data.buffer;
return run_crypto_work_async('encrypt_file', {
data: arrayBuffer,
k: k,
n: n
}, [arrayBuffer]).then(function(buffer) {
return new Uint8Array(buffer)
});
};
/**
......@@ -284,12 +314,23 @@
* @param {Uint8Array} text The encrypted data of the file in Uint8Array encoding with prepended nonce
* @param {string} secret_key The secret key used in the past to encrypt the text
*
* @returns {string} The decrypted data
* @returns {promise} A promise that will return the decrypted data as Uint8Array
*/
var decrypt_file = function (text, secret_key) {
var k = converter.from_hex(secret_key);
return nacl.secret_box.formatWN.open(text, k);
// sync code
// var k = converter.from_hex(secret_key);
//
// return nacl.secret_box.formatWN.open(text, k);
var k = converter.from_hex(secret_key).buffer;
var arrayBuffer = text.buffer;
return run_crypto_work_async('decrypt_file', {
text: arrayBuffer,
k: k
}, [arrayBuffer]).then(function(buffer) {
return new Uint8Array(buffer)
});
};
/**
......@@ -614,7 +655,6 @@
sha1: sha1,
sha256: sha256,
sha512: sha512,
blake2b: blake2b,
password_scrypt: password_scrypt,
generate_authkey: generate_authkey,
generate_secret_key: generate_secret_key,
......@@ -639,7 +679,7 @@
};
var app = angular.module('psonocli');
app.factory("cryptoLibrary", ['$window', '$timeout', 'converter', 'helper', cryptoLibrary]);
app.factory("cryptoLibrary", ['$q', '$window', '$timeout', 'converter', 'helper', cryptoLibrary]);
}(angular, require, sha512, sha256, sha1, uuid, blake));
}(angular, require, sha512, sha256, sha1, uuid));
......@@ -224,34 +224,31 @@
*/
function multi_chunk_upload(shard, file, file_transfer_id, file_secret_key, file_chunk_size) {
var time_start = new Date().getTime();
var on_load_end = function(bytes, file_secret_key, chunk_position, resolve) {
registrations['upload_step_complete']('ENCRYPT_FILE_CHUNK');
console.log("on_load_end " + chunk_position + " " + (new Date().getTime() - time_start)/1000);
time_start = new Date().getTime();
var encrypted_bytes = cryptoLibrary.encrypt_file(bytes, file_secret_key);
registrations[