]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Rename hash2 -> hash.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 18 May 2025 18:31:33 +0000 (20:31 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Thu, 22 May 2025 17:08:23 +0000 (19:08 +0200)
Now that sha1 is no longer supported, the hash2 naming has become meaningless.
Rename it back to "hash".

aft.c
client_common.c
command.c
crypt.h
crypt_common.c
gcrypt.c
openssl.c

diff --git a/aft.c b/aft.c
index 89739356808224ce9158fdc24422df074f19d2c1..a9145f2cb4ea65264664e970fa0d2b471f1c3926 100644 (file)
--- 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;
index 8542a010b7421784de518ad98ff42edc06c6baa8..8b28b29425641faf60b056e6c35934d8bc484876 100644 (file)
@@ -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;
index 4139c8cb3413bc1963b2a2b4fad5d981521f9575..351116565f6255884836e8c744f776e1aa04e87c 100644 (file)
--- 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 27da9aa31f404f508ea94d397720cfd38778ce21..8ddf2b55ad89fe49b1ada6226721d4276020654c 100644 (file)
--- 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);
index dbd63b5084eb415fe07e51cb7e5bd8bcdce338b5..9b78f3605b067ae075d6314cd84d7b1113fb2d61 100644 (file)
@@ -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])
index 5eca71efb8a0836bce51c29802aae641e128c1a1..17c048ea50803d38f56f00a0dfefd6d4426e54e2 100644 (file)
--- 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);
 }
 
index 34e42886635d0982b541631d8d23e44a07ff1553..4fc836d32289c353583ababb8b274bccef4bb5b9 100644 (file)
--- 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;