Changeset 397

Show
Ignore:
Timestamp:
03/03/06 14:45:32
Author:
ben
Message:

Handle one pass signatures.

Files:

Legend:

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

    r394 r397  
    512512        print_unsigned_int("Signature Version", 
    513513               content->signature.version); 
    514         if (content->signature.version == 3)  
    515             print_time("Signature Creation Time", content->signature.creation_time); 
     514        if (content->signature.creation_time_set)  
     515            print_time("Signature Creation Time", 
     516                       content->signature.creation_time); 
    516517 
    517518        print_string_and_value("Signature Type", 
     
    519520                               content->signature.type); 
    520521 
    521         print_hexdump_data("Signer ID", 
    522                       content->signature.signer_id, 
    523                       sizeof content->signature.signer_id); 
     522        if(content->signature.signer_id_set) 
     523            print_hexdump_data("Signer ID", 
     524                               content->signature.signer_id, 
     525                               sizeof content->signature.signer_id); 
    524526 
    525527        print_string_and_value("Public Key Algorithm", 
     
    552554        default: 
    553555            assert(0); 
    554             }     
     556            } 
     557 
     558        if(content->signature.hash) 
     559            printf("data hash is set\n"); 
     560 
    555561        break; 
    556562 
  • openpgpsdk/trunk/examples/verify2.c

    r371 r397  
    6969            } 
    7070 
     71        if(content->signature.hash) 
     72            signed_hash=content->signature.hash; 
     73 
     74        if(!signed_hash) 
     75            { 
     76            fprintf(stderr,"No signature to check!!!\n"); 
     77            exit(3); 
     78            } 
     79 
    7180        if(ops_check_hash_signature(signed_hash,&content->signature, 
    7281                                    ops_get_public_key_from_data(signer))) 
     
    116125        fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag, 
    117126                content_->tag); 
    118         exit(1)
     127        break
    119128        } 
    120129 
  • openpgpsdk/trunk/include/openpgpsdk/crypto.h

    r383 r397  
    99#include "packet-parse.h" 
    1010 
    11 #define OPS_MAX_HASH_SIZE       64 
    1211#define OPS_MIN_HASH_SIZE       16 
    1312 
     
    2120    { 
    2221    ops_hash_algorithm_t algorithm; 
     22    size_t size; 
    2323    const char *name; 
    2424    ops_hash_init_t *init; 
  • openpgpsdk/trunk/include/openpgpsdk/packet-parse.h

    r388 r397  
    127127    }; 
    128128 
    129 void ops_parse_options(ops_parse_info_t *parse_info,ops_content_tag_t tag, 
     129void ops_parse_options(ops_parse_info_t *pinfo,ops_content_tag_t tag, 
    130130                       ops_parse_type_t type); 
    131131 
     
    139139                                       ops_reader_info_t *rinfo, 
    140140                                       ops_parse_cb_info_t *cbinfo); 
     141void ops_parse_hash_init(ops_parse_info_t *pinfo,ops_hash_algorithm_t type, 
     142                         const unsigned char *keyid); 
     143void ops_parse_hash_data(ops_parse_info_t *pinfo,const void *data, 
     144                         size_t length); 
     145void ops_parse_hash_finish(ops_parse_info_t *pinfo); 
     146ops_hash_t *ops_parse_hash_find(ops_parse_info_t *pinfo, 
     147                                const unsigned char keyid[OPS_KEY_ID_SIZE]); 
    141148 
    142149ops_reader_t ops_stacked_read; 
  • openpgpsdk/trunk/include/openpgpsdk/packet.h

    r383 r397  
    429429#define OPS_CHECKHASH_SIZE      20 
    430430 
     431// Max hash size 
     432#define OPS_MAX_HASH_SIZE       64 
     433 
    431434/** ops_secret_key_t 
    432435 */ 
     
    553556    size_t                      v4_hashed_data_start; /* only valid if accumulate is set */ 
    554557    size_t                      v4_hashed_data_length; 
     558    ops_hash_t                  *hash;          /*!< if set, the hash filled in for the data so far */ 
    555559    ops_boolean_t               creation_time_set:1; 
    556560    ops_boolean_t               signer_id_set:1; 
  • openpgpsdk/trunk/src/openssl_crypto.c

    r383 r397  
    3434    } 
    3535 
    36 static ops_hash_t md5={OPS_HASH_MD5,"MD5",md5_init,md5_add,md5_finish,NULL}; 
     36static ops_hash_t md5={OPS_HASH_MD5,MD5_DIGEST_LENGTH,"MD5",md5_init,md5_add, 
     37                       md5_finish,NULL}; 
    3738 
    3839void ops_hash_md5(ops_hash_t *hash) 
     
    6263    } 
    6364 
    64 static ops_hash_t sha1={OPS_HASH_SHA1,"SHA1",sha1_init,sha1_add,sha1_finish
    65                         NULL}; 
     65static ops_hash_t sha1={OPS_HASH_SHA1,SHA_DIGEST_LENGTH,"SHA1",sha1_init
     66                        sha1_add,sha1_finish,NULL}; 
    6667 
    6768void ops_hash_sha1(ops_hash_t *hash) 
  • openpgpsdk/trunk/src/packet-parse.c

    r392 r397  
    12151215        ERR1P(pinfo,"Unconsumed data (%d)",region->length-region->length_read); 
    12161216 
     1217    if(C.signature.signer_id_set) 
     1218        C.signature.hash=ops_parse_hash_find(pinfo,C.signature.signer_id); 
     1219 
    12171220    CBP(pinfo,OPS_PTAG_CT_SIGNATURE,&content); 
    12181221 
     
    17261729    CBP(pinfo,OPS_PTAG_CT_ONE_PASS_SIGNATURE,&content); 
    17271730 
     1731    // XXX: we should, perhaps, let the app choose whether to hash or not 
     1732    ops_parse_hash_init(pinfo,C.one_pass_signature.hash_algorithm, 
     1733                        C.one_pass_signature.keyid); 
     1734 
    17281735    return 1; 
    17291736    } 
     
    18051812 
    18061813        C.literal_data_body.length=l; 
     1814 
     1815        ops_parse_hash_data(pinfo,C.literal_data_body.data,l); 
    18071816 
    18081817        CBP(pinfo,OPS_PTAG_CT_LITERAL_DATA_BODY,&content); 
     
    27152724    } 
    27162725 
     2726void ops_parse_hash_init(ops_parse_info_t *pinfo,ops_hash_algorithm_t type, 
     2727                         const unsigned char *keyid) 
     2728    { 
     2729    ops_parse_hash_info_t *hash; 
     2730 
     2731    pinfo->hashes=realloc(pinfo->hashes, 
     2732                          (pinfo->nhashes+1)*sizeof *pinfo->hashes); 
     2733    hash=&pinfo->hashes[pinfo->nhashes++]; 
     2734 
     2735    ops_hash_any(&hash->hash,type); 
     2736    hash->hash.init(&hash->hash); 
     2737    memcpy(hash->keyid,keyid,sizeof hash->keyid); 
     2738    } 
     2739 
     2740void ops_parse_hash_data(ops_parse_info_t *pinfo,const void *data, 
     2741                         size_t length) 
     2742    { 
     2743    size_t n; 
     2744 
     2745    for(n=0 ; n < pinfo->nhashes ; ++n) 
     2746        pinfo->hashes[n].hash.add(&pinfo->hashes[n].hash,data,length); 
     2747    } 
     2748 
     2749ops_hash_t *ops_parse_hash_find(ops_parse_info_t *pinfo, 
     2750                                const unsigned char keyid[OPS_KEY_ID_SIZE]) 
     2751    { 
     2752    size_t n; 
     2753 
     2754    for(n=0 ; n < pinfo->nhashes ; ++n) 
     2755        if(!memcmp(pinfo->hashes[n].keyid,keyid,OPS_KEY_ID_SIZE)) 
     2756            return &pinfo->hashes[n].hash; 
     2757    return NULL; 
     2758    } 
     2759 
    27172760/* vim:set textwidth=120: */ 
    27182761/* vim:set ts=8: */ 
  • openpgpsdk/trunk/src/parse_local.h

    r392 r397  
    2424    ops_parse_cb_info_t *next; 
    2525    }; 
     26 
     27typedef struct 
     28    { 
     29    ops_hash_t hash; /*!< hashes we should hash data with */ 
     30    unsigned char keyid[OPS_KEY_ID_SIZE]; 
     31    } ops_parse_hash_info_t; 
    2632 
    2733#define NTAGS   0x100 
     
    5965    ops_error_t *errors; 
    6066    ops_decrypt_t decrypt; 
     67    size_t nhashes; 
     68    ops_parse_hash_info_t *hashes; 
    6169    ops_boolean_t reading_v3_secret:1; 
    6270    ops_boolean_t reading_mpi_length:1;