Changeset 354

Show
Ignore:
Timestamp:
02/02/06 14:21:04
Author:
ben
Message:

Partial support for V3 secret keys. Doesn't work yet.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/examples/packet-dump.c

    r352 r354  
    338338    printf("Symmetric algorithm: %d\n",sk->algorithm); 
    339339    printf("Hash algorithm: %d\n",sk->hash_algorithm); 
    340     print_hexdump("Salt",sk->salt,sizeof sk->salt); 
    341     printf("Octet count: %d\n",sk->octet_count); 
     340    if(sk->s2k_specifier != OPS_S2KS_SIMPLE) 
     341        print_hexdump("Salt",sk->salt,sizeof sk->salt); 
     342    if(sk->s2k_specifier == OPS_S2KS_ITERATED_AND_SALTED) 
     343        printf("Octet count: %d\n",sk->octet_count); 
    342344    print_hexdump("IV",sk->iv,ops_block_size(sk->algorithm)); 
    343345 
  • openpgpsdk/trunk/src/packet-parse.c

    r349 r354  
    306306                                  ops_region_t *region,ops_parse_info_t *info) 
    307307    { 
    308     return ops_limited_read(dest,length,region,&info->errors,&info->rinfo, 
    309                             &info->cbinfo); 
     308    return ops_limited_read(dest,length,region,&info->errors, 
     309                            &info->rinfo,&info->cbinfo); 
    310310    } 
    311311 
     
    462462                                ever need for the buffer is 8192 bytes. */ 
    463463    ops_parser_content_t content; 
    464  
    465     if(!limited_read_scalar(&length,2,region,parse_info)) 
     464    ops_boolean_t ret; 
     465 
     466    parse_info->reading_mpi_length=ops_true; 
     467    ret=limited_read_scalar(&length,2,region,parse_info); 
     468    parse_info->reading_mpi_length=ops_false; 
     469    if(!ret) 
    466470        return 0; 
    467471 
     
    19581962        ops_reader_push_sum16(parse_info); 
    19591963 
     1964    parse_info->reading_v3_secret=C.secret_key.public_key.version != OPS_V4; 
     1965 
    19601966    switch(C.secret_key.public_key.algorithm) 
    19611967        { 
     
    19831989        } 
    19841990 
     1991    parse_info->reading_v3_secret=ops_false; 
     1992 
    19851993    if(C.secret_key.s2k_usage == OPS_S2KU_ENCRYPTED_AND_HASHED) 
    19861994        { 
     
    24482456    *rinfo=pinfo->rinfo; 
    24492457    pinfo->rinfo.next=rinfo; 
     2458    rinfo->pinfo=pinfo; 
    24502459    ops_reader_set(pinfo,reader,arg); 
    24512460    } 
  • openpgpsdk/trunk/src/parse_local.h

    r336 r354  
    1414 
    1515    ops_reader_info_t *next; 
     16    ops_parse_info_t *pinfo; /*!< A pointer back to the parent parse_info structure */ 
    1617    }; 
    1718 
     
    5859    ops_error_t *errors; 
    5960    ops_decrypt_t *decrypt; 
     61    ops_boolean_t reading_v3_secret:1; 
     62    ops_boolean_t reading_mpi_length:1; 
    6063    }; 
  • openpgpsdk/trunk/src/symmetric.c

    r350 r354  
    44#include <openssl/cast.h> 
    55#include <openssl/idea.h> 
     6#include "parse_local.h" 
    67 
    78typedef struct 
     
    1213    ops_decrypt_t *decrypt; 
    1314    ops_region_t *region; 
     15    ops_boolean_t prev_read_was_plain:1; 
    1416    } encrypted_arg_t; 
    1517 
     
    2628    OPS_USED(flags); 
    2729 
     30    // V3 MPIs have the count plain and the cipher is reset after each count 
     31    if(arg->prev_read_was_plain && !rinfo->pinfo->reading_mpi_length) 
     32        { 
     33        assert(rinfo->pinfo->reading_v3_secret); 
     34        arg->decrypt->init(arg->decrypt); 
     35        arg->prev_read_was_plain=ops_false; 
     36        } 
     37    else if(rinfo->pinfo->reading_v3_secret 
     38            && rinfo->pinfo->reading_mpi_length) 
     39        arg->prev_read_was_plain=ops_true; 
     40 
    2841    while(length > 0) 
    2942        { 
     
    3144            { 
    3245            unsigned n; 
     46 
     47            // if we are reading v3 we should never read more than 
     48            // we're asked for 
     49            assert(length >= arg->decrypted_count 
     50                   || !rinfo->pinfo->reading_v3_secret); 
    3351 
    3452            if(length > arg->decrypted_count) 
     
    6078                n=sizeof buffer; 
    6179 
     80            // we can only read as much as we're asked for in v3 keys 
     81            // because they're partially unencrypted! 
     82            if(rinfo->pinfo->reading_v3_secret && n > length) 
     83                n=length; 
     84 
    6285            if(!ops_stacked_limited_read(buffer,n,arg->region,errors,rinfo, 
    6386                                         cbinfo)) 
    6487                return OPS_R_EARLY_EOF; 
    6588 
    66             arg->decrypted_count=arg->decrypt->decrypt(arg->decrypt, 
    67                                                        arg->decrypted, 
    68                                                        buffer,n); 
     89            if(!rinfo->pinfo->reading_v3_secret 
     90               || !rinfo->pinfo->reading_mpi_length) 
     91                arg->decrypted_count=arg->decrypt->decrypt(arg->decrypt, 
     92                                                           arg->decrypted, 
     93                                                           buffer,n); 
     94            else 
     95                { 
     96                memcpy(arg->decrypted,buffer,n); 
     97                arg->decrypted_count=n; 
     98                } 
     99 
    69100            assert(arg->decrypted_count > 0); 
    70101