]> Git Repo - J-u-boot.git/blame - lib/crc8.c
efi_loader: set up secure boot
[J-u-boot.git] / lib / crc8.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
60d18d3f
SG
2/*
3 * Copyright (c) 2013 Google, Inc
60d18d3f
SG
4 */
5
c3a4d1c3
SG
6#ifdef USE_HOSTCC
7#include <arpa/inet.h>
8#else
9#include <common.h>
10#endif
11#include <u-boot/crc.h>
60d18d3f 12
456ecd08
SR
13#define POLY (0x1070U << 3)
14
15static unsigned char _crc8(unsigned short data)
60d18d3f 16{
456ecd08
SR
17 int i;
18
19 for (i = 0; i < 8; i++) {
20 if (data & 0x8000)
21 data = data ^ POLY;
22 data = data << 1;
60d18d3f
SG
23 }
24
456ecd08
SR
25 return (unsigned char)(data >> 8);
26}
27
28unsigned int crc8(unsigned int crc, const unsigned char *vptr, int len)
29{
30 int i;
31
32 for (i = 0; i < len; i++)
33 crc = _crc8((crc ^ vptr[i]) << 8);
34
35 return crc;
60d18d3f 36}
This page took 0.266992 seconds and 4 git commands to generate.