1 /* 2 * Copyright (C) 2013-2015 Marc Hoersken <info@marc-hoersken.de> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, 6 * with or without modification, are permitted provided 7 * that the following conditions are met: 8 * 9 * Redistributions of source code must retain the above 10 * copyright notice, this list of conditions and the 11 * following disclaimer. 12 * 13 * Redistributions in binary form must reproduce the above 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials 16 * provided with the distribution. 17 * 18 * Neither the name of the copyright holder nor the names 19 * of any other contributors may be used to endorse or 20 * promote products derived from this software without 21 * specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 33 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 35 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 36 * OF SUCH DAMAGE. 37 */ 38 39 /* required for cross-compilation against the w64 mingw-runtime package */ 40 #if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600) 41 #undef _WIN32_WINNT 42 #endif 43 #ifndef _WIN32_WINNT 44 #define _WIN32_WINNT 0x0600 45 #endif 46 47 #include <windows.h> 48 #include <bcrypt.h> 49 50 51 #define LIBSSH2_MD5 1 52 53 #define LIBSSH2_HMAC_RIPEMD 0 54 #define LIBSSH2_HMAC_SHA256 1 55 #define LIBSSH2_HMAC_SHA512 1 56 57 #define LIBSSH2_AES 1 58 #define LIBSSH2_AES_CTR 1 59 #define LIBSSH2_BLOWFISH 0 60 #define LIBSSH2_RC4 1 61 #define LIBSSH2_CAST 0 62 #define LIBSSH2_3DES 1 63 64 #define LIBSSH2_RSA 1 65 #define LIBSSH2_DSA 1 66 #define LIBSSH2_ECDSA 0 67 #define LIBSSH2_ED25519 0 68 69 #define MD5_DIGEST_LENGTH 16 70 #define SHA_DIGEST_LENGTH 20 71 #define SHA256_DIGEST_LENGTH 32 72 #define SHA512_DIGEST_LENGTH 64 73 74 #define EC_MAX_POINT_LEN ((528 * 2 / 8) + 1) 75 76 #if LIBSSH2_ECDSA 77 #else 78 #define _libssh2_ec_key void 79 #endif 80 81 /*******************************************************************/ 82 /* 83 * Windows CNG backend: Global context handles 84 */ 85 86 struct _libssh2_wincng_ctx { 87 BCRYPT_ALG_HANDLE hAlgRNG; 88 BCRYPT_ALG_HANDLE hAlgHashMD5; 89 BCRYPT_ALG_HANDLE hAlgHashSHA1; 90 BCRYPT_ALG_HANDLE hAlgHashSHA256; 91 BCRYPT_ALG_HANDLE hAlgHashSHA512; 92 BCRYPT_ALG_HANDLE hAlgHmacMD5; 93 BCRYPT_ALG_HANDLE hAlgHmacSHA1; 94 BCRYPT_ALG_HANDLE hAlgHmacSHA256; 95 BCRYPT_ALG_HANDLE hAlgHmacSHA512; 96 BCRYPT_ALG_HANDLE hAlgRSA; 97 BCRYPT_ALG_HANDLE hAlgDSA; 98 BCRYPT_ALG_HANDLE hAlgAES_CBC; 99 BCRYPT_ALG_HANDLE hAlgAES_ECB; 100 BCRYPT_ALG_HANDLE hAlgRC4_NA; 101 BCRYPT_ALG_HANDLE hAlg3DES_CBC; 102 }; 103 104 struct _libssh2_wincng_ctx _libssh2_wincng; 105 106 107 /*******************************************************************/ 108 /* 109 * Windows CNG backend: Generic functions 110 */ 111 112 void _libssh2_wincng_init(void); 113 void _libssh2_wincng_free(void); 114 115 #define libssh2_crypto_init() \ 116 _libssh2_wincng_init() 117 #define libssh2_crypto_exit() \ 118 _libssh2_wincng_free() 119 120 #define _libssh2_random(buf, len) \ 121 _libssh2_wincng_random(buf, len) 122 123 #define libssh2_prepare_iovec(vec, len) /* Empty. */ 124 125 126 /*******************************************************************/ 127 /* 128 * Windows CNG backend: Hash structure 129 */ 130 131 typedef struct __libssh2_wincng_hash_ctx { 132 BCRYPT_HASH_HANDLE hHash; 133 unsigned char *pbHashObject; 134 unsigned long dwHashObject; 135 unsigned long cbHash; 136 } _libssh2_wincng_hash_ctx; 137 138 /* 139 * Windows CNG backend: Hash functions 140 */ 141 142 #define libssh2_sha1_ctx _libssh2_wincng_hash_ctx 143 #define libssh2_sha1_init(ctx) \ 144 (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA1, \ 145 SHA_DIGEST_LENGTH, NULL, 0) == 0) 146 #define libssh2_sha1_update(ctx, data, datalen) \ 147 _libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) 148 #define libssh2_sha1_final(ctx, hash) \ 149 _libssh2_wincng_hash_final(&ctx, hash) 150 #define libssh2_sha1(data, datalen, hash) \ 151 _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA1, \ 152 hash, SHA_DIGEST_LENGTH) 153 154 #define libssh2_sha256_ctx _libssh2_wincng_hash_ctx 155 #define libssh2_sha256_init(ctx) \ 156 (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA256, \ 157 SHA256_DIGEST_LENGTH, NULL, 0) == 0) 158 #define libssh2_sha256_update(ctx, data, datalen) \ 159 _libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) 160 #define libssh2_sha256_final(ctx, hash) \ 161 _libssh2_wincng_hash_final(&ctx, hash) 162 #define libssh2_sha256(data, datalen, hash) \ 163 _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA256, \ 164 hash, SHA256_DIGEST_LENGTH) 165 166 #define libssh2_sha512_ctx _libssh2_wincng_hash_ctx 167 #define libssh2_sha512_init(ctx) \ 168 (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashSHA512, \ 169 SHA512_DIGEST_LENGTH, NULL, 0) == 0) 170 #define libssh2_sha512_update(ctx, data, datalen) \ 171 _libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) 172 #define libssh2_sha512_final(ctx, hash) \ 173 _libssh2_wincng_hash_final(&ctx, hash) 174 #define libssh2_sha512(data, datalen, hash) \ 175 _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashSHA512, \ 176 hash, SHA512_DIGEST_LENGTH) 177 178 #define libssh2_md5_ctx _libssh2_wincng_hash_ctx 179 #define libssh2_md5_init(ctx) \ 180 (_libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHashMD5, \ 181 MD5_DIGEST_LENGTH, NULL, 0) == 0) 182 #define libssh2_md5_update(ctx, data, datalen) \ 183 _libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) 184 #define libssh2_md5_final(ctx, hash) \ 185 _libssh2_wincng_hash_final(&ctx, hash) 186 #define libssh2_md5(data, datalen, hash) \ 187 _libssh2_wincng_hash(data, datalen, _libssh2_wincng.hAlgHashMD5, \ 188 hash, MD5_DIGEST_LENGTH) 189 190 /* 191 * Windows CNG backend: HMAC functions 192 */ 193 194 #define libssh2_hmac_ctx _libssh2_wincng_hash_ctx 195 #define libssh2_hmac_ctx_init(ctx) 196 #define libssh2_hmac_sha1_init(ctx, key, keylen) \ 197 _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA1, \ 198 SHA_DIGEST_LENGTH, key, keylen) 199 #define libssh2_hmac_md5_init(ctx, key, keylen) \ 200 _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacMD5, \ 201 MD5_DIGEST_LENGTH, key, keylen) 202 #define libssh2_hmac_ripemd160_init(ctx, key, keylen) 203 /* not implemented */ 204 #define libssh2_hmac_sha256_init(ctx, key, keylen) \ 205 _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA256, \ 206 SHA256_DIGEST_LENGTH, key, keylen) 207 #define libssh2_hmac_sha512_init(ctx, key, keylen) \ 208 _libssh2_wincng_hash_init(ctx, _libssh2_wincng.hAlgHmacSHA512, \ 209 SHA512_DIGEST_LENGTH, key, keylen) 210 #define libssh2_hmac_update(ctx, data, datalen) \ 211 _libssh2_wincng_hash_update(&ctx, (unsigned char *) data, datalen) 212 #define libssh2_hmac_final(ctx, hash) \ 213 _libssh2_wincng_hmac_final(&ctx, hash) 214 #define libssh2_hmac_cleanup(ctx) \ 215 _libssh2_wincng_hmac_cleanup(ctx) 216 217 218 /*******************************************************************/ 219 /* 220 * Windows CNG backend: Key Context structure 221 */ 222 223 typedef struct __libssh2_wincng_key_ctx { 224 BCRYPT_KEY_HANDLE hKey; 225 unsigned char *pbKeyObject; 226 unsigned long cbKeyObject; 227 } _libssh2_wincng_key_ctx; 228 229 230 /* 231 * Windows CNG backend: RSA functions 232 */ 233 234 #define libssh2_rsa_ctx _libssh2_wincng_key_ctx 235 #define _libssh2_rsa_new(rsactx, e, e_len, n, n_len, \ 236 d, d_len, p, p_len, q, q_len, \ 237 e1, e1_len, e2, e2_len, c, c_len) \ 238 _libssh2_wincng_rsa_new(rsactx, e, e_len, n, n_len, \ 239 d, d_len, p, p_len, q, q_len, \ 240 e1, e1_len, e2, e2_len, c, c_len) 241 #define _libssh2_rsa_new_private(rsactx, s, filename, passphrase) \ 242 _libssh2_wincng_rsa_new_private(rsactx, s, filename, passphrase) 243 #define _libssh2_rsa_new_private_frommemory(rsactx, s, filedata, \ 244 filedata_len, passphrase) \ 245 _libssh2_wincng_rsa_new_private_frommemory(rsactx, s, filedata, \ 246 filedata_len, passphrase) 247 #define _libssh2_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) \ 248 _libssh2_wincng_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) 249 #define _libssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) \ 250 _libssh2_wincng_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) 251 #define _libssh2_rsa_free(rsactx) \ 252 _libssh2_wincng_rsa_free(rsactx) 253 254 /* 255 * Windows CNG backend: DSA functions 256 */ 257 258 #define libssh2_dsa_ctx _libssh2_wincng_key_ctx 259 #define _libssh2_dsa_new(dsactx, p, p_len, q, q_len, \ 260 g, g_len, y, y_len, x, x_len) \ 261 _libssh2_wincng_dsa_new(dsactx, p, p_len, q, q_len, \ 262 g, g_len, y, y_len, x, x_len) 263 #define _libssh2_dsa_new_private(dsactx, s, filename, passphrase) \ 264 _libssh2_wincng_dsa_new_private(dsactx, s, filename, passphrase) 265 #define _libssh2_dsa_new_private_frommemory(dsactx, s, filedata, \ 266 filedata_len, passphrase) \ 267 _libssh2_wincng_dsa_new_private_frommemory(dsactx, s, filedata, \ 268 filedata_len, passphrase) 269 #define _libssh2_dsa_sha1_sign(dsactx, hash, hash_len, sig) \ 270 _libssh2_wincng_dsa_sha1_sign(dsactx, hash, hash_len, sig) 271 #define _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len) \ 272 _libssh2_wincng_dsa_sha1_verify(dsactx, sig, m, m_len) 273 #define _libssh2_dsa_free(dsactx) \ 274 _libssh2_wincng_dsa_free(dsactx) 275 276 /* 277 * Windows CNG backend: Key functions 278 */ 279 280 #define _libssh2_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) \ 281 _libssh2_wincng_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) 282 #define _libssh2_pub_priv_keyfilememory(s, m, m_len, p, p_len, \ 283 pk, pk_len, pw) \ 284 _libssh2_wincng_pub_priv_keyfilememory(s, m, m_len, p, p_len, \ 285 pk, pk_len, pw) 286 287 288 /*******************************************************************/ 289 /* 290 * Windows CNG backend: Cipher Context structure 291 */ 292 293 struct _libssh2_wincng_cipher_ctx { 294 BCRYPT_KEY_HANDLE hKey; 295 unsigned char *pbKeyObject; 296 unsigned char *pbIV; 297 unsigned char *pbCtr; 298 unsigned long dwKeyObject; 299 unsigned long dwIV; 300 unsigned long dwBlockLength; 301 unsigned long dwCtrLength; 302 }; 303 304 #define _libssh2_cipher_ctx struct _libssh2_wincng_cipher_ctx 305 306 /* 307 * Windows CNG backend: Cipher Type structure 308 */ 309 310 struct _libssh2_wincng_cipher_type { 311 BCRYPT_ALG_HANDLE *phAlg; 312 unsigned long dwKeyLength; 313 int useIV; /* TODO: Convert to bool when a C89 compatible bool type 314 is defined */ 315 int ctrMode; 316 }; 317 318 #define _libssh2_cipher_type(type) struct _libssh2_wincng_cipher_type type 319 320 #define _libssh2_cipher_aes256ctr { &_libssh2_wincng.hAlgAES_ECB, 32, 0, 1 } 321 #define _libssh2_cipher_aes192ctr { &_libssh2_wincng.hAlgAES_ECB, 24, 0, 1 } 322 #define _libssh2_cipher_aes128ctr { &_libssh2_wincng.hAlgAES_ECB, 16, 0, 1 } 323 #define _libssh2_cipher_aes256 { &_libssh2_wincng.hAlgAES_CBC, 32, 1, 0 } 324 #define _libssh2_cipher_aes192 { &_libssh2_wincng.hAlgAES_CBC, 24, 1, 0 } 325 #define _libssh2_cipher_aes128 { &_libssh2_wincng.hAlgAES_CBC, 16, 1, 0 } 326 #define _libssh2_cipher_arcfour { &_libssh2_wincng.hAlgRC4_NA, 16, 0, 0 } 327 #define _libssh2_cipher_3des { &_libssh2_wincng.hAlg3DES_CBC, 24, 1, 0 } 328 329 /* 330 * Windows CNG backend: Cipher functions 331 */ 332 333 #define _libssh2_cipher_init(ctx, type, iv, secret, encrypt) \ 334 _libssh2_wincng_cipher_init(ctx, type, iv, secret, encrypt) 335 #define _libssh2_cipher_crypt(ctx, type, encrypt, block, blocklen) \ 336 _libssh2_wincng_cipher_crypt(ctx, type, encrypt, block, blocklen) 337 #define _libssh2_cipher_dtor(ctx) \ 338 _libssh2_wincng_cipher_dtor(ctx) 339 340 /*******************************************************************/ 341 /* 342 * Windows CNG backend: BigNumber Context 343 */ 344 345 #define _libssh2_bn_ctx int /* not used */ 346 #define _libssh2_bn_ctx_new() 0 /* not used */ 347 #define _libssh2_bn_ctx_free(bnctx) ((void)0) /* not used */ 348 349 350 /*******************************************************************/ 351 /* 352 * Windows CNG backend: BigNumber structure 353 */ 354 355 struct _libssh2_wincng_bignum { 356 unsigned char *bignum; 357 unsigned long length; 358 }; 359 360 #define _libssh2_bn struct _libssh2_wincng_bignum 361 362 /* 363 * Windows CNG backend: BigNumber functions 364 */ 365 366 _libssh2_bn *_libssh2_wincng_bignum_init(void); 367 368 #define _libssh2_bn_init() \ 369 _libssh2_wincng_bignum_init() 370 #define _libssh2_bn_init_from_bin() \ 371 _libssh2_bn_init() 372 #define _libssh2_bn_set_word(bn, word) \ 373 _libssh2_wincng_bignum_set_word(bn, word) 374 #define _libssh2_bn_from_bin(bn, len, bin) \ 375 _libssh2_wincng_bignum_from_bin(bn, len, bin) 376 #define _libssh2_bn_to_bin(bn, bin) \ 377 _libssh2_wincng_bignum_to_bin(bn, bin) 378 #define _libssh2_bn_bytes(bn) bn->length 379 #define _libssh2_bn_bits(bn) \ 380 _libssh2_wincng_bignum_bits(bn) 381 #define _libssh2_bn_free(bn) \ 382 _libssh2_wincng_bignum_free(bn) 383 384 /* 385 * Windows CNG backend: Diffie-Hellman support 386 */ 387 388 #define _libssh2_dh_ctx struct _libssh2_wincng_bignum * 389 #define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx) 390 #define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \ 391 _libssh2_dh_key_pair(dhctx, public, g, p, group_order) 392 #define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \ 393 _libssh2_dh_secret(dhctx, secret, f, p) 394 #define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx) 395 396 /*******************************************************************/ 397 /* 398 * Windows CNG backend: forward declarations 399 */ 400 void _libssh2_wincng_init(void); 401 void _libssh2_wincng_free(void); 402 int _libssh2_wincng_random(void *buf, int len); 403 404 int 405 _libssh2_wincng_hash_init(_libssh2_wincng_hash_ctx *ctx, 406 BCRYPT_ALG_HANDLE hAlg, unsigned long hashlen, 407 unsigned char *key, unsigned long keylen); 408 int 409 _libssh2_wincng_hash_update(_libssh2_wincng_hash_ctx *ctx, 410 const unsigned char *data, unsigned long datalen); 411 int 412 _libssh2_wincng_hash_final(_libssh2_wincng_hash_ctx *ctx, 413 unsigned char *hash); 414 int 415 _libssh2_wincng_hash(unsigned char *data, unsigned long datalen, 416 BCRYPT_ALG_HANDLE hAlg, 417 unsigned char *hash, unsigned long hashlen); 418 419 int 420 _libssh2_wincng_hmac_final(_libssh2_wincng_hash_ctx *ctx, 421 unsigned char *hash); 422 void 423 _libssh2_wincng_hmac_cleanup(_libssh2_wincng_hash_ctx *ctx); 424 425 int 426 _libssh2_wincng_key_sha1_verify(_libssh2_wincng_key_ctx *ctx, 427 const unsigned char *sig, 428 unsigned long sig_len, 429 const unsigned char *m, 430 unsigned long m_len, 431 unsigned long flags); 432 433 int 434 _libssh2_wincng_rsa_new(libssh2_rsa_ctx **rsa, 435 const unsigned char *edata, 436 unsigned long elen, 437 const unsigned char *ndata, 438 unsigned long nlen, 439 const unsigned char *ddata, 440 unsigned long dlen, 441 const unsigned char *pdata, 442 unsigned long plen, 443 const unsigned char *qdata, 444 unsigned long qlen, 445 const unsigned char *e1data, 446 unsigned long e1len, 447 const unsigned char *e2data, 448 unsigned long e2len, 449 const unsigned char *coeffdata, 450 unsigned long coefflen); 451 int 452 _libssh2_wincng_rsa_new_private(libssh2_rsa_ctx **rsa, 453 LIBSSH2_SESSION *session, 454 const char *filename, 455 const unsigned char *passphrase); 456 int 457 _libssh2_wincng_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, 458 LIBSSH2_SESSION *session, 459 const char *filedata, 460 size_t filedata_len, 461 unsigned const char *passphrase); 462 int 463 _libssh2_wincng_rsa_sha1_verify(libssh2_rsa_ctx *rsa, 464 const unsigned char *sig, 465 unsigned long sig_len, 466 const unsigned char *m, 467 unsigned long m_len); 468 int 469 _libssh2_wincng_rsa_sha1_sign(LIBSSH2_SESSION *session, 470 libssh2_rsa_ctx *rsa, 471 const unsigned char *hash, 472 size_t hash_len, 473 unsigned char **signature, 474 size_t *signature_len); 475 void 476 _libssh2_wincng_rsa_free(libssh2_rsa_ctx *rsa); 477 478 #if LIBSSH2_DSA 479 int 480 _libssh2_wincng_dsa_new(libssh2_dsa_ctx **dsa, 481 const unsigned char *pdata, 482 unsigned long plen, 483 const unsigned char *qdata, 484 unsigned long qlen, 485 const unsigned char *gdata, 486 unsigned long glen, 487 const unsigned char *ydata, 488 unsigned long ylen, 489 const unsigned char *xdata, 490 unsigned long xlen); 491 int 492 _libssh2_wincng_dsa_new_private(libssh2_dsa_ctx **dsa, 493 LIBSSH2_SESSION *session, 494 const char *filename, 495 const unsigned char *passphrase); 496 int 497 _libssh2_wincng_dsa_new_private_frommemory(libssh2_dsa_ctx **dsa, 498 LIBSSH2_SESSION *session, 499 const char *filedata, 500 size_t filedata_len, 501 unsigned const char *passphrase); 502 int 503 _libssh2_wincng_dsa_sha1_verify(libssh2_dsa_ctx *dsa, 504 const unsigned char *sig_fixed, 505 const unsigned char *m, 506 unsigned long m_len); 507 int 508 _libssh2_wincng_dsa_sha1_sign(libssh2_dsa_ctx *dsa, 509 const unsigned char *hash, 510 unsigned long hash_len, 511 unsigned char *sig_fixed); 512 void 513 _libssh2_wincng_dsa_free(libssh2_dsa_ctx *dsa); 514 #endif 515 516 int 517 _libssh2_wincng_pub_priv_keyfile(LIBSSH2_SESSION *session, 518 unsigned char **method, 519 size_t *method_len, 520 unsigned char **pubkeydata, 521 size_t *pubkeydata_len, 522 const char *privatekey, 523 const char *passphrase); 524 int 525 _libssh2_wincng_pub_priv_keyfilememory(LIBSSH2_SESSION *session, 526 unsigned char **method, 527 size_t *method_len, 528 unsigned char **pubkeydata, 529 size_t *pubkeydata_len, 530 const char *privatekeydata, 531 size_t privatekeydata_len, 532 const char *passphrase); 533 534 int 535 _libssh2_wincng_cipher_init(_libssh2_cipher_ctx *ctx, 536 _libssh2_cipher_type(type), 537 unsigned char *iv, 538 unsigned char *secret, 539 int encrypt); 540 int 541 _libssh2_wincng_cipher_crypt(_libssh2_cipher_ctx *ctx, 542 _libssh2_cipher_type(type), 543 int encrypt, 544 unsigned char *block, 545 size_t blocklen); 546 void 547 _libssh2_wincng_cipher_dtor(_libssh2_cipher_ctx *ctx); 548 549 _libssh2_bn * 550 _libssh2_wincng_bignum_init(void); 551 int 552 _libssh2_wincng_bignum_set_word(_libssh2_bn *bn, unsigned long word); 553 unsigned long 554 _libssh2_wincng_bignum_bits(const _libssh2_bn *bn); 555 void 556 _libssh2_wincng_bignum_from_bin(_libssh2_bn *bn, unsigned long len, 557 const unsigned char *bin); 558 void 559 _libssh2_wincng_bignum_to_bin(const _libssh2_bn *bn, unsigned char *bin); 560 void 561 _libssh2_wincng_bignum_free(_libssh2_bn *bn); 562 extern void 563 _libssh2_dh_init(_libssh2_dh_ctx *dhctx); 564 extern int 565 _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, 566 _libssh2_bn *g, _libssh2_bn *p, int group_order); 567 extern int 568 _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, 569 _libssh2_bn *f, _libssh2_bn *p); 570 extern void 571 _libssh2_dh_dtor(_libssh2_dh_ctx *dhctx); 572