1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
11 #define ARRAY_SIZE(_a) (sizeof((_a)) / sizeof((_a)[0]))
12 #define BIT(_x) (1UL << (_x))
14 #define TAG_BRAND_LEN 32
15 #define TAG_PRODUCT_LEN 32
16 #define TAG_VERSION_LEN 8
17 #define TAG_REGION_LEN 2
18 #define TAG_LANGUAGE_LEN 8
19 #define TAG_PLATFORM_LEN 8
20 #define TAG_HWVER_LEN 4
21 #define TAG_HWVER_VAL_LEN 4
24 unsigned char product
[TAG_PRODUCT_LEN
];
25 unsigned char brand
[TAG_BRAND_LEN
];
26 unsigned char ver_major
[TAG_VERSION_LEN
];
27 unsigned char ver_minor
[TAG_VERSION_LEN
];
28 unsigned char region_code
[2];
30 unsigned char unknown0
[2];
31 unsigned char language
[TAG_LANGUAGE_LEN
];
32 unsigned char platform
[TAG_PLATFORM_LEN
];
33 unsigned char hwv
[TAG_HWVER_LEN
];
34 unsigned char hwv_val
[TAG_HWVER_VAL_LEN
];
44 } __attribute ((packed
));
47 unsigned char product
[TAG_PRODUCT_LEN
];
48 unsigned char brand
[TAG_BRAND_LEN
];
49 unsigned char ver_major
[TAG_VERSION_LEN
];
50 unsigned char ver_minor
[TAG_VERSION_LEN
];
51 unsigned char region_code
[2];
53 unsigned char unknown0
[2];
54 unsigned char language
[TAG_LANGUAGE_LEN
];
55 unsigned char platform
[TAG_PLATFORM_LEN
];
56 unsigned char hwv
[TAG_HWVER_LEN
];
57 unsigned char hwv_val
[TAG_HWVER_VAL_LEN
];
66 } __attribute ((packed
));
69 unsigned char product
[TAG_PRODUCT_LEN
];
70 unsigned char brand
[TAG_BRAND_LEN
];
71 unsigned char ver_major
[TAG_VERSION_LEN
];
72 unsigned char ver_minor
[TAG_VERSION_LEN
];
73 unsigned char region_code
[2];
75 unsigned char unknown0
[2];
76 unsigned char language
[TAG_LANGUAGE_LEN
];
77 unsigned char platform
[TAG_PLATFORM_LEN
];
78 unsigned char hwv
[TAG_HWVER_LEN
];
79 unsigned char hwv_val
[TAG_HWVER_VAL_LEN
];
86 } __attribute ((packed
));
88 #define ENC_PRODUCT_LEN 32
89 #define ENC_VERSION_LEN 8
90 #define ENC_MAGIC_LEN 6
92 unsigned long enc_compute_header_len(char *product
, char *version
);
93 unsigned long enc_compute_buf_len(char *product
, char *version
,
94 unsigned long datalen
);
98 unsigned char magic
[ENC_MAGIC_LEN
];
99 unsigned char product
[ENC_PRODUCT_LEN
];
100 unsigned char version
[ENC_VERSION_LEN
];
107 int encrypt_buf(struct enc_param
*ep
, unsigned char *hdr
,
108 unsigned char *data
);
109 int decrypt_buf(struct enc_param
*ep
, unsigned char *data
,
110 unsigned long datalen
);
112 #define BCRYPT_DEFAULT_STATE_LEN 256
113 #define BCRYPT_MAX_KEYLEN 254
118 unsigned char *state
;
119 unsigned long state_len
;
122 int bcrypt_init(struct bcrypt_ctx
*ctx
, void *key
, int keylen
,
123 unsigned long state_len
);
124 int bcrypt_process(struct bcrypt_ctx
*ctx
, unsigned char *src
,
125 unsigned char *dst
, unsigned long len
);
126 void bcrypt_finish(struct bcrypt_ctx
*ctx
);
127 int bcrypt_buf(unsigned char seed
, unsigned char *key
, unsigned char *src
,
128 unsigned char *dst
, unsigned long len
, int longstate
);
130 uint32_t buffalo_csum(uint32_t csum
, void *buf
, unsigned long len
);
131 uint32_t buffalo_crc(void *buf
, unsigned long len
);
133 ssize_t
get_file_size(char *name
);
134 int read_file_to_buf(char *name
, void *buf
, ssize_t buflen
);
135 int write_buf_to_file(char *name
, void *buf
, ssize_t buflen
);
137 #endif /* _BUFFALO_LIB_H */