Changeset 397
- Timestamp:
- 03/03/06 14:45:32
- Files:
-
- openpgpsdk/trunk/examples/packet-dump.c (modified) (3 diffs)
- openpgpsdk/trunk/examples/verify2.c (modified) (2 diffs)
- openpgpsdk/trunk/include/openpgpsdk/crypto.h (modified) (2 diffs)
- openpgpsdk/trunk/include/openpgpsdk/packet-parse.h (modified) (2 diffs)
- openpgpsdk/trunk/include/openpgpsdk/packet.h (modified) (2 diffs)
- openpgpsdk/trunk/src/openssl_crypto.c (modified) (2 diffs)
- openpgpsdk/trunk/src/packet-parse.c (modified) (4 diffs)
- openpgpsdk/trunk/src/parse_local.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/examples/packet-dump.c
r394 r397 512 512 print_unsigned_int("Signature Version", 513 513 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); 516 517 517 518 print_string_and_value("Signature Type", … … 519 520 content->signature.type); 520 521 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); 524 526 525 527 print_string_and_value("Public Key Algorithm", … … 552 554 default: 553 555 assert(0); 554 } 556 } 557 558 if(content->signature.hash) 559 printf("data hash is set\n"); 560 555 561 break; 556 562 openpgpsdk/trunk/examples/verify2.c
r371 r397 69 69 } 70 70 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 71 80 if(ops_check_hash_signature(signed_hash,&content->signature, 72 81 ops_get_public_key_from_data(signer))) … … 116 125 fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag, 117 126 content_->tag); 118 exit(1);127 break; 119 128 } 120 129 openpgpsdk/trunk/include/openpgpsdk/crypto.h
r383 r397 9 9 #include "packet-parse.h" 10 10 11 #define OPS_MAX_HASH_SIZE 6412 11 #define OPS_MIN_HASH_SIZE 16 13 12 … … 21 20 { 22 21 ops_hash_algorithm_t algorithm; 22 size_t size; 23 23 const char *name; 24 24 ops_hash_init_t *init; openpgpsdk/trunk/include/openpgpsdk/packet-parse.h
r388 r397 127 127 }; 128 128 129 void ops_parse_options(ops_parse_info_t *p arse_info,ops_content_tag_t tag,129 void ops_parse_options(ops_parse_info_t *pinfo,ops_content_tag_t tag, 130 130 ops_parse_type_t type); 131 131 … … 139 139 ops_reader_info_t *rinfo, 140 140 ops_parse_cb_info_t *cbinfo); 141 void ops_parse_hash_init(ops_parse_info_t *pinfo,ops_hash_algorithm_t type, 142 const unsigned char *keyid); 143 void ops_parse_hash_data(ops_parse_info_t *pinfo,const void *data, 144 size_t length); 145 void ops_parse_hash_finish(ops_parse_info_t *pinfo); 146 ops_hash_t *ops_parse_hash_find(ops_parse_info_t *pinfo, 147 const unsigned char keyid[OPS_KEY_ID_SIZE]); 141 148 142 149 ops_reader_t ops_stacked_read; openpgpsdk/trunk/include/openpgpsdk/packet.h
r383 r397 429 429 #define OPS_CHECKHASH_SIZE 20 430 430 431 // Max hash size 432 #define OPS_MAX_HASH_SIZE 64 433 431 434 /** ops_secret_key_t 432 435 */ … … 553 556 size_t v4_hashed_data_start; /* only valid if accumulate is set */ 554 557 size_t v4_hashed_data_length; 558 ops_hash_t *hash; /*!< if set, the hash filled in for the data so far */ 555 559 ops_boolean_t creation_time_set:1; 556 560 ops_boolean_t signer_id_set:1; openpgpsdk/trunk/src/openssl_crypto.c
r383 r397 34 34 } 35 35 36 static ops_hash_t md5={OPS_HASH_MD5,"MD5",md5_init,md5_add,md5_finish,NULL}; 36 static ops_hash_t md5={OPS_HASH_MD5,MD5_DIGEST_LENGTH,"MD5",md5_init,md5_add, 37 md5_finish,NULL}; 37 38 38 39 void ops_hash_md5(ops_hash_t *hash) … … 62 63 } 63 64 64 static ops_hash_t sha1={OPS_HASH_SHA1, "SHA1",sha1_init,sha1_add,sha1_finish,65 NULL};65 static ops_hash_t sha1={OPS_HASH_SHA1,SHA_DIGEST_LENGTH,"SHA1",sha1_init, 66 sha1_add,sha1_finish,NULL}; 66 67 67 68 void ops_hash_sha1(ops_hash_t *hash) openpgpsdk/trunk/src/packet-parse.c
r392 r397 1215 1215 ERR1P(pinfo,"Unconsumed data (%d)",region->length-region->length_read); 1216 1216 1217 if(C.signature.signer_id_set) 1218 C.signature.hash=ops_parse_hash_find(pinfo,C.signature.signer_id); 1219 1217 1220 CBP(pinfo,OPS_PTAG_CT_SIGNATURE,&content); 1218 1221 … … 1726 1729 CBP(pinfo,OPS_PTAG_CT_ONE_PASS_SIGNATURE,&content); 1727 1730 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 1728 1735 return 1; 1729 1736 } … … 1805 1812 1806 1813 C.literal_data_body.length=l; 1814 1815 ops_parse_hash_data(pinfo,C.literal_data_body.data,l); 1807 1816 1808 1817 CBP(pinfo,OPS_PTAG_CT_LITERAL_DATA_BODY,&content); … … 2715 2724 } 2716 2725 2726 void 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 2740 void 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 2749 ops_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 2717 2760 /* vim:set textwidth=120: */ 2718 2761 /* vim:set ts=8: */ openpgpsdk/trunk/src/parse_local.h
r392 r397 24 24 ops_parse_cb_info_t *next; 25 25 }; 26 27 typedef 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; 26 32 27 33 #define NTAGS 0x100 … … 59 65 ops_error_t *errors; 60 66 ops_decrypt_t decrypt; 67 size_t nhashes; 68 ops_parse_hash_info_t *hashes; 61 69 ops_boolean_t reading_v3_secret:1; 62 70 ops_boolean_t reading_mpi_length:1;
