int
seama_fix_md5(char *buf, size_t len)
{
- struct seama_hdr *shdr = (struct seama_hdr *) buf;
+ struct seama_entity_header *shdr = (struct seama_entity_header *) buf;
char *data;
size_t msize;
size_t isize;
unsigned char digest[16];
int i;
- if (len < sizeof(struct seama_hdr))
+ if (len < sizeof(struct seama_entity_header))
return -1;
isize = ntohl(shdr->size);
return -1;
}
- len -= sizeof(struct seama_hdr) + sizeof(digest) + msize;
+ len -= sizeof(struct seama_entity_header) + msize;
if (isize > len)
isize = len;
- data = buf + sizeof(struct seama_hdr) + sizeof(digest) + msize;
+ data = buf + sizeof(struct seama_entity_header) + msize;
MD5_Init(&ctx);
MD5_Update(&ctx, data, isize);
MD5_Final(digest, &ctx);
- if (!memcmp(digest, &buf[sizeof(struct seama_hdr)], sizeof(digest))) {
+ if (!memcmp(digest, shdr->md5, sizeof(digest))) {
if (quiet < 2)
fprintf(stderr, "the header is fixed already\n");
return -1;
shdr->size = htonl(isize);
/* update the checksum in the image */
- for (i = 0; i < sizeof(digest); i++)
- buf[sizeof(struct seama_hdr) + i] = digest[i];
+ memcpy(shdr->md5, digest, sizeof(digest));
return 0;
}
char *buf;
ssize_t res;
size_t block_offset;
- struct seama_hdr *shdr;
+ struct seama_entity_header *shdr;
if (quiet < 2)
fprintf(stderr, "Trying to fix SEAMA header in %s at 0x%x...\n",
exit(1);
}
- shdr = (struct seama_hdr *)first_block;
+ shdr = (struct seama_entity_header *)first_block;
if (shdr->magic != htonl(SEAMA_MAGIC)) {
fprintf(stderr, "No SEAMA header found\n");
return -1;
* | image size |
* +-------------+-------------+
*/
+
/* seama header */
-typedef struct seama_hdr seamahdr_t;
-struct seama_hdr
-{
+struct seama_entity_header {
uint32_t magic; /* should always be SEAMA_MAGIC. */
uint16_t reserved; /* reserved for */
uint16_t metasize; /* size of the META data */
uint32_t size; /* size of the image */
+ uint8_t md5[16];
} __attribute__ ((packed));