19 #if defined(HAVE_ECDH) || defined(HAVE_X25519) || defined(HAVE_X448)
27 #if defined(HAVE_ECDH)
28 cx_err_t cx_ecdh_no_throw(
const cx_ecfp_private_key_t *key,
41 CX_CHECK(cx_ecdomain_parameters_length(curve, &sz));
44 #ifdef HAVE_ECC_WEIERSTRASS
45 || CX_CURVE_RANGE(curve, WEIERSTRASS)
47 #ifdef HAVE_ECC_MONTGOMERY
48 || CX_CURVE_RANGE(curve, MONTGOMERY)
51 if (P_len != (1 + sz * 2)) {
52 error = CX_INVALID_PARAMETER;
56 error = CX_INVALID_PARAMETER;
61 error = INVALID_PARAMETER;
67 if (secret_len < P_len) {
68 error = INVALID_PARAMETER;
73 if (secret_len < sz) {
74 error = INVALID_PARAMETER;
79 error = INVALID_PARAMETER;
84 CX_CHECK(cx_bn_lock(sz, 0));
85 CX_CHECK(cx_ecpoint_alloc(&W, curve));
86 CX_CHECK(cx_ecpoint_init(&W, public_point + 1, sz, public_point + 1 + sz, sz));
88 if (CX_CURVE_RANGE(curve, WEIERSTRASS)) {
89 CX_CHECK(cx_ecpoint_rnd_fixed_scalarmul(&W, key->d, key->d_len));
92 CX_CHECK(cx_ecpoint_rnd_scalarmul(&W, key->d, key->d_len));
97 CX_CHECK(cx_ecpoint_export(&W, secret + 1, sz, secret + 1 + sz, sz));
100 CX_CHECK(cx_ecpoint_export(&W, secret, sz, NULL, 0));
111 #if defined(HAVE_X25519)
115 size_t domain_length;
118 CX_CHECK(cx_ecdomain_parameters_length(CX_CURVE_Curve25519, &domain_length));
119 CX_CHECK(cx_bn_lock(domain_length, 0));
120 CX_CHECK(cx_bn_alloc(&bn_u, domain_length));
121 CX_CHECK(cx_bn_init(bn_u, u, domain_length));
122 CX_CHECK(cx_ecpoint_x25519(bn_u, k, k_len));
123 CX_CHECK(cx_bn_export(bn_u, u, domain_length));
131 #if defined(HAVE_X448)
135 size_t domain_length;
138 CX_CHECK(cx_ecdomain_parameters_length(CX_CURVE_Curve448, &domain_length));
139 CX_CHECK(cx_bn_lock(domain_length, 0));
140 CX_CHECK(cx_bn_alloc(&bn_u, domain_length));
141 CX_CHECK(cx_bn_init(bn_u, u, domain_length));
142 CX_CHECK(cx_ecpoint_x448(bn_u, k, k_len));
143 CX_CHECK(cx_bn_export(bn_u, u, domain_length));