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