Changeset 516
- Timestamp:
- 10/17/07 17:11:48
- Files:
-
- openpgpsdk/trunk/include/openpgpsdk/crypto.h (modified) (1 diff)
- openpgpsdk/trunk/include/openpgpsdk/errors.h (modified) (1 diff)
- openpgpsdk/trunk/include/openpgpsdk/keyring.h (modified) (2 diffs)
- openpgpsdk/trunk/include/openpgpsdk/random.h (modified) (1 diff)
- openpgpsdk/trunk/include/openpgpsdk/util.h (modified) (1 diff)
- openpgpsdk/trunk/src/advanced/Makefile.template (modified) (1 diff)
- openpgpsdk/trunk/src/advanced/adv_compress.c (modified) (1 diff)
- openpgpsdk/trunk/src/advanced/adv_create.c (modified) (7 diffs)
- openpgpsdk/trunk/src/advanced/adv_crypto.c (modified) (1 diff)
- openpgpsdk/trunk/src/advanced/adv_errors.c (modified) (2 diffs)
- openpgpsdk/trunk/src/advanced/adv_fingerprint.c (modified) (1 diff)
- openpgpsdk/trunk/src/advanced/adv_keyring.c (modified) (5 diffs)
- openpgpsdk/trunk/src/advanced/adv_openssl_crypto.c (modified) (2 diffs)
- openpgpsdk/trunk/src/advanced/adv_packet-parse.c (modified) (15 diffs)
- openpgpsdk/trunk/src/advanced/adv_symmetric.c (modified) (5 diffs)
- openpgpsdk/trunk/src/advanced/adv_util.c (modified) (1 diff)
- openpgpsdk/trunk/src/advanced/adv_writer_encrypt.c (modified) (3 diffs)
- openpgpsdk/trunk/src/advanced/adv_writer_encrypt_se_ip.c (modified) (10 diffs)
- openpgpsdk/trunk/src/standard/std_keyring.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/include/openpgpsdk/crypto.h
r500 r516 128 128 int ops_decrypt_and_unencode_mpi(unsigned char *buf,unsigned buflen,const BIGNUM *encmpi, 129 129 const ops_secret_key_t *skey); 130 ops_boolean_t ops_encrypt_mpi(const unsigned char *buf, size_t buflen,130 ops_boolean_t ops_encrypt_mpi(const unsigned char *buf, const size_t buflen, 131 131 const ops_public_key_t *pkey, 132 132 ops_pk_session_key_parameters_t *spk); openpgpsdk/trunk/include/openpgpsdk/errors.h
r496 r516 78 78 void ops_print_error(ops_error_t *err); 79 79 void ops_print_errors(ops_error_t *errstack); 80 void ops_free_errors(ops_error_t *errstack); 80 81 81 82 #define OPS_SYSTEM_ERROR_1(err,code,syscall,fmt,arg) do { ops_push_error(err,OPS_E_SYSTEM_ERROR,errno,__FILE__,__LINE__,syscall); ops_push_error(err,code,0,__FILE__,__LINE__,fmt,arg); } while(0) openpgpsdk/trunk/include/openpgpsdk/keyring.h
r503 r516 37 37 const char *pphrase); 38 38 39 voidops_keyring_read(ops_keyring_t *keyring,const char *file);39 ops_boolean_t ops_keyring_read(ops_keyring_t *keyring,const char *file); 40 40 41 41 char *ops_malloc_passphrase(char *passphrase); … … 47 47 48 48 const unsigned char* ops_get_key_id(const ops_key_data_t *key); 49 unsigned ops_get_user_id_count(const ops_key_data_t *key); 50 const unsigned char* ops_get_user_id(const ops_key_data_t *key, unsigned index); 51 ops_boolean_t ops_key_is_supported(const ops_key_data_t *key); 52 const ops_key_data_t* ops_keyring_get_key(const ops_keyring_t *keyring, int index); 49 53 50 54 #endif openpgpsdk/trunk/include/openpgpsdk/random.h
r470 r516 1 #ifdef WIN32 2 #include <malloc.h> 3 #else 1 4 #include <unistd.h> 5 #endif 2 6 3 7 void ops_random(void *dest,size_t length); openpgpsdk/trunk/include/openpgpsdk/util.h
r346 r516 19 19 20 20 /* typesafe deconstification */ 21 #ifdef WIN32 22 static void *_deconst(const void *p) 23 { return (void *)p; } 24 #else 21 25 static inline void *_deconst(const void *p) 22 26 { return (void *)p; } 27 #endif 23 28 #define DECONST(type,p) (((type *(*)(const type *))ops_fcast(_deconst))(p)) 24 29 openpgpsdk/trunk/src/advanced/Makefile.template
r509 r516 14 14 adv_validate.o adv_lists.o adv_armour.o adv_errors.o \ 15 15 adv_writer_encrypt_se_ip.o adv_writer_encrypt.o \ 16 adv_writer_stream_encrypt_se_ip.o \ 16 17 adv_symmetric.o adv_crypto.o random.o adv_readerwriter.o 17 18 openpgpsdk/trunk/src/advanced/adv_compress.c
r457 r516 132 132 ret=inflateInit(&arg.stream); 133 133 else 134 assert(0); 134 { 135 assert(0); 136 return 0; 137 } 135 138 136 139 if(ret != Z_OK) openpgpsdk/trunk/src/advanced/adv_create.c
r511 r516 14 14 #include <string.h> 15 15 #include <assert.h> 16 #ifndef WIN32 16 17 #include <unistd.h> 18 #endif 17 19 18 20 #include <openpgpsdk/final.h> … … 847 849 848 850 const ops_public_key_t* pub_key=ops_get_public_key_from_data(key); 849 const size_t sz_unencoded_m_buf=CAST_KEY_LENGTH+1+2; 850 unsigned char unencoded_m_buf[ sz_unencoded_m_buf];851 #define SZ_UNENCODED_M_BUF CAST_KEY_LENGTH+1+2 852 unsigned char unencoded_m_buf[SZ_UNENCODED_M_BUF]; 851 853 852 854 const size_t sz_encoded_m_buf=BN_num_bytes(pub_key->key.rsa.n); 853 unsigned char encoded_m_buf[sz_encoded_m_buf];855 unsigned char* encoded_m_buf = ops_mallocz(sz_encoded_m_buf); 854 856 855 857 ops_pk_session_key_t *session_key=ops_mallocz(sizeof *session_key); … … 861 863 if (debug) 862 864 { 865 unsigned int i=0; 863 866 fprintf(stderr,"Encrypting for RSA key id : "); 864 unsigned int i=0;865 867 for (i=0; i<sizeof session_key->key_id; i++) 866 868 fprintf(stderr,"%2x ", key->key_id[i]); … … 885 887 886 888 if (create_unencoded_m_buf(session_key, &unencoded_m_buf[0])==ops_false) 889 { 890 free(encoded_m_buf); 887 891 return NULL; 892 } 888 893 889 894 if (debug) … … 891 896 unsigned int i=0; 892 897 printf("unencoded m buf:\n"); 893 for (i=0; i< sz_unencoded_m_buf; i++)898 for (i=0; i<SZ_UNENCODED_M_BUF; i++) 894 899 printf("%2x ", unencoded_m_buf[i]); 895 900 printf("\n"); 896 901 } 897 encode_m_buf(&unencoded_m_buf[0], sz_unencoded_m_buf, pub_key, &encoded_m_buf[0]);902 encode_m_buf(&unencoded_m_buf[0], SZ_UNENCODED_M_BUF, pub_key, &encoded_m_buf[0]); 898 903 899 904 // and encrypt it 900 905 if(!ops_encrypt_mpi(encoded_m_buf, sz_encoded_m_buf, pub_key, &session_key->parameters)) 906 { 907 free (encoded_m_buf); 901 908 return NULL; 902 909 } 910 911 free(encoded_m_buf); 903 912 return session_key; 904 913 } 905 906 #ifndef ATTRIBUTE_UNUSED907 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))908 #endif /* ATTRIBUTE_UNUSED */909 914 910 915 ops_boolean_t ops_write_pk_session_key(ops_create_info_t *info, … … 953 958 ops_create_info_t *info) 954 959 { 960 int done=0; 955 961 ops_crypt_t crypt_info; 956 962 int encrypted_sz=0;// size of encrypted data … … 964 970 encrypted=ops_mallocz(encrypted_sz); 965 971 966 intdone=ops_encrypt_se(&crypt_info, encrypted, data, len);972 done=ops_encrypt_se(&crypt_info, encrypted, data, len); 967 973 assert(done==len); 968 974 // printf("len=%d, done: %d\n", len, done); openpgpsdk/trunk/src/advanced/adv_crypto.c
r490 r516 90 90 unsigned char encmpibuf[8192]; 91 91 int n=0; 92 #ifdef XXX93 unsigned char EM[8192];94 int k;95 unsigned i;96 92 97 // implementation of EME-PKCS1-v1_5-ENCODE, as defined in OpenPGP RFC98 99 assert(pkey->algorithm == OPS_PKA_RSA);100 101 k=BN_num_bytes(pkey->key.rsa.n);102 /*103 printf("k=%d (length in octets of key modulus)\n",k);104 printf("mLen=%d\n",mLen);105 */106 assert(mLen <= k-11);107 if (mLen > k-11)108 {109 fprintf(stderr,"message too long\n");110 return false;111 }112 113 // output will be written to ??114 115 // these two bytes defined by RFC116 EM[0]=0x00;117 EM[1]=0x02;118 119 // add non-zero random bytes of length k - mLen -3120 for(i=2 ; i < k-mLen-1 ; ++i)121 do122 ops_random(EM+i, 1);123 while(EM[i] == 0);124 125 assert (i >= 8+2);126 127 EM[i++]=0;128 129 memcpy(EM+i, M, mLen);130 131 /*132 int i=0;133 fprintf(stderr,"Encoded Message: \n");134 for (i=0; i<mLen; i++)135 fprintf(stderr,"%2x ", EM[i]);136 fprintf(stderr,"\n");137 */138 139 #endif140 93 n=ops_rsa_public_encrypt(encmpibuf, encoded_m_buf, sz_encoded_m_buf, &pkey->key.rsa); 141 94 assert(n!=-1); openpgpsdk/trunk/src/advanced/adv_errors.c
r493 r516 10 10 #include <stdio.h> 11 11 #include <stdlib.h> 12 13 #ifdef WIN32 14 #define vsnprintf _vsnprintf 15 #endif 12 16 13 17 #include <openpgpsdk/final.h> … … 117 121 ops_print_error(err); 118 122 } 123 124 void ops_free_errors(ops_error_t *errstack) 125 { 126 ops_error_t *next; 127 while(errstack!=NULL) { 128 next=errstack->next; 129 free(errstack->comment); 130 free(errstack); 131 errstack=next; 132 } 133 } openpgpsdk/trunk/src/advanced/adv_fingerprint.c
r426 r516 11 11 #ifdef HAVE_ALLOCA_H 12 12 # include <alloca.h> 13 #endif 14 15 #ifdef WIN32 16 #define alloca _alloca 13 17 #endif 14 18 openpgpsdk/trunk/src/advanced/adv_keyring.c
r505 r516 10 10 #include <stdlib.h> 11 11 #include <string.h> 12 #ifndef WIN32 12 13 #include <unistd.h> 14 #include <termios.h> 15 #endif 13 16 #include <fcntl.h> 14 17 #include <assert.h> 15 #include <termios.h>16 18 17 19 #include <openpgpsdk/final.h> … … 58 60 static void echo_off() 59 61 { 62 #ifndef WIN32 60 63 struct termios term; 61 64 int r; … … 70 73 r=tcsetattr(0,TCSANOW,&term); 71 74 assert(r >= 0); 75 #endif 72 76 } 73 77 74 78 static void echo_on() 75 79 { 80 #ifndef WIN32 76 81 struct termios term; 77 82 int r; … … 86 91 r=tcsetattr(0,TCSANOW,&term); 87 92 assert(r >= 0); 93 #endif 88 94 } 89 95 … … 218 224 return key->key_id; 219 225 } 226 227 unsigned ops_get_user_id_count(const ops_key_data_t *key) 228 { 229 return key->nuids; 230 } 231 232 const unsigned char* ops_get_user_id(const ops_key_data_t *key, unsigned index) 233 { 234 return key->uids[index].user_id; 235 } 236 237 ops_boolean_t ops_key_is_supported(const ops_key_data_t *key) 238 { 239 if ( key->type == OPS_PTAG_CT_PUBLIC_KEY ) { 240 if ( key->key.pkey.algorithm == OPS_PKA_RSA ) { 241 return ops_true; 242 } 243 } else if ( key->type == OPS_PTAG_CT_PUBLIC_KEY ) { 244 if ( key->key.skey.algorithm == OPS_PKA_RSA ) { 245 return ops_true; 246 } 247 } 248 return ops_false; 249 } 250 251 252 const ops_key_data_t* ops_keyring_get_key(const ops_keyring_t *keyring, int index) 253 { 254 return &keyring->keys[index]; 255 } openpgpsdk/trunk/src/advanced/adv_openssl_crypto.c
r490 r516 153 153 RSA *orsa; 154 154 int n; 155 char errbuf[1024]; 155 156 156 157 orsa=RSA_new(); … … 170 171 // printf("ops_rsa_private_decrypt: n=%d\n",n); 171 172 172 char errbuf[1024];173 173 errbuf[0]='\0'; 174 174 if (n==-1) openpgpsdk/trunk/src/advanced/adv_packet-parse.c
r511 r516 20 20 #include <stdlib.h> 21 21 #include <string.h> 22 #ifndef WIN32 22 23 #include <unistd.h> 24 #endif 23 25 #include <errno.h> 24 26 #include <limits.h> … … 84 86 len=subregion->length-subregion->length_read; 85 87 86 return(limited_read_data(data,len,subregion,pinfo)); 88 if ( len >= 0 ) { 89 return(limited_read_data(data,len,subregion,pinfo)); 90 } 91 return 0; 87 92 } 88 93 … … 207 212 for(n=0 ; n < length ; ) 208 213 { 209 int r=rinfo->reader( dest+n,length-n,errors,rinfo,cbinfo);214 int r=rinfo->reader((char*)dest+n,length-n,errors,rinfo,cbinfo); 210 215 211 216 assert(r <= (int)(length-n)); … … 2141 2146 2142 2147 default: 2143 fprintf(stderr,"Unexpected a glorithm: %d\n",2148 fprintf(stderr,"Unexpected algorithm: %d\n", 2144 2149 C.secret_key.public_key.algorithm); 2145 2150 ret=0; … … 2219 2224 unsigned k; 2220 2225 const ops_secret_key_t *secret; 2226 unsigned char cs[2]; 2227 unsigned char* iv; 2221 2228 2222 2229 // Can't rely on it being CAST5 … … 2345 2352 // Check checksum 2346 2353 2347 unsigned char cs[2];2348 2354 ops_calc_session_key_checksum(&C.pk_session_key, &cs[0]); 2349 2355 if (unencoded_m_buf[k+1]!=cs[0] || unencoded_m_buf[k+2]!=cs[1]) … … 2359 2365 2360 2366 ops_crypt_any(&pinfo->decrypt,C.pk_session_key.symmetric_algorithm); 2361 unsigned char *iv=ops_mallocz(pinfo->decrypt.blocksize);2367 iv=ops_mallocz(pinfo->decrypt.blocksize); 2362 2368 pinfo->decrypt.set_iv(&pinfo->decrypt, iv); 2363 2369 pinfo->decrypt.set_key(&pinfo->decrypt,C.pk_session_key.key); … … 2379 2385 */ 2380 2386 2387 unsigned int n=0; 2388 2381 2389 ops_region_t decrypted_region; 2382 2390 … … 2389 2397 ops_hash_t hash; 2390 2398 unsigned char hashed[SHA_DIGEST_LENGTH]; 2399 2400 size_t b; 2401 size_t sz_preamble; 2402 size_t sz_mdc_hash; 2403 size_t sz_mdc; 2404 size_t sz_plaintext; 2405 2406 unsigned char* preamble; 2407 unsigned char* plaintext; 2408 unsigned char* mdc; 2409 unsigned char* mdc_hash; 2391 2410 2392 2411 ops_hash_any(&hash,OPS_HASH_SHA1); … … 2404 2423 if (debug) 2405 2424 { 2425 unsigned int i=0; 2406 2426 fprintf(stderr,"\n\nentire SE IP packet (len=%d):\n",decrypted_region.length); 2407 unsigned int i=0;2408 2427 for (i=0; i<decrypted_region.length; i++) 2409 2428 { … … 2420 2439 if (debug) 2421 2440 { 2441 unsigned int i=0; 2422 2442 fprintf(stderr,"\npreamble: "); 2423 unsigned int i=0;2424 2443 for (i=0; i<arg->decrypt->blocksize+2;i++) 2425 2444 fprintf(stderr," 0x%02x", buf[i]); … … 2427 2446 } 2428 2447 2429 size_tb=arg->decrypt->blocksize;2448 b=arg->decrypt->blocksize; 2430 2449 if(buf[b-2] != buf[b] || buf[b-1] != buf[b+1]) 2431 2450 { … … 2438 2457 // Verify trailing MDC hash 2439 2458 2440 s ize_t sz_preamble=arg->decrypt->blocksize+2;2441 s ize_t sz_mdc_hash=OPS_SHA1_HASH_SIZE;2442 s ize_t sz_mdc=1+1+sz_mdc_hash;2443 s ize_t sz_plaintext=decrypted_region.length-sz_preamble-sz_mdc;2444 2445 unsigned char*preamble=buf;2446 unsigned char*plaintext=buf+sz_preamble;2447 unsigned char*mdc=plaintext+sz_plaintext;2448 unsigned char*mdc_hash=mdc+2;2459 sz_preamble=arg->decrypt->blocksize+2; 2460 sz_mdc_hash=OPS_SHA1_HASH_SIZE; 2461 sz_mdc=1+1+sz_mdc_hash; 2462 sz_plaintext=decrypted_region.length-sz_preamble-sz_mdc; 2463 2464 preamble=buf; 2465 plaintext=buf+sz_preamble; 2466 mdc=plaintext+sz_plaintext; 2467 mdc_hash=mdc+2; 2449 2468 2450 2469 if (debug) … … 2495 2514 } 2496 2515 2497 unsigned intn=len;2516 n=len; 2498 2517 if (n > arg->plaintext_available) 2499 2518 n=arg->plaintext_available; … … 3013 3032 if(pinfo->rinfo.destroyer) 3014 3033 pinfo->rinfo.destroyer(&pinfo->rinfo); 3034 ops_free_errors(pinfo->errors); 3035 if(pinfo->rinfo.accumulated) 3036 free(pinfo->rinfo.accumulated); 3015 3037 free(pinfo); 3016 3038 } openpgpsdk/trunk/src/advanced/adv_symmetric.c
r501 r516 13 13 #include <openpgpsdk/final.h> 14 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 */ 24 25 15 26 // \todo there's also a encrypted_arg_t in adv_create.c 16 27 // which is used for *encrypting* whereas this is used … … 66 77 arg->decrypted_offset+=n; 67 78 length-=n; 68 dest+=n; 79 #ifdef WIN32 80 (char*)dest+=n; 81 #else 82 dest+=n; 83 #endif 69 84 } 70 85 else … … 421 436 } 422 437 423 static void tripledes_cfb_encrypt(ops_crypt_t *crypt __attribute__((__unused__)),void *out __attribute__((__unused__)),const void *in __attribute__((__unused__)), size_t count __attribute__((__unused__)))438 static void tripledes_cfb_encrypt(ops_crypt_t *crypt ATTRIBUTE_UNUSED,void *out ATTRIBUTE_UNUSED,const void *in ATTRIBUTE_UNUSED, size_t count ATTRIBUTE_UNUSED) 424 439 { 425 440 assert(0); … … 431 446 } 432 447 433 static void tripledes_cfb_decrypt(ops_crypt_t *crypt __attribute__((__unused__)),void *out __attribute__((__unused__)),const void *in __attribute__((__unused__)), size_t count __attribute__((__unused__)))448 static void tripledes_cfb_decrypt(ops_crypt_t *crypt ATTRIBUTE_UNUSED,void *out ATTRIBUTE_UNUSED,const void *in ATTRIBUTE_UNUSED, size_t count ATTRIBUTE_UNUSED) 434 449 { 435 450 assert(0); … … 514 529 { 515 530 // \todo should there be a separate ops_encrypt_init? 516 returnops_decrypt_init(encrypt);531 ops_decrypt_init(encrypt); 517 532 } 518 533 openpgpsdk/trunk/src/advanced/adv_util.c
r457 r516 9 9 #include <stdio.h> 10 10 #include <assert.h> 11 12 #ifndef WIN32 11 13 #include <unistd.h> 14 #endif 15 12 16 #include <string.h> 13 17 openpgpsdk/trunk/src/advanced/adv_writer_encrypt.c
r511 r516 23 23 { 24 24 int debug=0; 25 26 #define BUFSZ 1024 // arbitrary number 27 unsigned char encbuf[BUFSZ]; 28 unsigned remaining=length; 29 unsigned done=0; 30 25 31 crypt_arg_t *arg=(crypt_arg_t *)ops_writer_get_arg(winfo); 26 32 … … 28 34 assert(0); // \todo proper error handling 29 35 30 #define BUFSZ 1024 // arbitrary number31 // unsigned char buf[BUFSZ];32 unsigned char encbuf[BUFSZ];33 unsigned remaining=length;34 unsigned done=0;35 36 while (remaining) 36 37 { … … 42 43 if (debug) 43 44 { 45 int i=0; 44 46 fprintf(stderr,"WRITING:\nunencrypted: "); 45 int i=0;46 47 for (i=0; i<16; i++) 47 48 fprintf(stderr,"%2x ", src[done+i]); openpgpsdk/trunk/src/advanced/adv_writer_encrypt_se_ip.c
r511 r516 4 4 #include <string.h> 5 5 #include <assert.h> 6 #include <unistd.h> 6 7 #ifndef WIN32 8 #include <unistd.h> 9 #endif 7 10 8 11 #include <openssl/cast.h> … … 30 33 const ops_key_data_t *pub_key) 31 34 { 35 ops_crypt_t* encrypt; 36 unsigned char *iv=NULL; 37 32 38 // Create arg to be used with this writer 33 39 // Remember to free this in the destroyer … … 40 46 41 47 // Setup the arg 42 ops_crypt_t*encrypt=ops_mallocz(sizeof *encrypt);48 encrypt=ops_mallocz(sizeof *encrypt); 43 49 ops_crypt_any(encrypt, encrypted_pk_session_key->symmetric_algorithm); 44 unsigned char *iv=NULL;45 50 iv=ops_mallocz(encrypt->blocksize); 46 51 encrypt->set_iv(encrypt, iv); … … 110 115 int debug=0; 111 116 ops_hash_t hash; 112 unsigned char c[0]; 113 114 if (debug) 115 { 117 unsigned char c[1]; 118 119 if (debug) 120 { 121 unsigned int i=0; 116 122 fprintf(stderr,"ops_calc_mdc_hash():\n"); 117 123 118 124 fprintf(stderr,"\npreamble: "); 119 unsigned int i=0;120 125 for (i=0; i<sz_preamble;i++) 121 126 fprintf(stderr," 0x%02x", preamble[i]); … … 164 169 unsigned char hashed[SHA_DIGEST_LENGTH]; 165 170 const size_t sz_mdc=1+1+SHA_DIGEST_LENGTH; 166 encrypt_se_ip_arg_t *arg=ops_mallocz(sizeof *arg);171 // encrypt_se_ip_arg_t *arg=ops_mallocz(sizeof *arg); 167 172 168 173 size_t sz_preamble=crypt->blocksize+2; … … 170 175 171 176 size_t sz_buf=sz_preamble+len+sz_mdc; 177 178 ops_memory_t *mem_mdc; 179 ops_create_info_t *cinfo_mdc; 172 180 173 181 #define SE_IP_DATA_VERSION 1 //\todo move this … … 184 192 if (debug) 185 193 { 194 unsigned int i=0; 186 195 fprintf(stderr,"\npreamble: "); 187 unsigned int i=0;188 196 for (i=0; i<sz_preamble;i++) 189 197 fprintf(stderr," 0x%02x", preamble[i]); … … 193 201 // now construct MDC packet and add to the end of the buffer 194 202 195 ops_memory_t *mem_mdc;196 ops_create_info_t *cinfo_mdc;197 198 203 ops_setup_memory_write(&cinfo_mdc, &mem_mdc,sz_mdc); 199 204 … … 205 210 { 206 211 unsigned int i=0; 212 size_t sz_plaintext=len; 213 size_t sz_mdc=1+1+OPS_SHA1_HASH_SIZE; 214 unsigned char* mdc=NULL; 207 215 208 216 fprintf(stderr,"\nplaintext: "); 209 size_t sz_plaintext=len;210 217 for (i=0; i<sz_plaintext;i++) 211 218 fprintf(stderr," 0x%02x", data[i]); … … 213 220 214 221 fprintf(stderr,"\nmdc: "); 215 size_t sz_mdc=1+1+OPS_SHA1_HASH_SIZE; 216 unsigned char* mdc=ops_memory_get_data(mem_mdc); 222 mdc=ops_memory_get_data(mem_mdc); 217 223 for (i=0; i<sz_mdc;i++) 218 224 fprintf(stderr," 0x%02x", mdc[i]); openpgpsdk/trunk/src/standard/std_keyring.c
r487 r516 65 65 #include <stdlib.h> 66 66 #include <string.h> 67 #include <unistd.h> 67 #ifndef WIN32 68 #include <unistd.h> 69 #endif 68 70 69 71 #include "openpgpsdk/packet.h" … … 96 98 ops_keyring_free() between these calls, you will introduce a memory leak. 97 99 */ 98 voidops_keyring_read(ops_keyring_t *keyring,const char *file)100 ops_boolean_t ops_keyring_read(ops_keyring_t *keyring,const char *file) 99 101 { 100 102 ops_parse_info_t *pinfo; 101 103 int fd; 104 ops_boolean_t res = ops_true; 102 105 103 106 memset(keyring,'\0',sizeof *keyring); … … 111 114 ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED); 112 115 116 #ifdef WIN32 117 fd=open(file,O_RDONLY|O_BINARY); 118 #else 113 119 fd=open(file,O_RDONLY); 120 #endif 114 121 if(fd < 0) 115 { 116 perror(file); 117 exit(1); 118 } 122 { 123 ops_parse_info_delete(pinfo); 124 perror(file); 125 return ops_false; 126 } 119 127 120 128 ops_reader_set_fd(pinfo,fd); … … 122 130 ops_parse_cb_set(pinfo,cb_keyring_read,NULL); 123 131 124 ops_parse_and_accumulate(keyring,pinfo); 132 if ( ops_parse_and_accumulate(keyring,pinfo) == 0 ) { 133 res = ops_false; 134 } 125 135 126 136 close(fd); 127 137 128 138 ops_parse_info_delete(pinfo); 139 140 return res; 129 141 } 130 142
