├── .gitignore ├── LICENSE ├── README.md ├── hua.pro ├── huawei ├── aescrypt.cpp ├── aescrypt.h ├── cfgfile.cpp ├── cfgfile.h ├── chinese.qm ├── huawei.cpp ├── huawei.h ├── huawei.pro ├── huawei.ui ├── huawei_logo.ico ├── logo.rc ├── main.cpp ├── qt_zh_CN.qm ├── res.qrc ├── xmlfile.cpp └── xmlfile.h ├── quazip ├── CMakeLists.txt ├── JlCompress.cpp ├── JlCompress.h ├── crypt.h ├── debian │ └── libquazip0.symbols ├── doc │ ├── faq.dox │ ├── index.dox │ └── usage.dox ├── ioapi.h ├── qioapi.cpp ├── quaadler32.cpp ├── quaadler32.h ├── quachecksum32.h ├── quacrc32.cpp ├── quacrc32.h ├── quagzipfile.cpp ├── quagzipfile.h ├── quaziodevice.cpp ├── quaziodevice.h ├── quazip.cpp ├── quazip.h ├── quazip.pro ├── quazip.sln ├── quazip.vcproj ├── quazip.vcxproj ├── quazip.vcxproj.filters ├── quazip_global.h ├── quazipdir.cpp ├── quazipdir.h ├── quazipfile.cpp ├── quazipfile.h ├── quazipfileinfo.cpp ├── quazipfileinfo.h ├── quazipnewinfo.cpp ├── quazipnewinfo.h ├── run_moc.bat ├── unzip.c ├── unzip.h ├── zip.c └── zip.h ├── src.png └── xyssl ├── aes.c ├── aes.h ├── arc4.c ├── arc4.h ├── base64.c ├── base64.h ├── bignum.c ├── bignum.h ├── bn_mul.h ├── certs.c ├── certs.h ├── config.h ├── debug.c ├── debug.h ├── des.c ├── des.h ├── dhm.c ├── dhm.h ├── havege.c ├── havege.h ├── md2.c ├── md2.h ├── md4.c ├── md4.h ├── md5.c ├── md5.h ├── net.c ├── net.h ├── openssl.h ├── padlock.c ├── padlock.h ├── rsa.c ├── rsa.h ├── sha1.c ├── sha1.h ├── sha2.c ├── sha2.h ├── sha4.c ├── sha4.h ├── ssl.h ├── ssl_cli.c ├── ssl_srv.c ├── ssl_tls.c ├── timing.c ├── timing.h ├── x509.h ├── x509parse.c └── xyssl.pro /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 华为光猫系列配置解密工具 2 | 3 | 4 | ![huawei](https://raw.githubusercontent.com/wx1183618058/HuaWei-Optical-Network-Terminal-Decoder/master/src.png) 5 | 6 | **本软件**是一款专为解密华为光猫配置的工具,使用QT开发。 7 | - **具体功能** :如图基本所有加解密都支持。 8 | - 用 Qt creator 打开编译即可, 在hua.pro中设置好依赖 zlib 9 | 10 | > $ cd huawei_optical_network_terminal_decoder 11 | > 12 | > $ qmake 13 | > 14 | > $ ./huawei 15 | -------------------------------------------------------------------------------- /hua.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS += \ 4 | huawei \ 5 | xyssl \ 6 | quazip 7 | 8 | huawei.depends = quazip xyssl 9 | #YOU PATH ZLIB 10 | ZLIB += YOU PATH ZLIB 11 | -------------------------------------------------------------------------------- /huawei/aescrypt.h: -------------------------------------------------------------------------------- 1 | #ifndef AESCRYPT_H 2 | #define AESCRYPT_H 3 | 4 | #include 5 | #include 6 | 7 | class AesCrypt 8 | { 9 | public: 10 | enum AesCryptMode { 11 | $1 = 1, 12 | $2 = 2, 13 | SU = 3 14 | }; 15 | AesCrypt(const QString &text, const AesCryptMode &mode); 16 | int check_format(); 17 | QString decrypt(); 18 | QString text() const; 19 | void setText(const QString &text); 20 | AesCryptMode mode() const; 21 | void setMode(const AesCryptMode &mode); 22 | 23 | private: 24 | QString text_; 25 | AesCryptMode mode_; 26 | QString decrypt_$1(); 27 | QString decrypt_$2(); 28 | QString decrypt_SU(); 29 | int encode_to_char(QString &encode); 30 | uint8_t aes_rotl(uint8_t ch, int c); 31 | void aes_ascii_unvisible(uint8_t *str, size_t str_len); 32 | void aes_generate_rand_pwd_key(const uint8_t *str, uint8_t *aes_key); 33 | uint32_t aes_enh_sys_to_long(const uint8_t *plain); 34 | void aes_plain_to_bin(const uint8_t * plain, uint8_t * bin); 35 | void wbox_decrypt(uint8_t *encryption_key, uint8_t *out); 36 | void aes_get_cbc_key(char *key, int len, char *key_out); 37 | 38 | }; 39 | 40 | #endif // AESCRYPT_H 41 | -------------------------------------------------------------------------------- /huawei/cfgfile.cpp: -------------------------------------------------------------------------------- 1 | #include "cfgfile.h" 2 | #include 3 | #include 4 | #include 5 | 6 | int CfgFile::decrypt(const QString &out_file) 7 | { 8 | QFile fin(in_file_); 9 | QTemporaryFile ftemp; 10 | if (!fin.open(QFile::ReadOnly)) return 0; 11 | if (!ftemp.open()) { 12 | fin.close(); 13 | return 0; 14 | } 15 | fin.read(32); 16 | ftemp.write(fin.readAll()); 17 | fin.close(); 18 | ftemp.close(); 19 | extract_gz(ftemp.fileName(), ftemp.fileName()); 20 | XmlFile::setIn_file(ftemp.fileName()); 21 | XmlFile::decrypt(out_file); 22 | return 1; 23 | } 24 | 25 | int CfgFile::encrypt(const QString &out_file) 26 | { 27 | uint8_t buffer[32]; 28 | QFile fout(out_file); 29 | QTemporaryFile ftemp; 30 | if (!fout.open(QFile::WriteOnly)) return 0; 31 | if (!ftemp.open()) { 32 | fout.close(); 33 | QFile::remove(out_file); 34 | return 0; 35 | } 36 | XmlFile::encrypt(ftemp.fileName()); 37 | compress_gz(ftemp.fileName(), ftemp.fileName()); 38 | 39 | //head 40 | memset(buffer, 0, 32); 41 | memcpy(buffer, "gfcq", 4); 42 | uint32_t crc = get_crc(ftemp.fileName(), 0); 43 | memcpy(buffer+4, (uint8_t*)&crc, 4); 44 | size_t size = ftemp.size(); 45 | memcpy(buffer+8, (uint8_t*)&size, 4); 46 | int time = QTime(0, 0).secsTo(QTime::currentTime()); 47 | memcpy(buffer+12, (uint8_t*)&time, 4); 48 | 49 | fout.write((char*)buffer, 32); 50 | fout.write(ftemp.readAll()); 51 | fout.close(); 52 | ftemp.close(); 53 | return 1; 54 | } 55 | 56 | int CfgFile::is_cfg() 57 | { 58 | char buffer[5]; 59 | buffer[4] = '\0'; 60 | QFile fin(in_file_); 61 | if (!fin.open(QFile::ReadOnly)) return 0; 62 | 63 | fin.read(buffer, 4); 64 | if (strcmp(buffer, "gfcq")) return 0; 65 | 66 | //head 32 67 | fin.read(buffer, 4); 68 | if (*((uint32_t*)buffer) != get_crc(in_file_, 32)) return 0; 69 | 70 | fin.read(buffer, 4); 71 | if (*((int*)buffer) != fin.size()-32) return 0; 72 | 73 | fin.close(); 74 | return 1; 75 | } 76 | 77 | void CfgFile::rename(const QString &newname) 78 | { 79 | in_file_ = newname; 80 | XmlFile::rename(newname); 81 | } 82 | 83 | uint32_t CfgFile::get_crc(const QString &in_file, int offset) 84 | { 85 | uint32_t crc_table[384] = { 86 | 0, 0x77073096, 0xEE0E612C, 0x990951BA, 0x76DC419, 0x706AF48F, 87 | 0xE963A535, 0x9E6495A3, 0xEDB8832, 0x79DCB8A4, 0xE0D5E91E, 88 | 0x97D2D988, 0x9B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 89 | 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 90 | 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 91 | 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 92 | 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 93 | 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 94 | 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 95 | 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 96 | 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 97 | 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 98 | 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x1DB7106, 99 | 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x6B6B51F, 0x9FBFE4A5, 100 | 0xE8B8D433, 0x7807C9A2, 0xF00F934, 0x9609A88E, 0xE10E9818, 101 | 0x7F6A0DBB, 0x86D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 102 | 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 103 | 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 104 | 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 105 | 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 106 | 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 107 | 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 108 | 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 109 | 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 110 | 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 111 | 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x3B6E20C , 112 | 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x4DB2615 , 0x73DC1683, 113 | 0xE3630B12, 0x94643B84, 0xD6D6A3E , 0x7A6A5AA8, 0xE40ECF0B, 114 | 0x9309FF9D, 0xA00AE27 , 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 115 | 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 116 | 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 117 | 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 118 | 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 119 | 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 120 | 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 121 | 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 122 | 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 123 | 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 124 | 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x26D930A , 125 | 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x5005713 , 0x95BF4A82, 126 | 0xE2B87A14, 0x7BB12BAE, 0xCB61B38 , 0x92D28E9B, 0xE5D5BE0D, 127 | 0x7CDCEFB7, 0xBDBDF21 , 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 128 | 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 129 | 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 130 | 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 131 | 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 132 | 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 133 | 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 134 | 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 135 | 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 136 | 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, 137 | 0xC0C10000, 0x140C181 , 0x3C0C301 , 0xC2410280, 0x6C0C601 , 138 | 0xC7410780, 0xC5C10500, 0x440C481 , 0xCC0CC01 , 0xCD410D80, 139 | 0xCFC10F00, 0xE40CE81 , 0xCAC10A00, 0xB40CB81 , 0x9C0C901 , 140 | 0xC8410880, 0x18C0D801, 0xD9411980, 0xDBC11B00, 0x1A40DA81, 141 | 0xDEC11E00, 0x1F40DF81, 0x1DC0DD01, 0xDC411C80, 0xD4C11400, 142 | 0x1540D581, 0x17C0D701, 0xD6411680, 0x12C0D201, 0xD3411380, 143 | 0xD1C11100, 0x1040D081, 0x30C0F001, 0xF1413180, 0xF3C13300, 144 | 0x3240F281, 0xF6C13600, 0x3740F781, 0x35C0F501, 0xF4413480, 145 | 0xFCC13C00, 0x3D40FD81, 0x3FC0FF01, 0xFE413E80, 0x3AC0FA01, 146 | 0xFB413B80, 0xF9C13900, 0x3840F881, 0xE8C12800, 0x2940E981, 147 | 0x2BC0EB01, 0xEA412A80, 0x2EC0EE01, 0xEF412F80, 0xEDC12D00, 148 | 0x2C40EC81, 0x24C0E401, 0xE5412580, 0xE7C12700, 0x2640E681, 149 | 0xE2C12200, 0x2340E381, 0x21C0E101, 0xE0412080, 0x60C0A001, 150 | 0xA1416180, 0xA3C16300, 0x6240A281, 0xA6C16600, 0x6740A781, 151 | 0x65C0A501, 0xA4416480, 0xACC16C00, 0x6D40AD81, 0x6FC0AF01, 152 | 0xAE416E80, 0x6AC0AA01, 0xAB416B80, 0xA9C16900, 0x6840A881, 153 | 0xB8C17800, 0x7940B981, 0x7BC0BB01, 0xBA417A80, 0x7EC0BE01, 154 | 0xBF417F80, 0xBDC17D00, 0x7C40BC81, 0x74C0B401, 0xB5417580, 155 | 0xB7C17700, 0x7640B681, 0xB2C17200, 0x7340B381, 0x71C0B101, 156 | 0xB0417080, 0x90C15000, 0x51409181, 0x53C09301, 0x92415280, 157 | 0x56C09601, 0x97415780, 0x95C15500, 0x54409481, 0x5CC09C01, 158 | 0x9D415D80, 0x9FC15F00, 0x5E409E81, 0x9AC15A00, 0x5B409B81, 159 | 0x59C09901, 0x98415880, 0x48C08801, 0x89414980, 0x8BC14B00, 160 | 0x4A408A81, 0x8EC14E00, 0x4F408F81, 0x4DC08D01, 0x8C414C80, 161 | 0x84C14400, 0x45408581, 0x47C08701, 0x86414680, 0x42C08201, 162 | 0x83414380, 0x81C14100, 0x40408081 163 | }; 164 | uint8_t buffer[1024]; 165 | size_t size = 0; 166 | unsigned int crc = 0xFFFFFFFF; 167 | QFile fin(in_file); 168 | if (!fin.open(QFile::ReadOnly)) return 0; 169 | 170 | //除去head 171 | fin.read(offset); 172 | 173 | while ((size = fin.read((char*)buffer, 1024))) { 174 | for (size_t x=0; x> 8); 176 | } 177 | fin.close(); 178 | return ~crc; 179 | } 180 | -------------------------------------------------------------------------------- /huawei/cfgfile.h: -------------------------------------------------------------------------------- 1 | #ifndef CFGFILE_H 2 | #define CFGFILE_H 3 | 4 | #include "xmlfile.h" 5 | 6 | class CfgFile : public XmlFile 7 | { 8 | public: 9 | CfgFile() = default; 10 | CfgFile(const QString &in_file) : XmlFile(in_file), in_file_(in_file) {} 11 | int decrypt(const QString &out_file); 12 | int encrypt(const QString &out_file); 13 | int is_cfg(); 14 | void rename(const QString &newname); 15 | 16 | protected: 17 | uint32_t get_crc(const QString &in_file, int offset); 18 | 19 | private: 20 | QString in_file_; 21 | }; 22 | 23 | #endif // CFGFILE_H 24 | -------------------------------------------------------------------------------- /huawei/chinese.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx1183618058/HuaWei-Optical-Network-Terminal-Decoder/6d430cdfbd5b29a6f6bf0e27b9ef055b95eb6dbb/huawei/chinese.qm -------------------------------------------------------------------------------- /huawei/huawei.h: -------------------------------------------------------------------------------- 1 | #ifndef HUAWEI_H 2 | #define HUAWEI_H 3 | 4 | #include 5 | 6 | class QTranslator; 7 | class QAction; 8 | 9 | namespace Ui { 10 | class HuaWei; 11 | } 12 | 13 | class HuaWei : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit HuaWei(QWidget *parent = 0); 19 | void dragEnterEvent(QDragEnterEvent *event); 20 | void dropEvent(QDropEvent *event); 21 | ~HuaWei(); 22 | 23 | private slots: 24 | void on_xml_tool_button__clicked(); 25 | void on_xml_en_button__clicked(); 26 | void on_xml_de_button__clicked(); 27 | void on_cfg_tool_button__clicked(); 28 | void on_cfg_en_button__clicked(); 29 | void on_cfg_de_button__clicked(); 30 | void on_de_1_button__clicked(); 31 | void on_de_2_button__clicked(); 32 | void on_de_su_button__clicked(); 33 | void update_ui(int i); 34 | 35 | private: 36 | Ui::HuaWei *ui; 37 | QTranslator *language; 38 | QTranslator *g_language; 39 | QAction *chinese; 40 | QAction *english; 41 | QAction *about; 42 | }; 43 | 44 | #endif // HUAWEI_H 45 | -------------------------------------------------------------------------------- /huawei/huawei.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-12-15T15:00:32 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = huawei 12 | TEMPLATE = app 13 | #CONFIG += static 14 | CONFIG(static): DEFINES += QUAZIP_STATIC 15 | TRANSLATIONS += chinese.ts 16 | 17 | # The following define makes your compiler emit warnings if you use 18 | # any feature of Qt which has been marked as deprecated (the exact warnings 19 | # depend on your compiler). Please consult the documentation of the 20 | # deprecated API in order to know how to port your code away from it. 21 | DEFINES += QT_DEPRECATED_WARNINGS 22 | 23 | # You can also make your code fail to compile if you use deprecated APIs. 24 | # In order to do so, uncomment the following line. 25 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 26 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 27 | 28 | 29 | SOURCES += \ 30 | main.cpp \ 31 | huawei.cpp \ 32 | cfgfile.cpp \ 33 | xmlfile.cpp \ 34 | aescrypt.cpp 35 | 36 | 37 | HEADERS += \ 38 | huawei.h \ 39 | cfgfile.h \ 40 | xmlfile.h \ 41 | aescrypt.h 42 | 43 | 44 | FORMS += \ 45 | huawei.ui 46 | 47 | 48 | RESOURCES += \ 49 | res.qrc 50 | 51 | win32 { 52 | RC_FILE += \ 53 | logo.rc 54 | } 55 | 56 | #quzaip 57 | INCLUDEPATH += $$PWD/../quazip 58 | DEPENDPATH += $$PWD/../quazip 59 | win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../quazip/release/ -lquazip 60 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../quazip/debug/ -lquazipd 61 | else:unix: LIBS += -L$$OUT_PWD/../quazip/ -lquazip 62 | static { 63 | win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../quazip/release/libquazip.a 64 | else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../quazip/debug/libquazipd.a 65 | else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../quazip/release/quazip.lib 66 | else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../quazip/debug/quazipd.lib 67 | else:unix: PRE_TARGETDEPS += $$OUT_PWD/../quazip/libquazip.a 68 | } 69 | 70 | #xyssl 71 | win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../xyssl/release/ -lxyssl 72 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../xyssl/debug/ -lxyssl 73 | else:unix: LIBS += -L$$OUT_PWD/../xyssl/ -lxyssl 74 | 75 | INCLUDEPATH += $$PWD/../xyssl 76 | DEPENDPATH += $$PWD/../xyssl 77 | 78 | win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../xyssl/release/libxyssl.a 79 | else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../xyssl/debug/libxyssl.a 80 | else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../xyssl/release/xyssl.lib 81 | else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../xyssl/debug/xyssl.lib 82 | else:unix: PRE_TARGETDEPS += $$OUT_PWD/../xyssl/libxyssl.a 83 | 84 | #zlib 85 | INCLUDEPATH += $ZLIB 86 | LIBS += -L $ZLIB -lz 87 | -------------------------------------------------------------------------------- /huawei/huawei.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | HuaWei 4 | 5 | 6 | 7 | 0 8 | 0 9 | 364 10 | 322 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | 21 | 16777215 22 | 16777215 23 | 24 | 25 | 26 | true 27 | 28 | 29 | HuaWei Configuration Tools 30 | 31 | 32 | 33 | :/logo/huawei_logo.ico:/logo/huawei_logo.ico 34 | 35 | 36 | 37 | 38 | 39 | Encryption 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 12 48 | 49 | 50 | 51 | CFG 52 | 53 | 54 | Qt::AlignCenter 55 | 56 | 57 | 58 | 59 | 60 | 61 | Qt::Vertical 62 | 63 | 64 | QSizePolicy::Fixed 65 | 66 | 67 | 68 | 20 69 | 15 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | Decryption 78 | 79 | 80 | 81 | 82 | 83 | 84 | false 85 | 86 | 87 | Please enter the ciphertext 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | false 97 | 98 | 99 | Please specify the CFG file 100 | 101 | 102 | 103 | 104 | 105 | 106 | ... 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 12 117 | 118 | 119 | 120 | XML 121 | 122 | 123 | Qt::AlignCenter 124 | 125 | 126 | 127 | 128 | 129 | 130 | Encryption 131 | 132 | 133 | 134 | 135 | 136 | 137 | Qt::Vertical 138 | 139 | 140 | QSizePolicy::Fixed 141 | 142 | 143 | 144 | 20 145 | 5 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | true 156 | 157 | 158 | false 159 | 160 | 161 | Please specify the XML file 162 | 163 | 164 | 165 | 166 | 167 | 168 | ... 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | Decryption 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 12 186 | 187 | 188 | 189 | Text Decryption 190 | 191 | 192 | Qt::AlignCenter 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | $1 202 | 203 | 204 | 205 | 206 | 207 | 208 | true 209 | 210 | 211 | $2 212 | 213 | 214 | 215 | 216 | 217 | 218 | SU 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | Qt::Vertical 228 | 229 | 230 | QSizePolicy::Fixed 231 | 232 | 233 | 234 | 20 235 | 15 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | By:欲断魂 244 | 245 | 246 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | xml_line_edit_ 255 | xml_tool_button_ 256 | xml_en_button_ 257 | xml_de_button_ 258 | cfg_line_edit_ 259 | cfg_tool_button_ 260 | cfg_en_button_ 261 | cfg_de_button_ 262 | plain_line_edit_ 263 | de_1_button_ 264 | de_2_button_ 265 | de_su_button_ 266 | 267 | 268 | 269 | 270 | 271 | 272 | -------------------------------------------------------------------------------- /huawei/huawei_logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx1183618058/HuaWei-Optical-Network-Terminal-Decoder/6d430cdfbd5b29a6f6bf0e27b9ef055b95eb6dbb/huawei/huawei_logo.ico -------------------------------------------------------------------------------- /huawei/logo.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON "huawei_logo.ico" 2 | -------------------------------------------------------------------------------- /huawei/main.cpp: -------------------------------------------------------------------------------- 1 | #include "huawei.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | HuaWei w; 8 | w.setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint); 9 | w.setFixedSize(364, 322); 10 | w.show(); 11 | 12 | return a.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /huawei/qt_zh_CN.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx1183618058/HuaWei-Optical-Network-Terminal-Decoder/6d430cdfbd5b29a6f6bf0e27b9ef055b95eb6dbb/huawei/qt_zh_CN.qm -------------------------------------------------------------------------------- /huawei/res.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | huawei_logo.ico 4 | 5 | 6 | chinese.qm 7 | qt_zh_CN.qm 8 | 9 | 10 | -------------------------------------------------------------------------------- /huawei/xmlfile.h: -------------------------------------------------------------------------------- 1 | #ifndef XMLFILE_H 2 | #define XMLFILE_H 3 | 4 | #include 5 | #include 6 | 7 | class XmlFile 8 | { 9 | public: 10 | XmlFile() = default; 11 | XmlFile(const QString &in_file) : in_file_(in_file) {} 12 | int decrypt(const QString &out_file); 13 | int encrypt(const QString &out_file); 14 | int is_xml(); 15 | void rename(const QString &newname); 16 | void setIn_file(const QString &in_file); 17 | 18 | protected: 19 | uint32_t get_crc(const QString &in_file, int offset); 20 | int compress_gz(const QString &in_file, const QString &out_file); 21 | int extract_gz(const QString &in_file, const QString &out_file); 22 | 23 | private: 24 | QString in_file_; 25 | }; 26 | 27 | #endif // XMLFILE_H 28 | -------------------------------------------------------------------------------- /quazip/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # set all include directories for in and out of source builds 2 | include_directories( 3 | ${CMAKE_CURRENT_SOURCE_DIR} 4 | ${CMAKE_CURRENT_BINARY_DIR} 5 | ${ZLIB_INCLUDE_DIRS} 6 | ) 7 | 8 | file(GLOB SRCS "*.c" "*.cpp") 9 | file(GLOB PUBLIC_HEADERS "*.h") 10 | 11 | # Must be added to enable export macro 12 | ADD_DEFINITIONS(-DQUAZIP_BUILD) 13 | 14 | qt_wrap_cpp(MOC_SRCS ${PUBLIC_HEADERS}) 15 | set(SRCS ${SRCS} ${MOC_SRCS}) 16 | 17 | add_library(${QUAZIP_LIB_TARGET_NAME} SHARED ${SRCS}) 18 | add_library(quazip_static STATIC ${SRCS}) 19 | 20 | # Windows uses .lib extension for both static and shared library 21 | # *nix systems use different extensions for SHARED and STATIC library and by convention both libraries have the same name 22 | if (NOT WIN32) 23 | set_target_properties(quazip_static PROPERTIES OUTPUT_NAME quazip${QUAZIP_LIB_VERSION_SUFFIX}) 24 | endif () 25 | 26 | set_target_properties(${QUAZIP_LIB_TARGET_NAME} quazip_static PROPERTIES VERSION 1.0.0 SOVERSION 1 DEBUG_POSTFIX d) 27 | # Link against ZLIB_LIBRARIES if needed (on Windows this variable is empty) 28 | target_link_libraries(${QUAZIP_LIB_TARGET_NAME} quazip_static ${QT_QTMAIN_LIBRARY} ${QTCORE_LIBRARIES} ${ZLIB_LIBRARIES}) 29 | 30 | install(FILES ${PUBLIC_HEADERS} DESTINATION include/quazip${QUAZIP_LIB_VERSION_SUFFIX}) 31 | install(TARGETS ${QUAZIP_LIB_TARGET_NAME} quazip_static LIBRARY DESTINATION ${LIB_DESTINATION} ARCHIVE DESTINATION ${LIB_DESTINATION} RUNTIME DESTINATION ${LIB_DESTINATION}) 32 | -------------------------------------------------------------------------------- /quazip/JlCompress.h: -------------------------------------------------------------------------------- 1 | #ifndef JLCOMPRESSFOLDER_H_ 2 | #define JLCOMPRESSFOLDER_H_ 3 | 4 | /* 5 | Copyright (C) 2010 Roberto Pompermaier 6 | Copyright (C) 2005-2016 Sergey A. Tachenov 7 | 8 | This file is part of QuaZIP. 9 | 10 | QuaZIP is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU Lesser General Public License as published by 12 | the Free Software Foundation, either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | QuaZIP is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public License 21 | along with QuaZIP. If not, see . 22 | 23 | See COPYING file for the full LGPL text. 24 | 25 | Original ZIP package is copyrighted by Gilles Vollant and contributors, 26 | see quazip/(un)zip.h files for details. Basically it's the zlib license. 27 | */ 28 | 29 | #include "quazip.h" 30 | #include "quazipfile.h" 31 | #include "quazipfileinfo.h" 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | /// Utility class for typical operations. 38 | /** 39 | This class contains a number of useful static functions to perform 40 | simple operations, such as mass ZIP packing or extraction. 41 | */ 42 | class QUAZIP_EXPORT JlCompress { 43 | private: 44 | static QStringList extractDir(QuaZip &zip, const QString &dir); 45 | static QStringList getFileList(QuaZip *zip); 46 | static QString extractFile(QuaZip &zip, QString fileName, QString fileDest); 47 | static QStringList extractFiles(QuaZip &zip, const QStringList &files, const QString &dir); 48 | /// Compress a single file. 49 | /** 50 | \param zip Opened zip to compress the file to. 51 | \param fileName The full path to the source file. 52 | \param fileDest The full name of the file inside the archive. 53 | \return true if success, false otherwise. 54 | */ 55 | static bool compressFile(QuaZip* zip, QString fileName, QString fileDest); 56 | /// Compress a subdirectory. 57 | /** 58 | \param parentZip Opened zip containing the parent directory. 59 | \param dir The full path to the directory to pack. 60 | \param parentDir The full path to the directory corresponding to 61 | the root of the ZIP. 62 | \param recursive Whether to pack sub-directories as well or only 63 | files. 64 | \return true if success, false otherwise. 65 | */ 66 | static bool compressSubDir(QuaZip* parentZip, QString dir, QString parentDir, bool recursive, 67 | QDir::Filters filters); 68 | /// Extract a single file. 69 | /** 70 | \param zip The opened zip archive to extract from. 71 | \param fileName The full name of the file to extract. 72 | \param fileDest The full path to the destination file. 73 | \return true if success, false otherwise. 74 | */ 75 | static bool extractFile(QuaZip* zip, QString fileName, QString fileDest); 76 | /// Remove some files. 77 | /** 78 | \param listFile The list of files to remove. 79 | \return true if success, false otherwise. 80 | */ 81 | static bool removeFile(QStringList listFile); 82 | 83 | public: 84 | /// Compress a single file. 85 | /** 86 | \param fileCompressed The name of the archive. 87 | \param file The file to compress. 88 | \return true if success, false otherwise. 89 | */ 90 | static bool compressFile(QString fileCompressed, QString file); 91 | /// Compress a list of files. 92 | /** 93 | \param fileCompressed The name of the archive. 94 | \param files The file list to compress. 95 | \return true if success, false otherwise. 96 | */ 97 | static bool compressFiles(QString fileCompressed, QStringList files); 98 | /// Compress a whole directory. 99 | /** 100 | Does not compress hidden files. See compressDir(QString, QString, bool, QDir::Filters). 101 | 102 | \param fileCompressed The name of the archive. 103 | \param dir The directory to compress. 104 | \param recursive Whether to pack the subdirectories as well, or 105 | just regular files. 106 | \return true if success, false otherwise. 107 | */ 108 | static bool compressDir(QString fileCompressed, QString dir = QString(), bool recursive = true); 109 | /** 110 | * @brief Compress a whole directory. 111 | * 112 | * Unless filters are specified explicitly, packs 113 | * only regular non-hidden files (and subdirs, if @c recursive is true). 114 | * If filters are specified, they are OR-combined with 115 | * %QDir::AllDirs|%QDir::NoDotAndDotDot when searching for dirs 116 | * and with QDir::Files when searching for files. 117 | * 118 | * @param fileCompressed path to the resulting archive 119 | * @param dir path to the directory being compressed 120 | * @param recursive if true, then the subdirectories are packed as well 121 | * @param filters what to pack, filters are applied both when searching 122 | * for subdirs (if packing recursively) and when looking for files to pack 123 | * @return true on success, false otherwise 124 | */ 125 | static bool compressDir(QString fileCompressed, QString dir, 126 | bool recursive, QDir::Filters filters); 127 | 128 | public: 129 | /// Extract a single file. 130 | /** 131 | \param fileCompressed The name of the archive. 132 | \param fileName The file to extract. 133 | \param fileDest The destination file, assumed to be identical to 134 | \a file if left empty. 135 | \return The list of the full paths of the files extracted, empty on failure. 136 | */ 137 | static QString extractFile(QString fileCompressed, QString fileName, QString fileDest = QString()); 138 | /// Extract a list of files. 139 | /** 140 | \param fileCompressed The name of the archive. 141 | \param files The file list to extract. 142 | \param dir The directory to put the files to, the current 143 | directory if left empty. 144 | \return The list of the full paths of the files extracted, empty on failure. 145 | */ 146 | static QStringList extractFiles(QString fileCompressed, QStringList files, QString dir = QString()); 147 | /// Extract a whole archive. 148 | /** 149 | \param fileCompressed The name of the archive. 150 | \param dir The directory to extract to, the current directory if 151 | left empty. 152 | \return The list of the full paths of the files extracted, empty on failure. 153 | */ 154 | static QStringList extractDir(QString fileCompressed, QString dir = QString()); 155 | /// Get the file list. 156 | /** 157 | \return The list of the files in the archive, or, more precisely, the 158 | list of the entries, including both files and directories if they 159 | are present separately. 160 | */ 161 | static QStringList getFileList(QString fileCompressed); 162 | /// Extract a single file. 163 | /** 164 | \param ioDevice pointer to device with compressed data. 165 | \param fileName The file to extract. 166 | \param fileDest The destination file, assumed to be identical to 167 | \a file if left empty. 168 | \return The list of the full paths of the files extracted, empty on failure. 169 | */ 170 | static QString extractFile(QIODevice *ioDevice, QString fileName, QString fileDest = QString()); 171 | /// Extract a list of files. 172 | /** 173 | \param ioDevice pointer to device with compressed data. 174 | \param files The file list to extract. 175 | \param dir The directory to put the files to, the current 176 | directory if left empty. 177 | \return The list of the full paths of the files extracted, empty on failure. 178 | */ 179 | static QStringList extractFiles(QIODevice *ioDevice, QStringList files, QString dir = QString()); 180 | /// Extract a whole archive. 181 | /** 182 | \param ioDevice pointer to device with compressed data. 183 | \param dir The directory to extract to, the current directory if 184 | left empty. 185 | \return The list of the full paths of the files extracted, empty on failure. 186 | */ 187 | static QStringList extractDir(QIODevice *ioDevice, QString dir = QString()); 188 | /// Get the file list. 189 | /** 190 | \return The list of the files in the archive, or, more precisely, the 191 | list of the entries, including both files and directories if they 192 | are present separately. 193 | */ 194 | static QStringList getFileList(QIODevice *ioDevice); 195 | }; 196 | 197 | #endif /* JLCOMPRESSFOLDER_H_ */ 198 | -------------------------------------------------------------------------------- /quazip/crypt.h: -------------------------------------------------------------------------------- 1 | /* crypt.h -- base code for crypt/uncrypt ZIPfile 2 | 3 | 4 | Version 1.01e, February 12th, 2005 5 | 6 | Copyright (C) 1998-2005 Gilles Vollant 7 | 8 | This code is a modified version of crypting code in Infozip distribution 9 | 10 | The encryption/decryption parts of this source code (as opposed to the 11 | non-echoing password parts) were originally written in Europe. The 12 | whole source package can be freely distributed, including from the USA. 13 | (Prior to January 2000, re-export from the US was a violation of US law.) 14 | 15 | This encryption code is a direct transcription of the algorithm from 16 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This 17 | file (appnote.txt) is distributed with the PKZIP program (even in the 18 | version without encryption capabilities). 19 | 20 | If you don't need crypting in your application, just define symbols 21 | NOCRYPT and NOUNCRYPT. 22 | 23 | This code support the "Traditional PKWARE Encryption". 24 | 25 | The new AES encryption added on Zip format by Winzip (see the page 26 | http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong 27 | Encryption is not supported. 28 | */ 29 | 30 | #include "quazip_global.h" 31 | 32 | #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 33 | 34 | /*********************************************************************** 35 | * Return the next byte in the pseudo-random sequence 36 | */ 37 | static int decrypt_byte(unsigned long* pkeys, const z_crc_t FAR * pcrc_32_tab UNUSED) 38 | { 39 | //(void) pcrc_32_tab; /* avoid "unused parameter" warning */ 40 | unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 41 | * unpredictable manner on 16-bit systems; not a problem 42 | * with any known compiler so far, though */ 43 | 44 | temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; 45 | return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); 46 | } 47 | 48 | /*********************************************************************** 49 | * Update the encryption keys with the next byte of plain text 50 | */ 51 | static int update_keys(unsigned long* pkeys,const z_crc_t FAR * pcrc_32_tab,int c) 52 | { 53 | (*(pkeys+0)) = CRC32((*(pkeys+0)), c); 54 | (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 55 | (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; 56 | { 57 | register int keyshift = (int)((*(pkeys+1)) >> 24); 58 | (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); 59 | } 60 | return c; 61 | } 62 | 63 | 64 | /*********************************************************************** 65 | * Initialize the encryption keys and the random header according to 66 | * the given password. 67 | */ 68 | static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t FAR * pcrc_32_tab) 69 | { 70 | *(pkeys+0) = 305419896L; 71 | *(pkeys+1) = 591751049L; 72 | *(pkeys+2) = 878082192L; 73 | while (*passwd != '\0') { 74 | update_keys(pkeys,pcrc_32_tab,(int)*passwd); 75 | passwd++; 76 | } 77 | } 78 | 79 | #define zdecode(pkeys,pcrc_32_tab,c) \ 80 | (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) 81 | 82 | #define zencode(pkeys,pcrc_32_tab,c,t) \ 83 | (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 84 | 85 | #ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED 86 | 87 | #define RAND_HEAD_LEN 12 88 | /* "last resort" source for second part of crypt seed pattern */ 89 | # ifndef ZCR_SEED2 90 | # define ZCR_SEED2 3141592654UL /* use PI as default pattern */ 91 | # endif 92 | 93 | static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) 94 | const char *passwd; /* password string */ 95 | unsigned char *buf; /* where to write header */ 96 | int bufSize; 97 | unsigned long* pkeys; 98 | const z_crc_t FAR * pcrc_32_tab; 99 | unsigned long crcForCrypting; 100 | { 101 | int n; /* index in random header */ 102 | int t; /* temporary */ 103 | int c; /* random byte */ 104 | unsigned char header[RAND_HEAD_LEN-2]; /* random header */ 105 | static unsigned calls = 0; /* ensure different random header each time */ 106 | 107 | if (bufSize> 7) & 0xff; 122 | header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); 123 | } 124 | /* Encrypt random header (last two bytes is high word of crc) */ 125 | init_keys(passwd, pkeys, pcrc_32_tab); 126 | for (n = 0; n < RAND_HEAD_LEN-2; n++) 127 | { 128 | buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); 129 | } 130 | buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); 131 | buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); 132 | return n; 133 | } 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /quazip/debian/libquazip0.symbols: -------------------------------------------------------------------------------- 1 | libquazip.so.0 libquazip0 #MINVER# 2 | _Z24qiodevice_open_file_funcPvS_i@Base 0.4.4 3 | _Z24qiodevice_read_file_funcPvS_S_m@Base 0.4.4 4 | _Z24qiodevice_seek_file_funcPvS_mi@Base 0.4.4 5 | _Z24qiodevice_tell_file_funcPvS_@Base 0.4.4 6 | _Z25qiodevice_close_file_funcPvS_@Base 0.4.4 7 | _Z25qiodevice_error_file_funcPvS_@Base 0.4.4 8 | _Z25qiodevice_write_file_funcPvS_PKvm@Base 0.4.4 9 | _ZN10JlCompress10extractDirE7QStringS0_@Base 0.4.4 10 | _ZN10JlCompress11compressDirE7QStringS0_b@Base 0.4.4 11 | _ZN10JlCompress11extractFileE7QStringS0_S0_@Base 0.4.4 12 | _ZN10JlCompress11getFileListE7QString@Base 0.4.4 13 | _ZN10JlCompress12compressFileE7QStringS0_@Base 0.4.4 14 | _ZN10JlCompress12extractFilesE7QString11QStringListS0_@Base 0.4.4 15 | _ZN10JlCompress13compressFilesE7QString11QStringList@Base 0.4.4 16 | _ZN10QuaAdler325resetEv@Base 0.4.4 17 | _ZN10QuaAdler325valueEv@Base 0.4.4 18 | _ZN10QuaAdler326updateERK10QByteArray@Base 0.4.4 19 | _ZN10QuaAdler329calculateERK10QByteArray@Base 0.4.4 20 | _ZN10QuaAdler32C1Ev@Base 0.4.4 21 | _ZN10QuaAdler32C2Ev@Base 0.4.4 22 | _ZN10QuaZipFile10setZipNameERK7QString@Base 0.4.4 23 | _ZN10QuaZipFile11getFileInfoEP14QuaZipFileInfo@Base 0.4.4 24 | _ZN10QuaZipFile11setFileNameERK7QStringN6QuaZip15CaseSensitivityE@Base 0.4.4 25 | _ZN10QuaZipFile4openE6QFlagsIN9QIODevice12OpenModeFlagEE@Base 0.4.4 26 | _ZN10QuaZipFile4openE6QFlagsIN9QIODevice12OpenModeFlagEEPiS4_bPKc@Base 0.4.4 27 | _ZN10QuaZipFile4openE6QFlagsIN9QIODevice12OpenModeFlagEERK13QuaZipNewInfoPKcjiibiii@Base 0.4.4 28 | _ZN10QuaZipFile5closeEv@Base 0.4.4 29 | _ZN10QuaZipFile6setZipEP6QuaZip@Base 0.4.4 30 | _ZN10QuaZipFile8readDataEPcx@Base 0.4.4 31 | _ZN10QuaZipFile9writeDataEPKcx@Base 0.4.4 32 | _ZN10QuaZipFileC1EP6QuaZipP7QObject@Base 0.4.4 33 | _ZN10QuaZipFileC1EP7QObject@Base 0.4.4 34 | _ZN10QuaZipFileC1ERK7QStringP7QObject@Base 0.4.4 35 | _ZN10QuaZipFileC1ERK7QStringS2_N6QuaZip15CaseSensitivityEP7QObject@Base 0.4.4 36 | _ZN10QuaZipFileC1Ev@Base 0.4.4 37 | _ZN10QuaZipFileC2EP6QuaZipP7QObject@Base 0.4.4 38 | _ZN10QuaZipFileC2EP7QObject@Base 0.4.4 39 | _ZN10QuaZipFileC2ERK7QStringP7QObject@Base 0.4.4 40 | _ZN10QuaZipFileC2ERK7QStringS2_N6QuaZip15CaseSensitivityEP7QObject@Base 0.4.4 41 | _ZN10QuaZipFileC2Ev@Base 0.4.4 42 | _ZN10QuaZipFileD0Ev@Base 0.4.4 43 | _ZN10QuaZipFileD1Ev@Base 0.4.4 44 | _ZN10QuaZipFileD2Ev@Base 0.4.4 45 | _ZN13QuaZipNewInfo15setFileDateTimeERK7QString@Base 0.4.4 46 | _ZN13QuaZipNewInfoC1ERK7QString@Base 0.4.4 47 | _ZN13QuaZipNewInfoC1ERK7QStringS2_@Base 0.4.4 48 | _ZN13QuaZipNewInfoC2ERK7QString@Base 0.4.4 49 | _ZN13QuaZipNewInfoC2ERK7QStringS2_@Base 0.4.4 50 | _ZN13QuaZipNewInfoD1Ev@Base 0.4.4 51 | _ZN13QuaZipNewInfoD2Ev@Base 0.4.4 52 | _ZN14QuaZipFileInfoD1Ev@Base 0.4.4 53 | _ZN14QuaZipFileInfoD2Ev@Base 0.4.4 54 | _ZN6QuaZip10getUnzFileEv@Base 0.4.4 55 | _ZN6QuaZip10getZipFileEv@Base 0.4.4 56 | _ZN6QuaZip10setCommentERK7QString@Base 0.4.4 57 | _ZN6QuaZip10setZipNameERK7QString@Base 0.4.4 58 | _ZN6QuaZip11setIoDeviceEP9QIODevice@Base 0.4.4 59 | _ZN6QuaZip12goToNextFileEv@Base 0.4.4 60 | _ZN6QuaZip13goToFirstFileEv@Base 0.4.4 61 | _ZN6QuaZip14setCurrentFileERK7QStringNS_15CaseSensitivityE@Base 0.4.4 62 | _ZN6QuaZip15setCommentCodecEP10QTextCodec@Base 0.4.4 63 | _ZN6QuaZip15setCommentCodecEPKc@Base 0.4.4 64 | _ZN6QuaZip16setFileNameCodecEP10QTextCodec@Base 0.4.4 65 | _ZN6QuaZip16setFileNameCodecEPKc@Base 0.4.4 66 | _ZN6QuaZip31setDataDescriptorWritingEnabledEb@Base 0.4.4 67 | _ZN6QuaZip4openENS_4ModeEP19zlib_filefunc_def_s@Base 0.4.4 68 | _ZN6QuaZip5closeEv@Base 0.4.4 69 | _ZN6QuaZipC1EP9QIODevice@Base 0.4.4 70 | _ZN6QuaZipC1ERK7QString@Base 0.4.4 71 | _ZN6QuaZipC1Ev@Base 0.4.4 72 | _ZN6QuaZipC2EP9QIODevice@Base 0.4.4 73 | _ZN6QuaZipC2ERK7QString@Base 0.4.4 74 | _ZN6QuaZipC2Ev@Base 0.4.4 75 | _ZN6QuaZipD1Ev@Base 0.4.4 76 | _ZN6QuaZipD2Ev@Base 0.4.4 77 | _ZN7QStringD1Ev@Base 0.4.4 78 | _ZN7QStringD2Ev@Base 0.4.4 79 | _ZN8QuaCrc325resetEv@Base 0.4.4 80 | _ZN8QuaCrc325valueEv@Base 0.4.4 81 | _ZN8QuaCrc326updateERK10QByteArray@Base 0.4.4 82 | _ZN8QuaCrc329calculateERK10QByteArray@Base 0.4.4 83 | _ZN8QuaCrc32C1Ev@Base 0.4.4 84 | _ZN8QuaCrc32C2Ev@Base 0.4.4 85 | _ZNK10QuaZipFile10getZipNameEv@Base 0.4.4 86 | _ZNK10QuaZipFile10metaObjectEv@Base 0.4.4 87 | _ZNK10QuaZipFile11getFileNameEv@Base 0.4.4 88 | _ZNK10QuaZipFile11getZipErrorEv@Base 0.4.4 89 | _ZNK10QuaZipFile12isSequentialEv@Base 0.4.4 90 | _ZNK10QuaZipFile14bytesAvailableEv@Base 0.4.4 91 | _ZNK10QuaZipFile17getActualFileNameEv@Base 0.4.4 92 | _ZNK10QuaZipFile18getCaseSensitivityEv@Base 0.4.4 93 | _ZNK10QuaZipFile3posEv@Base 0.4.4 94 | _ZNK10QuaZipFile4sizeEv@Base 0.4.4 95 | _ZNK10QuaZipFile5atEndEv@Base 0.4.4 96 | _ZNK10QuaZipFile5csizeEv@Base 0.4.4 97 | _ZNK10QuaZipFile5isRawEv@Base 0.4.4 98 | _ZNK10QuaZipFile5usizeEv@Base 0.4.4 99 | _ZNK10QuaZipFile6getZipEv@Base 0.4.4 100 | _ZNK6QuaZip10getCommentEv@Base 0.4.4 101 | _ZNK6QuaZip10getZipNameEv@Base 0.4.4 102 | _ZNK6QuaZip11getIoDeviceEv@Base 0.4.4 103 | _ZNK6QuaZip11getZipErrorEv@Base 0.4.4 104 | _ZNK6QuaZip14hasCurrentFileEv@Base 0.4.4 105 | _ZNK6QuaZip15getCommentCodecEv@Base 0.4.4 106 | _ZNK6QuaZip15getEntriesCountEv@Base 0.4.4 107 | _ZNK6QuaZip15getFileInfoListEv@Base 0.4.4 108 | _ZNK6QuaZip15getFileNameListEv@Base 0.4.4 109 | _ZNK6QuaZip16getFileNameCodecEv@Base 0.4.4 110 | _ZNK6QuaZip18getCurrentFileInfoEP14QuaZipFileInfo@Base 0.4.4 111 | _ZNK6QuaZip18getCurrentFileNameEv@Base 0.4.4 112 | _ZNK6QuaZip30isDataDescriptorWritingEnabledEv@Base 0.4.4 113 | _ZNK6QuaZip6isOpenEv@Base 0.4.4 114 | _ZNK6QuaZip7getModeEv@Base 0.4.4 115 | _ZTI10QuaAdler32@Base 0.4.4 116 | _ZTI10QuaZipFile@Base 0.4.4 117 | _ZTI13QuaChecksum32@Base 0.4.4 118 | _ZTI8QuaCrc32@Base 0.4.4 119 | _ZTS10QuaAdler32@Base 0.4.4 120 | _ZTS10QuaZipFile@Base 0.4.4 121 | _ZTS13QuaChecksum32@Base 0.4.4 122 | _ZTS8QuaCrc32@Base 0.4.4 123 | _ZTV10QuaAdler32@Base 0.4.4 124 | _ZTV10QuaZipFile@Base 0.4.4 125 | _ZTV13QuaChecksum32@Base 0.4.4 126 | _ZTV8QuaCrc32@Base 0.4.4 127 | fill_qiodevice_filefunc@Base 0.4.4 128 | unzClose@Base 0.4.4 129 | unzCloseCurrentFile@Base 0.4.4 130 | unzGetCurrentFileInfo@Base 0.4.4 131 | unzGetFilePos@Base 0.4.4 132 | unzGetGlobalComment@Base 0.4.4 133 | unzGetGlobalInfo@Base 0.4.4 134 | unzGetLocalExtrafield@Base 0.4.4 135 | unzGetOffset@Base 0.4.4 136 | unzGoToFilePos@Base 0.4.4 137 | unzGoToFirstFile@Base 0.4.4 138 | unzGoToNextFile@Base 0.4.4 139 | unzLocateFile@Base 0.4.4 140 | unzOpen2@Base 0.4.4 141 | unzOpen@Base 0.4.4 142 | unzOpenCurrentFile2@Base 0.4.4 143 | unzOpenCurrentFile3@Base 0.4.4 144 | unzOpenCurrentFile@Base 0.4.4 145 | unzOpenCurrentFilePassword@Base 0.4.4 146 | unzReadCurrentFile@Base 0.4.4 147 | unzSetOffset@Base 0.4.4 148 | unzStringFileNameCompare@Base 0.4.4 149 | unz_copyright@Base 0.4.4 150 | unzeof@Base 0.4.4 151 | unztell@Base 0.4.4 152 | zipClearFlags@Base 0.4.4 153 | zipClose@Base 0.4.4 154 | zipCloseFileInZip@Base 0.4.4 155 | zipCloseFileInZipRaw@Base 0.4.4 156 | zipOpen2@Base 0.4.4 157 | zipOpen@Base 0.4.4 158 | zipOpenNewFileInZip2@Base 0.4.4 159 | zipOpenNewFileInZip3@Base 0.4.4 160 | zipOpenNewFileInZip@Base 0.4.4 161 | zipSetFlags@Base 0.4.4 162 | zipWriteInFileInZip@Base 0.4.4 163 | zip_copyright@Base 0.4.4 164 | -------------------------------------------------------------------------------- /quazip/doc/faq.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * \page faq QuaZip FAQ 3 | * 4 | * 12 | * 13 | * \anchor faq-non-QIODevice Q. Is there any way to use QuaZipFile in Qt 14 | * where you are supposed to use normal (non-zipped) file, but not 15 | * through QIODevice API? 16 | * 17 | * A. Usually not. For example, if you are passing file name to some 18 | * database driver (like SQLite), Qt usually just passes this name down 19 | * to the 3rd-party library, which is usually does not know anything 20 | * about QIODevice and therefore there is no way to pass QuaZipFile as 21 | * normal file. However, if we are talking about some place where you 22 | * pass file name, and then indirectly use QFile to open it, then it is 23 | * a good idea to make overloaded method, which accepts a QIODevice 24 | * pointer. Then you would be able to pass QuaZipFile as well as many 25 | * other nice things such as QBuffer or QProcess. 26 | * 27 | * \anchor faq-zip64 Q. Can QuaZIP handle files larger than 4GB? What 28 | * about zip64 standard? 29 | * 30 | * A. Starting with version 0.6, QuaZIP uses Minizip 1.1 with zip64 31 | * support which should handle large files perfectly. The zip64 support 32 | * in Minizip looks like it's not 100% conforming to the standard, but 33 | * 3rd party tools seem to have no problem with the resulting archives. 34 | * 35 | * \anchor faq-seekable Q. Can QuaZIP write archives to a sequential QIODevice like QTcpSocket? 36 | * 37 | * A. Not yet. It is not supported by vanilla Minizip (the back-end 38 | * QuaZIP uses), although theoretically possible according to the ZIP 39 | * standard. It would require some Minizip modifications that would 40 | * allow it to detect non-seekable I/O and produce necessary output 41 | * structures. QuaZIP already writes data descriptor which is necessary 42 | * for non-seekable I/O. The only thing that is apparently left is to 43 | * make Minizip fill local headers with correct values and forget about 44 | * seeking after closing the file. 45 | **/ 46 | -------------------------------------------------------------------------------- /quazip/doc/index.dox: -------------------------------------------------------------------------------- 1 | /** 2 | * \mainpage QuaZIP - Qt/C++ wrapper for ZIP/UNZIP package 3 | * 4 | \htmlonly 5 | Powered by SourceForge.net 6 | \endhtmlonly 7 | * \section overview Overview 8 | * 9 | * QuaZIP is a simple C++ wrapper over Gilles Vollant's ZIP/UNZIP 11 | * package that can be used to access ZIP archives. It uses the Qt toolkit. 13 | * 14 | * If you do not know what Qt is, you have two options: 15 | * - Just forget about QuaZIP. 16 | * - Learn more about Qt by downloading it and/or reading the excellent official Qt documentation 18 | * 19 | * The choice is yours, but if you are really interested in 20 | * cross-platform (Windows/Linux/BSD/UNIX/Mac/Others) software 21 | * development, I would definitely recommend you the latter ^_^ 22 | * 23 | * QuaZIP allows you to access files inside ZIP archives using QIODevice 24 | * API, and - yes! - that means that you can also use QTextStream, 25 | * QDataStream or whatever you would like to use on your zipped files. 26 | * 27 | * QuaZIP provides complete abstraction of the ZIP/UNZIP API, for both 28 | * reading from and writing to ZIP archives. 29 | * 30 | * \section download Download QuaZIP 31 | * 32 | * Downloads are available from QuaZIP project's page 34 | * at SourceForge.net. 35 | * 36 | * \section platforms Platforms supported 37 | * 38 | * QuaZIP has been currently tested on the following platforms: 39 | * - linux-g++ (Ubuntu 11.10, Qt 4.7.4) 40 | * - freebsd-g++ (Qt 4.0.0 41 | * - hpux-acc (HP-UX 11.11) 42 | * - hpux-g++ (HP-UX 11.11) 43 | * - win32-g++ (MinGW) 44 | * - win32-msvc2010 (MS VS 2010 Express, Qt 4.8.4) 45 | * - win32-msvc2010 (Qt Creator, Qt 5.0.1) 46 | * - win32-msvc2012 (Qt Creator, Qt 5.2.0) 47 | * - some Symbian version, reportedly 48 | * 49 | * No testing has been officially done on other systems. Of course, patches to 50 | * make it work on any platform that it currently does not work on are 51 | * always welcome! 52 | * 53 | * \section whats-new What is new in this version of QuaZIP? 54 | * 55 | * See the NEWS.txt file supplied with the distribution. 56 | * 57 | * \section Requirements 58 | * 59 | * Just zlib and Qt 4/5. Well, Qt 4 60 | * depends on zlib anyway, but you will need zlib headers to compile 61 | * QuaZIP. With Qt5 sometimes you need the zlib library as well (on 62 | * Windows, for example). 63 | * 64 | * \section building Building, testing and installing 65 | * 66 | * \note Instructions given in this section assume that you are 67 | * using some UNIX dialect, but the build process should be very similar 68 | * on win32-g++ platform too. On other platforms it's essentially the 69 | * same process, maybe with some qmake adjustments not specific to 70 | * QuaZIP itself. 71 | * 72 | * To build the library, run: 73 | \verbatim 74 | $ cd /wherever/quazip/source/is/quazip-x.y.z/quazip 75 | $ qmake [PREFIX=where-to-install] 76 | $ make 77 | \endverbatim 78 | * 79 | * Make sure that you have Qt 4/5 installed with all required headers and 80 | * utilities (that is, including the 'dev' or 'devel' package on Linux) 81 | * and that you run qmake utility of the Qt 4, not some other version 82 | * you may have already installed (you may need to type full path to 83 | * qmake like /usr/local/qt4/bin/qmake). 84 | * 85 | * To reconfigure (with another PREFIX, for example), just run qmake 86 | * with appropriate arguments again. 87 | * 88 | * If you need to specify additional include path or libraries, use 89 | * qmake features (see qmake reference in the Qt documentation). For 90 | * example: 91 | * 92 | \verbatim 93 | $ qmake LIBS+=-L/usr/local/zlib/lib INCLUDEPATH+=/usr/local/zlib/include 94 | \endverbatim 95 | * (note abscence of "-I" before the include path and the presence of "-L" 96 | * before the lib path) 97 | * 98 | * Also note that you may or may not need to define ZLIB_WINAPI (qmake 99 | * DEFINES+=ZLIB_WINAPI) when linking to zlib on Windows, depending on 100 | * how zlib was built (generally, if using zlibwapi.dll, this define is 101 | * needed). 102 | * 103 | * To install compiled library: 104 | \verbatim 105 | $ make install 106 | \endverbatim 107 | * 108 | * By default, QuaZIP compiles as a DLL/SO, but you have other 109 | * options: 110 | * - Just copy appropriate source files to your project and use them, 111 | * but you need to define QUAZIP_STATIC before including any QuaZIP 112 | * headers (best done as a compiler option). This will save you from 113 | * possible side effects of importing/exporting QuaZIP symbols. 114 | * - Compile it as a static library using CONFIG += staticlib qmake 115 | * option. QUAZIP_STATIC is defined automatically by qmake in this case. 116 | * 117 | * Binary compatibility is guaranteed between minor releases starting 118 | * with version 0.5, thanks to the Pimpl idiom. That is, the next binary 119 | * incompatible version will be 1.x. 120 | * 121 | * \section test Testing 122 | * 123 | * To check if QuaZIP's basic features work OK on your platform, you may 124 | * wish to compile the test suite provided in test directory: 125 | \verbatim 126 | $ cd /wherever/quazip/source/is/quazip-x.y.z/qztest 127 | $ qmake 128 | $ make 129 | $ ./qztest 130 | \endverbatim 131 | * 132 | * Note that the test suite looks for the quazip library in the "quazip" 133 | * folder of the project ("../quazip"), but you may wish to use LIBS 134 | * for some systems (Windows often puts the library in the separate 135 | * "debug" or "release" directory). If you wish to use the quazip 136 | * version that's already installed, provide the appropriate path. 137 | * 138 | * On some systems you may need to set PATH, LD_LIBRARY_PATH or 139 | * SHLIB_PATH to get "qztest" to actually run. 140 | * 141 | * If everything went fine, the test suite should report a lot of PASS 142 | * messages. If something goes wrong, it will provide details and a 143 | * warning that some tests failed. 144 | * 145 | * \section using Using 146 | * 147 | * See \ref usage "usage page". 148 | * 149 | * \section contacts Authors and contacts 150 | * 151 | * This wrapper has been written by Sergey A. Tachenov, AKA Alqualos. 152 | * This is my first open source project, so it may suck, but I did not 153 | * find anything like that, so I just had no other choice but to write 154 | * it. 155 | * 156 | * If you have anything to say to me about QuaZIP library, feel free to 157 | * do so (read the \ref faq first, though). I can not promise, 158 | * though, that I fix all the bugs you report in, add any features you 159 | * want, or respond to your critics, or respond to your feedback at all. 160 | * I may be busy, I may be tired of working on QuaZIP, I may be even 161 | * dead already (you never know...). 162 | * 163 | * To report bugs or to post ideas about what should be done, use 164 | * SourceForge.net's trackers. 166 | * If you want to send me a private message, use my e-mail address 167 | * stachenov@gmail.com. 168 | * 169 | * Do not use e-mail to report bugs, please. Reporting bugs and problems 170 | * with the SourceForge.net's bug report system has that advantage that 171 | * it is visible to public, and I can always search for open tickets 172 | * that were created long ago. It is highly unlikely that I will search 173 | * my mail for that kind of stuff, so if a bug reported by mail isn't 174 | * fixed immediately, it will likely be forgotten forever. 175 | * 176 | * Copyright (C) 2005-2014 Sergey A. Tachenov and contributors 177 | **/ 178 | -------------------------------------------------------------------------------- /quazip/doc/usage.dox: -------------------------------------------------------------------------------- 1 | /** \page usage Usage 2 | * 3 | * This page provides general information on QuaZIP usage. See classes 4 | * QuaZip and QuaZipFile for the detailed documentation on what can 5 | * QuaZIP do and what it can not. Also, reading comments in the zip.h and 6 | * unzip.h files (taken from the original ZIP/UNZIP package) is always a 7 | * good idea too. After all, QuaZIP is just a wrapper with a few 8 | * convenience extensions and reimplementations. 9 | * 10 | * QuaZip is a class representing ZIP archive, QuaZipFile represents a 11 | * file inside archive and subclasses QIODevice as well. One limitation 12 | * is that there can be only one instance of QuaZipFile per QuaZip 13 | * instance, which kind of makes it confusing why there are two classes 14 | * instead of one. This is actually no more than an API design mistake. 15 | * 16 | * \section terminology Terminology 17 | * 18 | * "QuaZIP" means whole this library, while "QuaZip" (note the 19 | * lower case) is just one class in it. 20 | * 21 | * "ZIP/UNZIP API" or "minizip" means the original API of the Gilles 22 | * Vollant's ZIP/UNZIP package. It was slightly modified to better 23 | * integrate with Qt. These modifications are not source or binary 24 | * compatible with the official minizip release, which means you can't 25 | * just drop the newer minizip version into QuaZIP sources and make it 26 | * work. 27 | * 28 | * "ZIP", "ZIP archive" or "ZIP file" means any ZIP archive. Typically 29 | * this is a plain file with ".zip" (or ".ZIP") file name suffix, but it 30 | * can also be any seekable QIODevice (say, QBuffer, but not 31 | * QTcpSocket). 32 | * 33 | * "A file inside archive", "a file inside ZIP" or something like that 34 | * means file either being read or written from/to some ZIP archive. 35 | * 36 | * \section error-handling Error handling 37 | * 38 | * Almost any call to ZIP/UNZIP API return some error code. Most of the 39 | * original API's error checking could be done in this wrapper as well, 40 | * but it would cause unnecessary code bloating without any benefit. So, 41 | * QuaZIP only checks for situations that ZIP/UNZIP API can not check 42 | * for. For example, ZIP/UNZIP API has no "ZIP open mode" concept 43 | * because read and write modes are completely separated. On the other 44 | * hand, to avoid creating classes like "QuaZipReader", "QuaZipWriter" 45 | * or something like that, QuaZIP introduces "ZIP open mode" concept 46 | * instead, thus making it possible to use one class (QuaZip) for both 47 | * reading and writing. But this leads to additional open mode checks 48 | * which are not done in ZIP/UNZIP package. 49 | * 50 | * Therefore, error checking is two-level (QuaZIP's level and ZIP/UNZIP 51 | * API level), which sometimes can be confusing, so here are some 52 | * advices on how the error checking should be properly done: 53 | * 54 | * - Both QuaZip and QuaZipFile have getZipError() function, which return 55 | * error code of the last ZIP/UNZIP API call. Most function calls 56 | * reset error code to UNZ_OK on success and set error code on 57 | * failure. Some functions do not reset error code. Most of them are 58 | * \c const and do not access ZIP archive in any way. Some, on the 59 | * other hand, \em do access ZIP archive, but do not reset or set 60 | * error code. For example, QuaZipFile::pos() function. Such functions 61 | * are explicitly marked in the documentation. 62 | * - Most functions have their own way to report errors, by returning a 63 | * null string, negative value or \c false. If such a function returns 64 | * error value, call getZipError() to get more information about 65 | * error. See "zip.h" and "unzip.h" of the ZIP/UNZIP package for error 66 | * codes. 67 | * - If the function returns error-stating value (like \c false), but 68 | * getZipError() returns UNZ_OK, it means that you did something 69 | * obviously wrong. For example, tried to write in the archive open 70 | * for reading or not open at all. You better just not do that! 71 | * Most functions also issue a warning using qWarning() function in 72 | * such cases. See documentation for a specific function for details 73 | * on when it should not be called. 74 | * 75 | * I know that this is somewhat messy, but I could not find a better way 76 | * to do all the error handling. 77 | **/ 78 | -------------------------------------------------------------------------------- /quazip/ioapi.h: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 3 | 4 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 5 | 6 | Modifications for Zip64 support 7 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 8 | 9 | Modified by Sergey A. Tachenov to allow QIODevice API usage. 10 | 11 | For more info read MiniZip_info.txt 12 | 13 | Changes 14 | 15 | Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this) 16 | Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. 17 | More if/def section may be needed to support other platforms 18 | Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. 19 | (but you should use iowin32.c for windows instead) 20 | 21 | */ 22 | 23 | #ifndef _ZLIBIOAPI64_H 24 | #define _ZLIBIOAPI64_H 25 | 26 | #if (!defined(_WIN32)) && (!defined(WIN32)) 27 | 28 | // Linux needs this to support file operation on files larger then 4+GB 29 | // But might need better if/def to select just the platforms that needs them. 30 | 31 | #ifndef __USE_FILE_OFFSET64 32 | #define __USE_FILE_OFFSET64 33 | #endif 34 | #ifndef __USE_LARGEFILE64 35 | #define __USE_LARGEFILE64 36 | #endif 37 | #ifndef _LARGEFILE64_SOURCE 38 | #define _LARGEFILE64_SOURCE 39 | #endif 40 | #ifndef _FILE_OFFSET_BIT 41 | #define _FILE_OFFSET_BIT 64 42 | #endif 43 | #endif 44 | 45 | #include 46 | #include 47 | #include "zlib.h" 48 | 49 | #if defined(USE_FILE32API) 50 | #define fopen64 fopen 51 | #define ftello64 ftell 52 | #define fseeko64 fseek 53 | #else 54 | #ifdef _MSC_VER 55 | #define fopen64 fopen 56 | #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) 57 | #define ftello64 _ftelli64 58 | #define fseeko64 _fseeki64 59 | #else // old MSC 60 | #define ftello64 ftell 61 | #define fseeko64 fseek 62 | #endif 63 | #endif 64 | #endif 65 | 66 | /* 67 | #ifndef ZPOS64_T 68 | #ifdef _WIN32 69 | #define ZPOS64_T fpos_t 70 | #else 71 | #include 72 | #define ZPOS64_T uint64_t 73 | #endif 74 | #endif 75 | */ 76 | 77 | #ifdef HAVE_MINIZIP64_CONF_H 78 | #include "mz64conf.h" 79 | #endif 80 | 81 | /* a type choosen by DEFINE */ 82 | #ifdef HAVE_64BIT_INT_CUSTOM 83 | typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; 84 | #else 85 | #ifdef HAS_STDINT_H 86 | #include "stdint.h" 87 | typedef uint64_t ZPOS64_T; 88 | #else 89 | 90 | 91 | #if defined(_MSC_VER) || defined(__BORLANDC__) 92 | typedef unsigned __int64 ZPOS64_T; 93 | #else 94 | typedef unsigned long long int ZPOS64_T; 95 | #endif 96 | #endif 97 | #endif 98 | 99 | 100 | 101 | #ifdef __cplusplus 102 | extern "C" { 103 | #endif 104 | 105 | #ifndef OF 106 | #define OF _Z_OF 107 | #endif 108 | 109 | #define ZLIB_FILEFUNC_SEEK_CUR (1) 110 | #define ZLIB_FILEFUNC_SEEK_END (2) 111 | #define ZLIB_FILEFUNC_SEEK_SET (0) 112 | 113 | #define ZLIB_FILEFUNC_MODE_READ (1) 114 | #define ZLIB_FILEFUNC_MODE_WRITE (2) 115 | #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 116 | 117 | #define ZLIB_FILEFUNC_MODE_EXISTING (4) 118 | #define ZLIB_FILEFUNC_MODE_CREATE (8) 119 | 120 | 121 | #ifndef ZCALLBACK 122 | #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 123 | #define ZCALLBACK CALLBACK 124 | #else 125 | #define ZCALLBACK 126 | #endif 127 | #endif 128 | 129 | 130 | 131 | 132 | typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, voidpf file, int mode)); 133 | typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 134 | typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 135 | typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 136 | typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 137 | 138 | typedef uLong (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 139 | typedef int (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 140 | 141 | 142 | /* here is the "old" 32 bits structure structure */ 143 | typedef struct zlib_filefunc_def_s 144 | { 145 | open_file_func zopen_file; 146 | read_file_func zread_file; 147 | write_file_func zwrite_file; 148 | tell_file_func ztell_file; 149 | seek_file_func zseek_file; 150 | close_file_func zclose_file; 151 | testerror_file_func zerror_file; 152 | voidpf opaque; 153 | } zlib_filefunc_def; 154 | 155 | typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); 156 | typedef int (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 157 | typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, voidpf file, int mode)); 158 | 159 | typedef struct zlib_filefunc64_def_s 160 | { 161 | open64_file_func zopen64_file; 162 | read_file_func zread_file; 163 | write_file_func zwrite_file; 164 | tell64_file_func ztell64_file; 165 | seek64_file_func zseek64_file; 166 | close_file_func zclose_file; 167 | testerror_file_func zerror_file; 168 | voidpf opaque; 169 | close_file_func zfakeclose_file; // for no-auto-close flag 170 | } zlib_filefunc64_def; 171 | 172 | void fill_qiodevice64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); 173 | void fill_qiodevice_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 174 | 175 | /* now internal definition, only for zip.c and unzip.h */ 176 | typedef struct zlib_filefunc64_32_def_s 177 | { 178 | zlib_filefunc64_def zfile_func64; 179 | open_file_func zopen32_file; 180 | tell_file_func ztell32_file; 181 | seek_file_func zseek32_file; 182 | } zlib_filefunc64_32_def; 183 | 184 | 185 | #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 186 | #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 187 | //#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) 188 | //#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) 189 | #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) 190 | #define ZFAKECLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zfakeclose_file)) ((filefunc).zfile_func64.opaque,filestream)) 191 | #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) 192 | 193 | voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf file,int mode)); 194 | int call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); 195 | ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); 196 | 197 | void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); 198 | 199 | #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) 200 | #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) 201 | #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) 202 | 203 | #ifdef __cplusplus 204 | } 205 | #endif 206 | 207 | #endif 208 | -------------------------------------------------------------------------------- /quazip/quaadler32.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2010 Adam Walczak 3 | Copyright (C) 2005-2014 Sergey A. Tachenov 4 | 5 | This file is part of QuaZIP. 6 | 7 | QuaZIP is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation, either version 2.1 of the License, or 10 | (at your option) any later version. 11 | 12 | QuaZIP is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with QuaZIP. If not, see . 19 | 20 | See COPYING file for the full LGPL text. 21 | 22 | Original ZIP package is copyrighted by Gilles Vollant and contributors, 23 | see quazip/(un)zip.h files for details. Basically it's the zlib license. 24 | */ 25 | 26 | #include "quaadler32.h" 27 | 28 | #include "zlib.h" 29 | 30 | QuaAdler32::QuaAdler32() 31 | { 32 | reset(); 33 | } 34 | 35 | quint32 QuaAdler32::calculate(const QByteArray &data) 36 | { 37 | return adler32( adler32(0L, Z_NULL, 0), (const Bytef*)data.data(), data.size() ); 38 | } 39 | 40 | void QuaAdler32::reset() 41 | { 42 | checksum = adler32(0L, Z_NULL, 0); 43 | } 44 | 45 | void QuaAdler32::update(const QByteArray &buf) 46 | { 47 | checksum = adler32( checksum, (const Bytef*)buf.data(), buf.size() ); 48 | } 49 | 50 | quint32 QuaAdler32::value() 51 | { 52 | return checksum; 53 | } 54 | -------------------------------------------------------------------------------- /quazip/quaadler32.h: -------------------------------------------------------------------------------- 1 | #ifndef QUAADLER32_H 2 | #define QUAADLER32_H 3 | 4 | /* 5 | Copyright (C) 2010 Adam Walczak 6 | Copyright (C) 2005-2014 Sergey A. Tachenov 7 | 8 | This file is part of QuaZIP. 9 | 10 | QuaZIP is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU Lesser General Public License as published by 12 | the Free Software Foundation, either version 2.1 of the License, or 13 | (at your option) any later version. 14 | 15 | QuaZIP is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public License 21 | along with QuaZIP. If not, see . 22 | 23 | See COPYING file for the full LGPL text. 24 | 25 | Original ZIP package is copyrighted by Gilles Vollant and contributors, 26 | see quazip/(un)zip.h files for details. Basically it's the zlib license. 27 | */ 28 | 29 | #include 30 | 31 | #include "quachecksum32.h" 32 | 33 | /// Adler32 checksum 34 | /** \class QuaAdler32 quaadler32.h 35 | * This class wrappers the adler32 function with the QuaChecksum32 interface. 36 | * See QuaChecksum32 for more info. 37 | */ 38 | class QUAZIP_EXPORT QuaAdler32 : public QuaChecksum32 39 | { 40 | 41 | public: 42 | QuaAdler32(); 43 | 44 | quint32 calculate(const QByteArray &data); 45 | 46 | void reset(); 47 | void update(const QByteArray &buf); 48 | quint32 value(); 49 | 50 | private: 51 | quint32 checksum; 52 | }; 53 | 54 | #endif //QUAADLER32_H 55 | -------------------------------------------------------------------------------- /quazip/quachecksum32.h: -------------------------------------------------------------------------------- 1 | #ifndef QUACHECKSUM32_H 2 | #define QUACHECKSUM32_H 3 | 4 | /* 5 | Copyright (C) 2005-2014 Sergey A. Tachenov 6 | 7 | This file is part of QuaZIP. 8 | 9 | QuaZIP is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 2.1 of the License, or 12 | (at your option) any later version. 13 | 14 | QuaZIP is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with QuaZIP. If not, see . 21 | 22 | See COPYING file for the full LGPL text. 23 | 24 | Original ZIP package is copyrighted by Gilles Vollant and contributors, 25 | see quazip/(un)zip.h files for details. Basically it's the zlib license. 26 | */ 27 | 28 | #include 29 | #include "quazip_global.h" 30 | 31 | /// Checksum interface. 32 | /** \class QuaChecksum32 quachecksum32.h 33 | * This is an interface for 32 bit checksums. 34 | * Classes implementing this interface can calcunate a certin 35 | * checksum in a single step: 36 | * \code 37 | * QChecksum32 *crc32 = new QuaCrc32(); 38 | * rasoult = crc32->calculate(data); 39 | * \endcode 40 | * or by streaming the data: 41 | * \code 42 | * QChecksum32 *crc32 = new QuaCrc32(); 43 | * while(!fileA.atEnd()) 44 | * crc32->update(fileA.read(bufSize)); 45 | * resoultA = crc32->value(); 46 | * crc32->reset(); 47 | * while(!fileB.atEnd()) 48 | * crc32->update(fileB.read(bufSize)); 49 | * resoultB = crc32->value(); 50 | * \endcode 51 | */ 52 | class QUAZIP_EXPORT QuaChecksum32 53 | { 54 | 55 | public: 56 | ///Calculates the checksum for data. 57 | /** \a data source data 58 | * \return data checksum 59 | * 60 | * This function has no efect on the value returned by value(). 61 | */ 62 | virtual quint32 calculate(const QByteArray &data) = 0; 63 | 64 | ///Resets the calculation on a checksun for a stream. 65 | virtual void reset() = 0; 66 | 67 | ///Updates the calculated checksum for the stream 68 | /** \a buf next portion of data from the stream 69 | */ 70 | virtual void update(const QByteArray &buf) = 0; 71 | 72 | ///Value of the checksum calculated for the stream passed throw update(). 73 | /** \return checksum 74 | */ 75 | virtual quint32 value() = 0; 76 | }; 77 | 78 | #endif //QUACHECKSUM32_H 79 | -------------------------------------------------------------------------------- /quazip/quacrc32.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2014 Sergey A. Tachenov 3 | 4 | This file is part of QuaZIP. 5 | 6 | QuaZIP is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 2.1 of the License, or 9 | (at your option) any later version. 10 | 11 | QuaZIP is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with QuaZIP. If not, see . 18 | 19 | See COPYING file for the full LGPL text. 20 | 21 | Original ZIP package is copyrighted by Gilles Vollant and contributors, 22 | see quazip/(un)zip.h files for details. Basically it's the zlib license. 23 | */ 24 | 25 | #include "quacrc32.h" 26 | 27 | #include "zlib.h" 28 | 29 | QuaCrc32::QuaCrc32() 30 | { 31 | reset(); 32 | } 33 | 34 | quint32 QuaCrc32::calculate(const QByteArray &data) 35 | { 36 | return crc32( crc32(0L, Z_NULL, 0), (const Bytef*)data.data(), data.size() ); 37 | } 38 | 39 | void QuaCrc32::reset() 40 | { 41 | checksum = crc32(0L, Z_NULL, 0); 42 | } 43 | 44 | void QuaCrc32::update(const QByteArray &buf) 45 | { 46 | checksum = crc32( checksum, (const Bytef*)buf.data(), buf.size() ); 47 | } 48 | 49 | quint32 QuaCrc32::value() 50 | { 51 | return checksum; 52 | } 53 | -------------------------------------------------------------------------------- /quazip/quacrc32.h: -------------------------------------------------------------------------------- 1 | #ifndef QUACRC32_H 2 | #define QUACRC32_H 3 | 4 | /* 5 | Copyright (C) 2005-2014 Sergey A. Tachenov 6 | 7 | This file is part of QuaZIP. 8 | 9 | QuaZIP is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 2.1 of the License, or 12 | (at your option) any later version. 13 | 14 | QuaZIP is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with QuaZIP. If not, see . 21 | 22 | See COPYING file for the full LGPL text. 23 | 24 | Original ZIP package is copyrighted by Gilles Vollant and contributors, 25 | see quazip/(un)zip.h files for details. Basically it's the zlib license. 26 | */ 27 | 28 | #include "quachecksum32.h" 29 | 30 | ///CRC32 checksum 31 | /** \class QuaCrc32 quacrc32.h 32 | * This class wrappers the crc32 function with the QuaChecksum32 interface. 33 | * See QuaChecksum32 for more info. 34 | */ 35 | class QUAZIP_EXPORT QuaCrc32 : public QuaChecksum32 { 36 | 37 | public: 38 | QuaCrc32(); 39 | 40 | quint32 calculate(const QByteArray &data); 41 | 42 | void reset(); 43 | void update(const QByteArray &buf); 44 | quint32 value(); 45 | 46 | private: 47 | quint32 checksum; 48 | }; 49 | 50 | #endif //QUACRC32_H 51 | -------------------------------------------------------------------------------- /quazip/quagzipfile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2014 Sergey A. Tachenov 3 | 4 | This file is part of QuaZIP. 5 | 6 | QuaZIP is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 2.1 of the License, or 9 | (at your option) any later version. 10 | 11 | QuaZIP is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with QuaZIP. If not, see . 18 | 19 | See COPYING file for the full LGPL text. 20 | 21 | Original ZIP package is copyrighted by Gilles Vollant and contributors, 22 | see quazip/(un)zip.h files for details. Basically it's the zlib license. 23 | */ 24 | 25 | #include 26 | 27 | #include "quagzipfile.h" 28 | 29 | /// \cond internal 30 | class QuaGzipFilePrivate { 31 | friend class QuaGzipFile; 32 | QString fileName; 33 | gzFile gzd; 34 | inline QuaGzipFilePrivate(): gzd(NULL) {} 35 | inline QuaGzipFilePrivate(const QString &fileName): 36 | fileName(fileName), gzd(NULL) {} 37 | template bool open(FileId id, 38 | QIODevice::OpenMode mode, QString &error); 39 | gzFile open(int fd, const char *modeString); 40 | gzFile open(const QString &name, const char *modeString); 41 | }; 42 | 43 | gzFile QuaGzipFilePrivate::open(const QString &name, const char *modeString) 44 | { 45 | return gzopen(QFile::encodeName(name).constData(), modeString); 46 | } 47 | 48 | gzFile QuaGzipFilePrivate::open(int fd, const char *modeString) 49 | { 50 | return gzdopen(fd, modeString); 51 | } 52 | 53 | template 54 | bool QuaGzipFilePrivate::open(FileId id, QIODevice::OpenMode mode, 55 | QString &error) 56 | { 57 | char modeString[2]; 58 | modeString[0] = modeString[1] = '\0'; 59 | if ((mode & QIODevice::Append) != 0) { 60 | error = QuaGzipFile::trUtf8("QIODevice::Append is not " 61 | "supported for GZIP"); 62 | return false; 63 | } 64 | if ((mode & QIODevice::ReadOnly) != 0 65 | && (mode & QIODevice::WriteOnly) != 0) { 66 | error = QuaGzipFile::trUtf8("Opening gzip for both reading" 67 | " and writing is not supported"); 68 | return false; 69 | } else if ((mode & QIODevice::ReadOnly) != 0) { 70 | modeString[0] = 'r'; 71 | } else if ((mode & QIODevice::WriteOnly) != 0) { 72 | modeString[0] = 'w'; 73 | } else { 74 | error = QuaGzipFile::trUtf8("You can open a gzip either for reading" 75 | " or for writing. Which is it?"); 76 | return false; 77 | } 78 | gzd = open(id, modeString); 79 | if (gzd == NULL) { 80 | error = QuaGzipFile::trUtf8("Could not gzopen() file"); 81 | return false; 82 | } 83 | return true; 84 | } 85 | /// \endcond 86 | 87 | QuaGzipFile::QuaGzipFile(): 88 | d(new QuaGzipFilePrivate()) 89 | { 90 | } 91 | 92 | QuaGzipFile::QuaGzipFile(QObject *parent): 93 | QIODevice(parent), 94 | d(new QuaGzipFilePrivate()) 95 | { 96 | } 97 | 98 | QuaGzipFile::QuaGzipFile(const QString &fileName, QObject *parent): 99 | QIODevice(parent), 100 | d(new QuaGzipFilePrivate(fileName)) 101 | { 102 | } 103 | 104 | QuaGzipFile::~QuaGzipFile() 105 | { 106 | if (isOpen()) { 107 | close(); 108 | } 109 | delete d; 110 | } 111 | 112 | void QuaGzipFile::setFileName(const QString& fileName) 113 | { 114 | d->fileName = fileName; 115 | } 116 | 117 | QString QuaGzipFile::getFileName() const 118 | { 119 | return d->fileName; 120 | } 121 | 122 | bool QuaGzipFile::isSequential() const 123 | { 124 | return true; 125 | } 126 | 127 | bool QuaGzipFile::open(QIODevice::OpenMode mode) 128 | { 129 | QString error; 130 | if (!d->open(d->fileName, mode, error)) { 131 | setErrorString(error); 132 | return false; 133 | } 134 | return QIODevice::open(mode); 135 | } 136 | 137 | bool QuaGzipFile::open(int fd, QIODevice::OpenMode mode) 138 | { 139 | QString error; 140 | if (!d->open(fd, mode, error)) { 141 | setErrorString(error); 142 | return false; 143 | } 144 | return QIODevice::open(mode); 145 | } 146 | 147 | bool QuaGzipFile::flush() 148 | { 149 | return gzflush(d->gzd, Z_SYNC_FLUSH) == Z_OK; 150 | } 151 | 152 | void QuaGzipFile::close() 153 | { 154 | QIODevice::close(); 155 | gzclose(d->gzd); 156 | } 157 | 158 | qint64 QuaGzipFile::readData(char *data, qint64 maxSize) 159 | { 160 | return gzread(d->gzd, (voidp)data, (unsigned)maxSize); 161 | } 162 | 163 | qint64 QuaGzipFile::writeData(const char *data, qint64 maxSize) 164 | { 165 | if (maxSize == 0) 166 | return 0; 167 | int written = gzwrite(d->gzd, (voidp)data, (unsigned)maxSize); 168 | if (written == 0) 169 | return -1; 170 | else 171 | return written; 172 | } 173 | -------------------------------------------------------------------------------- /quazip/quagzipfile.h: -------------------------------------------------------------------------------- 1 | #ifndef QUAZIP_QUAGZIPFILE_H 2 | #define QUAZIP_QUAGZIPFILE_H 3 | 4 | /* 5 | Copyright (C) 2005-2014 Sergey A. Tachenov 6 | 7 | This file is part of QuaZIP. 8 | 9 | QuaZIP is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 2.1 of the License, or 12 | (at your option) any later version. 13 | 14 | QuaZIP is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with QuaZIP. If not, see . 21 | 22 | See COPYING file for the full LGPL text. 23 | 24 | Original ZIP package is copyrighted by Gilles Vollant and contributors, 25 | see quazip/(un)zip.h files for details. Basically it's the zlib license. 26 | */ 27 | 28 | #include 29 | #include "quazip_global.h" 30 | 31 | #include 32 | 33 | class QuaGzipFilePrivate; 34 | 35 | /// GZIP file 36 | /** 37 | This class is a wrapper around GZIP file access functions in zlib. Unlike QuaZip classes, it doesn't allow reading from a GZIP file opened as QIODevice, for example, if your GZIP file is in QBuffer. It only provides QIODevice access to a GZIP file contents, but the GZIP file itself must be identified by its name on disk or by descriptor id. 38 | */ 39 | class QUAZIP_EXPORT QuaGzipFile: public QIODevice { 40 | Q_OBJECT 41 | public: 42 | /// Empty constructor. 43 | /** 44 | Must call setFileName() before trying to open. 45 | */ 46 | QuaGzipFile(); 47 | /// Empty constructor with a parent. 48 | /** 49 | Must call setFileName() before trying to open. 50 | \param parent The parent object, as per QObject logic. 51 | */ 52 | QuaGzipFile(QObject *parent); 53 | /// Constructor. 54 | /** 55 | \param fileName The name of the GZIP file. 56 | \param parent The parent object, as per QObject logic. 57 | */ 58 | QuaGzipFile(const QString &fileName, QObject *parent = NULL); 59 | /// Destructor. 60 | virtual ~QuaGzipFile(); 61 | /// Sets the name of the GZIP file to be opened. 62 | void setFileName(const QString& fileName); 63 | /// Returns the name of the GZIP file. 64 | QString getFileName() const; 65 | /// Returns true. 66 | /** 67 | Strictly speaking, zlib supports seeking for GZIP files, but it is 68 | poorly implemented, because there is no way to implement it 69 | properly. For reading, seeking backwards is very slow, and for 70 | writing, it is downright impossible. Therefore, QuaGzipFile does not 71 | support seeking at all. 72 | */ 73 | virtual bool isSequential() const; 74 | /// Opens the file. 75 | /** 76 | \param mode Can be either QIODevice::Write or QIODevice::Read. 77 | ReadWrite and Append aren't supported. 78 | */ 79 | virtual bool open(QIODevice::OpenMode mode); 80 | /// Opens the file. 81 | /** 82 | \overload 83 | \param fd The file descriptor to read/write the GZIP file from/to. 84 | \param mode Can be either QIODevice::Write or QIODevice::Read. 85 | ReadWrite and Append aren't supported. 86 | */ 87 | virtual bool open(int fd, QIODevice::OpenMode mode); 88 | /// Flushes data to file. 89 | /** 90 | The data is written using Z_SYNC_FLUSH mode. Doesn't make any sense 91 | when reading. 92 | */ 93 | virtual bool flush(); 94 | /// Closes the file. 95 | virtual void close(); 96 | protected: 97 | /// Implementation of QIODevice::readData(). 98 | virtual qint64 readData(char *data, qint64 maxSize); 99 | /// Implementation of QIODevice::writeData(). 100 | virtual qint64 writeData(const char *data, qint64 maxSize); 101 | private: 102 | // not implemented by design to disable copy 103 | QuaGzipFile(const QuaGzipFile &that); 104 | QuaGzipFile& operator=(const QuaGzipFile &that); 105 | QuaGzipFilePrivate *d; 106 | }; 107 | 108 | #endif // QUAZIP_QUAGZIPFILE_H 109 | -------------------------------------------------------------------------------- /quazip/quaziodevice.h: -------------------------------------------------------------------------------- 1 | #ifndef QUAZIP_QUAZIODEVICE_H 2 | #define QUAZIP_QUAZIODEVICE_H 3 | 4 | /* 5 | Copyright (C) 2005-2014 Sergey A. Tachenov 6 | 7 | This file is part of QuaZIP. 8 | 9 | QuaZIP is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 2.1 of the License, or 12 | (at your option) any later version. 13 | 14 | QuaZIP is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with QuaZIP. If not, see . 21 | 22 | See COPYING file for the full LGPL text. 23 | 24 | Original ZIP package is copyrighted by Gilles Vollant and contributors, 25 | see quazip/(un)zip.h files for details. Basically it's the zlib license. 26 | */ 27 | 28 | #include 29 | #include "quazip_global.h" 30 | 31 | #include 32 | 33 | class QuaZIODevicePrivate; 34 | 35 | /// A class to compress/decompress QIODevice. 36 | /** 37 | This class can be used to compress any data written to QIODevice or 38 | decompress it back. Compressing data sent over a QTcpSocket is a good 39 | example. 40 | */ 41 | class QUAZIP_EXPORT QuaZIODevice: public QIODevice { 42 | Q_OBJECT 43 | public: 44 | /// Constructor. 45 | /** 46 | \param io The QIODevice to read/write. 47 | \param parent The parent object, as per QObject logic. 48 | */ 49 | QuaZIODevice(QIODevice *io, QObject *parent = NULL); 50 | /// Destructor. 51 | ~QuaZIODevice(); 52 | /// Flushes data waiting to be written. 53 | /** 54 | Unfortunately, as QIODevice doesn't support flush() by itself, the 55 | only thing this method does is write the compressed data into the 56 | device using Z_SYNC_FLUSH mode. If you need the compressed data to 57 | actually be flushed from the buffer of the underlying QIODevice, you 58 | need to call its flush() method as well, providing it supports it 59 | (like QTcpSocket does). Example: 60 | \code 61 | QuaZIODevice dev(&sock); 62 | dev.open(QIODevice::Write); 63 | dev.write(yourDataGoesHere); 64 | dev.flush(); 65 | sock->flush(); // this actually sends data to network 66 | \endcode 67 | 68 | This may change in the future versions of QuaZIP by implementing an 69 | ugly hack: trying to cast the QIODevice using qobject_cast to known 70 | flush()-supporting subclasses, and calling flush if the resulting 71 | pointer is not zero. 72 | */ 73 | virtual bool flush(); 74 | /// Opens the device. 75 | /** 76 | \param mode Neither QIODevice::ReadWrite nor QIODevice::Append are 77 | not supported. 78 | */ 79 | virtual bool open(QIODevice::OpenMode mode); 80 | /// Closes this device, but not the underlying one. 81 | /** 82 | The underlying QIODevice is not closed in case you want to write 83 | something else to it. 84 | */ 85 | virtual void close(); 86 | /// Returns the underlying device. 87 | QIODevice *getIoDevice() const; 88 | /// Returns true. 89 | virtual bool isSequential() const; 90 | /// Returns true iff the end of the compressed stream is reached. 91 | virtual bool atEnd() const; 92 | /// Returns the number of the bytes buffered. 93 | virtual qint64 bytesAvailable() const; 94 | protected: 95 | /// Implementation of QIODevice::readData(). 96 | virtual qint64 readData(char *data, qint64 maxSize); 97 | /// Implementation of QIODevice::writeData(). 98 | virtual qint64 writeData(const char *data, qint64 maxSize); 99 | private: 100 | QuaZIODevicePrivate *d; 101 | }; 102 | #endif // QUAZIP_QUAZIODEVICE_H 103 | -------------------------------------------------------------------------------- /quazip/quazip.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | CONFIG += qt warn_on 3 | QT -= gui 4 | 5 | # The ABI version. 6 | 7 | !win32:VERSION = 1.0.0 8 | 9 | # 1.0.0 is the first stable ABI. 10 | # The next binary incompatible change will be 2.0.0 and so on. 11 | # The existing QuaZIP policy on changing ABI requires to bump the 12 | # major version of QuaZIP itself as well. Note that there may be 13 | # other reasons for chaging the major version of QuaZIP, so 14 | # in case where there is a QuaZIP major version bump but no ABI change, 15 | # the VERSION variable will stay the same. 16 | 17 | # For example: 18 | 19 | # QuaZIP 1.0 is released after some 0.x, keeping binary compatibility. 20 | # VERSION stays 1.0.0. 21 | # Then some binary incompatible change is introduced. QuaZIP goes up to 22 | # 2.0, VERSION to 2.0.0. 23 | # And so on. 24 | 25 | 26 | # This one handles dllimport/dllexport directives. 27 | DEFINES += QUAZIP_BUILD 28 | 29 | # You'll need to define this one manually if using a build system other 30 | # than qmake or using QuaZIP sources directly in your project. 31 | CONFIG(staticlib): DEFINES += QUAZIP_STATIC 32 | 33 | CONFIG(debug, debug|release) { 34 | mac: TARGET = $$join(TARGET,,,_debug) 35 | win32: TARGET = $$join(TARGET,,,d) 36 | } 37 | 38 | unix { 39 | headers.path=$$PREFIX/include/quazip 40 | headers.files=$$HEADERS 41 | target.path=$$PREFIX/lib/$${LIB_ARCH} 42 | INSTALLS += headers target 43 | 44 | OBJECTS_DIR=.obj 45 | MOC_DIR=.moc 46 | 47 | } 48 | 49 | win32 { 50 | headers.path=$$PREFIX/include/quazip 51 | headers.files=$$HEADERS 52 | target.path=$$PREFIX/lib 53 | INSTALLS += headers target 54 | # workaround for qdatetime.h macro bug 55 | DEFINES += NOMINMAX 56 | } 57 | 58 | INCLUDEPATH += $$PWD 59 | DEPENDPATH += $$PWD 60 | HEADERS += \ 61 | $$PWD/crypt.h \ 62 | $$PWD/ioapi.h \ 63 | $$PWD/JlCompress.h \ 64 | $$PWD/quaadler32.h \ 65 | $$PWD/quachecksum32.h \ 66 | $$PWD/quacrc32.h \ 67 | $$PWD/quagzipfile.h \ 68 | $$PWD/quaziodevice.h \ 69 | $$PWD/quazipdir.h \ 70 | $$PWD/quazipfile.h \ 71 | $$PWD/quazipfileinfo.h \ 72 | $$PWD/quazip_global.h \ 73 | $$PWD/quazip.h \ 74 | $$PWD/quazipnewinfo.h \ 75 | $$PWD/unzip.h \ 76 | $$PWD/zip.h 77 | 78 | SOURCES += $$PWD/qioapi.cpp \ 79 | $$PWD/JlCompress.cpp \ 80 | $$PWD/quaadler32.cpp \ 81 | $$PWD/quacrc32.cpp \ 82 | $$PWD/quagzipfile.cpp \ 83 | $$PWD/quaziodevice.cpp \ 84 | $$PWD/quazip.cpp \ 85 | $$PWD/quazipdir.cpp \ 86 | $$PWD/quazipfile.cpp \ 87 | $$PWD/quazipfileinfo.cpp \ 88 | $$PWD/quazipnewinfo.cpp \ 89 | $$PWD/unzip.c \ 90 | $$PWD/zip.c 91 | 92 | INCLUDEPATH += $ZLIB 93 | LIBS += -L $ZLIB -lz 94 | -------------------------------------------------------------------------------- /quazip/quazip.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual C++ Express 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "quazip", "quazip.vcproj", "{E4AC5F56-B711-4F0E-BC83-CDE8B6CD53AD}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {E4AC5F56-B711-4F0E-BC83-CDE8B6CD53AD}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {E4AC5F56-B711-4F0E-BC83-CDE8B6CD53AD}.Debug|Win32.Build.0 = Debug|Win32 14 | {E4AC5F56-B711-4F0E-BC83-CDE8B6CD53AD}.Release|Win32.ActiveCfg = Release|Win32 15 | {E4AC5F56-B711-4F0E-BC83-CDE8B6CD53AD}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /quazip/quazip.vcproj: -------------------------------------------------------------------------------- 1 |  2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 24 | 27 | 30 | 33 | 36 | 39 | 51 | 54 | 57 | 60 | 68 | 71 | 74 | 77 | 80 | 83 | 86 | 89 | 90 | 96 | 99 | 102 | 105 | 108 | 111 | 120 | 123 | 126 | 129 | 139 | 142 | 145 | 148 | 151 | 154 | 157 | 160 | 161 | 162 | 163 | 164 | 165 | 170 | 173 | 174 | 177 | 178 | 181 | 182 | 185 | 186 | 189 | 190 | 193 | 194 | 197 | 198 | 201 | 202 | 205 | 206 | 209 | 210 | 213 | 214 | 217 | 218 | 221 | 222 | 225 | 226 | 229 | 230 | 233 | 234 | 235 | 240 | 241 | 246 | 249 | 250 | 253 | 254 | 257 | 258 | 261 | 262 | 265 | 266 | 269 | 270 | 273 | 274 | 277 | 278 | 281 | 282 | 285 | 286 | 289 | 290 | 293 | 294 | 297 | 298 | 301 | 302 | 305 | 306 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | -------------------------------------------------------------------------------- /quazip/quazip.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 6 | h;hpp;hxx;hm;inl;inc;xsd 7 | 8 | 9 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 10 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx 11 | 12 | 13 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 14 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | Header Files 50 | 51 | 52 | Header Files 53 | 54 | 55 | Header Files 56 | 57 | 58 | Header Files 59 | 60 | 61 | Header Files 62 | 63 | 64 | Header Files 65 | 66 | 67 | 68 | 69 | Source Files 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | Source Files 82 | 83 | 84 | Source Files 85 | 86 | 87 | Source Files 88 | 89 | 90 | Source Files 91 | 92 | 93 | Source Files 94 | 95 | 96 | Source Files 97 | 98 | 99 | Source Files 100 | 101 | 102 | Source Files 103 | 104 | 105 | Source Files 106 | 107 | 108 | Source Files 109 | 110 | 111 | Source Files 112 | 113 | 114 | Source Files 115 | 116 | 117 | -------------------------------------------------------------------------------- /quazip/quazip_global.h: -------------------------------------------------------------------------------- 1 | #ifndef QUAZIP_GLOBAL_H 2 | #define QUAZIP_GLOBAL_H 3 | 4 | /* 5 | Copyright (C) 2005-2014 Sergey A. Tachenov 6 | 7 | This file is part of QuaZIP. 8 | 9 | QuaZIP is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 2.1 of the License, or 12 | (at your option) any later version. 13 | 14 | QuaZIP is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with QuaZIP. If not, see . 21 | 22 | See COPYING file for the full LGPL text. 23 | 24 | Original ZIP package is copyrighted by Gilles Vollant and contributors, 25 | see quazip/(un)zip.h files for details. Basically it's the zlib license. 26 | */ 27 | 28 | #include 29 | 30 | /** 31 | This is automatically defined when building a static library, but when 32 | including QuaZip sources directly into a project, QUAZIP_STATIC should 33 | be defined explicitly to avoid possible troubles with unnecessary 34 | importing/exporting. 35 | */ 36 | #ifdef QUAZIP_STATIC 37 | #define QUAZIP_EXPORT 38 | #else 39 | /** 40 | * When building a DLL with MSVC, QUAZIP_BUILD must be defined. 41 | * qglobal.h takes care of defining Q_DECL_* correctly for msvc/gcc. 42 | */ 43 | #if defined(QUAZIP_BUILD) 44 | #define QUAZIP_EXPORT Q_DECL_EXPORT 45 | #else 46 | #define QUAZIP_EXPORT Q_DECL_IMPORT 47 | #endif 48 | #endif // QUAZIP_STATIC 49 | 50 | #ifdef __GNUC__ 51 | #define UNUSED __attribute__((__unused__)) 52 | #else 53 | #define UNUSED 54 | #endif 55 | 56 | #define QUAZIP_EXTRA_NTFS_MAGIC 0x000Au 57 | #define QUAZIP_EXTRA_NTFS_TIME_MAGIC 0x0001u 58 | 59 | #endif // QUAZIP_GLOBAL_H 60 | -------------------------------------------------------------------------------- /quazip/quazipfileinfo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2014 Sergey A. Tachenov 3 | 4 | This file is part of QuaZIP. 5 | 6 | QuaZIP is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation, either version 2.1 of the License, or 9 | (at your option) any later version. 10 | 11 | QuaZIP is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with QuaZIP. If not, see . 18 | 19 | See COPYING file for the full LGPL text. 20 | 21 | Original ZIP package is copyrighted by Gilles Vollant and contributors, 22 | see quazip/(un)zip.h files for details. Basically it's the zlib license. 23 | */ 24 | 25 | #include "quazipfileinfo.h" 26 | 27 | static QFile::Permissions permissionsFromExternalAttr(quint32 externalAttr) { 28 | quint32 uPerm = (externalAttr & 0xFFFF0000u) >> 16; 29 | QFile::Permissions perm = 0; 30 | if ((uPerm & 0400) != 0) 31 | perm |= QFile::ReadOwner; 32 | if ((uPerm & 0200) != 0) 33 | perm |= QFile::WriteOwner; 34 | if ((uPerm & 0100) != 0) 35 | perm |= QFile::ExeOwner; 36 | if ((uPerm & 0040) != 0) 37 | perm |= QFile::ReadGroup; 38 | if ((uPerm & 0020) != 0) 39 | perm |= QFile::WriteGroup; 40 | if ((uPerm & 0010) != 0) 41 | perm |= QFile::ExeGroup; 42 | if ((uPerm & 0004) != 0) 43 | perm |= QFile::ReadOther; 44 | if ((uPerm & 0002) != 0) 45 | perm |= QFile::WriteOther; 46 | if ((uPerm & 0001) != 0) 47 | perm |= QFile::ExeOther; 48 | return perm; 49 | 50 | } 51 | 52 | QFile::Permissions QuaZipFileInfo::getPermissions() const 53 | { 54 | return permissionsFromExternalAttr(externalAttr); 55 | } 56 | 57 | QFile::Permissions QuaZipFileInfo64::getPermissions() const 58 | { 59 | return permissionsFromExternalAttr(externalAttr); 60 | } 61 | 62 | bool QuaZipFileInfo64::toQuaZipFileInfo(QuaZipFileInfo &info) const 63 | { 64 | bool noOverflow = true; 65 | info.name = name; 66 | info.versionCreated = versionCreated; 67 | info.versionNeeded = versionNeeded; 68 | info.flags = flags; 69 | info.method = method; 70 | info.dateTime = dateTime; 71 | info.crc = crc; 72 | if (compressedSize > 0xFFFFFFFFu) { 73 | info.compressedSize = 0xFFFFFFFFu; 74 | noOverflow = false; 75 | } else { 76 | info.compressedSize = compressedSize; 77 | } 78 | if (uncompressedSize > 0xFFFFFFFFu) { 79 | info.uncompressedSize = 0xFFFFFFFFu; 80 | noOverflow = false; 81 | } else { 82 | info.uncompressedSize = uncompressedSize; 83 | } 84 | info.diskNumberStart = diskNumberStart; 85 | info.internalAttr = internalAttr; 86 | info.externalAttr = externalAttr; 87 | info.comment = comment; 88 | info.extra = extra; 89 | return noOverflow; 90 | } 91 | 92 | static QDateTime getNTFSTime(const QByteArray &extra, int position, 93 | int *fineTicks) 94 | { 95 | QDateTime dateTime; 96 | for (int i = 0; i <= extra.size() - 4; ) { 97 | unsigned type = static_cast(static_cast( 98 | extra.at(i))) 99 | | (static_cast(static_cast( 100 | extra.at(i + 1))) << 8); 101 | i += 2; 102 | unsigned length = static_cast(static_cast( 103 | extra.at(i))) 104 | | (static_cast(static_cast( 105 | extra.at(i + 1))) << 8); 106 | i += 2; 107 | if (type == QUAZIP_EXTRA_NTFS_MAGIC && length >= 32) { 108 | i += 4; // reserved 109 | while (i <= extra.size() - 4) { 110 | unsigned tag = static_cast( 111 | static_cast(extra.at(i))) 112 | | (static_cast( 113 | static_cast(extra.at(i + 1))) 114 | << 8); 115 | i += 2; 116 | int tagsize = static_cast( 117 | static_cast(extra.at(i))) 118 | | (static_cast( 119 | static_cast(extra.at(i + 1))) 120 | << 8); 121 | i += 2; 122 | if (tag == QUAZIP_EXTRA_NTFS_TIME_MAGIC 123 | && tagsize >= position + 8) { 124 | i += position; 125 | quint64 mtime = static_cast( 126 | static_cast(extra.at(i))) 127 | | (static_cast(static_cast( 128 | extra.at(i + 1))) << 8) 129 | | (static_cast(static_cast( 130 | extra.at(i + 2))) << 16) 131 | | (static_cast(static_cast( 132 | extra.at(i + 3))) << 24) 133 | | (static_cast(static_cast( 134 | extra.at(i + 4))) << 32) 135 | | (static_cast(static_cast( 136 | extra.at(i + 5))) << 40) 137 | | (static_cast(static_cast( 138 | extra.at(i + 6))) << 48) 139 | | (static_cast(static_cast( 140 | extra.at(i + 7))) << 56); 141 | // the NTFS time is measured from 1601 for whatever reason 142 | QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC); 143 | dateTime = base.addMSecs(mtime / 10000); 144 | if (fineTicks != NULL) { 145 | *fineTicks = static_cast(mtime % 10000); 146 | } 147 | i += tagsize - position; 148 | } else { 149 | i += tagsize; 150 | } 151 | 152 | } 153 | } else { 154 | i += length; 155 | } 156 | } 157 | if (fineTicks != NULL && dateTime.isNull()) { 158 | *fineTicks = 0; 159 | } 160 | return dateTime; 161 | } 162 | 163 | QDateTime QuaZipFileInfo64::getNTFSmTime(int *fineTicks) const 164 | { 165 | return getNTFSTime(extra, 0, fineTicks); 166 | } 167 | 168 | QDateTime QuaZipFileInfo64::getNTFSaTime(int *fineTicks) const 169 | { 170 | return getNTFSTime(extra, 8, fineTicks); 171 | } 172 | 173 | QDateTime QuaZipFileInfo64::getNTFScTime(int *fineTicks) const 174 | { 175 | return getNTFSTime(extra, 16, fineTicks); 176 | } 177 | -------------------------------------------------------------------------------- /quazip/quazipfileinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef QUA_ZIPFILEINFO_H 2 | #define QUA_ZIPFILEINFO_H 3 | 4 | /* 5 | Copyright (C) 2005-2014 Sergey A. Tachenov 6 | 7 | This file is part of QuaZIP. 8 | 9 | QuaZIP is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU Lesser General Public License as published by 11 | the Free Software Foundation, either version 2.1 of the License, or 12 | (at your option) any later version. 13 | 14 | QuaZIP is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public License 20 | along with QuaZIP. If not, see . 21 | 22 | See COPYING file for the full LGPL text. 23 | 24 | Original ZIP package is copyrighted by Gilles Vollant and contributors, 25 | see quazip/(un)zip.h files for details. Basically it's the zlib license. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "quazip_global.h" 33 | 34 | /// Information about a file inside archive. 35 | /** 36 | * \deprecated Use QuaZipFileInfo64 instead. Not only it supports large files, 37 | * but also more convenience methods as well. 38 | * 39 | * Call QuaZip::getCurrentFileInfo() or QuaZipFile::getFileInfo() to 40 | * fill this structure. */ 41 | struct QUAZIP_EXPORT QuaZipFileInfo { 42 | /// File name. 43 | QString name; 44 | /// Version created by. 45 | quint16 versionCreated; 46 | /// Version needed to extract. 47 | quint16 versionNeeded; 48 | /// General purpose flags. 49 | quint16 flags; 50 | /// Compression method. 51 | quint16 method; 52 | /// Last modification date and time. 53 | QDateTime dateTime; 54 | /// CRC. 55 | quint32 crc; 56 | /// Compressed file size. 57 | quint32 compressedSize; 58 | /// Uncompressed file size. 59 | quint32 uncompressedSize; 60 | /// Disk number start. 61 | quint16 diskNumberStart; 62 | /// Internal file attributes. 63 | quint16 internalAttr; 64 | /// External file attributes. 65 | quint32 externalAttr; 66 | /// Comment. 67 | QString comment; 68 | /// Extra field. 69 | QByteArray extra; 70 | /// Get the file permissions. 71 | /** 72 | Returns the high 16 bits of external attributes converted to 73 | QFile::Permissions. 74 | */ 75 | QFile::Permissions getPermissions() const; 76 | }; 77 | 78 | /// Information about a file inside archive (with zip64 support). 79 | /** Call QuaZip::getCurrentFileInfo() or QuaZipFile::getFileInfo() to 80 | * fill this structure. */ 81 | struct QUAZIP_EXPORT QuaZipFileInfo64 { 82 | /// File name. 83 | QString name; 84 | /// Version created by. 85 | quint16 versionCreated; 86 | /// Version needed to extract. 87 | quint16 versionNeeded; 88 | /// General purpose flags. 89 | quint16 flags; 90 | /// Compression method. 91 | quint16 method; 92 | /// Last modification date and time. 93 | /** 94 | * This is the time stored in the standard ZIP header. This format only allows 95 | * to store time with 2-second precision, so the seconds will always be even 96 | * and the milliseconds will always be zero. If you need more precise 97 | * date and time, you can try to call the getNTFSmTime() function or 98 | * its siblings, provided that the archive itself contains these NTFS times. 99 | */ 100 | QDateTime dateTime; 101 | /// CRC. 102 | quint32 crc; 103 | /// Compressed file size. 104 | quint64 compressedSize; 105 | /// Uncompressed file size. 106 | quint64 uncompressedSize; 107 | /// Disk number start. 108 | quint16 diskNumberStart; 109 | /// Internal file attributes. 110 | quint16 internalAttr; 111 | /// External file attributes. 112 | quint32 externalAttr; 113 | /// Comment. 114 | QString comment; 115 | /// Extra field. 116 | QByteArray extra; 117 | /// Get the file permissions. 118 | /** 119 | Returns the high 16 bits of external attributes converted to 120 | QFile::Permissions. 121 | */ 122 | QFile::Permissions getPermissions() const; 123 | /// Converts to QuaZipFileInfo 124 | /** 125 | If any of the fields are greater than 0xFFFFFFFFu, they are set to 126 | 0xFFFFFFFFu exactly, not just truncated. This function should be mainly used 127 | for compatibility with the old code expecting QuaZipFileInfo, in the cases 128 | when it's impossible or otherwise unadvisable (due to ABI compatibility 129 | reasons, for example) to modify that old code to use QuaZipFileInfo64. 130 | 131 | \return \c true if all fields converted correctly, \c false if an overflow 132 | occured. 133 | */ 134 | bool toQuaZipFileInfo(QuaZipFileInfo &info) const; 135 | /// Returns the NTFS modification time 136 | /** 137 | * The getNTFS*Time() functions only work if there is an NTFS extra field 138 | * present. Otherwise, they all return invalid null timestamps. 139 | * @param fineTicks If not NULL, the fractional part of milliseconds returned 140 | * there, measured in 100-nanosecond ticks. Will be set to 141 | * zero if there is no NTFS extra field. 142 | * @sa dateTime 143 | * @sa getNTFSaTime() 144 | * @sa getNTFScTime() 145 | * @return The NTFS modification time, UTC 146 | */ 147 | QDateTime getNTFSmTime(int *fineTicks = NULL) const; 148 | /// Returns the NTFS access time 149 | /** 150 | * The getNTFS*Time() functions only work if there is an NTFS extra field 151 | * present. Otherwise, they all return invalid null timestamps. 152 | * @param fineTicks If not NULL, the fractional part of milliseconds returned 153 | * there, measured in 100-nanosecond ticks. Will be set to 154 | * zero if there is no NTFS extra field. 155 | * @sa dateTime 156 | * @sa getNTFSmTime() 157 | * @sa getNTFScTime() 158 | * @return The NTFS access time, UTC 159 | */ 160 | QDateTime getNTFSaTime(int *fineTicks = NULL) const; 161 | /// Returns the NTFS creation time 162 | /** 163 | * The getNTFS*Time() functions only work if there is an NTFS extra field 164 | * present. Otherwise, they all return invalid null timestamps. 165 | * @param fineTicks If not NULL, the fractional part of milliseconds returned 166 | * there, measured in 100-nanosecond ticks. Will be set to 167 | * zero if there is no NTFS extra field. 168 | * @sa dateTime 169 | * @sa getNTFSmTime() 170 | * @sa getNTFSaTime() 171 | * @return The NTFS creation time, UTC 172 | */ 173 | QDateTime getNTFScTime(int *fineTicks = NULL) const; 174 | /// Checks whether the file is encrypted. 175 | bool isEncrypted() const {return (flags & 1) != 0;} 176 | }; 177 | 178 | #endif 179 | -------------------------------------------------------------------------------- /quazip/run_moc.bat: -------------------------------------------------------------------------------- 1 | moc -o moc\moc_quazipfile.cpp quazipfile.h 2 | moc -o moc\moc_quagzipfile.cpp quagzipfile.h 3 | moc -o moc\moc_quaziodevice.cpp quaziodevice.h 4 | -------------------------------------------------------------------------------- /src.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wx1183618058/HuaWei-Optical-Network-Terminal-Decoder/6d430cdfbd5b29a6f6bf0e27b9ef055b95eb6dbb/src.png -------------------------------------------------------------------------------- /xyssl/aes.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file aes.h 3 | */ 4 | #ifndef XYSSL_AES_H 5 | #define XYSSL_AES_H 6 | 7 | #define AES_ENCRYPT 1 8 | #define AES_DECRYPT 0 9 | 10 | /** 11 | * \brief AES context structure 12 | */ 13 | typedef struct 14 | { 15 | int nr; /*!< number of rounds */ 16 | unsigned long *rk; /*!< AES round keys */ 17 | unsigned long buf[68]; /*!< unaligned data */ 18 | } 19 | aes_context; 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /** 26 | * \brief AES key schedule (encryption) 27 | * 28 | * \param ctx AES context to be initialized 29 | * \param key encryption key 30 | * \param keysize must be 128, 192 or 256 31 | */ 32 | void aes_setkey_enc( aes_context *ctx, unsigned char *key, int keysize ); 33 | 34 | /** 35 | * \brief AES key schedule (decryption) 36 | * 37 | * \param ctx AES context to be initialized 38 | * \param key decryption key 39 | * \param keysize must be 128, 192 or 256 40 | */ 41 | void aes_setkey_dec( aes_context *ctx, unsigned char *key, int keysize ); 42 | 43 | /** 44 | * \brief AES-ECB block encryption/decryption 45 | * 46 | * \param ctx AES context 47 | * \param mode AES_ENCRYPT or AES_DECRYPT 48 | * \param input 16-byte input block 49 | * \param output 16-byte output block 50 | */ 51 | void aes_crypt_ecb( aes_context *ctx, 52 | int mode, 53 | unsigned char input[16], 54 | unsigned char output[16] ); 55 | 56 | /** 57 | * \brief AES-CBC buffer encryption/decryption 58 | * 59 | * \param ctx AES context 60 | * \param mode AES_ENCRYPT or AES_DECRYPT 61 | * \param length length of the input data 62 | * \param iv initialization vector (updated after use) 63 | * \param input buffer holding the input data 64 | * \param output buffer holding the output data 65 | */ 66 | void aes_crypt_cbc( aes_context *ctx, 67 | int mode, 68 | int length, 69 | unsigned char iv[16], 70 | unsigned char *input, 71 | unsigned char *output ); 72 | 73 | /** 74 | * \brief AES-CFB buffer encryption/decryption 75 | * 76 | * \param ctx AES context 77 | * \param mode AES_ENCRYPT or AES_DECRYPT 78 | * \param length length of the input data 79 | * \param iv_off offset in IV (updated after use) 80 | * \param iv initialization vector (updated after use) 81 | * \param input buffer holding the input data 82 | * \param output buffer holding the output data 83 | */ 84 | void aes_crypt_cfb( aes_context *ctx, 85 | int mode, 86 | int length, 87 | int *iv_off, 88 | unsigned char iv[16], 89 | unsigned char *input, 90 | unsigned char *output ); 91 | 92 | /** 93 | * \brief Checkup routine 94 | * 95 | * \return 0 if successful, or 1 if the test failed 96 | */ 97 | int aes_self_test( int verbose ); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif /* aes.h */ 104 | -------------------------------------------------------------------------------- /xyssl/arc4.c: -------------------------------------------------------------------------------- 1 | /* 2 | * An implementation of the ARCFOUR algorithm 3 | * 4 | * Copyright (C) 2006-2007 Christophe Devine 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | /* 21 | * The ARCFOUR algorithm was publicly disclosed on 94/09. 22 | * 23 | * http://groups.google.com/group/sci.crypt/msg/10a300c9d21afca0 24 | */ 25 | 26 | #include "config.h" 27 | 28 | #if defined(XYSSL_ARC4_C) 29 | 30 | #include "arc4.h" 31 | 32 | /* 33 | * ARC4 key schedule 34 | */ 35 | void arc4_setup( arc4_context *ctx, unsigned char *key, int keylen ) 36 | { 37 | int i, j, k, a; 38 | unsigned char *m; 39 | 40 | ctx->x = 0; 41 | ctx->y = 0; 42 | m = ctx->m; 43 | 44 | for( i = 0; i < 256; i++ ) 45 | m[i] = (unsigned char) i; 46 | 47 | j = k = 0; 48 | 49 | for( i = 0; i < 256; i++, k++ ) 50 | { 51 | if( k >= keylen ) k = 0; 52 | 53 | a = m[i]; 54 | j = ( j + a + key[k] ) & 0xFF; 55 | m[i] = m[j]; 56 | m[j] = (unsigned char) a; 57 | } 58 | } 59 | 60 | /* 61 | * ARC4 cipher function 62 | */ 63 | void arc4_crypt( arc4_context *ctx, unsigned char *buf, int buflen ) 64 | { 65 | int i, x, y, a, b; 66 | unsigned char *m; 67 | 68 | x = ctx->x; 69 | y = ctx->y; 70 | m = ctx->m; 71 | 72 | for( i = 0; i < buflen; i++ ) 73 | { 74 | x = ( x + 1 ) & 0xFF; a = m[x]; 75 | y = ( y + a ) & 0xFF; b = m[y]; 76 | 77 | m[x] = (unsigned char) b; 78 | m[y] = (unsigned char) a; 79 | 80 | buf[i] = (unsigned char) 81 | ( buf[i] ^ m[(unsigned char)( a + b )] ); 82 | } 83 | 84 | ctx->x = x; 85 | ctx->y = y; 86 | } 87 | 88 | #if defined(XYSSL_SELF_TEST) 89 | 90 | #include 91 | #include 92 | 93 | /* 94 | * ARC4 tests vectors as posted by Eric Rescorla in sep. 1994: 95 | * 96 | * http://groups.google.com/group/comp.security.misc/msg/10a300c9d21afca0 97 | */ 98 | static const unsigned char arc4_test_key[3][8] = 99 | { 100 | { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }, 101 | { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }, 102 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } 103 | }; 104 | 105 | static const unsigned char arc4_test_pt[3][8] = 106 | { 107 | { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }, 108 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 109 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } 110 | }; 111 | 112 | static const unsigned char arc4_test_ct[3][8] = 113 | { 114 | { 0x75, 0xB7, 0x87, 0x80, 0x99, 0xE0, 0xC5, 0x96 }, 115 | { 0x74, 0x94, 0xC2, 0xE7, 0x10, 0x4B, 0x08, 0x79 }, 116 | { 0xDE, 0x18, 0x89, 0x41, 0xA3, 0x37, 0x5D, 0x3A } 117 | }; 118 | 119 | /* 120 | * Checkup routine 121 | */ 122 | int arc4_self_test( int verbose ) 123 | { 124 | int i; 125 | unsigned char buf[8]; 126 | arc4_context ctx; 127 | 128 | for( i = 0; i < 3; i++ ) 129 | { 130 | if( verbose != 0 ) 131 | printf( " ARC4 test #%d: ", i + 1 ); 132 | 133 | memcpy( buf, arc4_test_pt[i], 8 ); 134 | 135 | arc4_setup( &ctx, (unsigned char *) arc4_test_key[i], 8 ); 136 | arc4_crypt( &ctx, buf, 8 ); 137 | 138 | if( memcmp( buf, arc4_test_ct[i], 8 ) != 0 ) 139 | { 140 | if( verbose != 0 ) 141 | printf( "failed\n" ); 142 | 143 | return( 1 ); 144 | } 145 | 146 | if( verbose != 0 ) 147 | printf( "passed\n" ); 148 | } 149 | 150 | if( verbose != 0 ) 151 | printf( "\n" ); 152 | 153 | return( 0 ); 154 | } 155 | 156 | #endif 157 | 158 | #endif 159 | -------------------------------------------------------------------------------- /xyssl/arc4.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file arc4.h 3 | */ 4 | #ifndef XYSSL_ARC4_H 5 | #define XYSSL_ARC4_H 6 | 7 | /** 8 | * \brief ARC4 context structure 9 | */ 10 | typedef struct 11 | { 12 | int x; /*!< permutation index */ 13 | int y; /*!< permutation index */ 14 | unsigned char m[256]; /*!< permutation table */ 15 | } 16 | arc4_context; 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | * \brief ARC4 key schedule 24 | * 25 | * \param ctx ARC4 context to be initialized 26 | * \param key the secret key 27 | * \param keylen length of the key 28 | */ 29 | void arc4_setup( arc4_context *ctx, unsigned char *key, int keylen ); 30 | 31 | /** 32 | * \brief ARC4 cipher function 33 | * 34 | * \param ctx ARC4 context 35 | * \param buf buffer to be processed 36 | * \param buflen amount of data in buf 37 | */ 38 | void arc4_crypt( arc4_context *ctx, unsigned char *buf, int buflen ); 39 | 40 | /* 41 | * \brief Checkup routine 42 | * 43 | * \return 0 if successful, or 1 if the test failed 44 | */ 45 | int arc4_self_test( int verbose ); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* arc4.h */ 52 | -------------------------------------------------------------------------------- /xyssl/base64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * RFC 1521 base64 encoding/decoding 3 | * 4 | * Copyright (C) 2006-2007 Christophe Devine 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | #include "config.h" 22 | 23 | #if defined(XYSSL_BASE64_C) 24 | 25 | #include "base64.h" 26 | 27 | static const unsigned char base64_enc_map[64] = 28 | { 29 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 30 | 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 31 | 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 32 | 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 33 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 34 | 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', 35 | '8', '9', '+', '/' 36 | }; 37 | 38 | static const unsigned char base64_dec_map[128] = 39 | { 40 | 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 41 | 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 42 | 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 43 | 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 44 | 127, 127, 127, 62, 127, 127, 127, 63, 52, 53, 45 | 54, 55, 56, 57, 58, 59, 60, 61, 127, 127, 46 | 127, 64, 127, 127, 127, 0, 1, 2, 3, 4, 47 | 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 48 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 49 | 25, 127, 127, 127, 127, 127, 127, 26, 27, 28, 50 | 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 51 | 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 52 | 49, 50, 51, 127, 127, 127, 127, 127 53 | }; 54 | 55 | /* 56 | * Encode a buffer into base64 format 57 | */ 58 | int base64_encode( unsigned char *dst, int *dlen, 59 | unsigned char *src, int slen ) 60 | { 61 | int i, n; 62 | int C1, C2, C3; 63 | unsigned char *p; 64 | 65 | if( slen == 0 ) 66 | return( 0 ); 67 | 68 | n = (slen << 3) / 6; 69 | 70 | switch( (slen << 3) - (n * 6) ) 71 | { 72 | case 2: n += 3; break; 73 | case 4: n += 2; break; 74 | default: break; 75 | } 76 | 77 | if( *dlen < n + 1 ) 78 | { 79 | *dlen = n + 1; 80 | return( XYSSL_ERR_BASE64_BUFFER_TOO_SMALL ); 81 | } 82 | 83 | n = (slen / 3) * 3; 84 | 85 | for( i = 0, p = dst; i < n; i += 3 ) 86 | { 87 | C1 = *src++; 88 | C2 = *src++; 89 | C3 = *src++; 90 | 91 | *p++ = base64_enc_map[(C1 >> 2) & 0x3F]; 92 | *p++ = base64_enc_map[(((C1 & 3) << 4) + (C2 >> 4)) & 0x3F]; 93 | *p++ = base64_enc_map[(((C2 & 15) << 2) + (C3 >> 6)) & 0x3F]; 94 | *p++ = base64_enc_map[C3 & 0x3F]; 95 | } 96 | 97 | if( i < slen ) 98 | { 99 | C1 = *src++; 100 | C2 = ((i + 1) < slen) ? *src++ : 0; 101 | 102 | *p++ = base64_enc_map[(C1 >> 2) & 0x3F]; 103 | *p++ = base64_enc_map[(((C1 & 3) << 4) + (C2 >> 4)) & 0x3F]; 104 | 105 | if( (i + 1) < slen ) 106 | *p++ = base64_enc_map[((C2 & 15) << 2) & 0x3F]; 107 | else *p++ = '='; 108 | 109 | *p++ = '='; 110 | } 111 | 112 | *dlen = p - dst; 113 | *p = 0; 114 | 115 | return( 0 ); 116 | } 117 | 118 | /* 119 | * Decode a base64-formatted buffer 120 | */ 121 | int base64_decode( unsigned char *dst, int *dlen, 122 | unsigned char *src, int slen ) 123 | { 124 | int i, j, n; 125 | unsigned long x; 126 | unsigned char *p; 127 | 128 | for( i = j = n = 0; i < slen; i++ ) 129 | { 130 | if( ( slen - i ) >= 2 && 131 | src[i] == '\r' && src[i + 1] == '\n' ) 132 | continue; 133 | 134 | if( src[i] == '\n' ) 135 | continue; 136 | 137 | if( src[i] == '=' && ++j > 2 ) 138 | return( XYSSL_ERR_BASE64_INVALID_CHARACTER ); 139 | 140 | if( src[i] > 127 || base64_dec_map[src[i]] == 127 ) 141 | return( XYSSL_ERR_BASE64_INVALID_CHARACTER ); 142 | 143 | if( base64_dec_map[src[i]] < 64 && j != 0 ) 144 | return( XYSSL_ERR_BASE64_INVALID_CHARACTER ); 145 | 146 | n++; 147 | } 148 | 149 | if( n == 0 ) 150 | return( 0 ); 151 | 152 | n = ((n * 6) + 7) >> 3; 153 | 154 | if( *dlen < n ) 155 | { 156 | *dlen = n; 157 | return( XYSSL_ERR_BASE64_BUFFER_TOO_SMALL ); 158 | } 159 | 160 | for( j = 3, n = x = 0, p = dst; i > 0; i--, src++ ) 161 | { 162 | if( *src == '\r' || *src == '\n' ) 163 | continue; 164 | 165 | j -= ( base64_dec_map[*src] == 64 ); 166 | x = (x << 6) | ( base64_dec_map[*src] & 0x3F ); 167 | 168 | if( ++n == 4 ) 169 | { 170 | n = 0; 171 | if( j > 0 ) *p++ = (unsigned char)( x >> 16 ); 172 | if( j > 1 ) *p++ = (unsigned char)( x >> 8 ); 173 | if( j > 2 ) *p++ = (unsigned char)( x ); 174 | } 175 | } 176 | 177 | *dlen = p - dst; 178 | 179 | return( 0 ); 180 | } 181 | 182 | #if defined(XYSSL_SELF_TEST) 183 | 184 | #include 185 | #include 186 | 187 | static const unsigned char base64_test_dec[64] = 188 | { 189 | 0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD, 190 | 0xBF, 0x17, 0xD9, 0xA2, 0xC4, 0x17, 0x1A, 0x01, 191 | 0x94, 0xED, 0x8F, 0x1E, 0x11, 0xB3, 0xD7, 0x09, 192 | 0x0C, 0xB6, 0xE9, 0x10, 0x6F, 0x22, 0xEE, 0x13, 193 | 0xCA, 0xB3, 0x07, 0x05, 0x76, 0xC9, 0xFA, 0x31, 194 | 0x6C, 0x08, 0x34, 0xFF, 0x8D, 0xC2, 0x6C, 0x38, 195 | 0x00, 0x43, 0xE9, 0x54, 0x97, 0xAF, 0x50, 0x4B, 196 | 0xD1, 0x41, 0xBA, 0x95, 0x31, 0x5A, 0x0B, 0x97 197 | }; 198 | 199 | static const unsigned char base64_test_enc[] = 200 | "JEhuVodiWr2/F9mixBcaAZTtjx4Rs9cJDLbpEG8i7hPK" 201 | "swcFdsn6MWwINP+Nwmw4AEPpVJevUEvRQbqVMVoLlw=="; 202 | 203 | /* 204 | * Checkup routine 205 | */ 206 | int base64_self_test( int verbose ) 207 | { 208 | int len; 209 | unsigned char *src, buffer[128]; 210 | 211 | if( verbose != 0 ) 212 | printf( " Base64 encoding test: " ); 213 | 214 | len = sizeof( buffer ); 215 | src = (unsigned char *) base64_test_dec; 216 | 217 | if( base64_encode( buffer, &len, src, 64 ) != 0 || 218 | memcmp( base64_test_enc, buffer, 88 ) != 0 ) 219 | { 220 | if( verbose != 0 ) 221 | printf( "failed\n" ); 222 | 223 | return( 1 ); 224 | } 225 | 226 | if( verbose != 0 ) 227 | printf( "passed\n Base64 decoding test: " ); 228 | 229 | len = sizeof( buffer ); 230 | src = (unsigned char *) base64_test_enc; 231 | 232 | if( base64_decode( buffer, &len, src, 88 ) != 0 || 233 | memcmp( base64_test_dec, buffer, 64 ) != 0 ) 234 | { 235 | if( verbose != 0 ) 236 | printf( "failed\n" ); 237 | 238 | return( 1 ); 239 | } 240 | 241 | if( verbose != 0 ) 242 | printf( "passed\n\n" ); 243 | 244 | return( 0 ); 245 | } 246 | 247 | #endif 248 | 249 | #endif 250 | -------------------------------------------------------------------------------- /xyssl/base64.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file base64.h 3 | */ 4 | #ifndef XYSSL_BASE64_H 5 | #define XYSSL_BASE64_H 6 | 7 | #define XYSSL_ERR_BASE64_BUFFER_TOO_SMALL -0x0010 8 | #define XYSSL_ERR_BASE64_INVALID_CHARACTER -0x0012 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /** 15 | * \brief Encode a buffer into base64 format 16 | * 17 | * \param dst destination buffer 18 | * \param dlen size of the buffer 19 | * \param src source buffer 20 | * \param slen amount of data to be encoded 21 | * 22 | * \return 0 if successful, or XYSSL_ERR_BASE64_BUFFER_TOO_SMALL. 23 | * *dlen is always updated to reflect the amount 24 | * of data that has (or would have) been written. 25 | * 26 | * \note Call this function with *dlen = 0 to obtain the 27 | * required buffer size in *dlen 28 | */ 29 | int base64_encode( unsigned char *dst, int *dlen, 30 | unsigned char *src, int slen ); 31 | 32 | /** 33 | * \brief Decode a base64-formatted buffer 34 | * 35 | * \param dst destination buffer 36 | * \param dlen size of the buffer 37 | * \param src source buffer 38 | * \param slen amount of data to be decoded 39 | * 40 | * \return 0 if successful, XYSSL_ERR_BASE64_BUFFER_TOO_SMALL, or 41 | * XYSSL_ERR_BASE64_INVALID_DATA if the input data is not 42 | * correct. *dlen is always updated to reflect the amount 43 | * of data that has (or would have) been written. 44 | * 45 | * \note Call this function with *dlen = 0 to obtain the 46 | * required buffer size in *dlen 47 | */ 48 | int base64_decode( unsigned char *dst, int *dlen, 49 | unsigned char *src, int slen ); 50 | 51 | /** 52 | * \brief Checkup routine 53 | * 54 | * \return 0 if successful, or 1 if the test failed 55 | */ 56 | int base64_self_test( int verbose ); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* base64.h */ 63 | -------------------------------------------------------------------------------- /xyssl/certs.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file certs.h 3 | */ 4 | #ifndef XYSSL_CERTS_H 5 | #define XYSSL_CERTS_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | extern char test_ca_crt[]; 12 | extern char test_ca_key[]; 13 | extern char test_ca_pwd[]; 14 | extern char test_srv_crt[]; 15 | extern char test_srv_key[]; 16 | extern char test_cli_crt[]; 17 | extern char test_cli_key[]; 18 | extern char xyssl_ca_crt[]; 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif /* certs.h */ 25 | -------------------------------------------------------------------------------- /xyssl/config.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file config.h 3 | * 4 | * This set of compile-time options may be used to enable 5 | * or disable features selectively, and reduce the global 6 | * memory footprint. 7 | */ 8 | #ifndef XYSSL_CONFIG_H 9 | #define XYSSL_CONFIG_H 10 | 11 | #ifndef _CRT_SECURE_NO_DEPRECATE 12 | #define _CRT_SECURE_NO_DEPRECATE 1 13 | #endif 14 | 15 | /* 16 | * Uncomment if native integers are 8-bit wide. 17 | * 18 | #define XYSSL_HAVE_INT8 19 | */ 20 | 21 | /* 22 | * Uncomment if native integers are 16-bit wide. 23 | * 24 | #define XYSSL_HAVE_INT16 25 | */ 26 | 27 | /* 28 | * Uncomment if the compiler supports long long. 29 | * 30 | #define XYSSL_HAVE_LONGLONG 31 | */ 32 | 33 | /* 34 | * Uncomment to enable the use of assembly code. 35 | */ 36 | #define XYSSL_HAVE_ASM 37 | 38 | /* 39 | * Uncomment if the CPU supports SSE2 (IA-32 specific). 40 | * 41 | #define XYSSL_HAVE_SSE2 42 | */ 43 | 44 | /* 45 | * Enable all SSL/TLS debugging messages. 46 | */ 47 | #define XYSSL_DEBUG_MSG 48 | 49 | /* 50 | * Enable the checkup functions (*_self_test). 51 | */ 52 | #define XYSSL_SELF_TEST 53 | 54 | /* 55 | * Enable the prime-number generation code. 56 | */ 57 | #define XYSSL_GENPRIME 58 | 59 | /* 60 | * Uncomment this macro to store the AES tables in ROM. 61 | * 62 | #define XYSSL_AES_ROM_TABLES 63 | */ 64 | 65 | /* 66 | * Module: library/aes.c 67 | * Caller: library/ssl_tls.c 68 | * 69 | * This module enables the following ciphersuites: 70 | * SSL_RSA_AES_128_SHA 71 | * SSL_RSA_AES_256_SHA 72 | * SSL_EDH_RSA_AES_256_SHA 73 | */ 74 | #define XYSSL_AES_C 75 | 76 | /* 77 | * Module: library/arc4.c 78 | * Caller: library/ssl_tls.c 79 | * 80 | * This module enables the following ciphersuites: 81 | * SSL_RSA_RC4_128_MD5 82 | * SSL_RSA_RC4_128_SHA 83 | */ 84 | #define XYSSL_ARC4_C 85 | 86 | /* 87 | * Module: library/base64.c 88 | * Caller: library/x509parse.c 89 | * 90 | * This module is required for X.509 support. 91 | */ 92 | #define XYSSL_BASE64_C 93 | 94 | /* 95 | * Module: library/bignum.c 96 | * Caller: library/dhm.c 97 | * library/rsa.c 98 | * library/ssl_tls.c 99 | * library/x509parse.c 100 | * 101 | * This module is required for RSA and DHM support. 102 | */ 103 | #define XYSSL_BIGNUM_C 104 | 105 | /* 106 | * Module: library/certs.c 107 | * Caller: 108 | * 109 | * This module is used for testing (ssl_client/server). 110 | */ 111 | #define XYSSL_CERTS_C 112 | 113 | /* 114 | * Module: library/debug.c 115 | * Caller: library/ssl_cli.c 116 | * library/ssl_srv.c 117 | * library/ssl_tls.c 118 | * 119 | * This module provides debugging functions. 120 | */ 121 | #define XYSSL_DEBUG_C 122 | 123 | /* 124 | * Module: library/des.c 125 | * Caller: library/ssl_tls.c 126 | * 127 | * This module enables the following ciphersuites: 128 | * SSL_RSA_DES_168_SHA 129 | * SSL_EDH_RSA_DES_168_SHA 130 | */ 131 | #define XYSSL_DES_C 132 | 133 | /* 134 | * Module: library/dhm.c 135 | * Caller: library/ssl_cli.c 136 | * library/ssl_srv.c 137 | * 138 | * This module enables the following ciphersuites: 139 | * SSL_EDH_RSA_DES_168_SHA 140 | * SSL_EDH_RSA_AES_256_SHA 141 | */ 142 | #define XYSSL_DHM_C 143 | 144 | /* 145 | * Module: library/havege.c 146 | * Caller: 147 | * 148 | * This module enables the HAVEGE random number generator. 149 | */ 150 | #define XYSSL_HAVEGE_C 151 | 152 | /* 153 | * Module: library/md2.c 154 | * Caller: library/x509parse.c 155 | * 156 | * Uncomment to enable support for (rare) MD2-signed X.509 certs. 157 | * 158 | #define XYSSL_MD2_C 159 | */ 160 | 161 | /* 162 | * Module: library/md4.c 163 | * Caller: library/x509parse.c 164 | * 165 | * Uncomment to enable support for (rare) MD4-signed X.509 certs. 166 | * 167 | #define XYSSL_MD4_C 168 | */ 169 | 170 | /* 171 | * Module: library/md5.c 172 | * Caller: library/ssl_tls.c 173 | * library/x509parse.c 174 | * 175 | * This module is required for SSL/TLS and X.509. 176 | */ 177 | #define XYSSL_MD5_C 178 | 179 | /* 180 | * Module: library/net.c 181 | * Caller: 182 | * 183 | * This module provides TCP/IP networking routines. 184 | */ 185 | #define XYSSL_NET_C 186 | 187 | /* 188 | * Module: library/padlock.c 189 | * Caller: library/aes.c 190 | * 191 | * This modules adds support for the VIA PadLock on x86. 192 | */ 193 | #define XYSSL_PADLOCK_C 194 | 195 | /* 196 | * Module: library/rsa.c 197 | * Caller: library/ssl_cli.c 198 | * library/ssl_srv.c 199 | * library/ssl_tls.c 200 | * library/x509.c 201 | * 202 | * This module is required for SSL/TLS and MD5-signed certificates. 203 | */ 204 | #define XYSSL_RSA_C 205 | 206 | /* 207 | * Module: library/sha1.c 208 | * Caller: library/ssl_cli.c 209 | * library/ssl_srv.c 210 | * library/ssl_tls.c 211 | * library/x509parse.c 212 | * 213 | * This module is required for SSL/TLS and SHA1-signed certificates. 214 | */ 215 | #define XYSSL_SHA1_C 216 | 217 | /* 218 | * Module: library/sha2.c 219 | * Caller: 220 | * 221 | * This module adds support for SHA-224 and SHA-256. 222 | */ 223 | #define XYSSL_SHA2_C 224 | 225 | /* 226 | * Module: library/sha4.c 227 | * Caller: 228 | * 229 | * This module adds support for SHA-384 and SHA-512. 230 | */ 231 | #define XYSSL_SHA4_C 232 | 233 | /* 234 | * Module: library/ssl_cli.c 235 | * Caller: 236 | * 237 | * This module is required for SSL/TLS client support. 238 | */ 239 | #define XYSSL_SSL_CLI_C 240 | 241 | /* 242 | * Module: library/ssl_srv.c 243 | * Caller: 244 | * 245 | * This module is required for SSL/TLS server support. 246 | */ 247 | #define XYSSL_SSL_SRV_C 248 | 249 | /* 250 | * Module: library/ssl_tls.c 251 | * Caller: library/ssl_cli.c 252 | * library/ssl_srv.c 253 | * 254 | * This module is required for SSL/TLS. 255 | */ 256 | #define XYSSL_SSL_TLS_C 257 | 258 | /* 259 | * Module: library/timing.c 260 | * Caller: library/havege.c 261 | * 262 | * This module is used by the HAVEGE random number generator. 263 | */ 264 | #define XYSSL_TIMING_C 265 | 266 | /* 267 | * Module: library/x509parse.c 268 | * Caller: library/ssl_cli.c 269 | * library/ssl_srv.c 270 | * library/ssl_tls.c 271 | * 272 | * This module is required for X.509 certificate parsing. 273 | */ 274 | #define XYSSL_X509_PARSE_C 275 | 276 | /* 277 | * Module: library/x509_write.c 278 | * Caller: 279 | * 280 | * This module is required for X.509 certificate writing. 281 | */ 282 | #define XYSSL_X509_WRITE_C 283 | 284 | #endif /* config.h */ 285 | -------------------------------------------------------------------------------- /xyssl/debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Debugging routines 3 | * 4 | * Copyright (C) 2006-2007 Christophe Devine 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | #include "config.h" 22 | 23 | #if defined(XYSSL_DEBUG_C) 24 | 25 | #include "debug.h" 26 | 27 | #include 28 | #include 29 | 30 | #if defined _MSC_VER && !defined snprintf 31 | #define snprintf _snprintf 32 | #endif 33 | 34 | #if defined _MSC_VER && !defined vsnprintf 35 | #define vsnprintf _vsnprintf 36 | #endif 37 | 38 | char *debug_fmt( const char *format, ... ) 39 | { 40 | va_list argp; 41 | static char str[512]; 42 | int maxlen = sizeof( str ) - 1; 43 | 44 | va_start( argp, format ); 45 | vsnprintf( str, maxlen, format, argp ); 46 | va_end( argp ); 47 | 48 | str[maxlen] = '\0'; 49 | return( str ); 50 | } 51 | 52 | void debug_print_msg( ssl_context *ssl, int level, 53 | char *file, int line, char *text ) 54 | { 55 | char str[512]; 56 | int maxlen = sizeof( str ) - 1; 57 | 58 | if( ssl->f_dbg == NULL ) 59 | return; 60 | 61 | snprintf( str, maxlen, "%s(%04d): %s\n", file, line, text ); 62 | str[maxlen] = '\0'; 63 | ssl->f_dbg( ssl->p_dbg, level, str ); 64 | } 65 | 66 | void debug_print_ret( ssl_context *ssl, int level, 67 | char *file, int line, char *text, int ret ) 68 | { 69 | char str[512]; 70 | int maxlen = sizeof( str ) - 1; 71 | 72 | if( ssl->f_dbg == NULL ) 73 | return; 74 | 75 | snprintf( str, maxlen, "%s(%04d): %s() returned %d (0x%x)\n", 76 | file, line, text, ret, ret ); 77 | 78 | str[maxlen] = '\0'; 79 | ssl->f_dbg( ssl->p_dbg, level, str ); 80 | } 81 | 82 | void debug_print_buf( ssl_context *ssl, int level, 83 | char *file, int line, char *text, 84 | unsigned char *buf, int len ) 85 | { 86 | char str[512]; 87 | int i, maxlen = sizeof( str ) - 1; 88 | 89 | if( ssl->f_dbg == NULL || len < 0 ) 90 | return; 91 | 92 | snprintf( str, maxlen, "%s(%04d): dumping '%s' (%d bytes)\n", 93 | file, line, text, len ); 94 | 95 | str[maxlen] = '\0'; 96 | ssl->f_dbg( ssl->p_dbg, level, str ); 97 | 98 | for( i = 0; i < len; i++ ) 99 | { 100 | if( i >= 4096 ) 101 | break; 102 | 103 | if( i % 16 == 0 ) 104 | { 105 | if( i > 0 ) 106 | ssl->f_dbg( ssl->p_dbg, level, "\n" ); 107 | 108 | snprintf( str, maxlen, "%s(%04d): %04x: ", file, line, i ); 109 | 110 | str[maxlen] = '\0'; 111 | ssl->f_dbg( ssl->p_dbg, level, str ); 112 | } 113 | 114 | snprintf( str, maxlen, " %02x", (unsigned int) buf[i] ); 115 | 116 | str[maxlen] = '\0'; 117 | ssl->f_dbg( ssl->p_dbg, level, str ); 118 | } 119 | 120 | if( len > 0 ) 121 | ssl->f_dbg( ssl->p_dbg, level, "\n" ); 122 | } 123 | 124 | void debug_print_mpi( ssl_context *ssl, int level, 125 | char *file, int line, char *text, mpi *X ) 126 | { 127 | char str[512]; 128 | int i, j, k, n, maxlen = sizeof( str ) - 1; 129 | 130 | if( ssl->f_dbg == NULL || X == NULL ) 131 | return; 132 | 133 | for( n = X->n - 1; n >= 0; n-- ) 134 | if( X->p[n] != 0 ) 135 | break; 136 | 137 | snprintf( str, maxlen, "%s(%04d): value of '%s' (%d bits) is:\n", 138 | file, line, text, ((n + 1) * sizeof( t_int )) << 3 ); 139 | 140 | str[maxlen] = '\0'; 141 | ssl->f_dbg( ssl->p_dbg, level, str ); 142 | 143 | for( i = n, j = 0; i >= 0; i--, j++ ) 144 | { 145 | if( j % ( 16 / sizeof( t_int ) ) == 0 ) 146 | { 147 | if( j > 0 ) 148 | ssl->f_dbg( ssl->p_dbg, level, "\n" ); 149 | 150 | snprintf( str, maxlen, "%s(%04d): ", file, line ); 151 | 152 | str[maxlen] = '\0'; 153 | ssl->f_dbg( ssl->p_dbg, level, str ); 154 | } 155 | 156 | for( k = sizeof( t_int ) - 1; k >= 0; k-- ) 157 | { 158 | snprintf( str, maxlen, " %02x", (unsigned int) 159 | ( X->p[i] >> (k << 3) ) & 0xFF ); 160 | 161 | str[maxlen] = '\0'; 162 | ssl->f_dbg( ssl->p_dbg, level, str ); 163 | } 164 | } 165 | 166 | ssl->f_dbg( ssl->p_dbg, level, "\n" ); 167 | } 168 | 169 | void debug_print_crt( ssl_context *ssl, int level, 170 | char *file, int line, char *text, x509_cert *crt ) 171 | { 172 | char str[512], prefix[64], *p; 173 | int i = 0, maxlen = sizeof( prefix ) - 1; 174 | 175 | if( ssl->f_dbg == NULL || crt == NULL ) 176 | return; 177 | 178 | snprintf( prefix, maxlen, "%s(%04d): ", file, line ); 179 | prefix[maxlen] = '\0'; 180 | maxlen = sizeof( str ) - 1; 181 | 182 | while( crt != NULL && crt->next != NULL ) 183 | { 184 | p = x509parse_cert_info( prefix, crt ); 185 | 186 | snprintf( str, maxlen, "%s(%04d): %s #%d:\n%s", 187 | file, line, text, ++i, p ); 188 | 189 | str[maxlen] = '\0'; 190 | ssl->f_dbg( ssl->p_dbg, level, str ); 191 | 192 | debug_print_mpi( ssl, level, file, line, 193 | "crt->rsa.N", &crt->rsa.N ); 194 | 195 | debug_print_mpi( ssl, level, file, line, 196 | "crt->rsa.E", &crt->rsa.E ); 197 | 198 | crt = crt->next; 199 | } 200 | } 201 | 202 | #endif 203 | -------------------------------------------------------------------------------- /xyssl/debug.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file debug.h 3 | */ 4 | #ifndef SSL_DEBUG_H 5 | #define SSL_DEBUG_H 6 | 7 | #include "config.h" 8 | #include "ssl.h" 9 | 10 | #if defined(XYSSL_DEBUG_MSG) 11 | 12 | #define SSL_DEBUG_MSG( level, args ) \ 13 | debug_print_msg( ssl, level, __FILE__, __LINE__, debug_fmt args ); 14 | 15 | #define SSL_DEBUG_RET( level, text, ret ) \ 16 | debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret ); 17 | 18 | #define SSL_DEBUG_BUF( level, text, buf, len ) \ 19 | debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len ); 20 | 21 | #define SSL_DEBUG_MPI( level, text, X ) \ 22 | debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X ); 23 | 24 | #define SSL_DEBUG_CRT( level, text, crt ) \ 25 | debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt ); 26 | 27 | #else 28 | 29 | #define SSL_DEBUG_MSG( level, args ) do { } while( 0 ) 30 | #define SSL_DEBUG_RET( level, text, ret ) do { } while( 0 ) 31 | #define SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 ) 32 | #define SSL_DEBUG_MPI( level, text, X ) do { } while( 0 ) 33 | #define SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 ) 34 | 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | char *debug_fmt( const char *format, ... ); 42 | 43 | void debug_print_msg( ssl_context *ssl, int level, 44 | char *file, int line, char *text ); 45 | 46 | void debug_print_ret( ssl_context *ssl, int level, 47 | char *file, int line, char *text, int ret ); 48 | 49 | void debug_print_buf( ssl_context *ssl, int level, 50 | char *file, int line, char *text, 51 | unsigned char *buf, int len ); 52 | 53 | void debug_print_mpi( ssl_context *ssl, int level, 54 | char *file, int line, char *text, mpi *X ); 55 | 56 | void debug_print_crt( ssl_context *ssl, int level, 57 | char *file, int line, char *text, x509_cert *crt ); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* debug.h */ 64 | -------------------------------------------------------------------------------- /xyssl/des.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file des.h 3 | */ 4 | #ifndef XYSSL_DES_H 5 | #define XYSSL_DES_H 6 | 7 | #define DES_ENCRYPT 1 8 | #define DES_DECRYPT 0 9 | 10 | /** 11 | * \brief DES context structure 12 | */ 13 | typedef struct 14 | { 15 | int mode; /*!< encrypt/decrypt */ 16 | unsigned long sk[32]; /*!< DES subkeys */ 17 | } 18 | des_context; 19 | 20 | /** 21 | * \brief Triple-DES context structure 22 | */ 23 | typedef struct 24 | { 25 | int mode; /*!< encrypt/decrypt */ 26 | unsigned long sk[96]; /*!< 3DES subkeys */ 27 | } 28 | des3_context; 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * \brief DES key schedule (56-bit, encryption) 36 | * 37 | * \param ctx DES context to be initialized 38 | * \param key 8-byte secret key 39 | */ 40 | void des_setkey_enc( des_context *ctx, unsigned char key[8] ); 41 | 42 | /** 43 | * \brief DES key schedule (56-bit, decryption) 44 | * 45 | * \param ctx DES context to be initialized 46 | * \param key 8-byte secret key 47 | */ 48 | void des_setkey_dec( des_context *ctx, unsigned char key[8] ); 49 | 50 | /** 51 | * \brief Triple-DES key schedule (112-bit, encryption) 52 | * 53 | * \param ctx 3DES context to be initialized 54 | * \param key 16-byte secret key 55 | */ 56 | void des3_set2key_enc( des3_context *ctx, unsigned char key[16] ); 57 | 58 | /** 59 | * \brief Triple-DES key schedule (112-bit, decryption) 60 | * 61 | * \param ctx 3DES context to be initialized 62 | * \param key 16-byte secret key 63 | */ 64 | void des3_set2key_dec( des3_context *ctx, unsigned char key[16] ); 65 | 66 | /** 67 | * \brief Triple-DES key schedule (168-bit, encryption) 68 | * 69 | * \param ctx 3DES context to be initialized 70 | * \param key 24-byte secret key 71 | */ 72 | void des3_set3key_enc( des3_context *ctx, unsigned char key[24] ); 73 | 74 | /** 75 | * \brief Triple-DES key schedule (168-bit, decryption) 76 | * 77 | * \param ctx 3DES context to be initialized 78 | * \param key 24-byte secret key 79 | */ 80 | void des3_set3key_dec( des3_context *ctx, unsigned char key[24] ); 81 | 82 | /** 83 | * \brief DES-ECB block encryption/decryption 84 | * 85 | * \param ctx DES context 86 | * \param input 64-bit input block 87 | * \param output 64-bit output block 88 | */ 89 | void des_crypt_ecb( des_context *ctx, 90 | unsigned char input[8], 91 | unsigned char output[8] ); 92 | 93 | /** 94 | * \brief DES-CBC buffer encryption/decryption 95 | * 96 | * \param ctx DES context 97 | * \param mode DES_ENCRYPT or DES_DECRYPT 98 | * \param length length of the input data 99 | * \param iv initialization vector (updated after use) 100 | * \param input buffer holding the input data 101 | * \param output buffer holding the output data 102 | */ 103 | void des_crypt_cbc( des_context *ctx, 104 | int mode, 105 | int length, 106 | unsigned char iv[8], 107 | unsigned char *input, 108 | unsigned char *output ); 109 | 110 | /** 111 | * \brief 3DES-ECB block encryption/decryption 112 | * 113 | * \param ctx 3DES context 114 | * \param input 64-bit input block 115 | * \param output 64-bit output block 116 | */ 117 | void des3_crypt_ecb( des3_context *ctx, 118 | unsigned char input[8], 119 | unsigned char output[8] ); 120 | 121 | /** 122 | * \brief 3DES-CBC buffer encryption/decryption 123 | * 124 | * \param ctx 3DES context 125 | * \param mode DES_ENCRYPT or DES_DECRYPT 126 | * \param length length of the input data 127 | * \param iv initialization vector (updated after use) 128 | * \param input buffer holding the input data 129 | * \param output buffer holding the output data 130 | */ 131 | void des3_crypt_cbc( des3_context *ctx, 132 | int mode, 133 | int length, 134 | unsigned char iv[8], 135 | unsigned char *input, 136 | unsigned char *output ); 137 | 138 | /* 139 | * \brief Checkup routine 140 | * 141 | * \return 0 if successful, or 1 if the test failed 142 | */ 143 | int des_self_test( int verbose ); 144 | 145 | #ifdef __cplusplus 146 | } 147 | #endif 148 | 149 | #endif /* des.h */ 150 | -------------------------------------------------------------------------------- /xyssl/dhm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Diffie-Hellman-Merkle key exchange 3 | * 4 | * Copyright (C) 2006-2007 Christophe Devine 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | /* 21 | * Reference: 22 | * 23 | * http://www.cacr.math.uwaterloo.ca/hac/ (chapter 12) 24 | */ 25 | 26 | #include "config.h" 27 | 28 | #if defined(XYSSL_DHM_C) 29 | 30 | #include "dhm.h" 31 | 32 | #include 33 | 34 | /* 35 | * helper to validate the mpi size and import it 36 | */ 37 | static int dhm_read_bignum( mpi *X, 38 | unsigned char **p, 39 | unsigned char *end ) 40 | { 41 | int ret, n; 42 | 43 | if( end - *p < 2 ) 44 | return( XYSSL_ERR_DHM_BAD_INPUT_DATA ); 45 | 46 | n = ( (*p)[0] << 8 ) | (*p)[1]; 47 | (*p) += 2; 48 | 49 | if( (int)( end - *p ) < n ) 50 | return( XYSSL_ERR_DHM_BAD_INPUT_DATA ); 51 | 52 | if( ( ret = mpi_read_binary( X, *p, n ) ) != 0 ) 53 | return( XYSSL_ERR_DHM_READ_PARAMS_FAILED | ret ); 54 | 55 | (*p) += n; 56 | 57 | return( 0 ); 58 | } 59 | 60 | /* 61 | * Parse the ServerKeyExchange parameters 62 | */ 63 | int dhm_read_params( dhm_context *ctx, 64 | unsigned char **p, 65 | unsigned char *end ) 66 | { 67 | int ret, n; 68 | 69 | memset( ctx, 0, sizeof( dhm_context ) ); 70 | 71 | if( ( ret = dhm_read_bignum( &ctx->P, p, end ) ) != 0 || 72 | ( ret = dhm_read_bignum( &ctx->G, p, end ) ) != 0 || 73 | ( ret = dhm_read_bignum( &ctx->GY, p, end ) ) != 0 ) 74 | return( ret ); 75 | 76 | ctx->len = mpi_size( &ctx->P ); 77 | 78 | if( end - *p < 2 ) 79 | return( XYSSL_ERR_DHM_BAD_INPUT_DATA ); 80 | 81 | n = ( (*p)[0] << 8 ) | (*p)[1]; 82 | (*p) += 2; 83 | 84 | if( end != *p + n ) 85 | return( XYSSL_ERR_DHM_BAD_INPUT_DATA ); 86 | 87 | return( 0 ); 88 | } 89 | 90 | /* 91 | * Setup and write the ServerKeyExchange parameters 92 | */ 93 | int dhm_make_params( dhm_context *ctx, int x_size, 94 | unsigned char *output, int *olen, 95 | int (*f_rng)(void *), void *p_rng ) 96 | { 97 | int i, ret, n, n1, n2, n3; 98 | unsigned char *p; 99 | 100 | /* 101 | * generate X and calculate GX = G^X mod P 102 | */ 103 | n = x_size / sizeof( t_int ); 104 | MPI_CHK( mpi_grow( &ctx->X, n ) ); 105 | MPI_CHK( mpi_lset( &ctx->X, 0 ) ); 106 | 107 | n = x_size >> 3; 108 | p = (unsigned char *) ctx->X.p; 109 | for( i = 0; i < n; i++ ) 110 | *p++ = (unsigned char) f_rng( p_rng ); 111 | 112 | while( mpi_cmp_mpi( &ctx->X, &ctx->P ) >= 0 ) 113 | mpi_shift_r( &ctx->X, 1 ); 114 | 115 | MPI_CHK( mpi_exp_mod( &ctx->GX, &ctx->G, &ctx->X, 116 | &ctx->P , &ctx->RP ) ); 117 | 118 | /* 119 | * export P, G, GX 120 | */ 121 | #define DHM_MPI_EXPORT(X,n) \ 122 | MPI_CHK( mpi_write_binary( X, p + 2, n ) ); \ 123 | *p++ = (unsigned char)( n >> 8 ); \ 124 | *p++ = (unsigned char)( n ); p += n; 125 | 126 | n1 = mpi_size( &ctx->P ); 127 | n2 = mpi_size( &ctx->G ); 128 | n3 = mpi_size( &ctx->GX ); 129 | 130 | p = output; 131 | DHM_MPI_EXPORT( &ctx->P , n1 ); 132 | DHM_MPI_EXPORT( &ctx->G , n2 ); 133 | DHM_MPI_EXPORT( &ctx->GX, n3 ); 134 | 135 | *olen = p - output; 136 | 137 | ctx->len = n1; 138 | 139 | cleanup: 140 | 141 | if( ret != 0 ) 142 | return( ret | XYSSL_ERR_DHM_MAKE_PARAMS_FAILED ); 143 | 144 | return( 0 ); 145 | } 146 | 147 | /* 148 | * Import the peer's public value G^Y 149 | */ 150 | int dhm_read_public( dhm_context *ctx, 151 | unsigned char *input, int ilen ) 152 | { 153 | int ret; 154 | 155 | if( ctx == NULL || ilen < 1 || ilen > ctx->len ) 156 | return( XYSSL_ERR_DHM_BAD_INPUT_DATA ); 157 | 158 | if( ( ret = mpi_read_binary( &ctx->GY, input, ilen ) ) != 0 ) 159 | return( XYSSL_ERR_DHM_READ_PUBLIC_FAILED | ret ); 160 | 161 | return( 0 ); 162 | } 163 | 164 | /* 165 | * Create own private value X and export G^X 166 | */ 167 | int dhm_make_public( dhm_context *ctx, int x_size, 168 | unsigned char *output, int olen, 169 | int (*f_rng)(void *), void *p_rng ) 170 | { 171 | int ret, i, n; 172 | unsigned char *p; 173 | 174 | if( ctx == NULL || olen < 1 || olen > ctx->len ) 175 | return( XYSSL_ERR_DHM_BAD_INPUT_DATA ); 176 | 177 | /* 178 | * generate X and calculate GX = G^X mod P 179 | */ 180 | n = x_size / sizeof( t_int ); 181 | MPI_CHK( mpi_grow( &ctx->X, n ) ); 182 | MPI_CHK( mpi_lset( &ctx->X, 0 ) ); 183 | 184 | n = x_size >> 3; 185 | p = (unsigned char *) ctx->X.p; 186 | for( i = 0; i < n; i++ ) 187 | *p++ = (unsigned char) f_rng( p_rng ); 188 | 189 | while( mpi_cmp_mpi( &ctx->X, &ctx->P ) >= 0 ) 190 | mpi_shift_r( &ctx->X, 1 ); 191 | 192 | MPI_CHK( mpi_exp_mod( &ctx->GX, &ctx->G, &ctx->X, 193 | &ctx->P , &ctx->RP ) ); 194 | 195 | MPI_CHK( mpi_write_binary( &ctx->GX, output, olen ) ); 196 | 197 | cleanup: 198 | 199 | if( ret != 0 ) 200 | return( XYSSL_ERR_DHM_MAKE_PUBLIC_FAILED | ret ); 201 | 202 | return( 0 ); 203 | } 204 | 205 | /* 206 | * Derive and export the shared secret (G^Y)^X mod P 207 | */ 208 | int dhm_calc_secret( dhm_context *ctx, 209 | unsigned char *output, int *olen ) 210 | { 211 | int ret; 212 | 213 | if( ctx == NULL || *olen < ctx->len ) 214 | return( XYSSL_ERR_DHM_BAD_INPUT_DATA ); 215 | 216 | MPI_CHK( mpi_exp_mod( &ctx->K, &ctx->GY, &ctx->X, 217 | &ctx->P, &ctx->RP ) ); 218 | 219 | *olen = mpi_size( &ctx->K ); 220 | 221 | MPI_CHK( mpi_write_binary( &ctx->K, output, *olen ) ); 222 | 223 | cleanup: 224 | 225 | if( ret != 0 ) 226 | return( XYSSL_ERR_DHM_CALC_SECRET_FAILED | ret ); 227 | 228 | return( 0 ); 229 | } 230 | 231 | /* 232 | * Free the components of a DHM key 233 | */ 234 | void dhm_free( dhm_context *ctx ) 235 | { 236 | mpi_free( &ctx->RP, &ctx->K, &ctx->GY, 237 | &ctx->GX, &ctx->X, &ctx->G, 238 | &ctx->P, NULL ); 239 | } 240 | 241 | #if defined(XYSSL_SELF_TEST) 242 | 243 | /* 244 | * Checkup routine 245 | */ 246 | int dhm_self_test( int verbose ) 247 | { 248 | return( verbose++ ); 249 | } 250 | 251 | #endif 252 | 253 | #endif 254 | -------------------------------------------------------------------------------- /xyssl/dhm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file dhm.h 3 | */ 4 | #ifndef XYSSL_DHM_H 5 | #define XYSSL_DHM_H 6 | 7 | #include "bignum.h" 8 | 9 | #define XYSSL_ERR_DHM_BAD_INPUT_DATA -0x0480 10 | #define XYSSL_ERR_DHM_READ_PARAMS_FAILED -0x0490 11 | #define XYSSL_ERR_DHM_MAKE_PARAMS_FAILED -0x04A0 12 | #define XYSSL_ERR_DHM_READ_PUBLIC_FAILED -0x04B0 13 | #define XYSSL_ERR_DHM_MAKE_PUBLIC_FAILED -0x04C0 14 | #define XYSSL_ERR_DHM_CALC_SECRET_FAILED -0x04D0 15 | 16 | typedef struct 17 | { 18 | int len; /*!< size(P) in chars */ 19 | mpi P; /*!< prime modulus */ 20 | mpi G; /*!< generator */ 21 | mpi X; /*!< secret value */ 22 | mpi GX; /*!< self = G^X mod P */ 23 | mpi GY; /*!< peer = G^Y mod P */ 24 | mpi K; /*!< key = GY^X mod P */ 25 | mpi RP; /*!< cached R^2 mod P */ 26 | } 27 | dhm_context; 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | /** 34 | * \brief Parse the ServerKeyExchange parameters 35 | * 36 | * \param ctx DHM context 37 | * \param p &(start of input buffer) 38 | * \param end end of buffer 39 | * 40 | * \return 0 if successful, or an XYSSL_ERR_DHM_XXX error code 41 | */ 42 | int dhm_read_params( dhm_context *ctx, 43 | unsigned char **p, 44 | unsigned char *end ); 45 | 46 | /** 47 | * \brief Setup and write the ServerKeyExchange parameters 48 | * 49 | * \param ctx DHM context 50 | * \param x_size private value size in bits 51 | * \param output destination buffer 52 | * \param olen number of chars written 53 | * \param f_rng RNG function 54 | * \param p_rng RNG parameter 55 | * 56 | * \note This function assumes that ctx->P and ctx->G 57 | * have already been properly set (for example 58 | * using mpi_read_string or mpi_read_binary). 59 | * 60 | * \return 0 if successful, or an XYSSL_ERR_DHM_XXX error code 61 | */ 62 | int dhm_make_params( dhm_context *ctx, int s_size, 63 | unsigned char *output, int *olen, 64 | int (*f_rng)(void *), void *p_rng ); 65 | 66 | /** 67 | * \brief Import the peer's public value G^Y 68 | * 69 | * \param ctx DHM context 70 | * \param input input buffer 71 | * \param ilen size of buffer 72 | * 73 | * \return 0 if successful, or an XYSSL_ERR_DHM_XXX error code 74 | */ 75 | int dhm_read_public( dhm_context *ctx, 76 | unsigned char *input, int ilen ); 77 | 78 | /** 79 | * \brief Create own private value X and export G^X 80 | * 81 | * \param ctx DHM context 82 | * \param x_size private value size in bits 83 | * \param output destination buffer 84 | * \param olen must be equal to ctx->P.len 85 | * \param f_rng RNG function 86 | * \param p_rng RNG parameter 87 | * 88 | * \return 0 if successful, or an XYSSL_ERR_DHM_XXX error code 89 | */ 90 | int dhm_make_public( dhm_context *ctx, int s_size, 91 | unsigned char *output, int olen, 92 | int (*f_rng)(void *), void *p_rng ); 93 | 94 | /** 95 | * \brief Derive and export the shared secret (G^Y)^X mod P 96 | * 97 | * \param ctx DHM context 98 | * \param output destination buffer 99 | * \param olen number of chars written 100 | * 101 | * \return 0 if successful, or an XYSSL_ERR_DHM_XXX error code 102 | */ 103 | int dhm_calc_secret( dhm_context *ctx, 104 | unsigned char *output, int *olen ); 105 | 106 | /* 107 | * \brief Free the components of a DHM key 108 | */ 109 | void dhm_free( dhm_context *ctx ); 110 | 111 | /** 112 | * \brief Checkup routine 113 | * 114 | * \return 0 if successful, or 1 if the test failed 115 | */ 116 | int dhm_self_test( int verbose ); 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /xyssl/havege.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file havege.h 3 | */ 4 | #ifndef XYSSL_HAVEGE_H 5 | #define XYSSL_HAVEGE_H 6 | 7 | #define COLLECT_SIZE 1024 8 | 9 | /** 10 | * \brief HAVEGE state structure 11 | */ 12 | typedef struct 13 | { 14 | int PT1, PT2, offset[2]; 15 | int pool[COLLECT_SIZE]; 16 | int WALK[8192]; 17 | } 18 | havege_state; 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /** 25 | * \brief HAVEGE initialization 26 | * 27 | * \param hs HAVEGE state to be initialized 28 | */ 29 | void havege_init( havege_state *hs ); 30 | 31 | /** 32 | * \brief HAVEGE rand function 33 | * 34 | * \param rng_st points to an HAVEGE state 35 | * 36 | * \return A random int 37 | */ 38 | int havege_rand( void *p_rng ); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif /* havege.h */ 45 | -------------------------------------------------------------------------------- /xyssl/md2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file md2.h 3 | */ 4 | #ifndef XYSSL_MD2_H 5 | #define XYSSL_MD2_H 6 | 7 | /** 8 | * \brief MD2 context structure 9 | */ 10 | typedef struct 11 | { 12 | unsigned char cksum[16]; /*!< checksum of the data block */ 13 | unsigned char state[48]; /*!< intermediate digest state */ 14 | unsigned char buffer[16]; /*!< data block being processed */ 15 | 16 | unsigned char ipad[64]; /*!< HMAC: inner padding */ 17 | unsigned char opad[64]; /*!< HMAC: outer padding */ 18 | int left; /*!< amount of data in buffer */ 19 | } 20 | md2_context; 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /** 27 | * \brief MD2 context setup 28 | * 29 | * \param ctx context to be initialized 30 | */ 31 | void md2_starts( md2_context *ctx ); 32 | 33 | /** 34 | * \brief MD2 process buffer 35 | * 36 | * \param ctx MD2 context 37 | * \param input buffer holding the data 38 | * \param ilen length of the input data 39 | */ 40 | void md2_update( md2_context *ctx, unsigned char *input, int ilen ); 41 | 42 | /** 43 | * \brief MD2 final digest 44 | * 45 | * \param ctx MD2 context 46 | * \param output MD2 checksum result 47 | */ 48 | void md2_finish( md2_context *ctx, unsigned char output[16] ); 49 | 50 | /** 51 | * \brief Output = MD2( input buffer ) 52 | * 53 | * \param input buffer holding the data 54 | * \param ilen length of the input data 55 | * \param output MD2 checksum result 56 | */ 57 | void md2( unsigned char *input, int ilen, unsigned char output[16] ); 58 | 59 | /** 60 | * \brief Output = MD2( file contents ) 61 | * 62 | * \param path input file name 63 | * \param output MD2 checksum result 64 | * 65 | * \return 0 if successful, 1 if fopen failed, 66 | * or 2 if fread failed 67 | */ 68 | int md2_file( char *path, unsigned char output[16] ); 69 | 70 | /** 71 | * \brief MD2 HMAC context setup 72 | * 73 | * \param ctx HMAC context to be initialized 74 | * \param key HMAC secret key 75 | * \param keylen length of the HMAC key 76 | */ 77 | void md2_hmac_starts( md2_context *ctx, unsigned char *key, int keylen ); 78 | 79 | /** 80 | * \brief MD2 HMAC process buffer 81 | * 82 | * \param ctx HMAC context 83 | * \param input buffer holding the data 84 | * \param ilen length of the input data 85 | */ 86 | void md2_hmac_update( md2_context *ctx, unsigned char *input, int ilen ); 87 | 88 | /** 89 | * \brief MD2 HMAC final digest 90 | * 91 | * \param ctx HMAC context 92 | * \param output MD2 HMAC checksum result 93 | */ 94 | void md2_hmac_finish( md2_context *ctx, unsigned char output[16] ); 95 | 96 | /** 97 | * \brief Output = HMAC-MD2( hmac key, input buffer ) 98 | * 99 | * \param key HMAC secret key 100 | * \param keylen length of the HMAC key 101 | * \param input buffer holding the data 102 | * \param ilen length of the input data 103 | * \param output HMAC-MD2 result 104 | */ 105 | void md2_hmac( unsigned char *key, int keylen, 106 | unsigned char *input, int ilen, 107 | unsigned char output[16] ); 108 | 109 | /** 110 | * \brief Checkup routine 111 | * 112 | * \return 0 if successful, or 1 if the test failed 113 | */ 114 | int md2_self_test( int verbose ); 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | 120 | #endif /* md2.h */ 121 | -------------------------------------------------------------------------------- /xyssl/md4.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file md4.h 3 | */ 4 | #ifndef XYSSL_MD4_H 5 | #define XYSSL_MD4_H 6 | 7 | /** 8 | * \brief MD4 context structure 9 | */ 10 | typedef struct 11 | { 12 | unsigned long total[2]; /*!< number of bytes processed */ 13 | unsigned long state[4]; /*!< intermediate digest state */ 14 | unsigned char buffer[64]; /*!< data block being processed */ 15 | 16 | unsigned char ipad[64]; /*!< HMAC: inner padding */ 17 | unsigned char opad[64]; /*!< HMAC: outer padding */ 18 | } 19 | md4_context; 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /** 26 | * \brief MD4 context setup 27 | * 28 | * \param ctx context to be initialized 29 | */ 30 | void md4_starts( md4_context *ctx ); 31 | 32 | /** 33 | * \brief MD4 process buffer 34 | * 35 | * \param ctx MD4 context 36 | * \param input buffer holding the data 37 | * \param ilen length of the input data 38 | */ 39 | void md4_update( md4_context *ctx, unsigned char *input, int ilen ); 40 | 41 | /** 42 | * \brief MD4 final digest 43 | * 44 | * \param ctx MD4 context 45 | * \param output MD4 checksum result 46 | */ 47 | void md4_finish( md4_context *ctx, unsigned char output[16] ); 48 | 49 | /** 50 | * \brief Output = MD4( input buffer ) 51 | * 52 | * \param input buffer holding the data 53 | * \param ilen length of the input data 54 | * \param output MD4 checksum result 55 | */ 56 | void md4( unsigned char *input, int ilen, unsigned char output[16] ); 57 | 58 | /** 59 | * \brief Output = MD4( file contents ) 60 | * 61 | * \param path input file name 62 | * \param output MD4 checksum result 63 | * 64 | * \return 0 if successful, 1 if fopen failed, 65 | * or 2 if fread failed 66 | */ 67 | int md4_file( char *path, unsigned char output[16] ); 68 | 69 | /** 70 | * \brief MD4 HMAC context setup 71 | * 72 | * \param ctx HMAC context to be initialized 73 | * \param key HMAC secret key 74 | * \param keylen length of the HMAC key 75 | */ 76 | void md4_hmac_starts( md4_context *ctx, unsigned char *key, int keylen ); 77 | 78 | /** 79 | * \brief MD4 HMAC process buffer 80 | * 81 | * \param ctx HMAC context 82 | * \param input buffer holding the data 83 | * \param ilen length of the input data 84 | */ 85 | void md4_hmac_update( md4_context *ctx, unsigned char *input, int ilen ); 86 | 87 | /** 88 | * \brief MD4 HMAC final digest 89 | * 90 | * \param ctx HMAC context 91 | * \param output MD4 HMAC checksum result 92 | */ 93 | void md4_hmac_finish( md4_context *ctx, unsigned char output[16] ); 94 | 95 | /** 96 | * \brief Output = HMAC-MD4( hmac key, input buffer ) 97 | * 98 | * \param key HMAC secret key 99 | * \param keylen length of the HMAC key 100 | * \param input buffer holding the data 101 | * \param ilen length of the input data 102 | * \param output HMAC-MD4 result 103 | */ 104 | void md4_hmac( unsigned char *key, int keylen, 105 | unsigned char *input, int ilen, 106 | unsigned char output[16] ); 107 | 108 | /** 109 | * \brief Checkup routine 110 | * 111 | * \return 0 if successful, or 1 if the test failed 112 | */ 113 | int md4_self_test( int verbose ); 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif /* md4.h */ 120 | -------------------------------------------------------------------------------- /xyssl/md5.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file md5.h 3 | */ 4 | #ifndef XYSSL_MD5_H 5 | #define XYSSL_MD5_H 6 | 7 | /** 8 | * \brief MD5 context structure 9 | */ 10 | typedef struct 11 | { 12 | unsigned long total[2]; /*!< number of bytes processed */ 13 | unsigned long state[4]; /*!< intermediate digest state */ 14 | unsigned char buffer[64]; /*!< data block being processed */ 15 | 16 | unsigned char ipad[64]; /*!< HMAC: inner padding */ 17 | unsigned char opad[64]; /*!< HMAC: outer padding */ 18 | } 19 | md5_context; 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /** 26 | * \brief MD5 context setup 27 | * 28 | * \param ctx context to be initialized 29 | */ 30 | void md5_starts( md5_context *ctx ); 31 | 32 | /** 33 | * \brief MD5 process buffer 34 | * 35 | * \param ctx MD5 context 36 | * \param input buffer holding the data 37 | * \param ilen length of the input data 38 | */ 39 | void md5_update( md5_context *ctx, unsigned char *input, int ilen ); 40 | 41 | /** 42 | * \brief MD5 final digest 43 | * 44 | * \param ctx MD5 context 45 | * \param output MD5 checksum result 46 | */ 47 | void md5_finish( md5_context *ctx, unsigned char output[16] ); 48 | 49 | /** 50 | * \brief Output = MD5( input buffer ) 51 | * 52 | * \param input buffer holding the data 53 | * \param ilen length of the input data 54 | * \param output MD5 checksum result 55 | */ 56 | void md5( unsigned char *input, int ilen, unsigned char output[16] ); 57 | 58 | /** 59 | * \brief Output = MD5( file contents ) 60 | * 61 | * \param path input file name 62 | * \param output MD5 checksum result 63 | * 64 | * \return 0 if successful, 1 if fopen failed, 65 | * or 2 if fread failed 66 | */ 67 | int md5_file( char *path, unsigned char output[16] ); 68 | 69 | /** 70 | * \brief MD5 HMAC context setup 71 | * 72 | * \param ctx HMAC context to be initialized 73 | * \param key HMAC secret key 74 | * \param keylen length of the HMAC key 75 | */ 76 | void md5_hmac_starts( md5_context *ctx, unsigned char *key, int keylen ); 77 | 78 | /** 79 | * \brief MD5 HMAC process buffer 80 | * 81 | * \param ctx HMAC context 82 | * \param input buffer holding the data 83 | * \param ilen length of the input data 84 | */ 85 | void md5_hmac_update( md5_context *ctx, unsigned char *input, int ilen ); 86 | 87 | /** 88 | * \brief MD5 HMAC final digest 89 | * 90 | * \param ctx HMAC context 91 | * \param output MD5 HMAC checksum result 92 | */ 93 | void md5_hmac_finish( md5_context *ctx, unsigned char output[16] ); 94 | 95 | /** 96 | * \brief Output = HMAC-MD5( hmac key, input buffer ) 97 | * 98 | * \param key HMAC secret key 99 | * \param keylen length of the HMAC key 100 | * \param input buffer holding the data 101 | * \param ilen length of the input data 102 | * \param output HMAC-MD5 result 103 | */ 104 | void md5_hmac( unsigned char *key, int keylen, 105 | unsigned char *input, int ilen, 106 | unsigned char output[16] ); 107 | 108 | /** 109 | * \brief Checkup routine 110 | * 111 | * \return 0 if successful, or 1 if the test failed 112 | */ 113 | int md5_self_test( int verbose ); 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif /* md5.h */ 120 | -------------------------------------------------------------------------------- /xyssl/net.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file net.h 3 | */ 4 | #ifndef XYSSL_NET_H 5 | #define XYSSL_NET_H 6 | 7 | #define XYSSL_ERR_NET_UNKNOWN_HOST -0x0F00 8 | #define XYSSL_ERR_NET_SOCKET_FAILED -0x0F10 9 | #define XYSSL_ERR_NET_CONNECT_FAILED -0x0F20 10 | #define XYSSL_ERR_NET_BIND_FAILED -0x0F30 11 | #define XYSSL_ERR_NET_LISTEN_FAILED -0x0F40 12 | #define XYSSL_ERR_NET_ACCEPT_FAILED -0x0F50 13 | #define XYSSL_ERR_NET_RECV_FAILED -0x0F60 14 | #define XYSSL_ERR_NET_SEND_FAILED -0x0F70 15 | #define XYSSL_ERR_NET_CONN_RESET -0x0F80 16 | #define XYSSL_ERR_NET_TRY_AGAIN -0x0F90 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | * \brief Initiate a TCP connection with host:port 24 | * 25 | * \return 0 if successful, or one of: 26 | * XYSSL_ERR_NET_SOCKET_FAILED, 27 | * XYSSL_ERR_NET_UNKNOWN_HOST, 28 | * XYSSL_ERR_NET_CONNECT_FAILED 29 | */ 30 | int net_connect( int *fd, char *host, int port ); 31 | 32 | /** 33 | * \brief Create a listening socket on bind_ip:port. 34 | * If bind_ip == NULL, all interfaces are binded. 35 | * 36 | * \return 0 if successful, or one of: 37 | * XYSSL_ERR_NET_SOCKET_FAILED, 38 | * XYSSL_ERR_NET_BIND_FAILED, 39 | * XYSSL_ERR_NET_LISTEN_FAILED 40 | */ 41 | int net_bind( int *fd, char *bind_ip, int port ); 42 | 43 | /** 44 | * \brief Accept a connection from a remote client 45 | * 46 | * \return 0 if successful, XYSSL_ERR_NET_ACCEPT_FAILED, or 47 | * XYSSL_ERR_NET_WOULD_BLOCK is bind_fd was set to 48 | * non-blocking and accept() is blocking. 49 | */ 50 | int net_accept( int bind_fd, int *client_fd, void *client_ip ); 51 | 52 | /** 53 | * \brief Set the socket blocking 54 | * 55 | * \return 0 if successful, or a non-zero error code 56 | */ 57 | int net_set_block( int fd ); 58 | 59 | /** 60 | * \brief Set the socket non-blocking 61 | * 62 | * \return 0 if successful, or a non-zero error code 63 | */ 64 | int net_set_nonblock( int fd ); 65 | 66 | /** 67 | * \brief Portable usleep helper 68 | * 69 | * \note Real amount of time slept will not be less than 70 | * select()'s timeout granularity (typically, 10ms). 71 | */ 72 | void net_usleep( unsigned long usec ); 73 | 74 | /** 75 | * \brief Read at most 'len' characters. len is updated to 76 | * reflect the actual number of characters read. 77 | * 78 | * \return This function returns the number of bytes received, 79 | * or a negative error code; XYSSL_ERR_NET_TRY_AGAIN 80 | * indicates read() is blocking. 81 | */ 82 | int net_recv( void *ctx, unsigned char *buf, int len ); 83 | 84 | /** 85 | * \brief Write at most 'len' characters. len is updated to 86 | * reflect the number of characters _not_ written. 87 | * 88 | * \return This function returns the number of bytes sent, 89 | * or a negative error code; XYSSL_ERR_NET_TRY_AGAIN 90 | * indicates write() is blocking. 91 | */ 92 | int net_send( void *ctx, unsigned char *buf, int len ); 93 | 94 | /** 95 | * \brief Gracefully shutdown the connection 96 | */ 97 | void net_close( int fd ); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif /* net.h */ 104 | -------------------------------------------------------------------------------- /xyssl/openssl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file openssl.h 3 | */ 4 | /* 5 | * OpenSSL wrapper contributed by David Barett 6 | */ 7 | #ifndef XYSSL_OPENSSL_H 8 | #define XYSSL_OPENSSL_H 9 | 10 | #include "xyssl/aes.h" 11 | #include "xyssl/md5.h" 12 | #include "xyssl/rsa.h" 13 | #include "xyssl/sha1.h" 14 | 15 | #define AES_SIZE 16 16 | #define AES_BLOCK_SIZE 16 17 | #define AES_KEY aes_context 18 | #define MD5_CTX md5_context 19 | #define SHA_CTX sha1_context 20 | 21 | #define SHA1_Init( CTX ) \ 22 | sha1_starts( (CTX) ) 23 | #define SHA1_Update( CTX, BUF, LEN ) \ 24 | sha1_update( (CTX), (unsigned char *)(BUF), (LEN) ) 25 | #define SHA1_Final( OUT, CTX ) \ 26 | sha1_finish( (CTX), (OUT) ) 27 | 28 | #define MD5_Init( CTX ) \ 29 | md5_starts( (CTX) ) 30 | #define MD5_Update( CTX, BUF, LEN ) \ 31 | md5_update( (CTX), (unsigned char *)(BUF), (LEN) ) 32 | #define MD5_Final( OUT, CTX ) \ 33 | md5_finish( (CTX), (OUT) ) 34 | 35 | #define AES_set_encrypt_key( KEY, KEYSIZE, CTX ) \ 36 | aes_setkey_enc( (CTX), (KEY), (KEYSIZE) ) 37 | #define AES_set_decrypt_key( KEY, KEYSIZE, CTX ) \ 38 | aes_setkey_dec( (CTX), (KEY), (KEYSIZE) ) 39 | #define AES_cbc_encrypt( INPUT, OUTPUT, LEN, CTX, IV, MODE ) \ 40 | aes_crypt_cbc( (CTX), (MODE), (LEN), (IV), (INPUT), (OUTPUT) ) 41 | 42 | /* 43 | * RSA stuff follows. TODO: needs cleanup 44 | */ 45 | inline int __RSA_Passthrough( void *output, void *input, int size ) 46 | { 47 | memcpy( output, input, size ); 48 | return size; 49 | } 50 | 51 | inline rsa_context* d2i_RSA_PUBKEY( void *ignore, unsigned char **bufptr, 52 | int len ) 53 | { 54 | unsigned char *buffer = *(unsigned char **) bufptr; 55 | rsa_context *rsa; 56 | 57 | /* 58 | * Not a general-purpose parser: only parses public key from *exactly* 59 | * openssl genrsa -out privkey.pem 512 (or 1024) 60 | * openssl rsa -in privkey.pem -out privatekey.der -outform der 61 | * openssl rsa -in privkey.pem -out pubkey.der -outform der -pubout 62 | * 63 | * TODO: make a general-purpose parse 64 | */ 65 | if( ignore != 0 || ( len != 94 && len != 162 ) ) 66 | return( 0 ); 67 | 68 | rsa = (rsa_context *) malloc( sizeof( rsa_rsa ) ); 69 | if( rsa == NULL ) 70 | return( 0 ); 71 | 72 | memset( rsa, 0, sizeof( rsa_context ) ); 73 | 74 | if( ( len == 94 && 75 | mpi_read_binary( &rsa->N, &buffer[ 25], 64 ) == 0 && 76 | mpi_read_binary( &rsa->E, &buffer[ 91], 3 ) == 0 ) || 77 | ( len == 162 && 78 | mpi_read_binary( &rsa->N, &buffer[ 29], 128 ) == 0 ) && 79 | mpi_read_binary( &rsa->E, &buffer[159], 3 ) == 0 ) 80 | { 81 | /* 82 | * key read successfully 83 | */ 84 | rsa->len = ( mpi_msb( &rsa->N ) + 7 ) >> 3; 85 | return( rsa ); 86 | } 87 | else 88 | { 89 | memset( rsa, 0, sizeof( rsa_context ) ); 90 | free( rsa ); 91 | return( 0 ); 92 | } 93 | } 94 | 95 | #define RSA rsa_context 96 | #define RSA_PKCS1_PADDING 1 /* ignored; always encrypt with this */ 97 | #define RSA_size( CTX ) (CTX)->len 98 | #define RSA_free( CTX ) rsa_free( CTX ) 99 | #define ERR_get_error( ) "ERR_get_error() not supported" 100 | #define RSA_blinding_off( IGNORE ) 101 | 102 | #define d2i_RSAPrivateKey( a, b, c ) new rsa_context /* TODO: C++ bleh */ 103 | 104 | inline int RSA_public_decrypt ( int size, unsigned char* input, unsigned char* output, RSA* key, int ignore ) { int outsize=size; if( !rsa_pkcs1_decrypt( key, RSA_PUBLIC, &outsize, input, output ) ) return outsize; else return -1; } 105 | inline int RSA_private_decrypt( int size, unsigned char* input, unsigned char* output, RSA* key, int ignore ) { int outsize=size; if( !rsa_pkcs1_decrypt( key, RSA_PRIVATE, &outsize, input, output ) ) return outsize; else return -1; } 106 | inline int RSA_public_encrypt ( int size, unsigned char* input, unsigned char* output, RSA* key, int ignore ) { if( !rsa_pkcs1_encrypt( key, RSA_PUBLIC, size, input, output ) ) return RSA_size(key); else return -1; } 107 | inline int RSA_private_encrypt( int size, unsigned char* input, unsigned char* output, RSA* key, int ignore ) { if( !rsa_pkcs1_encrypt( key, RSA_PRIVATE, size, input, output ) ) return RSA_size(key); else return -1; } 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /* openssl.h */ 114 | -------------------------------------------------------------------------------- /xyssl/padlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * VIA PadLock support functions 3 | * 4 | * Copyright (C) 2006-2007 Christophe Devine 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | /* 21 | * This implementation is based on the VIA PadLock Programming Guide: 22 | * 23 | * http://www.via.com.tw/en/downloads/whitepapers/initiatives/padlock/ 24 | * programming_guide.pdf 25 | */ 26 | 27 | #include "config.h" 28 | 29 | #if defined(XYSSL_PADLOCK_C) 30 | 31 | #include "aes.h" 32 | #include "padlock.h" 33 | 34 | #if defined(XYSSL_HAVE_X86) 35 | 36 | #include 37 | 38 | /* 39 | * PadLock detection routine 40 | */ 41 | int padlock_supports( int feature ) 42 | { 43 | static int flags = -1; 44 | int ebx, edx; 45 | 46 | if( flags == -1 ) 47 | { 48 | asm( "movl %%ebx, %0 \n" \ 49 | "movl $0xC0000000, %%eax \n" \ 50 | "cpuid \n" \ 51 | "cmpl $0xC0000001, %%eax \n" \ 52 | "movl $0, %%edx \n" \ 53 | "jb unsupported \n" \ 54 | "movl $0xC0000001, %%eax \n" \ 55 | "cpuid \n" \ 56 | "unsupported: \n" \ 57 | "movl %%edx, %1 \n" \ 58 | "movl %2, %%ebx \n" 59 | : "=m" (ebx), "=m" (edx) 60 | : "m" (ebx) 61 | : "eax", "ecx", "edx" ); 62 | 63 | flags = edx; 64 | } 65 | 66 | return( flags & feature ); 67 | } 68 | 69 | /* 70 | * PadLock AES-ECB block en(de)cryption 71 | */ 72 | int padlock_xcryptecb( aes_context *ctx, 73 | int mode, 74 | unsigned char input[16], 75 | unsigned char output[16] ) 76 | { 77 | int ebx; 78 | unsigned long *rk; 79 | unsigned long *blk; 80 | unsigned long *ctrl; 81 | unsigned char buf[256]; 82 | 83 | rk = ctx->rk; 84 | blk = PADLOCK_ALIGN16( buf ); 85 | memcpy( blk, input, 16 ); 86 | 87 | ctrl = blk + 4; 88 | *ctrl = 0x80 | ctx->nr | ( ( ctx->nr + ( mode^1 ) - 10 ) << 9 ); 89 | 90 | asm( "pushfl; popfl \n" \ 91 | "movl %%ebx, %0 \n" \ 92 | "movl $1, %%ecx \n" \ 93 | "movl %2, %%edx \n" \ 94 | "movl %3, %%ebx \n" \ 95 | "movl %4, %%esi \n" \ 96 | "movl %4, %%edi \n" \ 97 | ".byte 0xf3,0x0f,0xa7,0xc8\n" \ 98 | "movl %1, %%ebx \n" 99 | : "=m" (ebx) 100 | : "m" (ebx), "m" (ctrl), "m" (rk), "m" (blk) 101 | : "ecx", "edx", "esi", "edi" ); 102 | 103 | memcpy( output, blk, 16 ); 104 | 105 | return( 0 ); 106 | } 107 | 108 | /* 109 | * PadLock AES-CBC buffer en(de)cryption 110 | */ 111 | int padlock_xcryptcbc( aes_context *ctx, 112 | int mode, 113 | int length, 114 | unsigned char iv[16], 115 | unsigned char *input, 116 | unsigned char *output ) 117 | { 118 | int ebx, count; 119 | unsigned long *rk; 120 | unsigned long *iw; 121 | unsigned long *ctrl; 122 | unsigned char buf[256]; 123 | 124 | if( ( (long) input & 15 ) != 0 || 125 | ( (long) output & 15 ) != 0 ) 126 | return( 1 ); 127 | 128 | rk = ctx->rk; 129 | iw = PADLOCK_ALIGN16( buf ); 130 | memcpy( iw, iv, 16 ); 131 | 132 | ctrl = iw + 4; 133 | *ctrl = 0x80 | ctx->nr | ( ( ctx->nr + (mode^1) - 10 ) << 9 ); 134 | 135 | count = (length + 15) >> 4; 136 | 137 | asm( "pushfl; popfl \n" \ 138 | "movl %%ebx, %0 \n" \ 139 | "movl %2, %%ecx \n" \ 140 | "movl %3, %%edx \n" \ 141 | "movl %4, %%ebx \n" \ 142 | "movl %5, %%esi \n" \ 143 | "movl %6, %%edi \n" \ 144 | "movl %7, %%eax \n" \ 145 | ".byte 0xf3,0x0f,0xa7,0xd0\n" \ 146 | "movl %1, %%ebx \n" 147 | : "=m" (ebx) 148 | : "m" (ebx), "m" (count), "m" (ctrl), 149 | "m" (rk), "m" (input), "m" (output), "m" (iw) 150 | : "eax", "ecx", "edx", "esi", "edi" ); 151 | 152 | memcpy( iv, iw, 16 ); 153 | 154 | return( 0 ); 155 | } 156 | 157 | #endif 158 | 159 | #endif 160 | -------------------------------------------------------------------------------- /xyssl/padlock.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file padlock.h 3 | */ 4 | #ifndef XYSSL_PADLOCK_H 5 | #define XYSSL_PADLOCK_H 6 | 7 | #include "aes.h" 8 | 9 | #if (defined(__GNUC__) && defined(__i386__)) 10 | 11 | #ifndef XYSSL_HAVE_X86 12 | #define XYSSL_HAVE_X86 13 | #endif 14 | 15 | #define PADLOCK_RNG 0x000C 16 | #define PADLOCK_ACE 0x00C0 17 | #define PADLOCK_PHE 0x0C00 18 | #define PADLOCK_PMM 0x3000 19 | 20 | #define PADLOCK_ALIGN16(x) (unsigned long *) (16 + ((long) x & ~15)) 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /** 27 | * \brief PadLock detection routine 28 | * 29 | * \return 1 if CPU has support for the feature, 0 otherwise 30 | */ 31 | int padlock_supports( int feature ); 32 | 33 | /** 34 | * \brief PadLock AES-ECB block en(de)cryption 35 | * 36 | * \param ctx AES context 37 | * \param mode AES_ENCRYPT or AES_DECRYPT 38 | * \param input 16-byte input block 39 | * \param output 16-byte output block 40 | * 41 | * \return 0 if success, 1 if operation failed 42 | */ 43 | int padlock_xcryptecb( aes_context *ctx, 44 | int mode, 45 | unsigned char input[16], 46 | unsigned char output[16] ); 47 | 48 | /** 49 | * \brief PadLock AES-CBC buffer en(de)cryption 50 | * 51 | * \param ctx AES context 52 | * \param mode AES_ENCRYPT or AES_DECRYPT 53 | * \param length length of the input data 54 | * \param iv initialization vector (updated after use) 55 | * \param input buffer holding the input data 56 | * \param output buffer holding the output data 57 | * 58 | * \return 0 if success, 1 if operation failed 59 | */ 60 | int padlock_xcryptcbc( aes_context *ctx, 61 | int mode, 62 | int length, 63 | unsigned char iv[16], 64 | unsigned char *input, 65 | unsigned char *output ); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* HAVE_X86 */ 72 | 73 | #endif /* padlock.h */ 74 | -------------------------------------------------------------------------------- /xyssl/sha1.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file sha1.h 3 | */ 4 | #ifndef XYSSL_SHA1_H 5 | #define XYSSL_SHA1_H 6 | 7 | /** 8 | * \brief SHA-1 context structure 9 | */ 10 | typedef struct 11 | { 12 | unsigned long total[2]; /*!< number of bytes processed */ 13 | unsigned long state[5]; /*!< intermediate digest state */ 14 | unsigned char buffer[64]; /*!< data block being processed */ 15 | 16 | unsigned char ipad[64]; /*!< HMAC: inner padding */ 17 | unsigned char opad[64]; /*!< HMAC: outer padding */ 18 | } 19 | sha1_context; 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /** 26 | * \brief SHA-1 context setup 27 | * 28 | * \param ctx context to be initialized 29 | */ 30 | void sha1_starts( sha1_context *ctx ); 31 | 32 | /** 33 | * \brief SHA-1 process buffer 34 | * 35 | * \param ctx SHA-1 context 36 | * \param input buffer holding the data 37 | * \param ilen length of the input data 38 | */ 39 | void sha1_update( sha1_context *ctx, unsigned char *input, int ilen ); 40 | 41 | /** 42 | * \brief SHA-1 final digest 43 | * 44 | * \param ctx SHA-1 context 45 | * \param output SHA-1 checksum result 46 | */ 47 | void sha1_finish( sha1_context *ctx, unsigned char output[20] ); 48 | 49 | /** 50 | * \brief Output = SHA-1( input buffer ) 51 | * 52 | * \param input buffer holding the data 53 | * \param ilen length of the input data 54 | * \param output SHA-1 checksum result 55 | */ 56 | void sha1( unsigned char *input, int ilen, unsigned char output[20] ); 57 | 58 | /** 59 | * \brief Output = SHA-1( file contents ) 60 | * 61 | * \param path input file name 62 | * \param output SHA-1 checksum result 63 | * 64 | * \return 0 if successful, 1 if fopen failed, 65 | * or 2 if fread failed 66 | */ 67 | int sha1_file( char *path, unsigned char output[20] ); 68 | 69 | /** 70 | * \brief SHA-1 HMAC context setup 71 | * 72 | * \param ctx HMAC context to be initialized 73 | * \param key HMAC secret key 74 | * \param keylen length of the HMAC key 75 | */ 76 | void sha1_hmac_starts( sha1_context *ctx, unsigned char *key, int keylen ); 77 | 78 | /** 79 | * \brief SHA-1 HMAC process buffer 80 | * 81 | * \param ctx HMAC context 82 | * \param input buffer holding the data 83 | * \param ilen length of the input data 84 | */ 85 | void sha1_hmac_update( sha1_context *ctx, unsigned char *input, int ilen ); 86 | 87 | /** 88 | * \brief SHA-1 HMAC final digest 89 | * 90 | * \param ctx HMAC context 91 | * \param output SHA-1 HMAC checksum result 92 | */ 93 | void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] ); 94 | 95 | /** 96 | * \brief Output = HMAC-SHA-1( hmac key, input buffer ) 97 | * 98 | * \param key HMAC secret key 99 | * \param keylen length of the HMAC key 100 | * \param input buffer holding the data 101 | * \param ilen length of the input data 102 | * \param output HMAC-SHA-1 result 103 | */ 104 | void sha1_hmac( unsigned char *key, int keylen, 105 | unsigned char *input, int ilen, 106 | unsigned char output[20] ); 107 | 108 | /** 109 | * \brief Checkup routine 110 | * 111 | * \return 0 if successful, or 1 if the test failed 112 | */ 113 | int sha1_self_test( int verbose ); 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif /* sha1.h */ 120 | -------------------------------------------------------------------------------- /xyssl/sha2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file sha2.h 3 | */ 4 | #ifndef XYSSL_SHA2_H 5 | #define XYSSL_SHA2_H 6 | 7 | /** 8 | * \brief SHA-256 context structure 9 | */ 10 | typedef struct 11 | { 12 | unsigned long total[2]; /*!< number of bytes processed */ 13 | unsigned long state[8]; /*!< intermediate digest state */ 14 | unsigned char buffer[64]; /*!< data block being processed */ 15 | 16 | unsigned char ipad[64]; /*!< HMAC: inner padding */ 17 | unsigned char opad[64]; /*!< HMAC: outer padding */ 18 | int is224; /*!< 0 => SHA-256, else SHA-224 */ 19 | } 20 | sha2_context; 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /** 27 | * \brief SHA-256 context setup 28 | * 29 | * \param ctx context to be initialized 30 | * \param is224 0 = use SHA256, 1 = use SHA224 31 | */ 32 | void sha2_starts( sha2_context *ctx, int is224 ); 33 | 34 | /** 35 | * \brief SHA-256 process buffer 36 | * 37 | * \param ctx SHA-256 context 38 | * \param input buffer holding the data 39 | * \param ilen length of the input data 40 | */ 41 | void sha2_update( sha2_context *ctx, unsigned char *input, int ilen ); 42 | 43 | /** 44 | * \brief SHA-256 final digest 45 | * 46 | * \param ctx SHA-256 context 47 | * \param output SHA-224/256 checksum result 48 | */ 49 | void sha2_finish( sha2_context *ctx, unsigned char output[32] ); 50 | 51 | /** 52 | * \brief Output = SHA-256( input buffer ) 53 | * 54 | * \param input buffer holding the data 55 | * \param ilen length of the input data 56 | * \param output SHA-224/256 checksum result 57 | * \param is224 0 = use SHA256, 1 = use SHA224 58 | */ 59 | void sha2( unsigned char *input, int ilen, 60 | unsigned char output[32], int is224 ); 61 | 62 | /** 63 | * \brief Output = SHA-256( file contents ) 64 | * 65 | * \param path input file name 66 | * \param output SHA-224/256 checksum result 67 | * \param is224 0 = use SHA256, 1 = use SHA224 68 | * 69 | * \return 0 if successful, 1 if fopen failed, 70 | * or 2 if fread failed 71 | */ 72 | int sha2_file( char *path, unsigned char output[32], int is224 ); 73 | 74 | /** 75 | * \brief SHA-256 HMAC context setup 76 | * 77 | * \param ctx HMAC context to be initialized 78 | * \param key HMAC secret key 79 | * \param keylen length of the HMAC key 80 | * \param is224 0 = use SHA256, 1 = use SHA224 81 | */ 82 | void sha2_hmac_starts( sha2_context *ctx, unsigned char *key, int keylen, 83 | int is224 ); 84 | 85 | /** 86 | * \brief SHA-256 HMAC process buffer 87 | * 88 | * \param ctx HMAC context 89 | * \param input buffer holding the data 90 | * \param ilen length of the input data 91 | */ 92 | void sha2_hmac_update( sha2_context *ctx, unsigned char *input, int ilen ); 93 | 94 | /** 95 | * \brief SHA-256 HMAC final digest 96 | * 97 | * \param ctx HMAC context 98 | * \param output SHA-224/256 HMAC checksum result 99 | */ 100 | void sha2_hmac_finish( sha2_context *ctx, unsigned char output[32] ); 101 | 102 | /** 103 | * \brief Output = HMAC-SHA-256( hmac key, input buffer ) 104 | * 105 | * \param key HMAC secret key 106 | * \param keylen length of the HMAC key 107 | * \param input buffer holding the data 108 | * \param ilen length of the input data 109 | * \param output HMAC-SHA-224/256 result 110 | * \param is224 0 = use SHA256, 1 = use SHA224 111 | */ 112 | void sha2_hmac( unsigned char *key, int keylen, 113 | unsigned char *input, int ilen, 114 | unsigned char output[32], int is224 ); 115 | 116 | /** 117 | * \brief Checkup routine 118 | * 119 | * \return 0 if successful, or 1 if the test failed 120 | */ 121 | int sha2_self_test( int verbose ); 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* sha2.h */ 128 | -------------------------------------------------------------------------------- /xyssl/sha4.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file sha4.h 3 | */ 4 | #ifndef XYSSL_SHA4_H 5 | #define XYSSL_SHA4_H 6 | 7 | #if defined(_MSC_VER) || defined(__WATCOMC__) 8 | #define UL64(x) x##ui64 9 | #define int64 __int64 10 | #else 11 | #define UL64(x) x##ULL 12 | #define int64 long long 13 | #endif 14 | 15 | /** 16 | * \brief SHA-512 context structure 17 | */ 18 | typedef struct 19 | { 20 | unsigned int64 total[2]; /*!< number of bytes processed */ 21 | unsigned int64 state[8]; /*!< intermediate digest state */ 22 | unsigned char buffer[128]; /*!< data block being processed */ 23 | 24 | unsigned char ipad[128]; /*!< HMAC: inner padding */ 25 | unsigned char opad[128]; /*!< HMAC: outer padding */ 26 | int is384; /*!< 0 => SHA-512, else SHA-384 */ 27 | } 28 | sha4_context; 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * \brief SHA-512 context setup 36 | * 37 | * \param ctx context to be initialized 38 | * \param is384 0 = use SHA512, 1 = use SHA384 39 | */ 40 | void sha4_starts( sha4_context *ctx, int is384 ); 41 | 42 | /** 43 | * \brief SHA-512 process buffer 44 | * 45 | * \param ctx SHA-512 context 46 | * \param input buffer holding the data 47 | * \param ilen length of the input data 48 | */ 49 | void sha4_update( sha4_context *ctx, unsigned char *input, int ilen ); 50 | 51 | /** 52 | * \brief SHA-512 final digest 53 | * 54 | * \param ctx SHA-512 context 55 | * \param output SHA-384/512 checksum result 56 | */ 57 | void sha4_finish( sha4_context *ctx, unsigned char output[64] ); 58 | 59 | /** 60 | * \brief Output = SHA-512( input buffer ) 61 | * 62 | * \param input buffer holding the data 63 | * \param ilen length of the input data 64 | * \param output SHA-384/512 checksum result 65 | * \param is384 0 = use SHA512, 1 = use SHA384 66 | */ 67 | void sha4( unsigned char *input, int ilen, 68 | unsigned char output[64], int is384 ); 69 | 70 | /** 71 | * \brief Output = SHA-512( file contents ) 72 | * 73 | * \param path input file name 74 | * \param output SHA-384/512 checksum result 75 | * \param is384 0 = use SHA512, 1 = use SHA384 76 | * 77 | * \return 0 if successful, 1 if fopen failed, 78 | * or 2 if fread failed 79 | */ 80 | int sha4_file( char *path, unsigned char output[64], int is384 ); 81 | 82 | /** 83 | * \brief SHA-512 HMAC context setup 84 | * 85 | * \param ctx HMAC context to be initialized 86 | * \param is384 0 = use SHA512, 1 = use SHA384 87 | * \param key HMAC secret key 88 | * \param keylen length of the HMAC key 89 | */ 90 | void sha4_hmac_starts( sha4_context *ctx, unsigned char *key, int keylen, 91 | int is384 ); 92 | 93 | /** 94 | * \brief SHA-512 HMAC process buffer 95 | * 96 | * \param ctx HMAC context 97 | * \param input buffer holding the data 98 | * \param ilen length of the input data 99 | */ 100 | void sha4_hmac_update( sha4_context *ctx, unsigned char *input, int ilen ); 101 | 102 | /** 103 | * \brief SHA-512 HMAC final digest 104 | * 105 | * \param ctx HMAC context 106 | * \param output SHA-384/512 HMAC checksum result 107 | */ 108 | void sha4_hmac_finish( sha4_context *ctx, unsigned char output[64] ); 109 | 110 | /** 111 | * \brief Output = HMAC-SHA-512( hmac key, input buffer ) 112 | * 113 | * \param key HMAC secret key 114 | * \param keylen length of the HMAC key 115 | * \param input buffer holding the data 116 | * \param ilen length of the input data 117 | * \param output HMAC-SHA-384/512 result 118 | * \param is384 0 = use SHA512, 1 = use SHA384 119 | */ 120 | void sha4_hmac( unsigned char *key, int keylen, 121 | unsigned char *input, int ilen, 122 | unsigned char output[64], int is384 ); 123 | 124 | /** 125 | * \brief Checkup routine 126 | * 127 | * \return 0 if successful, or 1 if the test failed 128 | */ 129 | int sha4_self_test( int verbose ); 130 | 131 | #ifdef __cplusplus 132 | } 133 | #endif 134 | 135 | #endif /* sha4.h */ 136 | -------------------------------------------------------------------------------- /xyssl/timing.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Portable interface to the CPU cycle counter 3 | * 4 | * Copyright (C) 2006-2007 Christophe Devine 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | */ 20 | 21 | #include "config.h" 22 | 23 | #if defined(XYSSL_TIMING_C) 24 | 25 | #include "timing.h" 26 | 27 | #if defined(WIN32) 28 | 29 | #include 30 | #include 31 | 32 | struct _hr_time 33 | { 34 | LARGE_INTEGER start; 35 | }; 36 | 37 | #else 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | struct _hr_time 46 | { 47 | struct timeval start; 48 | }; 49 | 50 | #endif 51 | 52 | #if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) 53 | 54 | unsigned long hardclock( void ) 55 | { 56 | unsigned long tsc; 57 | __asm rdtsc 58 | __asm mov [tsc], eax 59 | return( tsc ); 60 | } 61 | 62 | #else 63 | #if defined(__GNUC__) && defined(__i386__) 64 | 65 | unsigned long hardclock( void ) 66 | { 67 | unsigned long tsc; 68 | asm( "rdtsc" : "=a" (tsc) ); 69 | return( tsc ); 70 | } 71 | 72 | #else 73 | #if defined(__GNUC__) && (defined(__amd64__) || defined(__x86_64__)) 74 | 75 | unsigned long hardclock( void ) 76 | { 77 | unsigned long lo, hi; 78 | asm( "rdtsc" : "=a" (lo), "=d" (hi) ); 79 | return( lo | (hi << 32) ); 80 | } 81 | 82 | #else 83 | #if defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) 84 | 85 | unsigned long hardclock( void ) 86 | { 87 | unsigned long tbl, tbu0, tbu1; 88 | 89 | do 90 | { 91 | asm( "mftbu %0" : "=r" (tbu0) ); 92 | asm( "mftb %0" : "=r" (tbl ) ); 93 | asm( "mftbu %0" : "=r" (tbu1) ); 94 | } 95 | while( tbu0 != tbu1 ); 96 | 97 | return( tbl ); 98 | } 99 | 100 | #else 101 | #if defined(__GNUC__) && defined(__sparc__) 102 | 103 | unsigned long hardclock( void ) 104 | { 105 | unsigned long tick; 106 | asm( ".byte 0x83, 0x41, 0x00, 0x00" ); 107 | asm( "mov %%g1, %0" : "=r" (tick) ); 108 | return( tick ); 109 | } 110 | 111 | #else 112 | #if defined(__GNUC__) && defined(__alpha__) 113 | 114 | unsigned long hardclock( void ) 115 | { 116 | unsigned long cc; 117 | asm( "rpcc %0" : "=r" (cc) ); 118 | return( cc & 0xFFFFFFFF ); 119 | } 120 | 121 | #else 122 | #if defined(__GNUC__) && defined(__ia64__) 123 | 124 | unsigned long hardclock( void ) 125 | { 126 | unsigned long itc; 127 | asm( "mov %0 = ar.itc" : "=r" (itc) ); 128 | return( itc ); 129 | } 130 | 131 | #else 132 | 133 | static int hardclock_init = 0; 134 | static struct timeval tv_init; 135 | 136 | unsigned long hardclock( void ) 137 | { 138 | struct timeval tv_cur; 139 | 140 | if( hardclock_init == 0 ) 141 | { 142 | gettimeofday( &tv_init, NULL ); 143 | hardclock_init = 1; 144 | } 145 | 146 | gettimeofday( &tv_cur, NULL ); 147 | return( ( tv_cur.tv_sec - tv_init.tv_sec ) * 1000000 148 | + ( tv_cur.tv_usec - tv_init.tv_usec ) ); 149 | } 150 | 151 | #endif /* generic */ 152 | #endif /* IA-64 */ 153 | #endif /* Alpha */ 154 | #endif /* SPARC8 */ 155 | #endif /* PowerPC */ 156 | #endif /* AMD64 */ 157 | #endif /* i586+ */ 158 | 159 | int alarmed = 0; 160 | 161 | #if defined(WIN32) 162 | 163 | unsigned long get_timer( struct hr_time *val, int reset ) 164 | { 165 | unsigned long delta; 166 | LARGE_INTEGER offset, hfreq; 167 | struct _hr_time *t = (struct _hr_time *) val; 168 | 169 | QueryPerformanceCounter( &offset ); 170 | QueryPerformanceFrequency( &hfreq ); 171 | 172 | delta = (unsigned long)( ( 1000 * 173 | ( offset.QuadPart - t->start.QuadPart ) ) / 174 | hfreq.QuadPart ); 175 | 176 | if( reset ) 177 | QueryPerformanceCounter( &t->start ); 178 | 179 | return( delta ); 180 | } 181 | 182 | DWORD WINAPI TimerProc( LPVOID uElapse ) 183 | { 184 | Sleep( (DWORD) uElapse ); 185 | alarmed = 1; 186 | return( TRUE ); 187 | } 188 | 189 | void set_alarm( int seconds ) 190 | { 191 | DWORD ThreadId; 192 | 193 | alarmed = 0; 194 | CloseHandle( CreateThread( NULL, 0, TimerProc, 195 | (LPVOID) ( seconds * 1000 ), 0, &ThreadId ) ); 196 | } 197 | 198 | void m_sleep( int milliseconds ) 199 | { 200 | Sleep( milliseconds ); 201 | } 202 | 203 | #else 204 | 205 | unsigned long get_timer( struct hr_time *val, int reset ) 206 | { 207 | unsigned long delta; 208 | struct timeval offset; 209 | struct _hr_time *t = (struct _hr_time *) val; 210 | 211 | gettimeofday( &offset, NULL ); 212 | 213 | delta = ( offset.tv_sec - t->start.tv_sec ) * 1000 214 | + ( offset.tv_usec - t->start.tv_usec ) / 1000; 215 | 216 | if( reset ) 217 | { 218 | t->start.tv_sec = offset.tv_sec; 219 | t->start.tv_usec = offset.tv_usec; 220 | } 221 | 222 | return( delta ); 223 | } 224 | 225 | static void sighandler( int signum ) 226 | { 227 | alarmed = 1; 228 | signal( signum, sighandler ); 229 | } 230 | 231 | void set_alarm( int seconds ) 232 | { 233 | alarmed = 0; 234 | signal( SIGALRM, sighandler ); 235 | alarm( seconds ); 236 | } 237 | 238 | void m_sleep( int milliseconds ) 239 | { 240 | struct timeval tv; 241 | 242 | tv.tv_sec = milliseconds / 1000; 243 | tv.tv_usec = milliseconds * 1000; 244 | 245 | select( 0, NULL, NULL, NULL, &tv ); 246 | } 247 | 248 | #endif 249 | 250 | #endif 251 | -------------------------------------------------------------------------------- /xyssl/timing.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file timing.h 3 | */ 4 | #ifndef XYSSL_TIMING_H 5 | #define XYSSL_TIMING_H 6 | 7 | /** 8 | * \brief timer structure 9 | */ 10 | struct hr_time 11 | { 12 | unsigned char opaque[32]; 13 | }; 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | extern int alarmed; 20 | 21 | /** 22 | * \brief Return the CPU cycle counter value 23 | */ 24 | unsigned long hardclock( void ); 25 | 26 | /** 27 | * \brief Return the elapsed time in milliseconds 28 | * 29 | * \param val points to a timer structure 30 | * \param reset if set to 1, the timer is restarted 31 | */ 32 | unsigned long get_timer( struct hr_time *val, int reset ); 33 | 34 | /** 35 | * \brief Setup an alarm clock 36 | * 37 | * \param seconds delay before the "alarmed" flag is set 38 | */ 39 | void set_alarm( int seconds ); 40 | 41 | /** 42 | * \brief Sleep for a certain amount of time 43 | */ 44 | void m_sleep( int milliseconds ); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* timing.h */ 51 | -------------------------------------------------------------------------------- /xyssl/xyssl.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-12-23T18:46:45 4 | # 5 | #------------------------------------------------- 6 | 7 | QT -= core gui 8 | 9 | TARGET = xyssl 10 | TEMPLATE = lib 11 | CONFIG += staticlib 12 | 13 | SOURCES += \ 14 | aes.c \ 15 | arc4.c \ 16 | base64.c \ 17 | bignum.c \ 18 | certs.c \ 19 | debug.c \ 20 | des.c \ 21 | dhm.c \ 22 | havege.c \ 23 | md2.c \ 24 | md4.c \ 25 | md5.c \ 26 | net.c \ 27 | padlock.c \ 28 | rsa.c \ 29 | sha1.c \ 30 | sha2.c \ 31 | sha4.c \ 32 | ssl_cli.c \ 33 | ssl_srv.c \ 34 | ssl_tls.c \ 35 | timing.c \ 36 | x509parse.c 37 | 38 | HEADERS += \ 39 | aes.h \ 40 | arc4.h \ 41 | base64.h \ 42 | bignum.h \ 43 | bn_mul.h \ 44 | certs.h \ 45 | config.h \ 46 | debug.h \ 47 | des.h \ 48 | dhm.h \ 49 | havege.h \ 50 | md2.h \ 51 | md4.h \ 52 | md5.h \ 53 | net.h \ 54 | openssl.h \ 55 | padlock.h \ 56 | rsa.h \ 57 | sha1.h \ 58 | sha2.h \ 59 | sha4.h \ 60 | ssl.h \ 61 | timing.h \ 62 | x509.h 63 | unix { 64 | target.path = /usr/lib 65 | INSTALLS += target 66 | } 67 | 68 | DISTFILES += \ 69 | xyssl.pro.user \ 70 | Makefile 71 | --------------------------------------------------------------------------------