2 * Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
10 #ifndef _BUFFALO_LIB_H
11 #define _BUFFALO_LIB_H
15 #define ARRAY_SIZE(_a) (sizeof((_a)) / sizeof((_a)[0]))
16 #define BIT(_x) (1UL << (_x))
18 #define TAG_BRAND_LEN 32
19 #define TAG_PRODUCT_LEN 32
20 #define TAG_VERSION_LEN 8
21 #define TAG_REGION_LEN 2
22 #define TAG_LANGUAGE_LEN 8
23 #define TAG_PLATFORM_LEN 8
24 #define TAG_HWVER_LEN 4
25 #define TAG_HWVER_VAL_LEN 4
28 unsigned char product[TAG_PRODUCT_LEN];
29 unsigned char brand[TAG_BRAND_LEN];
30 unsigned char ver_major[TAG_VERSION_LEN];
31 unsigned char ver_minor[TAG_VERSION_LEN];
32 unsigned char region_code[2];
34 unsigned char unknown0[2];
35 unsigned char language[TAG_LANGUAGE_LEN];
36 unsigned char platform[TAG_PLATFORM_LEN];
37 unsigned char hwv[TAG_HWVER_LEN];
38 unsigned char hwv_val[TAG_HWVER_VAL_LEN];
48 } __attribute ((packed));
50 #define ENC_PRODUCT_LEN 32
51 #define ENC_VERSION_LEN 8
52 #define ENC_MAGIC_LEN 6
54 unsigned long enc_compute_header_len(char *product, char *version);
55 unsigned long enc_compute_buf_len(char *product, char *version,
56 unsigned long datalen);
60 unsigned char magic[ENC_MAGIC_LEN];
61 unsigned char product[ENC_PRODUCT_LEN];
62 unsigned char version[ENC_VERSION_LEN];
69 int encrypt_buf(struct enc_param *ep, unsigned char *hdr,
71 int decrypt_buf(struct enc_param *ep, unsigned char *data,
72 unsigned long datalen);
74 #define BCRYPT_DEFAULT_STATE_LEN 256
75 #define BCRYPT_MAX_KEYLEN 254
81 unsigned long state_len;
84 int bcrypt_init(struct bcrypt_ctx *ctx, void *key, int keylen,
85 unsigned long state_len);
86 int bcrypt_process(struct bcrypt_ctx *ctx, unsigned char *src,
87 unsigned char *dst, unsigned long len);
88 void bcrypt_finish(struct bcrypt_ctx *ctx);
89 int bcrypt_buf(unsigned char seed, unsigned char *key, unsigned char *src,
90 unsigned char *dst, unsigned long len, int longstate);
92 uint32_t buffalo_csum(uint32_t csum, void *buf, unsigned long len);
93 uint32_t buffalo_crc(void *buf, unsigned long len);
95 ssize_t get_file_size(char *name);
96 int read_file_to_buf(char *name, void *buf, ssize_t buflen);
97 int write_buf_to_file(char *name, void *buf, ssize_t buflen);
99 #endif /* _BUFFALO_LIB_H */