1 /*
2  * This software is Copyright (c) 2015 Sayantan Datta <std2048 at gmail dot com>
3  * and it is hereby released to the general public under the following terms:
4  * Redistribution and use in source and binary forms, with or without modification, are permitted.
5  * Based on Solar LMigner implementation of LM_bs_b.c in jtr-v1.7.9
6  */
7 
8 
9 #ifndef _JOHN_LM_BS_H
10 #define _JOHN_LM_BS_H
11 
12 #include "arch.h"
13 #include "opencl_common.h"
14 #include "opencl_lm_hst_dev_shared.h"
15 #include "loader.h"
16 
17 #define LM_OPENCL_ALGORITHM_NAME		"DES BS OpenCL"
18 
19 #define LM_DEPTH			32
20 #define LM_LOG_DEPTH			5
21 
22 #define WORD                      	int
23 
24 #define lm_vector			WORD
25 
26 #define MULTIPLIER                      (64 * 256)
27 #define PLAINTEXT_LENGTH		7
28 
29 #define MIN_KEYS_PER_CRYPT		(LM_DEPTH * MULTIPLIER)
30 #define MAX_KEYS_PER_CRYPT		(LM_DEPTH * MULTIPLIER)
31 
32 #define FORMAT_LABEL			"LM-opencl"
33 
34 #define	MAX_DEVICES_PER_PLATFORM	10
35 
36 #define get_key_body() {						\
37 	static char out[PLAINTEXT_LENGTH + 1];				\
38 	unsigned int section, block;					\
39 	unsigned char *src;						\
40 	char *dst;							\
41 									\
42 	if (hash_ids == NULL || hash_ids[0] == 0 ||			\
43 	    index > hash_ids[0] || hash_ids[0] > num_loaded_hashes) {	\
44 		section = 0;						\
45 		block = 0;						\
46 	}								\
47 	else {								\
48 		section = hash_ids[3 * index + 1] / 32;			\
49 		block  = hash_ids[3 * index + 1] & 31;			\
50 	}								\
51 									\
52 	if (section > global_work_size ) {				\
53 		/*fprintf(stderr, "Get key error! %u "Zu"\n", section, global_work_size);*/ \
54 		section = 0;						\
55 		block = 0;						\
56 	}								\
57 									\
58 	src = opencl_lm_all[section].pxkeys[block];			\
59 	dst = out;							\
60 	while (dst < &out[PLAINTEXT_LENGTH] && (*dst = *src)) {		\
61 		src += sizeof(lm_vector) * 8;				\
62 		dst++;							\
63 	}								\
64 	*dst = 0;							\
65 									\
66 	return out;							\
67 }
68 
69 typedef unsigned WORD vtype;
70 
71 extern unsigned int CC_CACHE_ALIGN opencl_lm_index768[0x300];
72 
73 extern unsigned char opencl_lm_u[0x100];
74 
75 typedef struct {
76 	unsigned char *pxkeys[LM_DEPTH]; /* Pointers into xkeys.c */
77 } opencl_lm_combined;
78 
79 struct fmt_main;
80 
81 extern struct fmt_main fmt_opencl_lm;
82 
83 extern opencl_lm_combined *opencl_lm_all;
84 extern opencl_lm_transfer *opencl_lm_keys;
85 extern unsigned int *opencl_lm_int_key_loc;
86 
87 extern void opencl_lm_b_register_functions(struct fmt_main *);
88 
89 extern void (*opencl_lm_init_global_variables)(void);
90 
91 extern int opencl_lm_get_hash_0(int index);
92 extern int opencl_lm_get_hash_1(int index);
93 extern int opencl_lm_get_hash_2(int index);
94 extern int opencl_lm_get_hash_3(int index);
95 extern int opencl_lm_get_hash_4(int index);
96 extern int opencl_lm_get_hash_5(int index);
97 extern int opencl_lm_get_hash_6(int index);
98 extern void opencl_lm_init(int block);
99 extern char *opencl_lm_get_source(WORD *raw);
100 extern WORD *opencl_lm_get_binary(char *ciphertext);
101 extern void opencl_lm_set_key(char *key, int index);
102 extern void opencl_lm_set_key_mm(char *key, int index);
103 extern void opencl_lm_init_index(void);
104 
105 #endif
106