summaryrefslogtreecommitdiff
path: root/ld/lddigest.h
blob: a1eeb022d00ba66ca1d9fbcec954283ed469be86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
 * Library: libcrc
 * Author:  Lammert Bies, Ulf Samuelsson
 *
 * This file is licensed under the MIT License as stated below
 *
 * Copyright (c) 2016 Lammert Bies
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

#ifndef LDDIGEST_H
#define LDDIGEST_H

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "bfd.h"

#define	CRC_POLY_64_ECMA	0x42F0E1EBA9EA3693ull	/* Normal */
#define	CRC_POLY_64_ECMA_EXP	0x6C40DF5F0B497347ull	/* CRC when testing "123456789" */
#define	CRC_POLY_64_ECMA_R	0xC96C5795D7870F42ull	/* Reversed */

#define	CRC_POLY_64_ISO		0x000000000000001Bull	/* Normal */
#define	CRC_POLY_64_ISO_EXP	0xB90956C775A41001ull	/* CRC when testing "123456789" */
#define	CRC_POLY_64_ISO_R	0xD800000000000000ull	/* Reversed */

#define	CRC_POLY_64_WE		0x42F0E1EBA9EA3693ull	/* Normal */
#define	CRC_POLY_64_WE_EXP	0x62EC59E3F1A4F00Aull	/* CRC when testing "123456789" */

#define	CRC_POLY_64_XZ		0x42F0E1EBA9EA3693ull	/* Normal */
#define	CRC_POLY_64_XZ_EXP	0x995DC9BBDF1939FAull	/* CRC when testing "123456789" */

#define	CRC_START_64		0x0000000000000000ull
#define	CRC_START_64_ECMA	0x0000000000000000ull
#define	CRC_START_64_WE		0xFFFFFFFFFFFFFFFFull
#define	CRC_START_64_INV	0xFFFFFFFFFFFFFFFFull
#define	CRC_END_64		0x0000000000000000ull
#define	CRC_END_64_INV		0xFFFFFFFFFFFFFFFFull

#define	CRC_START_32		0xFFFFFFFFul
#define	CRC_END_32		0xFFFFFFFFul

#define	CRC64_ADDRESS		"___CRC64___"
#define	CRC64_START		"___CRC64_START___"
#define	CRC64_END		"___CRC64_END___"
#define	CRC64_TABLE		"___CRC64_TABLE___"

#define	CRC_POLY_32		0x04C11DB7ul	/* Normal */
#define	CRC_POLY_32_R		0xEDB88320ul	/* Reversed */

#define	CRC_START_32_INV	0xFFFFFFFFul
#define	CRC_END_32_INV    0xFFFFFFFFul

#define	CRC32_ADDRESS		"___CRC32___"
#define	CRC32_START		"___CRC32_START___"
#define	CRC32_END		"___CRC32_END___"
#define	CRC32_TABLE		"___CRC32_TABLE___"

typedef enum algorithm
{
  no_algo = 0,
  sha_algo_1 = 1,
  crc_algo_32 = 4,
  crc_algo_64 = 8,
  sha_algo_256 = 256,
  sha_algo_512
} algo_t;

typedef enum
{
  CRC64_ECMA,
  CRC64_WE,
  CRC64_XZ,
  CRC64_ISO,
  CRC64_ISO_R,
  CRC32,
  MAXALGO
} poly_t;

typedef struct
{
  uint8_t _0;
  uint8_t _1;
  uint8_t _2;
  uint8_t _3;
  uint8_t _4;
  uint8_t _5;
  uint8_t _6;
  uint8_t _7;
} uint8_ut;

typedef struct
{
  uint16_t _0;
  uint16_t _1;
  uint16_t _2;
  uint16_t _3;
} uint16_ut;

typedef struct
{
  uint32_t _0;
  uint32_t _1;
} uint32_ut;

typedef union
{
  uint64_t d64;
  uint32_ut d32;
  uint16_ut d16;
  uint8_ut d8;
} int_t;

typedef struct
{
  algo_t crc_algo;
  uint32_t crc_size;
  const char *name;
  int_t poly;
  int_t initial;
  int_t xor_val;
  bool ireflect;
  bool oreflect;
  bool reciprocal;
  void *crc_tab;
  int_t expected;
  bool big_endian;
} algorithm_desc_t;

extern char *CRC_ADDRESS;
extern char *CRC_START;
extern char *CRC_END;
extern char *CRC_TABLE;
extern const algorithm_desc_t algorithms[];
extern algorithm_desc_t algorithm;

extern const char *digest_label;
extern bool digest_big_endian;
extern bool polynome_valid;

/* In ldcrc32.c.  */
extern uint32_t * init_crc32_tab
  (algorithm_desc_t *);
extern uint32_t calc_crc32
  (algorithm_desc_t *, const unsigned char *, size_t);
extern void lang_add_crc32_syndrome
  (algorithm_desc_t *);

/* In ldcrc64.c.  */
extern uint64_t * init_crc64_tab
  (algorithm_desc_t *);
extern uint64_t calc_crc64
  (algorithm_desc_t *, const unsigned char *, size_t);
extern void lang_add_crc64_syndrome
  (algorithm_desc_t * );

/* In lddigest.c  */
extern void lang_add_digest
  (bfd_vma, bfd_vma, bfd_vma, bfd_vma, bfd_vma, bfd_vma, bfd_vma);
extern bool lang_set_digest
  (char *);
extern void lang_add_digest_table
  (bool);
extern const char * lang_get_label
  (const char *, bool *);
extern void lang_generate_crc
  (void);
extern void lang_generate_digest
  (void);

#endif /* LDDIGEST_H */