├── .gitignore ├── C_SDK ├── crypt │ ├── aes.h │ ├── aescrypt.c │ ├── aeskey.c │ ├── aesopt.h │ ├── aestab.c │ ├── aestab.h │ ├── base64.c │ ├── base64.h │ ├── pseudorandom.c │ ├── pseudorandom.h │ ├── sha1.c │ └── sha1.h ├── csql.h ├── cubesql.c ├── cubesql.h ├── documentation │ ├── index.html │ └── style.css └── zlib │ ├── README │ ├── zconf.h │ ├── zlib.c │ └── zlib.h ├── Internals └── TestTLS │ ├── OpenSSL.xcodeproj │ └── project.pbxproj │ └── OpenSSL │ └── main.c ├── LICENSE ├── ObjC ├── CubeSQLObjC.h └── CubeSQLObjc.m ├── PHP ├── JSON │ └── cubeSQLServer.php ├── Native │ └── cubeSQLServer.php ├── PDO └── Test │ └── CubeSQLTest.php ├── README.md ├── Sample ├── Console │ ├── VisualC │ │ ├── TestApp.sln │ │ └── TestApp │ │ │ ├── TestApp.vcxproj │ │ │ ├── TestApp.vcxproj.filters │ │ │ └── TestApp.vcxproj.user │ ├── XCode │ │ └── testapp.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── testapp.xcscheme │ ├── gcc │ │ └── Makefile │ └── testapp.c ├── MacOS │ ├── Client │ │ ├── cubeSQLTest.xcodeproj │ │ │ └── project.pbxproj │ │ └── cubeSQLTest │ │ │ ├── AppDelegate.h │ │ │ ├── AppDelegate.m │ │ │ ├── Assets.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ │ ├── Base.lproj │ │ │ └── MainMenu.xib │ │ │ └── main.m │ └── Files API │ │ ├── cubeSQLFilesAPI.xcodeproj │ │ └── project.pbxproj │ │ └── cubeSQLTest │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ │ ├── Base.lproj │ │ └── MainMenu.xib │ │ └── main.m └── invoice.sqlite ├── SharedLibrary ├── Makefile └── libcubesql.dylib ├── Xojo └── Sample │ └── FilesAPI.rbp └── libs ├── linux-64 ├── libtls.a └── libtls_asm.a ├── linux-arm └── libtls.a ├── linux └── libtls.a ├── macOS └── libtls.a ├── win-32bit └── tls.lib └── win-64bit └── tls.lib /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.xcbkptlist 3 | *.xcuserstate 4 | *.plist 5 | *.xcworkspacedata 6 | Sample/Console/XCode/testapp.xcodeproj/xcshareddata/xcschemes/testapp.xcscheme 7 | Internals/old/ 8 | .DS_Store 9 | Sample/MacOS/Client/cubeSQLTest.xcodeproj/project.pbxproj 10 | Sample/Console/XCode/testapp.xcodeproj/xcshareddata/xcschemes/testapp.xcscheme 11 | Internals/TestTLS/OpenSSL.xcodeproj/xcshareddata/xcschemes/OpenSSL.xcscheme 12 | -------------------------------------------------------------------------------- /C_SDK/crypt/aes.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue 28/01/2004 31 | 32 | This file contains the definitions required to use AES in C. See aesopt.h 33 | for optimisation details. 34 | */ 35 | 36 | #if !defined( _AES_H ) 37 | #define _AES_H 38 | 39 | /* This include is used to find 8 & 32 bit unsigned integer types */ 40 | #include "limits.h" 41 | 42 | #if defined(__cplusplus) 43 | extern "C" 44 | { 45 | #endif 46 | 47 | typedef unsigned char aes_08t; 48 | 49 | #define AES_128 /* define if AES with 128 bit keys is needed */ 50 | #define AES_192 /* define if AES with 192 bit keys is needed */ 51 | #define AES_256 /* define if AES with 256 bit keys is needed */ 52 | #define AES_VAR /* define if a variable key size is needed */ 53 | 54 | /* The following must also be set in assembler files if being used */ 55 | 56 | #define AES_ENCRYPT /* if support for encryption is needed */ 57 | #define AES_DECRYPT /* if support for decryption is needed */ 58 | #define AES_ERR_CHK /* for parameter checks & error return codes */ 59 | 60 | /* 61 | #if UCHAR_MAX == 0xff // an unsigned 8 bit type 62 | typedef unsigned char aes_08t; 63 | #else 64 | # error Please define aes_08t as an 8-bit unsigned integer type in aes.h 65 | #endif 66 | */ 67 | 68 | #if UINT_MAX == 4294967295 /* an unsigned 32 bit type */ 69 | typedef unsigned int aes_32t; 70 | #elif ULONG_MAX == 4294967295ul 71 | typedef unsigned long aes_32t; 72 | #else 73 | # error Please define aes_32t as a 32-bit unsigned integer type in aes.h 74 | #endif 75 | 76 | #define AES_BLOCK_SIZE 16 /* the AES block size in bytes */ 77 | #define N_COLS 4 /* the number of columns in the state */ 78 | 79 | /* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */ 80 | /* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */ 81 | /* or 44, 52 or 60 32-bit words. For simplicity this code allocates */ 82 | /* the maximum 60 word array for the key schedule for all key sizes */ 83 | 84 | #if defined( AES_VAR ) || defined( AES_256 ) 85 | #define KS_LENGTH 60 86 | #elif defined( AES_192 ) 87 | #define KS_LENGTH 52 88 | #else 89 | #define KS_LENGTH 44 90 | #endif 91 | 92 | #if defined( AES_ERR_CHK ) 93 | #define aes_ret int 94 | #define aes_good 0 95 | #define aes_error -1 96 | #else 97 | #define aes_ret void 98 | #endif 99 | 100 | #if !defined( AES_DLL ) /* implement normal/DLL functions */ 101 | #define aes_rval aes_ret 102 | #else 103 | #define aes_rval aes_ret __declspec(dllexport) _stdcall 104 | #endif 105 | 106 | typedef struct 107 | { aes_32t ks[KS_LENGTH]; 108 | aes_32t rn; 109 | } csql_aes_encrypt_ctx; 110 | 111 | typedef struct 112 | { aes_32t ks[KS_LENGTH]; 113 | aes_32t rn; 114 | } csql_aes_decrypt_ctx; 115 | 116 | /* This routine must be called before first use if non-static */ 117 | /* tables are being used */ 118 | 119 | void csql_gen_tabs(void); 120 | 121 | /* The key length (klen) is input in bytes when it is in the range */ 122 | /* 16 <= klen <= 32 or in bits when in the range 128 <= klen <= 256 */ 123 | 124 | #if defined( AES_ENCRYPT ) 125 | 126 | #if defined(AES_128) || defined(AES_VAR) 127 | aes_rval csql_aes_encrypt_key128(const unsigned char *in_key, csql_aes_encrypt_ctx cx[1]); 128 | #endif 129 | 130 | #if defined(AES_192) || defined(AES_VAR) 131 | aes_rval csql_aes_encrypt_key192(const unsigned char *in_key, csql_aes_encrypt_ctx cx[1]); 132 | #endif 133 | 134 | #if defined(AES_256) || defined(AES_VAR) 135 | aes_rval csql_aes_encrypt_key256(const unsigned char *in_key, csql_aes_encrypt_ctx cx[1]); 136 | #endif 137 | 138 | #if defined(AES_VAR) 139 | aes_rval csql_aes_encrypt_key(const unsigned char *in_key, int key_len, csql_aes_encrypt_ctx cx[1]); 140 | #endif 141 | 142 | aes_rval csql_aes_encrypt(const unsigned char *in_blk, unsigned char *out_blk, const csql_aes_encrypt_ctx cx[1]); 143 | #endif 144 | 145 | #if defined( AES_DECRYPT ) 146 | 147 | #if defined(AES_128) || defined(AES_VAR) 148 | aes_rval csql_aes_decrypt_key128(const unsigned char *in_key, csql_aes_decrypt_ctx cx[1]); 149 | #endif 150 | 151 | #if defined(AES_192) || defined(AES_VAR) 152 | aes_rval csql_aes_decrypt_key192(const unsigned char *in_key, csql_aes_decrypt_ctx cx[1]); 153 | #endif 154 | 155 | #if defined(AES_256) || defined(AES_VAR) 156 | aes_rval csql_aes_decrypt_key256(const unsigned char *in_key, csql_aes_decrypt_ctx cx[1]); 157 | #endif 158 | 159 | #if defined(AES_VAR) 160 | aes_rval csql_aes_decrypt_key(const unsigned char *in_key, int key_len, csql_aes_decrypt_ctx cx[1]); 161 | #endif 162 | 163 | aes_rval csql_aes_decrypt(const unsigned char *in_blk, unsigned char *out_blk, const csql_aes_decrypt_ctx cx[1]); 164 | #endif 165 | 166 | #if defined(__cplusplus) 167 | } 168 | #endif 169 | 170 | #endif 171 | -------------------------------------------------------------------------------- /C_SDK/crypt/aescrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue 28/01/2004 31 | 32 | This file contains the code for implementing encryption and decryption 33 | for AES (Rijndael) for block and key sizes of 16, 24 and 32 bytes. It 34 | can optionally be replaced by code written in assembler using NASM. For 35 | further details see the file aesopt.h 36 | */ 37 | 38 | #include "aesopt.h" 39 | #include "aestab.h" 40 | 41 | #if defined(__cplusplus) 42 | extern "C" 43 | { 44 | #endif 45 | 46 | #define si(y,x,k,c) (s(y,c) = word_in(x, c) ^ (k)[c]) 47 | #define so(y,x,c) word_out(y, c, s(x,c)) 48 | 49 | #if defined(ARRAYS) 50 | #define locals(y,x) x[4],y[4] 51 | #else 52 | #define locals(y,x) x##0,x##1,x##2,x##3,y##0,y##1,y##2,y##3 53 | #endif 54 | 55 | #define l_copy(y, x) s(y,0) = s(x,0); s(y,1) = s(x,1); \ 56 | s(y,2) = s(x,2); s(y,3) = s(x,3); 57 | #define state_in(y,x,k) si(y,x,k,0); si(y,x,k,1); si(y,x,k,2); si(y,x,k,3) 58 | #define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3) 59 | #define round(rm,y,x,k) rm(y,x,k,0); rm(y,x,k,1); rm(y,x,k,2); rm(y,x,k,3) 60 | 61 | #if defined(ENCRYPTION) && !defined(AES_ASM) 62 | 63 | /* Visual C++ .Net v7.1 provides the fastest encryption code when using 64 | Pentium optimiation with small code but this is poor for decryption 65 | so we need to control this with the following VC++ pragmas 66 | */ 67 | 68 | #if defined(_MSC_VER) 69 | #pragma optimize( "s", on ) 70 | #endif 71 | 72 | /* Given the column (c) of the output state variable, the following 73 | macros give the input state variables which are needed in its 74 | computation for each row (r) of the state. All the alternative 75 | macros give the same end values but expand into different ways 76 | of calculating these values. In particular the complex macro 77 | used for dynamically variable block sizes is designed to expand 78 | to a compile time constant whenever possible but will expand to 79 | conditional clauses on some branches (I am grateful to Frank 80 | Yellin for this construction) 81 | */ 82 | 83 | #define fwd_var(x,r,c)\ 84 | ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\ 85 | : r == 1 ? ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))\ 86 | : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\ 87 | : ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2))) 88 | 89 | #if defined(FT4_SET) 90 | #undef dec_fmvars 91 | #define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(f,n),fwd_var,rf1,c)) 92 | #elif defined(FT1_SET) 93 | #undef dec_fmvars 94 | #define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,upr,t_use(f,n),fwd_var,rf1,c)) 95 | #else 96 | #define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ fwd_mcol(no_table(x,t_use(s,box),fwd_var,rf1,c))) 97 | #endif 98 | 99 | #if defined(FL4_SET) 100 | #define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(f,l),fwd_var,rf1,c)) 101 | #elif defined(FL1_SET) 102 | #define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,ups,t_use(f,l),fwd_var,rf1,c)) 103 | #else 104 | #define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ no_table(x,t_use(s,box),fwd_var,rf1,c)) 105 | #endif 106 | 107 | aes_rval csql_aes_encrypt(const unsigned char *in, 108 | unsigned char *out, const csql_aes_encrypt_ctx cx[1]) 109 | { aes_32t locals(b0, b1); 110 | const aes_32t *kp = cx->ks; 111 | #if defined( dec_fmvars ) 112 | dec_fmvars; /* declare variables for fwd_mcol() if needed */ 113 | #endif 114 | 115 | #if defined( AES_ERR_CHK ) 116 | if( cx->rn != 10 && cx->rn != 12 && cx->rn != 14 ) 117 | return aes_error; 118 | #endif 119 | 120 | state_in(b0, in, kp); 121 | 122 | #if (ENC_UNROLL == FULL) 123 | 124 | switch(cx->rn) 125 | { 126 | case 14: 127 | round(fwd_rnd, b1, b0, kp + 1 * N_COLS); 128 | round(fwd_rnd, b0, b1, kp + 2 * N_COLS); 129 | kp += 2 * N_COLS; 130 | case 12: 131 | round(fwd_rnd, b1, b0, kp + 1 * N_COLS); 132 | round(fwd_rnd, b0, b1, kp + 2 * N_COLS); 133 | kp += 2 * N_COLS; 134 | case 10: 135 | round(fwd_rnd, b1, b0, kp + 1 * N_COLS); 136 | round(fwd_rnd, b0, b1, kp + 2 * N_COLS); 137 | round(fwd_rnd, b1, b0, kp + 3 * N_COLS); 138 | round(fwd_rnd, b0, b1, kp + 4 * N_COLS); 139 | round(fwd_rnd, b1, b0, kp + 5 * N_COLS); 140 | round(fwd_rnd, b0, b1, kp + 6 * N_COLS); 141 | round(fwd_rnd, b1, b0, kp + 7 * N_COLS); 142 | round(fwd_rnd, b0, b1, kp + 8 * N_COLS); 143 | round(fwd_rnd, b1, b0, kp + 9 * N_COLS); 144 | round(fwd_lrnd, b0, b1, kp +10 * N_COLS); 145 | } 146 | 147 | #else 148 | 149 | #if (ENC_UNROLL == PARTIAL) 150 | { aes_32t rnd; 151 | for(rnd = 0; rnd < (cx->rn >> 1) - 1; ++rnd) 152 | { 153 | kp += N_COLS; 154 | round(fwd_rnd, b1, b0, kp); 155 | kp += N_COLS; 156 | round(fwd_rnd, b0, b1, kp); 157 | } 158 | kp += N_COLS; 159 | round(fwd_rnd, b1, b0, kp); 160 | #else 161 | { aes_32t rnd; 162 | for(rnd = 0; rnd < cx->rn - 1; ++rnd) 163 | { 164 | kp += N_COLS; 165 | round(fwd_rnd, b1, b0, kp); 166 | l_copy(b0, b1); 167 | } 168 | #endif 169 | kp += N_COLS; 170 | round(fwd_lrnd, b0, b1, kp); 171 | } 172 | #endif 173 | 174 | state_out(out, b0); 175 | #if defined( AES_ERR_CHK ) 176 | return aes_good; 177 | #endif 178 | } 179 | 180 | #endif 181 | 182 | #if defined(DECRYPTION) && !defined(AES_ASM) 183 | 184 | /* Visual C++ .Net v7.1 provides the fastest encryption code when using 185 | Pentium optimiation with small code but this is poor for decryption 186 | so we need to control this with the following VC++ pragmas 187 | */ 188 | 189 | #if defined(_MSC_VER) 190 | #pragma optimize( "t", on ) 191 | #endif 192 | 193 | /* Given the column (c) of the output state variable, the following 194 | macros give the input state variables which are needed in its 195 | computation for each row (r) of the state. All the alternative 196 | macros give the same end values but expand into different ways 197 | of calculating these values. In particular the complex macro 198 | used for dynamically variable block sizes is designed to expand 199 | to a compile time constant whenever possible but will expand to 200 | conditional clauses on some branches (I am grateful to Frank 201 | Yellin for this construction) 202 | */ 203 | 204 | #define inv_var(x,r,c)\ 205 | ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\ 206 | : r == 1 ? ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2))\ 207 | : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\ 208 | : ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))) 209 | 210 | #if defined(IT4_SET) 211 | #undef dec_imvars 212 | #define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(i,n),inv_var,rf1,c)) 213 | #elif defined(IT1_SET) 214 | #undef dec_imvars 215 | #define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,upr,t_use(i,n),inv_var,rf1,c)) 216 | #else 217 | #define inv_rnd(y,x,k,c) (s(y,c) = inv_mcol((k)[c] ^ no_table(x,t_use(i,box),inv_var,rf1,c))) 218 | #endif 219 | 220 | #if defined(IL4_SET) 221 | #define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(i,l),inv_var,rf1,c)) 222 | #elif defined(IL1_SET) 223 | #define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,ups,t_use(i,l),inv_var,rf1,c)) 224 | #else 225 | #define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ no_table(x,t_use(i,box),inv_var,rf1,c)) 226 | #endif 227 | 228 | aes_rval csql_aes_decrypt(const unsigned char *in, 229 | unsigned char *out, const csql_aes_decrypt_ctx cx[1]) 230 | { aes_32t locals(b0, b1); 231 | #if defined( dec_imvars ) 232 | dec_imvars; /* declare variables for inv_mcol() if needed */ 233 | #endif 234 | const aes_32t *kp = cx->ks + cx->rn * N_COLS; 235 | 236 | #if defined( AES_ERR_CHK ) 237 | if( cx->rn != 10 && cx->rn != 12 && cx->rn != 14 ) 238 | return aes_error; 239 | #endif 240 | 241 | state_in(b0, in, kp); 242 | 243 | #if (DEC_UNROLL == FULL) 244 | 245 | switch(cx->rn) 246 | { 247 | case 14: 248 | round(inv_rnd, b1, b0, kp - 1 * N_COLS); 249 | round(inv_rnd, b0, b1, kp - 2 * N_COLS); 250 | kp -= 2 * N_COLS; 251 | case 12: 252 | round(inv_rnd, b1, b0, kp - 1 * N_COLS); 253 | round(inv_rnd, b0, b1, kp - 2 * N_COLS); 254 | kp -= 2 * N_COLS; 255 | case 10: 256 | round(inv_rnd, b1, b0, kp - 1 * N_COLS); 257 | round(inv_rnd, b0, b1, kp - 2 * N_COLS); 258 | round(inv_rnd, b1, b0, kp - 3 * N_COLS); 259 | round(inv_rnd, b0, b1, kp - 4 * N_COLS); 260 | round(inv_rnd, b1, b0, kp - 5 * N_COLS); 261 | round(inv_rnd, b0, b1, kp - 6 * N_COLS); 262 | round(inv_rnd, b1, b0, kp - 7 * N_COLS); 263 | round(inv_rnd, b0, b1, kp - 8 * N_COLS); 264 | round(inv_rnd, b1, b0, kp - 9 * N_COLS); 265 | round(inv_lrnd, b0, b1, kp - 10 * N_COLS); 266 | } 267 | 268 | #else 269 | 270 | #if (DEC_UNROLL == PARTIAL) 271 | { aes_32t rnd; 272 | for(rnd = 0; rnd < (cx->rn >> 1) - 1; ++rnd) 273 | { 274 | kp -= N_COLS; 275 | round(inv_rnd, b1, b0, kp); 276 | kp -= N_COLS; 277 | round(inv_rnd, b0, b1, kp); 278 | } 279 | kp -= N_COLS; 280 | round(inv_rnd, b1, b0, kp); 281 | #else 282 | { aes_32t rnd; 283 | for(rnd = 0; rnd < cx->rn - 1; ++rnd) 284 | { 285 | kp -= N_COLS; 286 | round(inv_rnd, b1, b0, kp); 287 | l_copy(b0, b1); 288 | } 289 | #endif 290 | kp -= N_COLS; 291 | round(inv_lrnd, b0, b1, kp); 292 | } 293 | #endif 294 | 295 | state_out(out, b0); 296 | #if defined( AES_ERR_CHK ) 297 | return aes_good; 298 | #endif 299 | } 300 | 301 | #endif 302 | 303 | #if defined(__cplusplus) 304 | } 305 | #endif 306 | -------------------------------------------------------------------------------- /C_SDK/crypt/aeskey.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 26/08/2003 31 | 32 | This file contains the code for implementing the key schedule for AES 33 | (Rijndael) for block and key sizes of 16, 24, and 32 bytes. See aesopt.h 34 | for further details including optimisation. 35 | */ 36 | 37 | #include "aesopt.h" 38 | #include "aestab.h" 39 | 40 | #if defined(__cplusplus) 41 | extern "C" 42 | { 43 | #endif 44 | 45 | /* Initialise the key schedule from the user supplied key. The key 46 | length can be specified in bytes, with legal values of 16, 24 47 | and 32, or in bits, with legal values of 128, 192 and 256. These 48 | values correspond with Nk values of 4, 6 and 8 respectively. 49 | 50 | The following macros implement a single cycle in the key 51 | schedule generation process. The number of cycles needed 52 | for each cx->n_col and nk value is: 53 | 54 | nk = 4 5 6 7 8 55 | ------------------------------ 56 | cx->n_col = 4 10 9 8 7 7 57 | cx->n_col = 5 14 11 10 9 9 58 | cx->n_col = 6 19 15 12 11 11 59 | cx->n_col = 7 21 19 16 13 14 60 | cx->n_col = 8 29 23 19 17 14 61 | */ 62 | 63 | #define ke4(k,i) \ 64 | { k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+5] = ss[1] ^= ss[0]; \ 65 | k[4*(i)+6] = ss[2] ^= ss[1]; k[4*(i)+7] = ss[3] ^= ss[2]; \ 66 | } 67 | #define kel4(k,i) \ 68 | { k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+5] = ss[1] ^= ss[0]; \ 69 | k[4*(i)+6] = ss[2] ^= ss[1]; k[4*(i)+7] = ss[3] ^= ss[2]; \ 70 | } 71 | 72 | #define ke6(k,i) \ 73 | { k[6*(i)+ 6] = ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 7] = ss[1] ^= ss[0]; \ 74 | k[6*(i)+ 8] = ss[2] ^= ss[1]; k[6*(i)+ 9] = ss[3] ^= ss[2]; \ 75 | k[6*(i)+10] = ss[4] ^= ss[3]; k[6*(i)+11] = ss[5] ^= ss[4]; \ 76 | } 77 | #define kel6(k,i) \ 78 | { k[6*(i)+ 6] = ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 7] = ss[1] ^= ss[0]; \ 79 | k[6*(i)+ 8] = ss[2] ^= ss[1]; k[6*(i)+ 9] = ss[3] ^= ss[2]; \ 80 | } 81 | 82 | #define ke8(k,i) \ 83 | { k[8*(i)+ 8] = ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 9] = ss[1] ^= ss[0]; \ 84 | k[8*(i)+10] = ss[2] ^= ss[1]; k[8*(i)+11] = ss[3] ^= ss[2]; \ 85 | k[8*(i)+12] = ss[4] ^= ls_box(ss[3],0); k[8*(i)+13] = ss[5] ^= ss[4]; \ 86 | k[8*(i)+14] = ss[6] ^= ss[5]; k[8*(i)+15] = ss[7] ^= ss[6]; \ 87 | } 88 | #define kel8(k,i) \ 89 | { k[8*(i)+ 8] = ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 9] = ss[1] ^= ss[0]; \ 90 | k[8*(i)+10] = ss[2] ^= ss[1]; k[8*(i)+11] = ss[3] ^= ss[2]; \ 91 | } 92 | 93 | #if defined(ENCRYPTION_KEY_SCHEDULE) 94 | 95 | #if defined(AES_128) || defined(AES_VAR) 96 | 97 | aes_rval csql_aes_encrypt_key128(const unsigned char *key, csql_aes_encrypt_ctx cx[1]) 98 | { aes_32t ss[4]; 99 | 100 | cx->ks[0] = ss[0] = word_in(key, 0); 101 | cx->ks[1] = ss[1] = word_in(key, 1); 102 | cx->ks[2] = ss[2] = word_in(key, 2); 103 | cx->ks[3] = ss[3] = word_in(key, 3); 104 | 105 | #if ENC_UNROLL == NONE 106 | { aes_32t i; 107 | 108 | for(i = 0; i < ((11 * N_COLS - 5) / 4); ++i) 109 | ke4(cx->ks, i); 110 | } 111 | #else 112 | ke4(cx->ks, 0); ke4(cx->ks, 1); 113 | ke4(cx->ks, 2); ke4(cx->ks, 3); 114 | ke4(cx->ks, 4); ke4(cx->ks, 5); 115 | ke4(cx->ks, 6); ke4(cx->ks, 7); 116 | ke4(cx->ks, 8); 117 | #endif 118 | kel4(cx->ks, 9); 119 | cx->rn = 10; 120 | #if defined( AES_ERR_CHK ) 121 | return aes_good; 122 | #endif 123 | } 124 | 125 | #endif 126 | 127 | #if defined(AES_192) || defined(AES_VAR) 128 | 129 | aes_rval csql_aes_encrypt_key192(const unsigned char *key, csql_aes_encrypt_ctx cx[1]) 130 | { aes_32t ss[6]; 131 | 132 | cx->ks[0] = ss[0] = word_in(key, 0); 133 | cx->ks[1] = ss[1] = word_in(key, 1); 134 | cx->ks[2] = ss[2] = word_in(key, 2); 135 | cx->ks[3] = ss[3] = word_in(key, 3); 136 | cx->ks[4] = ss[4] = word_in(key, 4); 137 | cx->ks[5] = ss[5] = word_in(key, 5); 138 | 139 | #if ENC_UNROLL == NONE 140 | { aes_32t i; 141 | 142 | for(i = 0; i < (13 * N_COLS - 7) / 6; ++i) 143 | ke6(cx->ks, i); 144 | } 145 | #else 146 | ke6(cx->ks, 0); ke6(cx->ks, 1); 147 | ke6(cx->ks, 2); ke6(cx->ks, 3); 148 | ke6(cx->ks, 4); ke6(cx->ks, 5); 149 | ke6(cx->ks, 6); 150 | #endif 151 | kel6(cx->ks, 7); 152 | cx->rn = 12; 153 | #if defined( AES_ERR_CHK ) 154 | return aes_good; 155 | #endif 156 | } 157 | 158 | #endif 159 | 160 | #if defined(AES_256) || defined(AES_VAR) 161 | 162 | aes_rval csql_aes_encrypt_key256(const unsigned char *key, csql_aes_encrypt_ctx cx[1]) 163 | { aes_32t ss[8]; 164 | 165 | cx->ks[0] = ss[0] = word_in(key, 0); 166 | cx->ks[1] = ss[1] = word_in(key, 1); 167 | cx->ks[2] = ss[2] = word_in(key, 2); 168 | cx->ks[3] = ss[3] = word_in(key, 3); 169 | cx->ks[4] = ss[4] = word_in(key, 4); 170 | cx->ks[5] = ss[5] = word_in(key, 5); 171 | cx->ks[6] = ss[6] = word_in(key, 6); 172 | cx->ks[7] = ss[7] = word_in(key, 7); 173 | 174 | #if ENC_UNROLL == NONE 175 | { aes_32t i; 176 | 177 | for(i = 0; i < (15 * N_COLS - 9) / 8; ++i) 178 | ke8(cx->ks, i); 179 | } 180 | #else 181 | ke8(cx->ks, 0); ke8(cx->ks, 1); 182 | ke8(cx->ks, 2); ke8(cx->ks, 3); 183 | ke8(cx->ks, 4); ke8(cx->ks, 5); 184 | #endif 185 | kel8(cx->ks, 6); 186 | cx->rn = 14; 187 | #if defined( AES_ERR_CHK ) 188 | return aes_good; 189 | #endif 190 | } 191 | 192 | #endif 193 | 194 | #if defined(AES_VAR) 195 | 196 | aes_rval csql_aes_encrypt_key(const unsigned char *key, int key_len, csql_aes_encrypt_ctx cx[1]) 197 | { 198 | switch(key_len) 199 | { 200 | #if defined( AES_ERR_CHK ) 201 | case 16: case 128: return csql_aes_encrypt_key128(key, cx); 202 | case 24: case 192: return csql_aes_encrypt_key192(key, cx); 203 | case 32: case 256: return csql_aes_encrypt_key256(key, cx); 204 | default: return aes_error; 205 | #else 206 | case 16: case 128: csql_aes_encrypt_key128(key, cx); return; 207 | case 24: case 192: csql_aes_encrypt_key192(key, cx); return; 208 | case 32: case 256: csql_aes_encrypt_key256(key, cx); return; 209 | #endif 210 | } 211 | } 212 | 213 | #endif 214 | 215 | #endif 216 | 217 | #if defined(DECRYPTION_KEY_SCHEDULE) 218 | 219 | #if DEC_ROUND == NO_TABLES 220 | #define ff(x) (x) 221 | #else 222 | #define ff(x) inv_mcol(x) 223 | #if defined( dec_imvars ) 224 | #define d_vars dec_imvars 225 | #endif 226 | #endif 227 | 228 | #if 1 229 | #define kdf4(k,i) \ 230 | { ss[0] = ss[0] ^ ss[2] ^ ss[1] ^ ss[3]; ss[1] = ss[1] ^ ss[3]; ss[2] = ss[2] ^ ss[3]; ss[3] = ss[3]; \ 231 | ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; \ 232 | ss[4] ^= k[4*(i)]; k[4*(i)+4] = ff(ss[4]); ss[4] ^= k[4*(i)+1]; k[4*(i)+5] = ff(ss[4]); \ 233 | ss[4] ^= k[4*(i)+2]; k[4*(i)+6] = ff(ss[4]); ss[4] ^= k[4*(i)+3]; k[4*(i)+7] = ff(ss[4]); \ 234 | } 235 | #define kd4(k,i) \ 236 | { ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; ss[4] = ff(ss[4]); \ 237 | k[4*(i)+4] = ss[4] ^= k[4*(i)]; k[4*(i)+5] = ss[4] ^= k[4*(i)+1]; \ 238 | k[4*(i)+6] = ss[4] ^= k[4*(i)+2]; k[4*(i)+7] = ss[4] ^= k[4*(i)+3]; \ 239 | } 240 | #define kdl4(k,i) \ 241 | { ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; \ 242 | k[4*(i)+4] = (ss[0] ^= ss[1]) ^ ss[2] ^ ss[3]; k[4*(i)+5] = ss[1] ^ ss[3]; \ 243 | k[4*(i)+6] = ss[0]; k[4*(i)+7] = ss[1]; \ 244 | } 245 | #else 246 | #define kdf4(k,i) \ 247 | { ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+ 4] = ff(ss[0]); ss[1] ^= ss[0]; k[4*(i)+ 5] = ff(ss[1]); \ 248 | ss[2] ^= ss[1]; k[4*(i)+ 6] = ff(ss[2]); ss[3] ^= ss[2]; k[4*(i)+ 7] = ff(ss[3]); \ 249 | } 250 | #define kd4(k,i) \ 251 | { ss[4] = ls_box(ss[3],3) ^ t_use(r,c)[i]; \ 252 | ss[0] ^= ss[4]; ss[4] = ff(ss[4]); k[4*(i)+ 4] = ss[4] ^= k[4*(i)]; \ 253 | ss[1] ^= ss[0]; k[4*(i)+ 5] = ss[4] ^= k[4*(i)+ 1]; \ 254 | ss[2] ^= ss[1]; k[4*(i)+ 6] = ss[4] ^= k[4*(i)+ 2]; \ 255 | ss[3] ^= ss[2]; k[4*(i)+ 7] = ss[4] ^= k[4*(i)+ 3]; \ 256 | } 257 | #define kdl4(k,i) \ 258 | { ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+ 4] = ss[0]; ss[1] ^= ss[0]; k[4*(i)+ 5] = ss[1]; \ 259 | ss[2] ^= ss[1]; k[4*(i)+ 6] = ss[2]; ss[3] ^= ss[2]; k[4*(i)+ 7] = ss[3]; \ 260 | } 261 | #endif 262 | 263 | #define kdf6(k,i) \ 264 | { ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 6] = ff(ss[0]); ss[1] ^= ss[0]; k[6*(i)+ 7] = ff(ss[1]); \ 265 | ss[2] ^= ss[1]; k[6*(i)+ 8] = ff(ss[2]); ss[3] ^= ss[2]; k[6*(i)+ 9] = ff(ss[3]); \ 266 | ss[4] ^= ss[3]; k[6*(i)+10] = ff(ss[4]); ss[5] ^= ss[4]; k[6*(i)+11] = ff(ss[5]); \ 267 | } 268 | #define kd6(k,i) \ 269 | { ss[6] = ls_box(ss[5],3) ^ t_use(r,c)[i]; \ 270 | ss[0] ^= ss[6]; ss[6] = ff(ss[6]); k[6*(i)+ 6] = ss[6] ^= k[6*(i)]; \ 271 | ss[1] ^= ss[0]; k[6*(i)+ 7] = ss[6] ^= k[6*(i)+ 1]; \ 272 | ss[2] ^= ss[1]; k[6*(i)+ 8] = ss[6] ^= k[6*(i)+ 2]; \ 273 | ss[3] ^= ss[2]; k[6*(i)+ 9] = ss[6] ^= k[6*(i)+ 3]; \ 274 | ss[4] ^= ss[3]; k[6*(i)+10] = ss[6] ^= k[6*(i)+ 4]; \ 275 | ss[5] ^= ss[4]; k[6*(i)+11] = ss[6] ^= k[6*(i)+ 5]; \ 276 | } 277 | #define kdl6(k,i) \ 278 | { ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 6] = ss[0]; ss[1] ^= ss[0]; k[6*(i)+ 7] = ss[1]; \ 279 | ss[2] ^= ss[1]; k[6*(i)+ 8] = ss[2]; ss[3] ^= ss[2]; k[6*(i)+ 9] = ss[3]; \ 280 | } 281 | 282 | #define kdf8(k,i) \ 283 | { ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 8] = ff(ss[0]); ss[1] ^= ss[0]; k[8*(i)+ 9] = ff(ss[1]); \ 284 | ss[2] ^= ss[1]; k[8*(i)+10] = ff(ss[2]); ss[3] ^= ss[2]; k[8*(i)+11] = ff(ss[3]); \ 285 | ss[4] ^= ls_box(ss[3],0); k[8*(i)+12] = ff(ss[4]); ss[5] ^= ss[4]; k[8*(i)+13] = ff(ss[5]); \ 286 | ss[6] ^= ss[5]; k[8*(i)+14] = ff(ss[6]); ss[7] ^= ss[6]; k[8*(i)+15] = ff(ss[7]); \ 287 | } 288 | #define kd8(k,i) \ 289 | { aes_32t g = ls_box(ss[7],3) ^ t_use(r,c)[i]; \ 290 | ss[0] ^= g; g = ff(g); k[8*(i)+ 8] = g ^= k[8*(i)]; \ 291 | ss[1] ^= ss[0]; k[8*(i)+ 9] = g ^= k[8*(i)+ 1]; \ 292 | ss[2] ^= ss[1]; k[8*(i)+10] = g ^= k[8*(i)+ 2]; \ 293 | ss[3] ^= ss[2]; k[8*(i)+11] = g ^= k[8*(i)+ 3]; \ 294 | g = ls_box(ss[3],0); \ 295 | ss[4] ^= g; g = ff(g); k[8*(i)+12] = g ^= k[8*(i)+ 4]; \ 296 | ss[5] ^= ss[4]; k[8*(i)+13] = g ^= k[8*(i)+ 5]; \ 297 | ss[6] ^= ss[5]; k[8*(i)+14] = g ^= k[8*(i)+ 6]; \ 298 | ss[7] ^= ss[6]; k[8*(i)+15] = g ^= k[8*(i)+ 7]; \ 299 | } 300 | #define kdl8(k,i) \ 301 | { ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 8] = ss[0]; ss[1] ^= ss[0]; k[8*(i)+ 9] = ss[1]; \ 302 | ss[2] ^= ss[1]; k[8*(i)+10] = ss[2]; ss[3] ^= ss[2]; k[8*(i)+11] = ss[3]; \ 303 | } 304 | 305 | #if defined(AES_128) || defined(AES_VAR) 306 | 307 | aes_rval csql_aes_decrypt_key128(const unsigned char *key, csql_aes_decrypt_ctx cx[1]) 308 | { aes_32t ss[5]; 309 | #if defined( d_vars ) 310 | d_vars; 311 | #endif 312 | cx->ks[0] = ss[0] = word_in(key, 0); 313 | cx->ks[1] = ss[1] = word_in(key, 1); 314 | cx->ks[2] = ss[2] = word_in(key, 2); 315 | cx->ks[3] = ss[3] = word_in(key, 3); 316 | 317 | #if DEC_UNROLL == NONE 318 | { aes_32t i; 319 | 320 | for(i = 0; i < (11 * N_COLS - 5) / 4; ++i) 321 | ke4(cx->ks, i); 322 | kel4(cx->ks, 9); 323 | #if !(DEC_ROUND == NO_TABLES) 324 | for(i = N_COLS; i < 10 * N_COLS; ++i) 325 | cx->ks[i] = inv_mcol(cx->ks[i]); 326 | #endif 327 | } 328 | #else 329 | kdf4(cx->ks, 0); kd4(cx->ks, 1); 330 | kd4(cx->ks, 2); kd4(cx->ks, 3); 331 | kd4(cx->ks, 4); kd4(cx->ks, 5); 332 | kd4(cx->ks, 6); kd4(cx->ks, 7); 333 | kd4(cx->ks, 8); kdl4(cx->ks, 9); 334 | #endif 335 | cx->rn = 10; 336 | #if defined( AES_ERR_CHK ) 337 | return aes_good; 338 | #endif 339 | } 340 | 341 | #endif 342 | 343 | #if defined(AES_192) || defined(AES_VAR) 344 | 345 | aes_rval csql_aes_decrypt_key192(const unsigned char *key, csql_aes_decrypt_ctx cx[1]) 346 | { aes_32t ss[7]; 347 | #if defined( d_vars ) 348 | d_vars; 349 | #endif 350 | cx->ks[0] = ss[0] = word_in(key, 0); 351 | cx->ks[1] = ss[1] = word_in(key, 1); 352 | cx->ks[2] = ss[2] = word_in(key, 2); 353 | cx->ks[3] = ss[3] = word_in(key, 3); 354 | 355 | #if DEC_UNROLL == NONE 356 | cx->ks[4] = ss[4] = word_in(key, 4); 357 | cx->ks[5] = ss[5] = word_in(key, 5); 358 | { aes_32t i; 359 | 360 | for(i = 0; i < (13 * N_COLS - 7) / 6; ++i) 361 | ke6(cx->ks, i); 362 | kel6(cx->ks, 7); 363 | #if !(DEC_ROUND == NO_TABLES) 364 | for(i = N_COLS; i < 12 * N_COLS; ++i) 365 | cx->ks[i] = inv_mcol(cx->ks[i]); 366 | #endif 367 | } 368 | #else 369 | cx->ks[4] = ff(ss[4] = word_in(key, 4)); 370 | cx->ks[5] = ff(ss[5] = word_in(key, 5)); 371 | kdf6(cx->ks, 0); kd6(cx->ks, 1); 372 | kd6(cx->ks, 2); kd6(cx->ks, 3); 373 | kd6(cx->ks, 4); kd6(cx->ks, 5); 374 | kd6(cx->ks, 6); kdl6(cx->ks, 7); 375 | #endif 376 | cx->rn = 12; 377 | #if defined( AES_ERR_CHK ) 378 | return aes_good; 379 | #endif 380 | } 381 | 382 | #endif 383 | 384 | #if defined(AES_256) || defined(AES_VAR) 385 | 386 | aes_rval csql_aes_decrypt_key256(const unsigned char *key, csql_aes_decrypt_ctx cx[1]) 387 | { aes_32t ss[8]; 388 | #if defined( d_vars ) 389 | d_vars; 390 | #endif 391 | cx->ks[0] = ss[0] = word_in(key, 0); 392 | cx->ks[1] = ss[1] = word_in(key, 1); 393 | cx->ks[2] = ss[2] = word_in(key, 2); 394 | cx->ks[3] = ss[3] = word_in(key, 3); 395 | 396 | #if DEC_UNROLL == NONE 397 | cx->ks[4] = ss[4] = word_in(key, 4); 398 | cx->ks[5] = ss[5] = word_in(key, 5); 399 | cx->ks[6] = ss[6] = word_in(key, 6); 400 | cx->ks[7] = ss[7] = word_in(key, 7); 401 | { aes_32t i; 402 | 403 | for(i = 0; i < (15 * N_COLS - 9) / 8; ++i) 404 | ke8(cx->ks, i); 405 | kel8(cx->ks, i); 406 | #if !(DEC_ROUND == NO_TABLES) 407 | for(i = N_COLS; i < 14 * N_COLS; ++i) 408 | cx->ks[i] = inv_mcol(cx->ks[i]); 409 | 410 | #endif 411 | } 412 | #else 413 | cx->ks[4] = ff(ss[4] = word_in(key, 4)); 414 | cx->ks[5] = ff(ss[5] = word_in(key, 5)); 415 | cx->ks[6] = ff(ss[6] = word_in(key, 6)); 416 | cx->ks[7] = ff(ss[7] = word_in(key, 7)); 417 | kdf8(cx->ks, 0); kd8(cx->ks, 1); 418 | kd8(cx->ks, 2); kd8(cx->ks, 3); 419 | kd8(cx->ks, 4); kd8(cx->ks, 5); 420 | kdl8(cx->ks, 6); 421 | #endif 422 | cx->rn = 14; 423 | #if defined( AES_ERR_CHK ) 424 | return aes_good; 425 | #endif 426 | } 427 | 428 | #endif 429 | 430 | #if defined(AES_VAR) 431 | 432 | aes_rval csql_aes_decrypt_key(const unsigned char *key, int key_len, csql_aes_decrypt_ctx cx[1]) 433 | { 434 | switch(key_len) 435 | { 436 | #if defined( AES_ERR_CHK ) 437 | case 16: case 128: return csql_aes_decrypt_key128(key, cx); 438 | case 24: case 192: return csql_aes_decrypt_key192(key, cx); 439 | case 32: case 256: return csql_aes_decrypt_key256(key, cx); 440 | default: return aes_error; 441 | #else 442 | case 16: case 128: csql_aes_decrypt_key128(key, cx); return; 443 | case 24: case 192: csql_aes_decrypt_key192(key, cx); return; 444 | case 32: case 256: csql_aes_decrypt_key256(key, cx); return; 445 | #endif 446 | } 447 | } 448 | 449 | #endif 450 | 451 | #endif 452 | 453 | #if defined(__cplusplus) 454 | } 455 | #endif 456 | -------------------------------------------------------------------------------- /C_SDK/crypt/aestab.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue 28/01/2004 31 | 32 | */ 33 | 34 | #if defined(__cplusplus) 35 | extern "C" 36 | { 37 | #endif 38 | 39 | #define DO_TABLES 40 | 41 | #include "aesopt.h" 42 | 43 | #if defined(FIXED_TABLES) 44 | 45 | #define sb_data(w) {\ 46 | w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\ 47 | w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\ 48 | w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\ 49 | w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\ 50 | w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\ 51 | w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\ 52 | w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\ 53 | w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\ 54 | w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\ 55 | w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\ 56 | w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\ 57 | w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\ 58 | w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\ 59 | w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\ 60 | w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\ 61 | w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\ 62 | w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\ 63 | w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\ 64 | w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\ 65 | w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\ 66 | w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\ 67 | w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\ 68 | w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\ 69 | w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\ 70 | w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\ 71 | w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\ 72 | w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\ 73 | w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\ 74 | w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\ 75 | w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\ 76 | w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\ 77 | w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) } 78 | 79 | #define isb_data(w) {\ 80 | w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), w(0x38),\ 81 | w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), w(0xd7), w(0xfb),\ 82 | w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), w(0x2f), w(0xff), w(0x87),\ 83 | w(0x34), w(0x8e), w(0x43), w(0x44), w(0xc4), w(0xde), w(0xe9), w(0xcb),\ 84 | w(0x54), w(0x7b), w(0x94), w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d),\ 85 | w(0xee), w(0x4c), w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e),\ 86 | w(0x08), w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2),\ 87 | w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), w(0x25),\ 88 | w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), w(0x98), w(0x16),\ 89 | w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), w(0x65), w(0xb6), w(0x92),\ 90 | w(0x6c), w(0x70), w(0x48), w(0x50), w(0xfd), w(0xed), w(0xb9), w(0xda),\ 91 | w(0x5e), w(0x15), w(0x46), w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84),\ 92 | w(0x90), w(0xd8), w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a),\ 93 | w(0xf7), w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06),\ 94 | w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), w(0x02),\ 95 | w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), w(0x8a), w(0x6b),\ 96 | w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), w(0x67), w(0xdc), w(0xea),\ 97 | w(0x97), w(0xf2), w(0xcf), w(0xce), w(0xf0), w(0xb4), w(0xe6), w(0x73),\ 98 | w(0x96), w(0xac), w(0x74), w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85),\ 99 | w(0xe2), w(0xf9), w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e),\ 100 | w(0x47), w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89),\ 101 | w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), w(0x1b),\ 102 | w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), w(0x79), w(0x20),\ 103 | w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), w(0xcd), w(0x5a), w(0xf4),\ 104 | w(0x1f), w(0xdd), w(0xa8), w(0x33), w(0x88), w(0x07), w(0xc7), w(0x31),\ 105 | w(0xb1), w(0x12), w(0x10), w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f),\ 106 | w(0x60), w(0x51), w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d),\ 107 | w(0x2d), w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef),\ 108 | w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), w(0xb0),\ 109 | w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), w(0x99), w(0x61),\ 110 | w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), w(0x77), w(0xd6), w(0x26),\ 111 | w(0xe1), w(0x69), w(0x14), w(0x63), w(0x55), w(0x21), w(0x0c), w(0x7d) } 112 | 113 | #define mm_data(w) {\ 114 | w(0x00), w(0x01), w(0x02), w(0x03), w(0x04), w(0x05), w(0x06), w(0x07),\ 115 | w(0x08), w(0x09), w(0x0a), w(0x0b), w(0x0c), w(0x0d), w(0x0e), w(0x0f),\ 116 | w(0x10), w(0x11), w(0x12), w(0x13), w(0x14), w(0x15), w(0x16), w(0x17),\ 117 | w(0x18), w(0x19), w(0x1a), w(0x1b), w(0x1c), w(0x1d), w(0x1e), w(0x1f),\ 118 | w(0x20), w(0x21), w(0x22), w(0x23), w(0x24), w(0x25), w(0x26), w(0x27),\ 119 | w(0x28), w(0x29), w(0x2a), w(0x2b), w(0x2c), w(0x2d), w(0x2e), w(0x2f),\ 120 | w(0x30), w(0x31), w(0x32), w(0x33), w(0x34), w(0x35), w(0x36), w(0x37),\ 121 | w(0x38), w(0x39), w(0x3a), w(0x3b), w(0x3c), w(0x3d), w(0x3e), w(0x3f),\ 122 | w(0x40), w(0x41), w(0x42), w(0x43), w(0x44), w(0x45), w(0x46), w(0x47),\ 123 | w(0x48), w(0x49), w(0x4a), w(0x4b), w(0x4c), w(0x4d), w(0x4e), w(0x4f),\ 124 | w(0x50), w(0x51), w(0x52), w(0x53), w(0x54), w(0x55), w(0x56), w(0x57),\ 125 | w(0x58), w(0x59), w(0x5a), w(0x5b), w(0x5c), w(0x5d), w(0x5e), w(0x5f),\ 126 | w(0x60), w(0x61), w(0x62), w(0x63), w(0x64), w(0x65), w(0x66), w(0x67),\ 127 | w(0x68), w(0x69), w(0x6a), w(0x6b), w(0x6c), w(0x6d), w(0x6e), w(0x6f),\ 128 | w(0x70), w(0x71), w(0x72), w(0x73), w(0x74), w(0x75), w(0x76), w(0x77),\ 129 | w(0x78), w(0x79), w(0x7a), w(0x7b), w(0x7c), w(0x7d), w(0x7e), w(0x7f),\ 130 | w(0x80), w(0x81), w(0x82), w(0x83), w(0x84), w(0x85), w(0x86), w(0x87),\ 131 | w(0x88), w(0x89), w(0x8a), w(0x8b), w(0x8c), w(0x8d), w(0x8e), w(0x8f),\ 132 | w(0x90), w(0x91), w(0x92), w(0x93), w(0x94), w(0x95), w(0x96), w(0x97),\ 133 | w(0x98), w(0x99), w(0x9a), w(0x9b), w(0x9c), w(0x9d), w(0x9e), w(0x9f),\ 134 | w(0xa0), w(0xa1), w(0xa2), w(0xa3), w(0xa4), w(0xa5), w(0xa6), w(0xa7),\ 135 | w(0xa8), w(0xa9), w(0xaa), w(0xab), w(0xac), w(0xad), w(0xae), w(0xaf),\ 136 | w(0xb0), w(0xb1), w(0xb2), w(0xb3), w(0xb4), w(0xb5), w(0xb6), w(0xb7),\ 137 | w(0xb8), w(0xb9), w(0xba), w(0xbb), w(0xbc), w(0xbd), w(0xbe), w(0xbf),\ 138 | w(0xc0), w(0xc1), w(0xc2), w(0xc3), w(0xc4), w(0xc5), w(0xc6), w(0xc7),\ 139 | w(0xc8), w(0xc9), w(0xca), w(0xcb), w(0xcc), w(0xcd), w(0xce), w(0xcf),\ 140 | w(0xd0), w(0xd1), w(0xd2), w(0xd3), w(0xd4), w(0xd5), w(0xd6), w(0xd7),\ 141 | w(0xd8), w(0xd9), w(0xda), w(0xdb), w(0xdc), w(0xdd), w(0xde), w(0xdf),\ 142 | w(0xe0), w(0xe1), w(0xe2), w(0xe3), w(0xe4), w(0xe5), w(0xe6), w(0xe7),\ 143 | w(0xe8), w(0xe9), w(0xea), w(0xeb), w(0xec), w(0xed), w(0xee), w(0xef),\ 144 | w(0xf0), w(0xf1), w(0xf2), w(0xf3), w(0xf4), w(0xf5), w(0xf6), w(0xf7),\ 145 | w(0xf8), w(0xf9), w(0xfa), w(0xfb), w(0xfc), w(0xfd), w(0xfe), w(0xff) } 146 | 147 | #define rc_data(w) {\ 148 | w(0x01), w(0x02), w(0x04), w(0x08), w(0x10),w(0x20), w(0x40), w(0x80),\ 149 | w(0x1b), w(0x36) } 150 | 151 | #define h0(x) (x) 152 | 153 | #define w0(p) bytes2word(p, 0, 0, 0) 154 | #define w1(p) bytes2word(0, p, 0, 0) 155 | #define w2(p) bytes2word(0, 0, p, 0) 156 | #define w3(p) bytes2word(0, 0, 0, p) 157 | 158 | #define u0(p) bytes2word(f2(p), p, p, f3(p)) 159 | #define u1(p) bytes2word(f3(p), f2(p), p, p) 160 | #define u2(p) bytes2word(p, f3(p), f2(p), p) 161 | #define u3(p) bytes2word(p, p, f3(p), f2(p)) 162 | 163 | #define v0(p) bytes2word(fe(p), f9(p), fd(p), fb(p)) 164 | #define v1(p) bytes2word(fb(p), fe(p), f9(p), fd(p)) 165 | #define v2(p) bytes2word(fd(p), fb(p), fe(p), f9(p)) 166 | #define v3(p) bytes2word(f9(p), fd(p), fb(p), fe(p)) 167 | 168 | #endif 169 | 170 | #if defined(FIXED_TABLES) || !defined(FF_TABLES) 171 | 172 | #define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY)) 173 | #define f4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY)) 174 | #define f8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) \ 175 | ^ (((x>>5) & 4) * WPOLY)) 176 | #define f3(x) (f2(x) ^ x) 177 | #define f9(x) (f8(x) ^ x) 178 | #define fb(x) (f8(x) ^ f2(x) ^ x) 179 | #define fd(x) (f8(x) ^ f4(x) ^ x) 180 | #define fe(x) (f8(x) ^ f4(x) ^ f2(x)) 181 | 182 | #else 183 | 184 | #define f2(x) ((x) ? pow[log[x] + 0x19] : 0) 185 | #define f3(x) ((x) ? pow[log[x] + 0x01] : 0) 186 | #define f9(x) ((x) ? pow[log[x] + 0xc7] : 0) 187 | #define fb(x) ((x) ? pow[log[x] + 0x68] : 0) 188 | #define fd(x) ((x) ? pow[log[x] + 0xee] : 0) 189 | #define fe(x) ((x) ? pow[log[x] + 0xdf] : 0) 190 | #define fi(x) ((x) ? pow[ 255 - log[x]] : 0) 191 | 192 | #endif 193 | 194 | #include "aestab.h" 195 | 196 | #if defined(FIXED_TABLES) 197 | 198 | /* implemented in case of wrong call for fixed tables */ 199 | 200 | void csql_gen_tabs(void) 201 | { 202 | } 203 | 204 | #else /* dynamic table generation */ 205 | 206 | #if !defined(FF_TABLES) 207 | 208 | /* Generate the tables for the dynamic table option 209 | 210 | It will generally be sensible to use tables to compute finite 211 | field multiplies and inverses but where memory is scarse this 212 | code might sometimes be better. But it only has effect during 213 | initialisation so its pretty unimportant in overall terms. 214 | */ 215 | 216 | /* return 2 ^ (n - 1) where n is the bit number of the highest bit 217 | set in x with x in the range 1 < x < 0x00000200. This form is 218 | used so that locals within fi can be bytes rather than words 219 | */ 220 | 221 | static aes_08t hibit(const aes_32t x) 222 | { aes_08t r = (aes_08t)((x >> 1) | (x >> 2)); 223 | 224 | r |= (r >> 2); 225 | r |= (r >> 4); 226 | return (r + 1) >> 1; 227 | } 228 | 229 | /* return the inverse of the finite field element x */ 230 | 231 | static aes_08t fi(const aes_08t x) 232 | { aes_08t p1 = x, p2 = BPOLY, n1 = hibit(x), n2 = 0x80, v1 = 1, v2 = 0; 233 | 234 | if(x < 2) return x; 235 | 236 | for(;;) 237 | { 238 | if(!n1) return v1; 239 | 240 | while(n2 >= n1) 241 | { 242 | n2 /= n1; p2 ^= p1 * n2; v2 ^= v1 * n2; n2 = hibit(p2); 243 | } 244 | 245 | if(!n2) return v2; 246 | 247 | while(n1 >= n2) 248 | { 249 | n1 /= n2; p1 ^= p2 * n1; v1 ^= v2 * n1; n1 = hibit(p1); 250 | } 251 | } 252 | } 253 | 254 | #endif 255 | 256 | /* The forward and inverse affine transformations used in the S-box */ 257 | 258 | #define fwd_affine(x) \ 259 | (w = (aes_32t)x, w ^= (w<<1)^(w<<2)^(w<<3)^(w<<4), 0x63^(aes_08t)(w^(w>>8))) 260 | 261 | #define inv_affine(x) \ 262 | (w = (aes_32t)x, w = (w<<1)^(w<<3)^(w<<6), 0x05^(aes_08t)(w^(w>>8))) 263 | 264 | static int init = 0; 265 | 266 | void csql_gen_tabs(void) 267 | { aes_32t i, w; 268 | 269 | #if defined(FF_TABLES) 270 | 271 | aes_08t pow[512], log[256]; 272 | 273 | if(init) return; 274 | /* log and power tables for GF(2^8) finite field with 275 | WPOLY as modular polynomial - the simplest primitive 276 | root is 0x03, used here to generate the tables 277 | */ 278 | 279 | i = 0; w = 1; 280 | do 281 | { 282 | pow[i] = (aes_08t)w; 283 | pow[i + 255] = (aes_08t)w; 284 | log[w] = (aes_08t)i++; 285 | w ^= (w << 1) ^ (w & 0x80 ? WPOLY : 0); 286 | } 287 | while (w != 1); 288 | 289 | #else 290 | if(init) return; 291 | #endif 292 | 293 | for(i = 0, w = 1; i < RC_LENGTH; ++i) 294 | { 295 | t_set(r,c)[i] = bytes2word(w, 0, 0, 0); 296 | w = f2(w); 297 | } 298 | 299 | for(i = 0; i < 256; ++i) 300 | { aes_08t b; 301 | 302 | b = fwd_affine(fi((aes_08t)i)); 303 | w = bytes2word(f2(b), b, b, f3(b)); 304 | 305 | #if defined( SBX_SET ) 306 | t_set(s,box)[i] = b; 307 | #endif 308 | 309 | #if defined( FT1_SET ) /* tables for a normal encryption round */ 310 | t_set(f,n)[i] = w; 311 | #endif 312 | #if defined( FT4_SET ) 313 | t_set(f,n)[0][i] = w; 314 | t_set(f,n)[1][i] = upr(w,1); 315 | t_set(f,n)[2][i] = upr(w,2); 316 | t_set(f,n)[3][i] = upr(w,3); 317 | #endif 318 | w = bytes2word(b, 0, 0, 0); 319 | 320 | #if defined( FL1_SET ) /* tables for last encryption round (may also */ 321 | t_set(f,l)[i] = w; /* be used in the key schedule) */ 322 | #endif 323 | #if defined( FL4_SET ) 324 | t_set(f,l)[0][i] = w; 325 | t_set(f,l)[1][i] = upr(w,1); 326 | t_set(f,l)[2][i] = upr(w,2); 327 | t_set(f,l)[3][i] = upr(w,3); 328 | #endif 329 | 330 | #if defined( LS1_SET ) /* table for key schedule if t_set(f,l) above is */ 331 | t_set(l,s)[i] = w; /* not of the required form */ 332 | #endif 333 | #if defined( LS4_SET ) 334 | t_set(l,s)[0][i] = w; 335 | t_set(l,s)[1][i] = upr(w,1); 336 | t_set(l,s)[2][i] = upr(w,2); 337 | t_set(l,s)[3][i] = upr(w,3); 338 | #endif 339 | 340 | b = fi(inv_affine((aes_08t)i)); 341 | w = bytes2word(fe(b), f9(b), fd(b), fb(b)); 342 | 343 | #if defined( IM1_SET ) /* tables for the inverse mix column operation */ 344 | t_set(i,m)[b] = w; 345 | #endif 346 | #if defined( IM4_SET ) 347 | t_set(i,m)[0][b] = w; 348 | t_set(i,m)[1][b] = upr(w,1); 349 | t_set(i,m)[2][b] = upr(w,2); 350 | t_set(i,m)[3][b] = upr(w,3); 351 | #endif 352 | 353 | #if defined( ISB_SET ) 354 | t_set(i,box)[i] = b; 355 | #endif 356 | #if defined( IT1_SET ) /* tables for a normal decryption round */ 357 | t_set(i,n)[i] = w; 358 | #endif 359 | #if defined( IT4_SET ) 360 | t_set(i,n)[0][i] = w; 361 | t_set(i,n)[1][i] = upr(w,1); 362 | t_set(i,n)[2][i] = upr(w,2); 363 | t_set(i,n)[3][i] = upr(w,3); 364 | #endif 365 | w = bytes2word(b, 0, 0, 0); 366 | #if defined( IL1_SET ) /* tables for last decryption round */ 367 | t_set(i,l)[i] = w; 368 | #endif 369 | #if defined( IL4_SET ) 370 | t_set(i,l)[0][i] = w; 371 | t_set(i,l)[1][i] = upr(w,1); 372 | t_set(i,l)[2][i] = upr(w,2); 373 | t_set(i,l)[3][i] = upr(w,3); 374 | #endif 375 | } 376 | init = 1; 377 | } 378 | 379 | #endif 380 | 381 | #if defined(__cplusplus) 382 | } 383 | #endif 384 | 385 | -------------------------------------------------------------------------------- /C_SDK/crypt/aestab.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue 28/01/2004 31 | 32 | This file contains the code for declaring the tables needed to implement 33 | AES. The file aesopt.h is assumed to be included before this header file. 34 | If there are no global variables, the definitions here can be used to put 35 | the AES tables in a structure so that a pointer can then be added to the 36 | AES context to pass them to the AES routines that need them. If this 37 | facility is used, the calling program has to ensure that this pointer is 38 | managed appropriately. In particular, the value of the t_dec(in,it) item 39 | in the table structure must be set to zero in order to ensure that the 40 | tables are initialised. In practice the three code sequences in aeskey.c 41 | that control the calls to gen_tabs() and the gen_tabs() routine itself will 42 | have to be changed for a specific implementation. If global variables are 43 | available it will generally be preferable to use them with the precomputed 44 | FIXED_TABLES option that uses static global tables. 45 | 46 | The following defines can be used to control the way the tables 47 | are defined, initialised and used in embedded environments that 48 | require special features for these purposes 49 | 50 | the 't_dec' construction is used to declare fixed table arrays 51 | the 't_set' construction is used to set fixed table values 52 | the 't_use' construction is used to access fixed table values 53 | 54 | 256 byte tables: 55 | 56 | t_xxx(s,box) => forward S box 57 | t_xxx(i,box) => inverse S box 58 | 59 | 256 32-bit word OR 4 x 256 32-bit word tables: 60 | 61 | t_xxx(f,n) => forward normal round 62 | t_xxx(f,l) => forward last round 63 | t_xxx(i,n) => inverse normal round 64 | t_xxx(i,l) => inverse last round 65 | t_xxx(l,s) => key schedule table 66 | t_xxx(i,m) => key schedule table 67 | 68 | Other variables and tables: 69 | 70 | t_xxx(r,c) => the rcon table 71 | */ 72 | 73 | #if !defined( _AESTAB_H ) 74 | #define _AESTAB_H 75 | 76 | #define t_dec(m,n) csql_t_##m##n 77 | #define t_set(m,n) csql_t_##m##n 78 | #define t_use(m,n) csql_t_##m##n 79 | 80 | #if defined(FIXED_TABLES) 81 | #define Const const 82 | #else 83 | #define Const 84 | #endif 85 | 86 | #if defined(DO_TABLES) 87 | #define Extern 88 | #else 89 | #define Extern extern 90 | #endif 91 | 92 | #if defined(_MSC_VER) && defined(TABLE_ALIGN) 93 | #define Align __declspec(align(TABLE_ALIGN)) 94 | #else 95 | #define Align 96 | #endif 97 | 98 | #if defined(__cplusplus) 99 | extern "C" 100 | { 101 | #endif 102 | 103 | #if defined(DO_TABLES) && defined(FIXED_TABLES) 104 | #define d_1(t,n,b,e) Align Const t n[256] = b(e) 105 | #define d_4(t,n,b,e,f,g,h) Align Const t n[4][256] = { b(e), b(f), b(g), b(h) } 106 | Extern Align Const aes_32t t_dec(r,c)[RC_LENGTH] = rc_data(w0); 107 | #else 108 | #define d_1(t,n,b,e) Extern Align Const t n[256] 109 | #define d_4(t,n,b,e,f,g,h) Extern Align Const t n[4][256] 110 | Extern Align Const aes_32t t_dec(r,c)[RC_LENGTH]; 111 | #endif 112 | 113 | #if defined( SBX_SET ) 114 | d_1(aes_08t, t_dec(s,box), sb_data, h0); 115 | #endif 116 | #if defined( ISB_SET ) 117 | d_1(aes_08t, t_dec(i,box), isb_data, h0); 118 | #endif 119 | 120 | #if defined( FT1_SET ) 121 | d_1(aes_32t, t_dec(f,n), sb_data, u0); 122 | #endif 123 | #if defined( FT4_SET ) 124 | d_4(aes_32t, t_dec(f,n), sb_data, u0, u1, u2, u3); 125 | #endif 126 | 127 | #if defined( FL1_SET ) 128 | d_1(aes_32t, t_dec(f,l), sb_data, w0); 129 | #endif 130 | #if defined( FL4_SET ) 131 | d_4(aes_32t, t_dec(f,l), sb_data, w0, w1, w2, w3); 132 | #endif 133 | 134 | #if defined( IT1_SET ) 135 | d_1(aes_32t, t_dec(i,n), isb_data, v0); 136 | #endif 137 | #if defined( IT4_SET ) 138 | d_4(aes_32t, t_dec(i,n), isb_data, v0, v1, v2, v3); 139 | #endif 140 | 141 | #if defined( IL1_SET ) 142 | d_1(aes_32t, t_dec(i,l), isb_data, w0); 143 | #endif 144 | #if defined( IL4_SET ) 145 | d_4(aes_32t, t_dec(i,l), isb_data, w0, w1, w2, w3); 146 | #endif 147 | 148 | #if defined( LS1_SET ) 149 | #if defined( FL1_SET ) 150 | #undef LS1_SET 151 | #else 152 | d_1(aes_32t, t_dec(l,s), sb_data, w0); 153 | #endif 154 | #endif 155 | 156 | #if defined( LS4_SET ) 157 | #if defined( FL4_SET ) 158 | #undef LS4_SET 159 | #else 160 | d_4(aes_32t, t_dec(l,s), sb_data, w0, w1, w2, w3); 161 | #endif 162 | #endif 163 | 164 | #if defined( IM1_SET ) 165 | d_1(aes_32t, t_dec(i,m), mm_data, v0); 166 | #endif 167 | #if defined( IM4_SET ) 168 | d_4(aes_32t, t_dec(i,m), mm_data, v0, v1, v2, v3); 169 | #endif 170 | 171 | #if defined(__cplusplus) 172 | } 173 | #endif 174 | 175 | #endif 176 | -------------------------------------------------------------------------------- /C_SDK/crypt/base64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * base64.c -- base-64 conversion routines. 3 | * 4 | * This base 64 encoding is defined in RFC2045 section 6.8, 5 | * "Base64 Content-Transfer-Encoding", but lines must not be broken in the 6 | * scheme used here. 7 | */ 8 | 9 | #include 10 | #include "base64.h" 11 | 12 | #if !defined(isascii) 13 | #ifdef __MWERKS__ 14 | #ifdef WIN32 15 | #define isascii(x) ((unsigned)(x) < 0x80) 16 | #else 17 | int isascii(int c); 18 | #endif 19 | #endif 20 | #endif 21 | 22 | static const char base64digits[] = 23 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 24 | 25 | #define BAD -1 26 | static const char base64val[] = { 27 | BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, 28 | BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, 29 | BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD, 62, BAD,BAD,BAD, 63, 30 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,BAD,BAD, BAD,BAD,BAD,BAD, 31 | BAD, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 32 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,BAD, BAD,BAD,BAD,BAD, 33 | BAD, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 34 | 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,BAD, BAD,BAD,BAD,BAD 35 | }; 36 | #define DECODE64(c) (isascii(c) ? base64val[c] : BAD) 37 | 38 | void csql_to64frombits(unsigned char *out, const unsigned char *in, int inlen) 39 | /* raw bytes in quasi-big-endian order to base 64 string (NUL-terminated) */ 40 | { 41 | for (; inlen >= 3; inlen -= 3) 42 | { 43 | *out++ = base64digits[in[0] >> 2]; 44 | *out++ = base64digits[((in[0] << 4) & 0x30) | (in[1] >> 4)]; 45 | *out++ = base64digits[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; 46 | *out++ = base64digits[in[2] & 0x3f]; 47 | in += 3; 48 | } 49 | if (inlen > 0) 50 | { 51 | unsigned char fragment; 52 | 53 | *out++ = base64digits[in[0] >> 2]; 54 | fragment = (in[0] << 4) & 0x30; 55 | if (inlen > 1) 56 | fragment |= in[1] >> 4; 57 | *out++ = base64digits[fragment]; 58 | *out++ = (inlen < 2) ? '=' : base64digits[(in[1] << 2) & 0x3c]; 59 | *out++ = '='; 60 | } 61 | *out = '\0'; 62 | } 63 | 64 | int csql_from64tobits(char *out, const char *in) 65 | /* base 64 to raw bytes in quasi-big-endian order, returning count of bytes */ 66 | { 67 | int len = 0; 68 | register unsigned char digit1, digit2, digit3, digit4; 69 | 70 | if (in[0] == '+' && in[1] == ' ') 71 | in += 2; 72 | if (*in == '\r') 73 | return(0); 74 | 75 | do { 76 | digit1 = in[0]; 77 | if ((digit1 == 0) && (len > 0)) goto bug_workaround; 78 | 79 | if (DECODE64(digit1) == BAD) 80 | return(-1); 81 | digit2 = in[1]; 82 | if (DECODE64(digit2) == BAD) 83 | return(-1); 84 | digit3 = in[2]; 85 | if (digit3 != '=' && DECODE64(digit3) == BAD) 86 | return(-1); 87 | digit4 = in[3]; 88 | if (digit4 != '=' && DECODE64(digit4) == BAD) 89 | return(-1); 90 | in += 4; 91 | *out++ = (DECODE64(digit1) << 2) | (DECODE64(digit2) >> 4); 92 | ++len; 93 | if (digit3 != '=') 94 | { 95 | *out++ = ((DECODE64(digit2) << 4) & 0xf0) | (DECODE64(digit3) >> 2); 96 | ++len; 97 | if (digit4 != '=') 98 | { 99 | *out++ = ((DECODE64(digit3) << 6) & 0xc0) | DECODE64(digit4); 100 | ++len; 101 | } 102 | } 103 | } while 104 | (*in != '\r' && digit4 != '='); 105 | 106 | bug_workaround: 107 | return (len); 108 | } 109 | 110 | /* base64.c ends here */ 111 | -------------------------------------------------------------------------------- /C_SDK/crypt/base64.h: -------------------------------------------------------------------------------- 1 | #ifndef _BASE64_H_ 2 | #define _BASE64_H_ 3 | 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include 10 | 11 | /* Encode Base64 */ 12 | void csql_to64frombits(unsigned char *out, const unsigned char *in, int inlen); 13 | 14 | /* Decode Base64 */ 15 | int csql_from64tobits(char *out, const char *in); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /C_SDK/crypt/pseudorandom.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | From: http://remus.rutgers.edu/~rhoads/Code/tt800.c 3 | Code by Dr. Glenn Rhoads 4 | Modified by Marco Bambini 5 | 6 | A C-program for TT800 : July 8th 1996 Version 7 | by M. Matsumoto, email: matumoto@math.keio.ac.jp 8 | genrand() generate one pseudorandom number with double precision 9 | which is uniformly distributed on [0,1]-interval 10 | for each call. One may choose any initial 25 seeds 11 | except all zeros. 12 | 13 | See: ACM Transactions on Modelling and Computer Simulation, 14 | Vol. 4, No. 3, 1994, pages 254-266. 15 | ***********************************************************************/ 16 | 17 | #include "pseudorandom.h" 18 | 19 | #define N 25 20 | #define M 7 21 | 22 | static unsigned int x[N]; /* the 25 seeds */ 23 | 24 | void csql_rand_init (unsigned int seed) 25 | { 26 | int k; 27 | 28 | x[0] = (seed|1) & 0xffffffff; 29 | for (k=1; k> 1) ^ mag01[x[kk] & 1]; 49 | 50 | for (; kk < N; kk++) 51 | x[kk] = x[kk+(M-N)] ^ (x[kk] >> 1) ^ mag01[x[kk] & 1]; 52 | 53 | k=0; 54 | } 55 | 56 | y = x[k++]; 57 | y ^= (y << 7) & 0x2b5b2500; 58 | y ^= (y << 15) & 0xdb8b0000; 59 | y &= 0xffffffff; /* you may delete this line if word size = 32 */ 60 | y ^= (y >> 16); 61 | 62 | return y; 63 | } 64 | 65 | void csql_rand_fill (char *buf) 66 | { 67 | unsigned int randint, i, times; 68 | 69 | times = 20 / sizeof(unsigned int); 70 | for (i=0; i 10 | #include 11 | 12 | void csql_rand_init (unsigned int seed); 13 | void csql_static_randinit (void); 14 | unsigned int csql_rand_get (void); 15 | void csql_rand_fill (char *buf); 16 | void csql_rand_fill_16 (char *buf); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif 23 | 24 | -------------------------------------------------------------------------------- /C_SDK/crypt/sha1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the project nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | /* 30 | * FIPS pub 180-1: Secure Hash Algorithm (SHA-1) 31 | * based on: http://csrc.nist.gov/fips/fip180-1.txt 32 | * implemented by Jun-ichiro itojun Itoh 33 | */ 34 | 35 | #include 36 | #include 37 | #include "sha1.h" 38 | 39 | /* constant table */ 40 | static u_int32_t _K[] = { 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 }; 41 | #define K(t) _K[(t) / 20] 42 | 43 | #define F0(b, c, d) (((b) & (c)) | ((~(b)) & (d))) 44 | #define F1(b, c, d) (((b) ^ (c)) ^ (d)) 45 | #define F2(b, c, d) (((b) & (c)) | ((b) & (d)) | ((c) & (d))) 46 | #define F3(b, c, d) (((b) ^ (c)) ^ (d)) 47 | 48 | #define S(n, x) (((x) << (n)) | ((x) >> (32 - n))) 49 | 50 | #define H(n) (ctxt->h.b32[(n)]) 51 | #define COUNT (ctxt->count) 52 | #define BCOUNT (ctxt->c.b64[0] / 8) 53 | #define W(n) (ctxt->m.b32[(n)]) 54 | 55 | #define PUTBYTE(x) { \ 56 | ctxt->m.b8[(COUNT % 64)] = (x); \ 57 | COUNT++; \ 58 | COUNT %= 64; \ 59 | ctxt->c.b64[0] += 8; \ 60 | if (COUNT % 64 == 0) \ 61 | sha1_step(ctxt); \ 62 | } 63 | 64 | #define PUTPAD(x) { \ 65 | ctxt->m.b8[(COUNT % 64)] = (x); \ 66 | COUNT++; \ 67 | COUNT %= 64; \ 68 | if (COUNT % 64 == 0) \ 69 | sha1_step(ctxt); \ 70 | } 71 | 72 | static void sha1_step(struct csql_sha1_ctxt *ctxt) 73 | { 74 | u_int32_t a, b, c, d, e; 75 | size_t t, s; 76 | u_int32_t tmp; 77 | 78 | #if SHA1_BYTE_ORDER == SHA1_LITTLE_ENDIAN 79 | struct csql_sha1_ctxt tctxt; 80 | bcopy(&ctxt->m.b8[0], &tctxt.m.b8[0], 64); 81 | ctxt->m.b8[0] = tctxt.m.b8[3]; ctxt->m.b8[1] = tctxt.m.b8[2]; 82 | ctxt->m.b8[2] = tctxt.m.b8[1]; ctxt->m.b8[3] = tctxt.m.b8[0]; 83 | ctxt->m.b8[4] = tctxt.m.b8[7]; ctxt->m.b8[5] = tctxt.m.b8[6]; 84 | ctxt->m.b8[6] = tctxt.m.b8[5]; ctxt->m.b8[7] = tctxt.m.b8[4]; 85 | ctxt->m.b8[8] = tctxt.m.b8[11]; ctxt->m.b8[9] = tctxt.m.b8[10]; 86 | ctxt->m.b8[10] = tctxt.m.b8[9]; ctxt->m.b8[11] = tctxt.m.b8[8]; 87 | ctxt->m.b8[12] = tctxt.m.b8[15]; ctxt->m.b8[13] = tctxt.m.b8[14]; 88 | ctxt->m.b8[14] = tctxt.m.b8[13]; ctxt->m.b8[15] = tctxt.m.b8[12]; 89 | ctxt->m.b8[16] = tctxt.m.b8[19]; ctxt->m.b8[17] = tctxt.m.b8[18]; 90 | ctxt->m.b8[18] = tctxt.m.b8[17]; ctxt->m.b8[19] = tctxt.m.b8[16]; 91 | ctxt->m.b8[20] = tctxt.m.b8[23]; ctxt->m.b8[21] = tctxt.m.b8[22]; 92 | ctxt->m.b8[22] = tctxt.m.b8[21]; ctxt->m.b8[23] = tctxt.m.b8[20]; 93 | ctxt->m.b8[24] = tctxt.m.b8[27]; ctxt->m.b8[25] = tctxt.m.b8[26]; 94 | ctxt->m.b8[26] = tctxt.m.b8[25]; ctxt->m.b8[27] = tctxt.m.b8[24]; 95 | ctxt->m.b8[28] = tctxt.m.b8[31]; ctxt->m.b8[29] = tctxt.m.b8[30]; 96 | ctxt->m.b8[30] = tctxt.m.b8[29]; ctxt->m.b8[31] = tctxt.m.b8[28]; 97 | ctxt->m.b8[32] = tctxt.m.b8[35]; ctxt->m.b8[33] = tctxt.m.b8[34]; 98 | ctxt->m.b8[34] = tctxt.m.b8[33]; ctxt->m.b8[35] = tctxt.m.b8[32]; 99 | ctxt->m.b8[36] = tctxt.m.b8[39]; ctxt->m.b8[37] = tctxt.m.b8[38]; 100 | ctxt->m.b8[38] = tctxt.m.b8[37]; ctxt->m.b8[39] = tctxt.m.b8[36]; 101 | ctxt->m.b8[40] = tctxt.m.b8[43]; ctxt->m.b8[41] = tctxt.m.b8[42]; 102 | ctxt->m.b8[42] = tctxt.m.b8[41]; ctxt->m.b8[43] = tctxt.m.b8[40]; 103 | ctxt->m.b8[44] = tctxt.m.b8[47]; ctxt->m.b8[45] = tctxt.m.b8[46]; 104 | ctxt->m.b8[46] = tctxt.m.b8[45]; ctxt->m.b8[47] = tctxt.m.b8[44]; 105 | ctxt->m.b8[48] = tctxt.m.b8[51]; ctxt->m.b8[49] = tctxt.m.b8[50]; 106 | ctxt->m.b8[50] = tctxt.m.b8[49]; ctxt->m.b8[51] = tctxt.m.b8[48]; 107 | ctxt->m.b8[52] = tctxt.m.b8[55]; ctxt->m.b8[53] = tctxt.m.b8[54]; 108 | ctxt->m.b8[54] = tctxt.m.b8[53]; ctxt->m.b8[55] = tctxt.m.b8[52]; 109 | ctxt->m.b8[56] = tctxt.m.b8[59]; ctxt->m.b8[57] = tctxt.m.b8[58]; 110 | ctxt->m.b8[58] = tctxt.m.b8[57]; ctxt->m.b8[59] = tctxt.m.b8[56]; 111 | ctxt->m.b8[60] = tctxt.m.b8[63]; ctxt->m.b8[61] = tctxt.m.b8[62]; 112 | ctxt->m.b8[62] = tctxt.m.b8[61]; ctxt->m.b8[63] = tctxt.m.b8[60]; 113 | #endif 114 | 115 | a = H(0); b = H(1); c = H(2); d = H(3); e = H(4); 116 | 117 | for (t = 0; t < 20; t++) { 118 | s = t & 0x0f; 119 | if (t >= 16) { 120 | W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s)); 121 | } 122 | tmp = S(5, a) + F0(b, c, d) + e + W(s) + K(t); 123 | e = d; d = c; c = S(30, b); b = a; a = tmp; 124 | } 125 | for (t = 20; t < 40; t++) { 126 | s = t & 0x0f; 127 | W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s)); 128 | tmp = S(5, a) + F1(b, c, d) + e + W(s) + K(t); 129 | e = d; d = c; c = S(30, b); b = a; a = tmp; 130 | } 131 | for (t = 40; t < 60; t++) { 132 | s = t & 0x0f; 133 | W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s)); 134 | tmp = S(5, a) + F2(b, c, d) + e + W(s) + K(t); 135 | e = d; d = c; c = S(30, b); b = a; a = tmp; 136 | } 137 | for (t = 60; t < 80; t++) { 138 | s = t & 0x0f; 139 | W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s)); 140 | tmp = S(5, a) + F3(b, c, d) + e + W(s) + K(t); 141 | e = d; d = c; c = S(30, b); b = a; a = tmp; 142 | } 143 | 144 | H(0) = H(0) + a; 145 | H(1) = H(1) + b; 146 | H(2) = H(2) + c; 147 | H(3) = H(3) + d; 148 | H(4) = H(4) + e; 149 | 150 | bzero(&ctxt->m.b8[0], 64); 151 | } 152 | 153 | /*------------------------------------------------------------*/ 154 | 155 | void csql_sha1_init(struct csql_sha1_ctxt *ctxt) 156 | { 157 | bzero(ctxt, sizeof(struct csql_sha1_ctxt)); 158 | H(0) = 0x67452301; 159 | H(1) = 0xefcdab89; 160 | H(2) = 0x98badcfe; 161 | H(3) = 0x10325476; 162 | H(4) = 0xc3d2e1f0; 163 | } 164 | 165 | void csql_sha1_pad(struct csql_sha1_ctxt *ctxt) 166 | { 167 | size_t padlen; /*pad length in bytes*/ 168 | size_t padstart; 169 | 170 | PUTPAD(0x80); 171 | 172 | padstart = COUNT % 64; 173 | padlen = 64 - padstart; 174 | if (padlen < 8) { 175 | bzero(&ctxt->m.b8[padstart], padlen); 176 | COUNT += padlen; 177 | COUNT %= 64; 178 | sha1_step(ctxt); 179 | padstart = COUNT % 64; /* should be 0 */ 180 | padlen = 64 - padstart; /* should be 64 */ 181 | } 182 | bzero(&ctxt->m.b8[padstart], padlen - 8); 183 | COUNT += (padlen - 8); 184 | COUNT %= 64; 185 | #if SHA1_BYTE_ORDER == SHA1_BIG_ENDIAN 186 | PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]); 187 | PUTPAD(ctxt->c.b8[2]); PUTPAD(ctxt->c.b8[3]); 188 | PUTPAD(ctxt->c.b8[4]); PUTPAD(ctxt->c.b8[5]); 189 | PUTPAD(ctxt->c.b8[6]); PUTPAD(ctxt->c.b8[7]); 190 | #else 191 | PUTPAD(ctxt->c.b8[7]); PUTPAD(ctxt->c.b8[6]); 192 | PUTPAD(ctxt->c.b8[5]); PUTPAD(ctxt->c.b8[4]); 193 | PUTPAD(ctxt->c.b8[3]); PUTPAD(ctxt->c.b8[2]); 194 | PUTPAD(ctxt->c.b8[1]); PUTPAD(ctxt->c.b8[0]); 195 | #endif 196 | } 197 | 198 | void csql_sha1_loop(struct csql_sha1_ctxt *ctxt, const caddr_t input0, size_t len) 199 | { 200 | const u_int8_t *input; 201 | size_t gaplen; 202 | size_t gapstart; 203 | size_t off; 204 | size_t copysiz; 205 | 206 | input = (const u_int8_t *)input0; 207 | off = 0; 208 | 209 | while (off < len) { 210 | gapstart = COUNT % 64; 211 | gaplen = 64 - gapstart; 212 | 213 | copysiz = (gaplen < len - off) ? gaplen : len - off; 214 | bcopy(&input[off], &ctxt->m.b8[gapstart], copysiz); 215 | COUNT += copysiz; 216 | COUNT %= 64; 217 | ctxt->c.b64[0] += copysiz * 8; 218 | if (COUNT % 64 == 0) 219 | sha1_step(ctxt); 220 | off += copysiz; 221 | } 222 | } 223 | 224 | void csql_sha1_result(struct csql_sha1_ctxt *ctxt, caddr_t digest0) 225 | { 226 | u_int8_t *digest; 227 | 228 | digest = (u_int8_t *)digest0; 229 | csql_sha1_pad(ctxt); 230 | #if SHA1_BYTE_ORDER == SHA1_BIG_ENDIAN 231 | bcopy(&ctxt->h.b8[0], digest, 20); 232 | #else 233 | digest[0] = ctxt->h.b8[3]; digest[1] = ctxt->h.b8[2]; 234 | digest[2] = ctxt->h.b8[1]; digest[3] = ctxt->h.b8[0]; 235 | digest[4] = ctxt->h.b8[7]; digest[5] = ctxt->h.b8[6]; 236 | digest[6] = ctxt->h.b8[5]; digest[7] = ctxt->h.b8[4]; 237 | digest[8] = ctxt->h.b8[11]; digest[9] = ctxt->h.b8[10]; 238 | digest[10] = ctxt->h.b8[9]; digest[11] = ctxt->h.b8[8]; 239 | digest[12] = ctxt->h.b8[15]; digest[13] = ctxt->h.b8[14]; 240 | digest[14] = ctxt->h.b8[13]; digest[15] = ctxt->h.b8[12]; 241 | digest[16] = ctxt->h.b8[19]; digest[17] = ctxt->h.b8[18]; 242 | digest[18] = ctxt->h.b8[17]; digest[19] = ctxt->h.b8[16]; 243 | #endif 244 | } 245 | 246 | void csql_sha1(unsigned char hval[], const unsigned char data[], unsigned int len) 247 | { 248 | struct csql_sha1_ctxt ctxt; 249 | 250 | csql_sha1_init(&ctxt); csql_sha1_loop(&ctxt, (const caddr_t) data, len); csql_sha1_result(&ctxt, (char *)hval); 251 | } 252 | 253 | -------------------------------------------------------------------------------- /C_SDK/crypt/sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the project nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | /* 30 | * FIPS pub 180-1: Secure Hash Algorithm (SHA-1) 31 | * based on: http://csrc.nist.gov/fips/fip180-1.txt 32 | * implemented by Jun-ichiro itojun Itoh 33 | */ 34 | 35 | #ifndef _SHA1_H_ 36 | #define _SHA1_H_ 37 | 38 | #ifdef __GNUC__ 39 | #include 40 | #endif 41 | 42 | #ifdef __MWERKS__ 43 | #include 44 | #endif 45 | 46 | #if defined(__cplusplus) 47 | extern "C" 48 | { 49 | #endif 50 | 51 | #ifdef WIN32 52 | typedef unsigned char u_int8_t; 53 | typedef unsigned int u_int32_t; 54 | typedef unsigned long long u_int64_t; 55 | typedef char* caddr_t; 56 | #endif 57 | 58 | #define SHA1_BIG_ENDIAN 1 59 | #define SHA1_LITTLE_ENDIAN 2 60 | 61 | #if defined (__ppc__) 62 | #define SHA1_BYTE_ORDER SHA1_BIG_ENDIAN 63 | #else 64 | #define SHA1_BYTE_ORDER SHA1_LITTLE_ENDIAN 65 | #endif 66 | 67 | #define SHA1_DIGEST_SIZE 20 68 | #define SHA1_RESULTLEN (160/8) 69 | 70 | #if defined(HAVE_BZERO) || defined(bzero) 71 | // do nothing 72 | #else 73 | #define bzero(ptr,n) memset(ptr, 0, n) 74 | #endif 75 | 76 | #if defined(HAVE_BCOPY) || defined(bcopy) 77 | // do nothing 78 | #else 79 | #define bcopy(from, to, len) memcpy ((to), (from), (len)) 80 | #endif 81 | 82 | struct csql_sha1_ctxt { 83 | union { 84 | u_int8_t b8[20]; 85 | u_int32_t b32[5]; 86 | } h; 87 | union { 88 | u_int8_t b8[8]; 89 | u_int64_t b64[1]; 90 | } c; 91 | union { 92 | u_int8_t b8[64]; 93 | u_int32_t b32[16]; 94 | } m; 95 | u_int8_t count; 96 | }; 97 | 98 | void csql_sha1_init (struct csql_sha1_ctxt *); 99 | void csql_sha1_pad (struct csql_sha1_ctxt *); 100 | void csql_sha1_loop (struct csql_sha1_ctxt *, const caddr_t, size_t); 101 | void csql_sha1_result (struct csql_sha1_ctxt *, caddr_t); 102 | 103 | typedef struct csql_sha1_ctxt SHA1_CTX; 104 | #define CSQL_SHA1Init(x) csql_sha1_init((x)) 105 | #define CSQL_SHA1Update(x, y, z) csql_sha1_loop((x), (y), (z)) 106 | #define CSQL_SHA1Final(x, y) csql_sha1_result((y), (x)) 107 | 108 | void csql_sha1(unsigned char hval[], const unsigned char data[], unsigned int len); 109 | 110 | #if defined(__cplusplus) 111 | } 112 | #endif 113 | 114 | #endif /*__SHA1_H_*/ 115 | -------------------------------------------------------------------------------- /C_SDK/csql.h: -------------------------------------------------------------------------------- 1 | /* 2 | * csql.h 3 | * 4 | * This file is the private interface for the CubeSQL Server SDK. 5 | * You just need to include the cubesql.h header file in your projects. 6 | * 7 | * (c) 2006-2023 SQLabs srl -- All Rights Reserved 8 | * Author: Marco Bambini (MB) 9 | * 10 | */ 11 | 12 | #ifndef __CUBESQL_H__ 13 | #define __CUBESQL_H__ 14 | 15 | #ifdef WIN32 16 | #include 17 | #include 18 | #pragma comment(lib, "Ws2_32.lib") 19 | #endif 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #ifdef WIN32 30 | #include 31 | #include 32 | #include 33 | #include "zlib.h" 34 | #else 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #endif 56 | 57 | #if defined(__cplusplus) 58 | extern "C" 59 | { 60 | #endif 61 | 62 | #include "aes.h" 63 | #include "sha1.h" 64 | #include "pseudorandom.h" 65 | 66 | #ifdef WIN32 67 | // WINDOWS 68 | #pragma warning (disable: 4005) 69 | #pragma warning (disable: 4068) 70 | #define snprintf _snprintf 71 | #define strdup _strdup 72 | #define strtoll(x,y,z) _strtoi64(x,y,z) 73 | #define BSD_FD_ISSET FD_ISSET 74 | #define SHUT_RDWR 2 75 | #define SA SOCKADDR 76 | #define INET_ADDRSTRLEN 16 77 | #define EINTR WSAEINTR 78 | #define EAGAIN WSAEWOULDBLOCK 79 | #define EMSGSIZE WSAEMSGSIZE 80 | #define EAFNOSUPPORT WSAEAFNOSUPPORT 81 | #define EWOULDBLOCK WSAEWOULDBLOCK 82 | #define ECONNRESET WSAECONNRESET 83 | #define EINPROGRESS WSAEINPROGRESS 84 | #define IPV6_V6ONLY 27 85 | 86 | #define ioctl ioctlsocket 87 | #define bsd_h_errno() h_errno 88 | #define bsd_setsockopt setsockopt 89 | #define bsd_getsockopt getsockopt 90 | #define bsd_inet_pton inet_pton 91 | #define bsd_shutdown shutdown 92 | #define cleanup() WSACleanup() 93 | #define bsd_select select 94 | #define sock_read(a,b,c) recv((a), (b), (c), 0L) 95 | #define sock_write(a,b,c) send((a), (b), (c), 0L) 96 | #define PATH_SEPARATOR "\\" 97 | #define Pause() Sleep(INFINITE) 98 | #define mssleep(ms) Sleep(ms) 99 | 100 | typedef int socklen_t; 101 | typedef int ssize_t; 102 | typedef unsigned long in_addr_t; 103 | 104 | #else 105 | // UNIX 106 | #define BSD_FD_ISSET FD_ISSET 107 | #define bsd_h_errno() h_errno 108 | #define bsd_setsockopt setsockopt 109 | #define bsd_getsockopt getsockopt 110 | #define bsd_inet_pton inet_pton 111 | #define bsd_shutdown shutdown 112 | #define bsd_select select 113 | #define PATH_SEPARATOR "/" 114 | #define closesocket(s) close(s) 115 | #define cleanup() 116 | #define sock_write write 117 | #define sock_read read 118 | #define Pause() pause() 119 | #define mssleep(ms) usleep((ms)*1000) 120 | #endif 121 | 122 | /* PROTOCOL MACROS */ 123 | #define SETBIT(x, b) ((x) |= (b)) 124 | #define CLEARBIT(x, b) ((x) &= ~(b)) 125 | #define TESTBIT(x, b) (((x) & (b)) != 0) 126 | 127 | /* CLIENT -> SERVER */ 128 | #define CLIENT_SUPPORT_COMPRESSION 0x01 129 | #define CLIENT_UNUSED_1 0x02 130 | #define CLIENT_UNUSED_2 0x04 131 | #define CLIENT_COMPRESSED_PACKET 0x08 132 | #define CLIENT_ADD_ROWID_COLUMN 0x10 133 | #define CLIENT_PARTIAL_PACKET 0x20 134 | #define CLIENT_REQUEST_SERVER_SIDE 0x40 135 | #define CLIENT_UNUSED_3 0x80 136 | 137 | /* SERVER -> CLIENT */ 138 | #define SERVER_PROTOCOL_2009 0x01 139 | #define SERVER_UNUSED_1 0x02 140 | #define SERVER_HAS_ROWID_COLUMN 0x04 141 | #define SERVER_COMPRESSED_PACKET 0x08 142 | #define SERVER_UNUSED_2 0x10 143 | #define SERVER_PARTIAL_PACKET 0x20 144 | #define SERVER_SERVER_SIDE 0x40 145 | #define SERVER_HAS_TABLE_NAME 0x80 146 | 147 | // client version 148 | #define k2007PROTOCOL 3 149 | #define k2011PROTOCOL 4 150 | 151 | #define ERR_SOCKET_INVALID_PORT_HOST 800 152 | #define ERR_SOCKET 802 153 | #define ERR_SOCKET_NULL 805 154 | #define ERR_SOCKET_TIMEOUT 810 155 | #define ERR_SOCKET_WRITE 820 156 | #define ERR_SOCKET_READ 830 157 | #define ERR_WRONG_HEADER 835 158 | #define ERR_WRONG_SIGNATURE 840 159 | #define ERR_NULL_BUFFER 845 160 | #define ERR_WRONG_Y 850 161 | #define ERR_NULL_RANDBUFF 855 162 | #define ERR_RANDPOOL 860 163 | #define ERR_DB_IS_NULL 865 164 | #define ERR_BUFFER_NULL 870 165 | #define END_CHUNK 777 166 | #define ERR_SSL 888 167 | 168 | /* common definitions */ 169 | #define BLOCK_LEN AES_BLOCK_SIZE 170 | #define PROTOCOL_SIGNATURE 'SQLS' 171 | #define kRANDPOOLSIZE 20 172 | #define kHEADER_SIZE 32 173 | #define NULL_VALUE -1 174 | #define kNUMBUFFER 1000 175 | #define kMAXCHUNK 100*1024 176 | #define NO_TIMEOUT 0 177 | #define CONNECT_TIMEOUT 5 178 | 179 | #if defined(HAVE_BZERO) || defined(bzero) 180 | // do nothing 181 | #else 182 | #undef bzero 183 | #define bzero(ptr,n) memset(ptr, 0, n) 184 | #endif 185 | 186 | #if defined(HAVE_BCOPY) || defined(bcopy) 187 | // do nothing 188 | #else 189 | #undef bcopy 190 | #define bcopy(from, to, len) memcpy ((to), (from), (len)) 191 | #endif 192 | 193 | #ifndef WIN32 194 | typedef int SOCKET; 195 | #endif 196 | 197 | #ifndef HEADER_TLS_H 198 | #define TLS_WANT_POLLIN -2 199 | #define TLS_WANT_POLLOUT -3 200 | struct tls; 201 | struct tls_config; 202 | struct tls *tls_client(void); 203 | struct tls_config *tls_config_new(void); 204 | int tls_init(void); 205 | int tls_configure(struct tls *_ctx, struct tls_config *_config); 206 | int tls_connect_socket(struct tls *_ctx, int _s, const char *_servername); 207 | int tls_close(struct tls *_ctx); 208 | int tls_config_set_ca_file(struct tls_config *_config, const char *_ca_file); 209 | int tls_config_set_cert_file(struct tls_config *_config,const char *_cert_file); 210 | int tls_config_set_key_file(struct tls_config *_config, const char *_key_file); 211 | void tls_config_insecure_noverifycert(struct tls_config* config); 212 | void tls_config_insecure_noverifyname(struct tls_config* config); 213 | int tls_config_set_ciphers(struct tls_config *config, const char *ciphers); 214 | ssize_t tls_read(struct tls *_ctx, void *_buf, size_t _buflen); 215 | ssize_t tls_write(struct tls *_ctx, const void *_buf, size_t _buflen); 216 | const char *tls_error(struct tls *_ctx); 217 | const char *tls_config_error(struct tls_config *_config); 218 | void tls_free(struct tls *_ctx); 219 | const char* SSLeay_version(int t); 220 | #endif 221 | 222 | /* COMMANDS */ 223 | #define kCOMMAND_CONNECT 1 224 | #define kCOMMAND_SELECT 2 225 | #define kCOMMAND_EXECUTE 3 226 | #define kCOMMAND_CLOSE 7 227 | #define kCOMMAND_PING 8 228 | #define kCOMMAND_CHUNK 9 229 | #define kCOMMAND_ENDCHUNK 10 230 | #define kCOMMAND_CURSOR_STEP 11 231 | #define kCOMMAND_CURSOR_CLOSE 12 232 | #define kCOMMAND_CHUNK_BIND 19 233 | #define kCOMMAND_IGNORE 666 234 | #define kCOMMAND_ABORT 667 235 | 236 | /* FIELD VALUES */ 237 | #define kEMPTY_FIELD 0 238 | #define kNONE 0 239 | #define kZLIB 1 240 | 241 | /* SELECTORS */ 242 | #define kNO_SELECTOR 0 243 | #define kCLEAR_CONNECT_PHASE1 20 244 | #define kCLEAR_CONNECT_PHASE2 21 245 | #define kENCRYPT_CONNECT_PHASE1 22 246 | #define kENCRYPT_CONNECT_PHASE2 23 247 | #define kENCRYPT_CONNECT_PHASE3 24 248 | #define kCHUNK_OK 25 249 | #define kCHUNK_ABORT 26 250 | #define kBIND_START 0 251 | #define kBIND_STEP 27 252 | #define kBIND_FINALIZE 28 253 | #define kBIND_ABORT 29 254 | #define kCLEAR_TOKEN_CONNECT1 40 255 | #define kCLEAR_TOKEN_CONNECT2 41 256 | #define kENCRYPT_TOKEN_CONNECT1 42 257 | #define kENCRYPT_TOKEN_CONNECT2 43 258 | 259 | /* VM PREPARED */ 260 | #define kVM_PREPARE 50 261 | #define kVM_BIND 51 262 | #define kVM_EXECUTE 52 263 | #define kVM_SELECT 53 264 | #define kVM_CLOSE 54 265 | 266 | #define kDEFAULT_ALLOC_ROWS 100 267 | 268 | // client -> server header 269 | typedef struct { 270 | unsigned int signature; // PROTOCOL_SIGNATURE defined as 'SQLS' 271 | unsigned int packetSize; // size of the entire packet (header excluded) 272 | unsigned char command; // main command 273 | unsigned char selector; // sub command selector 274 | unsigned char flag1; // bit field 275 | unsigned char flag2; // bit field 276 | unsigned char flag3; // bit field 277 | unsigned char encryptedPacket; // kEmptyField, ENCRYPTION_NONE, AES128, AES192, AES256 278 | unsigned char protocolVersion; // always 3 in 2007, 4 in 2011 279 | unsigned char clientType; // always 3 in 2007 and 2008 280 | unsigned int numFields; // number of fields in the command (I could use 2 bytes instead of 4) 281 | unsigned int expandedSize; // if packet is compressed, this is the expanded size of the packet 282 | unsigned int timeout; // timeout value 283 | unsigned short reserved1; // unused in this version 284 | unsigned short reserved2; // unused in this version 285 | } inhead; 286 | 287 | // server -> client header 288 | typedef struct { 289 | unsigned int signature; // PROTOCOL_SIGNATURE defined as 'SQLS' 290 | unsigned int packetSize; // size of the entire packet (header excluded) 291 | unsigned short errorCode; // 0 means no error 292 | unsigned char flag1; // bit field 293 | unsigned char encryptedPacket; // kEmptyField, ENCRYPTION_NONE, AES128, AES192, AES256 294 | unsigned int expandedSize; // if flag1 is COMPRESSED_PACKET this is the expanded size of the entire buffer 295 | unsigned int rows; // number of rows in the cursor 296 | unsigned int cols; // number of columns in the cursor (it could be 2 bytes instead of 4?) 297 | unsigned int numFields; // number of fields in the command (I could use 2 bytes instead of 4) 298 | unsigned short reserved1; // unused in this version 299 | unsigned short reserved2; // unused in this version 300 | } outhead; 301 | 302 | struct csqldb { 303 | int timeout; // timeout used in the socket I/O operations 304 | int sockfd; // the socket 305 | int port; // port used for the connection 306 | char host[512]; // hostname 307 | char username[512]; // username 308 | char password[512]; // password 309 | char errmsg[512]; // last error message 310 | int errcode; // last error code 311 | int useOldProtocol; // flag to set if you want to use the old REALSQLServer protocol 312 | int verifyPeer; // flag to check if peer verification must be performed 313 | int family; 314 | 315 | char *token; // optional token used in token connect 316 | char *hostverification; // optional host verification name to use in SSL peer verification 317 | void *userptr; // optional pointer saved by the user 318 | int encryption; // CUBESQL_ENCRYPTION_NONE - CUBESQL_ENCRYPTION_AES128 319 | // CUBESQL_ENCRYPTION_AES192 - CUBESQL_ENCRYPTION_AES256 320 | 321 | csql_aes_encrypt_ctx encryptkey[1]; // session key used to encrypt data 322 | csql_aes_decrypt_ctx decryptkey[1]; // session key used to decrypt data 323 | 324 | int toread; 325 | char *inbuffer; 326 | int insize; 327 | 328 | inhead request; // request header 329 | outhead reply; // response header 330 | 331 | #ifndef CUBESQL_DISABLE_SSL_ENCRYPTION 332 | struct tls *tls_context; // TLS context connection 333 | #endif 334 | 335 | void (*trace) (const char*, void*); // trace callback 336 | void *data; // user argument to be passed to the callbacks function 337 | }; 338 | 339 | struct csqlvm { 340 | csqldb *db; 341 | int vmindex; 342 | }; 343 | 344 | struct csqlc { 345 | csqldb *db; 346 | int ncols; 347 | int nrows; 348 | int server_side; 349 | int has_rowid; 350 | int eof; 351 | 352 | char *data; 353 | char *names; 354 | char *tables; 355 | int *types; 356 | int *size; 357 | 358 | // reserved 359 | short cursor_id; 360 | int current_row; 361 | int current_buffer; 362 | int data_seek; 363 | int index; 364 | 365 | char *p0; 366 | char *data0; 367 | int *size0; 368 | 369 | char *p; 370 | int *psum; 371 | char **buffer; 372 | int **rowsum; 373 | int *rowcount; 374 | int nbuffer; 375 | int nalloc; 376 | }; 377 | 378 | // private functions 379 | void csql_libinit (void); 380 | csqldb *csql_dbinit (const char *host, int port, const char *username, const char *password, int timeout, int encryption, const char *ssl_certificate, const char *root_certificate, const char *ssl_certificate_password, const char *ssl_chiper_list); 381 | int csql_socketinit (csqldb *db); 382 | void csql_dbfree (csqldb *db); 383 | void csql_socketclose (csqldb *db); 384 | int csql_connect (csqldb *db, int encryption); 385 | int csql_connect_encrypted (csqldb *db); 386 | int csql_netread (csqldb *db, int expected_size, int expected_nfields, int is_chunk, int *end_chunk, int timeout); 387 | csqlc *csql_read_cursor (csqldb *db, csqlc *existing_c); 388 | int csql_checkinbuffer (csqldb *db); 389 | int csql_netwrite (csqldb *db, char *size_array, int nsize_array, char *buffer, int nbuffer); 390 | int csql_ack(csqldb *db, int chunk_code); 391 | int csql_socketwrite (csqldb *db, const char *buffer, int nbuffer); 392 | int csql_socketread (csqldb *db, int is_header, int timeout); 393 | int csql_socketerror (int fd); 394 | int csql_checkheader(csqldb *db, int expected_size, int expected_nfields, int *end_chunk); 395 | int csql_sendchunk (csqldb *db, char *buffer, int bufferlen, int buffertype, int is_bind); 396 | char *csql_receivechunk (csqldb *db, int *len, int *is_end_chunk); 397 | void csql_initrequest (csqldb *db, int packetsize, int nfields, char command, char selector); 398 | void random_hash_field (unsigned char hval[], const char *randpoll, const char *field); 399 | void csql_seterror(csqldb *db, int errcode, const char *errmsg); 400 | int csql_send_statement (csqldb *db, int command_type, const char *sql, int is_partial, int server_side); 401 | void hash_field (unsigned char hval[], const char *field, int len, int times); 402 | void hex_hash_field (char result[], const char *field, int len); 403 | void hex_hash_field2 (char result[], const char *field, unsigned char *randpoll); 404 | int encrypt_buffer (char *buffer, int dim, char random[], csql_aes_encrypt_ctx ctx[1]); 405 | int decrypt_buffer (char *buffer, int dim, csql_aes_decrypt_ctx ctx[1]); 406 | int generate_session_key (csqldb *db, int encryption, char *password, char *rand1, char *rand2); 407 | int csql_bindexecute(csqldb *db, const char *sql, char **colvalue, int *colsize, int *coltype, int ncols); 408 | int csql_bind_value (csqldb *db, int index, int bindtype, char *value, int len); 409 | csqlc *csql_cursor_alloc (csqldb *db); 410 | int csql_cursor_reallocate (csqlc *c); 411 | int csql_cursor_close (csqlc *c); 412 | int csql_cursor_step (csqlc *c); 413 | void csql_load_ssl (void); 414 | const char *ssl_error(void); 415 | int encryption_is_ssl (int encryption); 416 | int wildcmp(const char *wild, const char *string); 417 | 418 | #if defined(__cplusplus) 419 | } 420 | #endif 421 | 422 | #endif 423 | -------------------------------------------------------------------------------- /C_SDK/cubesql.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cubesql.h 3 | * 4 | * This file is the public interface for the CubeSQL Server SDK. 5 | * You just need to include this header file in your projects. 6 | * 7 | * (c) 2006-2023 SQLabs srl -- All Rights Reserved 8 | * Author: Marco Bambini (MB) 9 | * 10 | */ 11 | 12 | #ifndef CUBESQLSDK_H 13 | #define CUBESQLSDK_H 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #ifdef WIN32 20 | #ifdef CUBESQL_EXPORTSDLL 21 | #define CUBESQL_APIEXPORT __declspec(dllexport) 22 | #else 23 | #define CUBESQL_APIEXPORT __declspec(dllimport) 24 | #endif 25 | #else 26 | #define CUBESQL_APIEXPORT 27 | #endif 28 | 29 | #define CUBESQL_SDK_VERSION "060500" // means 6.5.0 30 | 31 | // custom boolean values (C89 doesn't have boolean support) 32 | #ifndef kTRUE 33 | #define kTRUE 1 34 | #endif 35 | 36 | #ifndef kFALSE 37 | #define kFALSE 0 38 | #endif 39 | 40 | // default values 41 | #define CUBESQL_DEFAULT_PORT 4430 42 | #define CUBESQL_DEFAULT_TIMEOUT 12 43 | 44 | // client side error codes 45 | #define CUBESQL_NOERR 0 46 | #define CUBESQL_ERR -1 47 | #define CUBESQL_MEMORY_ERROR -2 48 | #define CUBESQL_PARAMETER_ERROR -3 49 | #define CUBESQL_PROTOCOL_ERROR -4 50 | #define CUBESQL_ZLIB_ERROR -5 51 | #define CUBESQL_SSL_ERROR -6 52 | #define CUBESQL_SSL_CERT_ERROR -7 53 | #define CUBESQL_SSL_DISABLED_ERROR -8 54 | 55 | // encryption flags used in cubesql_connect 56 | #define CUBESQL_ENCRYPTION_NONE 0 57 | #define CUBESQL_ENCRYPTION_AES128 2 58 | #define CUBESQL_ENCRYPTION_AES192 3 59 | #define CUBESQL_ENCRYPTION_AES256 4 60 | #define CUBESQL_ENCRYPTION_SSL 8 61 | #define CUBESQL_ENCRYPTION_SSL_AES128 CUBESQL_ENCRYPTION_SSL+CUBESQL_ENCRYPTION_AES128 62 | #define CUBESQL_ENCRYPTION_SSL_AES192 CUBESQL_ENCRYPTION_SSL+CUBESQL_ENCRYPTION_AES192 63 | #define CUBESQL_ENCRYPTION_SSL_AES256 CUBESQL_ENCRYPTION_SSL+CUBESQL_ENCRYPTION_AES256 64 | 65 | // flag used in cubesql_cursor_getfield 66 | #define CUBESQL_COLNAME 0 67 | #define CUBESQL_CURROW -1 68 | #define CUBESQL_COLTABLE -2 69 | #define CUBESQL_ROWID -666 70 | 71 | // flag used in cubesql_cursor_seek 72 | #define CUBESQL_SEEKNEXT -2 73 | #define CUBESQL_SEEKFIRST -3 74 | #define CUBESQL_SEEKLAST -4 75 | #define CUBESQL_SEEKPREV -5 76 | 77 | #ifndef int64 78 | #ifdef WIN32 79 | typedef __int64 int64; 80 | #else 81 | typedef long long int int64; 82 | #endif 83 | #endif 84 | 85 | // column types coming from the server 86 | enum { 87 | CUBESQL_Type_None = 0, 88 | CUBESQL_Type_Integer = 1, 89 | CUBESQL_Type_Float = 2, 90 | CUBESQL_Type_Text = 3, 91 | CUBESQL_Type_Blob = 4, 92 | CUBESQL_Type_Boolean = 5, 93 | CUBESQL_Type_Date = 6, 94 | CUBESQL_Type_Time = 7, 95 | CUBESQL_Type_Timestamp = 8, 96 | CUBESQL_Type_Currency = 9 97 | }; 98 | 99 | // column types to specify in the cubesql_bind command (coltype) 100 | #define CUBESQL_BIND_INTEGER 1 101 | #define CUBESQL_BIND_DOUBLE 2 102 | #define CUBESQL_BIND_TEXT 3 103 | #define CUBESQL_BIND_BLOB 4 104 | #define CUBESQL_BIND_NULL 5 105 | #define CUBESQL_BIND_INT64 8 106 | #define CUBESQL_BIND_ZEROBLOB 9 107 | 108 | // define opaque datatypes and callbacks 109 | typedef struct csqldb csqldb; 110 | typedef struct csqlc csqlc; 111 | typedef struct csqlvm csqlvm; 112 | typedef void (*cubesql_trace_callback) (const char *, void *); 113 | 114 | // function prototypes 115 | CUBESQL_APIEXPORT const char *cubesql_version (void); 116 | 117 | CUBESQL_APIEXPORT int cubesql_connect (csqldb **db, const char *host, int port, const char *username, const char *password, int timeout, int encryption); 118 | CUBESQL_APIEXPORT int cubesql_connect_ssl (csqldb **db, const char *host, int port, const char *username, const char *password, int timeout, const char *ssl_certificate_path); 119 | CUBESQL_APIEXPORT void cubesql_disconnect (csqldb *db, int gracefully); 120 | CUBESQL_APIEXPORT int cubesql_execute (csqldb *db, const char *sql); 121 | CUBESQL_APIEXPORT csqlc *cubesql_select (csqldb *db, const char *sql, int unused); 122 | CUBESQL_APIEXPORT int cubesql_commit (csqldb *db); 123 | CUBESQL_APIEXPORT int cubesql_rollback (csqldb *db); 124 | CUBESQL_APIEXPORT int cubesql_begintransaction (csqldb *db); 125 | CUBESQL_APIEXPORT int cubesql_bind (csqldb *db, const char *sql, char **colvalue, int *colsize, int *coltype, int ncols); 126 | CUBESQL_APIEXPORT int cubesql_ping (csqldb *db); 127 | CUBESQL_APIEXPORT void cubesql_cancel (csqldb *db); 128 | CUBESQL_APIEXPORT int cubesql_errcode (csqldb *db); 129 | CUBESQL_APIEXPORT char *cubesql_errmsg (csqldb *db); 130 | CUBESQL_APIEXPORT int64 cubesql_changes (csqldb *db); 131 | CUBESQL_APIEXPORT void cubesql_set_trace_callback (csqldb *db, cubesql_trace_callback trace, void *arg); 132 | CUBESQL_APIEXPORT void cubesql_setpath (int type, char *path); 133 | 134 | CUBESQL_APIEXPORT int cubesql_set_database (csqldb *db, const char *dbname); 135 | CUBESQL_APIEXPORT int64 cubesql_affected_rows (csqldb *db); 136 | CUBESQL_APIEXPORT int64 cubesql_last_inserted_rowID (csqldb *db); 137 | CUBESQL_APIEXPORT void cubesql_mssleep (int ms); 138 | 139 | CUBESQL_APIEXPORT int cubesql_send_data (csqldb *db, const char *buffer, int len); 140 | CUBESQL_APIEXPORT int cubesql_send_enddata (csqldb *db); 141 | CUBESQL_APIEXPORT char *cubesql_receive_data (csqldb *db, int *len, int *is_end_chunk); 142 | 143 | CUBESQL_APIEXPORT csqlvm *cubesql_vmprepare (csqldb *db, const char *sql); 144 | CUBESQL_APIEXPORT int cubesql_vmbind_int (csqlvm *vm, int index, int value); 145 | CUBESQL_APIEXPORT int cubesql_vmbind_double (csqlvm *vm, int index, double value); 146 | CUBESQL_APIEXPORT int cubesql_vmbind_text (csqlvm *vm, int index, char *value, int len); 147 | CUBESQL_APIEXPORT int cubesql_vmbind_blob (csqlvm *vm, int index, void *value, int len); 148 | CUBESQL_APIEXPORT int cubesql_vmbind_null (csqlvm *vm, int index); 149 | CUBESQL_APIEXPORT int cubesql_vmbind_int64 (csqlvm *vm, int index, int64 value); 150 | CUBESQL_APIEXPORT int cubesql_vmbind_zeroblob (csqlvm *vm, int index, int len); 151 | CUBESQL_APIEXPORT int cubesql_vmexecute (csqlvm *vm); 152 | CUBESQL_APIEXPORT csqlc *cubesql_vmselect (csqlvm *vm); 153 | CUBESQL_APIEXPORT int cubesql_vmclose (csqlvm *vm); 154 | 155 | CUBESQL_APIEXPORT int cubesql_cursor_numrows (csqlc *c); 156 | CUBESQL_APIEXPORT int cubesql_cursor_numcolumns (csqlc *c); 157 | CUBESQL_APIEXPORT int cubesql_cursor_currentrow (csqlc *c); 158 | CUBESQL_APIEXPORT int cubesql_cursor_seek (csqlc *c, int index); 159 | CUBESQL_APIEXPORT int cubesql_cursor_iseof (csqlc *c); 160 | CUBESQL_APIEXPORT int cubesql_cursor_columntype (csqlc *c, int index); 161 | CUBESQL_APIEXPORT char *cubesql_cursor_field (csqlc *c, int row, int column, int *len); 162 | CUBESQL_APIEXPORT int64 cubesql_cursor_rowid (csqlc *c, int row); 163 | CUBESQL_APIEXPORT int64 cubesql_cursor_int64 (csqlc *c, int row, int column, int64 default_value); 164 | CUBESQL_APIEXPORT int cubesql_cursor_int (csqlc *c, int row, int column, int default_value); 165 | CUBESQL_APIEXPORT double cubesql_cursor_double (csqlc *c, int row, int column, double default_value); 166 | CUBESQL_APIEXPORT char *cubesql_cursor_cstring (csqlc *c, int row, int column); 167 | CUBESQL_APIEXPORT char *cubesql_cursor_cstring_static (csqlc *c, int row, int column, char *static_buffer, int bufferlen); 168 | CUBESQL_APIEXPORT void cubesql_cursor_free (csqlc *c); 169 | 170 | // private functions 171 | int cubesql_connect_token (csqldb **db, const char *host, int port, const char *username, const char *password, 172 | int timeout, int encryption, char *token, int useOldProtocol, const char *ssl_certificate, 173 | const char *root_certificate, const char *ssl_certificate_password, const char *ssl_chiper_list); 174 | int cubesql_connect_old_protocol (csqldb **db, const char *host, int port, const char *username, const char *password, int timeout, int encryption); 175 | void cubesql_clear_errors (csqldb *db); 176 | csqldb *cubesql_cursor_db (csqlc *cursor); 177 | csqlc *cubesql_cursor_create (csqldb *db, int nrows, int ncolumns, int *types, char **names); 178 | int cubesql_cursor_addrow (csqlc *cursor, char **row, int *len); 179 | int cubesql_cursor_columntypebind (csqlc *c, int index); 180 | void cubesql_setuserptr (csqldb *db, void *userptr); 181 | void *cubesql_getuserptr (csqldb *db); 182 | void cubesql_settoken (csqldb *db, char *token); 183 | void cubesql_sethostverification (csqldb *db, char *hostverification); 184 | char *cubesql_gettoken (csqldb *db); 185 | void cubesql_seterror (csqldb *db, int errcode, const char *errmsg); 186 | 187 | const char *cubesql_sslversion (void); 188 | unsigned long cubesql_sslversion_num (void); 189 | 190 | #ifdef __cplusplus 191 | } /* End of the 'extern "C"' block */ 192 | #endif 193 | 194 | #endif 195 | -------------------------------------------------------------------------------- /C_SDK/documentation/style.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | font-family: "Trebuchet MS", Trebuchet, Tahoma, sans-serif; 4 | font-size: 13px; 5 | background-color: #454545; 6 | color: white; 7 | margin: 0px; 8 | } 9 | 10 | h3 { 11 | font-weight: bold; color: #e24628; font-size: 1em; 12 | } 13 | 14 | h4 { 15 | font-weight: bold; color: #e24628; font-size: 1em; 16 | } 17 | 18 | a { 19 | text-decoration: none; 20 | } 21 | 22 | cite { font-style: normal; color: #067e2a; font-weight: bold; } 23 | var { font-style: normal; color: #0a4aa7; font-weight: bold; } 24 | 25 | lcite { font-style: normal; color: #067e2a; font-weight: normal; } 26 | lvar { font-style: normal; color: #0a4aa7; font-weight: normal; } 27 | 28 | 29 | .example cite { font-weight: normal; } 30 | .example var { font-weight: normal; } 31 | 32 | .content { 33 | 34 | background-color: white; 35 | /* color: #3e3e3e */ 36 | color: #4e4e4e; 37 | width: 580px; 38 | /*padding: 30px 50px; */ 39 | padding: 10px 50px 10px 50px; 40 | margin-top: 20px; 41 | margin-left: auto; 42 | margin-right: auto; 43 | 44 | 45 | line-height: 24px; 46 | } 47 | 48 | 49 | .notice { 50 | 51 | background-color: #efefef; 52 | color: #4e4e4e; 53 | width: 630px; 54 | /*padding: 30px 50px; */ 55 | padding: 10px 25px 10px 25px; 56 | margin-top: 20px; 57 | margin-left: auto; 58 | margin-right: auto; 59 | 60 | font-style: italic; 61 | 62 | 63 | line-height: 24px; 64 | } 65 | 66 | .docheader 67 | { 68 | 69 | width: 650px; 70 | padding: 15px; 71 | margin-left: auto; 72 | margin-right: auto; 73 | 74 | background-color: #373737; 75 | 76 | 77 | font-family: "Trebuchet MS", Trebuchet, Tahoma, sans-serif; 78 | font-size: 13px; 79 | text-align: left; 80 | } 81 | 82 | .docheader a:link {color: white; text-decoration: none; } 83 | .docheader a:visited {color: white; text-decoration: none; } 84 | .docheader a:hover {color: white; text-decoration: none; border-bottom: 1px dotted white; } 85 | 86 | em {font-weight: bold; font-style: normal; color: #e24628} 87 | .example em {font-weight: normal;} 88 | 89 | .clearfloat 90 | { 91 | clear: both; 92 | } 93 | 94 | 95 | strong {font-weight: normal; color: #161616} 96 | 97 | .listbox .title 98 | { 99 | border: 1px solid gray; 100 | text-align: center; 101 | font-weight: bold; 102 | padding: 0px 10px; 103 | } 104 | 105 | .listbox .body 106 | { 107 | border-top: 3px solid #e3e3e3; 108 | background-color: #f7f7f7; 109 | padding: 5px 10px; 110 | } 111 | 112 | .listbox 113 | { 114 | font-size: 12px; 115 | } 116 | 117 | .listbox em 118 | { 119 | font-weight: normal; 120 | } 121 | 122 | .listleft 123 | { 124 | margin-right: 30px; 125 | float: left; 126 | } 127 | 128 | .listright 129 | { 130 | margin-left: 30px; 131 | float: right; 132 | } 133 | 134 | .furtherreading 135 | { 136 | font-family: "Lucida Grande", Helvetica, sans-serif; 137 | line-height: 15px; 138 | font-size: 11px; 139 | } 140 | 141 | .furtherreading td.icon 142 | { 143 | width: 15px; 144 | } 145 | 146 | 147 | .furtherreading a:link {color: #4e4e4e; text-decoration: none; border-bottom: 1px dotted gray;} 148 | .furtherreading a:visited {color: #4e4e4e; text-decoration: none; border-bottom: 1px dotted gray;} 149 | .furtherreading a:hover {color: #4e4e4e; color: #e24628} 150 | 151 | 152 | .example 153 | { 154 | display: block; 155 | background-color: #f7f7f7; 156 | padding: 5px 10px; 157 | line-height: 16px; 158 | margin-left: 22px; 159 | border-right: 1px solid gray; 160 | border-bottom: 1px solid gray; 161 | border-top: 1px solid #e8e8e8; 162 | border-left: 1px solid #d3d3d3; 163 | font-family: Monaco, monospace; 164 | font-size: 11px; 165 | white-space: pre; 166 | } 167 | 168 | .filename 169 | { 170 | display: block; 171 | background-color: #e8e8e8; 172 | padding: 5px 10px; 173 | line-height: 12px; 174 | margin-left: 22px; 175 | border-top: 1px solid #d3d3d3; 176 | border-left: 1px solid #d3d3d3; 177 | border-right: 1px solid gray; 178 | border-bottom: 1px solid #a6a6a6; 179 | font-family: "Trebuchet MS", Trebuchet, Tahoma, sans-serif; 180 | font-size: 12px; 181 | color: #383838; 182 | } 183 | 184 | .unixbox 185 | { 186 | width: 400px; 187 | height: 122px; 188 | padding: 40px 39px 30px 25px; 189 | background-image: url("/images/global/terminal-bg.png"); 190 | background-repeat: no-repeat; 191 | font-family: Monaco, monospace; 192 | font-size: 10px; 193 | color: black; 194 | line-height: 14px; 195 | white-space: pre; 196 | 197 | margin-left: auto; 198 | margin-right: auto; 199 | } 200 | 201 | 202 | a:link {color: #e24628} 203 | a:visited {color: #e24628} 204 | a:hover {color: #4e4e4e} 205 | 206 | .listoflinks { line-height: 22px; } 207 | .listoflinks a:link {color: #4e4e4e} 208 | .listoflinks a:visited {color: #4e4e4e} 209 | .listoflinks a:hover {color: #4e4e4e; color: #e24628} 210 | .listoflinks th { text-align: left; padding: 0.75em; } 211 | 212 | 213 | tr.icon { background-color: #f7f7f7; } 214 | tr.icon th { font-weight: normal;} 215 | td.cell1 { background-color: #f0f0f0; } 216 | td.cell2 { background-color: #e6e6e6; } 217 | .codecell { font-family: Monaco, monospace; font-size: 11px; line-height: 20px;} 218 | .codecell cite { font-weight: normal; } 219 | 220 | .content img.title { margin-bottom: 68px; margin-top: 50px; } 221 | 222 | .header 223 | { 224 | font-weight: bold; 225 | } 226 | .pagenumber 227 | { 228 | font-style: italic; 229 | text-align: right; 230 | font-size: 12px; 231 | } 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | .footer 244 | { 245 | background-color: #f7f7f7; 246 | border-top: 1px dashed gray; 247 | margin-top: 65px; 248 | margin-bottom: 0px; 249 | } 250 | 251 | 252 | .extranote 253 | { 254 | font-style: italic; 255 | font-size: 12px; 256 | margin-top: 25px; 257 | margin-left: 22px; 258 | } 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | -------------------------------------------------------------------------------- /C_SDK/zlib/README: -------------------------------------------------------------------------------- 1 | ZLIB DATA COMPRESSION LIBRARY 2 | 3 | zlib 1.2.5 is a general purpose data compression library. All the code is 4 | thread safe. The data format used by the zlib library is described by RFCs 5 | (Request for Comments) 1950 to 1952 in the files 6 | http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) 7 | and rfc1952.txt (gzip format). 8 | 9 | All functions of the compression library are documented in the file zlib.h 10 | (volunteer to write man pages welcome, contact zlib@gzip.org). A usage example 11 | of the library is given in the file example.c which also tests that the library 12 | is working correctly. Another example is given in the file minigzip.c. The 13 | compression library itself is composed of all source files except example.c and 14 | minigzip.c. 15 | 16 | To compile all files and run the test program, follow the instructions given at 17 | the top of Makefile.in. In short "./configure; make test", and if that goes 18 | well, "make install" should work for most flavors of Unix. For Windows, use one 19 | of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use 20 | make_vms.com. 21 | 22 | Questions about zlib should be sent to , or to Gilles Vollant 23 | for the Windows DLL version. The zlib home page is 24 | http://zlib.net/ . Before reporting a problem, please check this site to 25 | verify that you have the latest version of zlib; otherwise get the latest 26 | version and check whether the problem still exists or not. 27 | 28 | PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help. 29 | 30 | Mark Nelson wrote an article about zlib for the Jan. 1997 31 | issue of Dr. Dobb's Journal; a copy of the article is available at 32 | http://marknelson.us/1997/01/01/zlib-engine/ . 33 | 34 | The changes made in version 1.2.5 are documented in the file ChangeLog. 35 | 36 | Unsupported third party contributions are provided in directory contrib/ . 37 | 38 | zlib is available in Java using the java.util.zip package, documented at 39 | http://java.sun.com/developer/technicalArticles/Programming/compression/ . 40 | 41 | A Perl interface to zlib written by Paul Marquess is available 42 | at CPAN (Comprehensive Perl Archive Network) sites, including 43 | http://search.cpan.org/~pmqs/IO-Compress-Zlib/ . 44 | 45 | A Python interface to zlib written by A.M. Kuchling is 46 | available in Python 1.5 and later versions, see 47 | http://www.python.org/doc/lib/module-zlib.html . 48 | 49 | zlib is built into tcl: http://wiki.tcl.tk/4610 . 50 | 51 | An experimental package to read and write files in .zip format, written on top 52 | of zlib by Gilles Vollant , is available in the 53 | contrib/minizip directory of zlib. 54 | 55 | 56 | Notes for some targets: 57 | 58 | - For Windows DLL versions, please see win32/DLL_FAQ.txt 59 | 60 | - For 64-bit Irix, deflate.c must be compiled without any optimization. With 61 | -O, one libpng test fails. The test works in 32 bit mode (with the -n32 62 | compiler flag). The compiler bug has been reported to SGI. 63 | 64 | - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works 65 | when compiled with cc. 66 | 67 | - On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is 68 | necessary to get gzprintf working correctly. This is done by configure. 69 | 70 | - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with 71 | other compilers. Use "make test" to check your compiler. 72 | 73 | - gzdopen is not supported on RISCOS or BEOS. 74 | 75 | - For PalmOs, see http://palmzlib.sourceforge.net/ 76 | 77 | 78 | Acknowledgments: 79 | 80 | The deflate format used by zlib was defined by Phil Katz. The deflate and 81 | zlib specifications were written by L. Peter Deutsch. Thanks to all the 82 | people who reported problems and suggested various improvements in zlib; they 83 | are too numerous to cite here. 84 | 85 | Copyright notice: 86 | 87 | (C) 1995-2010 Jean-loup Gailly and Mark Adler 88 | 89 | This software is provided 'as-is', without any express or implied 90 | warranty. In no event will the authors be held liable for any damages 91 | arising from the use of this software. 92 | 93 | Permission is granted to anyone to use this software for any purpose, 94 | including commercial applications, and to alter it and redistribute it 95 | freely, subject to the following restrictions: 96 | 97 | 1. The origin of this software must not be misrepresented; you must not 98 | claim that you wrote the original software. If you use this software 99 | in a product, an acknowledgment in the product documentation would be 100 | appreciated but is not required. 101 | 2. Altered source versions must be plainly marked as such, and must not be 102 | misrepresented as being the original software. 103 | 3. This notice may not be removed or altered from any source distribution. 104 | 105 | Jean-loup Gailly Mark Adler 106 | jloup@gzip.org madler@alumni.caltech.edu 107 | 108 | If you use the zlib library in a product, we would appreciate *not* receiving 109 | lengthy legal documents to sign. The sources are provided for free but without 110 | warranty of any kind. The library has been entirely written by Jean-loup 111 | Gailly and Mark Adler; it does not include third-party code. 112 | 113 | If you redistribute modified sources, we would appreciate that you include in 114 | the file ChangeLog history information documenting your changes. Please read 115 | the FAQ for more information on the distribution of modified source versions. 116 | -------------------------------------------------------------------------------- /C_SDK/zlib/zconf.h: -------------------------------------------------------------------------------- 1 | /* zconf.h -- configuration of the zlib compression library 2 | * Copyright (C) 1995-2010 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #ifndef ZCONF_H 9 | #define ZCONF_H 10 | 11 | /* 12 | * If you *really* need a unique prefix for all types and library functions, 13 | * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 14 | * Even better than compiling with -DZ_PREFIX would be to use configure to set 15 | * this permanently in zconf.h using "./configure --zprefix". 16 | */ 17 | #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ 18 | 19 | /* all linked symbols */ 20 | # define _dist_code z__dist_code 21 | # define _length_code z__length_code 22 | # define _tr_align z__tr_align 23 | # define _tr_flush_block z__tr_flush_block 24 | # define _tr_init z__tr_init 25 | # define _tr_stored_block z__tr_stored_block 26 | # define _tr_tally z__tr_tally 27 | # define adler32 z_adler32 28 | # define adler32_combine z_adler32_combine 29 | # define adler32_combine64 z_adler32_combine64 30 | # define compress z_compress 31 | # define compress2 z_compress2 32 | # define compressBound z_compressBound 33 | # define crc32 z_crc32 34 | # define crc32_combine z_crc32_combine 35 | # define crc32_combine64 z_crc32_combine64 36 | # define deflate z_deflate 37 | # define deflateBound z_deflateBound 38 | # define deflateCopy z_deflateCopy 39 | # define deflateEnd z_deflateEnd 40 | # define deflateInit2_ z_deflateInit2_ 41 | # define deflateInit_ z_deflateInit_ 42 | # define deflateParams z_deflateParams 43 | # define deflatePrime z_deflatePrime 44 | # define deflateReset z_deflateReset 45 | # define deflateSetDictionary z_deflateSetDictionary 46 | # define deflateSetHeader z_deflateSetHeader 47 | # define deflateTune z_deflateTune 48 | # define deflate_copyright z_deflate_copyright 49 | # define get_crc_table z_get_crc_table 50 | # define gz_error z_gz_error 51 | # define gz_intmax z_gz_intmax 52 | # define gz_strwinerror z_gz_strwinerror 53 | # define gzbuffer z_gzbuffer 54 | # define gzclearerr z_gzclearerr 55 | # define gzclose z_gzclose 56 | # define gzclose_r z_gzclose_r 57 | # define gzclose_w z_gzclose_w 58 | # define gzdirect z_gzdirect 59 | # define gzdopen z_gzdopen 60 | # define gzeof z_gzeof 61 | # define gzerror z_gzerror 62 | # define gzflush z_gzflush 63 | # define gzgetc z_gzgetc 64 | # define gzgets z_gzgets 65 | # define gzoffset z_gzoffset 66 | # define gzoffset64 z_gzoffset64 67 | # define gzopen z_gzopen 68 | # define gzopen64 z_gzopen64 69 | # define gzprintf z_gzprintf 70 | # define gzputc z_gzputc 71 | # define gzputs z_gzputs 72 | # define gzread z_gzread 73 | # define gzrewind z_gzrewind 74 | # define gzseek z_gzseek 75 | # define gzseek64 z_gzseek64 76 | # define gzsetparams z_gzsetparams 77 | # define gztell z_gztell 78 | # define gztell64 z_gztell64 79 | # define gzungetc z_gzungetc 80 | # define gzwrite z_gzwrite 81 | # define inflate z_inflate 82 | # define inflateBack z_inflateBack 83 | # define inflateBackEnd z_inflateBackEnd 84 | # define inflateBackInit_ z_inflateBackInit_ 85 | # define inflateCopy z_inflateCopy 86 | # define inflateEnd z_inflateEnd 87 | # define inflateGetHeader z_inflateGetHeader 88 | # define inflateInit2_ z_inflateInit2_ 89 | # define inflateInit_ z_inflateInit_ 90 | # define inflateMark z_inflateMark 91 | # define inflatePrime z_inflatePrime 92 | # define inflateReset z_inflateReset 93 | # define inflateReset2 z_inflateReset2 94 | # define inflateSetDictionary z_inflateSetDictionary 95 | # define inflateSync z_inflateSync 96 | # define inflateSyncPoint z_inflateSyncPoint 97 | # define inflateUndermine z_inflateUndermine 98 | # define inflate_copyright z_inflate_copyright 99 | # define inflate_fast z_inflate_fast 100 | # define inflate_table z_inflate_table 101 | # define uncompress z_uncompress 102 | # define zError z_zError 103 | # define zcalloc z_zcalloc 104 | # define zcfree z_zcfree 105 | # define zlibCompileFlags z_zlibCompileFlags 106 | # define zlibVersion z_zlibVersion 107 | 108 | /* all zlib typedefs in zlib.h and zconf.h */ 109 | # define Byte z_Byte 110 | # define Bytef z_Bytef 111 | # define alloc_func z_alloc_func 112 | # define charf z_charf 113 | # define free_func z_free_func 114 | # define gzFile z_gzFile 115 | # define gz_header z_gz_header 116 | # define gz_headerp z_gz_headerp 117 | # define in_func z_in_func 118 | # define intf z_intf 119 | # define out_func z_out_func 120 | # define uInt z_uInt 121 | # define uIntf z_uIntf 122 | # define uLong z_uLong 123 | # define uLongf z_uLongf 124 | # define voidp z_voidp 125 | # define voidpc z_voidpc 126 | # define voidpf z_voidpf 127 | 128 | /* all zlib structs in zlib.h and zconf.h */ 129 | # define gz_header_s z_gz_header_s 130 | # define internal_state z_internal_state 131 | 132 | #endif 133 | 134 | #if defined(__MSDOS__) && !defined(MSDOS) 135 | # define MSDOS 136 | #endif 137 | #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) 138 | # define OS2 139 | #endif 140 | #if defined(_WINDOWS) && !defined(WINDOWS) 141 | # define WINDOWS 142 | #endif 143 | #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) 144 | # ifndef WIN32 145 | # define WIN32 146 | # endif 147 | #endif 148 | #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) 149 | # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) 150 | # ifndef SYS16BIT 151 | # define SYS16BIT 152 | # endif 153 | # endif 154 | #endif 155 | 156 | /* 157 | * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 158 | * than 64k bytes at a time (needed on systems with 16-bit int). 159 | */ 160 | #ifdef SYS16BIT 161 | # define MAXSEG_64K 162 | #endif 163 | #ifdef MSDOS 164 | # define UNALIGNED_OK 165 | #endif 166 | 167 | #ifdef __STDC_VERSION__ 168 | # ifndef STDC 169 | # define STDC 170 | # endif 171 | # if __STDC_VERSION__ >= 199901L 172 | # ifndef STDC99 173 | # define STDC99 174 | # endif 175 | # endif 176 | #endif 177 | #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) 178 | # define STDC 179 | #endif 180 | #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) 181 | # define STDC 182 | #endif 183 | #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) 184 | # define STDC 185 | #endif 186 | #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) 187 | # define STDC 188 | #endif 189 | 190 | #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ 191 | # define STDC 192 | #endif 193 | 194 | #ifndef STDC 195 | # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 196 | # define const /* note: need a more gentle solution here */ 197 | # endif 198 | #endif 199 | 200 | /* Some Mac compilers merge all .h files incorrectly: */ 201 | #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) 202 | # define NO_DUMMY_DECL 203 | #endif 204 | 205 | /* Maximum value for memLevel in deflateInit2 */ 206 | #ifndef MAX_MEM_LEVEL 207 | # ifdef MAXSEG_64K 208 | # define MAX_MEM_LEVEL 8 209 | # else 210 | # define MAX_MEM_LEVEL 9 211 | # endif 212 | #endif 213 | 214 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. 215 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files 216 | * created by gzip. (Files created by minigzip can still be extracted by 217 | * gzip.) 218 | */ 219 | #ifndef MAX_WBITS 220 | # define MAX_WBITS 15 /* 32K LZ77 window */ 221 | #endif 222 | 223 | /* The memory requirements for deflate are (in bytes): 224 | (1 << (windowBits+2)) + (1 << (memLevel+9)) 225 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 226 | plus a few kilobytes for small objects. For example, if you want to reduce 227 | the default memory requirements from 256K to 128K, compile with 228 | make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 229 | Of course this will generally degrade compression (there's no free lunch). 230 | 231 | The memory requirements for inflate are (in bytes) 1 << windowBits 232 | that is, 32K for windowBits=15 (default value) plus a few kilobytes 233 | for small objects. 234 | */ 235 | 236 | /* Type declarations */ 237 | 238 | #ifndef OF /* function prototypes */ 239 | # ifdef STDC 240 | # define OF(args) args 241 | # else 242 | # define OF(args) () 243 | # endif 244 | #endif 245 | 246 | /* The following definitions for FAR are needed only for MSDOS mixed 247 | * model programming (small or medium model with some far allocations). 248 | * This was tested only with MSC; for other MSDOS compilers you may have 249 | * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 250 | * just define FAR to be empty. 251 | */ 252 | #ifdef SYS16BIT 253 | # if defined(M_I86SM) || defined(M_I86MM) 254 | /* MSC small or medium model */ 255 | # define SMALL_MEDIUM 256 | # ifdef _MSC_VER 257 | # define FAR _far 258 | # else 259 | # define FAR far 260 | # endif 261 | # endif 262 | # if (defined(__SMALL__) || defined(__MEDIUM__)) 263 | /* Turbo C small or medium model */ 264 | # define SMALL_MEDIUM 265 | # ifdef __BORLANDC__ 266 | # define FAR _far 267 | # else 268 | # define FAR far 269 | # endif 270 | # endif 271 | #endif 272 | 273 | #if defined(WINDOWS) || defined(WIN32) 274 | /* If building or using zlib as a DLL, define ZLIB_DLL. 275 | * This is not mandatory, but it offers a little performance increase. 276 | */ 277 | # ifdef ZLIB_DLL 278 | # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) 279 | # ifdef ZLIB_INTERNAL 280 | # define ZEXTERN extern __declspec(dllexport) 281 | # else 282 | # define ZEXTERN extern __declspec(dllimport) 283 | # endif 284 | # endif 285 | # endif /* ZLIB_DLL */ 286 | /* If building or using zlib with the WINAPI/WINAPIV calling convention, 287 | * define ZLIB_WINAPI. 288 | * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. 289 | */ 290 | # ifdef ZLIB_WINAPI 291 | # ifdef FAR 292 | # undef FAR 293 | # endif 294 | # include 295 | /* No need for _export, use ZLIB.DEF instead. */ 296 | /* For complete Windows compatibility, use WINAPI, not __stdcall. */ 297 | # define ZEXPORT WINAPI 298 | # ifdef WIN32 299 | # define ZEXPORTVA WINAPIV 300 | # else 301 | # define ZEXPORTVA FAR CDECL 302 | # endif 303 | # endif 304 | #endif 305 | 306 | #if defined (__BEOS__) 307 | # ifdef ZLIB_DLL 308 | # ifdef ZLIB_INTERNAL 309 | # define ZEXPORT __declspec(dllexport) 310 | # define ZEXPORTVA __declspec(dllexport) 311 | # else 312 | # define ZEXPORT __declspec(dllimport) 313 | # define ZEXPORTVA __declspec(dllimport) 314 | # endif 315 | # endif 316 | #endif 317 | 318 | #ifndef ZEXTERN 319 | # define ZEXTERN extern 320 | #endif 321 | #ifndef ZEXPORT 322 | # define ZEXPORT 323 | #endif 324 | #ifndef ZEXPORTVA 325 | # define ZEXPORTVA 326 | #endif 327 | 328 | #ifndef FAR 329 | # define FAR 330 | #endif 331 | 332 | #if !defined(__MACTYPES__) 333 | typedef unsigned char Byte; /* 8 bits */ 334 | #endif 335 | typedef unsigned int uInt; /* 16 bits or more */ 336 | typedef unsigned long uLong; /* 32 bits or more */ 337 | 338 | #ifdef SMALL_MEDIUM 339 | /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ 340 | # define Bytef Byte FAR 341 | #else 342 | typedef Byte FAR Bytef; 343 | #endif 344 | typedef char FAR charf; 345 | typedef int FAR intf; 346 | typedef uInt FAR uIntf; 347 | typedef uLong FAR uLongf; 348 | 349 | #ifdef STDC 350 | typedef void const *voidpc; 351 | typedef void FAR *voidpf; 352 | typedef void *voidp; 353 | #else 354 | typedef Byte const *voidpc; 355 | typedef Byte FAR *voidpf; 356 | typedef Byte *voidp; 357 | #endif 358 | 359 | #ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ 360 | # define Z_HAVE_UNISTD_H 361 | #endif 362 | 363 | #ifdef STDC 364 | # include /* for off_t */ 365 | #endif 366 | 367 | /* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and 368 | * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even 369 | * though the former does not conform to the LFS document), but considering 370 | * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as 371 | * equivalently requesting no 64-bit operations 372 | */ 373 | #if -_LARGEFILE64_SOURCE - -1 == 1 374 | # undef _LARGEFILE64_SOURCE 375 | #endif 376 | 377 | #if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) 378 | # include /* for SEEK_* and off_t */ 379 | # ifdef VMS 380 | # include /* for off_t */ 381 | # endif 382 | # ifndef z_off_t 383 | # define z_off_t off_t 384 | # endif 385 | #endif 386 | 387 | #ifndef SEEK_SET 388 | # define SEEK_SET 0 /* Seek from beginning of file. */ 389 | # define SEEK_CUR 1 /* Seek from current position. */ 390 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 391 | #endif 392 | 393 | #ifndef z_off_t 394 | # define z_off_t long 395 | #endif 396 | 397 | #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 398 | # define z_off64_t off64_t 399 | #else 400 | # define z_off64_t z_off_t 401 | #endif 402 | 403 | #if defined(__OS400__) 404 | # define NO_vsnprintf 405 | #endif 406 | 407 | #if defined(__MVS__) 408 | # define NO_vsnprintf 409 | #endif 410 | 411 | /* MVS linker does not support external names larger than 8 bytes */ 412 | #if defined(__MVS__) 413 | #pragma map(deflateInit_,"DEIN") 414 | #pragma map(deflateInit2_,"DEIN2") 415 | #pragma map(deflateEnd,"DEEND") 416 | #pragma map(deflateBound,"DEBND") 417 | #pragma map(inflateInit_,"ININ") 418 | #pragma map(inflateInit2_,"ININ2") 419 | #pragma map(inflateEnd,"INEND") 420 | #pragma map(inflateSync,"INSY") 421 | #pragma map(inflateSetDictionary,"INSEDI") 422 | #pragma map(compressBound,"CMBND") 423 | #pragma map(inflate_table,"INTABL") 424 | #pragma map(inflate_fast,"INFA") 425 | #pragma map(inflate_copyright,"INCOPY") 426 | #endif 427 | 428 | #endif /* ZCONF_H */ 429 | -------------------------------------------------------------------------------- /Internals/TestTLS/OpenSSL.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A9DB49A32209C59200C0E3F1 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = A9DB49A22209C59200C0E3F1 /* main.c */; }; 11 | A9DB49D22209C93400C0E3F1 /* cubesql.c in Sources */ = {isa = PBXBuildFile; fileRef = A9DB49AA2209C5C500C0E3F1 /* cubesql.c */; }; 12 | A9DB49D32209C93A00C0E3F1 /* aeskey.c in Sources */ = {isa = PBXBuildFile; fileRef = A9DB49AC2209C5C500C0E3F1 /* aeskey.c */; }; 13 | A9DB49D42209C93D00C0E3F1 /* aescrypt.c in Sources */ = {isa = PBXBuildFile; fileRef = A9DB49B02209C5C500C0E3F1 /* aescrypt.c */; }; 14 | A9DB49D52209C94000C0E3F1 /* sha1.c in Sources */ = {isa = PBXBuildFile; fileRef = A9DB49B22209C5C500C0E3F1 /* sha1.c */; }; 15 | A9DB49D62209C94200C0E3F1 /* pseudorandom.c in Sources */ = {isa = PBXBuildFile; fileRef = A9DB49B32209C5C500C0E3F1 /* pseudorandom.c */; }; 16 | A9DB49D72209C94400C0E3F1 /* base64.c in Sources */ = {isa = PBXBuildFile; fileRef = A9DB49B52209C5C500C0E3F1 /* base64.c */; }; 17 | A9DB49D82209C94700C0E3F1 /* aestab.c in Sources */ = {isa = PBXBuildFile; fileRef = A9DB49B62209C5C500C0E3F1 /* aestab.c */; }; 18 | A9DFF2F82B3DA8FC00CAD971 /* libtls.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A9DFF2F72B3DA8FC00CAD971 /* libtls.a */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXCopyFilesBuildPhase section */ 22 | A9DB499D2209C59200C0E3F1 /* CopyFiles */ = { 23 | isa = PBXCopyFilesBuildPhase; 24 | buildActionMask = 2147483647; 25 | dstPath = /usr/share/man/man1/; 26 | dstSubfolderSpec = 0; 27 | files = ( 28 | ); 29 | runOnlyForDeploymentPostprocessing = 1; 30 | }; 31 | /* End PBXCopyFilesBuildPhase section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | A9DB499F2209C59200C0E3F1 /* OpenSSL */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = OpenSSL; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | A9DB49A22209C59200C0E3F1 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; 36 | A9DB49AA2209C5C500C0E3F1 /* cubesql.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = cubesql.c; sourceTree = ""; }; 37 | A9DB49AC2209C5C500C0E3F1 /* aeskey.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = aeskey.c; sourceTree = ""; }; 38 | A9DB49AD2209C5C500C0E3F1 /* pseudorandom.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = pseudorandom.h; sourceTree = ""; }; 39 | A9DB49AE2209C5C500C0E3F1 /* aestab.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = aestab.h; sourceTree = ""; }; 40 | A9DB49AF2209C5C500C0E3F1 /* base64.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = base64.h; sourceTree = ""; }; 41 | A9DB49B02209C5C500C0E3F1 /* aescrypt.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = aescrypt.c; sourceTree = ""; }; 42 | A9DB49B12209C5C500C0E3F1 /* aesopt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = aesopt.h; sourceTree = ""; }; 43 | A9DB49B22209C5C500C0E3F1 /* sha1.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = sha1.c; sourceTree = ""; }; 44 | A9DB49B32209C5C500C0E3F1 /* pseudorandom.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = pseudorandom.c; sourceTree = ""; }; 45 | A9DB49B42209C5C500C0E3F1 /* aes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = aes.h; sourceTree = ""; }; 46 | A9DB49B52209C5C500C0E3F1 /* base64.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = base64.c; sourceTree = ""; }; 47 | A9DB49B62209C5C500C0E3F1 /* aestab.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = aestab.c; sourceTree = ""; }; 48 | A9DB49B72209C5C500C0E3F1 /* sha1.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = sha1.h; sourceTree = ""; }; 49 | A9DB49B82209C5C500C0E3F1 /* csql.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = csql.h; sourceTree = ""; }; 50 | A9DB49BE2209C5C500C0E3F1 /* cubesql.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cubesql.h; sourceTree = ""; }; 51 | A9DFF2F72B3DA8FC00CAD971 /* libtls.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtls.a; path = ../libs/macOS/libtls.a; sourceTree = ""; }; 52 | /* End PBXFileReference section */ 53 | 54 | /* Begin PBXFrameworksBuildPhase section */ 55 | A9DB499C2209C59200C0E3F1 /* Frameworks */ = { 56 | isa = PBXFrameworksBuildPhase; 57 | buildActionMask = 2147483647; 58 | files = ( 59 | A9DFF2F82B3DA8FC00CAD971 /* libtls.a in Frameworks */, 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | /* End PBXFrameworksBuildPhase section */ 64 | 65 | /* Begin PBXGroup section */ 66 | A9DB49962209C59200C0E3F1 = { 67 | isa = PBXGroup; 68 | children = ( 69 | A9DB49A12209C59200C0E3F1 /* OpenSSL */, 70 | A9DB49A02209C59200C0E3F1 /* Products */, 71 | ); 72 | sourceTree = ""; 73 | }; 74 | A9DB49A02209C59200C0E3F1 /* Products */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | A9DB499F2209C59200C0E3F1 /* OpenSSL */, 78 | ); 79 | name = Products; 80 | sourceTree = ""; 81 | }; 82 | A9DB49A12209C59200C0E3F1 /* OpenSSL */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | A9DB49A22209C59200C0E3F1 /* main.c */, 86 | A9DB49A92209C5C500C0E3F1 /* C_SDK */, 87 | ); 88 | path = OpenSSL; 89 | sourceTree = ""; 90 | }; 91 | A9DB49A92209C5C500C0E3F1 /* C_SDK */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | A9DFF2F72B3DA8FC00CAD971 /* libtls.a */, 95 | A9DB49AA2209C5C500C0E3F1 /* cubesql.c */, 96 | A9DB49BE2209C5C500C0E3F1 /* cubesql.h */, 97 | A9DB49B82209C5C500C0E3F1 /* csql.h */, 98 | A9DB49AB2209C5C500C0E3F1 /* crypt */, 99 | ); 100 | name = C_SDK; 101 | path = ../../../C_SDK; 102 | sourceTree = ""; 103 | }; 104 | A9DB49AB2209C5C500C0E3F1 /* crypt */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | A9DB49AC2209C5C500C0E3F1 /* aeskey.c */, 108 | A9DB49AD2209C5C500C0E3F1 /* pseudorandom.h */, 109 | A9DB49AE2209C5C500C0E3F1 /* aestab.h */, 110 | A9DB49AF2209C5C500C0E3F1 /* base64.h */, 111 | A9DB49B02209C5C500C0E3F1 /* aescrypt.c */, 112 | A9DB49B12209C5C500C0E3F1 /* aesopt.h */, 113 | A9DB49B22209C5C500C0E3F1 /* sha1.c */, 114 | A9DB49B32209C5C500C0E3F1 /* pseudorandom.c */, 115 | A9DB49B42209C5C500C0E3F1 /* aes.h */, 116 | A9DB49B52209C5C500C0E3F1 /* base64.c */, 117 | A9DB49B62209C5C500C0E3F1 /* aestab.c */, 118 | A9DB49B72209C5C500C0E3F1 /* sha1.h */, 119 | ); 120 | path = crypt; 121 | sourceTree = ""; 122 | }; 123 | /* End PBXGroup section */ 124 | 125 | /* Begin PBXNativeTarget section */ 126 | A9DB499E2209C59200C0E3F1 /* OpenSSL */ = { 127 | isa = PBXNativeTarget; 128 | buildConfigurationList = A9DB49A62209C59200C0E3F1 /* Build configuration list for PBXNativeTarget "OpenSSL" */; 129 | buildPhases = ( 130 | A9DB499B2209C59200C0E3F1 /* Sources */, 131 | A9DB499C2209C59200C0E3F1 /* Frameworks */, 132 | A9DB499D2209C59200C0E3F1 /* CopyFiles */, 133 | ); 134 | buildRules = ( 135 | ); 136 | dependencies = ( 137 | ); 138 | name = OpenSSL; 139 | productName = OpenSSL; 140 | productReference = A9DB499F2209C59200C0E3F1 /* OpenSSL */; 141 | productType = "com.apple.product-type.tool"; 142 | }; 143 | /* End PBXNativeTarget section */ 144 | 145 | /* Begin PBXProject section */ 146 | A9DB49972209C59200C0E3F1 /* Project object */ = { 147 | isa = PBXProject; 148 | attributes = { 149 | LastUpgradeCheck = 1120; 150 | ORGANIZATIONNAME = SQLabs; 151 | TargetAttributes = { 152 | A9DB499E2209C59200C0E3F1 = { 153 | CreatedOnToolsVersion = 10.1; 154 | }; 155 | }; 156 | }; 157 | buildConfigurationList = A9DB499A2209C59200C0E3F1 /* Build configuration list for PBXProject "OpenSSL" */; 158 | compatibilityVersion = "Xcode 9.3"; 159 | developmentRegion = en; 160 | hasScannedForEncodings = 0; 161 | knownRegions = ( 162 | en, 163 | Base, 164 | ); 165 | mainGroup = A9DB49962209C59200C0E3F1; 166 | productRefGroup = A9DB49A02209C59200C0E3F1 /* Products */; 167 | projectDirPath = ""; 168 | projectRoot = ""; 169 | targets = ( 170 | A9DB499E2209C59200C0E3F1 /* OpenSSL */, 171 | ); 172 | }; 173 | /* End PBXProject section */ 174 | 175 | /* Begin PBXSourcesBuildPhase section */ 176 | A9DB499B2209C59200C0E3F1 /* Sources */ = { 177 | isa = PBXSourcesBuildPhase; 178 | buildActionMask = 2147483647; 179 | files = ( 180 | A9DB49D52209C94000C0E3F1 /* sha1.c in Sources */, 181 | A9DB49D82209C94700C0E3F1 /* aestab.c in Sources */, 182 | A9DB49D32209C93A00C0E3F1 /* aeskey.c in Sources */, 183 | A9DB49D72209C94400C0E3F1 /* base64.c in Sources */, 184 | A9DB49D62209C94200C0E3F1 /* pseudorandom.c in Sources */, 185 | A9DB49A32209C59200C0E3F1 /* main.c in Sources */, 186 | A9DB49D42209C93D00C0E3F1 /* aescrypt.c in Sources */, 187 | A9DB49D22209C93400C0E3F1 /* cubesql.c in Sources */, 188 | ); 189 | runOnlyForDeploymentPostprocessing = 0; 190 | }; 191 | /* End PBXSourcesBuildPhase section */ 192 | 193 | /* Begin XCBuildConfiguration section */ 194 | A9DB49A42209C59200C0E3F1 /* Debug */ = { 195 | isa = XCBuildConfiguration; 196 | buildSettings = { 197 | ALWAYS_SEARCH_USER_PATHS = NO; 198 | CLANG_ANALYZER_NONNULL = YES; 199 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 200 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 201 | CLANG_CXX_LIBRARY = "libc++"; 202 | CLANG_ENABLE_MODULES = YES; 203 | CLANG_ENABLE_OBJC_ARC = YES; 204 | CLANG_ENABLE_OBJC_WEAK = YES; 205 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 206 | CLANG_WARN_BOOL_CONVERSION = YES; 207 | CLANG_WARN_COMMA = YES; 208 | CLANG_WARN_CONSTANT_CONVERSION = YES; 209 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 210 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 211 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 212 | CLANG_WARN_EMPTY_BODY = YES; 213 | CLANG_WARN_ENUM_CONVERSION = YES; 214 | CLANG_WARN_INFINITE_RECURSION = YES; 215 | CLANG_WARN_INT_CONVERSION = YES; 216 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 217 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 218 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 219 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 220 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 221 | CLANG_WARN_STRICT_PROTOTYPES = YES; 222 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 223 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 224 | CLANG_WARN_UNREACHABLE_CODE = YES; 225 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 226 | CODE_SIGN_IDENTITY = "Mac Developer"; 227 | COPY_PHASE_STRIP = NO; 228 | DEBUG_INFORMATION_FORMAT = dwarf; 229 | ENABLE_STRICT_OBJC_MSGSEND = YES; 230 | ENABLE_TESTABILITY = YES; 231 | GCC_C_LANGUAGE_STANDARD = gnu11; 232 | GCC_DYNAMIC_NO_PIC = NO; 233 | GCC_NO_COMMON_BLOCKS = YES; 234 | GCC_OPTIMIZATION_LEVEL = 0; 235 | GCC_PREPROCESSOR_DEFINITIONS = ( 236 | "DEBUG=1", 237 | "$(inherited)", 238 | ); 239 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 240 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 241 | GCC_WARN_UNDECLARED_SELECTOR = YES; 242 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 243 | GCC_WARN_UNUSED_FUNCTION = YES; 244 | GCC_WARN_UNUSED_VARIABLE = YES; 245 | MACOSX_DEPLOYMENT_TARGET = 10.14; 246 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 247 | MTL_FAST_MATH = YES; 248 | ONLY_ACTIVE_ARCH = YES; 249 | SDKROOT = macosx; 250 | }; 251 | name = Debug; 252 | }; 253 | A9DB49A52209C59200C0E3F1 /* Release */ = { 254 | isa = XCBuildConfiguration; 255 | buildSettings = { 256 | ALWAYS_SEARCH_USER_PATHS = NO; 257 | CLANG_ANALYZER_NONNULL = YES; 258 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 259 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 260 | CLANG_CXX_LIBRARY = "libc++"; 261 | CLANG_ENABLE_MODULES = YES; 262 | CLANG_ENABLE_OBJC_ARC = YES; 263 | CLANG_ENABLE_OBJC_WEAK = YES; 264 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 265 | CLANG_WARN_BOOL_CONVERSION = YES; 266 | CLANG_WARN_COMMA = YES; 267 | CLANG_WARN_CONSTANT_CONVERSION = YES; 268 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 269 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 270 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 271 | CLANG_WARN_EMPTY_BODY = YES; 272 | CLANG_WARN_ENUM_CONVERSION = YES; 273 | CLANG_WARN_INFINITE_RECURSION = YES; 274 | CLANG_WARN_INT_CONVERSION = YES; 275 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 276 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 277 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 278 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 279 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 280 | CLANG_WARN_STRICT_PROTOTYPES = YES; 281 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 282 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 283 | CLANG_WARN_UNREACHABLE_CODE = YES; 284 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 285 | CODE_SIGN_IDENTITY = "Mac Developer"; 286 | COPY_PHASE_STRIP = NO; 287 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 288 | ENABLE_NS_ASSERTIONS = NO; 289 | ENABLE_STRICT_OBJC_MSGSEND = YES; 290 | GCC_C_LANGUAGE_STANDARD = gnu11; 291 | GCC_NO_COMMON_BLOCKS = YES; 292 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 293 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 294 | GCC_WARN_UNDECLARED_SELECTOR = YES; 295 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 296 | GCC_WARN_UNUSED_FUNCTION = YES; 297 | GCC_WARN_UNUSED_VARIABLE = YES; 298 | MACOSX_DEPLOYMENT_TARGET = 10.14; 299 | MTL_ENABLE_DEBUG_INFO = NO; 300 | MTL_FAST_MATH = YES; 301 | SDKROOT = macosx; 302 | }; 303 | name = Release; 304 | }; 305 | A9DB49A72209C59200C0E3F1 /* Debug */ = { 306 | isa = XCBuildConfiguration; 307 | buildSettings = { 308 | CODE_SIGN_STYLE = Automatic; 309 | DEVELOPMENT_TEAM = 3ZH6236ET5; 310 | GCC_PREPROCESSOR_DEFINITIONS = ( 311 | "DEBUG=1", 312 | "$(inherited)", 313 | ); 314 | HEADER_SEARCH_PATHS = ( 315 | "\"$(SRCROOT)/../../C_SDK/crypt\"", 316 | "\"$(SRCROOT)/../../C_SDK\"", 317 | ); 318 | LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/../../libs/macOS\""; 319 | OTHER_LDFLAGS = "-lz"; 320 | PRODUCT_NAME = "$(TARGET_NAME)"; 321 | }; 322 | name = Debug; 323 | }; 324 | A9DB49A82209C59200C0E3F1 /* Release */ = { 325 | isa = XCBuildConfiguration; 326 | buildSettings = { 327 | CODE_SIGN_STYLE = Automatic; 328 | DEVELOPMENT_TEAM = 3ZH6236ET5; 329 | HEADER_SEARCH_PATHS = ( 330 | "\"$(SRCROOT)/../../C_SDK/crypt\"", 331 | "\"$(SRCROOT)/../../C_SDK\"", 332 | ); 333 | LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/../../libs/macOS\""; 334 | OTHER_LDFLAGS = "-lz"; 335 | PRODUCT_NAME = "$(TARGET_NAME)"; 336 | }; 337 | name = Release; 338 | }; 339 | /* End XCBuildConfiguration section */ 340 | 341 | /* Begin XCConfigurationList section */ 342 | A9DB499A2209C59200C0E3F1 /* Build configuration list for PBXProject "OpenSSL" */ = { 343 | isa = XCConfigurationList; 344 | buildConfigurations = ( 345 | A9DB49A42209C59200C0E3F1 /* Debug */, 346 | A9DB49A52209C59200C0E3F1 /* Release */, 347 | ); 348 | defaultConfigurationIsVisible = 0; 349 | defaultConfigurationName = Release; 350 | }; 351 | A9DB49A62209C59200C0E3F1 /* Build configuration list for PBXNativeTarget "OpenSSL" */ = { 352 | isa = XCConfigurationList; 353 | buildConfigurations = ( 354 | A9DB49A72209C59200C0E3F1 /* Debug */, 355 | A9DB49A82209C59200C0E3F1 /* Release */, 356 | ); 357 | defaultConfigurationIsVisible = 0; 358 | defaultConfigurationName = Release; 359 | }; 360 | /* End XCConfigurationList section */ 361 | }; 362 | rootObject = A9DB49972209C59200C0E3F1 /* Project object */; 363 | } 364 | -------------------------------------------------------------------------------- /Internals/TestTLS/OpenSSL/main.c: -------------------------------------------------------------------------------- 1 | // 2 | // main.c 3 | // OpenSSL 4 | // 5 | // Created by Marco Bambini on 05/02/2019. 6 | // Copyright © 2019 SQLabs. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "cubesql.h" 14 | 15 | #define HOSTNAME "localhost" 16 | #define USERNAME "admin" 17 | #define PASSWORD "admin" 18 | 19 | void do_test (csqldb *db); 20 | void print_cursor(csqlc *c); 21 | 22 | void do_print_ssl (void) { 23 | printf("SSL: %s\n", cubesql_sslversion()); 24 | printf("SSL num: %X\n\n", (unsigned int) cubesql_sslversion_num()); 25 | } 26 | 27 | void do_test (csqldb *db) { 28 | 29 | int err = 0; 30 | csqlc *c = NULL; 31 | 32 | // create db 33 | err = cubesql_execute(db, "CREATE DATABASE mytestdb.sqlite IF NOT EXISTS;"); 34 | if (err != CUBESQL_NOERR) goto abort; 35 | 36 | // set current db 37 | err = cubesql_execute(db, "USE DATABASE mytestdb.sqlite;"); 38 | if (err != CUBESQL_NOERR) goto abort; 39 | 40 | // create table 41 | err = cubesql_execute(db, "CREATE TABLE IF NOT EXISTS foo (id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT, col2 TEXT, col3 INTEGER);"); 42 | if (err != CUBESQL_NOERR) goto abort; 43 | 44 | // insert a couple records 45 | err = cubesql_execute(db, "INSERT INTO foo (col1, col2, col3) VALUES ('test1', 'test2', 13);"); 46 | err = cubesql_execute(db, "INSERT INTO foo (col1, col2, col3) VALUES ('test3', 'test4', 17);"); 47 | err = cubesql_execute(db, "INSERT INTO foo (col1, col2, col3) VALUES ('test5', 'test6', 19);"); 48 | err = cubesql_execute(db, "INSERT INTO foo (col1, col2, col3) VALUES ('test7', 'test8', 23);"); 49 | 50 | // commit current transaction 51 | err = cubesql_commit(db); 52 | 53 | // perform a simple select statement 54 | c = cubesql_select(db, "SELECT * FROM foo;", kFALSE); 55 | if (c == NULL) goto abort; 56 | print_cursor(c); 57 | cubesql_cursor_free(c); 58 | 59 | return; 60 | 61 | abort: 62 | printf("An error occured in do_test: %s (errocode %d)", cubesql_errmsg(db), cubesql_errcode(db)); 63 | return; 64 | } 65 | 66 | void print_cursor(csqlc *c) { 67 | int i, nrows, ncols, len; 68 | char *s, b[512]; 69 | 70 | if (c == NULL) return; 71 | 72 | nrows = cubesql_cursor_numrows(c); 73 | ncols = cubesql_cursor_numcolumns(c); 74 | printf("Record set contains\nrows: %d\ncolumns: %d\n\n", nrows, ncols); 75 | 76 | // print column's names 77 | for (i=1; i<=ncols; i++) { 78 | s = cubesql_cursor_field(c, CUBESQL_COLNAME, i, &len); 79 | printf("%s\t\t", s); 80 | } 81 | 82 | // print a separator 83 | printf("\n"); 84 | for (i=1; i<=70; i++) printf("-"); 85 | printf("\n"); 86 | 87 | // print data using the EOF property (safe for both server side and client side cursors) 88 | while (cubesql_cursor_iseof(c) != kTRUE) { 89 | for (i=1; i<=ncols; i++) { 90 | s = cubesql_cursor_cstring_static(c, CUBESQL_CURROW, i, b, sizeof(b)); 91 | printf("%s\t\t", s); 92 | } 93 | 94 | cubesql_cursor_seek(c, CUBESQL_SEEKNEXT); 95 | printf("\n"); 96 | } 97 | printf("\n"); 98 | } 99 | 100 | int do_test_clear (void) { 101 | csqldb *db = NULL; 102 | 103 | if (cubesql_connect(&db, HOSTNAME, CUBESQL_DEFAULT_PORT, USERNAME, PASSWORD, CUBESQL_DEFAULT_TIMEOUT, CUBESQL_ENCRYPTION_NONE) != CUBESQL_NOERR) goto abort; 104 | 105 | do_test(db); 106 | 107 | // disconnect 108 | cubesql_disconnect(db, kTRUE); 109 | return 0; 110 | 111 | abort: 112 | do_print_ssl(); 113 | if (db) { 114 | printf("error %d in cubesql_connect: %s\n", cubesql_errcode(db), cubesql_errmsg(db)); 115 | cubesql_disconnect(db, kFALSE); 116 | } 117 | return -1; 118 | } 119 | 120 | int do_test_tls (const char *rootCAFile) { 121 | csqldb *db = NULL; 122 | 123 | do_print_ssl(); 124 | if (cubesql_connect_token(&db, HOSTNAME, CUBESQL_DEFAULT_PORT, USERNAME, PASSWORD, CUBESQL_DEFAULT_TIMEOUT, CUBESQL_ENCRYPTION_SSL, NULL, kFALSE, NULL, rootCAFile, NULL, NULL) != CUBESQL_NOERR) goto abort; 125 | 126 | do_test(db); 127 | 128 | // disconnect 129 | cubesql_disconnect(db, kTRUE); 130 | return 0; 131 | 132 | abort: 133 | do_print_ssl(); 134 | if (db) { 135 | printf("error %d in cubesql_connect: %s\n", cubesql_errcode(db), cubesql_errmsg(db)); 136 | cubesql_disconnect(db, kFALSE); 137 | } 138 | return -1; 139 | } 140 | 141 | 142 | int main(int argc, const char * argv[]) { 143 | do_test_clear(); 144 | do_test_tls(argv[1]); 145 | 146 | return 0; 147 | } 148 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2018 SQLabs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ObjC/CubeSQLObjC.h: -------------------------------------------------------------------------------- 1 | // 2 | // CubeSQL.h 3 | // 4 | // 5 | // Created by Marco Bambini on 10/4/11. 6 | // Copyright 2011-2019 SQLabs. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "cubesql.h" 11 | 12 | @interface CubeSQLCursor : NSObject 13 | 14 | - (id) initWithCursor:(csqlc *)p; 15 | - (int) numRows; 16 | - (int) numColumns; 17 | - (int) currentRow; 18 | - (int) seek:(int)index; 19 | - (BOOL) isEOF; 20 | - (int) columnType:(int)index; 21 | - (char *) nativeType:(int)row column:(int)column len:(int *)len; 22 | - (int64) rowid:(int)row; 23 | - (int64) int64Type:(int)row column:(int)column defaultValue:(int64)defaultValue; 24 | - (int) intType:(int)row column:(int)column defaultValue:(int)defaultValue; 25 | - (double) doubleType:(int)row column:(int)column defaultValue:(double)defaultValue; 26 | - (NSString *) stringValue:(int)row column:(int)column; 27 | - (NSData *) blobValue:(int)row column:(int)column; 28 | - (BOOL) isNULLValue:(int)row column:(int)column; 29 | 30 | @end 31 | 32 | 33 | @interface CubeSQLVM : NSObject 34 | 35 | - (id) initWithVM:(csqlvm *)p; 36 | - (int) bindInt:(int)index value:(int)value; 37 | - (int) bindDouble:(int)index value:(double)value; 38 | - (int) bindText:(int)index value:(NSString *)value; 39 | - (int) bindBlob:(int)index value:(void *)value len:(int)len; 40 | - (int) bindNull:(int)index; 41 | - (int) bindInt64:(int)index value:(int64)value; 42 | - (int) bindZeroBlob:(int)index value:(int)len; 43 | - (int) execute; 44 | - (CubeSQLCursor *) select; 45 | 46 | @end 47 | 48 | 49 | @interface CubeSQL : NSObject 50 | 51 | @property (copy) NSString *hostname; 52 | @property (copy) NSString *username; 53 | @property (copy) NSString *password; 54 | @property (copy) NSString *token; 55 | @property (copy) NSString *ssl_certificate; 56 | @property (assign) int port; 57 | @property (assign) int timeout; 58 | @property (assign) int encryption; 59 | @property (nonatomic, readonly) csqldb *ref; 60 | 61 | - (int) connect; 62 | - (void) disconnect; 63 | - (int) sqlExecute:(NSString *)sql; 64 | - (CubeSQLCursor *) sqlSelect:(NSString *)sql; 65 | - (CubeSQLVM *) vmPrepare:(NSString *)sql; 66 | - (int) commit; 67 | - (int) rollback; 68 | - (int) ping; 69 | - (int64) changes; 70 | - (int) errorCode; 71 | - (NSString *) errorMessage; 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /ObjC/CubeSQLObjc.m: -------------------------------------------------------------------------------- 1 | // 2 | // CubeSQL.m 3 | // 4 | // 5 | // Created by Marco Bambini on 10/4/11. 6 | // Copyright 2011-2019 SQLabs. All rights reserved. 7 | // 8 | 9 | #import "CubeSQLObjC.h" 10 | 11 | @interface CubeSQL() { 12 | csqldb *db; 13 | } 14 | @end 15 | 16 | @implementation CubeSQL 17 | 18 | @synthesize hostname; 19 | @synthesize username; 20 | @synthesize password; 21 | @synthesize token; 22 | @synthesize port; 23 | @synthesize timeout; 24 | @synthesize encryption; 25 | @synthesize ssl_certificate; 26 | 27 | - (id) init { 28 | if (self = [super init]) { 29 | db = NULL; 30 | port = CUBESQL_DEFAULT_PORT; 31 | timeout = CUBESQL_DEFAULT_TIMEOUT; 32 | encryption = CUBESQL_ENCRYPTION_NONE; 33 | } 34 | return self; 35 | } 36 | 37 | - (csqldb *)ref { 38 | return db; 39 | } 40 | 41 | - (int) connect { 42 | return cubesql_connect_token(&db, [hostname UTF8String], port, [username UTF8String], 43 | [password UTF8String], timeout, encryption, (token) ? (char *)[token UTF8String]:NULL, kFALSE, 44 | (ssl_certificate) ? (char *)[ssl_certificate UTF8String]:NULL, NULL, NULL, NULL); 45 | } 46 | 47 | - (void) disconnect { 48 | cubesql_disconnect(db, kFALSE); 49 | db = nil; 50 | } 51 | 52 | - (int) sqlExecute:(NSString *)sql { 53 | return cubesql_execute(db, [sql UTF8String]); 54 | } 55 | 56 | - (CubeSQLCursor *) sqlSelect:(NSString *)sql { 57 | csqlc *c = cubesql_select(db, [sql UTF8String], kFALSE); 58 | if (c == NULL) return nil; 59 | 60 | CubeSQLCursor *cwrapper = [[CubeSQLCursor alloc] initWithCursor:c]; 61 | return cwrapper; 62 | } 63 | 64 | - (CubeSQLVM *) vmPrepare:(NSString *)sql; { 65 | csqlvm *vm = cubesql_vmprepare(db, [sql UTF8String]); 66 | if (vm == NULL) return nil; 67 | 68 | CubeSQLVM *vmwrapper = [[CubeSQLVM alloc] initWithVM:vm]; 69 | return vmwrapper; 70 | } 71 | 72 | - (int) commit { 73 | return cubesql_commit(db); 74 | } 75 | 76 | - (int) rollback { 77 | return cubesql_rollback(db); 78 | } 79 | 80 | - (int) ping { 81 | return cubesql_ping(db); 82 | } 83 | 84 | - (int64) changes { 85 | return cubesql_changes(db); 86 | } 87 | 88 | - (int) errorCode { 89 | return cubesql_errcode(db); 90 | } 91 | 92 | - (NSString *) errorMessage { 93 | return [NSString stringWithUTF8String:cubesql_errmsg(db)]; 94 | } 95 | 96 | - (void) dealloc { 97 | cubesql_disconnect(db, kFALSE); 98 | } 99 | 100 | @end 101 | 102 | #pragma mark - 103 | 104 | @interface CubeSQLCursor() { 105 | csqlc *c; 106 | } 107 | @end 108 | 109 | @implementation CubeSQLCursor 110 | 111 | - (id) initWithCursor:(csqlc *)p { 112 | if (self = [super init]) { 113 | c = p; 114 | } 115 | return self; 116 | } 117 | 118 | - (int) numRows { 119 | return cubesql_cursor_numrows(c); 120 | } 121 | 122 | - (int) numColumns { 123 | return cubesql_cursor_numcolumns(c); 124 | } 125 | 126 | - (int) currentRow { 127 | return cubesql_cursor_currentrow(c); 128 | } 129 | 130 | - (int) seek:(int)index { 131 | return cubesql_cursor_seek(c, index); 132 | } 133 | 134 | - (BOOL) isEOF { 135 | return (cubesql_cursor_iseof(c) == kTRUE); 136 | } 137 | 138 | - (int) columnType:(int)index { 139 | return cubesql_cursor_columntype(c, index); 140 | } 141 | 142 | - (char *) nativeType:(int)row column:(int)column len:(int *)len { 143 | return cubesql_cursor_field(c, row, column, len); 144 | } 145 | 146 | - (int64) rowid:(int)row { 147 | return cubesql_cursor_rowid(c, row); 148 | } 149 | 150 | - (int64) int64Type:(int)row column:(int)column defaultValue:(int64)defaultValue { 151 | return cubesql_cursor_int64(c, row, column, defaultValue); 152 | } 153 | 154 | - (int) intType:(int)row column:(int)column defaultValue:(int)defaultValue { 155 | return cubesql_cursor_int(c, row, column, defaultValue); 156 | } 157 | 158 | - (double) doubleType:(int)row column:(int)column defaultValue:(double)defaultValue { 159 | return cubesql_cursor_double(c, row, column, defaultValue); 160 | } 161 | 162 | - (NSString *) stringValue:(int)row column:(int)column { 163 | char *s = cubesql_cursor_cstring(c, row, column); 164 | if (s == NULL) return nil; 165 | 166 | NSString *value = [NSString stringWithUTF8String:s]; 167 | free(s); 168 | return value; 169 | } 170 | 171 | - (NSData *) blobValue:(int)row column:(int)column { 172 | int dataSize = 0; 173 | 174 | char *buffer = [self nativeType:row column:column len:&dataSize]; 175 | if ((buffer == NULL) || (dataSize == 0)) return nil; 176 | 177 | return [NSData dataWithBytes:(const void *)buffer length:(NSUInteger)dataSize]; 178 | } 179 | 180 | -(BOOL) isNULLValue:(int)row column:(int)column { 181 | int dataSize = 0; 182 | 183 | char *buffer = [self nativeType:row column:column len:&dataSize]; 184 | if ((buffer == NULL) || (dataSize == 0)) return YES; 185 | 186 | return NO; 187 | } 188 | 189 | - (void) dealloc { 190 | cubesql_cursor_free(c); 191 | c = nil; 192 | } 193 | 194 | @end 195 | 196 | #pragma mark - 197 | 198 | @interface CubeSQLVM() { 199 | csqlvm *vm; 200 | } 201 | @end 202 | 203 | @implementation CubeSQLVM 204 | 205 | - (id) initWithVM:(csqlvm *)p { 206 | if (self = [super init]) { 207 | vm = p; 208 | } 209 | return self; 210 | } 211 | 212 | - (int) bindInt:(int)index value:(int)value { 213 | return cubesql_vmbind_int(vm, index, value); 214 | } 215 | 216 | - (int) bindDouble:(int)index value:(double)value { 217 | return cubesql_vmbind_double(vm, index, value); 218 | } 219 | 220 | - (int) bindText:(int)index value:(NSString *)value { 221 | const char *s = [value UTF8String]; 222 | return cubesql_vmbind_text(vm, index, (char *)s, (int)strlen(s)); 223 | } 224 | 225 | - (int) bindBlob:(int)index value:(void *)value len:(int)len { 226 | return cubesql_vmbind_blob(vm, index, value, len); 227 | } 228 | 229 | - (int) bindNull:(int)index { 230 | return cubesql_vmbind_null(vm, index); 231 | } 232 | 233 | - (int) bindInt64:(int)index value:(int64)value { 234 | return cubesql_vmbind_int64(vm, index, value); 235 | } 236 | 237 | - (int) bindZeroBlob:(int)index value:(int)len { 238 | return cubesql_vmbind_zeroblob(vm, index, len); 239 | } 240 | 241 | - (int) execute { 242 | return cubesql_vmexecute(vm); 243 | } 244 | 245 | - (CubeSQLCursor *) select { 246 | csqlc *c = cubesql_vmselect(vm); 247 | if (c == NULL) return nil; 248 | 249 | CubeSQLCursor *cwrapper = [[CubeSQLCursor alloc] initWithCursor:c]; 250 | return cwrapper; 251 | } 252 | 253 | - (void) dealloc { 254 | cubesql_vmclose(vm); 255 | vm = nil; 256 | } 257 | 258 | @end 259 | 260 | -------------------------------------------------------------------------------- /PHP/JSON/cubeSQLServer.php: -------------------------------------------------------------------------------- 1 | 9 | * @see https://github.com/cubesql/connectors 10 | */ 11 | 12 | /** 13 | * Class cubeSQLServer 14 | */ 15 | class cubeSQLServer 16 | { 17 | /** @var int Stores the error code. 0 means no error. */ 18 | public $errorCode; 19 | 20 | /** @var string Stores the error message. */ 21 | public $errorMessage; 22 | 23 | /** @var int */ 24 | public $socketTimeout; 25 | 26 | /** @var */ 27 | private $socket; 28 | 29 | public function connect($host, $port, $username, $password, $timeout = 12) 30 | { 31 | $this->_resetError(); 32 | $this->socketTimeout = $timeout; 33 | 34 | // create socket 35 | $this->socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); 36 | if ($this->socket === false) { 37 | $this->_setSocketError(); 38 | return false; 39 | } 40 | 41 | // connect socket 42 | $ip = gethostbyname($host); 43 | $result = @socket_connect($this->socket, $ip, $port); 44 | if ($result === false) { 45 | $this->_setSocketError(); 46 | return false; 47 | } 48 | 49 | // generate randpool 50 | $randpool = ''; 51 | while (strlen($randpool) <= 10) $randpool .= mt_rand(); 52 | 53 | // compute sha1 (randpool;username) in hex mode 54 | // on the server password is stored as BASE64(SHA1(SHA1(password))) 55 | $sha1_username = sha1($randpool . $username); 56 | $sha1_password = sha1($randpool . base64_encode(sha1(sha1($password, true), true))); 57 | 58 | // create and send json request 59 | $request = array('command' => 'CONNECT', 'username' => "$sha1_username", 'password' => "$sha1_password", 'randpool' => "$randpool"); 60 | $json_request = json_encode($request); 61 | $data = $this->_sendRequest($json_request); 62 | 63 | // save results 64 | $this->errorCode = $data['errorCode']; 65 | $this->errorMessage = (array_key_exists('errorMsg', $data) ? $data['errorMsg'] : NULL); 66 | 67 | return !$this->isError(); 68 | } 69 | 70 | public function connect_database($host, $port, $username, $password, $database) 71 | { 72 | $rc = $this->connect($host, $port, $username, $password, 12); 73 | if ($rc === false) return $rc; 74 | 75 | $this->execute("USE DATABASE $database;"); 76 | if ($rc === false) return $rc; 77 | 78 | return !$this->isError(); 79 | } 80 | 81 | public function execute($sql) 82 | { 83 | $this->_resetError(); 84 | $request = array('command' => 'EXECUTE', 'sql' => "$sql"); 85 | $json_request = json_encode($request); 86 | $data = $this->_sendRequest($json_request); 87 | 88 | // save results 89 | $this->errorCode = $data['errorCode']; 90 | $this->errorMessage = (array_key_exists('errorMsg', $data) ? $data['errorMsg'] : NULL); 91 | } 92 | 93 | public function select($sql) 94 | { 95 | $this->_resetError(); 96 | $request = array('command' => 'SELECT', 'sql' => "$sql"); 97 | $json_request = json_encode($request); 98 | $data = $this->_sendRequest($json_request); 99 | if ($data === NULL) return NULL; 100 | 101 | // check if an error occurs 102 | if (array_key_exists('errorCode', $data)) { 103 | $this->errorCode = $data['errorCode']; 104 | $this->errorMessage = $data['errorMsg']; 105 | return NULL; 106 | } 107 | 108 | // return associative array 109 | return $data; 110 | } 111 | 112 | public function disconnect() 113 | { 114 | $this->_resetError(); 115 | $request = array('command' => 'DISCONNECT'); 116 | $json_request = json_encode($request); 117 | $data = $this->_sendRequest($json_request); 118 | socket_close($this->socket); 119 | } 120 | 121 | public function isError() 122 | { 123 | if ($this->errorCode != 0) return true; 124 | return false; 125 | } 126 | 127 | private function _resetError() 128 | { 129 | $this->errorCode = 0; 130 | $this->errorMessage = ""; 131 | } 132 | 133 | private function _setJSONError() 134 | { 135 | $this->errorCode = json_last_error(); 136 | switch ($this->errorCode) { 137 | case JSON_ERROR_DEPTH: 138 | $this->errorMessage = 'Maximum stack depth exceeded'; 139 | break; 140 | 141 | case JSON_ERROR_CTRL_CHAR: 142 | $this->errorMessage = 'Unexpected control character found'; 143 | break; 144 | 145 | case JSON_ERROR_SYNTAX: 146 | $this->errorMessage = 'Syntax error, malformed JSON'; 147 | break; 148 | 149 | case JSON_ERROR_STATE_MISMATCH: 150 | $this->errorMessage = 'Invalid or malformed JSON'; 151 | break; 152 | 153 | case JSON_ERROR_NONE: 154 | $this->errorMessage = 'No errors'; 155 | break; 156 | } 157 | } 158 | 159 | private function _setSocketError() 160 | { 161 | $this->errorCode = socket_last_error(); 162 | $this->errorMessage = socket_strerror($this->errorCode); 163 | } 164 | 165 | private function _sendRequest($json_request) 166 | { 167 | // write request 168 | $bytes = @socket_write($this->socket, $json_request); 169 | if ($bytes === false) { 170 | $this->_setSocketError(); 171 | return; 172 | } 173 | 174 | // read reply with a specified timeout 175 | $is_timeout = false; 176 | $reply = ''; 177 | $buf = ''; 178 | $start = microtime(true); 179 | while (1) { 180 | $bytes = @socket_recv($this->socket, $buf, 8192, MSG_DONTWAIT); 181 | if ($bytes === false) { 182 | $end = microtime(true); 183 | $wait_time = ($end - $start) * 1000000; 184 | if ($wait_time >= ($this->socketTimeout * 1000000)) { 185 | $is_timeout = true; 186 | break; 187 | } 188 | continue; 189 | } 190 | $reply .= $buf; 191 | 192 | // since there is no way to check when a JOSN packet is finished 193 | // the only way is to try to decode it 194 | //$reply = utf8_encode($reply); 195 | if (($bytes == 2) && (strcmp($reply, "[]") == 0)) return array(); // fix for empty recordset 196 | $r = json_decode($reply, true); 197 | if ($r != NULL) break; 198 | } 199 | 200 | // check for possible errors on exit 201 | if ($is_timeout == true) $this->_setSocketError(); 202 | else if ($r == NULL) $this->_setJSONError(); 203 | 204 | // uncomment these lines to add debug code 205 | /* 206 | $json_errors = array( 207 | JSON_ERROR_NONE => 'No error has occurred', 208 | JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded', 209 | JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded', 210 | JSON_ERROR_SYNTAX => 'Syntax error',); 211 | echo 'JSON Last Error : ', $json_errors[json_last_error()], PHP_EOL, PHP_EOL; 212 | */ 213 | 214 | return $r; 215 | } 216 | } -------------------------------------------------------------------------------- /PHP/PDO: -------------------------------------------------------------------------------- 1 | https://github.com/thelfensdrfer/cubesql-client 2 | -------------------------------------------------------------------------------- /PHP/Test/CubeSQLTest.php: -------------------------------------------------------------------------------- 1 | connect("localhost", 4430, "admin", "admin"); 6 | 7 | if ($rc === true) { 8 | $tstart = microtime(true); 9 | $rs = $cubesql->select("SHOW INFO;"); 10 | $tend = (microtime(true) - $tstart); 11 | var_dump($rs); 12 | echo "Time Elapsed: " . $tend . " secs. \n"; 13 | } else { 14 | echo "Error: " . $cubesql->errorMessage . "\n"; 15 | } 16 | ?> -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Official clients repository for cubeSQL server 2 | 3 | CubeSQL can can be freely downloaded from: [https://sqlabs.com](https://www.sqlabs.com/download/cubesql/)
4 | If you fix any issue or improve the extension please share your changes. 5 | 6 | ## C SDK 7 | The official reference should always be the C SDK. 8 | When linked in another project the **CUBESQL_DISABLE_SSL_ENCRYPTION** macro can be used to skip the usage of TLS code (LibreSSL). 9 | Starting from version 6.0.0 LibreSSL is the default static TLS library (OpenSSL is no longer required). 10 | 11 | # Contact 12 | Marco Bambini (marco@sqlabs.com) 13 | -------------------------------------------------------------------------------- /Sample/Console/VisualC/TestApp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual C++ Express 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestApp", "TestApp\TestApp.vcxproj", "{A260957F-2F2A-4899-90D6-3857925FAFAD}" 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 | {A260957F-2F2A-4899-90D6-3857925FAFAD}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {A260957F-2F2A-4899-90D6-3857925FAFAD}.Debug|Win32.Build.0 = Debug|Win32 14 | {A260957F-2F2A-4899-90D6-3857925FAFAD}.Release|Win32.ActiveCfg = Release|Win32 15 | {A260957F-2F2A-4899-90D6-3857925FAFAD}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Sample/Console/VisualC/TestApp/TestApp.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | {A260957F-2F2A-4899-90D6-3857925FAFAD} 38 | Win32Proj 39 | TestApp 40 | 41 | 42 | 43 | Application 44 | true 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | true 51 | Unicode 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | true 65 | 66 | 67 | false 68 | 69 | 70 | 71 | 72 | 73 | Level3 74 | Disabled 75 | WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 76 | C:\Users\marco\Desktop\cubesql\dev\sdk\crypt;C:\Users\marco\Desktop\cubesql\dev\sdk\zlib;C:\Users\marco\Desktop\cubesql\dev\sdk;%(AdditionalIncludeDirectories) 77 | 78 | 79 | Console 80 | true 81 | Ws2_32.lib;%(AdditionalDependencies) 82 | 83 | 84 | 85 | 86 | Level3 87 | 88 | 89 | MaxSpeed 90 | true 91 | true 92 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 93 | 94 | 95 | Console 96 | true 97 | true 98 | true 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /Sample/Console/VisualC/TestApp/TestApp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 10 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 11 | 12 | 13 | {89dd392f-0ceb-4711-9a78-e5b7c9554bfb} 14 | 15 | 16 | {e178b711-14d2-41a4-ab20-a43a8b782b3f} 17 | 18 | 19 | {8e02f009-cf10-488d-b285-6e7dc229c73a} 20 | 21 | 22 | 23 | 24 | SDK 25 | 26 | 27 | SDK 28 | 29 | 30 | SDK\zlib 31 | 32 | 33 | SDK\zlib 34 | 35 | 36 | SDK\crypt 37 | 38 | 39 | SDK\crypt 40 | 41 | 42 | SDK\crypt 43 | 44 | 45 | SDK\crypt 46 | 47 | 48 | SDK\crypt 49 | 50 | 51 | SDK\crypt 52 | 53 | 54 | 55 | 56 | SDK 57 | 58 | 59 | SDK\zlib 60 | 61 | 62 | SDK\crypt 63 | 64 | 65 | SDK\crypt 66 | 67 | 68 | SDK\crypt 69 | 70 | 71 | SDK\crypt 72 | 73 | 74 | SDK\crypt 75 | 76 | 77 | SDK\crypt 78 | 79 | 80 | Source Files 81 | 82 | 83 | -------------------------------------------------------------------------------- /Sample/Console/VisualC/TestApp/TestApp.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /Sample/Console/XCode/testapp.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 54; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 8DD76FAC0486AB0100D96B5E /* testapp.c in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* testapp.c */; settings = {ATTRIBUTES = (); }; }; 11 | A9292C1A2268990000CA9D69 /* cubesql.c in Sources */ = {isa = PBXBuildFile; fileRef = A9292C022268990000CA9D69 /* cubesql.c */; }; 12 | A9292C1B2268990000CA9D69 /* aeskey.c in Sources */ = {isa = PBXBuildFile; fileRef = A9292C072268990000CA9D69 /* aeskey.c */; }; 13 | A9292C1C2268990000CA9D69 /* aescrypt.c in Sources */ = {isa = PBXBuildFile; fileRef = A9292C0B2268990000CA9D69 /* aescrypt.c */; }; 14 | A9292C1D2268990000CA9D69 /* sha1.c in Sources */ = {isa = PBXBuildFile; fileRef = A9292C0D2268990000CA9D69 /* sha1.c */; }; 15 | A9292C1E2268990000CA9D69 /* pseudorandom.c in Sources */ = {isa = PBXBuildFile; fileRef = A9292C0E2268990000CA9D69 /* pseudorandom.c */; }; 16 | A9292C1F2268990000CA9D69 /* base64.c in Sources */ = {isa = PBXBuildFile; fileRef = A9292C102268990000CA9D69 /* base64.c */; }; 17 | A9292C202268990000CA9D69 /* aestab.c in Sources */ = {isa = PBXBuildFile; fileRef = A9292C112268990000CA9D69 /* aestab.c */; }; 18 | A993537E2B381D1F0043DCBD /* libtls.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A993537D2B381D1F0043DCBD /* libtls.a */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXCopyFilesBuildPhase section */ 22 | 8DD76FAF0486AB0100D96B5E /* CopyFiles */ = { 23 | isa = PBXCopyFilesBuildPhase; 24 | buildActionMask = 8; 25 | dstPath = /usr/share/man/man1/; 26 | dstSubfolderSpec = 0; 27 | files = ( 28 | ); 29 | runOnlyForDeploymentPostprocessing = 1; 30 | }; 31 | /* End PBXCopyFilesBuildPhase section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | 08FB7796FE84155DC02AAC07 /* testapp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testapp.c; path = ../testapp.c; sourceTree = ""; }; 35 | 8DD76FB20486AB0100D96B5E /* testapp */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testapp; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | A9292C022268990000CA9D69 /* cubesql.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cubesql.c; sourceTree = ""; }; 37 | A9292C072268990000CA9D69 /* aeskey.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aeskey.c; sourceTree = ""; }; 38 | A9292C082268990000CA9D69 /* pseudorandom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pseudorandom.h; sourceTree = ""; }; 39 | A9292C092268990000CA9D69 /* aestab.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aestab.h; sourceTree = ""; }; 40 | A9292C0A2268990000CA9D69 /* base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = base64.h; sourceTree = ""; }; 41 | A9292C0B2268990000CA9D69 /* aescrypt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aescrypt.c; sourceTree = ""; }; 42 | A9292C0C2268990000CA9D69 /* aesopt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aesopt.h; sourceTree = ""; }; 43 | A9292C0D2268990000CA9D69 /* sha1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sha1.c; sourceTree = ""; }; 44 | A9292C0E2268990000CA9D69 /* pseudorandom.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pseudorandom.c; sourceTree = ""; }; 45 | A9292C0F2268990000CA9D69 /* aes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes.h; sourceTree = ""; }; 46 | A9292C102268990000CA9D69 /* base64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = base64.c; sourceTree = ""; }; 47 | A9292C112268990000CA9D69 /* aestab.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aestab.c; sourceTree = ""; }; 48 | A9292C122268990000CA9D69 /* sha1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sha1.h; sourceTree = ""; }; 49 | A9292C132268990000CA9D69 /* csql.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = csql.h; sourceTree = ""; }; 50 | A9292C192268990000CA9D69 /* cubesql.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cubesql.h; sourceTree = ""; }; 51 | A993537D2B381D1F0043DCBD /* libtls.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtls.a; path = ../../../libs/macOS/libtls.a; sourceTree = ""; }; 52 | /* End PBXFileReference section */ 53 | 54 | /* Begin PBXFrameworksBuildPhase section */ 55 | 8DD76FAD0486AB0100D96B5E /* Frameworks */ = { 56 | isa = PBXFrameworksBuildPhase; 57 | buildActionMask = 2147483647; 58 | files = ( 59 | A993537E2B381D1F0043DCBD /* libtls.a in Frameworks */, 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | /* End PBXFrameworksBuildPhase section */ 64 | 65 | /* Begin PBXGroup section */ 66 | 08FB7794FE84155DC02AAC07 /* testapp */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 08FB7795FE84155DC02AAC07 /* Source */, 70 | 1AB674ADFE9D54B511CA2CBB /* Products */, 71 | ); 72 | name = testapp; 73 | sourceTree = ""; 74 | }; 75 | 08FB7795FE84155DC02AAC07 /* Source */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | 08FB7796FE84155DC02AAC07 /* testapp.c */, 79 | A993537D2B381D1F0043DCBD /* libtls.a */, 80 | A9292C012268990000CA9D69 /* C_SDK */, 81 | ); 82 | name = Source; 83 | sourceTree = ""; 84 | }; 85 | 1AB674ADFE9D54B511CA2CBB /* Products */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | 8DD76FB20486AB0100D96B5E /* testapp */, 89 | ); 90 | name = Products; 91 | sourceTree = ""; 92 | }; 93 | A9292C012268990000CA9D69 /* C_SDK */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | A9292C062268990000CA9D69 /* crypt */, 97 | A9292C132268990000CA9D69 /* csql.h */, 98 | A9292C192268990000CA9D69 /* cubesql.h */, 99 | A9292C022268990000CA9D69 /* cubesql.c */, 100 | ); 101 | name = C_SDK; 102 | path = ../../../C_SDK; 103 | sourceTree = ""; 104 | }; 105 | A9292C062268990000CA9D69 /* crypt */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | A9292C072268990000CA9D69 /* aeskey.c */, 109 | A9292C082268990000CA9D69 /* pseudorandom.h */, 110 | A9292C092268990000CA9D69 /* aestab.h */, 111 | A9292C0A2268990000CA9D69 /* base64.h */, 112 | A9292C0B2268990000CA9D69 /* aescrypt.c */, 113 | A9292C0C2268990000CA9D69 /* aesopt.h */, 114 | A9292C0D2268990000CA9D69 /* sha1.c */, 115 | A9292C0E2268990000CA9D69 /* pseudorandom.c */, 116 | A9292C0F2268990000CA9D69 /* aes.h */, 117 | A9292C102268990000CA9D69 /* base64.c */, 118 | A9292C112268990000CA9D69 /* aestab.c */, 119 | A9292C122268990000CA9D69 /* sha1.h */, 120 | ); 121 | path = crypt; 122 | sourceTree = ""; 123 | }; 124 | /* End PBXGroup section */ 125 | 126 | /* Begin PBXNativeTarget section */ 127 | 8DD76FA90486AB0100D96B5E /* testapp */ = { 128 | isa = PBXNativeTarget; 129 | buildConfigurationList = 1DEB928508733DD80010E9CD /* Build configuration list for PBXNativeTarget "testapp" */; 130 | buildPhases = ( 131 | 8DD76FAB0486AB0100D96B5E /* Sources */, 132 | 8DD76FAD0486AB0100D96B5E /* Frameworks */, 133 | 8DD76FAF0486AB0100D96B5E /* CopyFiles */, 134 | ); 135 | buildRules = ( 136 | ); 137 | dependencies = ( 138 | ); 139 | name = testapp; 140 | productInstallPath = "$(HOME)/bin"; 141 | productName = testapp; 142 | productReference = 8DD76FB20486AB0100D96B5E /* testapp */; 143 | productType = "com.apple.product-type.tool"; 144 | }; 145 | /* End PBXNativeTarget section */ 146 | 147 | /* Begin PBXProject section */ 148 | 08FB7793FE84155DC02AAC07 /* Project object */ = { 149 | isa = PBXProject; 150 | attributes = { 151 | BuildIndependentTargetsInParallel = YES; 152 | LastUpgradeCheck = 1500; 153 | }; 154 | buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "testapp" */; 155 | compatibilityVersion = "Xcode 3.1"; 156 | developmentRegion = en; 157 | hasScannedForEncodings = 1; 158 | knownRegions = ( 159 | Base, 160 | en, 161 | ); 162 | mainGroup = 08FB7794FE84155DC02AAC07 /* testapp */; 163 | projectDirPath = ""; 164 | projectRoot = ""; 165 | targets = ( 166 | 8DD76FA90486AB0100D96B5E /* testapp */, 167 | ); 168 | }; 169 | /* End PBXProject section */ 170 | 171 | /* Begin PBXSourcesBuildPhase section */ 172 | 8DD76FAB0486AB0100D96B5E /* Sources */ = { 173 | isa = PBXSourcesBuildPhase; 174 | buildActionMask = 2147483647; 175 | files = ( 176 | A9292C1D2268990000CA9D69 /* sha1.c in Sources */, 177 | A9292C202268990000CA9D69 /* aestab.c in Sources */, 178 | A9292C1B2268990000CA9D69 /* aeskey.c in Sources */, 179 | A9292C1F2268990000CA9D69 /* base64.c in Sources */, 180 | A9292C1E2268990000CA9D69 /* pseudorandom.c in Sources */, 181 | 8DD76FAC0486AB0100D96B5E /* testapp.c in Sources */, 182 | A9292C1C2268990000CA9D69 /* aescrypt.c in Sources */, 183 | A9292C1A2268990000CA9D69 /* cubesql.c in Sources */, 184 | ); 185 | runOnlyForDeploymentPostprocessing = 0; 186 | }; 187 | /* End PBXSourcesBuildPhase section */ 188 | 189 | /* Begin XCBuildConfiguration section */ 190 | 1DEB928608733DD80010E9CD /* Debug */ = { 191 | isa = XCBuildConfiguration; 192 | buildSettings = { 193 | ALWAYS_SEARCH_USER_PATHS = NO; 194 | CLANG_ENABLE_OBJC_WEAK = YES; 195 | COPY_PHASE_STRIP = NO; 196 | DEAD_CODE_STRIPPING = YES; 197 | GCC_DYNAMIC_NO_PIC = NO; 198 | GCC_MODEL_TUNING = G5; 199 | GCC_OPTIMIZATION_LEVEL = 0; 200 | INSTALL_PATH = /usr/local/bin; 201 | LIBRARY_SEARCH_PATHS = /Users/marco/GitHub/cubesql_sdk/libs/macOS; 202 | MACOSX_DEPLOYMENT_TARGET = 10.13; 203 | PRODUCT_NAME = testapp; 204 | SDKROOT = macosx; 205 | }; 206 | name = Debug; 207 | }; 208 | 1DEB928708733DD80010E9CD /* Release */ = { 209 | isa = XCBuildConfiguration; 210 | buildSettings = { 211 | ALWAYS_SEARCH_USER_PATHS = NO; 212 | CLANG_ENABLE_OBJC_WEAK = YES; 213 | DEAD_CODE_STRIPPING = YES; 214 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 215 | GCC_MODEL_TUNING = G5; 216 | INSTALL_PATH = /usr/local/bin; 217 | LIBRARY_SEARCH_PATHS = /Users/marco/GitHub/cubesql_sdk/libs/macOS; 218 | MACOSX_DEPLOYMENT_TARGET = 10.13; 219 | PRODUCT_NAME = testapp; 220 | SDKROOT = macosx; 221 | }; 222 | name = Release; 223 | }; 224 | 1DEB928A08733DD80010E9CD /* Debug */ = { 225 | isa = XCBuildConfiguration; 226 | buildSettings = { 227 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 228 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 229 | CLANG_WARN_BOOL_CONVERSION = YES; 230 | CLANG_WARN_COMMA = YES; 231 | CLANG_WARN_CONSTANT_CONVERSION = YES; 232 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 233 | CLANG_WARN_EMPTY_BODY = YES; 234 | CLANG_WARN_ENUM_CONVERSION = YES; 235 | CLANG_WARN_INFINITE_RECURSION = YES; 236 | CLANG_WARN_INT_CONVERSION = YES; 237 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 238 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 239 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 240 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 241 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 242 | CLANG_WARN_STRICT_PROTOTYPES = YES; 243 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 244 | CLANG_WARN_UNREACHABLE_CODE = YES; 245 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 246 | DEAD_CODE_STRIPPING = YES; 247 | ENABLE_STRICT_OBJC_MSGSEND = YES; 248 | ENABLE_TESTABILITY = YES; 249 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 250 | GCC_C_LANGUAGE_STANDARD = gnu99; 251 | GCC_NO_COMMON_BLOCKS = YES; 252 | GCC_OPTIMIZATION_LEVEL = 0; 253 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 254 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 255 | GCC_WARN_UNDECLARED_SELECTOR = YES; 256 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 257 | GCC_WARN_UNUSED_FUNCTION = YES; 258 | GCC_WARN_UNUSED_VARIABLE = YES; 259 | HEADER_SEARCH_PATHS = "../../sdk/**"; 260 | MACOSX_DEPLOYMENT_TARGET = 10.13; 261 | ONLY_ACTIVE_ARCH = YES; 262 | OTHER_LDFLAGS = "-lz"; 263 | SDKROOT = macosx; 264 | }; 265 | name = Debug; 266 | }; 267 | 1DEB928B08733DD80010E9CD /* Release */ = { 268 | isa = XCBuildConfiguration; 269 | buildSettings = { 270 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 271 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 272 | CLANG_WARN_BOOL_CONVERSION = YES; 273 | CLANG_WARN_COMMA = YES; 274 | CLANG_WARN_CONSTANT_CONVERSION = YES; 275 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 276 | CLANG_WARN_EMPTY_BODY = YES; 277 | CLANG_WARN_ENUM_CONVERSION = YES; 278 | CLANG_WARN_INFINITE_RECURSION = YES; 279 | CLANG_WARN_INT_CONVERSION = YES; 280 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 281 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 282 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 283 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 284 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 285 | CLANG_WARN_STRICT_PROTOTYPES = YES; 286 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 287 | CLANG_WARN_UNREACHABLE_CODE = YES; 288 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 289 | DEAD_CODE_STRIPPING = YES; 290 | ENABLE_STRICT_OBJC_MSGSEND = YES; 291 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 292 | GCC_C_LANGUAGE_STANDARD = gnu99; 293 | GCC_NO_COMMON_BLOCKS = YES; 294 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 295 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 296 | GCC_WARN_UNDECLARED_SELECTOR = YES; 297 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 298 | GCC_WARN_UNUSED_FUNCTION = YES; 299 | GCC_WARN_UNUSED_VARIABLE = YES; 300 | HEADER_SEARCH_PATHS = "../../sdk/**"; 301 | MACOSX_DEPLOYMENT_TARGET = 10.13; 302 | OTHER_LDFLAGS = "-lz"; 303 | SDKROOT = macosx; 304 | }; 305 | name = Release; 306 | }; 307 | /* End XCBuildConfiguration section */ 308 | 309 | /* Begin XCConfigurationList section */ 310 | 1DEB928508733DD80010E9CD /* Build configuration list for PBXNativeTarget "testapp" */ = { 311 | isa = XCConfigurationList; 312 | buildConfigurations = ( 313 | 1DEB928608733DD80010E9CD /* Debug */, 314 | 1DEB928708733DD80010E9CD /* Release */, 315 | ); 316 | defaultConfigurationIsVisible = 0; 317 | defaultConfigurationName = Release; 318 | }; 319 | 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "testapp" */ = { 320 | isa = XCConfigurationList; 321 | buildConfigurations = ( 322 | 1DEB928A08733DD80010E9CD /* Debug */, 323 | 1DEB928B08733DD80010E9CD /* Release */, 324 | ); 325 | defaultConfigurationIsVisible = 0; 326 | defaultConfigurationName = Release; 327 | }; 328 | /* End XCConfigurationList section */ 329 | }; 330 | rootObject = 08FB7793FE84155DC02AAC07 /* Project object */; 331 | } 332 | -------------------------------------------------------------------------------- /Sample/Console/XCode/testapp.xcodeproj/xcshareddata/xcschemes/testapp.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /Sample/Console/gcc/Makefile: -------------------------------------------------------------------------------- 1 | SDKDIR = ../../../C_SDK 2 | CRYPTDIR = ../../../C_SDK/crypt 3 | SRCDIR = .. 4 | INCLUDE = -I$(SRCDIR) -I$(SDKDIR)/ -I$(CRYPTDIR)/ 5 | 6 | CC = gcc 7 | LD = gcc 8 | CFLAGS = $(INCLUDE) -O2 9 | LDFLAGS = -lz 10 | RM = /bin/rm -f 11 | 12 | OBJS = testapp.o cubesql.o pseudorandom.o aescrypt.o aeskey.o aestab.o base64.o sha1.o 13 | 14 | PROG = testapp 15 | all: ${PROG} 16 | 17 | ${PROG}: ${OBJS} 18 | ${LD} ${LDFLAGS} ${OBJS} -o ${PROG} 19 | 20 | testapp.o: $(SRCDIR)/testapp.c 21 | ${CC} $(CFLAGS) -c $< -o $@ 22 | 23 | cubesql.o: $(SDKDIR)/cubesql.c 24 | ${CC} $(CFLAGS) -c $< -o $@ 25 | 26 | %.o: $(CRYPTDIR)/%.c 27 | ${CC} $(CFLAGS) -c $< -o $@ 28 | 29 | clean: 30 | ${RM} ${PROG} ${OBJS} 31 | 32 | -------------------------------------------------------------------------------- /Sample/Console/testapp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * main.c 3 | * testapp 4 | * 5 | * Created by Marco Bambini on 01/23/11. 6 | * Copyright 2011 SQLabs. All rights reserved. 7 | * 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include "cubesql.h" 14 | 15 | #define HOSTNAME "localhost" 16 | #define USERNAME "admin" 17 | #define PASSWORD "admin" 18 | 19 | // MARK: - 20 | 21 | static void print_cursor(csqlc *c) { 22 | int i, nrows, ncols, len; 23 | char *s, b[512]; 24 | 25 | if (c == NULL) return; 26 | 27 | nrows = cubesql_cursor_numrows(c); 28 | ncols = cubesql_cursor_numcolumns(c); 29 | printf("Record set contains\nrows: %d\ncolumns: %d\n\n", nrows, ncols); 30 | 31 | // print column's names 32 | for (i=1; i<=ncols; i++) { 33 | s = cubesql_cursor_field(c, CUBESQL_COLNAME, i, &len); 34 | printf("%s\t\t", s); 35 | } 36 | 37 | // print a separator 38 | printf("\n"); 39 | for (i=1; i<=70; i++) printf("-"); 40 | printf("\n"); 41 | 42 | // print data using the EOF property (safe for both server side and client side cursors) 43 | while (cubesql_cursor_iseof(c) != kTRUE) { 44 | for (i=1; i<=ncols; i++) { 45 | s = cubesql_cursor_cstring_static(c, CUBESQL_CURROW, i, b, sizeof(b)); 46 | printf("%s\t\t", s); 47 | } 48 | 49 | cubesql_cursor_seek(c, CUBESQL_SEEKNEXT); 50 | printf("\n"); 51 | } 52 | printf("\n"); 53 | } 54 | 55 | //static void do_trace (const char *sql, void *unused) { 56 | // printf("%s\n", sql); 57 | //} 58 | 59 | static int do_setup (csqldb *db) { 60 | int err = 0; 61 | 62 | // create db 63 | err = cubesql_execute(db, "CREATE DATABASE mytestdb.sqlite IF NOT EXISTS;"); 64 | if (err != CUBESQL_NOERR) goto abort; 65 | 66 | // set current db 67 | err = cubesql_execute(db, "USE DATABASE mytestdb.sqlite;"); 68 | if (err != CUBESQL_NOERR) goto abort; 69 | 70 | // create table 71 | err = cubesql_execute(db, "CREATE TABLE IF NOT EXISTS foo (id INTEGER PRIMARY KEY AUTOINCREMENT, col1 TEXT, col2 TEXT, col3 INTEGER);"); 72 | if (err != CUBESQL_NOERR) goto abort; 73 | 74 | return 1; 75 | 76 | abort: 77 | printf("An error occured in do_setup: %s (errocode %d)", cubesql_errmsg(db), cubesql_errcode(db)); 78 | return 0; 79 | } 80 | 81 | static void do_test (csqldb *db) { 82 | int err = 0; 83 | csqlc *c = NULL; 84 | 85 | // setup database and table 86 | if (do_setup(db) == 0) return; 87 | 88 | // insert a couple records 89 | err = cubesql_execute(db, "INSERT INTO foo (col1, col2, col3) VALUES ('test1', 'test2', 13);"); 90 | if (err != CUBESQL_NOERR) goto abort; 91 | 92 | // cubesql_set_trace_callback(db, do_trace, NULL); 93 | 94 | err = cubesql_execute(db, "INSERT INTO foo (col1, col2, col3) VALUES ('test3', 'test4', 17);"); 95 | if (err != CUBESQL_NOERR) goto abort; 96 | 97 | err = cubesql_execute(db, "INSERT INTO foo (col1, col2, col3) VALUES ('test5', 'test6', 19);"); 98 | if (err != CUBESQL_NOERR) goto abort; 99 | 100 | err = cubesql_execute(db, "INSERT INTO foo (col1, col2, col3) VALUES ('test7', 'test8', 23);"); 101 | if (err != CUBESQL_NOERR) goto abort; 102 | 103 | // commit current transaction 104 | err = cubesql_commit(db); 105 | if (err != CUBESQL_NOERR) goto abort; 106 | 107 | // perform a simple select statement 108 | c = cubesql_select(db, "SELECT * FROM foo;", kFALSE); 109 | if (c == NULL) goto abort; 110 | print_cursor(c); 111 | cubesql_cursor_free(c); 112 | 113 | return; 114 | 115 | abort: 116 | printf("An error occured in do_test: %s (errocode %d)", cubesql_errmsg(db), cubesql_errcode(db)); 117 | return; 118 | } 119 | 120 | static void do_test_bind (csqldb *db) { 121 | int err = 0; 122 | csqlvm *vm = NULL; 123 | 124 | // setup database and table 125 | if (do_setup(db) == 0) return; 126 | 127 | vm = cubesql_vmprepare(db, "INSERT INTO foo (col1, col2) VALUES (?1, ?2);"); 128 | if (vm == NULL) goto abort; 129 | 130 | //err = cubesql_vmbind_text(vm, 1, "", -1); 131 | err = cubesql_vmbind_null(vm, 1); 132 | if (err != CUBESQL_NOERR) goto abort; 133 | 134 | err = cubesql_vmbind_text(vm, 2, "World7", -1); 135 | if (err != CUBESQL_NOERR) goto abort; 136 | 137 | err = cubesql_vmexecute(vm); 138 | if (err != CUBESQL_NOERR) goto abort; 139 | 140 | // commit current transaction 141 | err = cubesql_commit(db); 142 | if (err != CUBESQL_NOERR) goto abort; 143 | 144 | return; 145 | 146 | abort: 147 | printf("An error occured in do_test_bind: %s (errocode %d)", cubesql_errmsg(db), cubesql_errcode(db)); 148 | return; 149 | } 150 | 151 | // MARK: - 152 | 153 | void do_upload_database (csqldb *db, const char *dbname, const char *local_filename_path) { 154 | // tell server to initiate upload 155 | char sql[1024]; 156 | snprintf(sql, sizeof(sql), "UPLOAD DATABASE %s WITH REPLACE;", dbname); 157 | int err = cubesql_execute(db, sql); 158 | if (err != CUBESQL_NOERR) goto abort; 159 | 160 | // open file local file for reading 161 | FILE *file = fopen(local_filename_path, "rb"); 162 | if (!file) { 163 | perror("Error opening file"); 164 | return; 165 | } 166 | 167 | int tot = 0; 168 | const int CHUNK_SIZE = 4096; 169 | unsigned char buffer[CHUNK_SIZE]; 170 | 171 | // loop to send database in chunks 172 | while (1) { 173 | size_t nread = fread(buffer, 1, CHUNK_SIZE, file); 174 | if (nread == 0) break; 175 | if (nread < 0) { 176 | perror("Error reading from file"); 177 | fclose(file); 178 | return; 179 | } 180 | 181 | // send chunk to server 182 | tot += nread; 183 | cubesql_send_data(db, (const char *)buffer, (int)nread); 184 | } 185 | 186 | // send end-of-chunk 187 | cubesql_send_enddata(db); 188 | 189 | fclose(file); 190 | printf("Database %s uploaded (%d bytes)\n", dbname, tot); 191 | return; 192 | abort: 193 | printf("Upload database aborted: %s\n", cubesql_errmsg(db)); 194 | } 195 | 196 | void do_download_database (csqldb *db, const char *dbname, const char *local_filename_path) { 197 | // tell server to initiate download 198 | char sql[1024]; 199 | snprintf(sql, sizeof(sql), "DOWNLOAD DATABASE %s;", dbname); 200 | int err = cubesql_execute(db, sql); 201 | if (err != CUBESQL_NOERR) goto abort; 202 | 203 | // create local file 204 | FILE *file = fopen(local_filename_path, "wb"); 205 | if (!file) { 206 | perror("Error opening file"); 207 | return; 208 | } 209 | 210 | // loop to receive database in chunks 211 | int tot = 0; 212 | while (1) { 213 | // receive one chunk at a time 214 | int len = 0; 215 | int is_end_chunk = 0; 216 | char *buffer = cubesql_receive_data (db, &len, &is_end_chunk); 217 | 218 | // check exit condition 219 | if (is_end_chunk) break; 220 | 221 | // write to file 222 | size_t written = fwrite(buffer, 1, len, file); 223 | if (written != len) { 224 | perror("Error writing to file"); 225 | fclose(file); 226 | return; 227 | } 228 | tot += len; 229 | } 230 | 231 | fclose(file); 232 | printf("Database %s downloaded in %s (%d bytes)\n", dbname, local_filename_path, tot); 233 | return; 234 | abort: 235 | printf("Donwload database aborted: %s\n", cubesql_errmsg(db)); 236 | } 237 | 238 | void do_duplicate_database(csqldb *db, const char *download_db_name, const char *upload_db_name, const char *local_file_path) { 239 | do_download_database(db, download_db_name, local_file_path); 240 | do_upload_database(db, upload_db_name, local_file_path); 241 | } 242 | 243 | // MARK: - 244 | 245 | int main (void) { 246 | csqldb *db = NULL; 247 | 248 | // connection without encryption 249 | if (cubesql_connect(&db, HOSTNAME, CUBESQL_DEFAULT_PORT, USERNAME, PASSWORD, CUBESQL_DEFAULT_TIMEOUT, CUBESQL_ENCRYPTION_NONE) != CUBESQL_NOERR) goto abort; 250 | 251 | //const char *root_ca_path = "full_path_to_root_CA_file"; 252 | //if (cubesql_connect_token (&db, HOSTNAME, CUBESQL_DEFAULT_PORT, USERNAME, PASSWORD, CUBESQL_DEFAULT_TIMEOUT, CUBESQL_ENCRYPTION_SSL, NULL, kFALSE, NULL, root_ca_path, NULL, NULL) != CUBESQL_NOERR) goto abort; 253 | 254 | // do a simple test 255 | // do_test_bind(db); 256 | // do_test(db); 257 | const char *local_file_path = "/Users/marco/Desktop/db.sqlite"; 258 | //do_download_database(db, "mytestdb.sqlite", local_file_path); 259 | //do_upload_database(db, "db2.sqlite", local_file_path); 260 | do_duplicate_database(db, "mytestdb.sqlite", "db3.sqlite", local_file_path); 261 | 262 | // disconnect 263 | cubesql_disconnect(db, kTRUE); 264 | return 0; 265 | 266 | abort: 267 | if (db) { 268 | printf("error %d in cubesql_connect: %s\n", cubesql_errcode(db), cubesql_errmsg(db)); 269 | cubesql_disconnect(db, kFALSE); 270 | } 271 | return -1; 272 | } 273 | -------------------------------------------------------------------------------- /Sample/MacOS/Client/cubeSQLTest/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // cubeSQLTest 4 | // 5 | // Created by Marco Bambini on 04/09/2018. 6 | // Copyright © 2018 SQLabs. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : NSObject 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /Sample/MacOS/Client/cubeSQLTest/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // cubeSQLTest 4 | // 5 | // Created by Marco Bambini on 04/09/2018. 6 | // Copyright © 2018 SQLabs. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "CubeSQLObjc.h" 11 | 12 | #define NEWLINE @"\n" 13 | #define TABLINE @"\t\t" 14 | 15 | @interface AppDelegate () { 16 | IBOutlet NSTextField *sdkversion; 17 | 18 | IBOutlet NSTextField *username; 19 | IBOutlet NSTextField *password; 20 | IBOutlet NSTextField *hostname; 21 | IBOutlet NSTextField *database; 22 | IBOutlet NSPopUpButton *encryption; 23 | 24 | IBOutlet NSTextField *sqlField; 25 | IBOutlet NSTextView *logField; 26 | 27 | IBOutlet NSButton *connectButton; 28 | IBOutlet NSButton *executeButton; 29 | 30 | CubeSQL *db; 31 | } 32 | @property (weak) IBOutlet NSWindow *window; 33 | @end 34 | 35 | // MARK: - 36 | 37 | @implementation AppDelegate 38 | 39 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 40 | const char *version = cubesql_version(); 41 | sdkversion.stringValue = [NSString stringWithFormat:@"SDK version: %s", version]; 42 | } 43 | 44 | - (void)applicationWillTerminate:(NSNotification *)aNotification { 45 | } 46 | 47 | // MARK: - 48 | 49 | - (IBAction)doConnect:(id)sender { 50 | if ([connectButton.title isEqualToString:@"Disconnect"]) { 51 | [self doDisconnect:sender]; 52 | return; 53 | } 54 | 55 | db = [[CubeSQL alloc] init]; 56 | db.hostname = hostname.stringValue; 57 | db.username = username.stringValue; 58 | db.password = password.stringValue; 59 | 60 | // set encryption 61 | NSInteger index = encryption.indexOfSelectedItem; 62 | if (index == 0) db.encryption = CUBESQL_ENCRYPTION_NONE; 63 | else if (index == 1) db.encryption = CUBESQL_ENCRYPTION_AES128; 64 | else if (index == 2) db.encryption = CUBESQL_ENCRYPTION_AES256; 65 | 66 | if ([db connect] != CUBESQL_NOERR) { 67 | [self displayError:db.errorMessage]; 68 | [db disconnect]; 69 | return; 70 | } 71 | 72 | [self appendText:@"Connection succesfully executed\n" termination:NEWLINE]; 73 | 74 | // connection is OK, now try to set current database 75 | NSString *sql = [NSString stringWithFormat:@"USE DATABASE %@;", database.stringValue]; 76 | [self appendText:sql termination:NEWLINE]; 77 | 78 | int res = [db sqlExecute:sql]; 79 | if (res != CUBESQL_NOERR) { 80 | [self displayError:db.errorMessage]; 81 | [db disconnect]; 82 | return; 83 | } 84 | 85 | // connection succesfull executed 86 | connectButton.title = @"Disconnect"; 87 | executeButton.enabled = YES; 88 | sqlField.enabled = YES; 89 | } 90 | 91 | - (IBAction)doDisconnect:(id)sender { 92 | [db disconnect]; 93 | db = nil; 94 | 95 | // reset log field 96 | logField.string = @""; 97 | 98 | connectButton.title = @"Connect"; 99 | executeButton.enabled = NO; 100 | sqlField.enabled = NO; 101 | } 102 | 103 | - (IBAction)doExecute:(id)sender { 104 | // small sanity check on db 105 | if (db == nil) {NSBeep(); return;} 106 | 107 | // retrieve command 108 | NSString *sql = [sqlField stringValue]; 109 | 110 | // sanity check on sql 111 | if ([sql length] == 0) {NSBeep(); return;} 112 | 113 | // log sql 114 | [self appendText:sql termination:NEWLINE]; 115 | 116 | // check the first word of the command 117 | // if it is SELECT or SHOW than its a query that returns a RecordSet 118 | // if it is a PRAGMA than it is a query ONLY if does not contain the = character 119 | // otherwise it is an EXECUTE command 120 | NSArray *words = [sql componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 121 | NSString *firstWord = [[words objectAtIndex:0] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].uppercaseString; 122 | BOOL isQuery = (([firstWord isEqualToString:@"SELECT"] || [firstWord isEqualToString:@"SHOW"]) || 123 | ([firstWord isEqualToString:@"PRAGMA"] && ([sql rangeOfString:@"="].location == NSNotFound))); 124 | 125 | if (isQuery) { 126 | CubeSQLCursor *c = [db sqlSelect:sql]; 127 | if (c == nil) [self displayError:[db errorMessage]]; 128 | else [self displayCursor:c]; 129 | } else { 130 | int res = [db sqlExecute:sql]; 131 | if (res == CUBESQL_NOERR) [self appendText:sql termination:NEWLINE]; 132 | else [self displayError:[db errorMessage]]; 133 | } 134 | 135 | [self appendText:NEWLINE termination:nil]; 136 | } 137 | 138 | - (void)displayCursor:(CubeSQLCursor *)c { 139 | if (c == NULL) return; 140 | 141 | int nrows = [c numRows]; 142 | int ncols = [c numColumns]; 143 | 144 | NSMutableString *s = [[NSMutableString alloc] initWithCapacity:4096]; 145 | [s appendFormat:@"rows: %d - columns: %d\n\n", nrows, ncols]; 146 | 147 | // print column names separated by tabs 148 | for (int i=1; i<=ncols; i++) { 149 | NSString *colName = [c stringValue:CUBESQL_COLNAME column:i]; 150 | [s appendString:colName]; 151 | [s appendString:TABLINE]; 152 | } 153 | [s appendString:NEWLINE]; 154 | 155 | while ([c isEOF] == NO) { 156 | for (int i=1; i<=ncols; i++) { 157 | NSString *colValue = [c stringValue:CUBESQL_CURROW column:i]; 158 | if (colValue == nil) colValue = @"NULL"; 159 | [s appendString:colValue]; 160 | [s appendString:TABLINE]; 161 | } 162 | [c seek:CUBESQL_SEEKNEXT]; 163 | [s appendString:NEWLINE]; 164 | } 165 | 166 | [self appendText:s termination:NEWLINE]; 167 | } 168 | 169 | - (void)displayError:(NSString *)error { 170 | NSAlert *alert = [[NSAlert alloc] init]; 171 | [alert setMessageText:error]; 172 | [alert beginSheetModalForWindow:_window completionHandler:nil]; 173 | } 174 | 175 | -(void)appendText:(NSString *)text termination:(NSString *)text2 { 176 | NSAttributedString *s; 177 | if (text2) s = [[NSAttributedString alloc] initWithString:[text stringByAppendingString:text2]]; 178 | else s = [[NSAttributedString alloc] initWithString:text]; 179 | 180 | [logField.textStorage appendAttributedString:s]; 181 | [logField scrollToEndOfDocument:nil]; 182 | } 183 | 184 | @end 185 | -------------------------------------------------------------------------------- /Sample/MacOS/Client/cubeSQLTest/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /Sample/MacOS/Client/cubeSQLTest/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Sample/MacOS/Client/cubeSQLTest/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // cubeSQLTest 4 | // 5 | // Created by Marco Bambini on 04/09/2018. 6 | // Copyright © 2018 SQLabs. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, const char * argv[]) { 12 | return NSApplicationMain(argc, argv); 13 | } 14 | -------------------------------------------------------------------------------- /Sample/MacOS/Files API/cubeSQLTest/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // cubeSQLTest 4 | // 5 | // Created by Marco Bambini on 04/09/2018. 6 | // Copyright © 2018 SQLabs. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : NSObject 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /Sample/MacOS/Files API/cubeSQLTest/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // cubeSQLTest 4 | // 5 | // Created by Marco Bambini on 04/09/2018. 6 | // Copyright © 2018 SQLabs. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "CubeSQLObjc.h" 11 | 12 | #define NEWLINE @"\n" 13 | #define TABLINE @"\t\t" 14 | #define CHUNK_SIZE 102400 15 | 16 | @interface AppDelegate () { 17 | IBOutlet NSTextField *sdkversion; 18 | 19 | IBOutlet NSTextField *username; 20 | IBOutlet NSTextField *password; 21 | IBOutlet NSTextField *hostname; 22 | IBOutlet NSTextField *database; 23 | IBOutlet NSPopUpButton *encryption; 24 | 25 | IBOutlet NSButton *connectButton; 26 | IBOutlet NSButton *uploadButton; 27 | IBOutlet NSButton *downloadButton; 28 | IBOutlet NSButton *deleteButton; 29 | 30 | IBOutlet NSTableView *tableView; 31 | NSMutableArray *names; 32 | NSMutableArray *sizes; 33 | 34 | CubeSQL *db; 35 | } 36 | @property (weak) IBOutlet NSWindow *window; 37 | @end 38 | 39 | // MARK: - 40 | 41 | @implementation AppDelegate 42 | 43 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 44 | const char *version = cubesql_version(); 45 | sdkversion.stringValue = [NSString stringWithFormat:@"SDK version: %s", version]; 46 | 47 | names = [NSMutableArray array]; 48 | sizes = [NSMutableArray array]; 49 | } 50 | 51 | - (void)applicationWillTerminate:(NSNotification *)aNotification { 52 | } 53 | 54 | // MARK: - 55 | 56 | - (IBAction)doConnect:(id)sender { 57 | if ([connectButton.title isEqualToString:@"Disconnect"]) { 58 | [self doDisconnect:sender]; 59 | return; 60 | } 61 | 62 | db = [[CubeSQL alloc] init]; 63 | db.hostname = hostname.stringValue; 64 | db.username = username.stringValue; 65 | db.password = password.stringValue; 66 | 67 | // set encryption 68 | NSInteger index = encryption.indexOfSelectedItem; 69 | if (index == 0) db.encryption = CUBESQL_ENCRYPTION_NONE; 70 | else if (index == 1) db.encryption = CUBESQL_ENCRYPTION_AES128; 71 | else if (index == 2) db.encryption = CUBESQL_ENCRYPTION_AES256; 72 | 73 | if ([db connect] != CUBESQL_NOERR) { 74 | [self displayError:db.errorMessage]; 75 | [db disconnect]; 76 | return; 77 | } 78 | 79 | // connection is OK, now try to set current database 80 | if (database.stringValue.length > 0) { 81 | NSString *sql = [NSString stringWithFormat:@"USE DATABASE %@;", database.stringValue]; 82 | int res = [db sqlExecute:sql]; 83 | if (res != CUBESQL_NOERR) { 84 | [self displayError:db.errorMessage]; 85 | [db disconnect]; 86 | return; 87 | } 88 | } 89 | 90 | // connection succesfull executed 91 | connectButton.title = @"Disconnect"; 92 | uploadButton.enabled = YES; 93 | 94 | // automatically get file list 95 | [self doListFiles:nil]; 96 | } 97 | 98 | - (IBAction)doDisconnect:(id)sender { 99 | [db disconnect]; 100 | db = nil; 101 | 102 | // reset tableview 103 | [names removeAllObjects]; 104 | [sizes removeAllObjects]; 105 | [tableView reloadData]; 106 | 107 | connectButton.title = @"Connect"; 108 | uploadButton.enabled = NO; 109 | } 110 | 111 | - (IBAction)doListFiles:(id)sender { 112 | // perform query 113 | CubeSQLCursor *c = [db sqlSelect:@"SHOW FILES;"]; 114 | if (c == nil) { 115 | [self displayError:[db errorMessage]]; 116 | return; 117 | } 118 | 119 | // reset 120 | [names removeAllObjects]; 121 | [sizes removeAllObjects]; 122 | 123 | // parse result 124 | while ([c isEOF] == NO) { 125 | NSString *fileName = [c stringValue:CUBESQL_CURROW column:1]; 126 | NSString *fileSize = [c stringValue:CUBESQL_CURROW column:2]; 127 | [names addObject:fileName]; 128 | [sizes addObject:fileSize]; 129 | [c seek:CUBESQL_SEEKNEXT]; 130 | } 131 | 132 | // reload table 133 | [tableView reloadData]; 134 | } 135 | 136 | - (IBAction)doUploadFile:(id)sender { 137 | // choose file to upload 138 | NSOpenPanel *panel = [NSOpenPanel openPanel]; 139 | [panel setCanChooseFiles:YES]; 140 | [panel setCanChooseDirectories:NO]; 141 | [panel setAllowsMultipleSelection:NO]; 142 | [panel setMessage:@"Choose a file to upload."]; 143 | if ([panel runModal] != NSFileHandlingPanelOKButton) return; 144 | 145 | NSURL *url = [[panel URLs] firstObject]; 146 | if (!url) return; 147 | 148 | // not a very smart way to read a file 149 | NSData *data = [[NSData alloc] initWithContentsOfURL:url]; 150 | if (!data) {NSBeep(); return;} 151 | 152 | [self uploadData:data withName:url.lastPathComponent]; 153 | [self doListFiles:nil]; 154 | } 155 | 156 | - (IBAction)doDownloadFile:(id)sender { 157 | NSInteger selectedRow = tableView.selectedRow; 158 | if (selectedRow == -1) return; 159 | NSString *fileName = names[selectedRow]; 160 | 161 | NSSavePanel *panel = [NSSavePanel savePanel]; 162 | panel.nameFieldStringValue = fileName; 163 | 164 | if ([panel runModal] != NSFileHandlingPanelOKButton) return; 165 | 166 | NSURL *url = [panel URL]; 167 | if (!url) return; 168 | 169 | [self beginDownload:fileName toURL:url]; 170 | } 171 | 172 | - (IBAction)doDeleteFile:(id)sender { 173 | NSInteger selectedRow = tableView.selectedRow; 174 | if (selectedRow == -1) return; 175 | NSString *fileName = names[selectedRow]; 176 | // Are you sure you want to delete file with name ... ? 177 | 178 | NSString *sql = [NSString stringWithFormat:@"FILE DELETE '%@';", fileName]; 179 | int res = [db sqlExecute:sql]; 180 | if (res != CUBESQL_NOERR) { 181 | [self displayError:db.errorMessage]; 182 | } 183 | 184 | [self doListFiles:nil]; 185 | } 186 | 187 | // MARK: - TableView - 188 | 189 | - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { 190 | return names.count; 191 | } 192 | 193 | - (id)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { 194 | NSTableCellView *result = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self]; 195 | 196 | NSString *s = ([tableColumn.identifier isEqualToString:@"col1"]) ? names[row] : sizes[row]; 197 | result.textField.stringValue = s; 198 | return result; 199 | } 200 | 201 | - (void)tableViewSelectionDidChange:(NSNotification *)notification { 202 | NSInteger selectedRow = tableView.selectedRow; 203 | downloadButton.enabled = (selectedRow != -1); 204 | deleteButton.enabled = (selectedRow != -1); 205 | } 206 | 207 | // MARK: - 208 | 209 | - (void)beginDownload:(NSString *)fileName toURL:(NSURL *)url { 210 | // write binary file in C because it is much more faster than converting to NDData each time 211 | FILE *f = fopen(url.path.UTF8String, "wb"); 212 | if (!f) { 213 | [self displayError:@"Unable to create file."]; 214 | return; 215 | } 216 | 217 | // prepare file uploading 218 | NSString *sql = [NSString stringWithFormat:@"FILE DOWNLOAD '%@'", fileName]; 219 | int res = [db sqlExecute:sql]; 220 | if (res != CUBESQL_NOERR) { 221 | [self displayError:db.errorMessage]; 222 | return; 223 | } 224 | 225 | while (1) { 226 | int len = 0; 227 | int isEndData = 0; 228 | char *data = cubesql_receive_data(db.ref, &len, &isEndData); 229 | if (isEndData) break; 230 | if (data && len) fwrite(data, len, 1, f); 231 | } 232 | 233 | fclose(f); 234 | } 235 | 236 | - (void)uploadData:(NSData *)data withName:(NSString *)fileName { 237 | // prepare file uploading 238 | NSString *sql = [NSString stringWithFormat:@"FILE UPLOAD '%@' WITH REPLACE;", fileName]; 239 | int res = [db sqlExecute:sql]; 240 | if (res != CUBESQL_NOERR) { 241 | [self displayError:db.errorMessage]; 242 | return; 243 | } 244 | 245 | // loop to upload data in chunk 246 | const void *bytes = data.bytes; 247 | NSInteger length = data.length; 248 | 249 | while (length > 0) { 250 | NSInteger chunckSize = (length < CHUNK_SIZE) ? length : CHUNK_SIZE; 251 | 252 | int err = cubesql_send_data(db.ref, bytes, (int)chunckSize); 253 | if (err != CUBESQL_NOERR) { 254 | [self displayError:db.errorMessage]; 255 | return; 256 | } 257 | 258 | // update length and buffer ptr 259 | length -= chunckSize; 260 | bytes += chunckSize; 261 | } 262 | 263 | // tell server 264 | cubesql_send_enddata(db.ref); 265 | } 266 | 267 | - (void)displayError:(NSString *)error { 268 | NSAlert *alert = [[NSAlert alloc] init]; 269 | [alert setMessageText:error]; 270 | [alert beginSheetModalForWindow:_window completionHandler:nil]; 271 | } 272 | 273 | @end 274 | -------------------------------------------------------------------------------- /Sample/MacOS/Files API/cubeSQLTest/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /Sample/MacOS/Files API/cubeSQLTest/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Sample/MacOS/Files API/cubeSQLTest/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // cubeSQLTest 4 | // 5 | // Created by Marco Bambini on 04/09/2018. 6 | // Copyright © 2018 SQLabs. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, const char * argv[]) { 12 | return NSApplicationMain(argc, argv); 13 | } 14 | -------------------------------------------------------------------------------- /Sample/invoice.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cubesql/sdk/e461ea2b379d39a5fbc9f4a08b964618c9ae7667/Sample/invoice.sqlite -------------------------------------------------------------------------------- /SharedLibrary/Makefile: -------------------------------------------------------------------------------- 1 | SDKDIR = ../C_SDK 2 | CRYPTDIR = ../C_SDK/crypt 3 | SRCDIR = .. 4 | INCLUDE = -I$(SRCDIR) -I$(SDKDIR)/ -I$(CRYPTDIR)/ 5 | 6 | CC = gcc 7 | LD = gcc 8 | CFLAGS = $(INCLUDE) -O2 9 | LDFLAGS = -shared -lz 10 | RM = /bin/rm -f 11 | UNAME := $(shell uname) 12 | 13 | OBJS = cubesql.o pseudorandom.o aescrypt.o aeskey.o aestab.o base64.o sha1.o 14 | PROG = libcubesql.so 15 | ifeq ($(UNAME), Darwin) 16 | PROG = libcubesql.dylib 17 | endif 18 | 19 | all: ${PROG} 20 | 21 | ${PROG}: ${OBJS} 22 | ${LD} ${LDFLAGS} ${OBJS} -o ${PROG} 23 | 24 | cubesql.o: $(SDKDIR)/cubesql.c 25 | ${CC} $(CFLAGS) -c $< -o $@ 26 | 27 | %.o: $(CRYPTDIR)/%.c 28 | ${CC} $(CFLAGS) -c $< -o $@ 29 | 30 | clean: 31 | ${RM} ${PROG} ${OBJS} 32 | -------------------------------------------------------------------------------- /SharedLibrary/libcubesql.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cubesql/sdk/e461ea2b379d39a5fbc9f4a08b964618c9ae7667/SharedLibrary/libcubesql.dylib -------------------------------------------------------------------------------- /Xojo/Sample/FilesAPI.rbp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cubesql/sdk/e461ea2b379d39a5fbc9f4a08b964618c9ae7667/Xojo/Sample/FilesAPI.rbp -------------------------------------------------------------------------------- /libs/linux-64/libtls.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cubesql/sdk/e461ea2b379d39a5fbc9f4a08b964618c9ae7667/libs/linux-64/libtls.a -------------------------------------------------------------------------------- /libs/linux-64/libtls_asm.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cubesql/sdk/e461ea2b379d39a5fbc9f4a08b964618c9ae7667/libs/linux-64/libtls_asm.a -------------------------------------------------------------------------------- /libs/linux-arm/libtls.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cubesql/sdk/e461ea2b379d39a5fbc9f4a08b964618c9ae7667/libs/linux-arm/libtls.a -------------------------------------------------------------------------------- /libs/linux/libtls.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cubesql/sdk/e461ea2b379d39a5fbc9f4a08b964618c9ae7667/libs/linux/libtls.a -------------------------------------------------------------------------------- /libs/macOS/libtls.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cubesql/sdk/e461ea2b379d39a5fbc9f4a08b964618c9ae7667/libs/macOS/libtls.a -------------------------------------------------------------------------------- /libs/win-32bit/tls.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cubesql/sdk/e461ea2b379d39a5fbc9f4a08b964618c9ae7667/libs/win-32bit/tls.lib -------------------------------------------------------------------------------- /libs/win-64bit/tls.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cubesql/sdk/e461ea2b379d39a5fbc9f4a08b964618c9ae7667/libs/win-64bit/tls.lib --------------------------------------------------------------------------------