Changeset 516

Show
Ignore:
Timestamp:
10/17/07 17:11:48
Author:
rachel
Message:

WIN32 changes provided by Alexey Simak

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/include/openpgpsdk/crypto.h

    r500 r516  
    128128int ops_decrypt_and_unencode_mpi(unsigned char *buf,unsigned buflen,const BIGNUM *encmpi, 
    129129                    const ops_secret_key_t *skey); 
    130 ops_boolean_t ops_encrypt_mpi(const unsigned char *buf, size_t buflen, 
     130ops_boolean_t ops_encrypt_mpi(const unsigned char *buf, const size_t buflen, 
    131131                              const ops_public_key_t *pkey, 
    132132                              ops_pk_session_key_parameters_t *spk); 
  • openpgpsdk/trunk/include/openpgpsdk/errors.h

    r496 r516  
    7878void ops_print_error(ops_error_t *err); 
    7979void ops_print_errors(ops_error_t *errstack); 
     80void ops_free_errors(ops_error_t *errstack); 
    8081 
    8182#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  
    3737                                                   const char *pphrase); 
    3838 
    39 void ops_keyring_read(ops_keyring_t *keyring,const char *file); 
     39ops_boolean_t ops_keyring_read(ops_keyring_t *keyring,const char *file); 
    4040 
    4141char *ops_malloc_passphrase(char *passphrase); 
     
    4747 
    4848const unsigned char* ops_get_key_id(const ops_key_data_t *key); 
     49unsigned ops_get_user_id_count(const ops_key_data_t *key); 
     50const unsigned char* ops_get_user_id(const ops_key_data_t *key, unsigned index); 
     51ops_boolean_t ops_key_is_supported(const ops_key_data_t *key); 
     52const ops_key_data_t* ops_keyring_get_key(const ops_keyring_t *keyring, int index); 
    4953 
    5054#endif 
  • openpgpsdk/trunk/include/openpgpsdk/random.h

    r470 r516  
     1#ifdef WIN32 
     2#include <malloc.h> 
     3#else 
    14#include <unistd.h> 
     5#endif 
    26 
    37void ops_random(void *dest,size_t length); 
  • openpgpsdk/trunk/include/openpgpsdk/util.h

    r346 r516  
    1919 
    2020/* typesafe deconstification */ 
     21#ifdef WIN32 
     22static void *_deconst(const void *p) 
     23    { return (void *)p; } 
     24#else  
    2125static inline void *_deconst(const void *p) 
    2226    { return (void *)p; } 
     27#endif 
    2328#define DECONST(type,p) (((type *(*)(const type *))ops_fcast(_deconst))(p)) 
    2429 
  • openpgpsdk/trunk/src/advanced/Makefile.template

    r509 r516  
    1414        adv_validate.o adv_lists.o adv_armour.o adv_errors.o \ 
    1515    adv_writer_encrypt_se_ip.o adv_writer_encrypt.o \ 
     16    adv_writer_stream_encrypt_se_ip.o \ 
    1617        adv_symmetric.o adv_crypto.o random.o adv_readerwriter.o 
    1718 
  • openpgpsdk/trunk/src/advanced/adv_compress.c

    r457 r516  
    132132        ret=inflateInit(&arg.stream); 
    133133    else 
    134         assert(0); 
     134        { 
     135        assert(0); 
     136        return 0; 
     137        } 
    135138 
    136139    if(ret != Z_OK) 
  • openpgpsdk/trunk/src/advanced/adv_create.c

    r511 r516  
    1414#include <string.h> 
    1515#include <assert.h> 
     16#ifndef WIN32 
    1617#include <unistd.h> 
     18#endif 
    1719 
    1820#include <openpgpsdk/final.h> 
     
    847849 
    848850    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]; 
    851853 
    852854    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)
    854856 
    855857    ops_pk_session_key_t *session_key=ops_mallocz(sizeof *session_key); 
     
    861863    if (debug) 
    862864        { 
     865        unsigned int i=0; 
    863866        fprintf(stderr,"Encrypting for RSA key id : "); 
    864         unsigned int i=0; 
    865867        for (i=0; i<sizeof session_key->key_id; i++) 
    866868            fprintf(stderr,"%2x ", key->key_id[i]); 
     
    885887 
    886888    if (create_unencoded_m_buf(session_key, &unencoded_m_buf[0])==ops_false) 
     889        { 
     890        free(encoded_m_buf); 
    887891        return NULL; 
     892        } 
    888893 
    889894    if (debug) 
     
    891896        unsigned int i=0; 
    892897        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++) 
    894899            printf("%2x ", unencoded_m_buf[i]); 
    895900        printf("\n"); 
    896901        } 
    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]); 
    898903     
    899904    // and encrypt it 
    900905    if(!ops_encrypt_mpi(encoded_m_buf, sz_encoded_m_buf, pub_key, &session_key->parameters)) 
     906        { 
     907        free (encoded_m_buf); 
    901908        return NULL; 
    902  
     909        } 
     910 
     911    free(encoded_m_buf); 
    903912    return session_key; 
    904913    } 
    905  
    906 #ifndef ATTRIBUTE_UNUSED 
    907 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 
    908 #endif /* ATTRIBUTE_UNUSED */ 
    909914 
    910915ops_boolean_t ops_write_pk_session_key(ops_create_info_t *info, 
     
    953958                                                     ops_create_info_t *info) 
    954959    { 
     960    int done=0; 
    955961    ops_crypt_t crypt_info; 
    956962    int encrypted_sz=0;// size of encrypted data 
     
    964970    encrypted=ops_mallocz(encrypted_sz); 
    965971 
    966     int done=ops_encrypt_se(&crypt_info, encrypted, data, len); 
     972    done=ops_encrypt_se(&crypt_info, encrypted, data, len); 
    967973    assert(done==len); 
    968974    //    printf("len=%d, done: %d\n", len, done); 
  • openpgpsdk/trunk/src/advanced/adv_crypto.c

    r490 r516  
    9090    unsigned char encmpibuf[8192]; 
    9191    int n=0; 
    92 #ifdef XXX 
    93     unsigned char EM[8192]; 
    94     int k; 
    95     unsigned i; 
    9692 
    97     // implementation of EME-PKCS1-v1_5-ENCODE, as defined in OpenPGP RFC 
    98      
    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 RFC 
    116     EM[0]=0x00; 
    117     EM[1]=0x02; 
    118  
    119     // add non-zero random bytes of length k - mLen -3 
    120     for(i=2 ; i < k-mLen-1 ; ++i) 
    121         do 
    122             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 #endif 
    14093    n=ops_rsa_public_encrypt(encmpibuf, encoded_m_buf, sz_encoded_m_buf, &pkey->key.rsa); 
    14194    assert(n!=-1); 
  • openpgpsdk/trunk/src/advanced/adv_errors.c

    r493 r516  
    1010#include <stdio.h> 
    1111#include <stdlib.h> 
     12 
     13#ifdef WIN32 
     14#define vsnprintf _vsnprintf 
     15#endif 
    1216 
    1317#include <openpgpsdk/final.h> 
     
    117121        ops_print_error(err); 
    118122    } 
     123 
     124void 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  
    1111#ifdef HAVE_ALLOCA_H 
    1212# include <alloca.h> 
     13#endif 
     14 
     15#ifdef WIN32 
     16#define alloca _alloca 
    1317#endif 
    1418 
  • openpgpsdk/trunk/src/advanced/adv_keyring.c

    r505 r516  
    1010#include <stdlib.h> 
    1111#include <string.h> 
     12#ifndef WIN32 
    1213#include <unistd.h> 
     14#include <termios.h> 
     15#endif 
    1316#include <fcntl.h> 
    1417#include <assert.h> 
    15 #include <termios.h> 
    1618 
    1719#include <openpgpsdk/final.h> 
     
    5860static void echo_off() 
    5961    { 
     62#ifndef WIN32 
    6063    struct termios term; 
    6164    int r; 
     
    7073    r=tcsetattr(0,TCSANOW,&term); 
    7174    assert(r >= 0); 
     75#endif 
    7276    } 
    7377         
    7478static void echo_on() 
    7579    { 
     80#ifndef WIN32 
    7681    struct termios term; 
    7782    int r; 
     
    8691    r=tcsetattr(0,TCSANOW,&term); 
    8792    assert(r >= 0); 
     93#endif 
    8894    } 
    8995 
     
    218224    return key->key_id; 
    219225    } 
     226 
     227unsigned ops_get_user_id_count(const ops_key_data_t *key) 
     228    { 
     229    return key->nuids; 
     230    } 
     231 
     232const unsigned char* ops_get_user_id(const ops_key_data_t *key, unsigned index) 
     233    { 
     234    return key->uids[index].user_id; 
     235    } 
     236 
     237ops_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 
     252const 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  
    153153    RSA *orsa; 
    154154    int n; 
     155    char errbuf[1024]; 
    155156 
    156157    orsa=RSA_new(); 
     
    170171    //    printf("ops_rsa_private_decrypt: n=%d\n",n); 
    171172 
    172     char errbuf[1024]; 
    173173    errbuf[0]='\0'; 
    174174    if (n==-1) 
  • openpgpsdk/trunk/src/advanced/adv_packet-parse.c

    r511 r516  
    2020#include <stdlib.h> 
    2121#include <string.h> 
     22#ifndef WIN32 
    2223#include <unistd.h> 
     24#endif 
    2325#include <errno.h> 
    2426#include <limits.h> 
     
    8486    len=subregion->length-subregion->length_read; 
    8587 
    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; 
    8792    } 
    8893 
     
    207212    for(n=0 ; n < length ; ) 
    208213        { 
    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); 
    210215 
    211216        assert(r <= (int)(length-n)); 
     
    21412146 
    21422147    default: 
    2143         fprintf(stderr,"Unexpected aglorithm: %d\n", 
     2148        fprintf(stderr,"Unexpected algorithm: %d\n", 
    21442149                C.secret_key.public_key.algorithm); 
    21452150        ret=0; 
     
    22192224    unsigned k; 
    22202225    const ops_secret_key_t *secret; 
     2226    unsigned char cs[2]; 
     2227    unsigned char* iv; 
    22212228 
    22222229    // Can't rely on it being CAST5 
     
    23452352    // Check checksum 
    23462353 
    2347     unsigned char cs[2]; 
    23482354    ops_calc_session_key_checksum(&C.pk_session_key, &cs[0]); 
    23492355    if (unencoded_m_buf[k+1]!=cs[0] || unencoded_m_buf[k+2]!=cs[1]) 
     
    23592365 
    23602366    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); 
    23622368    pinfo->decrypt.set_iv(&pinfo->decrypt, iv); 
    23632369    pinfo->decrypt.set_key(&pinfo->decrypt,C.pk_session_key.key); 
     
    23792385    */ 
    23802386 
     2387    unsigned int n=0; 
     2388 
    23812389    ops_region_t decrypted_region; 
    23822390 
     
    23892397        ops_hash_t hash; 
    23902398        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; 
    23912410 
    23922411        ops_hash_any(&hash,OPS_HASH_SHA1); 
     
    24042423        if (debug) 
    24052424            { 
     2425            unsigned int i=0; 
    24062426            fprintf(stderr,"\n\nentire SE IP packet (len=%d):\n",decrypted_region.length); 
    2407             unsigned int i=0; 
    24082427            for (i=0; i<decrypted_region.length; i++) 
    24092428                { 
     
    24202439        if (debug) 
    24212440            { 
     2441            unsigned int i=0; 
    24222442            fprintf(stderr,"\npreamble: "); 
    2423             unsigned int i=0; 
    24242443            for (i=0; i<arg->decrypt->blocksize+2;i++) 
    24252444                fprintf(stderr," 0x%02x", buf[i]); 
     
    24272446            } 
    24282447 
    2429         size_t b=arg->decrypt->blocksize; 
     2448        b=arg->decrypt->blocksize; 
    24302449        if(buf[b-2] != buf[b] || buf[b-1] != buf[b+1]) 
    24312450            { 
     
    24382457        // Verify trailing MDC hash 
    24392458 
    2440         size_t sz_preamble=arg->decrypt->blocksize+2; 
    2441         size_t sz_mdc_hash=OPS_SHA1_HASH_SIZE; 
    2442         size_t sz_mdc=1+1+sz_mdc_hash; 
    2443         size_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; 
    24492468     
    24502469        if (debug) 
     
    24952514        } 
    24962515 
    2497     unsigned int n=len; 
     2516    n=len; 
    24982517    if (n > arg->plaintext_available) 
    24992518        n=arg->plaintext_available; 
     
    30133032    if(pinfo->rinfo.destroyer) 
    30143033        pinfo->rinfo.destroyer(&pinfo->rinfo); 
     3034    ops_free_errors(pinfo->errors); 
     3035    if(pinfo->rinfo.accumulated) 
     3036        free(pinfo->rinfo.accumulated); 
    30153037    free(pinfo); 
    30163038    } 
  • openpgpsdk/trunk/src/advanced/adv_symmetric.c

    r501 r516  
    1313#include <openpgpsdk/final.h> 
    1414 
     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 
    1526// \todo there's also a encrypted_arg_t in adv_create.c  
    1627// which is used for *encrypting* whereas this is used 
     
    6677            arg->decrypted_offset+=n; 
    6778            length-=n; 
    68             dest+=n; 
     79#ifdef WIN32 
     80            (char*)dest+=n; 
     81#else 
     82        dest+=n; 
     83#endif 
    6984            } 
    7085        else 
     
    421436    } 
    422437 
    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__))
     438static void tripledes_cfb_encrypt(ops_crypt_t *crypt ATTRIBUTE_UNUSED,void *out ATTRIBUTE_UNUSED,const void *in ATTRIBUTE_UNUSED, size_t count ATTRIBUTE_UNUSED
    424439    {  
    425440    assert(0); 
     
    431446    } 
    432447 
    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__))
     448static void tripledes_cfb_decrypt(ops_crypt_t *crypt ATTRIBUTE_UNUSED,void *out ATTRIBUTE_UNUSED,const void *in ATTRIBUTE_UNUSED, size_t count ATTRIBUTE_UNUSED
    434449    {  
    435450    assert(0); 
     
    514529    { 
    515530    // \todo should there be a separate ops_encrypt_init? 
    516     return ops_decrypt_init(encrypt); 
     531    ops_decrypt_init(encrypt); 
    517532    } 
    518533 
  • openpgpsdk/trunk/src/advanced/adv_util.c

    r457 r516  
    99#include <stdio.h> 
    1010#include <assert.h> 
     11 
     12#ifndef WIN32 
    1113#include <unistd.h> 
     14#endif 
     15 
    1216#include <string.h> 
    1317 
  • openpgpsdk/trunk/src/advanced/adv_writer_encrypt.c

    r511 r516  
    2323    { 
    2424    int debug=0; 
     25 
     26#define BUFSZ 1024 // arbitrary number 
     27    unsigned char encbuf[BUFSZ]; 
     28    unsigned remaining=length; 
     29    unsigned done=0;  
     30 
    2531    crypt_arg_t *arg=(crypt_arg_t *)ops_writer_get_arg(winfo); 
    2632 
     
    2834        assert(0); // \todo proper error handling 
    2935 
    30 #define BUFSZ 1024 // arbitrary number 
    31     //    unsigned char buf[BUFSZ]; 
    32     unsigned char encbuf[BUFSZ]; 
    33     unsigned remaining=length; 
    34     unsigned done=0; 
    3536    while (remaining) 
    3637        { 
     
    4243        if (debug) 
    4344            { 
     45            int i=0; 
    4446            fprintf(stderr,"WRITING:\nunencrypted: "); 
    45             int i=0; 
    4647            for (i=0; i<16; i++) 
    4748                fprintf(stderr,"%2x ", src[done+i]); 
  • openpgpsdk/trunk/src/advanced/adv_writer_encrypt_se_ip.c

    r511 r516  
    44#include <string.h> 
    55#include <assert.h> 
    6 #include <unistd.h> 
     6 
     7#ifndef WIN32 
     8 #include <unistd.h> 
     9#endif 
    710 
    811#include <openssl/cast.h> 
     
    3033                             const ops_key_data_t *pub_key) 
    3134    { 
     35    ops_crypt_t* encrypt; 
     36    unsigned char *iv=NULL; 
     37 
    3238    // Create arg to be used with this writer 
    3339    // Remember to free this in the destroyer 
     
    4046 
    4147    // Setup the arg 
    42     ops_crypt_t* encrypt=ops_mallocz(sizeof *encrypt); 
     48    encrypt=ops_mallocz(sizeof *encrypt); 
    4349    ops_crypt_any(encrypt, encrypted_pk_session_key->symmetric_algorithm); 
    44     unsigned char *iv=NULL; 
    4550    iv=ops_mallocz(encrypt->blocksize); 
    4651    encrypt->set_iv(encrypt, iv); 
     
    110115    int debug=0; 
    111116    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; 
    116122        fprintf(stderr,"ops_calc_mdc_hash():\n"); 
    117123 
    118124        fprintf(stderr,"\npreamble: "); 
    119         unsigned int i=0; 
    120125        for (i=0; i<sz_preamble;i++) 
    121126            fprintf(stderr," 0x%02x", preamble[i]); 
     
    164169    unsigned char hashed[SHA_DIGEST_LENGTH]; 
    165170    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); 
    167172 
    168173    size_t sz_preamble=crypt->blocksize+2; 
     
    170175 
    171176    size_t sz_buf=sz_preamble+len+sz_mdc; 
     177 
     178    ops_memory_t *mem_mdc; 
     179    ops_create_info_t *cinfo_mdc; 
    172180 
    173181#define SE_IP_DATA_VERSION 1 //\todo move this 
     
    184192    if (debug) 
    185193        { 
     194        unsigned int i=0; 
    186195        fprintf(stderr,"\npreamble: "); 
    187         unsigned int i=0; 
    188196        for (i=0; i<sz_preamble;i++) 
    189197            fprintf(stderr," 0x%02x", preamble[i]); 
     
    193201    // now construct MDC packet and add to the end of the buffer 
    194202 
    195     ops_memory_t *mem_mdc; 
    196     ops_create_info_t *cinfo_mdc; 
    197  
    198203    ops_setup_memory_write(&cinfo_mdc, &mem_mdc,sz_mdc); 
    199204 
     
    205210        { 
    206211        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; 
    207215 
    208216        fprintf(stderr,"\nplaintext: "); 
    209         size_t sz_plaintext=len; 
    210217        for (i=0; i<sz_plaintext;i++) 
    211218            fprintf(stderr," 0x%02x", data[i]); 
     
    213220         
    214221        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); 
    217223        for (i=0; i<sz_mdc;i++) 
    218224            fprintf(stderr," 0x%02x", mdc[i]); 
  • openpgpsdk/trunk/src/standard/std_keyring.c

    r487 r516  
    6565#include <stdlib.h> 
    6666#include <string.h> 
    67 #include <unistd.h> 
     67#ifndef WIN32 
     68 #include <unistd.h> 
     69#endif 
    6870 
    6971#include "openpgpsdk/packet.h" 
     
    9698   ops_keyring_free() between these calls, you will introduce a memory leak. 
    9799*/ 
    98 void ops_keyring_read(ops_keyring_t *keyring,const char *file) 
     100ops_boolean_t ops_keyring_read(ops_keyring_t *keyring,const char *file) 
    99101    { 
    100102    ops_parse_info_t *pinfo; 
    101103    int fd; 
     104    ops_boolean_t res = ops_true; 
    102105 
    103106    memset(keyring,'\0',sizeof *keyring); 
     
    111114    ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED); 
    112115 
     116#ifdef WIN32 
     117    fd=open(file,O_RDONLY|O_BINARY); 
     118#else 
    113119    fd=open(file,O_RDONLY); 
     120#endif 
    114121    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        } 
    119127 
    120128    ops_reader_set_fd(pinfo,fd); 
     
    122130    ops_parse_cb_set(pinfo,cb_keyring_read,NULL); 
    123131 
    124     ops_parse_and_accumulate(keyring,pinfo); 
     132    if ( ops_parse_and_accumulate(keyring,pinfo) == 0 ) { 
     133        res = ops_false;  
     134    } 
    125135 
    126136    close(fd); 
    127137 
    128138    ops_parse_info_delete(pinfo); 
     139 
     140    return res; 
    129141    } 
    130142