I am generating 256 bit key for AES. I am using the following implementation
Expand|Select|Wrap|Line Numbers
- void fill_random_key(char *key)
- {
- /* Length of the key */
- unsigned short int length = KEYLENGTH;
- /* Seed number for rand() */
- srand((unsigned int) time(0) + getpid());
- int i=0;
- while(length--) {
- key[i]=rand() % 127;
- srand(rand());
- i++;
- }
- }
- void get_keys_for_files(char **files)
- {
- extern int num_of_files;
- char (*curr_file)[20]=files;
- char key[32];
- int i=0;
- FILE *fp;
- char key_file[1024];
- for(i=0;i<num_of_files;i++)
- {
- strcpy(key_file,cwd);
- strcat(key_file,"\\keys\\");
- strcat(key_file,curr_file);
- fill_random_key(key);
- fp=fopen(key_file,"w");
- fputs(key,fp);
- curr_file++;
- fclose(fp);
- sleep(1000);
- }
- }
Thanks for your help