Changeset 354
- Timestamp:
- 02/02/06 14:21:04
- Files:
-
- openpgpsdk/trunk/examples/packet-dump.c (modified) (1 diff)
- openpgpsdk/trunk/src/packet-parse.c (modified) (5 diffs)
- openpgpsdk/trunk/src/parse_local.h (modified) (2 diffs)
- openpgpsdk/trunk/src/symmetric.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/examples/packet-dump.c
r352 r354 338 338 printf("Symmetric algorithm: %d\n",sk->algorithm); 339 339 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); 342 344 print_hexdump("IV",sk->iv,ops_block_size(sk->algorithm)); 343 345 openpgpsdk/trunk/src/packet-parse.c
r349 r354 306 306 ops_region_t *region,ops_parse_info_t *info) 307 307 { 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); 310 310 } 311 311 … … 462 462 ever need for the buffer is 8192 bytes. */ 463 463 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) 466 470 return 0; 467 471 … … 1958 1962 ops_reader_push_sum16(parse_info); 1959 1963 1964 parse_info->reading_v3_secret=C.secret_key.public_key.version != OPS_V4; 1965 1960 1966 switch(C.secret_key.public_key.algorithm) 1961 1967 { … … 1983 1989 } 1984 1990 1991 parse_info->reading_v3_secret=ops_false; 1992 1985 1993 if(C.secret_key.s2k_usage == OPS_S2KU_ENCRYPTED_AND_HASHED) 1986 1994 { … … 2448 2456 *rinfo=pinfo->rinfo; 2449 2457 pinfo->rinfo.next=rinfo; 2458 rinfo->pinfo=pinfo; 2450 2459 ops_reader_set(pinfo,reader,arg); 2451 2460 } openpgpsdk/trunk/src/parse_local.h
r336 r354 14 14 15 15 ops_reader_info_t *next; 16 ops_parse_info_t *pinfo; /*!< A pointer back to the parent parse_info structure */ 16 17 }; 17 18 … … 58 59 ops_error_t *errors; 59 60 ops_decrypt_t *decrypt; 61 ops_boolean_t reading_v3_secret:1; 62 ops_boolean_t reading_mpi_length:1; 60 63 }; openpgpsdk/trunk/src/symmetric.c
r350 r354 4 4 #include <openssl/cast.h> 5 5 #include <openssl/idea.h> 6 #include "parse_local.h" 6 7 7 8 typedef struct … … 12 13 ops_decrypt_t *decrypt; 13 14 ops_region_t *region; 15 ops_boolean_t prev_read_was_plain:1; 14 16 } encrypted_arg_t; 15 17 … … 26 28 OPS_USED(flags); 27 29 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 28 41 while(length > 0) 29 42 { … … 31 44 { 32 45 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); 33 51 34 52 if(length > arg->decrypted_count) … … 60 78 n=sizeof buffer; 61 79 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 62 85 if(!ops_stacked_limited_read(buffer,n,arg->region,errors,rinfo, 63 86 cbinfo)) 64 87 return OPS_R_EARLY_EOF; 65 88 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 69 100 assert(arg->decrypted_count > 0); 70 101
