mbedtls_3.x.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. --- libssh2-1.10.0/src/mbedtls.c 2020-09-28 13:23:35.000000000 +0100
  2. +++ libssh2.mod/libssh2/src/mbedtls.c 2021-12-01 20:52:58.000000000 +0000
  3. @@ -122,10 +122,10 @@
  4. mbedtls_cipher_init(ctx);
  5. ret = mbedtls_cipher_setup(ctx, cipher_info);
  6. if(!ret)
  7. - ret = mbedtls_cipher_setkey(ctx, secret, cipher_info->key_bitlen, op);
  8. + ret = mbedtls_cipher_setkey(ctx, secret, cipher_info->MBEDTLS_PRIVATE(key_bitlen), op);
  9. if(!ret)
  10. - ret = mbedtls_cipher_set_iv(ctx, iv, cipher_info->iv_size);
  11. + ret = mbedtls_cipher_set_iv(ctx, iv, cipher_info->MBEDTLS_PRIVATE(iv_size));
  12. return ret == 0 ? 0 : -1;
  13. }
  14. @@ -331,29 +331,29 @@
  15. ctx = (libssh2_rsa_ctx *) mbedtls_calloc(1, sizeof(libssh2_rsa_ctx));
  16. if(ctx != NULL) {
  17. - mbedtls_rsa_init(ctx, MBEDTLS_RSA_PKCS_V15, 0);
  18. + mbedtls_rsa_init(ctx);
  19. }
  20. else
  21. return -1;
  22. /* !checksrc! disable ASSIGNWITHINCONDITION 1 */
  23. - if((ret = mbedtls_mpi_read_binary(&(ctx->E), edata, elen) ) != 0 ||
  24. - (ret = mbedtls_mpi_read_binary(&(ctx->N), ndata, nlen) ) != 0) {
  25. + if((ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(E)), edata, elen) ) != 0 ||
  26. + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(N)), ndata, nlen) ) != 0) {
  27. ret = -1;
  28. }
  29. if(!ret) {
  30. - ctx->len = mbedtls_mpi_size(&(ctx->N));
  31. + ctx->MBEDTLS_PRIVATE(len) = mbedtls_mpi_size(&(ctx->MBEDTLS_PRIVATE(N)));
  32. }
  33. if(!ret && ddata) {
  34. /* !checksrc! disable ASSIGNWITHINCONDITION 1 */
  35. - if((ret = mbedtls_mpi_read_binary(&(ctx->D), ddata, dlen) ) != 0 ||
  36. - (ret = mbedtls_mpi_read_binary(&(ctx->P), pdata, plen) ) != 0 ||
  37. - (ret = mbedtls_mpi_read_binary(&(ctx->Q), qdata, qlen) ) != 0 ||
  38. - (ret = mbedtls_mpi_read_binary(&(ctx->DP), e1data, e1len) ) != 0 ||
  39. - (ret = mbedtls_mpi_read_binary(&(ctx->DQ), e2data, e2len) ) != 0 ||
  40. - (ret = mbedtls_mpi_read_binary(&(ctx->QP), coeffdata, coefflen) )
  41. + if((ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(D)), ddata, dlen) ) != 0 ||
  42. + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(P)), pdata, plen) ) != 0 ||
  43. + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(Q)), qdata, qlen) ) != 0 ||
  44. + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(DP)), e1data, e1len) ) != 0 ||
  45. + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(DQ)), e2data, e2len) ) != 0 ||
  46. + (ret = mbedtls_mpi_read_binary(&(ctx->MBEDTLS_PRIVATE(QP)), coeffdata, coefflen) )
  47. != 0) {
  48. ret = -1;
  49. }
  50. @@ -381,14 +381,16 @@
  51. mbedtls_pk_context pkey;
  52. mbedtls_rsa_context *pk_rsa;
  53. +
  54. *rsa = (libssh2_rsa_ctx *) LIBSSH2_ALLOC(session, sizeof(libssh2_rsa_ctx));
  55. if(*rsa == NULL)
  56. return -1;
  57. - mbedtls_rsa_init(*rsa, MBEDTLS_RSA_PKCS_V15, 0);
  58. + mbedtls_rsa_init(*rsa);
  59. mbedtls_pk_init(&pkey);
  60. - ret = mbedtls_pk_parse_keyfile(&pkey, filename, (char *)passphrase);
  61. + ret = mbedtls_pk_parse_keyfile(&pkey, filename, (char *)passphrase,
  62. + mbedtls_ctr_drbg_random, &_libssh2_mbedtls_ctr_drbg);
  63. if(ret != 0 || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) {
  64. mbedtls_pk_free(&pkey);
  65. mbedtls_rsa_free(*rsa);
  66. @@ -436,7 +438,8 @@
  67. pwd_len = passphrase != NULL ? strlen((const char *)passphrase) : 0;
  68. ret = mbedtls_pk_parse_key(&pkey, (unsigned char *)filedata_nullterm,
  69. filedata_len + 1,
  70. - passphrase, pwd_len);
  71. + passphrase, pwd_len,
  72. + mbedtls_ctr_drbg_random, &_libssh2_mbedtls_ctr_drbg);
  73. _libssh2_mbedtls_safe_free(filedata_nullterm, filedata_len);
  74. if(ret != 0 || mbedtls_pk_get_type(&pkey) != MBEDTLS_PK_RSA) {
  75. @@ -468,8 +471,8 @@
  76. if(ret)
  77. return -1; /* failure */
  78. - ret = mbedtls_rsa_pkcs1_verify(rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC,
  79. - MBEDTLS_MD_SHA1, SHA_DIGEST_LENGTH,
  80. + ret = mbedtls_rsa_pkcs1_verify(rsa,
  81. + MBEDTLS_MD_SHA1, SHA_DIGEST_LENGTH,
  82. hash, sig);
  83. return (ret == 0) ? 0 : -1;
  84. @@ -489,13 +492,13 @@
  85. (void)hash_len;
  86. - sig_len = rsa->len;
  87. + sig_len = rsa->MBEDTLS_PRIVATE(len);
  88. sig = LIBSSH2_ALLOC(session, sig_len);
  89. if(!sig) {
  90. return -1;
  91. }
  92. - ret = mbedtls_rsa_pkcs1_sign(rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE,
  93. + ret = mbedtls_rsa_pkcs1_sign(rsa, NULL, NULL,
  94. MBEDTLS_MD_SHA1, SHA_DIGEST_LENGTH,
  95. hash, sig);
  96. if(ret) {
  97. @@ -526,8 +529,8 @@
  98. unsigned char *key;
  99. unsigned char *p;
  100. - e_bytes = mbedtls_mpi_size(&rsa->E);
  101. - n_bytes = mbedtls_mpi_size(&rsa->N);
  102. + e_bytes = mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(E));
  103. + n_bytes = mbedtls_mpi_size(&rsa->MBEDTLS_PRIVATE(N));
  104. /* Key form is "ssh-rsa" + e + n. */
  105. len = 4 + 7 + 4 + e_bytes + 4 + n_bytes;
  106. @@ -547,11 +550,11 @@
  107. _libssh2_htonu32(p, e_bytes);
  108. p += 4;
  109. - mbedtls_mpi_write_binary(&rsa->E, p, e_bytes);
  110. + mbedtls_mpi_write_binary(&rsa->MBEDTLS_PRIVATE(E), p, e_bytes);
  111. _libssh2_htonu32(p, n_bytes);
  112. p += 4;
  113. - mbedtls_mpi_write_binary(&rsa->N, p, n_bytes);
  114. + mbedtls_mpi_write_binary(&rsa->MBEDTLS_PRIVATE(N), p, n_bytes);
  115. *keylen = (size_t)(p - key);
  116. return key;
  117. @@ -623,7 +626,8 @@
  118. int ret;
  119. mbedtls_pk_init(&pkey);
  120. - ret = mbedtls_pk_parse_keyfile(&pkey, privatekey, passphrase);
  121. + ret = mbedtls_pk_parse_keyfile(&pkey, privatekey, passphrase,
  122. + mbedtls_ctr_drbg_random, &_libssh2_mbedtls_ctr_drbg);
  123. if(ret != 0) {
  124. mbedtls_strerror(ret, (char *)buf, sizeof(buf));
  125. mbedtls_pk_free(&pkey);
  126. @@ -670,7 +674,8 @@
  127. ret = mbedtls_pk_parse_key(&pkey,
  128. (unsigned char *)privatekeydata_nullterm,
  129. privatekeydata_len + 1,
  130. - (const unsigned char *)passphrase, pwd_len);
  131. + (const unsigned char *)passphrase, pwd_len,
  132. + mbedtls_ctr_drbg_random, &_libssh2_mbedtls_ctr_drbg);
  133. _libssh2_mbedtls_safe_free(privatekeydata_nullterm, privatekeydata_len);
  134. if(ret != 0) {
  135. @@ -766,13 +771,13 @@
  136. &_libssh2_mbedtls_ctr_drbg) != 0)
  137. goto failed;
  138. - plen = 2 * mbedtls_mpi_size(&(*privkey)->grp.P) + 1;
  139. + plen = 2 * mbedtls_mpi_size(&(*privkey)->MBEDTLS_PRIVATE(grp).P) + 1;
  140. *pubkey_oct = LIBSSH2_ALLOC(session, plen);
  141. if(*pubkey_oct == NULL)
  142. goto failed;
  143. - if(mbedtls_ecp_point_write_binary(&(*privkey)->grp, &(*privkey)->Q,
  144. + if(mbedtls_ecp_point_write_binary(&(*privkey)->MBEDTLS_PRIVATE(grp), &(*privkey)->MBEDTLS_PRIVATE(Q),
  145. MBEDTLS_ECP_PF_UNCOMPRESSED,
  146. pubkey_oct_len, *pubkey_oct, plen) == 0)
  147. return 0;
  148. @@ -805,13 +810,13 @@
  149. mbedtls_ecdsa_init(*ctx);
  150. - if(mbedtls_ecp_group_load(&(*ctx)->grp, (mbedtls_ecp_group_id)curve) != 0)
  151. + if(mbedtls_ecp_group_load(&(*ctx)->MBEDTLS_PRIVATE(grp), (mbedtls_ecp_group_id)curve) != 0)
  152. goto failed;
  153. - if(mbedtls_ecp_point_read_binary(&(*ctx)->grp, &(*ctx)->Q, k, k_len) != 0)
  154. + if(mbedtls_ecp_point_read_binary(&(*ctx)->MBEDTLS_PRIVATE(grp), &(*ctx)->MBEDTLS_PRIVATE(Q), k, k_len) != 0)
  155. goto failed;
  156. - if(mbedtls_ecp_check_pubkey(&(*ctx)->grp, &(*ctx)->Q) == 0)
  157. + if(mbedtls_ecp_check_pubkey(&(*ctx)->MBEDTLS_PRIVATE(grp), &(*ctx)->MBEDTLS_PRIVATE(Q)) == 0)
  158. return 0;
  159. failed:
  160. @@ -842,21 +847,21 @@
  161. mbedtls_ecp_point_init(&pubkey);
  162. - if(mbedtls_ecp_point_read_binary(&privkey->grp, &pubkey,
  163. + if(mbedtls_ecp_point_read_binary(&privkey->MBEDTLS_PRIVATE(grp), &pubkey,
  164. server_pubkey, server_pubkey_len) != 0) {
  165. rc = -1;
  166. goto cleanup;
  167. }
  168. - if(mbedtls_ecdh_compute_shared(&privkey->grp, *k,
  169. - &pubkey, &privkey->d,
  170. + if(mbedtls_ecdh_compute_shared(&privkey->MBEDTLS_PRIVATE(grp), *k,
  171. + &pubkey, &privkey->MBEDTLS_PRIVATE(d),
  172. mbedtls_ctr_drbg_random,
  173. &_libssh2_mbedtls_ctr_drbg) != 0) {
  174. rc = -1;
  175. goto cleanup;
  176. }
  177. - if(mbedtls_ecp_check_privkey(&privkey->grp, *k) != 0)
  178. + if(mbedtls_ecp_check_privkey(&privkey->MBEDTLS_PRIVATE(grp), *k) != 0)
  179. rc = -1;
  180. cleanup:
  181. @@ -871,9 +876,9 @@
  182. unsigned char hsh[SHA##digest_type##_DIGEST_LENGTH]; \
  183. \
  184. if(libssh2_sha##digest_type(m, m_len, hsh) == 0) { \
  185. - rc = mbedtls_ecdsa_verify(&ctx->grp, hsh, \
  186. + rc = mbedtls_ecdsa_verify(&ctx->MBEDTLS_PRIVATE(grp), hsh, \
  187. SHA##digest_type##_DIGEST_LENGTH, \
  188. - &ctx->Q, &pr, &ps); \
  189. + &ctx->MBEDTLS_PRIVATE(Q), &pr, &ps); \
  190. } \
  191. \
  192. }
  193. @@ -936,7 +941,8 @@
  194. pwd_len = pwd ? strlen((const char *) pwd) : 0;
  195. - if(mbedtls_pk_parse_key(pkey, data, data_len, pwd, pwd_len) != 0)
  196. + if(mbedtls_pk_parse_key(pkey, data, data_len, pwd, pwd_len,
  197. + mbedtls_ctr_drbg_random, &_libssh2_mbedtls_ctr_drbg) != 0)
  198. goto failed;
  199. if(mbedtls_pk_get_type(pkey) != MBEDTLS_PK_ECKEY)
  200. @@ -1001,19 +1007,19 @@
  201. mbedtls_ecdsa_init(*ctx);
  202. - if(mbedtls_ecp_group_load(&(*ctx)->grp, (mbedtls_ecp_group_id)type) != 0)
  203. + if(mbedtls_ecp_group_load(&(*ctx)->MBEDTLS_PRIVATE(grp), (mbedtls_ecp_group_id)type) != 0)
  204. goto failed;
  205. - if(mbedtls_mpi_read_binary(&(*ctx)->d, exponent, exponentlen) != 0)
  206. + if(mbedtls_mpi_read_binary(&(*ctx)->MBEDTLS_PRIVATE(d), exponent, exponentlen) != 0)
  207. goto failed;
  208. - if(mbedtls_ecp_mul(&(*ctx)->grp, &(*ctx)->Q,
  209. - &(*ctx)->d, &(*ctx)->grp.G,
  210. + if(mbedtls_ecp_mul(&(*ctx)->MBEDTLS_PRIVATE(grp), &(*ctx)->MBEDTLS_PRIVATE(Q),
  211. + &(*ctx)->MBEDTLS_PRIVATE(d), &(*ctx)->MBEDTLS_PRIVATE(grp).G,
  212. mbedtls_ctr_drbg_random,
  213. &_libssh2_mbedtls_ctr_drbg) != 0)
  214. goto failed;
  215. - if(mbedtls_ecp_check_privkey(&(*ctx)->grp, &(*ctx)->d) == 0)
  216. + if(mbedtls_ecp_check_privkey(&(*ctx)->MBEDTLS_PRIVATE(grp), &(*ctx)->MBEDTLS_PRIVATE(d)) == 0)
  217. goto cleanup;
  218. failed:
  219. @@ -1157,7 +1163,7 @@
  220. mbedtls_mpi_init(&pr);
  221. mbedtls_mpi_init(&ps);
  222. - if(mbedtls_ecdsa_sign(&ctx->grp, &pr, &ps, &ctx->d,
  223. + if(mbedtls_ecdsa_sign(&ctx->MBEDTLS_PRIVATE(grp), &pr, &ps, &ctx->MBEDTLS_PRIVATE(d),
  224. hash, hash_len,
  225. mbedtls_ctr_drbg_random,
  226. &_libssh2_mbedtls_ctr_drbg) != 0)
  227. @@ -1204,7 +1210,7 @@
  228. libssh2_curve_type
  229. _libssh2_mbedtls_ecdsa_get_curve_type(libssh2_ecdsa_ctx *ctx)
  230. {
  231. - return (libssh2_curve_type) ctx->grp.id;
  232. + return (libssh2_curve_type) ctx->MBEDTLS_PRIVATE(grp).id;
  233. }
  234. /* _libssh2_ecdsa_curve_type_from_name
  235. --- libssh2-1.10.0/src/mbedtls.h 2020-09-28 13:23:35.000000000 +0100
  236. +++ libssh2.mod/libssh2/src/mbedtls.h 2021-11-30 20:54:52.000000000 +0000
  237. @@ -65,12 +65,12 @@
  238. #define LIBSSH2_AES 1
  239. #define LIBSSH2_AES_CTR 1
  240. -#define LIBSSH2_BLOWFISH 1
  241. -#define LIBSSH2_RC4 1
  242. +#define LIBSSH2_BLOWFISH 0
  243. +#define LIBSSH2_RC4 0
  244. #define LIBSSH2_CAST 0
  245. #define LIBSSH2_3DES 1
  246. -#define LIBSSH2_RSA 1
  247. +#define LIBSSH2_RSA 0
  248. #define LIBSSH2_DSA 0
  249. #ifdef MBEDTLS_ECDSA_C
  250. # define LIBSSH2_ECDSA 1