From 039cce293a190b028f7013a9fbbcd999e2b348f1 Mon Sep 17 00:00:00 2001 From: Thomas Van Iseghem Date: Sun, 23 Apr 2023 12:29:29 +0200 Subject: Renamed "Capture" to "File"-decryption and moved webapp to it --- .gitignore | 1 + Capture-decryption/.gitignore | 2 - Capture-decryption/Capture.proto | 23 --- Capture-decryption/Capture_pb2.py | 193 ------------------ Capture-decryption/Dockerfile | 11 -- Capture-decryption/Makefile | 5 - Capture-decryption/README.md | 42 ---- Capture-decryption/decode_capture.py | 24 --- Capture-decryption/qc_decrypt.c | 177 ----------------- Capture-decryption/requirements.txt | 1 - File-decryption/.gitignore | 2 + File-decryption/Capture.proto | 23 +++ File-decryption/Capture_pb2.py | 193 ++++++++++++++++++ File-decryption/Dockerfile | 11 ++ File-decryption/Makefile | 5 + File-decryption/README.md | 42 ++++ File-decryption/decode_capture.py | 24 +++ File-decryption/qc_decrypt.c | 177 +++++++++++++++++ File-decryption/requirements.txt | 1 + File-decryption/webapp/index.html | 30 +++ File-decryption/webapp/main.js | 107 ++++++++++ File-decryption/webapp/sha1.js | 371 +++++++++++++++++++++++++++++++++++ qc_decrypt/webapp/index.html | 30 --- qc_decrypt/webapp/main.js | 107 ---------- qc_decrypt/webapp/sha1.js | 371 ----------------------------------- 25 files changed, 987 insertions(+), 986 deletions(-) delete mode 100644 Capture-decryption/.gitignore delete mode 100644 Capture-decryption/Capture.proto delete mode 100644 Capture-decryption/Capture_pb2.py delete mode 100644 Capture-decryption/Dockerfile delete mode 100644 Capture-decryption/Makefile delete mode 100644 Capture-decryption/README.md delete mode 100644 Capture-decryption/decode_capture.py delete mode 100644 Capture-decryption/qc_decrypt.c delete mode 100644 Capture-decryption/requirements.txt create mode 100644 File-decryption/.gitignore create mode 100644 File-decryption/Capture.proto create mode 100644 File-decryption/Capture_pb2.py create mode 100644 File-decryption/Dockerfile create mode 100644 File-decryption/Makefile create mode 100644 File-decryption/README.md create mode 100644 File-decryption/decode_capture.py create mode 100644 File-decryption/qc_decrypt.c create mode 100644 File-decryption/requirements.txt create mode 100644 File-decryption/webapp/index.html create mode 100644 File-decryption/webapp/main.js create mode 100644 File-decryption/webapp/sha1.js delete mode 100644 qc_decrypt/webapp/index.html delete mode 100644 qc_decrypt/webapp/main.js delete mode 100644 qc_decrypt/webapp/sha1.js diff --git a/.gitignore b/.gitignore index 6834822..54ad51e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode Capture-decryption/__pycache__ +File-decryption/__pycache__ diff --git a/Capture-decryption/.gitignore b/Capture-decryption/.gitignore deleted file mode 100644 index e698163..0000000 --- a/Capture-decryption/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -qc_decrypt -/data/* \ No newline at end of file diff --git a/Capture-decryption/Capture.proto b/Capture-decryption/Capture.proto deleted file mode 100644 index 01e66ad..0000000 --- a/Capture-decryption/Capture.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto3"; - -package captureProto; - -message Capture { - float sample_rate = 1; - uint32 pre_filter_length = 2; - uint32 post_filter_length = 3; - repeated float pre_filter_coefficients = 4; - repeated float post_filter_coefficients = 5; - float constant_pre_gain = 6; - float constant_post_gain = 7; - uint32 number_of_layers = 8; - repeated uint32 layer_sizes = 9; - repeated layerWeightsAndBiases weights_and_biases = 10; - float high_pass_frequency = 11; - float high_pass_bandwidth = 12; -} - -message layerWeightsAndBiases { - repeated float weights = 1; - repeated float biases = 2; -} \ No newline at end of file diff --git a/Capture-decryption/Capture_pb2.py b/Capture-decryption/Capture_pb2.py deleted file mode 100644 index fb6b9eb..0000000 --- a/Capture-decryption/Capture_pb2.py +++ /dev/null @@ -1,193 +0,0 @@ -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: Capture.proto - -import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) -from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection -from google.protobuf import symbol_database as _symbol_database -from google.protobuf import descriptor_pb2 -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor.FileDescriptor( - name='Capture.proto', - package='captureProto', - syntax='proto3', - serialized_pb=_b('\n\rCapture.proto\x12\x0c\x63\x61ptureProto\"\xf9\x02\n\x07\x43\x61pture\x12\x13\n\x0bsample_rate\x18\x01 \x01(\x02\x12\x19\n\x11pre_filter_length\x18\x02 \x01(\r\x12\x1a\n\x12post_filter_length\x18\x03 \x01(\r\x12\x1f\n\x17pre_filter_coefficients\x18\x04 \x03(\x02\x12 \n\x18post_filter_coefficients\x18\x05 \x03(\x02\x12\x19\n\x11\x63onstant_pre_gain\x18\x06 \x01(\x02\x12\x1a\n\x12\x63onstant_post_gain\x18\x07 \x01(\x02\x12\x18\n\x10number_of_layers\x18\x08 \x01(\r\x12\x13\n\x0blayer_sizes\x18\t \x03(\r\x12?\n\x12weights_and_biases\x18\n \x03(\x0b\x32#.captureProto.layerWeightsAndBiases\x12\x1b\n\x13high_pass_frequency\x18\x0b \x01(\x02\x12\x1b\n\x13high_pass_bandwidth\x18\x0c \x01(\x02\"8\n\x15layerWeightsAndBiases\x12\x0f\n\x07weights\x18\x01 \x03(\x02\x12\x0e\n\x06\x62iases\x18\x02 \x03(\x02\x62\x06proto3') -) -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - - - - -_CAPTURE = _descriptor.Descriptor( - name='Capture', - full_name='captureProto.Capture', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='sample_rate', full_name='captureProto.Capture.sample_rate', index=0, - number=1, type=2, cpp_type=6, label=1, - has_default_value=False, default_value=float(0), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='pre_filter_length', full_name='captureProto.Capture.pre_filter_length', index=1, - number=2, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='post_filter_length', full_name='captureProto.Capture.post_filter_length', index=2, - number=3, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='pre_filter_coefficients', full_name='captureProto.Capture.pre_filter_coefficients', index=3, - number=4, type=2, cpp_type=6, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='post_filter_coefficients', full_name='captureProto.Capture.post_filter_coefficients', index=4, - number=5, type=2, cpp_type=6, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='constant_pre_gain', full_name='captureProto.Capture.constant_pre_gain', index=5, - number=6, type=2, cpp_type=6, label=1, - has_default_value=False, default_value=float(0), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='constant_post_gain', full_name='captureProto.Capture.constant_post_gain', index=6, - number=7, type=2, cpp_type=6, label=1, - has_default_value=False, default_value=float(0), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='number_of_layers', full_name='captureProto.Capture.number_of_layers', index=7, - number=8, type=13, cpp_type=3, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='layer_sizes', full_name='captureProto.Capture.layer_sizes', index=8, - number=9, type=13, cpp_type=3, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='weights_and_biases', full_name='captureProto.Capture.weights_and_biases', index=9, - number=10, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='high_pass_frequency', full_name='captureProto.Capture.high_pass_frequency', index=10, - number=11, type=2, cpp_type=6, label=1, - has_default_value=False, default_value=float(0), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='high_pass_bandwidth', full_name='captureProto.Capture.high_pass_bandwidth', index=11, - number=12, type=2, cpp_type=6, label=1, - has_default_value=False, default_value=float(0), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=32, - serialized_end=409, -) - - -_LAYERWEIGHTSANDBIASES = _descriptor.Descriptor( - name='layerWeightsAndBiases', - full_name='captureProto.layerWeightsAndBiases', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='weights', full_name='captureProto.layerWeightsAndBiases.weights', index=0, - number=1, type=2, cpp_type=6, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='biases', full_name='captureProto.layerWeightsAndBiases.biases', index=1, - number=2, type=2, cpp_type=6, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=411, - serialized_end=467, -) - -_CAPTURE.fields_by_name['weights_and_biases'].message_type = _LAYERWEIGHTSANDBIASES -DESCRIPTOR.message_types_by_name['Capture'] = _CAPTURE -DESCRIPTOR.message_types_by_name['layerWeightsAndBiases'] = _LAYERWEIGHTSANDBIASES - -Capture = _reflection.GeneratedProtocolMessageType('Capture', (_message.Message,), dict( - DESCRIPTOR = _CAPTURE, - __module__ = 'Capture_pb2' - # @@protoc_insertion_point(class_scope:captureProto.Capture) - )) -_sym_db.RegisterMessage(Capture) - -layerWeightsAndBiases = _reflection.GeneratedProtocolMessageType('layerWeightsAndBiases', (_message.Message,), dict( - DESCRIPTOR = _LAYERWEIGHTSANDBIASES, - __module__ = 'Capture_pb2' - # @@protoc_insertion_point(class_scope:captureProto.layerWeightsAndBiases) - )) -_sym_db.RegisterMessage(layerWeightsAndBiases) - - -# @@protoc_insertion_point(module_scope) diff --git a/Capture-decryption/Dockerfile b/Capture-decryption/Dockerfile deleted file mode 100644 index b8daecc..0000000 --- a/Capture-decryption/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM gcc:12.2 AS builder -COPY ./ /usr/src/myapp -WORKDIR /usr/src/myapp -RUN make - -FROM debian:11-slim -COPY --from=builder /usr/src/myapp/qc_decrypt /usr/bin/qc_decrypt -RUN mkdir /data -WORKDIR /data -ENTRYPOINT [ "/usr/bin/qc_decrypt" ] - diff --git a/Capture-decryption/Makefile b/Capture-decryption/Makefile deleted file mode 100644 index d446c7a..0000000 --- a/Capture-decryption/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -all: - @gcc -lcrypto qc_decrypt.c -o qc_decrypt - -clean: - @rm -rf qc_decrypt \ No newline at end of file diff --git a/Capture-decryption/README.md b/Capture-decryption/README.md deleted file mode 100644 index 4a9a8e8..0000000 --- a/Capture-decryption/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# NeuralDSP QuadCortex Neural Capture file decryptor. - -This tool can be used to take one of the encrypted `.cns` or `.json` files, and decrypt them to a usable format. The `.cns` files are actually protobufs and can be decoded with the Python decoder. - -Build the image: - -```sh -docker build . -t qc_decrypt -``` - -To decrypt user files (pass the serial number found in `/etc/qc_sn` as command line argument): - -```sh -docker run -v/path/to/your/files/:/data qc_decrypt QA00XXXXX /data/encrypted.json -``` - -To decrypt update files instead, provide an empty serial: - -```sh -docker run -v/path/to/your/files/:/data qc_decrypt "" /data/encrypted.json -``` - -## License - -This tool was made with ♥ by [Simone Margaritelli](https://www.evilsocket.net/) and it is released under the GPL 3 license. - -# Unencrypted Neural Capture file decoder - -This tool allows you to decode the files, decrypted using the tool above. - -## Dependencies -You need to use the protobuf 3.20 package for this to work. You can get it by running: - -``` -pip install protobuf==3.20.* -``` - -## Usage - -``` -python decode_capture.py .cns.dec -``` \ No newline at end of file diff --git a/Capture-decryption/decode_capture.py b/Capture-decryption/decode_capture.py deleted file mode 100644 index dd3d413..0000000 --- a/Capture-decryption/decode_capture.py +++ /dev/null @@ -1,24 +0,0 @@ -import sys -import google.protobuf.json_format as json_format -import Capture_pb2 - -if len(sys.argv) != 2: - print(f"Usage: {sys.argv[0]} ") - sys.exit(1) - -protobuf_file = sys.argv[1] - -# Read the input protobuf from the file -with open(protobuf_file, "rb") as f: - input_data = f.read() - -# Parse the input protobuf into a message object -message = Capture_pb2.Capture() -message.ParseFromString(input_data) - -# Convert the message object to a JSON string -json_string = json_format.MessageToJson(message) - -# Save the JSON string to a file -with open("capture.json", "w") as f: - f.write(json_string) \ No newline at end of file diff --git a/Capture-decryption/qc_decrypt.c b/Capture-decryption/qc_decrypt.c deleted file mode 100644 index f04947f..0000000 --- a/Capture-decryption/qc_decrypt.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2023 Simone 'evilsocket' Margaritelli - evilsocket@gmail.com. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include -#include -#include -#include -#include - -// as seen in /usr/lib/libzc.so / SetupKeys -static unsigned char KEY_MATERIAL[] = { - 0x13, 0x27, 0x3f, 0x42, - 0xa5, 0xb6, 0x79, 0xe8, - 0x20, 0x31, 0xc4, 0xf5, - 0x16, 0x17, 0x88, 0x2f, - 0x43, 0xa4, 0x55, 0x69, - 0x77, 0xb8, 0xe2, 0x83, - 0x04, 0x05, 0x60, 0x70, - 0x80, 0x02, 0x03, 0x04, - 0x50, 0x6a, 0x7c, 0x8a, - 0x02, 0x30, 0x40, 0x51, - 0x6a, 0x7d, 0x8d, 0x22, - 0x33, 0x44, 0x59, 0x66, - 0x71, 0x08, 0x02, 0x03, - 0x43, 0x05, 0x67, 0x7a, - 0x8f}; - -int main(int argc, char **argv) -{ - if (argc != 3) - { - printf("Usage: %s \n", argv[0]); - return 1; - } - - char *serialNumber = argv[1], - *inputFileName = argv[2]; - - printf("Input file name: %s\n", inputFileName); - - // Split into the path and the file name - char *path = strrchr(inputFileName, '/'); - if (path == NULL) - { - printf("No path found in %s\n", inputFileName); - return 1; - } - - unsigned long serialSize = strlen(serialNumber); - if (serialSize != 9 && serialSize != 0) - { - printf("the serial number must be empty or 9 characters long.\n"); - return 1; - } - - // concatenate the hardcoded key material with the serial number from /etc/qc_sn - unsigned long key_material_size = sizeof(KEY_MATERIAL) / sizeof(KEY_MATERIAL[0]); - unsigned char *key_material = (unsigned char *)malloc(key_material_size + serialSize); - - memcpy(key_material, KEY_MATERIAL, key_material_size); - memcpy(key_material + key_material_size, serialNumber, serialSize); - - key_material_size += serialSize; - - // derive the actual key and iv from it - unsigned char key[32] = {0}; - unsigned char iv[32] = {0}; - - int iterations = 10; - const EVP_CIPHER *pCipher = EVP_aes_128_ctr(); - const EVP_MD *pDigest = EVP_sha1(); - - int derivedKeySize = EVP_BytesToKey( - pCipher, - pDigest, - NULL, // no salt - key_material, - key_material_size, - iterations, - key, - iv); - - if (derivedKeySize != 16) - { - printf("wrong derived key size: %d\n", derivedKeySize); - return 1; - } - - // read the encrypted file - FILE *fp = fopen(inputFileName, "rb"); - if (!fp) - { - printf("can't open %s\n", inputFileName); - return 1; - } - - fseek(fp, 0, SEEK_END); - long input_size = ftell(fp); - fseek(fp, 0, SEEK_SET); - - int ret, final_size, outlen; - unsigned char *input = (unsigned char *)malloc(input_size), - *plaintext = (unsigned char *)malloc(input_size); - - long read = fread(input, 1, input_size, fp); - - fclose(fp); - - // decrypt it - EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); - - ret = EVP_DecryptInit_ex(ctx, pCipher, NULL, key, iv); - if (ret != 1) - { - printf("EVP_DecryptInit_ex failed: %d\n", ret); - return 1; - } - - ret = EVP_DecryptUpdate(ctx, plaintext, &outlen, input, input_size); - if (ret != 1) - { - printf("EVP_DecryptUpdate failed: %d\n", ret); - return 1; - } - - ret = EVP_DecryptFinal(ctx, &plaintext[outlen], &final_size); - if (ret != 1) - { - printf("EVP_DecryptFinal failed: %d\n", ret); - return 1; - } - - // Print and save the decrypted file - for (int i = 0; i < outlen; i++) - { - printf("%c", plaintext[i]); - } - printf("\n"); - - // Save the decrypted file to disk - // It should be saved to the same directory as the encrypted file with the extension .dec - char *outputFileName = (char *)malloc(strlen(inputFileName) + 5); - strcpy(outputFileName, inputFileName); - strcat(outputFileName, ".dec"); - - fp = fopen(outputFileName, "wb"); - if (!fp) - { - printf("can't open %s\n", outputFileName); - return 1; - } - - fwrite(plaintext, 1, outlen, fp); - - fclose(fp); - - free(key_material); - free(input); - free(plaintext); - free(outputFileName); - - EVP_CIPHER_CTX_free(ctx); - - return 0; -} \ No newline at end of file diff --git a/Capture-decryption/requirements.txt b/Capture-decryption/requirements.txt deleted file mode 100644 index bed47cd..0000000 --- a/Capture-decryption/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -protobuf==3.20.* \ No newline at end of file diff --git a/File-decryption/.gitignore b/File-decryption/.gitignore new file mode 100644 index 0000000..e698163 --- /dev/null +++ b/File-decryption/.gitignore @@ -0,0 +1,2 @@ +qc_decrypt +/data/* \ No newline at end of file diff --git a/File-decryption/Capture.proto b/File-decryption/Capture.proto new file mode 100644 index 0000000..01e66ad --- /dev/null +++ b/File-decryption/Capture.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; + +package captureProto; + +message Capture { + float sample_rate = 1; + uint32 pre_filter_length = 2; + uint32 post_filter_length = 3; + repeated float pre_filter_coefficients = 4; + repeated float post_filter_coefficients = 5; + float constant_pre_gain = 6; + float constant_post_gain = 7; + uint32 number_of_layers = 8; + repeated uint32 layer_sizes = 9; + repeated layerWeightsAndBiases weights_and_biases = 10; + float high_pass_frequency = 11; + float high_pass_bandwidth = 12; +} + +message layerWeightsAndBiases { + repeated float weights = 1; + repeated float biases = 2; +} \ No newline at end of file diff --git a/File-decryption/Capture_pb2.py b/File-decryption/Capture_pb2.py new file mode 100644 index 0000000..fb6b9eb --- /dev/null +++ b/File-decryption/Capture_pb2.py @@ -0,0 +1,193 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: Capture.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='Capture.proto', + package='captureProto', + syntax='proto3', + serialized_pb=_b('\n\rCapture.proto\x12\x0c\x63\x61ptureProto\"\xf9\x02\n\x07\x43\x61pture\x12\x13\n\x0bsample_rate\x18\x01 \x01(\x02\x12\x19\n\x11pre_filter_length\x18\x02 \x01(\r\x12\x1a\n\x12post_filter_length\x18\x03 \x01(\r\x12\x1f\n\x17pre_filter_coefficients\x18\x04 \x03(\x02\x12 \n\x18post_filter_coefficients\x18\x05 \x03(\x02\x12\x19\n\x11\x63onstant_pre_gain\x18\x06 \x01(\x02\x12\x1a\n\x12\x63onstant_post_gain\x18\x07 \x01(\x02\x12\x18\n\x10number_of_layers\x18\x08 \x01(\r\x12\x13\n\x0blayer_sizes\x18\t \x03(\r\x12?\n\x12weights_and_biases\x18\n \x03(\x0b\x32#.captureProto.layerWeightsAndBiases\x12\x1b\n\x13high_pass_frequency\x18\x0b \x01(\x02\x12\x1b\n\x13high_pass_bandwidth\x18\x0c \x01(\x02\"8\n\x15layerWeightsAndBiases\x12\x0f\n\x07weights\x18\x01 \x03(\x02\x12\x0e\n\x06\x62iases\x18\x02 \x03(\x02\x62\x06proto3') +) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + + +_CAPTURE = _descriptor.Descriptor( + name='Capture', + full_name='captureProto.Capture', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='sample_rate', full_name='captureProto.Capture.sample_rate', index=0, + number=1, type=2, cpp_type=6, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='pre_filter_length', full_name='captureProto.Capture.pre_filter_length', index=1, + number=2, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='post_filter_length', full_name='captureProto.Capture.post_filter_length', index=2, + number=3, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='pre_filter_coefficients', full_name='captureProto.Capture.pre_filter_coefficients', index=3, + number=4, type=2, cpp_type=6, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='post_filter_coefficients', full_name='captureProto.Capture.post_filter_coefficients', index=4, + number=5, type=2, cpp_type=6, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='constant_pre_gain', full_name='captureProto.Capture.constant_pre_gain', index=5, + number=6, type=2, cpp_type=6, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='constant_post_gain', full_name='captureProto.Capture.constant_post_gain', index=6, + number=7, type=2, cpp_type=6, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='number_of_layers', full_name='captureProto.Capture.number_of_layers', index=7, + number=8, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='layer_sizes', full_name='captureProto.Capture.layer_sizes', index=8, + number=9, type=13, cpp_type=3, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='weights_and_biases', full_name='captureProto.Capture.weights_and_biases', index=9, + number=10, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='high_pass_frequency', full_name='captureProto.Capture.high_pass_frequency', index=10, + number=11, type=2, cpp_type=6, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='high_pass_bandwidth', full_name='captureProto.Capture.high_pass_bandwidth', index=11, + number=12, type=2, cpp_type=6, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=32, + serialized_end=409, +) + + +_LAYERWEIGHTSANDBIASES = _descriptor.Descriptor( + name='layerWeightsAndBiases', + full_name='captureProto.layerWeightsAndBiases', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='weights', full_name='captureProto.layerWeightsAndBiases.weights', index=0, + number=1, type=2, cpp_type=6, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='biases', full_name='captureProto.layerWeightsAndBiases.biases', index=1, + number=2, type=2, cpp_type=6, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=411, + serialized_end=467, +) + +_CAPTURE.fields_by_name['weights_and_biases'].message_type = _LAYERWEIGHTSANDBIASES +DESCRIPTOR.message_types_by_name['Capture'] = _CAPTURE +DESCRIPTOR.message_types_by_name['layerWeightsAndBiases'] = _LAYERWEIGHTSANDBIASES + +Capture = _reflection.GeneratedProtocolMessageType('Capture', (_message.Message,), dict( + DESCRIPTOR = _CAPTURE, + __module__ = 'Capture_pb2' + # @@protoc_insertion_point(class_scope:captureProto.Capture) + )) +_sym_db.RegisterMessage(Capture) + +layerWeightsAndBiases = _reflection.GeneratedProtocolMessageType('layerWeightsAndBiases', (_message.Message,), dict( + DESCRIPTOR = _LAYERWEIGHTSANDBIASES, + __module__ = 'Capture_pb2' + # @@protoc_insertion_point(class_scope:captureProto.layerWeightsAndBiases) + )) +_sym_db.RegisterMessage(layerWeightsAndBiases) + + +# @@protoc_insertion_point(module_scope) diff --git a/File-decryption/Dockerfile b/File-decryption/Dockerfile new file mode 100644 index 0000000..b8daecc --- /dev/null +++ b/File-decryption/Dockerfile @@ -0,0 +1,11 @@ +FROM gcc:12.2 AS builder +COPY ./ /usr/src/myapp +WORKDIR /usr/src/myapp +RUN make + +FROM debian:11-slim +COPY --from=builder /usr/src/myapp/qc_decrypt /usr/bin/qc_decrypt +RUN mkdir /data +WORKDIR /data +ENTRYPOINT [ "/usr/bin/qc_decrypt" ] + diff --git a/File-decryption/Makefile b/File-decryption/Makefile new file mode 100644 index 0000000..d446c7a --- /dev/null +++ b/File-decryption/Makefile @@ -0,0 +1,5 @@ +all: + @gcc -lcrypto qc_decrypt.c -o qc_decrypt + +clean: + @rm -rf qc_decrypt \ No newline at end of file diff --git a/File-decryption/README.md b/File-decryption/README.md new file mode 100644 index 0000000..4a9a8e8 --- /dev/null +++ b/File-decryption/README.md @@ -0,0 +1,42 @@ +# NeuralDSP QuadCortex Neural Capture file decryptor. + +This tool can be used to take one of the encrypted `.cns` or `.json` files, and decrypt them to a usable format. The `.cns` files are actually protobufs and can be decoded with the Python decoder. + +Build the image: + +```sh +docker build . -t qc_decrypt +``` + +To decrypt user files (pass the serial number found in `/etc/qc_sn` as command line argument): + +```sh +docker run -v/path/to/your/files/:/data qc_decrypt QA00XXXXX /data/encrypted.json +``` + +To decrypt update files instead, provide an empty serial: + +```sh +docker run -v/path/to/your/files/:/data qc_decrypt "" /data/encrypted.json +``` + +## License + +This tool was made with ♥ by [Simone Margaritelli](https://www.evilsocket.net/) and it is released under the GPL 3 license. + +# Unencrypted Neural Capture file decoder + +This tool allows you to decode the files, decrypted using the tool above. + +## Dependencies +You need to use the protobuf 3.20 package for this to work. You can get it by running: + +``` +pip install protobuf==3.20.* +``` + +## Usage + +``` +python decode_capture.py .cns.dec +``` \ No newline at end of file diff --git a/File-decryption/decode_capture.py b/File-decryption/decode_capture.py new file mode 100644 index 0000000..dd3d413 --- /dev/null +++ b/File-decryption/decode_capture.py @@ -0,0 +1,24 @@ +import sys +import google.protobuf.json_format as json_format +import Capture_pb2 + +if len(sys.argv) != 2: + print(f"Usage: {sys.argv[0]} ") + sys.exit(1) + +protobuf_file = sys.argv[1] + +# Read the input protobuf from the file +with open(protobuf_file, "rb") as f: + input_data = f.read() + +# Parse the input protobuf into a message object +message = Capture_pb2.Capture() +message.ParseFromString(input_data) + +# Convert the message object to a JSON string +json_string = json_format.MessageToJson(message) + +# Save the JSON string to a file +with open("capture.json", "w") as f: + f.write(json_string) \ No newline at end of file diff --git a/File-decryption/qc_decrypt.c b/File-decryption/qc_decrypt.c new file mode 100644 index 0000000..f04947f --- /dev/null +++ b/File-decryption/qc_decrypt.c @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2023 Simone 'evilsocket' Margaritelli - evilsocket@gmail.com. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include +#include +#include +#include + +// as seen in /usr/lib/libzc.so / SetupKeys +static unsigned char KEY_MATERIAL[] = { + 0x13, 0x27, 0x3f, 0x42, + 0xa5, 0xb6, 0x79, 0xe8, + 0x20, 0x31, 0xc4, 0xf5, + 0x16, 0x17, 0x88, 0x2f, + 0x43, 0xa4, 0x55, 0x69, + 0x77, 0xb8, 0xe2, 0x83, + 0x04, 0x05, 0x60, 0x70, + 0x80, 0x02, 0x03, 0x04, + 0x50, 0x6a, 0x7c, 0x8a, + 0x02, 0x30, 0x40, 0x51, + 0x6a, 0x7d, 0x8d, 0x22, + 0x33, 0x44, 0x59, 0x66, + 0x71, 0x08, 0x02, 0x03, + 0x43, 0x05, 0x67, 0x7a, + 0x8f}; + +int main(int argc, char **argv) +{ + if (argc != 3) + { + printf("Usage: %s \n", argv[0]); + return 1; + } + + char *serialNumber = argv[1], + *inputFileName = argv[2]; + + printf("Input file name: %s\n", inputFileName); + + // Split into the path and the file name + char *path = strrchr(inputFileName, '/'); + if (path == NULL) + { + printf("No path found in %s\n", inputFileName); + return 1; + } + + unsigned long serialSize = strlen(serialNumber); + if (serialSize != 9 && serialSize != 0) + { + printf("the serial number must be empty or 9 characters long.\n"); + return 1; + } + + // concatenate the hardcoded key material with the serial number from /etc/qc_sn + unsigned long key_material_size = sizeof(KEY_MATERIAL) / sizeof(KEY_MATERIAL[0]); + unsigned char *key_material = (unsigned char *)malloc(key_material_size + serialSize); + + memcpy(key_material, KEY_MATERIAL, key_material_size); + memcpy(key_material + key_material_size, serialNumber, serialSize); + + key_material_size += serialSize; + + // derive the actual key and iv from it + unsigned char key[32] = {0}; + unsigned char iv[32] = {0}; + + int iterations = 10; + const EVP_CIPHER *pCipher = EVP_aes_128_ctr(); + const EVP_MD *pDigest = EVP_sha1(); + + int derivedKeySize = EVP_BytesToKey( + pCipher, + pDigest, + NULL, // no salt + key_material, + key_material_size, + iterations, + key, + iv); + + if (derivedKeySize != 16) + { + printf("wrong derived key size: %d\n", derivedKeySize); + return 1; + } + + // read the encrypted file + FILE *fp = fopen(inputFileName, "rb"); + if (!fp) + { + printf("can't open %s\n", inputFileName); + return 1; + } + + fseek(fp, 0, SEEK_END); + long input_size = ftell(fp); + fseek(fp, 0, SEEK_SET); + + int ret, final_size, outlen; + unsigned char *input = (unsigned char *)malloc(input_size), + *plaintext = (unsigned char *)malloc(input_size); + + long read = fread(input, 1, input_size, fp); + + fclose(fp); + + // decrypt it + EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); + + ret = EVP_DecryptInit_ex(ctx, pCipher, NULL, key, iv); + if (ret != 1) + { + printf("EVP_DecryptInit_ex failed: %d\n", ret); + return 1; + } + + ret = EVP_DecryptUpdate(ctx, plaintext, &outlen, input, input_size); + if (ret != 1) + { + printf("EVP_DecryptUpdate failed: %d\n", ret); + return 1; + } + + ret = EVP_DecryptFinal(ctx, &plaintext[outlen], &final_size); + if (ret != 1) + { + printf("EVP_DecryptFinal failed: %d\n", ret); + return 1; + } + + // Print and save the decrypted file + for (int i = 0; i < outlen; i++) + { + printf("%c", plaintext[i]); + } + printf("\n"); + + // Save the decrypted file to disk + // It should be saved to the same directory as the encrypted file with the extension .dec + char *outputFileName = (char *)malloc(strlen(inputFileName) + 5); + strcpy(outputFileName, inputFileName); + strcat(outputFileName, ".dec"); + + fp = fopen(outputFileName, "wb"); + if (!fp) + { + printf("can't open %s\n", outputFileName); + return 1; + } + + fwrite(plaintext, 1, outlen, fp); + + fclose(fp); + + free(key_material); + free(input); + free(plaintext); + free(outputFileName); + + EVP_CIPHER_CTX_free(ctx); + + return 0; +} \ No newline at end of file diff --git a/File-decryption/requirements.txt b/File-decryption/requirements.txt new file mode 100644 index 0000000..bed47cd --- /dev/null +++ b/File-decryption/requirements.txt @@ -0,0 +1 @@ +protobuf==3.20.* \ No newline at end of file diff --git a/File-decryption/webapp/index.html b/File-decryption/webapp/index.html new file mode 100644 index 0000000..65a75f1 --- /dev/null +++ b/File-decryption/webapp/index.html @@ -0,0 +1,30 @@ + + + + + + + + OpenCortex + + + + + + + QuadCortex serial, found in /etc/qc_sn. Leave it blank for global decryption. +
+
+ +
+
+ Encrypted file: +
+
+ + + + + + + \ No newline at end of file diff --git a/File-decryption/webapp/main.js b/File-decryption/webapp/main.js new file mode 100644 index 0000000..792eb3d --- /dev/null +++ b/File-decryption/webapp/main.js @@ -0,0 +1,107 @@ +// as seen in /usr/lib/libzc.so / SetupKeys +const MASTER_KEY = new Uint8Array([ + 0x13, 0x27, 0x3f, 0x42, + 0xa5, 0xb6, 0x79, 0xe8, + 0x20, 0x31, 0xc4, 0xf5, + 0x16, 0x17, 0x88, 0x2f, + 0x43, 0xa4, 0x55, 0x69, + 0x77, 0xb8, 0xe2, 0x83, + 0x04, 0x05, 0x60, 0x70, + 0x80, 0x02, 0x03, 0x04, + 0x50, 0x6a, 0x7c, 0x8a, + 0x02, 0x30, 0x40, 0x51, + 0x6a, 0x7d, 0x8d, 0x22, + 0x33, 0x44, 0x59, 0x66, + 0x71, 0x08, 0x02, 0x03, + 0x43, 0x05, 0x67, 0x7a, + 0x8f]); + +function hex(byteArray) { + return Array.prototype.map.call(byteArray, function (byte) { + return ('0' + (byte & 0xFF).toString(16)).slice(-2); + }).join(''); +} + +// ported from EVP_BytesToKey +// https://github.com/openssl/openssl/blob/c04e78f0c69201226430fed14c291c281da47f2d/crypto/evp/evp_key.c#L78 +function deriveKeyAndIV(password, iterations = 10) { + var keyLen = 16; + var ivLen = 16; + var addmd = 0; + + var key = new Uint8Array(keyLen); + var iv = new Uint8Array(ivLen); + var tmp = new Uint8Array(); + var i, key_i = 0, iv_i = 0; + + for (; keyLen > 0 || ivLen > 0;) { + if (addmd++) { + block = new Uint8Array([...tmp, ...password]); + } else { + block = password; + } + + tmp = new Uint8Array(sha1.array(block)); + for (i = 1; i < iterations; i++) { + tmp = sha1.array(tmp); + } + + i = 0; + while (keyLen && i != tmp.length) { + key[key_i++] = tmp[i]; + keyLen--; + i++; + } + + while (ivLen != 0 && i != tmp.length) { + iv[iv_i++] = tmp[i]; + ivLen--; + i++; + } + } + + return { key: key, iv: iv }; +} + +function processFileInput(e) { + const fileName = e.target.fileName; + const serial = document.getElementById('serial-input').value; + let main_key = null; + if (serial.length > 0) { + // local decryption, use master key + serial + main_key = new Uint8Array([...MASTER_KEY, ...new TextEncoder("utf-8").encode(serial)]); + } else { + // global decryption, use master key only + main_key = MASTER_KEY; + } + + // derive key and iv with our EVP_BytesToKey port + const derived = deriveKeyAndIV(main_key); + // encrypted file contents + const ciphertext = e.target.result; + // import the raw key + window.crypto.subtle.importKey("raw", derived.key, "AES-CTR", true, ["encrypt", "decrypt"]).then(function (key) { + // decrypt using aes-128-ctr + window.crypto.subtle.decrypt({ name: "AES-CTR", counter: derived.iv, length: 128 }, key, ciphertext).then(function (cleartext) { + var blob = new Blob([cleartext], { type: "application/octet-stream" }); + const link = document.createElement('a'); + link.href = window.URL.createObjectURL(blob); + link.download = fileName + '.dec'; + link.click(); + }); + }); +} + +document.addEventListener("DOMContentLoaded", function () { + // handle file uploads + let fileInput = document.getElementById('file-input') + fileInput.onchange = () => { + const reader = new FileReader() + reader.onload = processFileInput; + for (let file of fileInput.files) { + // https://stackoverflow.com/questions/24245105/how-to-get-the-filename-from-the-javascript-filereader + reader.fileName = file.name; + reader.readAsArrayBuffer(file); + } + }; +}); \ No newline at end of file diff --git a/File-decryption/webapp/sha1.js b/File-decryption/webapp/sha1.js new file mode 100644 index 0000000..13d340f --- /dev/null +++ b/File-decryption/webapp/sha1.js @@ -0,0 +1,371 @@ +/* + * [js-sha1]{@link https://github.com/emn178/js-sha1} + * + * @version 0.6.0 + * @author Chen, Yi-Cyuan [emn178@gmail.com] + * @copyright Chen, Yi-Cyuan 2014-2017 + * @license MIT + */ +/*jslint bitwise: true */ +(function () { + 'use strict'; + + var root = typeof window === 'object' ? window : {}; + var NODE_JS = !root.JS_SHA1_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node; + if (NODE_JS) { + root = global; + } + var COMMON_JS = !root.JS_SHA1_NO_COMMON_JS && typeof module === 'object' && module.exports; + var AMD = typeof define === 'function' && define.amd; + var HEX_CHARS = '0123456789abcdef'.split(''); + var EXTRA = [-2147483648, 8388608, 32768, 128]; + var SHIFT = [24, 16, 8, 0]; + var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer']; + + var blocks = []; + + var createOutputMethod = function (outputType) { + return function (message) { + return new Sha1(true).update(message)[outputType](); + }; + }; + + var createMethod = function () { + var method = createOutputMethod('hex'); + if (NODE_JS) { + method = nodeWrap(method); + } + method.create = function () { + return new Sha1(); + }; + method.update = function (message) { + return method.create().update(message); + }; + for (var i = 0; i < OUTPUT_TYPES.length; ++i) { + var type = OUTPUT_TYPES[i]; + method[type] = createOutputMethod(type); + } + return method; + }; + + var nodeWrap = function (method) { + var crypto = eval("require('crypto')"); + var Buffer = eval("require('buffer').Buffer"); + var nodeMethod = function (message) { + if (typeof message === 'string') { + return crypto.createHash('sha1').update(message, 'utf8').digest('hex'); + } else if (message.constructor === ArrayBuffer) { + message = new Uint8Array(message); + } else if (message.length === undefined) { + return method(message); + } + return crypto.createHash('sha1').update(new Buffer(message)).digest('hex'); + }; + return nodeMethod; + }; + + function Sha1(sharedMemory) { + if (sharedMemory) { + blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = + blocks[4] = blocks[5] = blocks[6] = blocks[7] = + blocks[8] = blocks[9] = blocks[10] = blocks[11] = + blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; + this.blocks = blocks; + } else { + this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + } + + this.h0 = 0x67452301; + this.h1 = 0xEFCDAB89; + this.h2 = 0x98BADCFE; + this.h3 = 0x10325476; + this.h4 = 0xC3D2E1F0; + + this.block = this.start = this.bytes = this.hBytes = 0; + this.finalized = this.hashed = false; + this.first = true; + } + + Sha1.prototype.update = function (message) { + if (this.finalized) { + return; + } + var notString = typeof (message) !== 'string'; + if (notString && message.constructor === root.ArrayBuffer) { + message = new Uint8Array(message); + } + var code, index = 0, i, length = message.length || 0, blocks = this.blocks; + + while (index < length) { + if (this.hashed) { + this.hashed = false; + blocks[0] = this.block; + blocks[16] = blocks[1] = blocks[2] = blocks[3] = + blocks[4] = blocks[5] = blocks[6] = blocks[7] = + blocks[8] = blocks[9] = blocks[10] = blocks[11] = + blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; + } + + if (notString) { + for (i = this.start; index < length && i < 64; ++index) { + blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; + } + } else { + for (i = this.start; index < length && i < 64; ++index) { + code = message.charCodeAt(index); + if (code < 0x80) { + blocks[i >> 2] |= code << SHIFT[i++ & 3]; + } else if (code < 0x800) { + blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3]; + blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; + } else if (code < 0xd800 || code >= 0xe000) { + blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3]; + blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; + blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; + } else { + code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); + blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3]; + blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3]; + blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; + blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; + } + } + } + + this.lastByteIndex = i; + this.bytes += i - this.start; + if (i >= 64) { + this.block = blocks[16]; + this.start = i - 64; + this.hash(); + this.hashed = true; + } else { + this.start = i; + } + } + if (this.bytes > 4294967295) { + this.hBytes += this.bytes / 4294967296 << 0; + this.bytes = this.bytes % 4294967296; + } + return this; + }; + + Sha1.prototype.finalize = function () { + if (this.finalized) { + return; + } + this.finalized = true; + var blocks = this.blocks, i = this.lastByteIndex; + blocks[16] = this.block; + blocks[i >> 2] |= EXTRA[i & 3]; + this.block = blocks[16]; + if (i >= 56) { + if (!this.hashed) { + this.hash(); + } + blocks[0] = this.block; + blocks[16] = blocks[1] = blocks[2] = blocks[3] = + blocks[4] = blocks[5] = blocks[6] = blocks[7] = + blocks[8] = blocks[9] = blocks[10] = blocks[11] = + blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; + } + blocks[14] = this.hBytes << 3 | this.bytes >>> 29; + blocks[15] = this.bytes << 3; + this.hash(); + }; + + Sha1.prototype.hash = function () { + var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4; + var f, j, t, blocks = this.blocks; + + for (j = 16; j < 80; ++j) { + t = blocks[j - 3] ^ blocks[j - 8] ^ blocks[j - 14] ^ blocks[j - 16]; + blocks[j] = (t << 1) | (t >>> 31); + } + + for (j = 0; j < 20; j += 5) { + f = (b & c) | ((~b) & d); + t = (a << 5) | (a >>> 27); + e = t + f + e + 1518500249 + blocks[j] << 0; + b = (b << 30) | (b >>> 2); + + f = (a & b) | ((~a) & c); + t = (e << 5) | (e >>> 27); + d = t + f + d + 1518500249 + blocks[j + 1] << 0; + a = (a << 30) | (a >>> 2); + + f = (e & a) | ((~e) & b); + t = (d << 5) | (d >>> 27); + c = t + f + c + 1518500249 + blocks[j + 2] << 0; + e = (e << 30) | (e >>> 2); + + f = (d & e) | ((~d) & a); + t = (c << 5) | (c >>> 27); + b = t + f + b + 1518500249 + blocks[j + 3] << 0; + d = (d << 30) | (d >>> 2); + + f = (c & d) | ((~c) & e); + t = (b << 5) | (b >>> 27); + a = t + f + a + 1518500249 + blocks[j + 4] << 0; + c = (c << 30) | (c >>> 2); + } + + for (; j < 40; j += 5) { + f = b ^ c ^ d; + t = (a << 5) | (a >>> 27); + e = t + f + e + 1859775393 + blocks[j] << 0; + b = (b << 30) | (b >>> 2); + + f = a ^ b ^ c; + t = (e << 5) | (e >>> 27); + d = t + f + d + 1859775393 + blocks[j + 1] << 0; + a = (a << 30) | (a >>> 2); + + f = e ^ a ^ b; + t = (d << 5) | (d >>> 27); + c = t + f + c + 1859775393 + blocks[j + 2] << 0; + e = (e << 30) | (e >>> 2); + + f = d ^ e ^ a; + t = (c << 5) | (c >>> 27); + b = t + f + b + 1859775393 + blocks[j + 3] << 0; + d = (d << 30) | (d >>> 2); + + f = c ^ d ^ e; + t = (b << 5) | (b >>> 27); + a = t + f + a + 1859775393 + blocks[j + 4] << 0; + c = (c << 30) | (c >>> 2); + } + + for (; j < 60; j += 5) { + f = (b & c) | (b & d) | (c & d); + t = (a << 5) | (a >>> 27); + e = t + f + e - 1894007588 + blocks[j] << 0; + b = (b << 30) | (b >>> 2); + + f = (a & b) | (a & c) | (b & c); + t = (e << 5) | (e >>> 27); + d = t + f + d - 1894007588 + blocks[j + 1] << 0; + a = (a << 30) | (a >>> 2); + + f = (e & a) | (e & b) | (a & b); + t = (d << 5) | (d >>> 27); + c = t + f + c - 1894007588 + blocks[j + 2] << 0; + e = (e << 30) | (e >>> 2); + + f = (d & e) | (d & a) | (e & a); + t = (c << 5) | (c >>> 27); + b = t + f + b - 1894007588 + blocks[j + 3] << 0; + d = (d << 30) | (d >>> 2); + + f = (c & d) | (c & e) | (d & e); + t = (b << 5) | (b >>> 27); + a = t + f + a - 1894007588 + blocks[j + 4] << 0; + c = (c << 30) | (c >>> 2); + } + + for (; j < 80; j += 5) { + f = b ^ c ^ d; + t = (a << 5) | (a >>> 27); + e = t + f + e - 899497514 + blocks[j] << 0; + b = (b << 30) | (b >>> 2); + + f = a ^ b ^ c; + t = (e << 5) | (e >>> 27); + d = t + f + d - 899497514 + blocks[j + 1] << 0; + a = (a << 30) | (a >>> 2); + + f = e ^ a ^ b; + t = (d << 5) | (d >>> 27); + c = t + f + c - 899497514 + blocks[j + 2] << 0; + e = (e << 30) | (e >>> 2); + + f = d ^ e ^ a; + t = (c << 5) | (c >>> 27); + b = t + f + b - 899497514 + blocks[j + 3] << 0; + d = (d << 30) | (d >>> 2); + + f = c ^ d ^ e; + t = (b << 5) | (b >>> 27); + a = t + f + a - 899497514 + blocks[j + 4] << 0; + c = (c << 30) | (c >>> 2); + } + + this.h0 = this.h0 + a << 0; + this.h1 = this.h1 + b << 0; + this.h2 = this.h2 + c << 0; + this.h3 = this.h3 + d << 0; + this.h4 = this.h4 + e << 0; + }; + + Sha1.prototype.hex = function () { + this.finalize(); + + var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4; + + return HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] + + HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] + + HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] + + HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] + + HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] + + HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] + + HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] + + HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] + + HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] + + HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] + + HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] + + HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] + + HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F] + + HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] + + HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] + + HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] + + HEX_CHARS[(h4 >> 28) & 0x0F] + HEX_CHARS[(h4 >> 24) & 0x0F] + + HEX_CHARS[(h4 >> 20) & 0x0F] + HEX_CHARS[(h4 >> 16) & 0x0F] + + HEX_CHARS[(h4 >> 12) & 0x0F] + HEX_CHARS[(h4 >> 8) & 0x0F] + + HEX_CHARS[(h4 >> 4) & 0x0F] + HEX_CHARS[h4 & 0x0F]; + }; + + Sha1.prototype.toString = Sha1.prototype.hex; + + Sha1.prototype.digest = function () { + this.finalize(); + + var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4; + + return [ + (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, h0 & 0xFF, + (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, h1 & 0xFF, + (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, h2 & 0xFF, + (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, h3 & 0xFF, + (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, h4 & 0xFF + ]; + }; + + Sha1.prototype.array = Sha1.prototype.digest; + + Sha1.prototype.arrayBuffer = function () { + this.finalize(); + + var buffer = new ArrayBuffer(20); + var dataView = new DataView(buffer); + dataView.setUint32(0, this.h0); + dataView.setUint32(4, this.h1); + dataView.setUint32(8, this.h2); + dataView.setUint32(12, this.h3); + dataView.setUint32(16, this.h4); + return buffer; + }; + + var exports = createMethod(); + + if (COMMON_JS) { + module.exports = exports; + } else { + root.sha1 = exports; + if (AMD) { + define(function () { + return exports; + }); + } + } +})(); \ No newline at end of file diff --git a/qc_decrypt/webapp/index.html b/qc_decrypt/webapp/index.html deleted file mode 100644 index 65a75f1..0000000 --- a/qc_decrypt/webapp/index.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - OpenCortex - - - - - - - QuadCortex serial, found in /etc/qc_sn. Leave it blank for global decryption. -
-
- -
-
- Encrypted file: -
-
- - - - - - - \ No newline at end of file diff --git a/qc_decrypt/webapp/main.js b/qc_decrypt/webapp/main.js deleted file mode 100644 index 792eb3d..0000000 --- a/qc_decrypt/webapp/main.js +++ /dev/null @@ -1,107 +0,0 @@ -// as seen in /usr/lib/libzc.so / SetupKeys -const MASTER_KEY = new Uint8Array([ - 0x13, 0x27, 0x3f, 0x42, - 0xa5, 0xb6, 0x79, 0xe8, - 0x20, 0x31, 0xc4, 0xf5, - 0x16, 0x17, 0x88, 0x2f, - 0x43, 0xa4, 0x55, 0x69, - 0x77, 0xb8, 0xe2, 0x83, - 0x04, 0x05, 0x60, 0x70, - 0x80, 0x02, 0x03, 0x04, - 0x50, 0x6a, 0x7c, 0x8a, - 0x02, 0x30, 0x40, 0x51, - 0x6a, 0x7d, 0x8d, 0x22, - 0x33, 0x44, 0x59, 0x66, - 0x71, 0x08, 0x02, 0x03, - 0x43, 0x05, 0x67, 0x7a, - 0x8f]); - -function hex(byteArray) { - return Array.prototype.map.call(byteArray, function (byte) { - return ('0' + (byte & 0xFF).toString(16)).slice(-2); - }).join(''); -} - -// ported from EVP_BytesToKey -// https://github.com/openssl/openssl/blob/c04e78f0c69201226430fed14c291c281da47f2d/crypto/evp/evp_key.c#L78 -function deriveKeyAndIV(password, iterations = 10) { - var keyLen = 16; - var ivLen = 16; - var addmd = 0; - - var key = new Uint8Array(keyLen); - var iv = new Uint8Array(ivLen); - var tmp = new Uint8Array(); - var i, key_i = 0, iv_i = 0; - - for (; keyLen > 0 || ivLen > 0;) { - if (addmd++) { - block = new Uint8Array([...tmp, ...password]); - } else { - block = password; - } - - tmp = new Uint8Array(sha1.array(block)); - for (i = 1; i < iterations; i++) { - tmp = sha1.array(tmp); - } - - i = 0; - while (keyLen && i != tmp.length) { - key[key_i++] = tmp[i]; - keyLen--; - i++; - } - - while (ivLen != 0 && i != tmp.length) { - iv[iv_i++] = tmp[i]; - ivLen--; - i++; - } - } - - return { key: key, iv: iv }; -} - -function processFileInput(e) { - const fileName = e.target.fileName; - const serial = document.getElementById('serial-input').value; - let main_key = null; - if (serial.length > 0) { - // local decryption, use master key + serial - main_key = new Uint8Array([...MASTER_KEY, ...new TextEncoder("utf-8").encode(serial)]); - } else { - // global decryption, use master key only - main_key = MASTER_KEY; - } - - // derive key and iv with our EVP_BytesToKey port - const derived = deriveKeyAndIV(main_key); - // encrypted file contents - const ciphertext = e.target.result; - // import the raw key - window.crypto.subtle.importKey("raw", derived.key, "AES-CTR", true, ["encrypt", "decrypt"]).then(function (key) { - // decrypt using aes-128-ctr - window.crypto.subtle.decrypt({ name: "AES-CTR", counter: derived.iv, length: 128 }, key, ciphertext).then(function (cleartext) { - var blob = new Blob([cleartext], { type: "application/octet-stream" }); - const link = document.createElement('a'); - link.href = window.URL.createObjectURL(blob); - link.download = fileName + '.dec'; - link.click(); - }); - }); -} - -document.addEventListener("DOMContentLoaded", function () { - // handle file uploads - let fileInput = document.getElementById('file-input') - fileInput.onchange = () => { - const reader = new FileReader() - reader.onload = processFileInput; - for (let file of fileInput.files) { - // https://stackoverflow.com/questions/24245105/how-to-get-the-filename-from-the-javascript-filereader - reader.fileName = file.name; - reader.readAsArrayBuffer(file); - } - }; -}); \ No newline at end of file diff --git a/qc_decrypt/webapp/sha1.js b/qc_decrypt/webapp/sha1.js deleted file mode 100644 index 13d340f..0000000 --- a/qc_decrypt/webapp/sha1.js +++ /dev/null @@ -1,371 +0,0 @@ -/* - * [js-sha1]{@link https://github.com/emn178/js-sha1} - * - * @version 0.6.0 - * @author Chen, Yi-Cyuan [emn178@gmail.com] - * @copyright Chen, Yi-Cyuan 2014-2017 - * @license MIT - */ -/*jslint bitwise: true */ -(function () { - 'use strict'; - - var root = typeof window === 'object' ? window : {}; - var NODE_JS = !root.JS_SHA1_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node; - if (NODE_JS) { - root = global; - } - var COMMON_JS = !root.JS_SHA1_NO_COMMON_JS && typeof module === 'object' && module.exports; - var AMD = typeof define === 'function' && define.amd; - var HEX_CHARS = '0123456789abcdef'.split(''); - var EXTRA = [-2147483648, 8388608, 32768, 128]; - var SHIFT = [24, 16, 8, 0]; - var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer']; - - var blocks = []; - - var createOutputMethod = function (outputType) { - return function (message) { - return new Sha1(true).update(message)[outputType](); - }; - }; - - var createMethod = function () { - var method = createOutputMethod('hex'); - if (NODE_JS) { - method = nodeWrap(method); - } - method.create = function () { - return new Sha1(); - }; - method.update = function (message) { - return method.create().update(message); - }; - for (var i = 0; i < OUTPUT_TYPES.length; ++i) { - var type = OUTPUT_TYPES[i]; - method[type] = createOutputMethod(type); - } - return method; - }; - - var nodeWrap = function (method) { - var crypto = eval("require('crypto')"); - var Buffer = eval("require('buffer').Buffer"); - var nodeMethod = function (message) { - if (typeof message === 'string') { - return crypto.createHash('sha1').update(message, 'utf8').digest('hex'); - } else if (message.constructor === ArrayBuffer) { - message = new Uint8Array(message); - } else if (message.length === undefined) { - return method(message); - } - return crypto.createHash('sha1').update(new Buffer(message)).digest('hex'); - }; - return nodeMethod; - }; - - function Sha1(sharedMemory) { - if (sharedMemory) { - blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = - blocks[4] = blocks[5] = blocks[6] = blocks[7] = - blocks[8] = blocks[9] = blocks[10] = blocks[11] = - blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; - this.blocks = blocks; - } else { - this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - } - - this.h0 = 0x67452301; - this.h1 = 0xEFCDAB89; - this.h2 = 0x98BADCFE; - this.h3 = 0x10325476; - this.h4 = 0xC3D2E1F0; - - this.block = this.start = this.bytes = this.hBytes = 0; - this.finalized = this.hashed = false; - this.first = true; - } - - Sha1.prototype.update = function (message) { - if (this.finalized) { - return; - } - var notString = typeof (message) !== 'string'; - if (notString && message.constructor === root.ArrayBuffer) { - message = new Uint8Array(message); - } - var code, index = 0, i, length = message.length || 0, blocks = this.blocks; - - while (index < length) { - if (this.hashed) { - this.hashed = false; - blocks[0] = this.block; - blocks[16] = blocks[1] = blocks[2] = blocks[3] = - blocks[4] = blocks[5] = blocks[6] = blocks[7] = - blocks[8] = blocks[9] = blocks[10] = blocks[11] = - blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; - } - - if (notString) { - for (i = this.start; index < length && i < 64; ++index) { - blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; - } - } else { - for (i = this.start; index < length && i < 64; ++index) { - code = message.charCodeAt(index); - if (code < 0x80) { - blocks[i >> 2] |= code << SHIFT[i++ & 3]; - } else if (code < 0x800) { - blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3]; - blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; - } else if (code < 0xd800 || code >= 0xe000) { - blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3]; - blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; - blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; - } else { - code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); - blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3]; - blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3]; - blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; - blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; - } - } - } - - this.lastByteIndex = i; - this.bytes += i - this.start; - if (i >= 64) { - this.block = blocks[16]; - this.start = i - 64; - this.hash(); - this.hashed = true; - } else { - this.start = i; - } - } - if (this.bytes > 4294967295) { - this.hBytes += this.bytes / 4294967296 << 0; - this.bytes = this.bytes % 4294967296; - } - return this; - }; - - Sha1.prototype.finalize = function () { - if (this.finalized) { - return; - } - this.finalized = true; - var blocks = this.blocks, i = this.lastByteIndex; - blocks[16] = this.block; - blocks[i >> 2] |= EXTRA[i & 3]; - this.block = blocks[16]; - if (i >= 56) { - if (!this.hashed) { - this.hash(); - } - blocks[0] = this.block; - blocks[16] = blocks[1] = blocks[2] = blocks[3] = - blocks[4] = blocks[5] = blocks[6] = blocks[7] = - blocks[8] = blocks[9] = blocks[10] = blocks[11] = - blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; - } - blocks[14] = this.hBytes << 3 | this.bytes >>> 29; - blocks[15] = this.bytes << 3; - this.hash(); - }; - - Sha1.prototype.hash = function () { - var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4; - var f, j, t, blocks = this.blocks; - - for (j = 16; j < 80; ++j) { - t = blocks[j - 3] ^ blocks[j - 8] ^ blocks[j - 14] ^ blocks[j - 16]; - blocks[j] = (t << 1) | (t >>> 31); - } - - for (j = 0; j < 20; j += 5) { - f = (b & c) | ((~b) & d); - t = (a << 5) | (a >>> 27); - e = t + f + e + 1518500249 + blocks[j] << 0; - b = (b << 30) | (b >>> 2); - - f = (a & b) | ((~a) & c); - t = (e << 5) | (e >>> 27); - d = t + f + d + 1518500249 + blocks[j + 1] << 0; - a = (a << 30) | (a >>> 2); - - f = (e & a) | ((~e) & b); - t = (d << 5) | (d >>> 27); - c = t + f + c + 1518500249 + blocks[j + 2] << 0; - e = (e << 30) | (e >>> 2); - - f = (d & e) | ((~d) & a); - t = (c << 5) | (c >>> 27); - b = t + f + b + 1518500249 + blocks[j + 3] << 0; - d = (d << 30) | (d >>> 2); - - f = (c & d) | ((~c) & e); - t = (b << 5) | (b >>> 27); - a = t + f + a + 1518500249 + blocks[j + 4] << 0; - c = (c << 30) | (c >>> 2); - } - - for (; j < 40; j += 5) { - f = b ^ c ^ d; - t = (a << 5) | (a >>> 27); - e = t + f + e + 1859775393 + blocks[j] << 0; - b = (b << 30) | (b >>> 2); - - f = a ^ b ^ c; - t = (e << 5) | (e >>> 27); - d = t + f + d + 1859775393 + blocks[j + 1] << 0; - a = (a << 30) | (a >>> 2); - - f = e ^ a ^ b; - t = (d << 5) | (d >>> 27); - c = t + f + c + 1859775393 + blocks[j + 2] << 0; - e = (e << 30) | (e >>> 2); - - f = d ^ e ^ a; - t = (c << 5) | (c >>> 27); - b = t + f + b + 1859775393 + blocks[j + 3] << 0; - d = (d << 30) | (d >>> 2); - - f = c ^ d ^ e; - t = (b << 5) | (b >>> 27); - a = t + f + a + 1859775393 + blocks[j + 4] << 0; - c = (c << 30) | (c >>> 2); - } - - for (; j < 60; j += 5) { - f = (b & c) | (b & d) | (c & d); - t = (a << 5) | (a >>> 27); - e = t + f + e - 1894007588 + blocks[j] << 0; - b = (b << 30) | (b >>> 2); - - f = (a & b) | (a & c) | (b & c); - t = (e << 5) | (e >>> 27); - d = t + f + d - 1894007588 + blocks[j + 1] << 0; - a = (a << 30) | (a >>> 2); - - f = (e & a) | (e & b) | (a & b); - t = (d << 5) | (d >>> 27); - c = t + f + c - 1894007588 + blocks[j + 2] << 0; - e = (e << 30) | (e >>> 2); - - f = (d & e) | (d & a) | (e & a); - t = (c << 5) | (c >>> 27); - b = t + f + b - 1894007588 + blocks[j + 3] << 0; - d = (d << 30) | (d >>> 2); - - f = (c & d) | (c & e) | (d & e); - t = (b << 5) | (b >>> 27); - a = t + f + a - 1894007588 + blocks[j + 4] << 0; - c = (c << 30) | (c >>> 2); - } - - for (; j < 80; j += 5) { - f = b ^ c ^ d; - t = (a << 5) | (a >>> 27); - e = t + f + e - 899497514 + blocks[j] << 0; - b = (b << 30) | (b >>> 2); - - f = a ^ b ^ c; - t = (e << 5) | (e >>> 27); - d = t + f + d - 899497514 + blocks[j + 1] << 0; - a = (a << 30) | (a >>> 2); - - f = e ^ a ^ b; - t = (d << 5) | (d >>> 27); - c = t + f + c - 899497514 + blocks[j + 2] << 0; - e = (e << 30) | (e >>> 2); - - f = d ^ e ^ a; - t = (c << 5) | (c >>> 27); - b = t + f + b - 899497514 + blocks[j + 3] << 0; - d = (d << 30) | (d >>> 2); - - f = c ^ d ^ e; - t = (b << 5) | (b >>> 27); - a = t + f + a - 899497514 + blocks[j + 4] << 0; - c = (c << 30) | (c >>> 2); - } - - this.h0 = this.h0 + a << 0; - this.h1 = this.h1 + b << 0; - this.h2 = this.h2 + c << 0; - this.h3 = this.h3 + d << 0; - this.h4 = this.h4 + e << 0; - }; - - Sha1.prototype.hex = function () { - this.finalize(); - - var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4; - - return HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] + - HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] + - HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] + - HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] + - HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] + - HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] + - HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] + - HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] + - HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] + - HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] + - HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] + - HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] + - HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F] + - HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] + - HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] + - HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] + - HEX_CHARS[(h4 >> 28) & 0x0F] + HEX_CHARS[(h4 >> 24) & 0x0F] + - HEX_CHARS[(h4 >> 20) & 0x0F] + HEX_CHARS[(h4 >> 16) & 0x0F] + - HEX_CHARS[(h4 >> 12) & 0x0F] + HEX_CHARS[(h4 >> 8) & 0x0F] + - HEX_CHARS[(h4 >> 4) & 0x0F] + HEX_CHARS[h4 & 0x0F]; - }; - - Sha1.prototype.toString = Sha1.prototype.hex; - - Sha1.prototype.digest = function () { - this.finalize(); - - var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4; - - return [ - (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, h0 & 0xFF, - (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, h1 & 0xFF, - (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, h2 & 0xFF, - (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, h3 & 0xFF, - (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, h4 & 0xFF - ]; - }; - - Sha1.prototype.array = Sha1.prototype.digest; - - Sha1.prototype.arrayBuffer = function () { - this.finalize(); - - var buffer = new ArrayBuffer(20); - var dataView = new DataView(buffer); - dataView.setUint32(0, this.h0); - dataView.setUint32(4, this.h1); - dataView.setUint32(8, this.h2); - dataView.setUint32(12, this.h3); - dataView.setUint32(16, this.h4); - return buffer; - }; - - var exports = createMethod(); - - if (COMMON_JS) { - module.exports = exports; - } else { - root.sha1 = exports; - if (AMD) { - define(function () { - return exports; - }); - } - } -})(); \ No newline at end of file -- cgit v1.2.3