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));
51 unsigned char product[TAG_PRODUCT_LEN];
52 unsigned char brand[TAG_BRAND_LEN];
53 unsigned char ver_major[TAG_VERSION_LEN];
54 unsigned char ver_minor[TAG_VERSION_LEN];
55 unsigned char region_code[2];
57 unsigned char unknown0[2];
58 unsigned char language[TAG_LANGUAGE_LEN];
59 unsigned char platform[TAG_PLATFORM_LEN];
60 unsigned char hwv[TAG_HWVER_LEN];
61 unsigned char hwv_val[TAG_HWVER_VAL_LEN];
70 } __attribute ((packed));
72 #define ENC_PRODUCT_LEN 32
73 #define ENC_VERSION_LEN 8
74 #define ENC_MAGIC_LEN 6
76 unsigned long enc_compute_header_len(char *product, char *version);
77 unsigned long enc_compute_buf_len(char *product, char *version,
78 unsigned long datalen);
82 unsigned char magic[ENC_MAGIC_LEN];
83 unsigned char product[ENC_PRODUCT_LEN];
84 unsigned char version[ENC_VERSION_LEN];
91 int encrypt_buf(struct enc_param *ep, unsigned char *hdr,
93 int decrypt_buf(struct enc_param *ep, unsigned char *data,
94 unsigned long datalen);
96 #define BCRYPT_DEFAULT_STATE_LEN 256
97 #define BCRYPT_MAX_KEYLEN 254
102 unsigned char *state;
103 unsigned long state_len;
106 int bcrypt_init(struct bcrypt_ctx *ctx, void *key, int keylen,
107 unsigned long state_len);
108 int bcrypt_process(struct bcrypt_ctx *ctx, unsigned char *src,
109 unsigned char *dst, unsigned long len);
110 void bcrypt_finish(struct bcrypt_ctx *ctx);
111 int bcrypt_buf(unsigned char seed, unsigned char *key, unsigned char *src,
112 unsigned char *dst, unsigned long len, int longstate);
114 uint32_t buffalo_csum(uint32_t csum, void *buf, unsigned long len);
115 uint32_t buffalo_crc(void *buf, unsigned long len);
117 ssize_t get_file_size(char *name);
118 int read_file_to_buf(char *name, void *buf, ssize_t buflen);
119 int write_buf_to_file(char *name, void *buf, ssize_t buflen);
121 #endif /* _BUFFALO_LIB_H */