Changeset 514
- Timestamp:
- 10/15/07 12:11:28
- Files:
-
- openpgpsdk/trunk/tests/test_crypt_mpi.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_packet_types.c (modified) (5 diffs)
- openpgpsdk/trunk/tests/test_rsa_decrypt.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_rsa_encrypt.c (modified) (12 diffs)
- openpgpsdk/trunk/tests/test_rsa_signature.c (modified) (4 diffs)
- openpgpsdk/trunk/tests/test_rsa_verify.c (modified) (3 diffs)
- openpgpsdk/trunk/tests/tests.c (modified) (10 diffs)
- openpgpsdk/trunk/tests/tests.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/tests/test_crypt_mpi.c
r485 r514 33 33 snprintf(keydetails,MAXBUF,"%s/%s",dir,"keydetails.alpha"); 34 34 35 if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL , 0600))<0)35 if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600))<0) 36 36 { 37 37 fprintf(stderr,"Can't create key details\n"); openpgpsdk/trunk/tests/test_packet_types.c
r511 r514 238 238 char* plaintext="Text to be hashed in test_ops_mdc"; 239 239 int rtn=0; 240 size_t sz_preamble; 240 241 241 242 ops_crypt_t crypt; … … 245 246 ops_encrypt_init(&crypt); 246 247 247 s ize_t sz_preamble=crypt.blocksize+2;248 sz_preamble=crypt.blocksize+2; 248 249 preamble=ops_mallocz(sz_preamble); 249 250 ops_random(preamble, crypt.blocksize); … … 302 303 char* ldt_text="Test Data string for test_se_ip"; 303 304 304 ops_setup_memory_write(&cinfo_ldt,&mem_ldt,strlen(ldt_text));305 ops_write_literal_data((unsigned char *)ldt_text, strlen(ldt_text),306 OPS_LDT_TEXT, cinfo_ldt);307 308 /*309 * write out the encrypted packet310 */311 305 int rtn=0; 312 306 ops_create_info_t *cinfo; 313 307 ops_parse_info_t *pinfo; 314 308 ops_memory_t *mem; 309 310 ops_setup_memory_write(&cinfo_ldt,&mem_ldt,strlen(ldt_text)); 311 ops_write_literal_data((unsigned char *)ldt_text, strlen(ldt_text), 312 OPS_LDT_TEXT, cinfo_ldt); 313 314 /* 315 * write out the encrypted packet 316 */ 315 317 ops_setup_memory_write(&cinfo,&mem,MAXBUF); 316 318 … … 364 366 ops_memory_t *mem; 365 367 int rtn=0; 368 const ops_key_data_t *pub_key=NULL; 366 369 367 370 // setup for write … … 369 372 370 373 // write 371 const ops_key_data_t *pub_key=ops_keyring_find_key_by_userid(&pub_keyring, alpha_user_id);374 pub_key=ops_keyring_find_key_by_userid(&pub_keyring, alpha_user_id); 372 375 assert(pub_key); 373 376 openpgpsdk/trunk/tests/test_rsa_decrypt.c
r511 r514 214 214 protocol==NULL ? "" : "_", 215 215 filename,suffix); 216 #ifdef WIN32 217 fd=open(encfile,O_RDONLY | O_BINARY); 218 #else 216 219 fd=open(encfile,O_RDONLY); 220 #endif 217 221 if(fd < 0) 218 222 { openpgpsdk/trunk/tests/test_rsa_encrypt.c
r511 r514 133 133 134 134 // open encrypted file 135 #ifdef WIN32 136 fd=open(encfile,O_RDONLY | O_BINARY); 137 #else 135 138 fd=open(encfile,O_RDONLY); 139 #endif 136 140 if(fd < 0) 137 141 { … … 177 181 int fd_out=0; 178 182 int rtn=0; 183 ops_create_info_t *cinfo; 184 ops_pk_session_key_t* encrypted_pk_session_key; 185 ops_crypt_t encrypt; 186 unsigned char *iv=NULL; 179 187 180 188 /* … … 186 194 // open file to encrypt 187 195 snprintf(myfile,MAXBUF,"%s/%s",dir,filename); 196 #ifdef WIN32 197 fd_in=open(myfile,O_RDONLY | O_BINARY); 198 #else 188 199 fd_in=open(myfile,O_RDONLY); 200 #endif 189 201 if(fd_in < 0) 190 202 { … … 194 206 195 207 snprintf(encrypted_file,MAXBUF,"%s/%s.%s",dir,filename,suffix); 208 #ifdef WIN32 209 fd_out=open(encrypted_file,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600); 210 #else 196 211 fd_out=open(encrypted_file,O_WRONLY | O_CREAT | O_EXCL, 0600); 212 #endif 197 213 if(fd_out < 0) 198 214 { … … 226 242 // Set encryption writer and handling options 227 243 228 ops_create_info_t *cinfo;229 244 cinfo=ops_create_info_new(); 230 245 ops_writer_set_fd(cinfo,fd_out); … … 232 247 // Create and write encrypted PK session key 233 248 234 ops_pk_session_key_t* encrypted_pk_session_key;235 249 encrypted_pk_session_key=ops_create_pk_session_key(pub_key); 236 250 ops_write_pk_session_key(cinfo,encrypted_pk_session_key); 237 251 238 ops_crypt_t encrypt;239 252 ops_crypt_any(&encrypt, encrypted_pk_session_key->symmetric_algorithm); 240 unsigned char *iv=NULL;241 253 iv=ops_mallocz(encrypt.blocksize); 242 254 encrypt.set_iv(&encrypt, iv); … … 295 307 int rtn=0; 296 308 309 ops_create_info_t *cinfo; 310 char* testtext=NULL; 311 char pp[MAXBUF]; 312 297 313 /* 298 314 * Read from test file and write plaintext to memory … … 302 318 // open file to encrypt 303 319 snprintf(myfile,MAXBUF,"%s/%s",dir,filename); 320 #ifdef WIN32 321 fd_in=open(myfile,O_RDONLY | O_BINARY); 322 #else 304 323 fd_in=open(myfile,O_RDONLY); 324 #endif 305 325 if(fd_in < 0) 306 326 { … … 310 330 311 331 snprintf(encrypted_file,MAXBUF,"%s/%s%s.%s",dir,gpgtest,filename,suffix); 332 #ifdef WIN32 333 fd_out=open(encrypted_file,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600); 334 #else 312 335 fd_out=open(encrypted_file,O_WRONLY | O_CREAT | O_EXCL, 0600); 336 #endif 313 337 if(fd_out < 0) 314 338 { … … 324 348 // This example shows output to a file 325 349 326 ops_create_info_t *cinfo;327 350 cinfo=ops_create_info_new(); 328 351 ops_writer_set_fd(cinfo,fd_out); … … 367 390 // File contents should match - check with GPG 368 391 369 char pp[MAXBUF];370 392 if (pub_key==alpha_pub_keydata) 371 393 pp[0]='\0'; … … 383 405 // File contents should match - checking with OPS 384 406 385 char* testtext=NULL;386 407 testtext=create_testtext(filename); 387 408 test_rsa_decrypt(encrypted_file,testtext); openpgpsdk/trunk/tests/test_rsa_signature.c
r506 r514 57 57 int fd_out=0; 58 58 int rtn=0; 59 ops_create_info_t *cinfo=NULL; 59 60 60 61 // open file to sign 61 62 snprintf(myfile,MAXBUF,"%s/%s",dir,filename); 63 #ifdef WIN32 64 fd_in=open(myfile,O_RDONLY | O_BINARY); 65 #else 62 66 fd_in=open(myfile,O_RDONLY); 67 #endif 63 68 if(fd_in < 0) 64 69 { … … 68 73 69 74 snprintf(signed_file,MAXBUF,"%s/%s_%s.%s",dir,filename,ops_show_hash_algorithm(hash_alg),suffix); 75 #ifdef WIN32 76 fd_out=open(signed_file,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600); 77 #else 70 78 fd_out=open(signed_file,O_WRONLY | O_CREAT | O_EXCL, 0600); 79 #endif 71 80 if(fd_out < 0) 72 81 { … … 85 94 86 95 // set up output file 87 ops_create_info_t *cinfo;88 96 cinfo=ops_create_info_new(); 89 97 ops_writer_set_fd(cinfo,fd_out); … … 114 122 ops_write_signature(sig,(ops_public_key_t *)&skey->public_key,(ops_secret_key_t *)skey,cinfo); 115 123 ops_writer_close(cinfo); 124 close(fd_out); 116 125 117 126 #ifdef TODO openpgpsdk/trunk/tests/test_rsa_verify.c
r507 r514 12 12 13 13 #include "tests.h" 14 15 #ifndef ATTRIBUTE_UNUSED 16 17 #ifndef WIN32 18 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 19 #else 20 #define ATTRIBUTE_UNUSED 21 #endif // #ifndef WIN32 22 23 #endif /* ATTRIBUTE_UNUSED */ 14 24 15 25 typedef struct … … 162 172 } 163 173 164 static void test_rsa_verify(const int has_armour, const int has_passphrase __attribute__((__unused__)), const char *filename, const char* protocol)174 static void test_rsa_verify(const int has_armour, const int has_passphrase ATTRIBUTE_UNUSED, const char *filename, const char* protocol) 165 175 { 166 176 char signedfile[MAXBUF+1]; … … 178 188 protocol==NULL ? "" : "_", 179 189 filename,suffix); 190 #ifdef WIN32 191 fd=open(signedfile,O_RDONLY | O_BINARY); 192 #else 180 193 fd=open(signedfile,O_RDONLY); 194 #endif 181 195 if(fd < 0) 182 196 { openpgpsdk/trunk/tests/tests.c
r511 r514 3 3 #include <string.h> 4 4 #include <stdlib.h> 5 #ifndef WIN32 5 6 #include <unistd.h> 7 #endif 6 8 #include <sys/stat.h> 7 9 … … 57 59 snprintf(keydetails,MAXBUF,"%s/%s",dir,"keydetails.alpha"); 58 60 61 #ifdef WIN32 62 if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600))<0) 63 #else 59 64 if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL, 0600))<0) 65 #endif 60 66 { 61 67 fprintf(stderr,"Can't create Alpha key details\n"); … … 75 81 snprintf(keydetails,MAXBUF,"%s/%s",dir,"keydetails.bravo"); 76 82 83 #ifdef WIN32 84 if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600))<0) 85 #else 77 86 if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL, 0600))<0) 87 #endif 78 88 { 79 89 fprintf(stderr,"Can't create Bravo key details\n"); … … 206 216 int limit=10; // don't try indefinitely 207 217 long int rnd=0; 218 219 #ifdef WIN32 220 srand( (unsigned)time( NULL ) ); 221 #endif 208 222 while (limit--) 209 223 { … … 212 226 213 227 // Try to create directory 228 #ifndef WIN32 214 229 if (!mkdir(dir,0700)) 230 #else 231 if (!_mkdir(dir)) 232 #endif 215 233 { 216 234 // success … … 234 252 const unsigned int maxbuf=1024; 235 253 char buf[maxbuf+1]; 254 unsigned int sz_one=0; 255 unsigned int sz_big=0; 256 char* bigbuf=NULL; 257 236 258 buf[maxbuf]='\0'; 237 259 snprintf(buf,maxbuf,"%s : Test Text\n", text); 238 260 239 const unsigned int sz_one=strlen(buf); 240 const unsigned int sz_big=sz_one*repeats+1; 241 242 char* bigbuf=ops_mallocz(sz_big); 261 sz_one=strlen(buf); 262 sz_big=sz_one*repeats+1; 263 264 bigbuf=ops_mallocz(sz_big); 265 243 266 for (i=0; i<repeats; i++) 244 267 { … … 257 280 snprintf((char *)buf,maxlen,"%s%s", text, preamble); 258 281 282 #ifdef WIN32 283 srand( (unsigned)time( NULL ) ); 284 #endif 259 285 for (i=strlen(text)+strlen(preamble); i<maxlen; i++) 260 286 { … … 270 296 int fd=0; 271 297 snprintf(filename,MAXBUF,"%s/%s",dir,name); 298 #ifdef WIN32 299 if ((fd=open(filename,O_WRONLY| O_CREAT | O_EXCL | O_BINARY, 0600))<0) 300 #else 272 301 if ((fd=open(filename,O_WRONLY| O_CREAT | O_EXCL, 0600))<0) 302 #endif 273 303 return; 274 304 … … 318 348 const ops_key_data_t *keydata=NULL; 319 349 const ops_secret_key_t *secret; 350 char *passphrase=NULL; 320 351 321 352 OPS_USED(cbinfo); … … 331 362 332 363 // Do we need the passphrase and not have it? If so, get it 333 char *passphrase=NULL;334 364 passphrase=NULL; 335 365 openpgpsdk/trunk/tests/tests.h
r511 r514 6 6 #include <string.h> 7 7 #include <stdlib.h> 8 #ifndef WIN32 8 9 #include <unistd.h> 10 #else 11 #include <direct.h> 12 #define snprintf _snprintf 13 #define random rand 14 #endif 9 15 #include <fcntl.h> 10 16 #include <sys/stat.h>
