static int crypt_all(int *pcount, struct db_salt *salt) { const int count = *pcount; int index; size_t *lws = local_work_size ? &local_work_size : NULL; global_work_size = local_work_size ? (count + local_work_size - 1) / local_work_size * local_work_size : count; if (saved_salt->v.type) { // This salt passed valid() but failed get_salt(). // Should never happen. memset(crypt_key, 0, count * BINARY_SIZE); return count; } /// Copy data to gpu HANDLE_CLERROR(clEnqueueWriteBuffer(queue[gpu_id], mem_in, CL_FALSE, 0, insize, inbuffer, 0, NULL, multi_profilingEvent[0]), "Copy data to gpu"); /// Run kernel HANDLE_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], crypt_kernel, 1, NULL, &global_work_size, lws, 0, NULL, multi_profilingEvent[1]), "Run kernel"); /// Read the result back HANDLE_CLERROR(clEnqueueReadBuffer(queue[gpu_id], mem_out, CL_TRUE, 0, outsize, outbuffer, 0, NULL, multi_profilingEvent[2]), "Copy result back"); #ifdef _OPENMP #pragma omp parallel for #endif for (index = 0; index < count; index++) { if (!memcmp(&((unsigned char*)outbuffer[index].v)[2 * KEY_LENGTH(saved_salt->v.mode)], saved_salt->passverify, 2)) hmac_sha1(&((unsigned char*)outbuffer[index].v)[KEY_LENGTH(saved_salt->v.mode)], KEY_LENGTH(saved_salt->v.mode), (const unsigned char*)saved_salt->datablob, saved_salt->comp_len, crypt_key[index], BINARY_SIZE); else memset(crypt_key[index], 0, BINARY_SIZE); } return count; }
static void crypt_all(int count) { int index; #ifdef _OPENMP #pragma omp parallel for default(none) private(index) shared(count, passverify, has_been_cracked, saved_key, saved_salt, mode) #endif for (index = 0; index < count; index++) { unsigned char pwd_ver[2] = { 0 }; unsigned char kbuf[2 * MAX_KEY_LENGTH + PWD_VER_LENGTH]; /* Derive the encryption and authetication keys and the password verifier */ derive_key((unsigned char *)saved_key[index], strlen(saved_key[index]), saved_salt, SALT_LENGTH(mode), KEYING_ITERATIONS, kbuf, 2 * KEY_LENGTH(mode) + PWD_VER_LENGTH); memcpy(pwd_ver, kbuf + 2 * KEY_LENGTH(mode), PWD_VER_LENGTH); has_been_cracked[index] = !memcmp(pwd_ver, passverify, 2); } }
static void set_salt(void *salt) { cur_salt = (zip_cpu_salt*)salt; memcpy((char*)currentsalt.salt, cur_salt->salt, cur_salt->length); currentsalt.length = cur_salt->length; currentsalt.iterations = KEYING_ITERATIONS; currentsalt.outlen = 2 * KEY_LENGTH(cur_salt->mode) + PWD_VER_LENGTH; HANDLE_CLERROR(clEnqueueWriteBuffer(queue[ocl_gpu_id], mem_setting, CL_FALSE, 0, settingsize, ¤tsalt, 0, NULL, NULL), "Copy setting to gpu"); }
static void set_salt(void *salt) { saved_salt = *((my_salt**)salt); memcpy((char*)currentsalt.salt, saved_salt->salt, SALT_LENGTH(saved_salt->v.mode)); currentsalt.length = SALT_LENGTH(saved_salt->v.mode); currentsalt.iterations = KEYING_ITERATIONS; currentsalt.outlen = 2 * KEY_LENGTH(saved_salt->v.mode) + PWD_VER_LENGTH; HANDLE_CLERROR(clEnqueueWriteBuffer(queue[gpu_id], mem_setting, CL_FALSE, 0, settingsize, ¤tsalt, 0, NULL, NULL), "Copy setting to gpu"); }
static int crypt_all(int *pcount, struct db_salt *salt) { int count = *pcount; int index; global_work_size = (count + local_work_size - 1) / local_work_size * local_work_size; if (any_cracked) { memset(cracked, 0, cracked_size); any_cracked = 0; } /// Copy data to gpu HANDLE_CLERROR(clEnqueueWriteBuffer(queue[ocl_gpu_id], mem_in, CL_FALSE, 0, insize, inbuffer, 0, NULL, NULL), "Copy data to gpu"); /// Run kernel HANDLE_CLERROR(clEnqueueNDRangeKernel(queue[ocl_gpu_id], crypt_kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, profilingEvent), "Run kernel"); HANDLE_CLERROR(clFinish(queue[ocl_gpu_id]), "clFinish"); /// Read the result back HANDLE_CLERROR(clEnqueueReadBuffer(queue[ocl_gpu_id], mem_out, CL_FALSE, 0, outsize, outbuffer, 0, NULL, NULL), "Copy result back"); /// Await completion of all the above HANDLE_CLERROR(clFinish(queue[ocl_gpu_id]), "clFinish"); #ifdef _OPENMP #pragma omp parallel for #endif for (index = 0; index < count; index++) if (!memcmp(&((unsigned char*)outbuffer[index].v)[2 * KEY_LENGTH(cur_salt->mode)], cur_salt->passverify, 2)) any_cracked = cracked[index] = 1; return count; }
int fcrypt_init( int mode, /* the mode to be used (input) */ const unsigned char pwd[], /* the user specified password (input) */ unsigned int pwd_len, /* the length of the password (input) */ const unsigned char salt[], /* the salt (input) */ #ifdef PASSWORD_VERIFIER unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */ #endif fcrypt_ctx cx[1]) /* the file encryption context (output) */ { unsigned char kbuf[2 * MAX_KEY_LENGTH + PWD_VER_LENGTH]; if(pwd_len > MAX_PWD_LENGTH) return PASSWORD_TOO_LONG; if(mode < 1 || mode > 3) return BAD_MODE; cx->mode = mode; cx->pwd_len = pwd_len; /* initialise the encryption nonce and buffer pos */ cx->encr_pos = BLOCK_SIZE; /* if we need a random component in the encryption */ /* nonce, this is where it would have to be set */ memset(cx->nonce, 0, BLOCK_SIZE * sizeof(unsigned char)); /* initialise for authentication */ hmac_sha_begin(cx->auth_ctx); /* derive the encryption and authetication keys and the password verifier */ derive_key(pwd, pwd_len, salt, SALT_LENGTH(mode), KEYING_ITERATIONS, kbuf, 2 * KEY_LENGTH(mode) + PWD_VER_LENGTH); /* set the encryption key */ aes_encrypt_key(kbuf, KEY_LENGTH(mode), cx->encr_ctx); /* set the authentication key */ hmac_sha_key(kbuf + KEY_LENGTH(mode), KEY_LENGTH(mode), cx->auth_ctx); #ifdef PASSWORD_VERIFIER memcpy(pwd_ver, kbuf + 2 * KEY_LENGTH(mode), PWD_VER_LENGTH); #endif /* clear the buffer holding the derived key values */ memset(kbuf, 0, 2 * KEY_LENGTH(mode) + PWD_VER_LENGTH); return GOOD_RETURN; }
static void crypt_all(int count) { int index; /// Copy data to gpu HANDLE_CLERROR(clEnqueueWriteBuffer(queue[ocl_gpu_id], mem_in, CL_FALSE, 0, insize, inbuffer, 0, NULL, NULL), "Copy data to gpu"); HANDLE_CLERROR(clEnqueueWriteBuffer(queue[ocl_gpu_id], mem_setting, CL_FALSE, 0, settingsize, ¤tsalt, 0, NULL, NULL), "Copy setting to gpu"); /// Run kernel HANDLE_CLERROR(clEnqueueNDRangeKernel(queue[ocl_gpu_id], crypt_kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, profilingEvent), "Run kernel"); HANDLE_CLERROR(clFinish(queue[ocl_gpu_id]), "clFinish"); /// Read the result back HANDLE_CLERROR(clEnqueueReadBuffer(queue[ocl_gpu_id], mem_out, CL_FALSE, 0, outsize, outbuffer, 0, NULL, NULL), "Copy result back"); /// Await completion of all the above HANDLE_CLERROR(clFinish(queue[ocl_gpu_id]), "clFinish"); for (index = 0; index < count; index++) { unsigned char pwd_ver[2] = { 0 }; unsigned char *p; p = (unsigned char*)outbuffer[index].v; memcpy(pwd_ver, p + 2 * KEY_LENGTH(cur_salt->mode), 2); if(!memcmp(pwd_ver, cur_salt->passverify, 2)) cracked[index] = 1; else cracked[index] = 0; } }