From cb041d0305b8aeda8130f1febd7c31dd269ea83a Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 18 May 2025 20:31:33 +0200 Subject: [PATCH] Rename hash2 -> hash. Now that sha1 is no longer supported, the hash2 naming has become meaningless. Rename it back to "hash". --- aft.c | 46 +++++++++++++++++++++++----------------------- client_common.c | 8 ++++---- command.c | 8 ++++---- crypt.h | 22 +++++++++++----------- crypt_common.c | 10 +++++----- gcrypt.c | 4 ++-- openssl.c | 2 +- 7 files changed, 50 insertions(+), 50 deletions(-) diff --git a/aft.c b/aft.c index 89739356..a9145f2c 100644 --- a/aft.c +++ b/aft.c @@ -42,7 +42,7 @@ struct ls_data { */ static struct osl_table *audio_file_table; /* NULL if table not open */ static struct osl_row *current_aft_row; /* NULL if no audio file open */ -static unsigned char current_hash[HASH2_SIZE]; /* only used on sighup */ +static unsigned char current_hash[HASH_SIZE]; /* only used on sighup */ static char *status_items; static char *parser_friendly_status_items; @@ -216,7 +216,7 @@ enum audio_file_table_columns { static int aft_hash_compare(const struct osl_object *obj1, const struct osl_object *obj2) { - return hash2_compare((unsigned char *)obj1->data, + return hash_compare((unsigned char *)obj1->data, (unsigned char *)obj2->data); } @@ -226,7 +226,7 @@ static struct osl_column_description aft_cols[] = { .storage_flags = OSL_RBTREE | OSL_FIXED_SIZE | OSL_UNIQUE, .name = "hash", .compare_function = aft_hash_compare, - .data_size = HASH2_SIZE + .data_size = HASH_SIZE }, [AFTCOL_PATH] = { .storage_type = OSL_MAPPED_STORAGE, @@ -442,7 +442,7 @@ int aft_get_row_of_path(const char *path, struct osl_row **row) */ static int aft_get_row_of_hash(unsigned char *hash, struct osl_row **row) { - const struct osl_object obj = {.data = hash, .size = HASH2_SIZE}; + const struct osl_object obj = {.data = hash, .size = HASH_SIZE}; return osl(osl_get_row(audio_file_table, AFTCOL_HASH, &obj, row)); } @@ -843,7 +843,7 @@ static int print_list_item(struct ls_data *d, struct ls_options *opts, char duration_buf[30]; /* nobody has an audio file long enough to overflow this */ struct afs_info *afsi = &d->afsi; struct afh_info *afhi = &d->afhi; - char asc_hash[2 * HASH2_SIZE + 1]; + char asc_hash[2 * HASH_SIZE + 1]; if (opts->mode == LS_MODE_SHORT) { para_printf(b, "%s\n", d->path); @@ -914,7 +914,7 @@ static int print_list_item(struct ls_data *d, struct ls_options *opts, return ret; write_image_items(b, afsi); write_lyrics_items(b, afsi); - hash2_to_asc(d->hash, asc_hash); + hash_to_asc(d->hash, asc_hash); WRITE_STATUS_ITEM(b, SI_hash, "%s\n", asc_hash); WRITE_STATUS_ITEM(b, SI_bitrate, "%dkbit/s\n", afhi->bitrate); WRITE_STATUS_ITEM(b, SI_format, "%s\n", @@ -1041,7 +1041,7 @@ out: */ int open_and_update_audio_file(int *fd) { - unsigned char file_hash[HASH2_SIZE]; + unsigned char file_hash[HASH_SIZE]; struct osl_object afsi_obj; struct afs_info new_afsi; int ret; @@ -1067,8 +1067,8 @@ again: if (ret < 0) return ret; if (!d->hash) - d->hash = alloc(HASH2_SIZE); - memcpy(d->hash, tmp_hash, HASH2_SIZE); + d->hash = alloc(HASH_SIZE); + memcpy(d->hash, tmp_hash, HASH_SIZE); free(d->path); ret = get_audio_file_path_of_row(current_aft_row, &d->path); if (ret < 0) @@ -1101,8 +1101,8 @@ again: ret = mmap_full_file(d->path, O_RDONLY, &map.data, &map.size, fd); if (ret < 0) goto out; - hash2_function(map.data, map.size, file_hash); - ret = hash2_compare(file_hash, d->hash); + hash_function(map.data, map.size, file_hash); + ret = hash_compare(file_hash, d->hash); para_munmap(map.data, map.size); if (ret) { ret = -E_HASH_MISMATCH; @@ -1141,7 +1141,7 @@ out: static int ls_hash_compare(const void *a, const void *b) { struct ls_data *d1 = *(struct ls_data **)a, *d2 = *(struct ls_data **)b; - return memcmp(d1->hash, d2->hash, HASH2_SIZE); + return memcmp(d1->hash, d2->hash, HASH_SIZE); } static int ls_audio_format_compare(const void *a, const void *b) @@ -1573,7 +1573,7 @@ enum com_add_buffer_offsets { /** The hash of the audio file being added. */ CAB_HASH_OFFSET = 13, /** Start of the path of the audio file. */ - CAB_PATH_OFFSET = (CAB_HASH_OFFSET + HASH2_SIZE), + CAB_PATH_OFFSET = (CAB_HASH_OFFSET + HASH_SIZE), }; /* @@ -1596,7 +1596,7 @@ static void save_add_callback_buffer(unsigned char *hash, const char *path, assert(size <= ~(uint32_t)0); write_u8(buf + CAB_AUDIO_FORMAT_ID_OFFSET, audio_format_num); - memcpy(buf + CAB_HASH_OFFSET, hash, HASH2_SIZE); + memcpy(buf + CAB_HASH_OFFSET, hash, HASH_SIZE); strcpy(buf + CAB_PATH_OFFSET, path); pos = CAB_PATH_OFFSET + path_len; write_u32(buf + CAB_AFHI_OFFSET_POS, pos); @@ -1672,7 +1672,7 @@ static int com_add_callback(struct afs_callback_arg *aca) struct osl_row *hs; struct osl_object objs[NUM_AFT_COLUMNS]; unsigned char *hash; - char asc[2 * HASH2_SIZE + 1]; + char asc[2 * HASH_SIZE + 1]; int ret; char afsi_buf[AFSI_SIZE]; uint32_t slpr_offset = read_u32(buf + CAB_LPR_OFFSET); @@ -1688,9 +1688,9 @@ static int com_add_callback(struct afs_callback_arg *aca) r_v = SERVER_CMD_OPT_RESULT(ADD, VERBOSE, aca->lpr); hash = (unsigned char *)buf + CAB_HASH_OFFSET; - hash2_to_asc(hash, asc); + hash_to_asc(hash, asc); objs[AFTCOL_HASH].data = buf + CAB_HASH_OFFSET; - objs[AFTCOL_HASH].size = HASH2_SIZE; + objs[AFTCOL_HASH].size = HASH_SIZE; path = buf + CAB_PATH_OFFSET; objs[AFTCOL_PATH].data = path; @@ -1754,12 +1754,12 @@ static int com_add_callback(struct afs_callback_arg *aca) objs[AFTCOL_CHUNKS].data = buf + chunks_offset; objs[AFTCOL_CHUNKS].size = slpr_offset - chunks_offset; if (pb && !hs) { /* update pb's hash */ - char old_asc[2 * HASH2_SIZE + 1]; + char old_asc[2 * HASH_SIZE + 1]; unsigned char *old_hash; ret = get_hash_of_row(pb, &old_hash); if (ret < 0) goto out; - hash2_to_asc(old_hash, old_asc); + hash_to_asc(old_hash, old_asc); if (lls_opt_given(r_v)) para_printf(&aca->pbout, "file change: %s -> %s\n", old_asc, asc); @@ -1859,7 +1859,7 @@ static int add_one_audio_file(const char *path, void *private_data) struct afh_info afhi, *afhi_ptr = NULL; struct osl_row *pb = NULL, *hs = NULL; /* path brother/hash sister */ struct osl_object map, obj = {.data = NULL}, query; - unsigned char hash[HASH2_SIZE]; + unsigned char hash[HASH_SIZE]; bool a_given = SERVER_CMD_OPT_GIVEN(ADD, ALL, pad->lpr); bool f_given = SERVER_CMD_OPT_GIVEN(ADD, FORCE, pad->lpr); bool l_given = SERVER_CMD_OPT_GIVEN(ADD, LAZY, pad->lpr); @@ -1887,11 +1887,11 @@ static int add_one_audio_file(const char *path, void *private_data) ret = mmap_full_file(path, O_RDONLY, &map.data, &map.size, &fd); if (ret < 0) goto out_free; - hash2_function(map.data, map.size, hash); + hash_function(map.data, map.size, hash); /* Check whether the database contains a file with the same hash. */ query.data = hash; - query.size = HASH2_SIZE; + query.size = HASH_SIZE; ret = send_callback_request(hash_sister_callback, &query, get_row_pointer_from_result, &hs); if (ret < 0) @@ -2595,7 +2595,7 @@ static void aft_close(void) PARA_WARNING_LOG("hash lookup failure\n"); current_aft_row = NULL; } else - memcpy(current_hash, p, HASH2_SIZE); + memcpy(current_hash, p, HASH_SIZE); } osl_close_table(audio_file_table, OSL_MARK_CLEAN); audio_file_table = NULL; diff --git a/client_common.c b/client_common.c index 8542a010..8b28b294 100644 --- a/client_common.c +++ b/client_common.c @@ -330,10 +330,10 @@ static int client_post_monitor(struct sched *s, void *context) ret = -E_DECRYPT; goto out; } - ct->challenge_hash = alloc(HASH2_SIZE); - hash2_function((char *)crypt_buf, APC_CHALLENGE_SIZE, + ct->challenge_hash = alloc(HASH_SIZE); + hash_function((char *)crypt_buf, APC_CHALLENGE_SIZE, ct->challenge_hash); - hash2_to_asc(ct->challenge_hash, buf); + hash_to_asc(ct->challenge_hash, buf); ct->scc.send = sc_new(crypt_buf + APC_CHALLENGE_SIZE, SESSION_KEY_LEN); ct->scc.recv = sc_new(crypt_buf + APC_CHALLENGE_SIZE @@ -344,7 +344,7 @@ static int client_post_monitor(struct sched *s, void *context) return 0; } case CL_RECEIVED_CHALLENGE: - ret = send_sb(ct, 0, ct->challenge_hash, HASH2_SIZE, + ret = send_sb(ct, 0, ct->challenge_hash, HASH_SIZE, SBD_CHALLENGE_RESPONSE, false); if (ret != 0) ct->challenge_hash = NULL; diff --git a/command.c b/command.c index 4139c8cb..35111656 100644 --- a/command.c +++ b/command.c @@ -913,7 +913,7 @@ int handle_connect(int fd) { int ret; unsigned char rand_buf[APC_CHALLENGE_SIZE + 2 * SESSION_KEY_LEN]; - unsigned char challenge_hash[HASH2_SIZE]; + unsigned char challenge_hash[HASH_SIZE]; char *command = NULL, *buf = NULL, hsbuf[HANDSHAKE_BUFSIZE]; unsigned char *crypt_buf; size_t numbytes; @@ -977,10 +977,10 @@ int handle_connect(int fd) * of the random data. */ ret = -E_BAD_AUTH; - if (numbytes != HASH2_SIZE) + if (numbytes != HASH_SIZE) goto net_err; - hash2_function((char *)rand_buf, APC_CHALLENGE_SIZE, challenge_hash); - if (memcmp(challenge_hash, buf, HASH2_SIZE)) + hash_function((char *)rand_buf, APC_CHALLENGE_SIZE, challenge_hash); + if (memcmp(challenge_hash, buf, HASH_SIZE)) goto net_err; /* auth successful */ alarm(0); diff --git a/crypt.h b/crypt.h index 27da9aa3..8ddf2b55 100644 --- a/crypt.h +++ b/crypt.h @@ -163,35 +163,35 @@ _static_inline_ void sc_trafo(struct iovec *src, struct iovec *dst, void sc_free(struct stream_cipher *sc); /** Size of the hash value in bytes. */ -#define HASH2_SIZE 32 +#define HASH_SIZE 32 /** - * Compute the hash2 of the given input data. + * Compute the hash of the given input data. * * \param data Pointer to the data to compute the hash value from. * \param len The length of \a data in bytes. * \param hash Result pointer. * - * \a hash must point to an area at least \p HASH2_SIZE bytes large. + * \a hash must point to an area at least HASH_SIZE bytes large. * * \sa sha(3), openssl(1). * */ -void hash2_function(const char *data, unsigned long len, unsigned char *hash); +void hash_function(const char *data, unsigned long len, unsigned char *hash); /** - * Convert a hash2 value to ascii format. + * Convert a hash value to ascii format. * * \param hash the hash value. * \param asc Result pointer. * - * \a asc must point to an area of at least 2 * \p HASH2_SIZE + 1 bytes which - * will be filled by the function with the ascii representation of the hash - * value given by \a hash, and a terminating \p NULL byte. + * The result pointer must point to an area of at least 2 * HASH_SIZE + 1 + * bytes which will be filled by the function with the ascii representation + * of the hash value given by hash, and a terminating NUL byte. */ -void hash2_to_asc(const unsigned char *hash, char *asc); +void hash_to_asc(const unsigned char *hash, char *asc); /** - * Compare two version 2 hashes. + * Compare two hashes. * * \param h1 Pointer to the first hash value. * \param h2 Pointer to the second hash value. @@ -199,4 +199,4 @@ void hash2_to_asc(const unsigned char *hash, char *asc); * \return 1, -1, or zero, depending on whether \a h1 is greater than, * less than or equal to h2, respectively. */ -int hash2_compare(const unsigned char *h1, const unsigned char *h2); +int hash_compare(const unsigned char *h1, const unsigned char *h2); diff --git a/crypt_common.c b/crypt_common.c index dbd63b50..9b78f360 100644 --- a/crypt_common.c +++ b/crypt_common.c @@ -133,23 +133,23 @@ int check_private_key_file(const char *file) return 1; } -void hash2_to_asc(const unsigned char *hash, char *asc) +void hash_to_asc(const unsigned char *hash, char *asc) { int i; const char hexchar[] = "0123456789abcdef"; - for (i = 0; i < HASH2_SIZE; i++) { + for (i = 0; i < HASH_SIZE; i++) { asc[2 * i] = hexchar[hash[i] >> 4]; asc[2 * i + 1] = hexchar[hash[i] & 0xf]; } - asc[2 * HASH2_SIZE] = '\0'; + asc[2 * HASH_SIZE] = '\0'; } -int hash2_compare(const unsigned char *h1, const unsigned char *h2) +int hash_compare(const unsigned char *h1, const unsigned char *h2) { int i; - for (i = 0; i < HASH2_SIZE; i++) { + for (i = 0; i < HASH_SIZE; i++) { if (h1[i] < h2[i]) return -1; if (h1[i] > h2[i]) diff --git a/gcrypt.c b/gcrypt.c index 5eca71ef..17c048ea 100644 --- a/gcrypt.c +++ b/gcrypt.c @@ -29,7 +29,7 @@ static void dump_buffer(const char *msg, unsigned char *buf, int len) #define dump_buffer(a, b, c) #endif -void hash2_function(const char *data, unsigned long len, unsigned char *hash) +void hash_function(const char *data, unsigned long len, unsigned char *hash) { gcry_error_t gret; gcry_md_hd_t handle; @@ -41,7 +41,7 @@ void hash2_function(const char *data, unsigned long len, unsigned char *hash) gcry_md_final(handle); md = gcry_md_read(handle, GCRY_MD_SHA256); assert(md); - memcpy(hash, md, HASH2_SIZE); + memcpy(hash, md, HASH_SIZE); gcry_md_close(handle); } diff --git a/openssl.c b/openssl.c index 34e42886..4fc836d3 100644 --- a/openssl.c +++ b/openssl.c @@ -519,7 +519,7 @@ void sc_crypt(struct stream_cipher *sc, struct iovec *src, struct iovec *dst) return aes_ctr128_crypt(sc->aes, src, dst); } -void hash2_function(const char *data, unsigned long len, unsigned char *hash) +void hash_function(const char *data, unsigned long len, unsigned char *hash) { int ret; EVP_MD_CTX *c; -- 2.39.5