[coreboot] libpayload: verify LAR checksum

Peter Stuge peter at stuge.se
Tue May 27 21:52:57 CEST 2008


On Tue, May 27, 2008 at 01:44:01PM -0600, Jordan Crouse wrote:
> libpayload:  Add a function to verify the checksum on a LAR file
> 
> This function verifies the checksum on a LAR file.
> 
> Signed-off-by: Jordan Crouse <jordan.crouse at amd.com>

Acked-by: Peter Stuge <peter at stuge.se>


> Index: libpayload/include/libpayload.h
> ===================================================================
> --- libpayload.orig/include/libpayload.h	2008-05-14 09:23:10.000000000 -0600
> +++ libpayload/include/libpayload.h	2008-05-14 09:28:39.000000000 -0600
> @@ -251,6 +251,7 @@
>  void rewindlar(struct LAR *lar);
>  int larstat(struct LAR *lar, const char *path, struct larstat *buf);
>  void *larfptr(struct LAR *lar, const char *filename);
> +int lfverify(struct LAR *lar, const char *filename);
>  struct LFILE * lfopen(struct LAR *lar, const char *filename);
>  int lfread(void *ptr, size_t size, size_t nmemb, struct LFILE *stream);
>  
> Index: libpayload/libc/lar.c
> ===================================================================
> --- libpayload.orig/libc/lar.c	2008-05-14 09:18:30.000000000 -0600
> +++ libpayload/libc/lar.c	2008-05-14 10:52:39.000000000 -0600
> @@ -228,6 +228,41 @@
>  	return (void *) ((u8 *) header + ntohl(header->offset));
>  }
>  
> +/**
> + * Verify the checksum on a particular LAR entry
> + *
> + * @param lar A pointer to the LAR stream
> + * @param filename The lar entry to verify
> + * @return Return 1 if the entry is valid, 0 if it is not, or -1
> + * on error
> + */
> +
> +int lfverify(struct LAR *lar, const char *filename)
> +{
> +	struct lar_header *header = get_header_by_name(lar, filename);
> +
> +	u8 *ptr = (u8 *) header;
> +	int len = ntohl(header->len) + ntohl(header->offset);
> +	int offset;
> +	u32 csum = 0;
> +
> +	if (header == NULL)
> +		return -1;
> +
> +	/* The checksum needs to be calulated on entire data section,
> +	 * including any padding for the 16 byte alignment (which should
> +	 * be zeros
> +	 */
> +
> +	len = (len + 15) & 0xFFFFFFF0;
> +
> +	for(offset = 0; offset < len; offset += 4) {
> +		csum += *((u32 *) (ptr + offset));
> +	}
> +
> +	return (csum == 0xFFFFFFFF) ? 1 : 0;
> +}
> +
>  struct LFILE * lfopen(struct LAR *lar, const char *filename)
>  {
>  	struct LFILE *file;




More information about the coreboot mailing list