1 #ifndef __LIBSSH2_MBEDTLS_H 2 #define __LIBSSH2_MBEDTLS_H 3 /* Copyright (c) 2016, Art <https://github.com/wildart> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, 7 * with or without modification, are permitted provided 8 * that the following conditions are met: 9 * 10 * Redistributions of source code must retain the above 11 * copyright notice, this list of conditions and the 12 * following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above 15 * copyright notice, this list of conditions and the following 16 * disclaimer in the documentation and/or other materials 17 * provided with the distribution. 18 * 19 * Neither the name of the copyright holder nor the names 20 * of any other contributors may be used to endorse or 21 * promote products derived from this software without 22 * specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 25 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 26 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 34 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 36 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 37 * OF SUCH DAMAGE. 38 */ 39 40 #include <stdlib.h> 41 #include <string.h> 42 43 #include <mbedtls/platform.h> 44 #include <mbedtls/md.h> 45 #include <mbedtls/rsa.h> 46 #include <mbedtls/bignum.h> 47 #include <mbedtls/cipher.h> 48 #ifdef MBEDTLS_ECDH_C 49 # include <mbedtls/ecdh.h> 50 #endif 51 #ifdef MBEDTLS_ECDSA_C 52 # include <mbedtls/ecdsa.h> 53 #endif 54 #include <mbedtls/entropy.h> 55 #include <mbedtls/ctr_drbg.h> 56 #include <mbedtls/pk.h> 57 #include <mbedtls/error.h> 58 59 /* Define which features are supported. */ 60 #define LIBSSH2_MD5 1 61 62 #define LIBSSH2_HMAC_RIPEMD 1 63 #define LIBSSH2_HMAC_SHA256 1 64 #define LIBSSH2_HMAC_SHA512 1 65 66 #define LIBSSH2_AES 1 67 #define LIBSSH2_AES_CTR 1 68 #define LIBSSH2_BLOWFISH 1 69 #define LIBSSH2_RC4 1 70 #define LIBSSH2_CAST 0 71 #define LIBSSH2_3DES 1 72 73 #define LIBSSH2_RSA 1 74 #define LIBSSH2_DSA 0 75 #ifdef MBEDTLS_ECDSA_C 76 # define LIBSSH2_ECDSA 1 77 #else 78 # define LIBSSH2_ECDSA 0 79 #endif 80 #define LIBSSH2_ED25519 0 81 82 #define MD5_DIGEST_LENGTH 16 83 #define SHA_DIGEST_LENGTH 20 84 #define SHA256_DIGEST_LENGTH 32 85 #define SHA384_DIGEST_LENGTH 48 86 #define SHA512_DIGEST_LENGTH 64 87 88 #define EC_MAX_POINT_LEN ((528 * 2 / 8) + 1) 89 90 91 /*******************************************************************/ 92 /* 93 * mbedTLS backend: Generic functions 94 */ 95 96 #define libssh2_crypto_init() \ 97 _libssh2_mbedtls_init() 98 #define libssh2_crypto_exit() \ 99 _libssh2_mbedtls_free() 100 101 #define _libssh2_random(buf, len) \ 102 _libssh2_mbedtls_random(buf, len) 103 104 #define libssh2_prepare_iovec(vec, len) /* Empty. */ 105 106 107 /*******************************************************************/ 108 /* 109 * mbedTLS backend: HMAC functions 110 */ 111 112 #define libssh2_hmac_ctx mbedtls_md_context_t 113 114 #define libssh2_hmac_ctx_init(ctx) 115 #define libssh2_hmac_cleanup(pctx) \ 116 mbedtls_md_free(pctx) 117 #define libssh2_hmac_update(ctx, data, datalen) \ 118 mbedtls_md_hmac_update(&ctx, (unsigned char *) data, datalen) 119 #define libssh2_hmac_final(ctx, hash) \ 120 mbedtls_md_hmac_finish(&ctx, hash) 121 122 #define libssh2_hmac_sha1_init(pctx, key, keylen) \ 123 _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA1, key, keylen) 124 #define libssh2_hmac_md5_init(pctx, key, keylen) \ 125 _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_MD5, key, keylen) 126 #define libssh2_hmac_ripemd160_init(pctx, key, keylen) \ 127 _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_RIPEMD160, key, keylen) 128 #define libssh2_hmac_sha256_init(pctx, key, keylen) \ 129 _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA256, key, keylen) 130 #define libssh2_hmac_sha384_init(pctx, key, keylen) \ 131 _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA384, key, keylen) 132 #define libssh2_hmac_sha512_init(pctx, key, keylen) \ 133 _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA512, key, keylen) 134 135 136 /*******************************************************************/ 137 /* 138 * mbedTLS backend: SHA1 functions 139 */ 140 141 #define libssh2_sha1_ctx mbedtls_md_context_t 142 143 #define libssh2_sha1_init(pctx) \ 144 _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA1, NULL, 0) 145 #define libssh2_sha1_update(ctx, data, datalen) \ 146 mbedtls_md_update(&ctx, (unsigned char *) data, datalen) 147 #define libssh2_sha1_final(ctx, hash) \ 148 _libssh2_mbedtls_hash_final(&ctx, hash) 149 #define libssh2_sha1(data, datalen, hash) \ 150 _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA1, hash) 151 152 /*******************************************************************/ 153 /* 154 * mbedTLS backend: SHA256 functions 155 */ 156 157 #define libssh2_sha256_ctx mbedtls_md_context_t 158 159 #define libssh2_sha256_init(pctx) \ 160 _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA256, NULL, 0) 161 #define libssh2_sha256_update(ctx, data, datalen) \ 162 mbedtls_md_update(&ctx, (unsigned char *) data, datalen) 163 #define libssh2_sha256_final(ctx, hash) \ 164 _libssh2_mbedtls_hash_final(&ctx, hash) 165 #define libssh2_sha256(data, datalen, hash) \ 166 _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA256, hash) 167 168 169 /*******************************************************************/ 170 /* 171 * mbedTLS backend: SHA384 functions 172 */ 173 174 #define libssh2_sha384_ctx mbedtls_md_context_t 175 176 #define libssh2_sha384_init(pctx) \ 177 _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA384, NULL, 0) 178 #define libssh2_sha384_update(ctx, data, datalen) \ 179 mbedtls_md_update(&ctx, (unsigned char *) data, datalen) 180 #define libssh2_sha384_final(ctx, hash) \ 181 _libssh2_mbedtls_hash_final(&ctx, hash) 182 #define libssh2_sha384(data, datalen, hash) \ 183 _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA384, hash) 184 185 186 /*******************************************************************/ 187 /* 188 * mbedTLS backend: SHA512 functions 189 */ 190 191 #define libssh2_sha512_ctx mbedtls_md_context_t 192 193 #define libssh2_sha512_init(pctx) \ 194 _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA512, NULL, 0) 195 #define libssh2_sha512_update(ctx, data, datalen) \ 196 mbedtls_md_update(&ctx, (unsigned char *) data, datalen) 197 #define libssh2_sha512_final(ctx, hash) \ 198 _libssh2_mbedtls_hash_final(&ctx, hash) 199 #define libssh2_sha512(data, datalen, hash) \ 200 _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA512, hash) 201 202 203 /*******************************************************************/ 204 /* 205 * mbedTLS backend: MD5 functions 206 */ 207 208 #define libssh2_md5_ctx mbedtls_md_context_t 209 210 #define libssh2_md5_init(pctx) \ 211 _libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_MD5, NULL, 0) 212 #define libssh2_md5_update(ctx, data, datalen) \ 213 mbedtls_md_update(&ctx, (unsigned char *) data, datalen) 214 #define libssh2_md5_final(ctx, hash) \ 215 _libssh2_mbedtls_hash_final(&ctx, hash) 216 #define libssh2_md5(data, datalen, hash) \ 217 _libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_MD5, hash) 218 219 220 /*******************************************************************/ 221 /* 222 * mbedTLS backend: RSA functions 223 */ 224 225 #define libssh2_rsa_ctx mbedtls_rsa_context 226 227 #define _libssh2_rsa_new(rsactx, e, e_len, n, n_len, \ 228 d, d_len, p, p_len, q, q_len, \ 229 e1, e1_len, e2, e2_len, c, c_len) \ 230 _libssh2_mbedtls_rsa_new(rsactx, e, e_len, n, n_len, \ 231 d, d_len, p, p_len, q, q_len, \ 232 e1, e1_len, e2, e2_len, c, c_len) 233 234 #define _libssh2_rsa_new_private(rsactx, s, filename, passphrase) \ 235 _libssh2_mbedtls_rsa_new_private(rsactx, s, filename, passphrase) 236 237 #define _libssh2_rsa_new_private_frommemory(rsactx, s, filedata, \ 238 filedata_len, passphrase) \ 239 _libssh2_mbedtls_rsa_new_private_frommemory(rsactx, s, filedata, \ 240 filedata_len, passphrase) 241 242 #define _libssh2_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) \ 243 _libssh2_mbedtls_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) 244 245 #define _libssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) \ 246 _libssh2_mbedtls_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) 247 248 #define _libssh2_rsa_free(rsactx) \ 249 _libssh2_mbedtls_rsa_free(rsactx) 250 251 252 /*******************************************************************/ 253 /* 254 * mbedTLS backend: ECDSA structures 255 */ 256 257 #if LIBSSH2_ECDSA 258 259 typedef enum { 260 #ifdef MBEDTLS_ECP_DP_SECP256R1_ENABLED 261 LIBSSH2_EC_CURVE_NISTP256 = MBEDTLS_ECP_DP_SECP256R1, 262 #else 263 LIBSSH2_EC_CURVE_NISTP256 = MBEDTLS_ECP_DP_NONE, 264 #endif 265 #ifdef MBEDTLS_ECP_DP_SECP384R1_ENABLED 266 LIBSSH2_EC_CURVE_NISTP384 = MBEDTLS_ECP_DP_SECP384R1, 267 #else 268 LIBSSH2_EC_CURVE_NISTP384 = MBEDTLS_ECP_DP_NONE, 269 #endif 270 #ifdef MBEDTLS_ECP_DP_SECP521R1_ENABLED 271 LIBSSH2_EC_CURVE_NISTP521 = MBEDTLS_ECP_DP_SECP521R1 272 #else 273 LIBSSH2_EC_CURVE_NISTP521 = MBEDTLS_ECP_DP_NONE, 274 #endif 275 } libssh2_curve_type; 276 277 # define _libssh2_ec_key mbedtls_ecp_keypair 278 #else 279 # define _libssh2_ec_key void 280 #endif /* LIBSSH2_ECDSA */ 281 282 283 /*******************************************************************/ 284 /* 285 * mbedTLS backend: ECDSA functions 286 */ 287 288 #if LIBSSH2_ECDSA 289 290 #define libssh2_ecdsa_ctx mbedtls_ecdsa_context 291 292 #define _libssh2_ecdsa_create_key(session, privkey, pubkey_octal, \ 293 pubkey_octal_len, curve) \ 294 _libssh2_mbedtls_ecdsa_create_key(session, privkey, pubkey_octal, \ 295 pubkey_octal_len, curve) 296 297 #define _libssh2_ecdsa_curve_name_with_octal_new(ctx, k, k_len, curve) \ 298 _libssh2_mbedtls_ecdsa_curve_name_with_octal_new(ctx, k, k_len, curve) 299 300 #define _libssh2_ecdh_gen_k(k, privkey, server_pubkey, server_pubkey_len) \ 301 _libssh2_mbedtls_ecdh_gen_k(k, privkey, server_pubkey, server_pubkey_len) 302 303 #define _libssh2_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len) \ 304 _libssh2_mbedtls_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len) 305 306 #define _libssh2_ecdsa_new_private(ctx, session, filename, passphrase) \ 307 _libssh2_mbedtls_ecdsa_new_private(ctx, session, filename, passphrase) 308 309 #define _libssh2_ecdsa_new_private_frommemory(ctx, session, filedata, \ 310 filedata_len, passphrase) \ 311 _libssh2_mbedtls_ecdsa_new_private_frommemory(ctx, session, filedata, \ 312 filedata_len, passphrase) 313 314 #define _libssh2_ecdsa_sign(session, ctx, hash, hash_len, sign, sign_len) \ 315 _libssh2_mbedtls_ecdsa_sign(session, ctx, hash, hash_len, sign, sign_len) 316 317 #define _libssh2_ecdsa_get_curve_type(ctx) \ 318 _libssh2_mbedtls_ecdsa_get_curve_type(ctx) 319 320 #define _libssh2_ecdsa_free(ctx) \ 321 _libssh2_mbedtls_ecdsa_free(ctx) 322 323 #endif /* LIBSSH2_ECDSA */ 324 325 326 /*******************************************************************/ 327 /* 328 * mbedTLS backend: Key functions 329 */ 330 331 #define _libssh2_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) \ 332 _libssh2_mbedtls_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) 333 #define _libssh2_pub_priv_keyfilememory(s, m, m_len, p, p_len, \ 334 pk, pk_len, pw) \ 335 _libssh2_mbedtls_pub_priv_keyfilememory(s, m, m_len, p, p_len, \ 336 pk, pk_len, pw) 337 338 339 /*******************************************************************/ 340 /* 341 * mbedTLS backend: Cipher Context structure 342 */ 343 344 #define _libssh2_cipher_ctx mbedtls_cipher_context_t 345 346 #define _libssh2_cipher_type(algo) mbedtls_cipher_type_t algo 347 348 #define _libssh2_cipher_aes256ctr MBEDTLS_CIPHER_AES_256_CTR 349 #define _libssh2_cipher_aes192ctr MBEDTLS_CIPHER_AES_192_CTR 350 #define _libssh2_cipher_aes128ctr MBEDTLS_CIPHER_AES_128_CTR 351 #define _libssh2_cipher_aes256 MBEDTLS_CIPHER_AES_256_CBC 352 #define _libssh2_cipher_aes192 MBEDTLS_CIPHER_AES_192_CBC 353 #define _libssh2_cipher_aes128 MBEDTLS_CIPHER_AES_128_CBC 354 #define _libssh2_cipher_blowfish MBEDTLS_CIPHER_BLOWFISH_CBC 355 #define _libssh2_cipher_arcfour MBEDTLS_CIPHER_ARC4_128 356 #define _libssh2_cipher_cast5 MBEDTLS_CIPHER_NULL 357 #define _libssh2_cipher_3des MBEDTLS_CIPHER_DES_EDE3_CBC 358 359 360 /*******************************************************************/ 361 /* 362 * mbedTLS backend: Cipher functions 363 */ 364 365 #define _libssh2_cipher_init(ctx, type, iv, secret, encrypt) \ 366 _libssh2_mbedtls_cipher_init(ctx, type, iv, secret, encrypt) 367 #define _libssh2_cipher_crypt(ctx, type, encrypt, block, blocklen) \ 368 _libssh2_mbedtls_cipher_crypt(ctx, type, encrypt, block, blocklen) 369 #define _libssh2_cipher_dtor(ctx) \ 370 _libssh2_mbedtls_cipher_dtor(ctx) 371 372 373 /*******************************************************************/ 374 /* 375 * mbedTLS backend: BigNumber Support 376 */ 377 378 #define _libssh2_bn_ctx int /* not used */ 379 #define _libssh2_bn_ctx_new() 0 /* not used */ 380 #define _libssh2_bn_ctx_free(bnctx) ((void)0) /* not used */ 381 382 #define _libssh2_bn mbedtls_mpi 383 384 #define _libssh2_bn_init() \ 385 _libssh2_mbedtls_bignum_init() 386 #define _libssh2_bn_init_from_bin() \ 387 _libssh2_mbedtls_bignum_init() 388 #define _libssh2_bn_set_word(bn, word) \ 389 mbedtls_mpi_lset(bn, word) 390 #define _libssh2_bn_from_bin(bn, len, bin) \ 391 mbedtls_mpi_read_binary(bn, bin, len) 392 #define _libssh2_bn_to_bin(bn, bin) \ 393 mbedtls_mpi_write_binary(bn, bin, mbedtls_mpi_size(bn)) 394 #define _libssh2_bn_bytes(bn) \ 395 mbedtls_mpi_size(bn) 396 #define _libssh2_bn_bits(bn) \ 397 mbedtls_mpi_bitlen(bn) 398 #define _libssh2_bn_free(bn) \ 399 _libssh2_mbedtls_bignum_free(bn) 400 401 402 /*******************************************************************/ 403 /* 404 * mbedTLS backend: Diffie-Hellman support. 405 */ 406 407 #define _libssh2_dh_ctx mbedtls_mpi * 408 #define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx) 409 #define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \ 410 _libssh2_dh_key_pair(dhctx, public, g, p, group_order) 411 #define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \ 412 _libssh2_dh_secret(dhctx, secret, f, p) 413 #define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx) 414 415 416 /*******************************************************************/ 417 /* 418 * mbedTLS backend: forward declarations 419 */ 420 421 void 422 _libssh2_mbedtls_init(void); 423 424 void 425 _libssh2_mbedtls_free(void); 426 427 int 428 _libssh2_mbedtls_random(unsigned char *buf, int len); 429 430 int 431 _libssh2_mbedtls_cipher_init(_libssh2_cipher_ctx *ctx, 432 _libssh2_cipher_type(type), 433 unsigned char *iv, 434 unsigned char *secret, 435 int encrypt); 436 int 437 _libssh2_mbedtls_cipher_crypt(_libssh2_cipher_ctx *ctx, 438 _libssh2_cipher_type(type), 439 int encrypt, 440 unsigned char *block, 441 size_t blocklen); 442 void 443 _libssh2_mbedtls_cipher_dtor(_libssh2_cipher_ctx *ctx); 444 445 int 446 _libssh2_mbedtls_hash_init(mbedtls_md_context_t *ctx, 447 mbedtls_md_type_t mdtype, 448 const unsigned char *key, unsigned long keylen); 449 450 int 451 _libssh2_mbedtls_hash_final(mbedtls_md_context_t *ctx, unsigned char *hash); 452 int 453 _libssh2_mbedtls_hash(const unsigned char *data, unsigned long datalen, 454 mbedtls_md_type_t mdtype, unsigned char *hash); 455 456 _libssh2_bn * 457 _libssh2_mbedtls_bignum_init(void); 458 459 void 460 _libssh2_mbedtls_bignum_free(_libssh2_bn *bn); 461 462 int 463 _libssh2_mbedtls_rsa_new(libssh2_rsa_ctx **rsa, 464 const unsigned char *edata, 465 unsigned long elen, 466 const unsigned char *ndata, 467 unsigned long nlen, 468 const unsigned char *ddata, 469 unsigned long dlen, 470 const unsigned char *pdata, 471 unsigned long plen, 472 const unsigned char *qdata, 473 unsigned long qlen, 474 const unsigned char *e1data, 475 unsigned long e1len, 476 const unsigned char *e2data, 477 unsigned long e2len, 478 const unsigned char *coeffdata, 479 unsigned long coefflen); 480 481 int 482 _libssh2_mbedtls_rsa_new_private(libssh2_rsa_ctx **rsa, 483 LIBSSH2_SESSION *session, 484 const char *filename, 485 const unsigned char *passphrase); 486 487 int 488 _libssh2_mbedtls_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa, 489 LIBSSH2_SESSION *session, 490 const char *filedata, 491 size_t filedata_len, 492 unsigned const char *passphrase); 493 int 494 _libssh2_mbedtls_rsa_sha1_verify(libssh2_rsa_ctx *rsa, 495 const unsigned char *sig, 496 unsigned long sig_len, 497 const unsigned char *m, 498 unsigned long m_len); 499 int 500 _libssh2_mbedtls_rsa_sha1_sign(LIBSSH2_SESSION *session, 501 libssh2_rsa_ctx *rsa, 502 const unsigned char *hash, 503 size_t hash_len, 504 unsigned char **signature, 505 size_t *signature_len); 506 void 507 _libssh2_mbedtls_rsa_free(libssh2_rsa_ctx *rsa); 508 509 int 510 _libssh2_mbedtls_pub_priv_keyfile(LIBSSH2_SESSION *session, 511 unsigned char **method, 512 size_t *method_len, 513 unsigned char **pubkeydata, 514 size_t *pubkeydata_len, 515 const char *privatekey, 516 const char *passphrase); 517 int 518 _libssh2_mbedtls_pub_priv_keyfilememory(LIBSSH2_SESSION *session, 519 unsigned char **method, 520 size_t *method_len, 521 unsigned char **pubkeydata, 522 size_t *pubkeydata_len, 523 const char *privatekeydata, 524 size_t privatekeydata_len, 525 const char *passphrase); 526 #if LIBSSH2_ECDSA 527 int 528 _libssh2_mbedtls_ecdsa_create_key(LIBSSH2_SESSION *session, 529 _libssh2_ec_key **privkey, 530 unsigned char **pubkey_octal, 531 size_t *pubkey_octal_len, 532 libssh2_curve_type curve); 533 int 534 _libssh2_mbedtls_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx **ctx, 535 const unsigned char *k, 536 size_t k_len, 537 libssh2_curve_type curve); 538 int 539 _libssh2_mbedtls_ecdh_gen_k(_libssh2_bn **k, 540 _libssh2_ec_key *privkey, 541 const unsigned char *server_pubkey, 542 size_t server_pubkey_len); 543 int 544 _libssh2_mbedtls_ecdsa_verify(libssh2_ecdsa_ctx *ctx, 545 const unsigned char *r, size_t r_len, 546 const unsigned char *s, size_t s_len, 547 const unsigned char *m, size_t m_len); 548 int 549 _libssh2_mbedtls_ecdsa_new_private(libssh2_ecdsa_ctx **ctx, 550 LIBSSH2_SESSION *session, 551 const char *filename, 552 const unsigned char *passphrase); 553 int 554 _libssh2_mbedtls_ecdsa_new_private_frommemory(libssh2_ecdsa_ctx **ctx, 555 LIBSSH2_SESSION *session, 556 const char *filedata, 557 size_t filedata_len, 558 const unsigned char *passphrase); 559 int 560 _libssh2_mbedtls_ecdsa_sign(LIBSSH2_SESSION *session, 561 libssh2_ecdsa_ctx *ctx, 562 const unsigned char *hash, 563 unsigned long hash_len, 564 unsigned char **signature, 565 size_t *signature_len); 566 libssh2_curve_type 567 _libssh2_mbedtls_ecdsa_key_get_curve_type(libssh2_ecdsa_ctx *ctx); 568 int 569 _libssh2_mbedtls_ecdsa_curve_type_from_name(const char *name, 570 libssh2_curve_type *type); 571 void 572 _libssh2_mbedtls_ecdsa_free(libssh2_ecdsa_ctx *ctx); 573 #endif /* LIBSSH2_ECDSA */ 574 575 extern void 576 _libssh2_dh_init(_libssh2_dh_ctx *dhctx); 577 extern int 578 _libssh2_dh_key_pair(_libssh2_dh_ctx *dhctx, _libssh2_bn *public, 579 _libssh2_bn *g, _libssh2_bn *p, int group_order); 580 extern int 581 _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, 582 _libssh2_bn *f, _libssh2_bn *p); 583 extern void 584 _libssh2_dh_dtor(_libssh2_dh_ctx *dhctx); 585 586 #endif /* __LIBSSH2_MBEDTLS_H */ 587