- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
#include <openssl/rsa.h>
#include <openssl/rand.h>
#include <stdio.h>
#include <string.h>
#include <omp.h>
#define KEY_LENGTH 2048
#define EN_SIZE 200 //number of chars in a string
#define STR_NUM 1000 //number of strings to be encrypted
#define PUB_EXP 3
int main() {
int i, j, k;
int encrypt_len;
int decrypt_len;
char *en_m[STR_NUM]; //array of pointers for the input strings
char *tm_m[STR_NUM]; //array of pointers for the encrypted strings
char *rm_m[STR_NUM]; //array of pointers for the encrypted strings
// rm_m read back tm_m through a .txt file
char *de_m[STR_NUM]; //array of pointers for the decrypted strings
// Generate key pair
RSA *keypair = RSA_generate_key(KEY_LENGTH, PUB_EXP, NULL, NULL);
FILE *f;
f = fopen("message.txt", "r");
if(f==NULL){
perror ("Error in locating the file to be encrypted");
return(-1);
}
for (k=0; k<STR_NUM; k++){
en_m
tm_m
de_m
fread(en_m
en_m
}
fclose(f);
printf("The length of string to be encrypted in each encryption = %d bytes\n", EN_SIZE);
printf("Total number of the string message to be encrypted = %d\n", STR_NUM);
omp_set_num_threads(4); //set up 4 threads
kmp_set_defaults("KMP_AFFINITY=scatter");
// Encryption
#pragma omp parallel for shared(en_m, tm_m, keypair) private(i, encrypt_len) schedule(static)
for(i=0; i<STR_NUM; i++)
encrypt_len = RSA_public_encrypt(EN_SIZE, (unsigned char*)en_m, (unsigned char*)tm_m, keypair, RSA_PKCS1_OAEP_PADDING);
printf("Encryption has been finished\n");
f = fopen("en_message.txt", "w");
for (k=0; k<STR_NUM; k++){
fwrite(tm_m
}
fclose(f);
/************************************************************************************************/
f = fopen("en_message.txt", "r");
for (k=0; k<STR_NUM; k++){
rm_m
fread(rm_m
}
fclose(f);
// Decryption
#pragma omp parallel for shared(rm_m, de_m, keypair) private(j, decrypt_len) schedule(static)
for (j=0; j<STR_NUM; j++)
decrypt_len = RSA_private_decrypt(RSA_size(keypair), (unsigned char*)rm_m
printf("Decryption has been finished.\n");
int temp = 0;
for (k=0; k<STR_NUM; k++){
if (strcmp(en_m
temp += 1;
}
printf("Total number of dismatch = %d\n", temp);
RSA_free(keypair);
for (k=0; k<STR_NUM; k++){
free(en_m
free(de_m
free(tm_m
free(rm_m
}
return 0;
}
- Tags:
- Parallel Computing
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page