Changeset 373

Show
Ignore:
Timestamp:
02/21/06 10:33:23
Author:
ben
Message:

Start handling symmetric encryption.

Files:

Legend:

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

    r371 r373  
    431431        break; 
    432432 
    433     case OPS_PTAG_CT_SE_DATA
     433    case OPS_PTAG_CT_SE_DATA_HEADER
    434434        print_tagname("SYMMETRIC ENCRYPTED DATA"); 
     435        break; 
     436 
     437    case OPS_PTAG_CT_SE_IP_DATA_HEADER: 
     438        print_tagname("SYMMETRIC ENCRYPTED INTEGRITY PROTECTED DATA HEADER"); 
     439        printf("Version: %d\n",content->se_ip_data_header.version); 
     440        break; 
     441 
     442    case OPS_PTAG_CT_SE_IP_DATA_BODY: 
     443        print_tagname("SYMMETRIC ENCRYPTED INTEGRITY PROTECTED DATA BODY"); 
     444        printf("  data body length=%d\n", 
     445               content->se_data_body.length); 
     446        printf("    data="); 
     447        hexdump(content->se_data_body.data, 
     448                content->se_data_body.length); 
     449        printf("\n"); 
    435450        break; 
    436451 
     
    921936        print_hexdump("key ID",content->pk_session_key.key_id, 
    922937                      sizeof content->pk_session_key.key_id); 
    923         printf("Algorithm: %d\n",content->pk_session_key.algorithm); 
     938        printf("Algorithm: %d (%s)\n",content->pk_session_key.algorithm, 
     939               ops_show_symmetric_algorithm(content->pk_session_key.algorithm)); 
    924940        switch(content->pk_session_key.algorithm) 
    925941            { 
  • openpgpsdk/trunk/include/openpgpsdk/crypto.h

    r357 r373  
    8282unsigned ops_key_size(ops_symmetric_algorithm_t alg); 
    8383 
    84 int ops_decrypt_data(ops_region_t *region,ops_parse_info_t *parse_info); 
     84int ops_decrypt_data(ops_content_tag_t tag,ops_region_t *region, 
     85                     ops_parse_info_t *parse_info); 
    8586 
    8687void ops_decrypt_any(ops_decrypt_t *decrypt,ops_symmetric_algorithm_t alg); 
  • openpgpsdk/trunk/include/openpgpsdk/packet.h

    r344 r373  
    137137    OPS_PTAG_CT_RESERVED3               =16,    /*!< reserved */ 
    138138    OPS_PTAG_CT_USER_ATTRIBUTE          =17,    /*!< User Attribute Packet */ 
    139     OPS_PTAG_CT_SK_IP_DATA            =18,    /*!< Sym. Encrypted and Integrity Protected Data Packet */ 
     139    OPS_PTAG_CT_SE_IP_DATA            =18,    /*!< Sym. Encrypted and Integrity Protected Data Packet */ 
    140140    OPS_PTAG_CT_MDC                     =19,    /*!< Modification Detection Code Packet */ 
    141141 
     
    200200    OPS_PTAG_CT_SE_DATA_HEADER          =0x300+11, 
    201201    OPS_PTAG_CT_SE_DATA_BODY            =0x300+12, 
     202    OPS_PTAG_CT_SE_IP_DATA_HEADER       =0x300+13, 
     203    OPS_PTAG_CT_SE_IP_DATA_BODY         =0x300+14, 
    202204 
    203205    /* commands to the callback */ 
     
    834836    char                       **passphrase; /* point somewhere that gets filled in to work around constness of content */ 
    835837    } ops_secret_key_passphrase_t; 
     838 
     839typedef enum 
     840    { 
     841    OPS_SE_IP_V1=1 
     842    } ops_se_ip_version_t; 
     843 
     844typedef struct 
     845    { 
     846    ops_se_ip_version_t         version; 
     847    } ops_se_ip_data_header_t; 
     848 
     849typedef struct 
     850    { 
     851    unsigned                    length; 
     852    unsigned char               data[8192]; 
     853    } ops_se_data_body_t; 
    836854 
    837855/** ops_parser_union_content_t */ 
     
    881899    ops_pk_session_key_t        pk_session_key; 
    882900    ops_secret_key_passphrase_t secret_key_passphrase; 
     901    ops_se_ip_data_header_t     se_ip_data_header; 
     902    ops_se_data_body_t          se_data_body; 
    883903    } ops_parser_content_union_t; 
    884904 
  • openpgpsdk/trunk/src/packet-parse.c

    r372 r373  
    633633    case OPS_PTAG_CT_ARMOUR_TRAILER: 
    634634    case OPS_PTAG_CT_SIGNATURE_HEADER: 
    635     case OPS_PTAG_CT_SE_DATA: 
     635    case OPS_PTAG_CT_SE_DATA_HEADER: 
     636    case OPS_PTAG_CT_SE_IP_DATA_HEADER: 
     637    case OPS_PTAG_CT_SE_IP_DATA_BODY: 
    636638        break; 
    637639 
     
    21062108    } 
    21072109 
     2110// XXX: make this static? 
     2111int ops_decrypt_data(ops_content_tag_t tag,ops_region_t *region, 
     2112                     ops_parse_info_t *pinfo) 
     2113    { 
     2114    int r=1; 
     2115    ops_decrypt_t *decrypt=ops_parse_get_decrypt(pinfo); 
     2116 
     2117    if(decrypt) 
     2118        { 
     2119        ops_reader_push_decrypt(pinfo,decrypt,region); 
     2120        r=ops_parse(pinfo); 
     2121        ops_reader_pop_decrypt(pinfo); 
     2122        } 
     2123    else 
     2124        { 
     2125        ops_parser_content_t content; 
     2126 
     2127        while(region->length_read < region->length) 
     2128            { 
     2129            unsigned l=region->length-region->length_read; 
     2130 
     2131            if(l > sizeof C.se_data_body.data) 
     2132                l=sizeof C.se_data_body.data; 
     2133 
     2134            if(!limited_read(C.se_data_body.data,l,region,pinfo)) 
     2135                return 0; 
     2136 
     2137            C.se_data_body.length=l; 
     2138 
     2139            CBP(pinfo,tag,&content); 
     2140            } 
     2141        } 
     2142 
     2143    return r; 
     2144    } 
     2145 
    21082146static int parse_se_data(ops_region_t *region,ops_parse_info_t *parse_info) 
    21092147    { 
     
    21112149 
    21122150    /* there's no info to go with this, so just announce it */ 
    2113     CBP(parse_info,OPS_PTAG_CT_SE_DATA,&content); 
     2151    CBP(parse_info,OPS_PTAG_CT_SE_DATA_HEADER,&content); 
    21142152 
    21152153    /* The content of an encrypted data packet is more OpenPGP packets 
    2116        once decompressed, so recursively handle them */ 
    2117     return ops_decrypt_data(region,parse_info); 
     2154       once decrypted, so recursively handle them */ 
     2155    return ops_decrypt_data(OPS_PTAG_CT_SE_DATA_BODY,region,parse_info); 
     2156    } 
     2157 
     2158static int parse_se_ip_data(ops_region_t *region,ops_parse_info_t *parse_info) 
     2159    { 
     2160    unsigned char c[1]; 
     2161    ops_parser_content_t content; 
     2162 
     2163    if(!limited_read(c,1,region,parse_info)) 
     2164        return 0; 
     2165    C.se_ip_data_header.version=c[0]; 
     2166    assert(C.se_ip_data_header.version == OPS_SE_IP_V1); 
     2167 
     2168    CBP(parse_info,OPS_PTAG_CT_SE_IP_DATA_HEADER,&content); 
     2169 
     2170    /* The content of an encrypted data packet is more OpenPGP packets 
     2171       once decrypted, so recursively handle them */ 
     2172    return ops_decrypt_data(OPS_PTAG_CT_SE_IP_DATA_BODY,region,parse_info); 
    21182173    } 
    21192174 
     
    22432298        break; 
    22442299 
     2300    case OPS_PTAG_CT_SE_IP_DATA: 
     2301        r=parse_se_ip_data(&region,parse_info); 
     2302        break; 
     2303 
    22452304    default: 
    22462305        format_error(&content,"Format error (unknown content tag %d)", 
  • openpgpsdk/trunk/src/packet-show.c

    r371 r373  
    3939    { OPS_PTAG_CT_RESERVED3,            "reserved" }, 
    4040    { OPS_PTAG_CT_USER_ATTRIBUTE,       "User Attribute" }, 
    41     { OPS_PTAG_CT_SK_IP_DATA,         "Sym. Encrypted and Integrity Protected Data" }, 
     41    { OPS_PTAG_CT_SE_IP_DATA,         "Sym. Encrypted and Integrity Protected Data" }, 
    4242    { OPS_PTAG_CT_MDC,                  "Modification Detection Code" }, 
    4343    { (int) NULL,               (char *)NULL }, /* this is the end-of-array marker */ 
  • openpgpsdk/trunk/src/symmetric.c

    r371 r373  
    130130     
    131131    ops_reader_pop(pinfo); 
    132     } 
    133  
    134 int ops_decrypt_data(ops_region_t *region,ops_parse_info_t *pinfo) 
    135     { 
    136     int r; 
    137  
    138     ops_reader_push_decrypt(pinfo,ops_parse_get_decrypt(pinfo),region); 
    139     r=ops_parse(pinfo); 
    140     ops_reader_pop_decrypt(pinfo); 
    141  
    142     return r; 
    143132    } 
    144133