Changeset 667

Show
Ignore:
Timestamp:
08/01/09 14:26:33
Author:
ben
Message:

Fix indentation. More consistent layout.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/src/lib/crypto.c

    r625 r667  
    4242\note only RSA at present 
    4343*/ 
    44 int ops_decrypt_and_unencode_mpi(unsigned char *buf,unsigned buflen,const BIGNUM *encmpi, 
    45                     const ops_secret_key_t *skey) 
     44int ops_decrypt_and_unencode_mpi(unsigned char *buf,unsigned buflen, 
     45                                 const BIGNUM *encmpi, 
     46                                 const ops_secret_key_t *skey) 
    4647    { 
    4748    unsigned char encmpibuf[8192]; 
     
    5455    /* MPI can't be more than 65,536 */ 
    5556    assert(mpisize <= sizeof encmpibuf); 
    56     BN_bn2bin(encmpi,encmpibuf); 
     57    BN_bn2bin(encmpi, encmpibuf); 
    5758 
    5859    assert(skey->public_key.algorithm == OPS_PKA_RSA); 
     
    6667    */ 
    6768 
    68     n=ops_rsa_private_decrypt(mpibuf,encmpibuf,(BN_num_bits(encmpi)+7)/8, 
    69                               &skey->key.rsa,&skey->public_key.key.rsa); 
    70     assert(n!=-1); 
     69    n=ops_rsa_private_decrypt(mpibuf, encmpibuf, (BN_num_bits(encmpi)+7)/8, 
     70                              &skey->key.rsa, &skey->public_key.key.rsa); 
     71    assert(n != -1); 
    7172 
    7273    /* 
     
    103104    // this is the unencoded m buf 
    104105    if((unsigned)(n-i) <= buflen) 
    105         memcpy(buf,mpibuf+i,n-i); 
     106        memcpy(buf, mpibuf+i, n-i); 
    106107 
    107108    /* 
     
    121122*/ 
    122123ops_boolean_t ops_rsa_encrypt_mpi(const unsigned char *encoded_m_buf, 
    123                               const size_t sz_encoded_m_buf, 
    124                               const ops_public_key_t *pkey, 
    125                               ops_pk_session_key_parameters_t *skp) 
     124                                 const size_t sz_encoded_m_buf, 
     125                                 const ops_public_key_t *pkey, 
     126                                 ops_pk_session_key_parameters_t *skp) 
    126127    { 
    127128    assert(sz_encoded_m_buf==(size_t) BN_num_bytes(pkey->key.rsa.n)); 
     
    130131    int n=0; 
    131132 
    132     n=ops_rsa_public_encrypt(encmpibuf, encoded_m_buf, sz_encoded_m_buf, &pkey->key.rsa); 
     133    n=ops_rsa_public_encrypt(encmpibuf, encoded_m_buf, sz_encoded_m_buf, 
     134                             &pkey->key.rsa); 
    133135    assert(n!=-1); 
    134136 
     
    152154 
    153155static ops_parse_cb_return_t 
    154 callback_write_parsed(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 
     156callback_write_parsed(const ops_parser_content_t *content_, 
     157                      ops_parse_cb_info_t *cbinfo); 
    155158 
    156159/** 
     
    164167\return ops_true if OK; else ops_false 
    165168*/ 
    166 ops_boolean_t ops_encrypt_file(const char* input_filename, const char* output_filename, const ops_keydata_t *pub_key, const ops_boolean_t use_armour, const ops_boolean_t allow_overwrite) 
     169ops_boolean_t ops_encrypt_file(const char* input_filename, 
     170                               const char* output_filename, 
     171                               const ops_keydata_t *pub_key, 
     172                               const ops_boolean_t use_armour, 
     173                               const ops_boolean_t allow_overwrite) 
    167174    { 
    168175    int fd_in=0; 
     
    191198 
    192199    // Push the encrypted writer 
    193     ops_writer_push_encrypt_se_ip(cinfo,pub_key); 
     200    ops_writer_push_encrypt_se_ip(cinfo, pub_key); 
    194201 
    195202    // Do the writing 
     
    200207    for (;;) 
    201208        { 
    202         buf=realloc(buf,done+bufsz); 
     209        buf=realloc(buf, done+bufsz); 
    203210         
    204             int n=0; 
    205  
    206             n=read(fd_in,buf+done,bufsz); 
    207             if (!n) 
    208                     break; 
    209             assert(n>=0); 
     211        int n=0; 
     212 
     213        n=read(fd_in,buf+done,bufsz); 
     214        if (!n) 
     215            break; 
     216        assert(n>=0); 
     217 
    210218        done+=n; 
    211219        } 
    212220 
    213221    // This does the writing 
    214     ops_write(buf,done,cinfo); 
     222    ops_write(buf, done, cinfo); 
    215223 
    216224    // tidy up 
    217225    close(fd_in); 
    218226    free(buf); 
    219     ops_teardown_file_write(cinfo,fd_out); 
     227    ops_teardown_file_write(cinfo, fd_out); 
    220228 
    221229    return ops_true; 
     
    233241*/ 
    234242 
    235 ops_boolean_t ops_decrypt_file(const char* input_filename, const char* output_filename, ops_keyring_t* keyring, const ops_boolean_t use_armour, const ops_boolean_t allow_overwrite, ops_parse_cb_t* cb_get_passphrase) 
     243ops_boolean_t ops_decrypt_file(const char* input_filename, 
     244                               const char* output_filename, 
     245                               ops_keyring_t* keyring, 
     246                               const ops_boolean_t use_armour, 
     247                               const ops_boolean_t allow_overwrite, 
     248                               ops_parse_cb_t* cb_get_passphrase) 
    236249    { 
    237250    int fd_in=0; 
     
    244257    // setup for reading from given input file 
    245258    fd_in=ops_setup_file_read(&pinfo, input_filename,  
    246                         NULL, 
    247                         callback_write_parsed, 
    248                         ops_false); 
     259                             NULL, 
     260                             callback_write_parsed, 
     261                             ops_false); 
    249262    if (fd_in < 0) 
    250263        { 
     
    257270    if (output_filename) 
    258271        { 
    259         fd_out=ops_setup_file_write(&pinfo->cbinfo.cinfo, output_filename, allow_overwrite); 
     272        fd_out=ops_setup_file_write(&pinfo->cbinfo.cinfo, output_filename, 
     273                                    allow_overwrite); 
    260274 
    261275        if (fd_out < 0) 
     
    270284        int suffixlen=4; 
    271285        char *defaultsuffix=".decrypted"; 
    272         const char *suffix=input_filename+strlen((char *)input_filename)-suffixlen; 
     286        const char *suffix=input_filename+strlen((char *)input_filename) 
     287            -suffixlen; 
    273288        if (!strcmp(suffix,".gpg") || !strcmp(suffix,".asc")) 
    274289            { 
    275290            myfilename=ops_mallocz(strlen(input_filename)-suffixlen+1); 
    276             strncpy(myfilename,input_filename,strlen(input_filename)-suffixlen); 
     291            strncpy(myfilename, input_filename, 
     292                    strlen(input_filename)-suffixlen); 
    277293            } 
    278294        else 
     
    280296            unsigned filenamelen=strlen(input_filename)+strlen(defaultsuffix)+1; 
    281297            myfilename=ops_mallocz(filenamelen); 
    282             snprintf(myfilename,filenamelen,"%s%s",input_filename,defaultsuffix); 
     298            snprintf(myfilename, filenamelen, "%s%s", input_filename, 
     299                     defaultsuffix); 
    283300            } 
    284301 
    285         fd_out=ops_setup_file_write(&pinfo->cbinfo.cinfo, myfilename, allow_overwrite); 
     302        fd_out=ops_setup_file_write(&pinfo->cbinfo.cinfo, myfilename, 
     303                                    allow_overwrite); 
    286304         
    287305        if (fd_out < 0) 
     
    289307            perror(myfilename);  
    290308            free(myfilename); 
    291             ops_teardown_file_read(pinfo,fd_in); 
     309            ops_teardown_file_read(pinfo, fd_in); 
    292310            return ops_false; 
    293311            } 
     
    326344 
    327345static ops_parse_cb_return_t 
    328 callback_write_parsed(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 
     346callback_write_parsed(const ops_parser_content_t *content_, 
     347                      ops_parse_cb_info_t *cbinfo) 
    329348    { 
    330     ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 
     349    ops_parser_content_union_t* content 
     350        =(ops_parser_content_union_t *)&content_->content; 
    331351    static ops_boolean_t skipping; 
    332352    //    ops_boolean_t write=ops_true; 
     
    351371            skipping=ops_true; 
    352372            } 
    353         fwrite(content->unarmoured_text.data,1, 
    354                content->unarmoured_text.length,stdout); 
     373        fwrite(content->unarmoured_text.data, 1, 
     374               content->unarmoured_text.length, stdout); 
    355375        break; 
    356376 
    357377    case OPS_PTAG_CT_PK_SESSION_KEY: 
    358         return callback_pk_session_key(content_,cbinfo); 
     378        return callback_pk_session_key(content_, cbinfo); 
    359379        break; 
    360380 
    361381    case OPS_PARSER_CMD_GET_SECRET_KEY: 
    362         return callback_cmd_get_secret_key(content_,cbinfo); 
     382        return callback_cmd_get_secret_key(content_, cbinfo); 
    363383        break; 
    364384 
    365385    case OPS_PARSER_CMD_GET_SK_PASSPHRASE: 
    366386        //        return callback_cmd_get_secret_key_passphrase(content_,cbinfo); 
    367         return cbinfo->cryptinfo.cb_get_passphrase(content_,cbinfo); 
     387        return cbinfo->cryptinfo.cb_get_passphrase(content_, cbinfo); 
    368388        break; 
    369389 
    370390    case OPS_PTAG_CT_LITERAL_DATA_BODY: 
    371         return callback_literal_data(content_,cbinfo); 
    372                break; 
     391        return callback_literal_data(content_, cbinfo); 
     392        break; 
    373393 
    374394    case OPS_PTAG_CT_ARMOUR_HEADER: