Commit c7db968a authored by Michael Tremer's avatar Michael Tremer

format: Reduce the length of the signature header

Since a single signature can only be up to 2048 bytes long,
we do not need 32 bits to tell us how many of those bytes
are being used.
Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent 67c99e7e
...@@ -274,8 +274,8 @@ static int loc_database_read_header_v1(struct loc_database* db) { ...@@ -274,8 +274,8 @@ static int loc_database_read_header_v1(struct loc_database* db) {
db->description = be32toh(header.description); db->description = be32toh(header.description);
db->license = be32toh(header.license); db->license = be32toh(header.license);
db->signature1_length = be32toh(header.signature1_length); db->signature1_length = be16toh(header.signature1_length);
db->signature2_length = be32toh(header.signature2_length); db->signature2_length = be16toh(header.signature2_length);
// Read signatures // Read signatures
if (db->signature1_length) { if (db->signature1_length) {
......
...@@ -75,17 +75,14 @@ struct loc_database_header_v1 { ...@@ -75,17 +75,14 @@ struct loc_database_header_v1 {
uint32_t pool_offset; uint32_t pool_offset;
uint32_t pool_length; uint32_t pool_length;
// Some padding
char padding1[2];
// Signatures // Signatures
uint32_t signature1_length; uint16_t signature1_length;
uint32_t signature2_length; uint16_t signature2_length;
char signature1[LOC_SIGNATURE_MAX_LENGTH]; char signature1[LOC_SIGNATURE_MAX_LENGTH];
char signature2[LOC_SIGNATURE_MAX_LENGTH]; char signature2[LOC_SIGNATURE_MAX_LENGTH];
// Add some padding for future extensions // Add some padding for future extensions
char padding2[32]; char padding[32];
}; };
struct loc_database_network_node_v1 { struct loc_database_network_node_v1 {
......
...@@ -531,7 +531,7 @@ static int loc_database_write_countries(struct loc_writer* writer, ...@@ -531,7 +531,7 @@ static int loc_database_write_countries(struct loc_writer* writer,
static int loc_writer_create_signature(struct loc_writer* writer, static int loc_writer_create_signature(struct loc_writer* writer,
struct loc_database_header_v1* header, FILE* f, EVP_PKEY* private_key, struct loc_database_header_v1* header, FILE* f, EVP_PKEY* private_key,
char* signature, size_t* length) { char* signature, size_t* length) {
DEBUG(writer->ctx, "Signing database...\n"); DEBUG(writer->ctx, "Creating signature...\n");
// Read file from the beginning // Read file from the beginning
rewind(f); rewind(f);
...@@ -649,8 +649,7 @@ LOC_EXPORT int loc_writer_write(struct loc_writer* writer, FILE* f, enum loc_dat ...@@ -649,8 +649,7 @@ LOC_EXPORT int loc_writer_write(struct loc_writer* writer, FILE* f, enum loc_dat
header.signature2_length = 0; header.signature2_length = 0;
// Clear the padding // Clear the padding
memset(header.padding1, '\0', sizeof(header.padding1)); memset(header.padding, '\0', sizeof(header.padding));
memset(header.padding2, '\0', sizeof(header.padding2));
int r; int r;
off_t offset = 0; off_t offset = 0;
...@@ -718,13 +717,19 @@ LOC_EXPORT int loc_writer_write(struct loc_writer* writer, FILE* f, enum loc_dat ...@@ -718,13 +717,19 @@ LOC_EXPORT int loc_writer_write(struct loc_writer* writer, FILE* f, enum loc_dat
// Copy the signatures into the header // Copy the signatures into the header
if (writer->signature1_length) { if (writer->signature1_length) {
DEBUG(writer->ctx, "Copying first signature of %zu byte(s)\n",
writer->signature1_length);
memcpy(header.signature1, writer->signature1, writer->signature1_length); memcpy(header.signature1, writer->signature1, writer->signature1_length);
header.signature1_length = htobe32(writer->signature1_length); header.signature1_length = htobe16(writer->signature1_length);
} }
if (writer->signature2_length) { if (writer->signature2_length) {
DEBUG(writer->ctx, "Copying second signature of %zu byte(s)\n",
writer->signature1_length);
memcpy(header.signature2, writer->signature2, writer->signature2_length); memcpy(header.signature2, writer->signature2, writer->signature2_length);
header.signature2_length = htobe32(writer->signature2_length); header.signature2_length = htobe16(writer->signature2_length);
} }
// Write the header // Write the header
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment