├── timing-patch-2 ├── README.txt ├── patch3.asm ├── patch4.asm ├── patch1.asm ├── Makefile ├── patch2.asm ├── README.md ├── patcher.c └── read-log.c ├── util ├── Makefile └── readhex.c ├── timing-patch-1 ├── Makefile ├── dump.bin ├── README.md ├── linker_script.ld ├── patch-code.c └── main-replacement.c ├── tests ├── log.bin ├── ones.vmdk.akira ├── zeroes.vmdk.akira ├── config-chacha-zeroes.json └── config-test.json ├── public-key-patch ├── pub2.der ├── public.der ├── patch-public-key ├── Makefile ├── README.md ├── patch-zero-time.c ├── patch-public-key.c ├── private.pem └── read-trailer.c ├── test-ts.h ├── generate-test-files.py ├── Makefile ├── chacha8.h ├── kcipher2.h ├── README.md ├── chacha8.c ├── kcipher2.c ├── decrypt.c ├── kcipher2-tables.h ├── akira-bruteforce.h └── LICENSE /timing-patch-2/README.txt: -------------------------------------------------------------------------------- 1 | This is a manual patch 2 | 3 | -------------------------------------------------------------------------------- /util/Makefile: -------------------------------------------------------------------------------- 1 | readhex : readhex.c 2 | cc readhex.c -o readhex 3 | 4 | -------------------------------------------------------------------------------- /timing-patch-1/Makefile: -------------------------------------------------------------------------------- 1 | patch-code : patch-code.c 2 | $(CC) $(CFLAGS) -o $@ $< -------------------------------------------------------------------------------- /tests/log.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yohanes/akira-bruteforce/HEAD/tests/log.bin -------------------------------------------------------------------------------- /tests/ones.vmdk.akira: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yohanes/akira-bruteforce/HEAD/tests/ones.vmdk.akira -------------------------------------------------------------------------------- /tests/zeroes.vmdk.akira: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yohanes/akira-bruteforce/HEAD/tests/zeroes.vmdk.akira -------------------------------------------------------------------------------- /timing-patch-1/dump.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yohanes/akira-bruteforce/HEAD/timing-patch-1/dump.bin -------------------------------------------------------------------------------- /public-key-patch/pub2.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yohanes/akira-bruteforce/HEAD/public-key-patch/pub2.der -------------------------------------------------------------------------------- /public-key-patch/public.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yohanes/akira-bruteforce/HEAD/public-key-patch/public.der -------------------------------------------------------------------------------- /test-ts.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //so we have a consistent test timestamp 4 | 5 | #define TEST_TIMESTAMP 1739876543000000000 -------------------------------------------------------------------------------- /public-key-patch/patch-public-key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yohanes/akira-bruteforce/HEAD/public-key-patch/patch-public-key -------------------------------------------------------------------------------- /timing-patch-2/patch3.asm: -------------------------------------------------------------------------------- 1 | BITS 64 2 | 3 | section .text 4 | 5 | org 0x4466EA 6 | call 0x407F0E ;; write log 7 | xor rax, rax 8 | inc rax 9 | sub ebx, ebx 10 | 11 | -------------------------------------------------------------------------------- /generate-test-files.py: -------------------------------------------------------------------------------- 1 | #generate test files 2 | with open("tests/zeroes.vmdk", "wb") as f: 3 | f.write(b'\x00' * (5*1024*1024)) 4 | with open("tests/ones.vmdk", "wb") as f: 5 | f.write(b'\x01' * (5*1024*1024)) 6 | 7 | -------------------------------------------------------------------------------- /tests/config-chacha-zeroes.json: -------------------------------------------------------------------------------- 1 | { 2 | "t3_ts": 1741841294374553498, 3 | "t3_t1_offset": 3000000, 4 | "t1_t2_start_offset": 1300000, 5 | "t1_t2_end_offset": 2000000, 6 | "encrypted": "0x03d3319ddbf9caee", 7 | "plaintext": "0x0" 8 | } 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: akira-bruteforce decrypt 2 | 3 | akira-bruteforce: akira-bruteforce.cu chacha8.c 4 | nvcc --compiler-options -Wall -arch=sm_86 $(CFLAGS) -O3 -o $@ $^ 5 | 6 | decrypt: decrypt.c chacha8.c kcipher2.c 7 | $(CC) $(CFLAGS) -static -o $@ $^ -lnettle -lhogweed 8 | -------------------------------------------------------------------------------- /timing-patch-2/patch4.asm: -------------------------------------------------------------------------------- 1 | BITS 64 2 | 3 | section .text 4 | 5 | org 0x409650 6 | mov rdi, 0x1000000 7 | call 0x05830F0 ; malloc 8 | lea rsi, pointer 9 | mov [rsi], rax 10 | 11 | 12 | section .data vstart=0x6B75B0 13 | counter: 14 | section .data2 vstart=0x6B75B8 15 | 16 | pointer: 17 | -------------------------------------------------------------------------------- /public-key-patch/Makefile: -------------------------------------------------------------------------------- 1 | all: patch-public-key read-trailer 2 | 3 | patch-public-key: patch-public-key.c 4 | $(CC) $(CFLAGS) -o $@ $< 5 | 6 | read-trailer : read-trailer.c 7 | $(CC) $(CFLAGS) -Wno-deprecated-declarations -o $@ $< -lcrypto -lhogweed -lnettle 8 | 9 | clean: 10 | rm -f patch-public-key read-trailer -------------------------------------------------------------------------------- /timing-patch-2/patch1.asm: -------------------------------------------------------------------------------- 1 | BITS 64 2 | 3 | section .text 4 | 5 | org 0x49149F 6 | lea rsi, counter 7 | mov rdi, [pointer] 8 | mov rcx, [rsi] 9 | inc qword [rsi] 10 | mov [rdi+rcx*8], rax 11 | add rsp, 28h 12 | ret 13 | 14 | 15 | section .data vstart=0x6B75B0 16 | counter: 17 | 18 | section .data2 vstart=0x6B75B8 19 | 20 | pointer: 21 | -------------------------------------------------------------------------------- /timing-patch-1/README.md: -------------------------------------------------------------------------------- 1 | This is an attempt to measure how fast is the random key/IV generation 2 | 3 | I assume you already have patched sample as explained in ../public-key-patch 4 | 5 | This is done by overwriting the main function with our code, that will call the `generate_random` 6 | 7 | This is not very accurate (too fast, it doesn't get interupted), but we can get the lower bound for our offset 8 | 9 | How to use: 10 | ``` 11 | cp ../sample-akira . 12 | make 13 | ./patch-code 14 | ./our-akira 15 | ``` 16 | -------------------------------------------------------------------------------- /timing-patch-2/Makefile: -------------------------------------------------------------------------------- 1 | all: patch1.bin patch2.bin patch3.bin patch4.bin patcher read-log 2 | 3 | patcher: patcher.c 4 | $(CC) $(CFLAGS) -o $@ $< 5 | 6 | read-log: read-log.c 7 | $(CC) $(CFLAGS) -o $@ $< -lnettle 8 | 9 | 10 | patch1.bin: patch1.asm 11 | nasm -f bin -o $@ $< 12 | patch2.bin: patch2.asm 13 | nasm -f bin -o $@ $< 14 | patch3.bin: patch3.asm 15 | nasm -f bin -o $@ $< 16 | patch4.bin: patch4.asm 17 | nasm -f bin -o $@ $< 18 | clean: 19 | rm -f patch1.bin patch2.bin patch3.bin patch4.bin patcher read-log 20 | -------------------------------------------------------------------------------- /public-key-patch/README.md: -------------------------------------------------------------------------------- 1 | # creating patched malware 2 | 3 | This is for creating a patched malware with our own public key 4 | 5 | Go to virus.exchange, register/login 6 | 7 | Get this sample: https://virus.exchange/samples/34613319 8 | 9 | Or search for this hash somewhere else: 10 | 11 | MD5: 6b03b31c8cbd4a0a5829b63d16936ed3 12 | 13 | SHA1: a90790c35bea365befd3af55cbedfffd2cc4481b 14 | 15 | SHA256: bcae978c17bcddc0bf6419ae978e3471197801c36f73cff2fc88cecbe3d88d1a 16 | 17 | 18 | ``` 19 | ./patch-public-key sample pub2.der sample-patched 20 | ``` 21 | -------------------------------------------------------------------------------- /tests/config-test.json: -------------------------------------------------------------------------------- 1 | { 2 | "count": 20000000, 3 | "start_timestamp": 1741841294358440000, 4 | "brute_force_time_range": 30000, 5 | "offset": 1111000, 6 | "matches": [ 7 | { 8 | "filename": "zeroes.vmdk", 9 | "plaintext": "0x0000000000000000", 10 | "encrypted": "0xd5b71efb8d6969e5", 11 | "bitmask": " 0xffffffffffffffff" 12 | }, 13 | { 14 | "filename" :"ones.vmdk", 15 | "plaintext": "0x0101010101010101", 16 | "encrypted": "0x9d1c37f111077987", 17 | "bitmask": " 0xffffffffffffffff" 18 | } 19 | ] 20 | } 21 | 22 | -------------------------------------------------------------------------------- /timing-patch-2/patch2.asm: -------------------------------------------------------------------------------- 1 | BITS 64 2 | 3 | section .text 4 | 5 | org 0x407F0E 6 | 7 | mov rax, 2 ; file open 8 | lea rdi, logfile 9 | mov rsi, 42h ; flags 10 | mov rdx, 1B6h ; mode 11 | syscall 12 | push rax ; fd 13 | mov rdi, rax 14 | mov rsi, [pointer] 15 | mov rdx, [counter] 16 | shl rdx, 3 17 | mov rax, 1 ; write 18 | syscall 19 | pop rdi ; fd 20 | mov rax, 3; close 21 | syscall 22 | ret 23 | 24 | 25 | 26 | logfile db "/tmp/log.bin", 0 27 | 28 | 29 | section .data vstart=0x6B75B0 30 | counter: 31 | 32 | section .data2 vstart=0x6B75B8 33 | 34 | pointer: 35 | -------------------------------------------------------------------------------- /util/readhex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | size_t offset = 0; 8 | if (argc < 2) { 9 | fprintf(stderr, "Usage: %s \n", argv[0]); 10 | return 1; 11 | } 12 | if (argc > 2) { 13 | offset = atoi(argv[2]); 14 | } 15 | FILE *fp = fopen(argv[1], "rb"); 16 | if (!fp) { 17 | perror("fopen"); 18 | return 1; 19 | } 20 | if (fseek(fp, offset, SEEK_SET) < 0) { 21 | perror("fseek"); 22 | fclose(fp); 23 | return 1; 24 | } 25 | uint64_t buf; 26 | fread(&buf, 1, 8, fp); 27 | printf("0x%016lx\n", buf); 28 | fclose(fp); 29 | } 30 | -------------------------------------------------------------------------------- /chacha8.h: -------------------------------------------------------------------------------- 1 | #ifndef SRC_CHACHA8_H_ 2 | #define SRC_CHACHA8_H_ 3 | 4 | #include 5 | 6 | struct chacha8_ctx { 7 | uint32_t input[16]; 8 | }; 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | void chacha8_keysetup(struct chacha8_ctx *x, const uint8_t *k, const uint8_t *iv); 15 | void chacha8_get_keystream_oneblock( 16 | const struct chacha8_ctx *ctx, 17 | uint8_t *c); 18 | 19 | void chacha8_get_keystream( 20 | struct chacha8_ctx *x, 21 | uint64_t pos, 22 | uint32_t n_blocks, 23 | uint8_t *c); 24 | 25 | 26 | 27 | void chacha8_xor_keystream( 28 | struct chacha8_ctx *x, 29 | uint64_t pos, 30 | uint32_t n_blocks, 31 | uint8_t *c); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif // SRC_CHACHA8_H_ 38 | -------------------------------------------------------------------------------- /kcipher2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define INIT 0 6 | #define NORMAL 1 7 | 8 | typedef struct 9 | { 10 | unsigned int A[5]; 11 | unsigned int B[11]; 12 | unsigned int L1, R1, L2, R2; 13 | 14 | } kcipher2_state; 15 | 16 | extern unsigned int IK[12]; 17 | extern unsigned int IV[4]; 18 | extern kcipher2_state State; 19 | 20 | void kcipher2_encrypt(unsigned char* in, unsigned long len, unsigned char* out); 21 | void kcipher2_init(unsigned int* key, unsigned int* iv); 22 | 23 | typedef struct { 24 | kcipher2_state state; 25 | uint64_t remaining; 26 | char buffer[2000*64]; 27 | } kcipher2_stream; 28 | 29 | void init_kcipher2_stream(kcipher2_stream *stream, kcipher2_state *state); 30 | 31 | void kcipher2_xor_data( 32 | kcipher2_stream *stream, 33 | uint64_t size, 34 | uint8_t *data); 35 | -------------------------------------------------------------------------------- /timing-patch-1/linker_script.ld: -------------------------------------------------------------------------------- 1 | SECTIONS { 2 | .my_main 0x406DB7 : { *(.my_main) *(.my_main_string) *(.my_other_functions) } 3 | .func_fxprintf 0x5718c0 : { *(.func_fxprintf) } 4 | .func_snprintf 0x5e8d10 : { *(.func_snprintf) } 5 | .func_get_nanosecond 0x491470 : { *(.func_mw_get_time_seed) } 6 | .func_generate_random 0x455f40 : { *(.func_mw_keygen) } 7 | .func_malloc 0x5830f0 : { *(.func_malloc) } 8 | .func_memset 0x401100 : { *(.func_memset) } 9 | .func_memcpy 0x4010e0 : { *(.func_memcpy) } 10 | .func_mprotect 0x5d54b0 : { *(.func_mprotect) } 11 | .func_getpagesize 0x5d5180 : { *(.func_getpagesize) } 12 | .func_fork 0x5d2900 : { *(.func_fork) } 13 | .data_ransom_note 0x6a7640 : { *(.data_ransom_note) } 14 | .data_counter 0x6b75b0 : { *(.data_counter) } 15 | .data_writable_global 0x6B75BA : { *(.data_writable_global) } 16 | } -------------------------------------------------------------------------------- /timing-patch-2/README.md: -------------------------------------------------------------------------------- 1 | # Patch to record timing 2 | 3 | I assume that you already have patched akira sample, as explained in ../public-key-patch 4 | 5 | To get an accurate reading of the time taken to generate a random key/IV, we will need to record the ransomware encrypting real files. 6 | 7 | These patches will record the time taken to encrypt a file, and write it to a file named `/tmp/log.bin` 8 | 9 | Since this is multithreaded, we don't know the order of the log, but we can figure it out later by reading the trailer of the files, and matching the timestamp. 10 | 11 | ## patch1.asm 12 | 13 | This is added after getting the current time, we record it in the heap. 14 | 15 | ### patch2.asm 16 | 17 | This is a function that will write the content of the heap (containing list of timestamp) into a file named `/tmp/log.bin` 18 | 19 | ### patch3.asm 20 | 21 | This will write the log everytime a new file is processed (this will call `patch2.asm`) 22 | 23 | ### patch4.asm 24 | 25 | This is the initial function that will allocate a buffer using `malloc` 26 | 27 | ## How to use: 28 | 29 | ``` 30 | cp ../sample-akira . 31 | make 32 | ./patch-code sample-patched akira-ts 33 | #copy akira-ts on ESXI host 34 | scp akira-ts esxi-host: 35 | #use akira-ts on ESXI host 36 | ./akira-ts -n=15 -p=/vmfs/volumes/testdir/ 37 | #pull /tmp/log.bin 38 | ./read-log log.bin 39 | #to dump the keys for a file 40 | ../public-key-patch/read-trailer filename.vmdk.akira log.bin 41 | ``` 42 | 43 | -------------------------------------------------------------------------------- /public-key-patch/patch-zero-time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | if (argc != 3) { 7 | fprintf(stderr, "Usage: %s \n", argv[0]); 8 | return 1; 9 | } 10 | 11 | FILE *in = fopen(argv[1], "rb"); 12 | if (!in) { 13 | perror("Failed to open input file"); 14 | return 1; 15 | } 16 | 17 | FILE *out = fopen(argv[2], "wb"); 18 | if (!out) { 19 | perror("Failed to create output file"); 20 | fclose(in); 21 | return 1; 22 | } 23 | 24 | // Copy until patch offset 25 | unsigned char buffer[4096]; 26 | size_t bytes_to_patch = 0x00916f4; 27 | size_t bytes_read; 28 | 29 | while (bytes_to_patch > 0) { 30 | size_t chunk = bytes_to_patch < sizeof(buffer) ? bytes_to_patch : sizeof(buffer); 31 | bytes_read = fread(buffer, 1, chunk, in); 32 | if (bytes_read != chunk) { 33 | perror("Failed to read input file"); 34 | goto cleanup; 35 | } 36 | if (fwrite(buffer, 1, bytes_read, out) != bytes_read) { 37 | perror("Failed to write to output file"); 38 | goto cleanup; 39 | } 40 | bytes_to_patch -= bytes_read; 41 | } 42 | 43 | // Write patch bytes 44 | unsigned char patch[] = {0x31, 0xc0, 0xc3}; 45 | if (fwrite(patch, 1, sizeof(patch), out) != sizeof(patch)) { 46 | perror("Failed to write patch"); 47 | goto cleanup; 48 | } 49 | 50 | // Skip original bytes in input 51 | if (fseek(in, sizeof(patch), SEEK_CUR) != 0) { 52 | perror("Failed to seek in input file"); 53 | goto cleanup; 54 | } 55 | 56 | // Copy remaining bytes 57 | while ((bytes_read = fread(buffer, 1, sizeof(buffer), in)) > 0) { 58 | if (fwrite(buffer, 1, bytes_read, out) != bytes_read) { 59 | perror("Failed to write remaining bytes"); 60 | goto cleanup; 61 | } 62 | } 63 | 64 | fclose(in); 65 | fclose(out); 66 | printf("Successfully created patched file: %s\n", argv[2]); 67 | return 0; 68 | 69 | cleanup: 70 | fclose(in); 71 | fclose(out); 72 | return 1; 73 | } -------------------------------------------------------------------------------- /public-key-patch/patch-public-key.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | //note: this is for patching public key 6 | /* 7 | * DER must use legacy format 8 | * 9 | * openssl pkey -inform PEM -pubin -in public.pem -outform DER -out public.der 10 | * openssl rsa -in public.der -inform DER -pubin -RSAPublicKey_out -outform DER -out pub2.der 11 | */ 12 | 13 | #define PATCH_ADDRESS 0x02a76c0 14 | 15 | #define PAD_SIZE 4096 16 | 17 | void read_file(const char *filename, unsigned char **data, size_t *size) { 18 | FILE *file = fopen(filename, "rb"); 19 | if (!file) { 20 | perror("Failed to open file"); 21 | exit(EXIT_FAILURE); 22 | } 23 | fseek(file, 0, SEEK_END); 24 | *size = ftell(file); 25 | rewind(file); 26 | *data = malloc(*size); 27 | if (!*data) { 28 | perror("Memory allocation failed"); 29 | exit(EXIT_FAILURE); 30 | } 31 | fread(*data, 1, *size, file); 32 | fclose(file); 33 | } 34 | 35 | void write_file(const char *filename, unsigned char *data, size_t size) { 36 | FILE *file = fopen(filename, "wb"); 37 | if (!file) { 38 | perror("Failed to open file"); 39 | exit(EXIT_FAILURE); 40 | } 41 | fwrite(data, 1, size, file); 42 | fclose(file); 43 | } 44 | 45 | void patch_elf(const char *input_elf, const char *public_der, const char *output_elf) { 46 | unsigned char *elf_data, *der_data; 47 | size_t elf_size, der_size; 48 | 49 | read_file(input_elf, &elf_data, &elf_size); 50 | read_file(public_der, &der_data, &der_size); 51 | 52 | if (der_size != 526) { 53 | printf("Invalid DER size\n"); //if it is not 526, we need to patch the length, and we don't need that for now 54 | return; 55 | } 56 | 57 | unsigned char padded_der[PAD_SIZE] = {0}; 58 | memcpy(padded_der, der_data, der_size < PAD_SIZE ? der_size : PAD_SIZE); 59 | free(der_data); 60 | 61 | if (PATCH_ADDRESS + PAD_SIZE > elf_size) { 62 | fprintf(stderr, "Patch address out of bounds\n"); 63 | exit(EXIT_FAILURE); 64 | } 65 | 66 | memcpy(elf_data + PATCH_ADDRESS, padded_der, PAD_SIZE); 67 | 68 | write_file(output_elf, elf_data, elf_size); 69 | free(elf_data); 70 | 71 | printf("Patched %s and saved to %s\n", input_elf, output_elf); 72 | } 73 | 74 | int main(int argc, char *argv[]) { 75 | //read arguments from the command line 76 | if (argc != 4) { 77 | printf("Usage: %s \n", argv[0]); 78 | return EXIT_FAILURE; 79 | } 80 | patch_elf(argv[1], argv[2], argv[3]); 81 | return 0; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Read more about the akira decryption process at https://tinyhack.com 2 | 3 | 4 | Initial chacha8 code is from : https://github.com/madMAx43v3r/chia-plotter, the license is Apache 2: https://github.com/madMAx43v3r/chia-plotter/blob/master/LICENSE 5 | 6 | Initial kcipher2 code is from https://github.com/l00sy4/LCipher2, the license is GPL v3: https://github.com/l00sy4/LCipher2/blob/main/LICENSE 7 | 8 | The License for this software is GPL v3 9 | 10 | ## Requirements 11 | 12 | I tested this on Debian Bookworm, but Ubuntu might be easier to setup 13 | 14 | ``` 15 | apt-get install -y nettle-dev libssl-dev nvidia-cuda-toolkit nvidia-cuda-toolkit-gcc build-essential git nasm 16 | ``` 17 | 18 | ## Building 19 | 20 | ``` 21 | git clone https://github.com/yohanes/akira-bruteforce 22 | cd akira-bruteforce 23 | make 24 | ``` 25 | 26 | ## Testing 27 | 28 | I have provided akira encrypted files (the akira ransomware is patched with my own code to record the timing), you can test it by running 29 | 30 | ``` 31 | cd tests 32 | # Note: this will take several minutes and will make your GPU fans spin fast 33 | ./akira-bruteforce run2 config-test.json 34 | ``` 35 | 36 | Meaning of the fields: 37 | 38 | * `count`: number nano seconds tested starting from `start_timestamp` 39 | * `start_timestamp`: the timestamp when the test started 40 | * `brute_force_time_range`: the time range in nano seconds that we are testing (the "offset range") 41 | * `offset`: the start offset of the brute force 42 | * `matches`: the list of matches to check, the `filename` is used to make the output to be more readable 43 | 44 | ```json 45 | { 46 | "count": 20000000, 47 | "start_timestamp": 1741841294358440000, 48 | "brute_force_time_range": 30000, 49 | "offset": 1111000, 50 | "matches": [ 51 | { 52 | "filename": "zeroes.vmdk", 53 | "plaintext": "0x0000000000000000", 54 | "encrypted": "0xd5b71efb8d6969e5", 55 | "bitmask": " 0xffffffffffffffff" 56 | }, 57 | { 58 | "filename" :"ones.vmdk", 59 | "plaintext": "0x0101010101010101", 60 | "encrypted": "0x9d1c37f111077987", 61 | "bitmask": " 0xffffffffffffffff" 62 | } 63 | ] 64 | } 65 | ``` 66 | 67 | Obtaining plaintext: as explained in the blog post, this depends on the file type 68 | 69 | Obtaining ciphertext: use a hex editor, or use the "readhex" in the util directory 70 | 71 | ``` 72 | ./util/readhex tests/ones.vmdk.akira 73 | ./util/readhex tests/ones.vmdk.akira 65535 # for chacha8 74 | ``` 75 | 76 | ## chacha8 bruteforce 77 | 78 | An example chacha config is like this 79 | 80 | ```json 81 | { 82 | "t3_ts": 1741841294374553498, 83 | "t3_t1_offset": 3000000, 84 | "t1_t2_start_offset": 1300000, 85 | "t1_t2_end_offset": 2000000, 86 | "encrypted": "0x03d3319ddbf9caee", 87 | "plaintext": "0x0" 88 | } 89 | ``` 90 | 91 | * `t3_ts` is the timestamp found by akira-bruteforce 92 | * `t3_t1_offset` is how far back (maximum) the time from `t1` to `t3` 93 | * `t1_t2_start_offset` is the start offset of the brute force 94 | * `t1_t2_end_offset` is the end offset of the brute force 95 | * `encrypted` is the encrypted value 96 | * `plaintext` is the plaintext value 97 | -------------------------------------------------------------------------------- /timing-patch-1/patch-code.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define PATCH_ADDRESS 0x6DB7 7 | 8 | char filename[] = "sample-patched"; 9 | 10 | int main(int argc, char *argv[]) { 11 | 12 | if (argc > 1) { 13 | strcpy(filename, argv[1]); 14 | } 15 | 16 | const char *cmd1 = "clang -O1 -T linker_script.ld -o output.elf main-replacement.c"; 17 | //execute and if it fails, print the error 18 | if (system(cmd1) != 0) { 19 | perror("Error compiling main-replacement.c"); 20 | return EXIT_FAILURE; 21 | } 22 | //check if dump.bin exists 23 | if (access("dump.bin", F_OK) != -1) { 24 | //remove dump.bin 25 | if (remove("dump.bin") != 0) { 26 | perror("Error removing dump.bin"); 27 | return EXIT_FAILURE; 28 | } 29 | } 30 | //execute objcopy --dump-section .my_main=dump.bin output.elf 31 | const char *cmd2 = "objcopy --dump-section .my_main=dump.bin output.elf"; 32 | if (system(cmd2) != 0) { 33 | perror("Error dumping section .my_main"); 34 | return EXIT_FAILURE; 35 | } 36 | //read akira-patched to a buffer 37 | FILE *file = fopen(filename, "rb"); 38 | if (!file) { 39 | perror("Error opening file"); 40 | return EXIT_FAILURE; 41 | } 42 | fseek(file, 0, SEEK_END); 43 | size_t size = ftell(file); 44 | fseek(file, 0, SEEK_SET); 45 | unsigned char *buffer = malloc(size); 46 | if (!buffer) { 47 | perror("Memory allocation failed"); 48 | fclose(file); 49 | return EXIT_FAILURE; 50 | } 51 | if (fread(buffer, 1, size, file) != size) { 52 | perror("Error reading file"); 53 | free(buffer); 54 | fclose(file); 55 | return EXIT_FAILURE; 56 | } 57 | fclose(file); 58 | //read dump.bin to the buffer + PATCH_ADDRESS 59 | file = fopen("dump.bin", "rb"); 60 | if (!file) { 61 | perror("Error opening file"); 62 | free(buffer); 63 | return EXIT_FAILURE; 64 | } 65 | fseek(file, 0, SEEK_END); 66 | size_t size2 = ftell(file); 67 | 68 | //warn if more than 3 kb 69 | if (size2 > 3072) { 70 | printf("WARNING: Section .my_main is larger than 3 KB\n"); 71 | } 72 | 73 | fseek(file, 0, SEEK_SET); 74 | fread(buffer + PATCH_ADDRESS, 1, size2, file); 75 | fclose(file); 76 | //save to our-akira 77 | file = fopen("our-akira", "wb"); 78 | if (!file) { 79 | perror("Error opening file"); 80 | free(buffer); 81 | return EXIT_FAILURE; 82 | } 83 | if (fwrite(buffer, 1, size, file) != size) { 84 | perror("Error writing file"); 85 | free(buffer); 86 | fclose(file); 87 | return EXIT_FAILURE; 88 | } 89 | fclose(file); 90 | //set to executable 91 | const char *cmd3 = "chmod +x our-akira"; 92 | if (system(cmd3) != 0) { 93 | perror("Error setting executable permission"); 94 | return EXIT_FAILURE; 95 | } 96 | free(buffer); 97 | printf("Patched %s and saved to our-akira\n", filename); 98 | 99 | } 100 | -------------------------------------------------------------------------------- /public-key-patch/private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIJQQIBADANBgkqhkiG9w0BAQEFAASCCSswggknAgEAAoICAQC/qXWINh9g3YNk 3 | RDNVUf8uLGStfT3PL+rpFrcD/RAOpW8/jyfEtO+0dEa9x/qq3iquFmZiVEIHKbjC 4 | jqx+UKJNNo/Pybeq8tjvVbF3qatWPsLt6In49u7+/Ko45NYASV873J1qZgMRDw+1 5 | 86ucNFsz3nG2o21ETiHErxcLCs+ycoxK6UjWZ9RGbGDnTsRljErCZW/sZP6lcMRv 6 | BbC2dcrJEukHhtPFlGyglNX7PAyssEOiFYyCHdcs7ArQFxe0QV0seO8L9wQXw1QZ 7 | CHJDHyF4NwLUUUbTHcbjNe1LO6K88yeXcnXkg2UW6ORFMaL09LoiW29/B5QzWvzj 8 | twxRvZZ+09sO+OEe+fewAzxOdyCTPxkofnqJ8RqbgSD94xpvzVsxQ1XYU0QJ1r2h 9 | 17tkiOGOQ0ICskpV2tCNg1E6/tWWcqcsJ0IE/RClp6kMDAaI7QtBOlHY4QxnPs/j 10 | 81YHGlElticqPq3nXItmJvNdeDguBHB7LGrv5imPRkrs83pn4iv7yFtrkeL0i1l1 11 | nEKhyOsfHrzsFvO+thlWBdwklr8YoNvQNy3LP6Qgg4/NCQYxfLu6ROZRU/rGWNlX 12 | iUKE0QDuyWSB/5YIX2+tpRiZv1FsrNYsndtkDEx2RbFA7ZQarzmUM6PAJi43AmNZ 13 | xzsPb3NER8RolAKYlxfze/ndVhBBwwIDAQABAoICAAv+jhyhw5rNxFRSGlCW89xY 14 | PLvbAo6W/OFss9ipjbVXOTeTs/nHzmp8/BSkiEe/5SNzMLQZDIGjQEhq/cbxDHYH 15 | 2b4AtqBQfHgDCc05zoiGsa9BHQVVjQ5jEkDnYdTUC81UvTIP6B8UrUmqrYPj9FV7 16 | TBDtCpvfD5anHQXYPbhCGjFfYjRToPht2S5ZuaTf0hdSdacoP7qQESVErRwRf8j0 17 | UaYHJmLqhlYSCmr/F7H3OIV3t59IrhMhZ1eK4mwXgau5CFHcTDUPEcjl1qJ2SX7a 18 | 9VRxMWZFBbZpaZ54Lrw/IVDzFAc+CYonI2qI2TBfFvRhnzcB/Q5k2Rn2P0gMR0Dn 19 | Q40siMEKK5ITkwkRgg5PvRvsxM6JeWDy5ibGuR240ZcV/LOp0RoAtx7a9V+3zdxJ 20 | RbpgATDFPlpAxF6AjNooHoI0WlAKQNBnFCUt+jnr7tsPQZu2EJcJQUqpOKWHD9+p 21 | d8rkPlDIssrEoqDR1BW/u5nU8OnixrLbSAHFKL3jygjWz8yQeuVqfSvdMoxGsnjn 22 | 11X+QlYX1Y6c4pYKzVhpvvS0RTgd7egEUM2Y/MSUo868ZEh++o4RxyAdie/yMo9P 23 | kwJ5KwWlhO/HWO7md2iR49hvOKZMjM1cfVgCmuXlMDcFizfOB5T+86r8DzDgg+Xt 24 | cntnvQT1sdra6bbfZCKFAoIBAQDvKbPU/+yv0tJ+Xhy5PtVrpca8yRvNvTcQt8/R 25 | q0oNFKhpvbM7IW2bFp9c9FbmNMRMOFfw8+rYOM+uvtBlatm6Vh9eS+IBTmsSvBp0 26 | Bmgmk1YO7zmwlXXuT3P23pn3UwNCfrwVLMr/9mk6LmCiSlHw3yI4JahDLp8DsFd/ 27 | msMEV5fDehq+UUa3dyRK7POs876wdYESnFzkboAZh77dNOJVwocTjLfrIDyGMMaW 28 | UHsqxH852upQgn4IEdJzsXFa7WUT/BkC0QSV89xrq642lMoBSRe38HQCpi1/2edK 29 | GF/cAoAzcuhh8rlXv/nNvPR8hW+2qJaEK6XCHg1ryH4+W+kNAoIBAQDNJ6yE+daS 30 | ELu925vAjJLxqok+bRponmkLkVb1v9p3GOY6PFO3FbkmCyD4cnO1plKvIqgHq4j3 31 | VPjQDWdmEIwtmWvyLKJzdHxnda+tQDvIl1efkQlP4L+zl7qsZVBct9CytTC1gTUI 32 | q0u0spBMGz8R6OBT/LvWwECklRsJD8mtlJ0I0ls/CuXC/pNZ5V1HreiHH85b2D2c 33 | NJ5aJZaPjFtGZhlck84l37T3R1/BTYyt9IFfKlwooL1tYtLLNI9AL8XV/PHsE9IU 34 | 5Kp+a5JPEwCZnHFrlfsD7EvksuFIBz+I0++M06KKF6Afs9gMgqS7yHaQxWFdeZbr 35 | wKq2otEcaYIPAoIBAE3W0tLWYOBwy1WZp9ua2bdpgx9ajRQPK2bjjF3/U+CiApY3 36 | yafLH3NEj6WfWNEgB2uPQwAHQz4Qb3e+XvFDL434DcmRBQPL1AmK80kj9K3pci72 37 | KV6Rpopjjaihlpbqi7sOqIRzybY5KtJm2ci4S6cL2IVRrEwBVnvK3w+G/UXihGB4 38 | 009yAIQh4MwKBt0Zj8y60cGO5qTqWgL1LWetmKS05WW1fP6nxUsfgOLXWt72iTn5 39 | SB3f+skBk+9Xpz8i2K0Cddl20flEH09j1xWoo357nZ6eQgPCtjhQYXi6KijfH36f 40 | PYbziuNGdjVB9Ii6nTtj72khE5f0VAXqgTwmidkCggEAeKgsvshxedZ9lFvkboo+ 41 | ogM6VIy2S3FfNn50NnRveDwcq4NveO49xjIlYfluNBdt6bLoQBqSo2RGMZawiUaS 42 | Kv9gjT3TDTQlNnPwrmRoxMC9uAsE/wWfuXAzSdEMQnuZMoF99EHZfw+/praeRyR/ 43 | I3li9gJeNx865ZEMJXgzlPMiqF2PbLRsDRLMdsJ+6flOGKqMI1g6Y/RObZZNxn81 44 | 72F86QXE6GF5fTVtC7MgWe7DZ8TyDrL6taq5bumqloWCRShO4BmIJOGXpGJ/2iHC 45 | 6JUp36yFxPjkac0K0eHxa/e5m4mcvrrGYd7T4gez+v0bPmnXqbIpIN5fiKqZcaxb 46 | 4QKCAQBpIs8gujn8mosHkv0cKjmjD56IxGYI3JWzNjI1R43HYmakDYUzbJqAhBUN 47 | 1JUyE8p0wV3/GCAjMZRZEFf47FCnSgrhRsG1Z303b0tSv7ovDe75CB3lIbkyn5GB 48 | qNhrlSgPdY09vB0dKAylWvnYEk7m85uK+5iDF07FhmTi5CrD9kcpniM4jtJcP0uJ 49 | aLvrMdQLYmQhr8c2qt7Ilv9J2hwCQwA62pP6/jsno8uE+jxDQblYzvRd2RjKFawo 50 | w9R2kUj9OOeOtCs4q5TksbstneU90dmr3VNzvheLIQF6Yv1Ww2mka5+a9PzlrHyU 51 | sOKmXagzbDe1FDdgyr5b/0WEv0xq 52 | -----END PRIVATE KEY----- 53 | -------------------------------------------------------------------------------- /timing-patch-2/patcher.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void hexdump(const void *data, size_t size) 5 | { 6 | const unsigned char *p = data; 7 | for (size_t i = 0; i < size; i++) 8 | { 9 | printf("%02x ", p[i]); 10 | } 11 | printf("\n"); 12 | } 13 | 14 | void patch_file(const char *thefile, const char *patch_file, size_t offset) 15 | { 16 | //open the file for patching 17 | FILE *file = fopen(thefile, "r+b"); 18 | if (!file) 19 | { 20 | perror("Failed to open file for patching"); 21 | exit(EXIT_FAILURE); 22 | } 23 | //read the entire patch file 24 | FILE *patchfile = fopen(patch_file, "rb"); 25 | if (!patchfile) 26 | { 27 | perror("Failed to open patch file"); 28 | fclose(file); 29 | exit(EXIT_FAILURE); 30 | } 31 | fseek(patchfile, 0, SEEK_END); 32 | size_t patchsize = ftell(patchfile); 33 | fseek(patchfile, 0, SEEK_SET); 34 | unsigned char *patch = malloc(patchsize); 35 | if (!patch) 36 | { 37 | perror("Memory allocation failed"); 38 | fclose(patchfile); 39 | fclose(file); 40 | exit(EXIT_FAILURE); 41 | } 42 | if (fread(patch, 1, patchsize, patchfile) != patchsize) 43 | { 44 | perror("Error reading patch file"); 45 | free(patch); 46 | fclose(patchfile); 47 | fclose(file); 48 | exit(EXIT_FAILURE); 49 | } 50 | fclose(patchfile); 51 | unsigned char *temp = malloc(patchsize); 52 | //goto the offset, read the current data, hexdump 53 | fseek(file, offset, SEEK_SET); 54 | if (fread(temp, 1, patchsize, file) != patchsize) 55 | { 56 | perror("Error reading file for patching"); 57 | free(patch); 58 | free(temp); 59 | fclose(file); 60 | exit(EXIT_FAILURE); 61 | } 62 | printf("Before patching:\n"); 63 | hexdump(temp, patchsize); 64 | //write the patch data 65 | fseek(file, offset, SEEK_SET); 66 | if (fwrite(patch, 1, patchsize, file) != patchsize) 67 | { 68 | perror("Error writing patch data"); 69 | free(patch); 70 | free(temp); 71 | fclose(file); 72 | exit(EXIT_FAILURE); 73 | } 74 | //read the data again, hexdump 75 | fseek(file, offset, SEEK_SET); 76 | if (fread(temp, 1, patchsize, file) != patchsize) 77 | { 78 | perror("Error reading file for patching"); 79 | free(patch); 80 | free(temp); 81 | fclose(file); 82 | exit(EXIT_FAILURE); 83 | } 84 | printf("After patching:\n"); 85 | hexdump(temp, patchsize); 86 | free(patch); 87 | free(temp); 88 | fclose(file); 89 | 90 | } 91 | 92 | int main(int argc, char *argv[]) { 93 | if (argc != 3) { 94 | fprintf(stderr, "Usage: %s \n", argv[0]); 95 | return EXIT_FAILURE; 96 | } 97 | 98 | FILE *input = fopen(argv[1], "rb"); 99 | if (!input) { 100 | perror("Failed to open input file"); 101 | return EXIT_FAILURE; 102 | } 103 | 104 | FILE *output = fopen(argv[2], "wb"); 105 | if (!output) { 106 | perror("Failed to open output file"); 107 | fclose(input); 108 | return EXIT_FAILURE; 109 | } 110 | 111 | char buffer[4096]; 112 | //copy the input file to the output file 113 | size_t bytes_read; 114 | while ((bytes_read = fread(buffer, 1, sizeof(buffer), input)) > 0) { 115 | fwrite(buffer, 1, bytes_read, output); 116 | } 117 | 118 | fclose(input); 119 | fclose(output); 120 | patch_file(argv[2], "patch1.bin", 0x9149F); 121 | patch_file(argv[2], "patch2.bin", 0x7f0e); 122 | patch_file(argv[2], "patch3.bin", 0x466ea); 123 | patch_file(argv[2], "patch4.bin", 0x9650); 124 | 125 | 126 | return EXIT_SUCCESS; 127 | } -------------------------------------------------------------------------------- /chacha8.c: -------------------------------------------------------------------------------- 1 | #include "chacha8.h" 2 | 3 | #include 4 | 5 | __inline static unsigned int __attribute__((__always_inline__, __artificial__, __gnu_inline__)) _rotl(unsigned int value, int count) 6 | { 7 | // count &= 31; 8 | return (value << count) | (value >> (-count & 31)); 9 | } 10 | 11 | 12 | #define U32TO32_LITTLE(v) (v) 13 | #define U8TO32_LITTLE(p) (*(const uint32_t *)(p)) 14 | #define U32TO8_LITTLE(p, v) (((uint32_t *)(p))[0] = U32TO32_LITTLE(v)) 15 | #define ROTL32(v, n) (((v) << (n)) | ((v) >> (32 - (n)))) 16 | 17 | #define ROTATE(v, c) (ROTL32(v, c)) 18 | #define XOR(v, w) ((v) ^ (w)) 19 | #define PLUS(v, w) ((v) + (w)) 20 | #define PLUSONE(v) (PLUS((v), 1)) 21 | 22 | //static const char sigma[16] = "expand 32-byte k"; 23 | static const char tau[16] = "expand 16-byte k"; 24 | 25 | void chacha8_keysetup(struct chacha8_ctx *x, const uint8_t *k, const uint8_t *iv) 26 | { 27 | const char *constants; 28 | 29 | x->input[4] = U8TO32_LITTLE(k + 0); 30 | x->input[5] = U8TO32_LITTLE(k + 4); 31 | x->input[6] = U8TO32_LITTLE(k + 8); 32 | x->input[7] = U8TO32_LITTLE(k + 12); 33 | constants = tau; 34 | 35 | x->input[8] = U8TO32_LITTLE(k + 0); 36 | x->input[9] = U8TO32_LITTLE(k + 4); 37 | x->input[10] = U8TO32_LITTLE(k + 8); 38 | x->input[11] = U8TO32_LITTLE(k + 12); 39 | x->input[0] = U8TO32_LITTLE(constants + 0); 40 | x->input[1] = U8TO32_LITTLE(constants + 4); 41 | x->input[2] = U8TO32_LITTLE(constants + 8); 42 | x->input[3] = U8TO32_LITTLE(constants + 12); 43 | x->input[12] = 0; 44 | x->input[13] = 0; 45 | x->input[14] = U8TO32_LITTLE(iv + 0); 46 | x->input[15] = U8TO32_LITTLE(iv + 4); 47 | 48 | } 49 | 50 | 51 | typedef struct { 52 | uint32_t a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p; 53 | } BLOCK; 54 | 55 | #define QROUND(a, b, c, d) \ 56 | d = _rotl(d ^ (a += b), 16); \ 57 | b = _rotl(b ^ (c += d), 12); \ 58 | d = _rotl(d ^ (a += b), 8); \ 59 | b = _rotl(b ^ (c += d), 7) 60 | #define FROUND \ 61 | QROUND(x.d, x.h, x.l, x.p); \ 62 | QROUND(x.c, x.g, x.k, x.o); \ 63 | QROUND(x.b, x.f, x.j, x.n); \ 64 | QROUND(x.a, x.e, x.i, x.m); \ 65 | QROUND(x.a, x.f, x.k, x.p); \ 66 | QROUND(x.b, x.g, x.l, x.m); \ 67 | QROUND(x.c, x.h, x.i, x.n); \ 68 | QROUND(x.d, x.e, x.j, x.o) 69 | #define FFINAL \ 70 | x.a += j.a; \ 71 | x.b += j.b; \ 72 | x.c += j.c; \ 73 | x.d += j.d; \ 74 | x.e += j.e; \ 75 | x.f += j.f; \ 76 | x.g += j.g; \ 77 | x.h += j.h; \ 78 | x.i += j.i; \ 79 | x.j += j.j; \ 80 | x.k += j.k; \ 81 | x.l += j.l; \ 82 | x.m += j.m; \ 83 | x.n += j.n; \ 84 | x.o += j.o; \ 85 | x.p += j.p 86 | 87 | void chacha8_get_keystream( 88 | struct chacha8_ctx *ctx, 89 | uint64_t pos, 90 | uint32_t n_blocks, 91 | uint8_t *c) 92 | { 93 | BLOCK x; 94 | BLOCK j; 95 | 96 | if (!n_blocks) 97 | return; 98 | 99 | memcpy(&j, ctx, sizeof(BLOCK)); 100 | j.m = pos; 101 | j.n = pos >> 32; 102 | 103 | _BLOCK_LOOP: 104 | 105 | memcpy(&x, &j, sizeof(BLOCK)); 106 | 107 | FROUND; 108 | FROUND; 109 | FROUND; 110 | FROUND; 111 | FFINAL; 112 | 113 | memcpy(c, &x, sizeof(BLOCK)); 114 | 115 | if (--n_blocks) { 116 | c += 64, j.n += !++j.m; 117 | goto _BLOCK_LOOP; 118 | } 119 | } 120 | 121 | void chacha8_xor_keystream( 122 | struct chacha8_ctx *ctx, 123 | uint64_t pos, 124 | uint32_t n_blocks, 125 | uint8_t *c) 126 | { 127 | BLOCK x; 128 | BLOCK j; 129 | 130 | if (!n_blocks) 131 | return; 132 | 133 | memcpy(&j, ctx, sizeof(BLOCK)); 134 | j.m = pos; 135 | j.n = pos >> 32; 136 | 137 | _BLOCK_LOOP: 138 | 139 | memcpy(&x, &j, sizeof(BLOCK)); 140 | 141 | FROUND; 142 | FROUND; 143 | FROUND; 144 | FROUND; 145 | FFINAL; 146 | 147 | uint8_t *src = (uint8_t *)&x; 148 | for (int i = 0; i < 64; i++) { 149 | c[i] ^= src[i]; 150 | } 151 | 152 | if (--n_blocks) { 153 | c += 64, j.n += !++j.m; 154 | goto _BLOCK_LOOP; 155 | } 156 | //memcpy(ctx, &j, sizeof(BLOCK)); 157 | } 158 | 159 | 160 | #define QUARTERROUND(a, b, c, d) \ 161 | a = PLUS(a, b); \ 162 | d = ROTATE(XOR(d, a), 16); \ 163 | c = PLUS(c, d); \ 164 | b = ROTATE(XOR(b, c), 12); \ 165 | a = PLUS(a, b); \ 166 | d = ROTATE(XOR(d, a), 8); \ 167 | c = PLUS(c, d); \ 168 | b = ROTATE(XOR(b, c), 7) 169 | 170 | void chacha8_get_keystream_oneblock( 171 | const struct chacha8_ctx *ctx, 172 | uint8_t *c) 173 | { 174 | BLOCK x; 175 | BLOCK j; 176 | 177 | memcpy(&j, ctx, sizeof(BLOCK)); 178 | j.m = 0; 179 | j.n = 0; 180 | 181 | memcpy(&x, &j, sizeof(BLOCK)); 182 | 183 | FROUND; 184 | FROUND; 185 | FROUND; 186 | FROUND; 187 | FFINAL; 188 | 189 | memcpy(c, &x, sizeof(BLOCK)); 190 | 191 | } 192 | 193 | 194 | -------------------------------------------------------------------------------- /timing-patch-1/main-replacement.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define DUMMY_EXTERNAL_FUNCTION __attribute__((naked)) __attribute__((noinline)) 7 | #define USE_SECTION(x) __attribute__((section(x))) 8 | #define USE_STRING_SECTION __attribute__((section(".my_main_string"))) 9 | 10 | // LIBC functions 11 | 12 | // NOTE: the addresses must be set in linker_script.ld 13 | 14 | // malloc 15 | void *DUMMY_EXTERNAL_FUNCTION USE_SECTION(".func_malloc") my_malloc(size_t size) 16 | { 17 | } 18 | // memcpy 19 | void DUMMY_EXTERNAL_FUNCTION USE_SECTION(".func_memcpy") my_memcpy(void *dest, const void *src, size_t n) 20 | { 21 | } 22 | // memset 23 | void DUMMY_EXTERNAL_FUNCTION USE_SECTION(".func_memset") my_memset(void *s, int c, size_t n) 24 | { 25 | } 26 | 27 | // mprotect 28 | int DUMMY_EXTERNAL_FUNCTION USE_SECTION(".func_mprotect") my_mprotect(void *addr, size_t len, int prot) 29 | { 30 | } 31 | 32 | // fxprintf (when handle is NULL, it will output to stderr) 33 | int DUMMY_EXTERNAL_FUNCTION USE_SECTION(".func_fxprintf") fxprintf(void *handle, const char *format, ...) 34 | { 35 | } 36 | 37 | //snprintf 38 | int DUMMY_EXTERNAL_FUNCTION USE_SECTION(".func_snprintf") my_snprintf(char *str, size_t size, const char *format, ...) 39 | { 40 | } 41 | 42 | // getpagesiz 43 | size_t DUMMY_EXTERNAL_FUNCTION USE_SECTION(".func_getpagesize") my_getpagesize() 44 | { 45 | } 46 | 47 | uint64_t DUMMY_EXTERNAL_FUNCTION USE_SECTION(".func_get_nanosecond") get_nanosecond() 48 | { 49 | } 50 | 51 | void DUMMY_EXTERNAL_FUNCTION USE_SECTION(".func_generate_random") generate_random(void *dummy, int len, uint8_t *result) 52 | { 53 | } 54 | 55 | // fork 56 | int DUMMY_EXTERNAL_FUNCTION USE_SECTION(".func_fork") my_fork() 57 | { 58 | } 59 | 60 | // DATA in binary 61 | 62 | 63 | 64 | volatile uint64_t *ransom_note USE_SECTION(".data_ransom_note") = 0; 65 | 66 | volatile uint32_t *volatile data_counter USE_SECTION(".data_counter") = 0; 67 | 68 | //------------------------------------------------------------------------ 69 | // Main function 70 | //------------------------------------------------------------------------ 71 | 72 | int tmp_time USE_SECTION(".data_writable_global") = 0; 73 | 74 | uint64_t USE_SECTION(".my_other_functions") my_fake_time(int clock, struct timespec *tp) 75 | { 76 | tp->tv_sec = 0; 77 | tp->tv_nsec = 0; 78 | // tp->tv_nsec = tmp_time; 79 | // tmp_time++; 80 | return 0; 81 | } 82 | 83 | 84 | //unbuffered write to stdout 85 | void USE_SECTION(".my_other_functions") my_puts(const char *s) { 86 | int len = 0; 87 | while (s[len] != '\0') 88 | { 89 | len++; 90 | } 91 | asm volatile( 92 | "mov $1, %%rax\n" 93 | "mov $1, %%rdi\n" 94 | "mov %0, %%rsi\n" 95 | "movslq %1, %%rdx\n" // sign extend 32-bit len to 64-bit 96 | "syscall\n" 97 | : 98 | : "r"(s), "r"(len) 99 | : "rax", "rdi", "rsi", "rdx"); 100 | } 101 | 102 | 103 | int USE_SECTION(".my_main") mymain(int argc, char *argv[]) 104 | { 105 | 106 | static const char fmt[] USE_STRING_SECTION = "Time seed: %d '%lld' to '%lld'\n"; 107 | static const char fmt_diff[] USE_STRING_SECTION = "Diff: %d :%lld\n"; 108 | static const char fmt_hex[] USE_STRING_SECTION = "%02x"; 109 | static const char fmt_int[] USE_STRING_SECTION = "%d\n"; 110 | static const char fmt_ptr[] USE_STRING_SECTION = "%p\n"; 111 | static const char fmt_enter[] USE_STRING_SECTION = "\n"; 112 | static const char fmt_ptrnow[] USE_STRING_SECTION = "Pointer now: %p\n"; 113 | 114 | 115 | int page_size = my_getpagesize(); 116 | fxprintf(0, fmt_int, page_size); 117 | 118 | 119 | void *tmp1 = my_malloc(32); 120 | void *tmp2 = my_malloc(16); 121 | void *tmp3 = my_malloc(16); 122 | void *tmp4 = my_malloc(16); 123 | 124 | #define MAX_TEST 1000 125 | unsigned char **tmp_all = my_malloc(MAX_TEST * sizeof(unsigned char *)); 126 | for (int i = 0; i < MAX_TEST; i++) { 127 | asm volatile("" ::: "memory"); 128 | tmp_all[i] = my_malloc(80); 129 | my_memset(tmp_all[i], 0, 80); 130 | 131 | } 132 | 133 | int errno; 134 | errno = 0; 135 | 136 | uint64_t *time_start = my_malloc(MAX_TEST * sizeof(uint64_t)); 137 | uint64_t *time_end = my_malloc(MAX_TEST * sizeof(uint64_t)); 138 | 139 | for (int i =0; i < MAX_TEST; i++) { 140 | my_memset(tmp1, 0, 32); 141 | my_memset(tmp2, 0, 16); 142 | my_memset(tmp3, 0, 16); 143 | my_memset(tmp4, 0, 16); 144 | generate_random(0, 32, tmp1); 145 | generate_random(0, 16, tmp2); 146 | asm volatile("" ::: "memory"); // Prevent compiler optimizations 147 | time_start[i] = get_nanosecond(); 148 | generate_random(0, 16, tmp3); 149 | //generate_random(0, 16, tmp4); 150 | 151 | asm volatile("" ::: "memory"); // Prevent compiler optimizations 152 | time_end[i] = get_nanosecond(); 153 | unsigned char *dest = tmp_all[i]; 154 | my_memcpy(dest, tmp1, 32); 155 | my_memcpy(dest + 32, tmp2, 16); 156 | my_memcpy(dest + 48, tmp3, 16); 157 | my_memcpy(dest + 64, tmp4, 16); 158 | } 159 | for (int i =0; i < MAX_TEST; i++) { 160 | fxprintf(0, fmt, i, time_start[i], time_end[i]); 161 | uint64_t time_diff = time_end[i] - time_start[i]; 162 | fxprintf(0, fmt_diff, i, time_diff); 163 | //dump the buffer 164 | asm volatile("" ::: "memory"); 165 | // unsigned char *dest = tmp_all[i]; 166 | // for (int j = 0; j < 80; j++) { 167 | // fxprintf(0, fmt_hex, dest[j]); 168 | // } 169 | // fxprintf(0, fmt_enter); 170 | } 171 | } 172 | 173 | int main() { return 0; } 174 | -------------------------------------------------------------------------------- /kcipher2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "kcipher2-tables.h" 5 | #include "kcipher2.h" 6 | 7 | unsigned int IK[12]; 8 | unsigned int IV[4]; 9 | kcipher2_state State; 10 | 11 | unsigned int nlf(const unsigned int a, const unsigned int b, const unsigned int c, const unsigned int d) 12 | { 13 | return a + b ^ c ^ d; 14 | } 15 | 16 | unsigned char gf_multiply_by_2(const unsigned char t) 17 | { 18 | unsigned int lq = t << 1; 19 | 20 | if ((lq & 0x100) != 0) 21 | { 22 | lq ^= 0x011B; 23 | } 24 | 25 | return (unsigned char)lq ^ 0xFF; 26 | } 27 | 28 | unsigned char gf_multiply_by_3(const unsigned char t) 29 | { 30 | unsigned int lq = t << 1 ^ t; 31 | 32 | if ((lq & 0x100) != 0) 33 | { 34 | lq ^= 0x011B; 35 | } 36 | 37 | return (unsigned char)lq ^ 0xFF; 38 | } 39 | 40 | unsigned int sub_k2(const unsigned int in) 41 | { 42 | unsigned char w0 = in & 0x000000ff; 43 | unsigned char w1 = in >> 8 & 0x000000ff; 44 | unsigned char w2 = in >> 16 & 0x000000ff; 45 | unsigned char w3 = in >> 24 & 0x000000ff; 46 | 47 | unsigned char t0 = s_box[w0]; 48 | unsigned char t1 = s_box[w1]; 49 | unsigned char t2 = s_box[w2]; 50 | unsigned char t3 = s_box[w3]; 51 | 52 | unsigned char q0 = gf_multiply_by_2(t0) ^ gf_multiply_by_3(t1) ^ t2 ^ t3; 53 | unsigned char q1 = t0 ^ gf_multiply_by_2(t1) ^ gf_multiply_by_3(t2) ^ t3; 54 | unsigned char q2 = t0 ^ t1 ^ gf_multiply_by_2(t2) ^ gf_multiply_by_3(t3); 55 | unsigned char q3 = gf_multiply_by_3(t0) ^ t1 ^ t2 ^ gf_multiply_by_2(t3); 56 | 57 | return q3 << 24 | q2 << 16 | q1 << 8 | q0; 58 | } 59 | 60 | void key_expansion(const unsigned int *key, const unsigned int *iv) 61 | { 62 | IV[0] = iv[0]; 63 | IV[1] = iv[1]; 64 | IV[2] = iv[2]; 65 | IV[3] = iv[3]; 66 | 67 | IK[0] = key[0]; 68 | IK[1] = key[1]; 69 | IK[2] = key[2]; 70 | IK[3] = key[3]; 71 | 72 | IK[4] = IK[0] ^ sub_k2(IK[3] << 8 ^ IK[3] >> 24) ^ 0x01000000; 73 | IK[5] = IK[1] ^ IK[4]; 74 | IK[6] = IK[2] ^ IK[5]; 75 | IK[7] = IK[3] ^ IK[6]; 76 | IK[8] = IK[4] ^ sub_k2(IK[7] << 8 ^ IK[7] >> 24) ^ 0x02000000; 77 | 78 | printf("IK[4] = %08x\n", IK[4]); 79 | printf("IK[7] = %08x\n", IK[7]); 80 | printf("IK[8] = %08x\n", IK[8]); 81 | 82 | IK[9] = IK[5] ^ IK[8]; 83 | IK[10] = IK[6] ^ IK[9]; 84 | IK[11] = IK[7] ^ IK[10]; 85 | } 86 | 87 | void setup_state_values(const unsigned int *key, const unsigned int *iv) 88 | { 89 | key_expansion(key, iv); 90 | 91 | State.A[0] = IK[4]; 92 | State.A[1] = IK[3]; 93 | State.A[2] = IK[2]; 94 | State.A[3] = IK[1]; 95 | State.A[4] = IK[0]; 96 | State.B[0] = IK[10]; 97 | State.B[1] = IK[11]; 98 | State.B[2] = IV[0]; 99 | State.B[3] = IV[1]; 100 | State.B[4] = IK[8]; 101 | State.B[5] = IK[9]; 102 | State.B[6] = IV[2]; 103 | State.B[7] = IV[3]; 104 | State.B[8] = IK[7]; 105 | State.B[9] = IK[5]; 106 | State.B[10] = IK[6]; 107 | 108 | State.L1 = State.R1 = State.L2 = State.R2 = 0x00000000; 109 | } 110 | 111 | void next(const unsigned char mode); 112 | 113 | void kcipher2_init(unsigned int *key, unsigned int *iv) 114 | { 115 | setup_state_values(key, iv); 116 | 117 | for (unsigned char i = 0; i < 24; i++) 118 | { 119 | next(INIT); 120 | } 121 | } 122 | 123 | void next(const unsigned char mode) 124 | { 125 | unsigned int temp2; 126 | 127 | unsigned int nL1 = sub_k2(State.R2 + State.B[4]); 128 | unsigned int nR1 = sub_k2(State.L2 + State.B[9]); 129 | unsigned int nL2 = sub_k2(State.L1); 130 | unsigned int nR2 = sub_k2(State.R1); 131 | 132 | unsigned int nA[5]; 133 | 134 | nA[0] = State.A[1]; 135 | nA[1] = State.A[2]; 136 | nA[2] = State.A[3]; 137 | nA[3] = State.A[4]; 138 | 139 | unsigned int nB[11]; 140 | 141 | nB[0] = State.B[1]; 142 | nB[1] = State.B[2]; 143 | nB[2] = State.B[3]; 144 | nB[3] = State.B[4]; 145 | nB[4] = State.B[5]; 146 | nB[5] = State.B[6]; 147 | nB[6] = State.B[7]; 148 | nB[7] = State.B[8]; 149 | nB[8] = State.B[9]; 150 | nB[9] = State.B[10]; 151 | 152 | unsigned int temp1 = State.A[0] << 8 ^ amul0[(State.A[0] >> 24)]; 153 | nA[4] = temp1 ^ State.A[3]; 154 | 155 | if (mode == INIT) 156 | { 157 | nA[4] ^= nlf(State.B[0], State.R2, State.R1, State.A[4]); 158 | } 159 | 160 | if (State.A[2] & 0x40000000) 161 | { 162 | temp1 = State.B[0] << 8 ^ amul1[(State.B[0] >> 24)]; 163 | } 164 | else 165 | { 166 | temp1 = State.B[0] << 8 ^ amul2[(State.B[0] >> 24)]; 167 | } 168 | 169 | if (State.A[2] & 0x80000000) 170 | { 171 | temp2 = State.B[8] << 8 ^ amul3[(State.B[8] >> 24)]; 172 | } 173 | else 174 | { 175 | temp2 = State.B[8]; 176 | } 177 | 178 | nB[10] = temp1 ^ State.B[1] ^ State.B[6] ^ temp2; 179 | 180 | if (mode == INIT) 181 | { 182 | nB[10] ^= nlf(State.B[10], State.L2, State.L1, State.A[0]); 183 | } 184 | 185 | State.A[0] = nA[0]; 186 | State.A[1] = nA[1]; 187 | State.A[2] = nA[2]; 188 | State.A[3] = nA[3]; 189 | State.A[4] = nA[4]; 190 | State.B[0] = nB[0]; 191 | State.B[1] = nB[1]; 192 | State.B[2] = nB[2]; 193 | State.B[3] = nB[3]; 194 | State.B[4] = nB[4]; 195 | State.B[5] = nB[5]; 196 | State.B[6] = nB[6]; 197 | State.B[7] = nB[7]; 198 | State.B[8] = nB[8]; 199 | State.B[9] = nB[9]; 200 | State.B[10] = nB[10]; 201 | 202 | State.L1 = nL1; 203 | State.R1 = nR1; 204 | State.L2 = nL2; 205 | State.R2 = nR2; 206 | } 207 | 208 | unsigned long long stream() 209 | { 210 | const unsigned int zh = nlf(State.B[10], State.L2, State.L1, State.A[0]); 211 | const unsigned int zl = nlf(State.B[0], State.R2, State.R1, State.A[4]); 212 | 213 | return (unsigned long long)zh << 32 | zl; 214 | } 215 | 216 | void kcipher2_encrypt(unsigned char *in, const unsigned long len, unsigned char *out) 217 | { 218 | unsigned long long key_stream; 219 | unsigned long long *buffer = (unsigned long long *)in; 220 | unsigned long long *out_buffer = (unsigned long long *)out; 221 | 222 | for (unsigned long i = 0; i < len / 8; i++) 223 | { 224 | key_stream = stream(); 225 | next(NORMAL); 226 | 227 | out_buffer[i] = __builtin_bswap64(buffer[i] ^ key_stream); 228 | } 229 | 230 | unsigned long remaining_bytes = len % 8; 231 | 232 | if (remaining_bytes > 0) 233 | { 234 | unsigned char *byte_buffer = (unsigned char *)&buffer[len / 8]; 235 | unsigned char *out_byte_buffer = (unsigned char *)&out_buffer[len / 8]; 236 | 237 | key_stream = stream(); 238 | next(NORMAL); 239 | 240 | for (unsigned long i = 0; i < remaining_bytes; i++) 241 | { 242 | out_byte_buffer[i] = byte_buffer[i] ^ ((unsigned char *)&key_stream)[i]; 243 | } 244 | } 245 | } 246 | 247 | void init_kcipher2_stream(kcipher2_stream *stream, kcipher2_state *state) 248 | { 249 | memset(stream, 0, sizeof(kcipher2_stream)); 250 | memcpy(&stream->state, state, sizeof(kcipher2_state)); 251 | } 252 | 253 | static uint8_t enc_zero_block[128*1024]; 254 | 255 | void kcipher2_xor_data( 256 | kcipher2_stream *stream, 257 | uint64_t size, 258 | uint8_t *data) 259 | { 260 | printf("kcipher size: %d\n", size); 261 | if (stream->remaining < size) 262 | { 263 | int needed = size + stream->remaining; 264 | // round up to nearest 64 byte 265 | int blocks = (needed + 63) / 64; 266 | printf("requesting %d blocks\n", blocks); 267 | int block_size = blocks * 64; 268 | assert(block_size < sizeof(enc_zero_block)); 269 | kcipher2_encrypt(enc_zero_block, block_size, stream->buffer + stream->remaining); 270 | stream->remaining += block_size; 271 | } 272 | // xor the data, then move remaining to the front 273 | for (int i = 0; i < size; i++) 274 | { 275 | //printf("%02x ", (uint8_t)stream->buffer[i]); 276 | data[i] ^= stream->buffer[i]; 277 | } 278 | printf("\n"); 279 | memmove(stream->buffer, stream->buffer+size, stream->remaining - size); 280 | stream->remaining -= size; 281 | printf("remaining: %d\n", stream->remaining); 282 | } 283 | -------------------------------------------------------------------------------- /timing-patch-2/read-log.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define YARROW_RESEED_ITERATIONS 1500 11 | 12 | static inline void WRITE_UINT32(uint8_t *p, uint32_t i) { 13 | p[0] = (i >> 24) & 0xff; 14 | p[1] = (i >> 16) & 0xff; 15 | p[2] = (i >> 8) & 0xff; 16 | p[3] = i & 0xff; 17 | } 18 | 19 | 20 | //TODO: fast version still crashing 21 | #if USE_OPENSSL 22 | 23 | #include 24 | #include 25 | 26 | 27 | /* Yarrow-256, based on SHA-256 and AES-256 */ 28 | struct yarrow256_fast_ctx 29 | { 30 | /* Indexed by yarrow_pool_id */ 31 | SHA256_CTX pools[2]; 32 | 33 | int seeded; 34 | 35 | /* The current key and counter block */ 36 | AES_KEY key; 37 | uint8_t counter[AES_BLOCK_SIZE]; 38 | 39 | /* The entropy sources */ 40 | unsigned nsources; 41 | struct yarrow_source *sources; 42 | }; 43 | 44 | 45 | 46 | 47 | void 48 | yarrow256_fast_init(struct yarrow256_fast_ctx *ctx, 49 | unsigned n, 50 | struct yarrow_source *s) 51 | { 52 | unsigned i; 53 | memset(ctx, 0, sizeof(*ctx)); 54 | 55 | SHA256_Init(&ctx->pools[0]); 56 | SHA256_Init(&ctx->pools[1]); 57 | 58 | ctx->seeded = 0; 59 | 60 | /* Not strictly necessary, but it makes it easier to see if the 61 | * values are sane. */ 62 | memset(ctx->counter, 0, sizeof(ctx->counter)); 63 | 64 | ctx->nsources = n; 65 | ctx->sources = s; 66 | 67 | for (i = 0; isources[i].estimate[YARROW_FAST] = 0; 70 | ctx->sources[i].estimate[YARROW_SLOW] = 0; 71 | ctx->sources[i].next = YARROW_FAST; 72 | } 73 | //initialize AES key 74 | 75 | } 76 | 77 | void yarrow256_fast_seed(struct yarrow256_fast_ctx *ctx, size_t length, const uint8_t *seed_file) 78 | { 79 | uint8_t digest[SHA256_DIGEST_SIZE]; 80 | uint8_t v0[SHA256_DIGEST_SIZE]; 81 | uint8_t count[4]; 82 | uint32_t i; 83 | 84 | assert(length > 0); 85 | 86 | /* Update the FAST pool with seed data */ 87 | SHA256_Update(&ctx->pools[YARROW_FAST], seed_file, length); 88 | SHA256_Final(digest, &ctx->pools[YARROW_FAST]); 89 | 90 | memcpy(v0, digest, SHA256_DIGEST_SIZE); 91 | 92 | /* Reseed iterations: hash (digest || v0 || count) repeatedly */ 93 | for (i = 1; i < YARROW_RESEED_ITERATIONS; i++) { 94 | SHA256_CTX hash; 95 | SHA256_Init(&hash); 96 | SHA256_Update(&hash, digest, SHA256_DIGEST_SIZE); 97 | SHA256_Update(&hash, v0, SHA256_DIGEST_SIZE); 98 | WRITE_UINT32(count, i); 99 | SHA256_Update(&hash, count, sizeof(count)); 100 | SHA256_Final(digest, &hash); 101 | } 102 | 103 | /* Set the 256-bit AES key using the final digest */ 104 | AES_set_encrypt_key(digest, 256, &ctx->key); 105 | ctx->seeded = 1; 106 | 107 | /* Derive a new counter value by encrypting a zero block */ 108 | memset(ctx->counter, 0, sizeof(ctx->counter)); 109 | AES_encrypt(ctx->counter, ctx->counter, &ctx->key); 110 | 111 | /* Reset the entropy estimates for all sources in the FAST pool */ 112 | for (i = 0; i < ctx->nsources; i++) { 113 | ctx->sources[i].estimate[YARROW_FAST] = 0; 114 | } 115 | } 116 | 117 | void fast_gen_key() 118 | { 119 | time_t t = time(0); 120 | 121 | struct yarrow256_fast_ctx ctx; 122 | yarrow256_fast_init(&ctx, 0, NULL); 123 | char seed[32]; 124 | snprintf(seed, sizeof(seed), "%lld", t); 125 | 126 | yarrow256_fast_seed(&ctx, strlen(seed), seed); 127 | //char buffer[32]; 128 | //yarrow256_random(&ctx, 32, buffer); 129 | // for (int i =0; i < sizeof(buffer); i++) { 130 | // printf("%02x", (unsigned char )(buffer[i])); 131 | // } 132 | // printf("\n"); 133 | } 134 | 135 | #endif 136 | 137 | static void 138 | yarrow_iterate(uint8_t *digest) 139 | { 140 | uint8_t v0[SHA256_DIGEST_SIZE]; 141 | unsigned i; 142 | 143 | memcpy(v0, digest, SHA256_DIGEST_SIZE); 144 | 145 | /* When hashed inside the loop, i should run from 1 to 146 | * YARROW_RESEED_ITERATIONS */ 147 | for (i = 0; ++i < YARROW_RESEED_ITERATIONS; ) 148 | { 149 | uint8_t count[4]; 150 | struct sha256_ctx hash; 151 | 152 | sha256_init(&hash); 153 | 154 | /* Hash v_i | v_0 | i */ 155 | WRITE_UINT32(count, i); 156 | sha256_update(&hash, SHA256_DIGEST_SIZE, digest); 157 | sha256_update(&hash, sizeof(v0), v0); 158 | sha256_update(&hash, sizeof(count), count); 159 | 160 | sha256_digest(&hash, SHA256_DIGEST_SIZE, digest); 161 | } 162 | } 163 | 164 | /* FIXME: Generalize so that it generates a few more blocks at a 165 | * time. */ 166 | static void 167 | yarrow_generate_block(struct yarrow256_ctx *ctx, 168 | uint8_t *block) 169 | { 170 | unsigned i; 171 | 172 | aes256_encrypt(&ctx->key, sizeof(ctx->counter), block, ctx->counter); 173 | 174 | /* Increment counter, treating it as a big-endian number. This is 175 | * machine independent, and follows appendix B of the NIST 176 | * specification of cipher modes of operation. 177 | * 178 | * We could keep a representation of the counter as 4 32-bit values, 179 | * and write entire words (in big-endian byteorder) into the counter 180 | * block, whenever they change. */ 181 | for (i = sizeof(ctx->counter); i--; ) 182 | { 183 | if (++ctx->counter[i]) 184 | break; 185 | } 186 | } 187 | 188 | void 189 | yarrow256_fast_reseed_debug(struct yarrow256_ctx *ctx) 190 | { 191 | uint8_t digest[SHA256_DIGEST_SIZE]; 192 | unsigned i; 193 | 194 | #if YARROW_DEBUG 195 | fprintf(stderr, "yarrow256_fast_reseed\n"); 196 | #endif 197 | 198 | /* We feed two block of output using the current key into the pool 199 | * before emptying it. */ 200 | if (ctx->seeded) 201 | { 202 | uint8_t blocks[AES_BLOCK_SIZE * 2]; 203 | 204 | yarrow_generate_block(ctx, blocks); 205 | yarrow_generate_block(ctx, blocks + AES_BLOCK_SIZE); 206 | sha256_update(&ctx->pools[YARROW_FAST], sizeof(blocks), blocks); 207 | } 208 | 209 | sha256_digest(&ctx->pools[YARROW_FAST], sizeof(digest), digest); 210 | 211 | /* Iterate */ 212 | yarrow_iterate(digest); 213 | 214 | //debug print the digest 215 | // for (int i = 0; i < sizeof(digest); i++) { 216 | // printf("%02x", (unsigned char)(digest[i])); 217 | // } 218 | // printf("\n"); 219 | 220 | aes256_set_encrypt_key(&ctx->key, digest); 221 | ctx->seeded = 1; 222 | 223 | /* Derive new counter value */ 224 | memset(ctx->counter, 0, sizeof(ctx->counter)); 225 | aes256_encrypt(&ctx->key, sizeof(ctx->counter), ctx->counter, ctx->counter); 226 | 227 | /* Reset estimates. */ 228 | for (i = 0; insources; i++) 229 | ctx->sources[i].estimate[YARROW_FAST] = 0; 230 | } 231 | 232 | 233 | 234 | 235 | void 236 | yarrow256_seed_debug(struct yarrow256_ctx *ctx, 237 | size_t length, 238 | const uint8_t *seed_file) 239 | { 240 | assert(length > 0); 241 | 242 | sha256_update(&ctx->pools[YARROW_FAST], length, seed_file); 243 | yarrow256_fast_reseed_debug(ctx); 244 | } 245 | 246 | 247 | 248 | void gen_key(uint64_t t) 249 | { 250 | 251 | struct yarrow256_ctx ctx; 252 | yarrow256_init(&ctx, 0, NULL); 253 | char seed[32]; 254 | snprintf(seed, sizeof(seed), "%lld", t); 255 | 256 | yarrow256_seed(&ctx, strlen(seed), seed); 257 | char buffer[32]; 258 | yarrow256_random(&ctx, 32, buffer); 259 | for (int i =0; i < sizeof(buffer); i++) { 260 | printf("%02x", (unsigned char )(buffer[i])); 261 | } 262 | printf("\n"); 263 | } 264 | 265 | 266 | int main(int argc, char *argv[]) 267 | { 268 | if (argc < 2) { 269 | printf("Usage: %s \n", argv[0]); 270 | return 1; 271 | } 272 | //read log file 273 | FILE *fp = fopen(argv[1], "rb"); 274 | if (fp == NULL) { 275 | printf("Error: Unable to open file %s\n", argv[1]); 276 | return 1; 277 | } 278 | fseek(fp, 0, SEEK_END); 279 | long fsize = ftell(fp); 280 | fseek(fp, 0, SEEK_SET); 281 | char *buffer = malloc(fsize + 1); 282 | if (buffer == NULL) { 283 | printf("Error: Unable to allocate memory\n"); 284 | return 1; 285 | } 286 | fread(buffer, fsize, 1, fp); 287 | fclose(fp); 288 | uint64_t *t = (uint64_t *)buffer; 289 | for (int i = 0; i < fsize/sizeof(uint64_t); i++) { 290 | 291 | if (t[i] < 1700000000000000000) { 292 | break; 293 | } 294 | if (t[i] > 1800000000000000000) { 295 | break; 296 | } 297 | printf("t = %lld: ", t[i]); 298 | gen_key(t[i]); 299 | } 300 | 301 | 302 | 303 | } -------------------------------------------------------------------------------- /public-key-patch/read-trailer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | const char *PRIVATE_KEY_PEM = 14 | "-----BEGIN PRIVATE KEY-----\n" 15 | "MIIJQQIBADANBgkqhkiG9w0BAQEFAASCCSswggknAgEAAoICAQC/qXWINh9g3YNk\n" 16 | "RDNVUf8uLGStfT3PL+rpFrcD/RAOpW8/jyfEtO+0dEa9x/qq3iquFmZiVEIHKbjC\n" 17 | "jqx+UKJNNo/Pybeq8tjvVbF3qatWPsLt6In49u7+/Ko45NYASV873J1qZgMRDw+1\n" 18 | "86ucNFsz3nG2o21ETiHErxcLCs+ycoxK6UjWZ9RGbGDnTsRljErCZW/sZP6lcMRv\n" 19 | "BbC2dcrJEukHhtPFlGyglNX7PAyssEOiFYyCHdcs7ArQFxe0QV0seO8L9wQXw1QZ\n" 20 | "CHJDHyF4NwLUUUbTHcbjNe1LO6K88yeXcnXkg2UW6ORFMaL09LoiW29/B5QzWvzj\n" 21 | "twxRvZZ+09sO+OEe+fewAzxOdyCTPxkofnqJ8RqbgSD94xpvzVsxQ1XYU0QJ1r2h\n" 22 | "17tkiOGOQ0ICskpV2tCNg1E6/tWWcqcsJ0IE/RClp6kMDAaI7QtBOlHY4QxnPs/j\n" 23 | "81YHGlElticqPq3nXItmJvNdeDguBHB7LGrv5imPRkrs83pn4iv7yFtrkeL0i1l1\n" 24 | "nEKhyOsfHrzsFvO+thlWBdwklr8YoNvQNy3LP6Qgg4/NCQYxfLu6ROZRU/rGWNlX\n" 25 | "iUKE0QDuyWSB/5YIX2+tpRiZv1FsrNYsndtkDEx2RbFA7ZQarzmUM6PAJi43AmNZ\n" 26 | "xzsPb3NER8RolAKYlxfze/ndVhBBwwIDAQABAoICAAv+jhyhw5rNxFRSGlCW89xY\n" 27 | "PLvbAo6W/OFss9ipjbVXOTeTs/nHzmp8/BSkiEe/5SNzMLQZDIGjQEhq/cbxDHYH\n" 28 | "2b4AtqBQfHgDCc05zoiGsa9BHQVVjQ5jEkDnYdTUC81UvTIP6B8UrUmqrYPj9FV7\n" 29 | "TBDtCpvfD5anHQXYPbhCGjFfYjRToPht2S5ZuaTf0hdSdacoP7qQESVErRwRf8j0\n" 30 | "UaYHJmLqhlYSCmr/F7H3OIV3t59IrhMhZ1eK4mwXgau5CFHcTDUPEcjl1qJ2SX7a\n" 31 | "9VRxMWZFBbZpaZ54Lrw/IVDzFAc+CYonI2qI2TBfFvRhnzcB/Q5k2Rn2P0gMR0Dn\n" 32 | "Q40siMEKK5ITkwkRgg5PvRvsxM6JeWDy5ibGuR240ZcV/LOp0RoAtx7a9V+3zdxJ\n" 33 | "RbpgATDFPlpAxF6AjNooHoI0WlAKQNBnFCUt+jnr7tsPQZu2EJcJQUqpOKWHD9+p\n" 34 | "d8rkPlDIssrEoqDR1BW/u5nU8OnixrLbSAHFKL3jygjWz8yQeuVqfSvdMoxGsnjn\n" 35 | "11X+QlYX1Y6c4pYKzVhpvvS0RTgd7egEUM2Y/MSUo868ZEh++o4RxyAdie/yMo9P\n" 36 | "kwJ5KwWlhO/HWO7md2iR49hvOKZMjM1cfVgCmuXlMDcFizfOB5T+86r8DzDgg+Xt\n" 37 | "cntnvQT1sdra6bbfZCKFAoIBAQDvKbPU/+yv0tJ+Xhy5PtVrpca8yRvNvTcQt8/R\n" 38 | "q0oNFKhpvbM7IW2bFp9c9FbmNMRMOFfw8+rYOM+uvtBlatm6Vh9eS+IBTmsSvBp0\n" 39 | "Bmgmk1YO7zmwlXXuT3P23pn3UwNCfrwVLMr/9mk6LmCiSlHw3yI4JahDLp8DsFd/\n" 40 | "msMEV5fDehq+UUa3dyRK7POs876wdYESnFzkboAZh77dNOJVwocTjLfrIDyGMMaW\n" 41 | "UHsqxH852upQgn4IEdJzsXFa7WUT/BkC0QSV89xrq642lMoBSRe38HQCpi1/2edK\n" 42 | "GF/cAoAzcuhh8rlXv/nNvPR8hW+2qJaEK6XCHg1ryH4+W+kNAoIBAQDNJ6yE+daS\n" 43 | "ELu925vAjJLxqok+bRponmkLkVb1v9p3GOY6PFO3FbkmCyD4cnO1plKvIqgHq4j3\n" 44 | "VPjQDWdmEIwtmWvyLKJzdHxnda+tQDvIl1efkQlP4L+zl7qsZVBct9CytTC1gTUI\n" 45 | "q0u0spBMGz8R6OBT/LvWwECklRsJD8mtlJ0I0ls/CuXC/pNZ5V1HreiHH85b2D2c\n" 46 | "NJ5aJZaPjFtGZhlck84l37T3R1/BTYyt9IFfKlwooL1tYtLLNI9AL8XV/PHsE9IU\n" 47 | "5Kp+a5JPEwCZnHFrlfsD7EvksuFIBz+I0++M06KKF6Afs9gMgqS7yHaQxWFdeZbr\n" 48 | "wKq2otEcaYIPAoIBAE3W0tLWYOBwy1WZp9ua2bdpgx9ajRQPK2bjjF3/U+CiApY3\n" 49 | "yafLH3NEj6WfWNEgB2uPQwAHQz4Qb3e+XvFDL434DcmRBQPL1AmK80kj9K3pci72\n" 50 | "KV6Rpopjjaihlpbqi7sOqIRzybY5KtJm2ci4S6cL2IVRrEwBVnvK3w+G/UXihGB4\n" 51 | "009yAIQh4MwKBt0Zj8y60cGO5qTqWgL1LWetmKS05WW1fP6nxUsfgOLXWt72iTn5\n" 52 | "SB3f+skBk+9Xpz8i2K0Cddl20flEH09j1xWoo357nZ6eQgPCtjhQYXi6KijfH36f\n" 53 | "PYbziuNGdjVB9Ii6nTtj72khE5f0VAXqgTwmidkCggEAeKgsvshxedZ9lFvkboo+\n" 54 | "ogM6VIy2S3FfNn50NnRveDwcq4NveO49xjIlYfluNBdt6bLoQBqSo2RGMZawiUaS\n" 55 | "Kv9gjT3TDTQlNnPwrmRoxMC9uAsE/wWfuXAzSdEMQnuZMoF99EHZfw+/praeRyR/\n" 56 | "I3li9gJeNx865ZEMJXgzlPMiqF2PbLRsDRLMdsJ+6flOGKqMI1g6Y/RObZZNxn81\n" 57 | "72F86QXE6GF5fTVtC7MgWe7DZ8TyDrL6taq5bumqloWCRShO4BmIJOGXpGJ/2iHC\n" 58 | "6JUp36yFxPjkac0K0eHxa/e5m4mcvrrGYd7T4gez+v0bPmnXqbIpIN5fiKqZcaxb\n" 59 | "4QKCAQBpIs8gujn8mosHkv0cKjmjD56IxGYI3JWzNjI1R43HYmakDYUzbJqAhBUN\n" 60 | "1JUyE8p0wV3/GCAjMZRZEFf47FCnSgrhRsG1Z303b0tSv7ovDe75CB3lIbkyn5GB\n" 61 | "qNhrlSgPdY09vB0dKAylWvnYEk7m85uK+5iDF07FhmTi5CrD9kcpniM4jtJcP0uJ\n" 62 | "aLvrMdQLYmQhr8c2qt7Ilv9J2hwCQwA62pP6/jsno8uE+jxDQblYzvRd2RjKFawo\n" 63 | "w9R2kUj9OOeOtCs4q5TksbstneU90dmr3VNzvheLIQF6Yv1Ww2mka5+a9PzlrHyU\n" 64 | "sOKmXagzbDe1FDdgyr5b/0WEv0xq\n" 65 | "-----END PRIVATE KEY-----\n"; 66 | 67 | 68 | uint32_t swap32(uint32_t a1) 69 | { 70 | return (a1 >> 8 << 16) & 0xFF0000 | (a1 << 8 >> 16) & 0xFF00 | (a1 >> 24) | (a1 << 24); 71 | } 72 | 73 | void inverse_swap32_buffer(uint32_t *buffer, size_t size) 74 | { 75 | for (size_t i = 0; i < size / 4; i++) 76 | { 77 | buffer[i] = swap32(buffer[i]); // Applying swap32 again to reverse 78 | } 79 | } 80 | 81 | void hexdump(const char *title, uint8_t *data, int len) 82 | { 83 | printf("%s: ", title); 84 | for (int i = 0; i < len; i++) 85 | { 86 | printf("%02x", data[i]); 87 | if ((i + 1) % 16 == 0) 88 | { 89 | printf("\n"); 90 | } 91 | } 92 | printf("\n"); 93 | } 94 | 95 | void hexprint(uint8_t *data, int len) 96 | { 97 | for (int i = 0; i < len; i++) 98 | { 99 | printf("%02x", data[i]); 100 | } 101 | printf(" "); 102 | } 103 | 104 | void split_back(uint64_t a1, // original byte length of first array 105 | uint64_t a3, // original byte length of second array 106 | const uint32_t *merged, // merged (and swapped) array 107 | uint32_t *out1, // output: first array (unswapped) 108 | uint32_t *out2) // output: second array (unswapped) 109 | { 110 | // Compute word counts for each array. 111 | size_t count1 = a1 >> 2; 112 | size_t count2 = a3 >> 2; 113 | size_t total = count1 + count2; 114 | 115 | // Determine interleaving pattern (must match merge_and_swap): 116 | // If a1 is 32 bytes (i.e. 8 words) then every 3rd word starting at index 2 came from the second array. 117 | // Otherwise, every 2nd word starting at index 1 came from the second array. 118 | int next_arr2_index, arr2_step; 119 | if (a1 == 32) 120 | { 121 | next_arr2_index = 2; 122 | arr2_step = 3; 123 | } 124 | else 125 | { 126 | next_arr2_index = 1; 127 | arr2_step = 2; 128 | } 129 | 130 | size_t index1 = 0, index2 = 0; 131 | for (size_t i = 0; i < total; i++) 132 | { 133 | // If this position originally came from arr2, recover it there. 134 | if ((int)i == next_arr2_index) 135 | { 136 | out2[index2++] = swap32(merged[i]); 137 | next_arr2_index += arr2_step; 138 | } 139 | else 140 | { 141 | // Otherwise, it came from arr1. 142 | out1[index1++] = swap32(merged[i]); 143 | } 144 | } 145 | } 146 | 147 | 148 | 149 | void gen_key(uint64_t t, char *dest) 150 | { 151 | 152 | struct yarrow256_ctx ctx; 153 | yarrow256_init(&ctx, 0, NULL); 154 | char seed[32]; 155 | snprintf(seed, sizeof(seed), "%lld", t); 156 | 157 | yarrow256_seed(&ctx, strlen(seed), seed); 158 | char buffer[32]; 159 | yarrow256_random(&ctx, 32, buffer); 160 | for (int i =0; i < sizeof(buffer); i++) { 161 | printf("%02x", (unsigned char )(buffer[i])); 162 | } 163 | memcpy(dest, buffer, 32); 164 | printf("\n"); 165 | } 166 | 167 | 168 | static uint64_t *timestamps; 169 | static char **timestamp_random; 170 | static int timestamp_count; 171 | 172 | int readlog(char *logfile) 173 | { 174 | //read log file 175 | FILE *fp = fopen(logfile, "rb"); 176 | if (fp == NULL) { 177 | printf("Error: Unable to open file %s\n", logfile); 178 | return 1; 179 | } 180 | fseek(fp, 0, SEEK_END); 181 | long fsize = ftell(fp); 182 | fseek(fp, 0, SEEK_SET); 183 | char *buffer = malloc(fsize + 1); 184 | if (buffer == NULL) { 185 | printf("Error: Unable to allocate memory\n"); 186 | return 1; 187 | } 188 | fread(buffer, fsize, 1, fp); 189 | fclose(fp); 190 | uint64_t *t = (uint64_t *)buffer; 191 | for (int i = 0; i < fsize/sizeof(uint64_t); i++) { 192 | if (t[i] < 1700000000000000000) { 193 | break; 194 | } 195 | if (t[i] > 1800000000000000000) { 196 | break; 197 | } 198 | printf("t = %lld: ", t[i]); 199 | char *random = (char *)malloc(32); 200 | gen_key(t[i], random); 201 | timestamp_random = (char **)realloc(timestamp_random, (i+1)*sizeof(char *)); 202 | timestamp_random[i] = random; 203 | timestamp_count = i + 1; 204 | } 205 | timestamps = t; 206 | return 0; 207 | } 208 | 209 | uint64_t search_timestamp(char *data, int len) 210 | { 211 | for (int i = 0; i < timestamp_count; i++) { 212 | if (memcmp(timestamp_random[i], data, len)==0) { 213 | return timestamps[i]; 214 | } 215 | } 216 | return 0; 217 | } 218 | 219 | int main(int argc, char *argv[]) 220 | { 221 | 222 | if (argc > 1) 223 | { 224 | if (argc > 2) { 225 | readlog(argv[2]); 226 | } 227 | const char *input_filename = argv[1]; 228 | FILE *input_file = fopen(input_filename, "rb"); 229 | if (!input_file) 230 | { 231 | perror("Error opening input file"); 232 | return EXIT_FAILURE; 233 | } 234 | 235 | fseek(input_file, 0, SEEK_END); 236 | long file_size = ftell(input_file); 237 | if (file_size < 512) 238 | { 239 | printf("File is smaller than 512 bytes, processing entire file.\n"); 240 | file_size = 512; 241 | } 242 | 243 | fseek(input_file, file_size - 512, SEEK_SET); 244 | uint8_t buffer[512]; 245 | size_t bytes_read = fread(buffer, 1, 512, input_file); 246 | fclose(input_file); 247 | 248 | if (bytes_read == 0) 249 | { 250 | perror("Error reading file"); 251 | return EXIT_FAILURE; 252 | } 253 | 254 | int inlen = 512; 255 | 256 | inverse_swap32_buffer((uint32_t *)buffer, bytes_read); 257 | 258 | BIO *bio = BIO_new_mem_buf(PRIVATE_KEY_PEM, -1); 259 | if (!bio) 260 | { 261 | perror("Error creating BIO"); 262 | return EXIT_FAILURE; 263 | } 264 | 265 | RSA *rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL); 266 | BIO_free(bio); 267 | if (!rsa) 268 | { 269 | printf("Error reading private key\n"); 270 | return EXIT_FAILURE; 271 | } 272 | 273 | unsigned char *encrypted = buffer; 274 | unsigned char *decrypted = malloc(RSA_size(rsa)); 275 | if (!decrypted) 276 | { 277 | printf("Error allocating memory\n"); 278 | return EXIT_FAILURE; 279 | } 280 | int decrypted_len = RSA_private_decrypt(inlen, encrypted, decrypted, rsa, RSA_PKCS1_PADDING); 281 | if (decrypted_len == -1) 282 | { 283 | printf("Error decrypting\n"); 284 | return EXIT_FAILURE; 285 | } 286 | RSA_free(rsa); 287 | 288 | uint8_t chacha20_key[32]; 289 | uint8_t chacha20_nonce[16]; 290 | uint8_t *start_chacha = (uint8_t *)decrypted + 11; 291 | split_back(32, 16, (uint32_t *)start_chacha, (uint32_t *)chacha20_key, (uint32_t *)chacha20_nonce); 292 | hexdump("chacha20_key", chacha20_key, 32); 293 | uint64_t t1 = search_timestamp(chacha20_key, 32); 294 | if (t1 != 0) { 295 | printf("T1 = %lld\n\n", t1); 296 | } 297 | 298 | hexdump("chacha20_nonce", chacha20_nonce, 16); 299 | uint64_t t2 = search_timestamp(chacha20_nonce, 16); 300 | if (t2 != 0) { 301 | printf("T2 = %lld\n\n", t2); 302 | } 303 | 304 | 305 | uint8_t *start_kcipher2 = (uint8_t *)decrypted + 59; 306 | uint8_t kcipher2_key[16]; 307 | uint8_t kcipher2_iv[16]; 308 | split_back(16, 16, (uint32_t *)start_kcipher2, (uint32_t *)kcipher2_key, (uint32_t *)kcipher2_iv); 309 | hexdump("kcipher2_key", kcipher2_key, 16); 310 | uint64_t t3 = search_timestamp(kcipher2_key, 16); 311 | if (t3 != 0) { 312 | printf("T3 = %lld\n\n", t3); 313 | } 314 | 315 | 316 | hexdump("kcipher2_iv", kcipher2_iv, 16); 317 | uint64_t t4 = search_timestamp(kcipher2_iv, 16); 318 | if (t4 != 0) { 319 | printf("T4 = %lld\n", t4); 320 | } 321 | 322 | if (timestamp_count > 0) { 323 | printf("\n"); 324 | printf("T4 - T3 = %d\n", t4 - t3); 325 | printf("T3 - T1 = %d\n", t3 - t1); 326 | printf("T2 - T1 = %d\n", t2 - t1); 327 | } 328 | 329 | } 330 | else 331 | { 332 | printf("No arguments provided\n"); 333 | } 334 | } 335 | -------------------------------------------------------------------------------- /decrypt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "chacha8.h" 10 | #include "test-ts.h" 11 | #include "kcipher2.h" 12 | #include 13 | 14 | 15 | uint32_t swap32(uint32_t x) 16 | { 17 | return ((x & 0xff) << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | ((x & 0xff000000) >> 24); 18 | } 19 | 20 | 21 | void gen_key(uint64_t t, char *buffer, int size) 22 | { 23 | struct yarrow256_ctx ctx; 24 | yarrow256_init(&ctx, 0, NULL); 25 | char seed[32]; 26 | snprintf(seed, sizeof(seed), "%lld", t); 27 | 28 | yarrow256_seed(&ctx, strlen(seed), seed); 29 | yarrow256_random(&ctx, size, buffer); 30 | 31 | } 32 | 33 | void hexdump(const char *title, const void *data, size_t size) 34 | { 35 | printf("%s: ", title); 36 | const uint8_t *p = data; 37 | for (size_t i = 0; i < size; i++) { 38 | printf("%02x ", p[i]); 39 | } 40 | printf("\n"); 41 | } 42 | 43 | 44 | 45 | void compute_blocks(uint64_t filesize, 46 | uint8_t percent, 47 | uint64_t *enc_block_size, 48 | uint64_t *part_size, 49 | uint64_t *encrypted_parts) 50 | { 51 | int parts = 3; 52 | if ( percent > 49u ) 53 | parts = 5; 54 | uint64_t enc_size = filesize * (uint64_t)percent / 100; 55 | *enc_block_size = enc_size / parts; 56 | *encrypted_parts = parts - 1; 57 | *part_size = (filesize - *enc_block_size * (*encrypted_parts)) / parts; 58 | } 59 | 60 | void test_compute() 61 | { 62 | uint64_t enc_block_size; 63 | uint64_t part_size; 64 | uint64_t encrypted_parts; 65 | compute_blocks(330, 15, &enc_block_size, &part_size, &encrypted_parts); 66 | printf("Enc block size: %lld\n", enc_block_size); 67 | printf("Part size: %lld\n", part_size); 68 | printf("Encrypted parts: %lld\n", encrypted_parts); 69 | } 70 | 71 | void decrypt_file_bykey(const char *filename, 72 | uint8_t *chacha8_key, 73 | uint8_t *cacha8_nonce, 74 | uint8_t *kcipher2_key, 75 | uint8_t *kcipher2_iv 76 | ) 77 | { 78 | 79 | //get file size 80 | FILE *fp = fopen(filename, "rb"); 81 | if (!fp) { 82 | perror("fopen"); 83 | return; 84 | } 85 | fseek(fp, 0, SEEK_END); 86 | uint64_t filesize = ftell(fp); 87 | fseek(fp, 0, SEEK_SET); 88 | fclose(fp); 89 | 90 | 91 | uint64_t enc_block_size; 92 | uint64_t part_size; 93 | uint64_t encrypted_parts; 94 | #define PERCENT 15 95 | compute_blocks(filesize - 512, PERCENT, &enc_block_size, &part_size, &encrypted_parts); 96 | 97 | printf("Allocating: %zu bytes\n", enc_block_size); 98 | 99 | uint8_t *enc_block = (uint8_t *)malloc(128*1024); 100 | 101 | 102 | fp = fopen(filename, "r+b"); 103 | if (!fp) { 104 | perror("fopen"); 105 | free(enc_block); 106 | return; 107 | } 108 | 109 | struct chacha8_ctx chacha_ctx; 110 | 111 | chacha8_keysetup(&chacha_ctx, chacha8_key, cacha8_nonce); 112 | 113 | 114 | uint32_t *kcipher2_key_ptr = (uint32_t *)kcipher2_key; 115 | //swap32 116 | for (int i = 0; i < 4; i++) { 117 | kcipher2_key_ptr[i] = swap32(kcipher2_key_ptr[i]); 118 | } 119 | 120 | uint32_t *kcipher2_iv_ptr = (uint32_t *)kcipher2_iv; 121 | //swap32 122 | for (int i = 0; i < 4; i++) { 123 | kcipher2_iv_ptr[i] = swap32(kcipher2_iv_ptr[i]); 124 | } 125 | 126 | kcipher2_init(kcipher2_key_ptr, kcipher2_iv_ptr); 127 | 128 | kcipher2_stream stream; 129 | init_kcipher2_stream(&stream, &State); 130 | 131 | size_t chacha_bytes = 0; 132 | int current_chacha_block = 0; 133 | 134 | for (int i = 0; encrypted_parts > i; ++i ) 135 | { 136 | uint64_t offs = 0LL; 137 | uint64_t block_pos = part_size * i; 138 | while ( offs < enc_block_size ) 139 | { 140 | size_t enc_size = 0xFFFFLL; 141 | if ( enc_block_size - offs <= 0xFFFF ) 142 | enc_size = enc_block_size - offs; 143 | 144 | assert(enc_size < 128*1024); 145 | 146 | //seek to offs + block_pos 147 | fseek(fp, offs + block_pos, SEEK_SET); 148 | //read enc_size 149 | size_t bytesread = fread(enc_block, 1, enc_size, fp); 150 | if ( bytesread != enc_size ) 151 | { 152 | perror("fread"); 153 | free(enc_block); 154 | fclose(fp); 155 | return; 156 | } 157 | int current_enc = 0; 158 | if ( !offs || enc_block_size <= offs + bytesread ) 159 | current_enc = 1; // kcipher2 160 | 161 | if ( current_enc ) { 162 | //kcipher2 163 | printf("Decrypting with kcipher2: %d at offs %zu\n", bytesread, offs + block_pos); 164 | //hexdump("Encrypted kcipher2 block", enc_block, bytesread>32?32:bytesread); 165 | 166 | // // block size must be multiple of 8 167 | // int block_size = bytesread; 168 | // if (block_size % 8 != 0) { 169 | // block_size = (block_size / 8 + 1) * 8; 170 | // } 171 | // kcipher2_encrypt(enc_zero_block, block_size, enc_tmp_block); 172 | // for (int i = 0; i < bytesread; i++) { 173 | // enc_block[i] ^= enc_tmp_block[i]; 174 | // } 175 | kcipher2_xor_data(&stream, bytesread, enc_block); 176 | 177 | // //dump enc_tmp_block 178 | // hexdump("stream", enc_tmp_block, bytesread>32?32:bytesread); 179 | // //last 32 bytes 180 | // hexdump("stream (last 32 bytes)", enc_tmp_block + bytesread - 32,bytesread>32?32:bytesread); 181 | 182 | 183 | //hexdump("decrypted kchiper2", enc_block, bytesread>32?32:bytesread); 184 | //last 32 185 | //hexdump("decrypted kchiper2 (last 32 bytes)", enc_block + bytesread - 32, bytesread>32?32:bytesread); 186 | } else { 187 | //hexdump("Encrypted block", enc_block, bytesread>32?32:bytesread); 188 | 189 | printf("Decrypting with chacha8 %zu offs=%zu\n", bytesread, offs); 190 | //chacha8 191 | 192 | int blocks = (bytesread + 63) / 64; 193 | chacha8_xor_keystream(&chacha_ctx, current_chacha_block, blocks, enc_block); 194 | current_chacha_block += blocks; 195 | 196 | //chacha8_xor_data(&chacha_stream, bytesread, enc_block); 197 | chacha_bytes += bytesread ; 198 | //hexdump("decrypted chacha", enc_block, bytesread<32?bytesread:32); 199 | //dump last 32 bytes 200 | //hexdump("decrypted chacha (last 32 bytes)", enc_block + bytesread - 32, bytesread>32?32:bytesread); 201 | 202 | } 203 | //seek and write back 204 | fseek(fp, offs + block_pos, SEEK_SET); 205 | fwrite(enc_block, 1, bytesread, fp); 206 | offs += bytesread; 207 | 208 | } 209 | } 210 | //truncate last 512 bytes 211 | ftruncate(fileno(fp), filesize - 512); 212 | fclose(fp); 213 | free(enc_block); 214 | printf("Decryption done\n"); 215 | //rename, removing .akira from end of file 216 | char newname[256]; 217 | snprintf(newname, sizeof(newname), "%s", filename); 218 | if (strstr(newname, ".akira")) { 219 | newname[strlen(newname) - 6] = 0; 220 | rename(filename, newname); 221 | } 222 | 223 | 224 | 225 | #if 0 226 | struct chacha8_ctx chacha_ctx; 227 | chacha8_keysetup(&chacha_ctx, chacha8_key, cacha8_nonce); 228 | //dump keystream hex 229 | printf("Chacha 20 state: "); 230 | uint8_t *state = (uint8_t *)chacha_ctx.input; 231 | for (int i = 0; i < 64; i++) { 232 | printf("%02x ", state[i]); 233 | } 234 | printf("\n"); 235 | uint8_t test_data[256]; 236 | uint8_t test_data_out[256]; 237 | memset(test_data, 0, sizeof(test_data)); 238 | memset(test_data_out, 0, sizeof(test_data_out)); 239 | 240 | chacha8_get_keystream(&chacha_ctx, 0, 5, test_data); 241 | hexdump("Chacha8 Stream", test_data, sizeof(test_data)); 242 | 243 | uint32_t *kcipher2_key_ptr = (uint32_t *)kcipher2_key; 244 | //swap32 245 | for (int i = 0; i < 4; i++) { 246 | kcipher2_key_ptr[i] = swap32(kcipher2_key_ptr[i]); 247 | } 248 | 249 | uint32_t *kcipher2_iv_ptr = (uint32_t *)kcipher2_iv; 250 | //swap32 251 | for (int i = 0; i < 4; i++) { 252 | kcipher2_iv_ptr[i] = swap32(kcipher2_iv_ptr[i]); 253 | } 254 | 255 | //for testing zero vectors 256 | // memset(kcipher2_key_ptr, 0, 16); 257 | // memset(kcipher2_iv_ptr, 0, 16); 258 | 259 | printf("KEY as int32: "); 260 | for (int i = 0; i < 4; i++) { 261 | printf("%08x ", kcipher2_key_ptr[i]); 262 | } 263 | printf("\n"); 264 | printf("IV as int32: "); 265 | for (int i = 0; i < 4; i++) { 266 | printf("%08x ", kcipher2_iv_ptr[i]); 267 | } 268 | printf("\n"); 269 | 270 | kcipher2_init(kcipher2_key_ptr, kcipher2_iv_ptr); 271 | 272 | 273 | /* 274 | * 275 | typedef struct 276 | { 277 | unsigned int A[5]; 278 | unsigned int B[11]; 279 | unsigned int L1, R1, L2, R2; 280 | 281 | } kcipher2_state; 282 | 283 | */ 284 | //DUMP all the state 285 | // printf("kcipher2_state:\n"); 286 | // printf("A[5]:\n"); 287 | // for (int i = 0; i < 5; i++) { 288 | // printf("%08x ", State.A[i]); 289 | // } 290 | // printf("\n"); 291 | // printf("B[11]:\n"); 292 | // for (int i = 0; i < 11; i++) { 293 | // printf("%08x ", State.B[i]); 294 | // } 295 | // printf("\n"); 296 | // printf("L1: %08x\n", State.L1); 297 | // printf("R1: %08x\n", State.R1); 298 | // printf("L2: %08x\n", State.L2); 299 | // printf("R2: %08x\n", State.R2); 300 | // printf("\n"); 301 | 302 | memset(test_data, 0, sizeof(test_data)); 303 | memset(test_data_out, 0, sizeof(test_data_out)); 304 | kcipher2_encrypt(test_data, sizeof(test_data), test_data_out); 305 | hexdump("Kcipher2 Stream", test_data_out, sizeof(test_data_out)); 306 | #endif 307 | } 308 | 309 | 310 | void decrypt_file(const char *filename, uint64_t t1, uint64_t t2, uint64_t t3, uint64_t t4) 311 | { 312 | uint8_t chacha8_key[32]; 313 | uint8_t cacha8_nonce[16]; 314 | uint8_t kcipher2_key[16]; 315 | uint8_t kcipher2_iv[16]; 316 | 317 | printf("T1 = %lld\n", t1); 318 | gen_key(t1, chacha8_key, 32); 319 | hexdump("chacha8_k8", chacha8_key, 32); 320 | printf("T2 = %lld\n", t2); 321 | gen_key(t2, cacha8_nonce, 16); 322 | hexdump("chacha8_nonce", cacha8_nonce, 16); 323 | printf("T3 = %lld\n", t3); 324 | gen_key(t3, kcipher2_key, 16); 325 | hexdump("kcipher2_key ", kcipher2_key, 16); 326 | printf("T4 = %lld\n", t4); 327 | gen_key(t4, kcipher2_iv, 16); 328 | hexdump("kcipher2_iv ", kcipher2_iv, 16); 329 | 330 | decrypt_file_bykey(filename, chacha8_key, cacha8_nonce, kcipher2_key, kcipher2_iv); 331 | 332 | } 333 | 334 | 335 | int main(int argc, char *argv[]) 336 | { 337 | //test_compute(); 338 | 339 | // uint8_t chacha8_key[32]; 340 | // uint8_t cacha8_nonce[16]; 341 | // uint8_t kcipher2_key[16]; 342 | // uint8_t kcipher2_iv[16]; 343 | // memset(chacha8_key, 0, sizeof(chacha8_key)); 344 | // memset(cacha8_nonce, 0, sizeof(cacha8_nonce)); 345 | // memset(kcipher2_key, 0, sizeof(kcipher2_key)); 346 | // memset(kcipher2_iv, 0, sizeof(kcipher2_iv)); 347 | 348 | // printf("Test zero input: "); 349 | // decrypt_file_bykey("test-zero/mytest.akira", chacha8_key, cacha8_nonce, kcipher2_key, kcipher2_iv); 350 | 351 | if (argc > 5) { 352 | uint64_t t1 = atoll(argv[2]); 353 | uint64_t t2 = atoll(argv[3]); 354 | uint64_t t3 = atoll(argv[4]); 355 | uint64_t t4 = atoll(argv[5]); 356 | decrypt_file(argv[1], t1, t2, t3, t4); 357 | } else { 358 | printf("Usage: %s \n", argv[0]); 359 | } 360 | 361 | 362 | // uint64_t time_start = TEST_TIMESTAMP; 363 | // decrypt_file("test-zero/mytest.akira", time_start, time_start + 1000, time_start +2000 , time_start + 3000); 364 | // decrypt_file("test-zero/mytest.akira", time_start, time_start + 1000, time_start +2000 , time_start + 3001); 365 | // decrypt_file("test-zero/mytest.akira", time_start, time_start + 1000, time_start +2000 , time_start + 3999); 366 | // decrypt_file("test-zero/mytest.akira", time_start, time_start + 1000, time_start +2001 , time_start + 3001); 367 | 368 | return 0; 369 | } 370 | -------------------------------------------------------------------------------- /kcipher2-tables.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | static const unsigned char s_box[256] = 4 | { 5 | 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 6 | 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 7 | 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 8 | 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 9 | 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 10 | 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 11 | 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 12 | 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 13 | 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 14 | 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 15 | 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 16 | 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 17 | 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 18 | 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 19 | 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 20 | 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 21 | 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 22 | 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 23 | 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 24 | 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 25 | 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 26 | 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 27 | 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 28 | 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 29 | 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 30 | 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 31 | 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 32 | 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 33 | 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 34 | 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 35 | 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 36 | 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 37 | }; 38 | 39 | static const unsigned int amul0[256] = 40 | { 41 | 0x00000000,0xB6086D1A,0xAF10DA34,0x1918B72E, 42 | 0x9D207768,0x2B281A72,0x3230AD5C,0x8438C046, 43 | 0xF940EED0,0x4F4883CA,0x565034E4,0xE05859FE, 44 | 0x646099B8,0xD268F4A2,0xCB70438C,0x7D782E96, 45 | 0x31801F63,0x87887279,0x9E90C557,0x2898A84D, 46 | 0xACA0680B,0x1AA80511,0x03B0B23F,0xB5B8DF25, 47 | 0xC8C0F1B3,0x7EC89CA9,0x67D02B87,0xD1D8469D, 48 | 0x55E086DB,0xE3E8EBC1,0xFAF05CEF,0x4CF831F5, 49 | 0x62C33EC6,0xD4CB53DC,0xCDD3E4F2,0x7BDB89E8, 50 | 0xFFE349AE,0x49EB24B4,0x50F3939A,0xE6FBFE80, 51 | 0x9B83D016,0x2D8BBD0C,0x34930A22,0x829B6738, 52 | 0x06A3A77E,0xB0ABCA64,0xA9B37D4A,0x1FBB1050, 53 | 0x534321A5,0xE54B4CBF,0xFC53FB91,0x4A5B968B, 54 | 0xCE6356CD,0x786B3BD7,0x61738CF9,0xD77BE1E3, 55 | 0xAA03CF75,0x1C0BA26F,0x05131541,0xB31B785B, 56 | 0x3723B81D,0x812BD507,0x98336229,0x2E3B0F33, 57 | 0xC4457C4F,0x724D1155,0x6B55A67B,0xDD5DCB61, 58 | 0x59650B27,0xEF6D663D,0xF675D113,0x407DBC09, 59 | 0x3D05929F,0x8B0DFF85,0x921548AB,0x241D25B1, 60 | 0xA025E5F7,0x162D88ED,0x0F353FC3,0xB93D52D9, 61 | 0xF5C5632C,0x43CD0E36,0x5AD5B918,0xECDDD402, 62 | 0x68E51444,0xDEED795E,0xC7F5CE70,0x71FDA36A, 63 | 0x0C858DFC,0xBA8DE0E6,0xA39557C8,0x159D3AD2, 64 | 0x91A5FA94,0x27AD978E,0x3EB520A0,0x88BD4DBA, 65 | 0xA6864289,0x108E2F93,0x099698BD,0xBF9EF5A7, 66 | 0x3BA635E1,0x8DAE58FB,0x94B6EFD5,0x22BE82CF, 67 | 0x5FC6AC59,0xE9CEC143,0xF0D6766D,0x46DE1B77, 68 | 0xC2E6DB31,0x74EEB62B,0x6DF60105,0xDBFE6C1F, 69 | 0x97065DEA,0x210E30F0,0x381687DE,0x8E1EEAC4, 70 | 0x0A262A82,0xBC2E4798,0xA536F0B6,0x133E9DAC, 71 | 0x6E46B33A,0xD84EDE20,0xC156690E,0x775E0414, 72 | 0xF366C452,0x456EA948,0x5C761E66,0xEA7E737C, 73 | 0x4B8AF89E,0xFD829584,0xE49A22AA,0x52924FB0, 74 | 0xD6AA8FF6,0x60A2E2EC,0x79BA55C2,0xCFB238D8, 75 | 0xB2CA164E,0x04C27B54,0x1DDACC7A,0xABD2A160, 76 | 0x2FEA6126,0x99E20C3C,0x80FABB12,0x36F2D608, 77 | 0x7A0AE7FD,0xCC028AE7,0xD51A3DC9,0x631250D3, 78 | 0xE72A9095,0x5122FD8F,0x483A4AA1,0xFE3227BB, 79 | 0x834A092D,0x35426437,0x2C5AD319,0x9A52BE03, 80 | 0x1E6A7E45,0xA862135F,0xB17AA471,0x0772C96B, 81 | 0x2949C658,0x9F41AB42,0x86591C6C,0x30517176, 82 | 0xB469B130,0x0261DC2A,0x1B796B04,0xAD71061E, 83 | 0xD0092888,0x66014592,0x7F19F2BC,0xC9119FA6, 84 | 0x4D295FE0,0xFB2132FA,0xE23985D4,0x5431E8CE, 85 | 0x18C9D93B,0xAEC1B421,0xB7D9030F,0x01D16E15, 86 | 0x85E9AE53,0x33E1C349,0x2AF97467,0x9CF1197D, 87 | 0xE18937EB,0x57815AF1,0x4E99EDDF,0xF89180C5, 88 | 0x7CA94083,0xCAA12D99,0xD3B99AB7,0x65B1F7AD, 89 | 0x8FCF84D1,0x39C7E9CB,0x20DF5EE5,0x96D733FF, 90 | 0x12EFF3B9,0xA4E79EA3,0xBDFF298D,0x0BF74497, 91 | 0x768F6A01,0xC087071B,0xD99FB035,0x6F97DD2F, 92 | 0xEBAF1D69,0x5DA77073,0x44BFC75D,0xF2B7AA47, 93 | 0xBE4F9BB2,0x0847F6A8,0x115F4186,0xA7572C9C, 94 | 0x236FECDA,0x956781C0,0x8C7F36EE,0x3A775BF4, 95 | 0x470F7562,0xF1071878,0xE81FAF56,0x5E17C24C, 96 | 0xDA2F020A,0x6C276F10,0x753FD83E,0xC337B524, 97 | 0xED0CBA17,0x5B04D70D,0x421C6023,0xF4140D39, 98 | 0x702CCD7F,0xC624A065,0xDF3C174B,0x69347A51, 99 | 0x144C54C7,0xA24439DD,0xBB5C8EF3,0x0D54E3E9, 100 | 0x896C23AF,0x3F644EB5,0x267CF99B,0x90749481, 101 | 0xDC8CA574,0x6A84C86E,0x739C7F40,0xC594125A, 102 | 0x41ACD21C,0xF7A4BF06,0xEEBC0828,0x58B46532, 103 | 0x25CC4BA4,0x93C426BE,0x8ADC9190,0x3CD4FC8A, 104 | 0xB8EC3CCC,0x0EE451D6,0x17FCE6F8,0xA1F48BE2 105 | }; 106 | 107 | static const unsigned int amul1[256] = 108 | { 109 | 0x00000000,0xA0F5FC2E,0x6DC7D55C,0xCD322972, 110 | 0xDAA387B8,0x7A567B96,0xB76452E4,0x1791AECA, 111 | 0x996B235D,0x399EDF73,0xF4ACF601,0x54590A2F, 112 | 0x43C8A4E5,0xE33D58CB,0x2E0F71B9,0x8EFA8D97, 113 | 0x1FD646BA,0xBF23BA94,0x721193E6,0xD2E46FC8, 114 | 0xC575C102,0x65803D2C,0xA8B2145E,0x0847E870, 115 | 0x86BD65E7,0x264899C9,0xEB7AB0BB,0x4B8F4C95, 116 | 0x5C1EE25F,0xFCEB1E71,0x31D93703,0x912CCB2D, 117 | 0x3E818C59,0x9E747077,0x53465905,0xF3B3A52B, 118 | 0xE4220BE1,0x44D7F7CF,0x89E5DEBD,0x29102293, 119 | 0xA7EAAF04,0x071F532A,0xCA2D7A58,0x6AD88676, 120 | 0x7D4928BC,0xDDBCD492,0x108EFDE0,0xB07B01CE, 121 | 0x2157CAE3,0x81A236CD,0x4C901FBF,0xEC65E391, 122 | 0xFBF44D5B,0x5B01B175,0x96339807,0x36C66429, 123 | 0xB83CE9BE,0x18C91590,0xD5FB3CE2,0x750EC0CC, 124 | 0x629F6E06,0xC26A9228,0x0F58BB5A,0xAFAD4774, 125 | 0x7C2F35B2,0xDCDAC99C,0x11E8E0EE,0xB11D1CC0, 126 | 0xA68CB20A,0x06794E24,0xCB4B6756,0x6BBE9B78, 127 | 0xE54416EF,0x45B1EAC1,0x8883C3B3,0x28763F9D, 128 | 0x3FE79157,0x9F126D79,0x5220440B,0xF2D5B825, 129 | 0x63F97308,0xC30C8F26,0x0E3EA654,0xAECB5A7A, 130 | 0xB95AF4B0,0x19AF089E,0xD49D21EC,0x7468DDC2, 131 | 0xFA925055,0x5A67AC7B,0x97558509,0x37A07927, 132 | 0x2031D7ED,0x80C42BC3,0x4DF602B1,0xED03FE9F, 133 | 0x42AEB9EB,0xE25B45C5,0x2F696CB7,0x8F9C9099, 134 | 0x980D3E53,0x38F8C27D,0xF5CAEB0F,0x553F1721, 135 | 0xDBC59AB6,0x7B306698,0xB6024FEA,0x16F7B3C4, 136 | 0x01661D0E,0xA193E120,0x6CA1C852,0xCC54347C, 137 | 0x5D78FF51,0xFD8D037F,0x30BF2A0D,0x904AD623, 138 | 0x87DB78E9,0x272E84C7,0xEA1CADB5,0x4AE9519B, 139 | 0xC413DC0C,0x64E62022,0xA9D40950,0x0921F57E, 140 | 0x1EB05BB4,0xBE45A79A,0x73778EE8,0xD38272C6, 141 | 0xF85E6A49,0x58AB9667,0x9599BF15,0x356C433B, 142 | 0x22FDEDF1,0x820811DF,0x4F3A38AD,0xEFCFC483, 143 | 0x61354914,0xC1C0B53A,0x0CF29C48,0xAC076066, 144 | 0xBB96CEAC,0x1B633282,0xD6511BF0,0x76A4E7DE, 145 | 0xE7882CF3,0x477DD0DD,0x8A4FF9AF,0x2ABA0581, 146 | 0x3D2BAB4B,0x9DDE5765,0x50EC7E17,0xF0198239, 147 | 0x7EE30FAE,0xDE16F380,0x1324DAF2,0xB3D126DC, 148 | 0xA4408816,0x04B57438,0xC9875D4A,0x6972A164, 149 | 0xC6DFE610,0x662A1A3E,0xAB18334C,0x0BEDCF62, 150 | 0x1C7C61A8,0xBC899D86,0x71BBB4F4,0xD14E48DA, 151 | 0x5FB4C54D,0xFF413963,0x32731011,0x9286EC3F, 152 | 0x851742F5,0x25E2BEDB,0xE8D097A9,0x48256B87, 153 | 0xD909A0AA,0x79FC5C84,0xB4CE75F6,0x143B89D8, 154 | 0x03AA2712,0xA35FDB3C,0x6E6DF24E,0xCE980E60, 155 | 0x406283F7,0xE0977FD9,0x2DA556AB,0x8D50AA85, 156 | 0x9AC1044F,0x3A34F861,0xF706D113,0x57F32D3D, 157 | 0x84715FFB,0x2484A3D5,0xE9B68AA7,0x49437689, 158 | 0x5ED2D843,0xFE27246D,0x33150D1F,0x93E0F131, 159 | 0x1D1A7CA6,0xBDEF8088,0x70DDA9FA,0xD02855D4, 160 | 0xC7B9FB1E,0x674C0730,0xAA7E2E42,0x0A8BD26C, 161 | 0x9BA71941,0x3B52E56F,0xF660CC1D,0x56953033, 162 | 0x41049EF9,0xE1F162D7,0x2CC34BA5,0x8C36B78B, 163 | 0x02CC3A1C,0xA239C632,0x6F0BEF40,0xCFFE136E, 164 | 0xD86FBDA4,0x789A418A,0xB5A868F8,0x155D94D6, 165 | 0xBAF0D3A2,0x1A052F8C,0xD73706FE,0x77C2FAD0, 166 | 0x6053541A,0xC0A6A834,0x0D948146,0xAD617D68, 167 | 0x239BF0FF,0x836E0CD1,0x4E5C25A3,0xEEA9D98D, 168 | 0xF9387747,0x59CD8B69,0x94FFA21B,0x340A5E35, 169 | 0xA5269518,0x05D36936,0xC8E14044,0x6814BC6A, 170 | 0x7F8512A0,0xDF70EE8E,0x1242C7FC,0xB2B73BD2, 171 | 0x3C4DB645,0x9CB84A6B,0x518A6319,0xF17F9F37, 172 | 0xE6EE31FD,0x461BCDD3,0x8B29E4A1,0x2BDC188F 173 | }; 174 | 175 | static const unsigned int amul2[256] = 176 | { 177 | 0x00000000,0x5BF87F93,0xB6BDFE6B,0xED4581F8, 178 | 0x2137B1D6,0x7ACFCE45,0x978A4FBD,0xCC72302E, 179 | 0x426E2FE1,0x19965072,0xF4D3D18A,0xAF2BAE19, 180 | 0x63599E37,0x38A1E1A4,0xD5E4605C,0x8E1C1FCF, 181 | 0x84DC5E8F,0xDF24211C,0x3261A0E4,0x6999DF77, 182 | 0xA5EBEF59,0xFE1390CA,0x13561132,0x48AE6EA1, 183 | 0xC6B2716E,0x9D4A0EFD,0x700F8F05,0x2BF7F096, 184 | 0xE785C0B8,0xBC7DBF2B,0x51383ED3,0x0AC04140, 185 | 0x45F5BC53,0x1E0DC3C0,0xF3484238,0xA8B03DAB, 186 | 0x64C20D85,0x3F3A7216,0xD27FF3EE,0x89878C7D, 187 | 0x079B93B2,0x5C63EC21,0xB1266DD9,0xEADE124A, 188 | 0x26AC2264,0x7D545DF7,0x9011DC0F,0xCBE9A39C, 189 | 0xC129E2DC,0x9AD19D4F,0x77941CB7,0x2C6C6324, 190 | 0xE01E530A,0xBBE62C99,0x56A3AD61,0x0D5BD2F2, 191 | 0x8347CD3D,0xD8BFB2AE,0x35FA3356,0x6E024CC5, 192 | 0xA2707CEB,0xF9880378,0x14CD8280,0x4F35FD13, 193 | 0x8AA735A6,0xD15F4A35,0x3C1ACBCD,0x67E2B45E, 194 | 0xAB908470,0xF068FBE3,0x1D2D7A1B,0x46D50588, 195 | 0xC8C91A47,0x933165D4,0x7E74E42C,0x258C9BBF, 196 | 0xE9FEAB91,0xB206D402,0x5F4355FA,0x04BB2A69, 197 | 0x0E7B6B29,0x558314BA,0xB8C69542,0xE33EEAD1, 198 | 0x2F4CDAFF,0x74B4A56C,0x99F12494,0xC2095B07, 199 | 0x4C1544C8,0x17ED3B5B,0xFAA8BAA3,0xA150C530, 200 | 0x6D22F51E,0x36DA8A8D,0xDB9F0B75,0x806774E6, 201 | 0xCF5289F5,0x94AAF666,0x79EF779E,0x2217080D, 202 | 0xEE653823,0xB59D47B0,0x58D8C648,0x0320B9DB, 203 | 0x8D3CA614,0xD6C4D987,0x3B81587F,0x607927EC, 204 | 0xAC0B17C2,0xF7F36851,0x1AB6E9A9,0x414E963A, 205 | 0x4B8ED77A,0x1076A8E9,0xFD332911,0xA6CB5682, 206 | 0x6AB966AC,0x3141193F,0xDC0498C7,0x87FCE754, 207 | 0x09E0F89B,0x52188708,0xBF5D06F0,0xE4A57963, 208 | 0x28D7494D,0x732F36DE,0x9E6AB726,0xC592C8B5, 209 | 0x59036A01,0x02FB1592,0xEFBE946A,0xB446EBF9, 210 | 0x7834DBD7,0x23CCA444,0xCE8925BC,0x95715A2F, 211 | 0x1B6D45E0,0x40953A73,0xADD0BB8B,0xF628C418, 212 | 0x3A5AF436,0x61A28BA5,0x8CE70A5D,0xD71F75CE, 213 | 0xDDDF348E,0x86274B1D,0x6B62CAE5,0x309AB576, 214 | 0xFCE88558,0xA710FACB,0x4A557B33,0x11AD04A0, 215 | 0x9FB11B6F,0xC44964FC,0x290CE504,0x72F49A97, 216 | 0xBE86AAB9,0xE57ED52A,0x083B54D2,0x53C32B41, 217 | 0x1CF6D652,0x470EA9C1,0xAA4B2839,0xF1B357AA, 218 | 0x3DC16784,0x66391817,0x8B7C99EF,0xD084E67C, 219 | 0x5E98F9B3,0x05608620,0xE82507D8,0xB3DD784B, 220 | 0x7FAF4865,0x245737F6,0xC912B60E,0x92EAC99D, 221 | 0x982A88DD,0xC3D2F74E,0x2E9776B6,0x756F0925, 222 | 0xB91D390B,0xE2E54698,0x0FA0C760,0x5458B8F3, 223 | 0xDA44A73C,0x81BCD8AF,0x6CF95957,0x370126C4, 224 | 0xFB7316EA,0xA08B6979,0x4DCEE881,0x16369712, 225 | 0xD3A45FA7,0x885C2034,0x6519A1CC,0x3EE1DE5F, 226 | 0xF293EE71,0xA96B91E2,0x442E101A,0x1FD66F89, 227 | 0x91CA7046,0xCA320FD5,0x27778E2D,0x7C8FF1BE, 228 | 0xB0FDC190,0xEB05BE03,0x06403FFB,0x5DB84068, 229 | 0x57780128,0x0C807EBB,0xE1C5FF43,0xBA3D80D0, 230 | 0x764FB0FE,0x2DB7CF6D,0xC0F24E95,0x9B0A3106, 231 | 0x15162EC9,0x4EEE515A,0xA3ABD0A2,0xF853AF31, 232 | 0x34219F1F,0x6FD9E08C,0x829C6174,0xD9641EE7, 233 | 0x9651E3F4,0xCDA99C67,0x20EC1D9F,0x7B14620C, 234 | 0xB7665222,0xEC9E2DB1,0x01DBAC49,0x5A23D3DA, 235 | 0xD43FCC15,0x8FC7B386,0x6282327E,0x397A4DED, 236 | 0xF5087DC3,0xAEF00250,0x43B583A8,0x184DFC3B, 237 | 0x128DBD7B,0x4975C2E8,0xA4304310,0xFFC83C83, 238 | 0x33BA0CAD,0x6842733E,0x8507F2C6,0xDEFF8D55, 239 | 0x50E3929A,0x0B1BED09,0xE65E6CF1,0xBDA61362, 240 | 0x71D4234C,0x2A2C5CDF,0xC769DD27,0x9C91A2B4 241 | }; 242 | 243 | static const unsigned long amul3[256] = 244 | { 245 | 0x00000000,0x4559568B,0x8AB2AC73,0xCFEBFAF8, 246 | 0x71013DE6,0x34586B6D,0xFBB39195,0xBEEAC71E, 247 | 0xE2027AA9,0xA75B2C22,0x68B0D6DA,0x2DE98051, 248 | 0x9303474F,0xD65A11C4,0x19B1EB3C,0x5CE8BDB7, 249 | 0xA104F437,0xE45DA2BC,0x2BB65844,0x6EEF0ECF, 250 | 0xD005C9D1,0x955C9F5A,0x5AB765A2,0x1FEE3329, 251 | 0x43068E9E,0x065FD815,0xC9B422ED,0x8CED7466, 252 | 0x3207B378,0x775EE5F3,0xB8B51F0B,0xFDEC4980, 253 | 0x27088D6E,0x6251DBE5,0xADBA211D,0xE8E37796, 254 | 0x5609B088,0x1350E603,0xDCBB1CFB,0x99E24A70, 255 | 0xC50AF7C7,0x8053A14C,0x4FB85BB4,0x0AE10D3F, 256 | 0xB40BCA21,0xF1529CAA,0x3EB96652,0x7BE030D9, 257 | 0x860C7959,0xC3552FD2,0x0CBED52A,0x49E783A1, 258 | 0xF70D44BF,0xB2541234,0x7DBFE8CC,0x38E6BE47, 259 | 0x640E03F0,0x2157557B,0xEEBCAF83,0xABE5F908, 260 | 0x150F3E16,0x5056689D,0x9FBD9265,0xDAE4C4EE, 261 | 0x4E107FDC,0x0B492957,0xC4A2D3AF,0x81FB8524, 262 | 0x3F11423A,0x7A4814B1,0xB5A3EE49,0xF0FAB8C2, 263 | 0xAC120575,0xE94B53FE,0x26A0A906,0x63F9FF8D, 264 | 0xDD133893,0x984A6E18,0x57A194E0,0x12F8C26B, 265 | 0xEF148BEB,0xAA4DDD60,0x65A62798,0x20FF7113, 266 | 0x9E15B60D,0xDB4CE086,0x14A71A7E,0x51FE4CF5, 267 | 0x0D16F142,0x484FA7C9,0x87A45D31,0xC2FD0BBA, 268 | 0x7C17CCA4,0x394E9A2F,0xF6A560D7,0xB3FC365C, 269 | 0x6918F2B2,0x2C41A439,0xE3AA5EC1,0xA6F3084A, 270 | 0x1819CF54,0x5D4099DF,0x92AB6327,0xD7F235AC, 271 | 0x8B1A881B,0xCE43DE90,0x01A82468,0x44F172E3, 272 | 0xFA1BB5FD,0xBF42E376,0x70A9198E,0x35F04F05, 273 | 0xC81C0685,0x8D45500E,0x42AEAAF6,0x07F7FC7D, 274 | 0xB91D3B63,0xFC446DE8,0x33AF9710,0x76F6C19B, 275 | 0x2A1E7C2C,0x6F472AA7,0xA0ACD05F,0xE5F586D4, 276 | 0x5B1F41CA,0x1E461741,0xD1ADEDB9,0x94F4BB32, 277 | 0x9C20FEDD,0xD979A856,0x169252AE,0x53CB0425, 278 | 0xED21C33B,0xA87895B0,0x67936F48,0x22CA39C3, 279 | 0x7E228474,0x3B7BD2FF,0xF4902807,0xB1C97E8C, 280 | 0x0F23B992,0x4A7AEF19,0x859115E1,0xC0C8436A, 281 | 0x3D240AEA,0x787D5C61,0xB796A699,0xF2CFF012, 282 | 0x4C25370C,0x097C6187,0xC6979B7F,0x83CECDF4, 283 | 0xDF267043,0x9A7F26C8,0x5594DC30,0x10CD8ABB, 284 | 0xAE274DA5,0xEB7E1B2E,0x2495E1D6,0x61CCB75D, 285 | 0xBB2873B3,0xFE712538,0x319ADFC0,0x74C3894B, 286 | 0xCA294E55,0x8F7018DE,0x409BE226,0x05C2B4AD, 287 | 0x592A091A,0x1C735F91,0xD398A569,0x96C1F3E2, 288 | 0x282B34FC,0x6D726277,0xA299988F,0xE7C0CE04, 289 | 0x1A2C8784,0x5F75D10F,0x909E2BF7,0xD5C77D7C, 290 | 0x6B2DBA62,0x2E74ECE9,0xE19F1611,0xA4C6409A, 291 | 0xF82EFD2D,0xBD77ABA6,0x729C515E,0x37C507D5, 292 | 0x892FC0CB,0xCC769640,0x039D6CB8,0x46C43A33, 293 | 0xD2308101,0x9769D78A,0x58822D72,0x1DDB7BF9, 294 | 0xA331BCE7,0xE668EA6C,0x29831094,0x6CDA461F, 295 | 0x3032FBA8,0x756BAD23,0xBA8057DB,0xFFD90150, 296 | 0x4133C64E,0x046A90C5,0xCB816A3D,0x8ED83CB6, 297 | 0x73347536,0x366D23BD,0xF986D945,0xBCDF8FCE, 298 | 0x023548D0,0x476C1E5B,0x8887E4A3,0xCDDEB228, 299 | 0x91360F9F,0xD46F5914,0x1B84A3EC,0x5EDDF567, 300 | 0xE0373279,0xA56E64F2,0x6A859E0A,0x2FDCC881, 301 | 0xF5380C6F,0xB0615AE4,0x7F8AA01C,0x3AD3F697, 302 | 0x84393189,0xC1606702,0x0E8B9DFA,0x4BD2CB71, 303 | 0x173A76C6,0x5263204D,0x9D88DAB5,0xD8D18C3E, 304 | 0x663B4B20,0x23621DAB,0xEC89E753,0xA9D0B1D8, 305 | 0x543CF858,0x1165AED3,0xDE8E542B,0x9BD702A0, 306 | 0x253DC5BE,0x60649335,0xAF8F69CD,0xEAD63F46, 307 | 0xB63E82F1,0xF367D47A,0x3C8C2E82,0x79D57809, 308 | 0xC73FBF17,0x8266E99C,0x4D8D1364,0x08D445EF 309 | }; -------------------------------------------------------------------------------- /akira-bruteforce.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // SHA-256 constants. 3 | __device__ __constant__ uint32_t k[64] = { 4 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 5 | 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 6 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 7 | 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 8 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 9 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 10 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 11 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 12 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 13 | 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 14 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 15 | 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 16 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 17 | 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 18 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 19 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2}; 20 | 21 | 22 | // AES S-box. 23 | __device__ __constant__ uint8_t sbox[256] = { 24 | 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 25 | 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 26 | 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 27 | 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 28 | 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 29 | 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 30 | 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 31 | 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 32 | 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 33 | 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 34 | 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 35 | 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 36 | 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 37 | 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 38 | 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 39 | 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 40 | 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 41 | 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 42 | 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 43 | 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 44 | 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 45 | 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 46 | 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 47 | 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 48 | 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 49 | 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 50 | 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 51 | 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 52 | 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 53 | 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 54 | 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 55 | 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16}; 56 | 57 | // Round constant word array. 58 | __device__ __constant__ uint32_t Rcon[7] = { 59 | 0x01000000, 0x02000000, 0x04000000, 60 | 0x08000000, 0x10000000, 0x20000000, 0x40000000}; 61 | 62 | 63 | 64 | //--------------------------------------------------------------------------- 65 | // Constant tables (ported from kcipher2-tables.h) 66 | //--------------------------------------------------------------------------- 67 | 68 | __device__ __constant__ unsigned char d_s_box[256] = { 69 | 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 70 | 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 71 | 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 72 | 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 73 | 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 74 | 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 75 | 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 76 | 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 77 | 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 78 | 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 79 | 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 80 | 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 81 | 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 82 | 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 83 | 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 84 | 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 85 | 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 86 | 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 87 | 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 88 | 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 89 | 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 90 | 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 91 | 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 92 | 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 93 | 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 94 | 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 95 | 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 96 | 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 97 | 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 98 | 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 99 | 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 100 | 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 101 | }; 102 | 103 | // Note: The following multiplication tables are copied from kcipher2-tables.h. 104 | __device__ __constant__ unsigned int d_amul0[256] = { 105 | 0x00000000,0xB6086D1A,0xAF10DA34,0x1918B72E, 106 | 0x9D207768,0x2B281A72,0x3230AD5C,0x8438C046, 107 | 0xF940EED0,0x4F4883CA,0x565034E4,0xE05859FE, 108 | 0x646099B8,0xD268F4A2,0xCB70438C,0x7D782E96, 109 | 0x31801F63,0x87887279,0x9E90C557,0x2898A84D, 110 | 0xACA0680B,0x1AA80511,0x03B0B23F,0xB5B8DF25, 111 | 0xC8C0F1B3,0x7EC89CA9,0x67D02B87,0xD1D8469D, 112 | 0x55E086DB,0xE3E8EBC1,0xFAF05CEF,0x4CF831F5, 113 | 0x62C33EC6,0xD4CB53DC,0xCDD3E4F2,0x7BDB89E8, 114 | 0xFFE349AE,0x49EB24B4,0x50F3939A,0xE6FBFE80, 115 | 0x9B83D016,0x2D8BBD0C,0x34930A22,0x829B6738, 116 | 0x06A3A77E,0xB0ABCA64,0xA9B37D4A,0x1FBB1050, 117 | 0x534321A5,0xE54B4CBF,0xFC53FB91,0x4A5B968B, 118 | 0xCE6356CD,0x786B3BD7,0x61738CF9,0xD77BE1E3, 119 | 0xAA03CF75,0x1C0BA26F,0x05131541,0xB31B785B, 120 | 0x3723B81D,0x812BD507,0x98336229,0x2E3B0F33, 121 | 0xC4457C4F,0x724D1155,0x6B55A67B,0xDD5DCB61, 122 | 0x59650B27,0xEF6D663D,0xF675D113,0x407DBC09, 123 | 0x3D05929F,0x8B0DFF85,0x921548AB,0x241D25B1, 124 | 0xA025E5F7,0x162D88ED,0x0F353FC3,0xB93D52D9, 125 | 0xF5C5632C,0x43CD0E36,0x5AD5B918,0xECDDD402, 126 | 0x68E51444,0xDEED795E,0xC7F5CE70,0x71FDA36A, 127 | 0x0C858DFC,0xBA8DE0E6,0xA39557C8,0x159D3AD2, 128 | 0x91A5FA94,0x27AD978E,0x3EB520A0,0x88BD4DBA, 129 | 0xA6864289,0x108E2F93,0x099698BD,0xBF9EF5A7, 130 | 0x3BA635E1,0x8DAE58FB,0x94B6EFD5,0x22BE82CF, 131 | 0x5FC6AC59,0xE9CEC143,0xF0D6766D,0x46DE1B77, 132 | 0xC2E6DB31,0x74EEB62B,0x6DF60105,0xDBFE6C1F, 133 | 0x97065DEA,0x210E30F0,0x381687DE,0x8E1EEAC4, 134 | 0x0A262A82,0xBC2E4798,0xA536F0B6,0x133E9DAC, 135 | 0x6E46B33A,0xD84EDE20,0xC156690E,0x775E0414, 136 | 0xF366C452,0x456EA948,0x5C761E66,0xEA7E737C, 137 | 0x4B8AF89E,0xFD829584,0xE49A22AA,0x52924FB0, 138 | 0xD6AA8FF6,0x60A2E2EC,0x79BA55C2,0xCFB238D8, 139 | 0xB2CA164E,0x04C27B54,0x1DDACC7A,0xABD2A160, 140 | 0x2FEA6126,0x99E20C3C,0x80FABB12,0x36F2D608, 141 | 0x7A0AE7FD,0xCC028AE7,0xD51A3DC9,0x631250D3, 142 | 0xE72A9095,0x5122FD8F,0x483A4AA1,0xFE3227BB, 143 | 0x834A092D,0x35426437,0x2C5AD319,0x9A52BE03, 144 | 0x1E6A7E45,0xA862135F,0xB17AA471,0x0772C96B, 145 | 0x2949C658,0x9F41AB42,0x86591C6C,0x30517176, 146 | 0xB469B130,0x0261DC2A,0x1B796B04,0xAD71061E, 147 | 0xD0092888,0x66014592,0x7F19F2BC,0xC9119FA6, 148 | 0x4D295FE0,0xFB2132FA,0xE23985D4,0x5431E8CE, 149 | 0x18C9D93B,0xAEC1B421,0xB7D9030F,0x01D16E15, 150 | 0x85E9AE53,0x33E1C349,0x2AF97467,0x9CF1197D, 151 | 0xE18937EB,0x57815AF1,0x4E99EDDF,0xF89180C5, 152 | 0x7CA94083,0xCAA12D99,0xD3B99AB7,0x65B1F7AD, 153 | 0x8FCF84D1,0x39C7E9CB,0x20DF5EE5,0x96D733FF, 154 | 0x12EFF3B9,0xA4E79EA3,0xBDFF298D,0x0BF74497, 155 | 0x768F6A01,0xC087071B,0xD99FB035,0x6F97DD2F, 156 | 0xEBAF1D69,0x5DA77073,0x44BFC75D,0xF2B7AA47, 157 | 0xBE4F9BB2,0x0847F6A8,0x115F4186,0xA7572C9C, 158 | 0x236FECDA,0x956781C0,0x8C7F36EE,0x3A775BF4, 159 | 0x470F7562,0xF1071878,0xE81FAF56,0x5E17C24C, 160 | 0xDA2F020A,0x6C276F10,0x753FD83E,0xC337B524, 161 | 0xED0CBA17,0x5B04D70D,0x421C6023,0xF4140D39, 162 | 0x702CCD7F,0xC624A065,0xDF3C174B,0x69347A51, 163 | 0x144C54C7,0xA24439DD,0xBB5C8EF3,0x0D54E3E9, 164 | 0x896C23AF,0x3F644EB5,0x267CF99B,0x90749481, 165 | 0xDC8CA574,0x6A84C86E,0x739C7F40,0xC594125A, 166 | 0x41ACD21C,0xF7A4BF06,0xEEBC0828,0x58B46532, 167 | 0x25CC4BA4,0x93C426BE,0x8ADC9190,0x3CD4FC8A, 168 | 0xB8EC3CCC,0x0EE451D6,0x17FCE6F8,0xA1F48BE2 169 | 170 | }; 171 | 172 | __device__ __constant__ unsigned int d_amul1[256] = { 173 | 0x00000000,0xA0F5FC2E,0x6DC7D55C,0xCD322972, 174 | 0xDAA387B8,0x7A567B96,0xB76452E4,0x1791AECA, 175 | 0x996B235D,0x399EDF73,0xF4ACF601,0x54590A2F, 176 | 0x43C8A4E5,0xE33D58CB,0x2E0F71B9,0x8EFA8D97, 177 | 0x1FD646BA,0xBF23BA94,0x721193E6,0xD2E46FC8, 178 | 0xC575C102,0x65803D2C,0xA8B2145E,0x0847E870, 179 | 0x86BD65E7,0x264899C9,0xEB7AB0BB,0x4B8F4C95, 180 | 0x5C1EE25F,0xFCEB1E71,0x31D93703,0x912CCB2D, 181 | 0x3E818C59,0x9E747077,0x53465905,0xF3B3A52B, 182 | 0xE4220BE1,0x44D7F7CF,0x89E5DEBD,0x29102293, 183 | 0xA7EAAF04,0x071F532A,0xCA2D7A58,0x6AD88676, 184 | 0x7D4928BC,0xDDBCD492,0x108EFDE0,0xB07B01CE, 185 | 0x2157CAE3,0x81A236CD,0x4C901FBF,0xEC65E391, 186 | 0xFBF44D5B,0x5B01B175,0x96339807,0x36C66429, 187 | 0xB83CE9BE,0x18C91590,0xD5FB3CE2,0x750EC0CC, 188 | 0x629F6E06,0xC26A9228,0x0F58BB5A,0xAFAD4774, 189 | 0x7C2F35B2,0xDCDAC99C,0x11E8E0EE,0xB11D1CC0, 190 | 0xA68CB20A,0x06794E24,0xCB4B6756,0x6BBE9B78, 191 | 0xE54416EF,0x45B1EAC1,0x8883C3B3,0x28763F9D, 192 | 0x3FE79157,0x9F126D79,0x5220440B,0xF2D5B825, 193 | 0x63F97308,0xC30C8F26,0x0E3EA654,0xAECB5A7A, 194 | 0xB95AF4B0,0x19AF089E,0xD49D21EC,0x7468DDC2, 195 | 0xFA925055,0x5A67AC7B,0x97558509,0x37A07927, 196 | 0x2031D7ED,0x80C42BC3,0x4DF602B1,0xED03FE9F, 197 | 0x42AEB9EB,0xE25B45C5,0x2F696CB7,0x8F9C9099, 198 | 0x980D3E53,0x38F8C27D,0xF5CAEB0F,0x553F1721, 199 | 0xDBC59AB6,0x7B306698,0xB6024FEA,0x16F7B3C4, 200 | 0x01661D0E,0xA193E120,0x6CA1C852,0xCC54347C, 201 | 0x5D78FF51,0xFD8D037F,0x30BF2A0D,0x904AD623, 202 | 0x87DB78E9,0x272E84C7,0xEA1CADB5,0x4AE9519B, 203 | 0xC413DC0C,0x64E62022,0xA9D40950,0x0921F57E, 204 | 0x1EB05BB4,0xBE45A79A,0x73778EE8,0xD38272C6, 205 | 0xF85E6A49,0x58AB9667,0x9599BF15,0x356C433B, 206 | 0x22FDEDF1,0x820811DF,0x4F3A38AD,0xEFCFC483, 207 | 0x61354914,0xC1C0B53A,0x0CF29C48,0xAC076066, 208 | 0xBB96CEAC,0x1B633282,0xD6511BF0,0x76A4E7DE, 209 | 0xE7882CF3,0x477DD0DD,0x8A4FF9AF,0x2ABA0581, 210 | 0x3D2BAB4B,0x9DDE5765,0x50EC7E17,0xF0198239, 211 | 0x7EE30FAE,0xDE16F380,0x1324DAF2,0xB3D126DC, 212 | 0xA4408816,0x04B57438,0xC9875D4A,0x6972A164, 213 | 0xC6DFE610,0x662A1A3E,0xAB18334C,0x0BEDCF62, 214 | 0x1C7C61A8,0xBC899D86,0x71BBB4F4,0xD14E48DA, 215 | 0x5FB4C54D,0xFF413963,0x32731011,0x9286EC3F, 216 | 0x851742F5,0x25E2BEDB,0xE8D097A9,0x48256B87, 217 | 0xD909A0AA,0x79FC5C84,0xB4CE75F6,0x143B89D8, 218 | 0x03AA2712,0xA35FDB3C,0x6E6DF24E,0xCE980E60, 219 | 0x406283F7,0xE0977FD9,0x2DA556AB,0x8D50AA85, 220 | 0x9AC1044F,0x3A34F861,0xF706D113,0x57F32D3D, 221 | 0x84715FFB,0x2484A3D5,0xE9B68AA7,0x49437689, 222 | 0x5ED2D843,0xFE27246D,0x33150D1F,0x93E0F131, 223 | 0x1D1A7CA6,0xBDEF8088,0x70DDA9FA,0xD02855D4, 224 | 0xC7B9FB1E,0x674C0730,0xAA7E2E42,0x0A8BD26C, 225 | 0x9BA71941,0x3B52E56F,0xF660CC1D,0x56953033, 226 | 0x41049EF9,0xE1F162D7,0x2CC34BA5,0x8C36B78B, 227 | 0x02CC3A1C,0xA239C632,0x6F0BEF40,0xCFFE136E, 228 | 0xD86FBDA4,0x789A418A,0xB5A868F8,0x155D94D6, 229 | 0xBAF0D3A2,0x1A052F8C,0xD73706FE,0x77C2FAD0, 230 | 0x6053541A,0xC0A6A834,0x0D948146,0xAD617D68, 231 | 0x239BF0FF,0x836E0CD1,0x4E5C25A3,0xEEA9D98D, 232 | 0xF9387747,0x59CD8B69,0x94FFA21B,0x340A5E35, 233 | 0xA5269518,0x05D36936,0xC8E14044,0x6814BC6A, 234 | 0x7F8512A0,0xDF70EE8E,0x1242C7FC,0xB2B73BD2, 235 | 0x3C4DB645,0x9CB84A6B,0x518A6319,0xF17F9F37, 236 | 0xE6EE31FD,0x461BCDD3,0x8B29E4A1,0x2BDC188F 237 | 238 | }; 239 | 240 | __device__ __constant__ unsigned int d_amul2[256] = { 241 | 0x00000000,0x5BF87F93,0xB6BDFE6B,0xED4581F8, 242 | 0x2137B1D6,0x7ACFCE45,0x978A4FBD,0xCC72302E, 243 | 0x426E2FE1,0x19965072,0xF4D3D18A,0xAF2BAE19, 244 | 0x63599E37,0x38A1E1A4,0xD5E4605C,0x8E1C1FCF, 245 | 0x84DC5E8F,0xDF24211C,0x3261A0E4,0x6999DF77, 246 | 0xA5EBEF59,0xFE1390CA,0x13561132,0x48AE6EA1, 247 | 0xC6B2716E,0x9D4A0EFD,0x700F8F05,0x2BF7F096, 248 | 0xE785C0B8,0xBC7DBF2B,0x51383ED3,0x0AC04140, 249 | 0x45F5BC53,0x1E0DC3C0,0xF3484238,0xA8B03DAB, 250 | 0x64C20D85,0x3F3A7216,0xD27FF3EE,0x89878C7D, 251 | 0x079B93B2,0x5C63EC21,0xB1266DD9,0xEADE124A, 252 | 0x26AC2264,0x7D545DF7,0x9011DC0F,0xCBE9A39C, 253 | 0xC129E2DC,0x9AD19D4F,0x77941CB7,0x2C6C6324, 254 | 0xE01E530A,0xBBE62C99,0x56A3AD61,0x0D5BD2F2, 255 | 0x8347CD3D,0xD8BFB2AE,0x35FA3356,0x6E024CC5, 256 | 0xA2707CEB,0xF9880378,0x14CD8280,0x4F35FD13, 257 | 0x8AA735A6,0xD15F4A35,0x3C1ACBCD,0x67E2B45E, 258 | 0xAB908470,0xF068FBE3,0x1D2D7A1B,0x46D50588, 259 | 0xC8C91A47,0x933165D4,0x7E74E42C,0x258C9BBF, 260 | 0xE9FEAB91,0xB206D402,0x5F4355FA,0x04BB2A69, 261 | 0x0E7B6B29,0x558314BA,0xB8C69542,0xE33EEAD1, 262 | 0x2F4CDAFF,0x74B4A56C,0x99F12494,0xC2095B07, 263 | 0x4C1544C8,0x17ED3B5B,0xFAA8BAA3,0xA150C530, 264 | 0x6D22F51E,0x36DA8A8D,0xDB9F0B75,0x806774E6, 265 | 0xCF5289F5,0x94AAF666,0x79EF779E,0x2217080D, 266 | 0xEE653823,0xB59D47B0,0x58D8C648,0x0320B9DB, 267 | 0x8D3CA614,0xD6C4D987,0x3B81587F,0x607927EC, 268 | 0xAC0B17C2,0xF7F36851,0x1AB6E9A9,0x414E963A, 269 | 0x4B8ED77A,0x1076A8E9,0xFD332911,0xA6CB5682, 270 | 0x6AB966AC,0x3141193F,0xDC0498C7,0x87FCE754, 271 | 0x09E0F89B,0x52188708,0xBF5D06F0,0xE4A57963, 272 | 0x28D7494D,0x732F36DE,0x9E6AB726,0xC592C8B5, 273 | 0x59036A01,0x02FB1592,0xEFBE946A,0xB446EBF9, 274 | 0x7834DBD7,0x23CCA444,0xCE8925BC,0x95715A2F, 275 | 0x1B6D45E0,0x40953A73,0xADD0BB8B,0xF628C418, 276 | 0x3A5AF436,0x61A28BA5,0x8CE70A5D,0xD71F75CE, 277 | 0xDDDF348E,0x86274B1D,0x6B62CAE5,0x309AB576, 278 | 0xFCE88558,0xA710FACB,0x4A557B33,0x11AD04A0, 279 | 0x9FB11B6F,0xC44964FC,0x290CE504,0x72F49A97, 280 | 0xBE86AAB9,0xE57ED52A,0x083B54D2,0x53C32B41, 281 | 0x1CF6D652,0x470EA9C1,0xAA4B2839,0xF1B357AA, 282 | 0x3DC16784,0x66391817,0x8B7C99EF,0xD084E67C, 283 | 0x5E98F9B3,0x05608620,0xE82507D8,0xB3DD784B, 284 | 0x7FAF4865,0x245737F6,0xC912B60E,0x92EAC99D, 285 | 0x982A88DD,0xC3D2F74E,0x2E9776B6,0x756F0925, 286 | 0xB91D390B,0xE2E54698,0x0FA0C760,0x5458B8F3, 287 | 0xDA44A73C,0x81BCD8AF,0x6CF95957,0x370126C4, 288 | 0xFB7316EA,0xA08B6979,0x4DCEE881,0x16369712, 289 | 0xD3A45FA7,0x885C2034,0x6519A1CC,0x3EE1DE5F, 290 | 0xF293EE71,0xA96B91E2,0x442E101A,0x1FD66F89, 291 | 0x91CA7046,0xCA320FD5,0x27778E2D,0x7C8FF1BE, 292 | 0xB0FDC190,0xEB05BE03,0x06403FFB,0x5DB84068, 293 | 0x57780128,0x0C807EBB,0xE1C5FF43,0xBA3D80D0, 294 | 0x764FB0FE,0x2DB7CF6D,0xC0F24E95,0x9B0A3106, 295 | 0x15162EC9,0x4EEE515A,0xA3ABD0A2,0xF853AF31, 296 | 0x34219F1F,0x6FD9E08C,0x829C6174,0xD9641EE7, 297 | 0x9651E3F4,0xCDA99C67,0x20EC1D9F,0x7B14620C, 298 | 0xB7665222,0xEC9E2DB1,0x01DBAC49,0x5A23D3DA, 299 | 0xD43FCC15,0x8FC7B386,0x6282327E,0x397A4DED, 300 | 0xF5087DC3,0xAEF00250,0x43B583A8,0x184DFC3B, 301 | 0x128DBD7B,0x4975C2E8,0xA4304310,0xFFC83C83, 302 | 0x33BA0CAD,0x6842733E,0x8507F2C6,0xDEFF8D55, 303 | 0x50E3929A,0x0B1BED09,0xE65E6CF1,0xBDA61362, 304 | 0x71D4234C,0x2A2C5CDF,0xC769DD27,0x9C91A2B4 305 | 306 | }; 307 | 308 | __device__ __constant__ unsigned int d_amul3[256] = { 309 | 0x00000000,0x4559568B,0x8AB2AC73,0xCFEBFAF8, 310 | 0x71013DE6,0x34586B6D,0xFBB39195,0xBEEAC71E, 311 | 0xE2027AA9,0xA75B2C22,0x68B0D6DA,0x2DE98051, 312 | 0x9303474F,0xD65A11C4,0x19B1EB3C,0x5CE8BDB7, 313 | 0xA104F437,0xE45DA2BC,0x2BB65844,0x6EEF0ECF, 314 | 0xD005C9D1,0x955C9F5A,0x5AB765A2,0x1FEE3329, 315 | 0x43068E9E,0x065FD815,0xC9B422ED,0x8CED7466, 316 | 0x3207B378,0x775EE5F3,0xB8B51F0B,0xFDEC4980, 317 | 0x27088D6E,0x6251DBE5,0xADBA211D,0xE8E37796, 318 | 0x5609B088,0x1350E603,0xDCBB1CFB,0x99E24A70, 319 | 0xC50AF7C7,0x8053A14C,0x4FB85BB4,0x0AE10D3F, 320 | 0xB40BCA21,0xF1529CAA,0x3EB96652,0x7BE030D9, 321 | 0x860C7959,0xC3552FD2,0x0CBED52A,0x49E783A1, 322 | 0xF70D44BF,0xB2541234,0x7DBFE8CC,0x38E6BE47, 323 | 0x640E03F0,0x2157557B,0xEEBCAF83,0xABE5F908, 324 | 0x150F3E16,0x5056689D,0x9FBD9265,0xDAE4C4EE, 325 | 0x4E107FDC,0x0B492957,0xC4A2D3AF,0x81FB8524, 326 | 0x3F11423A,0x7A4814B1,0xB5A3EE49,0xF0FAB8C2, 327 | 0xAC120575,0xE94B53FE,0x26A0A906,0x63F9FF8D, 328 | 0xDD133893,0x984A6E18,0x57A194E0,0x12F8C26B, 329 | 0xEF148BEB,0xAA4DDD60,0x65A62798,0x20FF7113, 330 | 0x9E15B60D,0xDB4CE086,0x14A71A7E,0x51FE4CF5, 331 | 0x0D16F142,0x484FA7C9,0x87A45D31,0xC2FD0BBA, 332 | 0x7C17CCA4,0x394E9A2F,0xF6A560D7,0xB3FC365C, 333 | 0x6918F2B2,0x2C41A439,0xE3AA5EC1,0xA6F3084A, 334 | 0x1819CF54,0x5D4099DF,0x92AB6327,0xD7F235AC, 335 | 0x8B1A881B,0xCE43DE90,0x01A82468,0x44F172E3, 336 | 0xFA1BB5FD,0xBF42E376,0x70A9198E,0x35F04F05, 337 | 0xC81C0685,0x8D45500E,0x42AEAAF6,0x07F7FC7D, 338 | 0xB91D3B63,0xFC446DE8,0x33AF9710,0x76F6C19B, 339 | 0x2A1E7C2C,0x6F472AA7,0xA0ACD05F,0xE5F586D4, 340 | 0x5B1F41CA,0x1E461741,0xD1ADEDB9,0x94F4BB32, 341 | 0x9C20FEDD,0xD979A856,0x169252AE,0x53CB0425, 342 | 0xED21C33B,0xA87895B0,0x67936F48,0x22CA39C3, 343 | 0x7E228474,0x3B7BD2FF,0xF4902807,0xB1C97E8C, 344 | 0x0F23B992,0x4A7AEF19,0x859115E1,0xC0C8436A, 345 | 0x3D240AEA,0x787D5C61,0xB796A699,0xF2CFF012, 346 | 0x4C25370C,0x097C6187,0xC6979B7F,0x83CECDF4, 347 | 0xDF267043,0x9A7F26C8,0x5594DC30,0x10CD8ABB, 348 | 0xAE274DA5,0xEB7E1B2E,0x2495E1D6,0x61CCB75D, 349 | 0xBB2873B3,0xFE712538,0x319ADFC0,0x74C3894B, 350 | 0xCA294E55,0x8F7018DE,0x409BE226,0x05C2B4AD, 351 | 0x592A091A,0x1C735F91,0xD398A569,0x96C1F3E2, 352 | 0x282B34FC,0x6D726277,0xA299988F,0xE7C0CE04, 353 | 0x1A2C8784,0x5F75D10F,0x909E2BF7,0xD5C77D7C, 354 | 0x6B2DBA62,0x2E74ECE9,0xE19F1611,0xA4C6409A, 355 | 0xF82EFD2D,0xBD77ABA6,0x729C515E,0x37C507D5, 356 | 0x892FC0CB,0xCC769640,0x039D6CB8,0x46C43A33, 357 | 0xD2308101,0x9769D78A,0x58822D72,0x1DDB7BF9, 358 | 0xA331BCE7,0xE668EA6C,0x29831094,0x6CDA461F, 359 | 0x3032FBA8,0x756BAD23,0xBA8057DB,0xFFD90150, 360 | 0x4133C64E,0x046A90C5,0xCB816A3D,0x8ED83CB6, 361 | 0x73347536,0x366D23BD,0xF986D945,0xBCDF8FCE, 362 | 0x023548D0,0x476C1E5B,0x8887E4A3,0xCDDEB228, 363 | 0x91360F9F,0xD46F5914,0x1B84A3EC,0x5EDDF567, 364 | 0xE0373279,0xA56E64F2,0x6A859E0A,0x2FDCC881, 365 | 0xF5380C6F,0xB0615AE4,0x7F8AA01C,0x3AD3F697, 366 | 0x84393189,0xC1606702,0x0E8B9DFA,0x4BD2CB71, 367 | 0x173A76C6,0x5263204D,0x9D88DAB5,0xD8D18C3E, 368 | 0x663B4B20,0x23621DAB,0xEC89E753,0xA9D0B1D8, 369 | 0x543CF858,0x1165AED3,0xDE8E542B,0x9BD702A0, 370 | 0x253DC5BE,0x60649335,0xAF8F69CD,0xEAD63F46, 371 | 0xB63E82F1,0xF367D47A,0x3C8C2E82,0x79D57809, 372 | 0xC73FBF17,0x8266E99C,0x4D8D1364,0x08D445EF 373 | }; 374 | 375 | 376 | __device__ __constant__ unsigned char gf2_table[256] = { 377 | 0xFF,0xFD,0xFB,0xF9,0xF7,0xF5,0xF3,0xF1,0xEF,0xED,0xEB,0xE9,0xE7,0xE5,0xE3,0xE1, 378 | 0xDF,0xDD,0xDB,0xD9,0xD7,0xD5,0xD3,0xD1,0xCF,0xCD,0xCB,0xC9,0xC7,0xC5,0xC3,0xC1, 379 | 0xBF,0xBD,0xBB,0xB9,0xB7,0xB5,0xB3,0xB1,0xAF,0xAD,0xAB,0xA9,0xA7,0xA5,0xA3,0xA1, 380 | 0x9F,0x9D,0x9B,0x99,0x97,0x95,0x93,0x91,0x8F,0x8D,0x8B,0x89,0x87,0x85,0x83,0x81, 381 | 0x7F,0x7D,0x7B,0x79,0x77,0x75,0x73,0x71,0x6F,0x6D,0x6B,0x69,0x67,0x65,0x63,0x61, 382 | 0x5F,0x5D,0x5B,0x59,0x57,0x55,0x53,0x51,0x4F,0x4D,0x4B,0x49,0x47,0x45,0x43,0x41, 383 | 0x3F,0x3D,0x3B,0x39,0x37,0x35,0x33,0x31,0x2F,0x2D,0x2B,0x29,0x27,0x25,0x23,0x21, 384 | 0x1F,0x1D,0x1B,0x19,0x17,0x15,0x13,0x11,0x0F,0x0D,0x0B,0x09,0x07,0x05,0x03,0x01, 385 | 0xE4,0xE6,0xE0,0xE2,0xEC,0xEE,0xE8,0xEA,0xF4,0xF6,0xF0,0xF2,0xFC,0xFE,0xF8,0xFA, 386 | 0xC4,0xC6,0xC0,0xC2,0xCC,0xCE,0xC8,0xCA,0xD4,0xD6,0xD0,0xD2,0xDC,0xDE,0xD8,0xDA, 387 | 0xA4,0xA6,0xA0,0xA2,0xAC,0xAE,0xA8,0xAA,0xB4,0xB6,0xB0,0xB2,0xBC,0xBE,0xB8,0xBA, 388 | 0x84,0x86,0x80,0x82,0x8C,0x8E,0x88,0x8A,0x94,0x96,0x90,0x92,0x9C,0x9E,0x98,0x9A, 389 | 0x64,0x66,0x60,0x62,0x6C,0x6E,0x68,0x6A,0x74,0x76,0x70,0x72,0x7C,0x7E,0x78,0x7A, 390 | 0x44,0x46,0x40,0x42,0x4C,0x4E,0x48,0x4A,0x54,0x56,0x50,0x52,0x5C,0x5E,0x58,0x5A, 391 | 0x24,0x26,0x20,0x22,0x2C,0x2E,0x28,0x2A,0x34,0x36,0x30,0x32,0x3C,0x3E,0x38,0x3A, 392 | 0x04,0x06,0x00,0x02,0x0C,0x0E,0x08,0x0A,0x14,0x16,0x10,0x12,0x1C,0x1E,0x18,0x1A 393 | }; 394 | 395 | __device__ __constant__ unsigned char gf3_table[256] = { 396 | 0xFF,0xFC,0xF9,0xFA,0xF3,0xF0,0xF5,0xF6,0xE7,0xE4,0xE1,0xE2,0xEB,0xE8,0xED,0xEE, 397 | 0xCF,0xCC,0xC9,0xCA,0xC3,0xC0,0xC5,0xC6,0xD7,0xD4,0xD1,0xD2,0xDB,0xD8,0xDD,0xDE, 398 | 0x9F,0x9C,0x99,0x9A,0x93,0x90,0x95,0x96,0x87,0x84,0x81,0x82,0x8B,0x88,0x8D,0x8E, 399 | 0xAF,0xAC,0xA9,0xAA,0xA3,0xA0,0xA5,0xA6,0xB7,0xB4,0xB1,0xB2,0xBB,0xB8,0xBD,0xBE, 400 | 0x3F,0x3C,0x39,0x3A,0x33,0x30,0x35,0x36,0x27,0x24,0x21,0x22,0x2B,0x28,0x2D,0x2E, 401 | 0x0F,0x0C,0x09,0x0A,0x03,0x00,0x05,0x06,0x17,0x14,0x11,0x12,0x1B,0x18,0x1D,0x1E, 402 | 0x5F,0x5C,0x59,0x5A,0x53,0x50,0x55,0x56,0x47,0x44,0x41,0x42,0x4B,0x48,0x4D,0x4E, 403 | 0x6F,0x6C,0x69,0x6A,0x63,0x60,0x65,0x66,0x77,0x74,0x71,0x72,0x7B,0x78,0x7D,0x7E, 404 | 0x64,0x67,0x62,0x61,0x68,0x6B,0x6E,0x6D,0x7C,0x7F,0x7A,0x79,0x70,0x73,0x76,0x75, 405 | 0x54,0x57,0x52,0x51,0x58,0x5B,0x5E,0x5D,0x4C,0x4F,0x4A,0x49,0x40,0x43,0x46,0x45, 406 | 0x04,0x07,0x02,0x01,0x08,0x0B,0x0E,0x0D,0x1C,0x1F,0x1A,0x19,0x10,0x13,0x16,0x15, 407 | 0x34,0x37,0x32,0x31,0x38,0x3B,0x3E,0x3D,0x2C,0x2F,0x2A,0x29,0x20,0x23,0x26,0x25, 408 | 0xA4,0xA7,0xA2,0xA1,0xA8,0xAB,0xAE,0xAD,0xBC,0xBF,0xBA,0xB9,0xB0,0xB3,0xB6,0xB5, 409 | 0x94,0x97,0x92,0x91,0x98,0x9B,0x9E,0x9D,0x8C,0x8F,0x8A,0x89,0x80,0x83,0x86,0x85, 410 | 0xC4,0xC7,0xC2,0xC1,0xC8,0xCB,0xCE,0xCD,0xDC,0xDF,0xDA,0xD9,0xD0,0xD3,0xD6,0xD5, 411 | 0xF4,0xF7,0xF2,0xF1,0xF8,0xFB,0xFE,0xFD,0xEC,0xEF,0xEA,0xE9,0xE0,0xE3,0xE6,0xE5 412 | }; 413 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . --------------------------------------------------------------------------------