core: replace SHA1() function by SHA1_uint32()

The SHA1() helper function was only used when calculating a
SHA1 hash and taking the first four bytes of it as uint32.

Make that explicit by renaming the function into SHA1_uint32()
and directly returning an uint32_t.

Note that the usage in cochran.cpp is sketchy: it generates
a four-byte hash out of two-byte data. Why!?

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-04-23 15:28:11 +08:00 committed by bstoeger
parent 0b817e468a
commit b24f37fb4f
4 changed files with 17 additions and 18 deletions

View file

@ -610,7 +610,6 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
struct dive *dive;
struct divecomputer *dc;
struct tm tm = {0};
uint32_t csum[5];
double max_depth, avg_depth, min_temp;
unsigned int duration = 0, corrupt_dive = 0;
@ -719,8 +718,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
* (double) log[CMD_ALTITUDE] * 250 * FEET, 5.25588) * 1000);
dc->salinity = 10000 + 150 * log[CMD_WATER_CONDUCTIVITY];
SHA1(log + CMD_NUMBER, 2, (unsigned char *)csum);
dc->diveid = csum[0];
dc->diveid = SHA1_uint32(log + CMD_NUMBER, 2);
if (log[CMD_MAX_DEPTH] == 0xff && log[CMD_MAX_DEPTH + 1] == 0xff)
corrupt_dive = 1;
@ -765,8 +763,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
* (double) log[EMC_ALTITUDE] * 250 * FEET, 5.25588) * 1000);
dc->salinity = 10000 + 150 * (log[EMC_WATER_CONDUCTIVITY] & 0x3);
SHA1(log + EMC_NUMBER, 2, (unsigned char *)csum);
dc->diveid = csum[0];
dc->diveid = SHA1_uint32(log + EMC_NUMBER, 2);
if (log[EMC_MAX_DEPTH] == 0xff && log[EMC_MAX_DEPTH + 1] == 0xff)
corrupt_dive = 1;