int main (int argc, char *argv[]){ //int c = sizeof("one"); int a = isUpper('a'); int b = isLower('a'); int c = isUpper('Z'); int d = isLower('Z'); char r = shiftChar('.', 1); printf("%d %d %d %d\n", a,b,c,d); printf("%c\n", r); char *message = strdup("M! K fobi pkcd, iod kd dswoc pbecdbkdsxq vkxqekqo."); printf("message : %s\n", message); encryptInPlace(message,-10); printf("ciphertext : %s\n\n", message); char *message1 = strdup("M! K fobi pkcd, iod kd dswoc pbecdbkdsxq vkxqekqo."); printf("message : %s\n", message1); char *ciphertext = encrpytNewMemory(message1,-10); printf("ciphertext : %s\n", ciphertext); free(ciphertext); printf("ciphertext : %s\n", ciphertext); test(); return 0; }
void* encryptQueue(void* parameters) { pdebug("encryptQueue()\n"); bool first_chunk = true; bool encrypted = false; //a flag to protect a chunk from getting encrpted multiple times cryptParams* params = parameters; chunk* encrypt_chunk = NULL; uint64_t* chain = NULL; chain = calloc(params->tf_key->stateSize/64, sizeof(uint64_t)); if (chain == NULL) //check that calloc succeeded { *(params->error) = MEMORY_ALLOCATION_FAIL; return NULL; } uint64_t crypto_progress = 0; while (*(params->running) && *(params->error) == 0) { if (encrypt_chunk == NULL) { pthread_mutex_lock(params->in_mutex); if (front(params->in) != NULL) { encrypt_chunk = front(params->in); if (encrypt_chunk != NULL) { encrypted = false; //set the encrypted flag deque(params->in); } } pthread_mutex_unlock(params->in_mutex); } if (encrypt_chunk != NULL && encrypt_chunk->action == DONE) { pdebug("$$$ encryptQueue() terminating loop $$$\n"); destroyChunk(encrypt_chunk); break; } if (first_chunk && encrypt_chunk != NULL) //assume the first chunk is the header { pdebug("$$$ Encrypting header of size %lu $$$\n", encrypt_chunk->data_size); if (!encryptHeader(params->tf_key, encrypt_chunk->data)) { //if we failed to encrypt the header pdebug("$$$ Failed to encrypt header $$$\n"); destroyChunk(encrypt_chunk); *(params->error) = CIPHER_OPERATION_FAIL; //set the error flag break; //break out } //save the chain of cipher text in the next chunk getChainInBuffer(encrypt_chunk->data, chain, 2, params->tf_key->stateSize); crypto_progress += encrypt_chunk->data_size; first_chunk = false; } else if (!first_chunk && encrypt_chunk != NULL && !encrypted) { uint64_t num_blocks = getNumBlocks(encrypt_chunk->data_size, (uint32_t)params->tf_key->stateSize); encryptInPlace(params->tf_key, chain, encrypt_chunk->data, num_blocks); getChainInBuffer(encrypt_chunk->data, chain, num_blocks, params->tf_key->stateSize); crypto_progress += encrypt_chunk->data_size; encrypted = true; } if (encrypt_chunk != NULL && !queueIsFull(params->out)) //attempt to queue the last encrypted chunk { encrypt_chunk->action = GEN_MAC; //change the next queued action //on success clear the chunk ptr so the next operation can happen pthread_mutex_lock(params->out_mutex); if(enque(encrypt_chunk, params->out)) { pdebug("$$$ Queing encrypted chunk of size %lu $$$\n", encrypt_chunk->data_size); encrypt_chunk = NULL; } pthread_mutex_unlock(params->out_mutex); } //end queue operation if (crypto_progress > 0) //update the progress bar { if (pthread_mutex_trylock(params->progress->progress_mutex) == 0) { params->progress->progress += crypto_progress; crypto_progress = 0; pthread_mutex_unlock(params->progress->progress_mutex); } } } //end while loop //queue Done flag while (queueIsFull(params->out)) { nanosleep(&wait_interval, NULL); } pthread_mutex_lock(params->out_mutex); if (!queueDone(params->out)) { pdebug("Error queueing done\n"); *(params->error) = QUEUE_OPERATION_FAIL; if (chain != NULL) { free(chain); } return NULL; } pthread_mutex_unlock(params->out_mutex); pdebug("$$$ Done queued $$$ \n"); if (chain != NULL) { free(chain); } return NULL; } //end encryptQueue()