diff options
author | Werner Koch <[email protected]> | 2019-09-27 11:51:52 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2019-09-27 11:51:52 +0000 |
commit | 0af1c6447dc0f981ab7306e3bef520f37aded167 (patch) | |
tree | d5bd0cd69bc8a42fc011cdebd1dd05c6fd0e081a /kbx/keybox-search.c | |
parent | kbx,gpg: Allow lookup using a UBID. (diff) | |
download | gnupg-0af1c6447dc0f981ab7306e3bef520f37aded167.tar.gz gnupg-0af1c6447dc0f981ab7306e3bef520f37aded167.zip |
kbx: Store the UBIB in the blob.
* kbx/keybox-blob.c (create_blob_header): New blob flag UBIB.
(create_blob_finish): Write the UBIB.
* kbx/keybox-dump.c (print_ubib): New.
(_keybox_dump_blob): Print UBIB flag.
* kbx/keybox-search.c (has_ubid): Compare the stored UBIB if
available.
--
This make scanning the keybox for a given UBIB much faster once it has
been stored.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'kbx/keybox-search.c')
-rw-r--r-- | kbx/keybox-search.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/kbx/keybox-search.c b/kbx/keybox-search.c index cb763cf5f..95ad07251 100644 --- a/kbx/keybox-search.c +++ b/kbx/keybox-search.c @@ -707,14 +707,23 @@ has_ubid (KEYBOXBLOB blob, const unsigned char *ubid) buffer = _keybox_get_blob_image (blob, &length); if (length < 40) return 0; /*GPG_ERR_TOO_SHORT*/ - image_off = get32 (buffer+8); - image_len = get32 (buffer+12); - if ((uint64_t)image_off+(uint64_t)image_len > (uint64_t)length) - return 0; /*GPG_ERR_TOO_SHORT*/ - - gcry_md_hash_buffer (GCRY_MD_SHA1, ubid_blob, buffer + image_off, image_len); - return !memcmp (ubid, ubid_blob, 20); + if ((get16 (buffer + 6) & 4)) + { + /* The blob has a stored UBID. */ + return !memcmp (ubid, buffer + length - 40, 20); + } + else + { + /* Need to compute the UBID. */ + image_off = get32 (buffer+8); + image_len = get32 (buffer+12); + if ((uint64_t)image_off+(uint64_t)image_len > (uint64_t)length) + return 0; /*GPG_ERR_TOO_SHORT*/ + + gcry_md_hash_buffer (GCRY_MD_SHA1, ubid_blob, buffer+image_off,image_len); + return !memcmp (ubid, ubid_blob, 20); + } } static inline int |