// // ec_wNAF_mul from 0xd9297c to 0xd937ac (3632 bytes) // // 3 xrefs: // > EC_POINTs_mul @ 0xd9260c // > ec_GF2m_simple_mul @ 0xe7d548 // > @ 0x84ee8 // // This function is hookable on this platform! // // Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA // Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings // __int64 __fastcall ec_wNAF_mul( __int64 *a1, _QWORD *a2, __int64 a3, unsigned __int64 a4, _QWORD **a5, __int64 a6, __int64 a7) { __int64 v9; // x2 _QWORD *v11; // x22 __int64 v14; // x0 __int64 v15; // d13 __int64 v16; // x0 __int64 v17; // x0 __int64 v18; // x3 unsigned __int64 v19; // x0 unsigned __int64 v20; // x0 __int64 v21; // x24 char *v22; // d11 __int64 v23; // x25 __int64 v24; // x27 unsigned __int64 *v25; // d15 _QWORD *v26; // x21 __int64 v27; // x0 __int64 v28; // d14 __int64 v29; // x5 __int64 v30; // x27 unsigned __int64 *v31; // d8 unsigned __int64 v32; // x24 unsigned __int64 v33; // d12 unsigned __int64 v34; // x23 __int64 v35; // d10 unsigned __int64 v36; // x0 __int64 v37; // x5 __int64 v38; // x1 __int64 v39; // x0 __int64 v40; // x0 unsigned __int64 v41; // x0 __int64 v43; // x0 __int64 v44; // x6 _QWORD **v45; // x19 _BOOL4 v46; // w27 __int64 v47; // x0 _QWORD *v48; // x20 __int64 v49; // t1 _QWORD *v50; // x0 _QWORD **v51; // x20 _QWORD *v52; // t1 __int64 v53; // x0 _QWORD *v54; // x24 int v55; // w0 __int64 v56; // x3 __int64 v57; // x27 unsigned __int64 v58; // x0 __int64 v59; // x5 __int64 v60; // x0 _QWORD *v61; // d8 _QWORD *v62; // x24 __int64 v63; // x3 char v64; // w0 unsigned __int64 v65; // x27 _QWORD *v66; // x0 int v67; // w0 unsigned __int64 v68; // x2 unsigned __int64 v69; // x0 _QWORD *v70; // x6 char *v71; // d8 unsigned __int64 v72; // x19 size_t *v73; // x24 size_t v74; // x0 void *v75; // x0 const void *v76; // x1 size_t v77; // x2 unsigned __int64 i; // x5 _QWORD **v79; // x0 int v80; // w0 unsigned __int64 v81; // x5 __int64 v82; // x9 unsigned __int64 v83; // x27 __int64 v84; // x2 _QWORD *v85; // x1 int v86; // w0 __int64 v87; // x23 int v88; // w26 int v89; // s10 __int64 v90; // d12 __int64 v91; // x28 unsigned __int64 v92; // d8 int v93; // w3 int v94; // w1 int v95; // w3 int v96; // w0 __int64 v97; // [xsp+A8h] [xbp+A8h] int v98; // [xsp+B0h] [xbp+B0h] __int64 v99; // [xsp+B0h] [xbp+B0h] _QWORD *v100; // [xsp+B8h] [xbp+B8h] unsigned __int64 v101; // [xsp+C0h] [xbp+C0h] size_t v102; // [xsp+C8h] [xbp+C8h] __int64 v103; // [xsp+D0h] [xbp+D0h] __int64 v104; // [xsp+D8h] [xbp+D8h] __int64 v105; // [xsp+E0h] [xbp+E0h] __int64 v106; // [xsp+E0h] [xbp+E0h] unsigned __int64 v107; // [xsp+E0h] [xbp+E0h] __int64 v108; // [xsp+E8h] [xbp+E8h] __int64 v109; // [xsp+E8h] [xbp+E8h] __int64 v110; // [xsp+E8h] [xbp+E8h] __int64 v111; // [xsp+E8h] [xbp+E8h] __int64 v112; // [xsp+E8h] [xbp+E8h] __int64 v113; // [xsp+E8h] [xbp+E8h] __int64 v114; // [xsp+E8h] [xbp+E8h] __int64 v115; // [xsp+E8h] [xbp+E8h] _QWORD *v116; // [xsp+E8h] [xbp+E8h] unsigned __int64 v117; // [xsp+E8h] [xbp+E8h] unsigned __int64 v118; // [xsp+E8h] [xbp+E8h] __int64 v119; // [xsp+E8h] [xbp+E8h] unsigned __int64 v120; // [xsp+E8h] [xbp+E8h] int v121; // [xsp+E8h] [xbp+E8h] unsigned __int64 v122; // [xsp+F8h] [xbp+F8h] BYREF v9 = *a1; v11 = a2; if ( *a1 != *a2 ) { ERR_put_error(16, 187, 101, "crypto/ec/ec_mult.c", 155); return 0; } if ( !a3 && !a4 ) return EC_POINT_set_to_infinity((__int64)a1, a2); if ( a4 ) { if ( v9 != **a5 ) { LABEL_38: ERR_put_error(16, 187, 101, "crypto/ec/ec_mult.c", 165); return 0; } v14 = 0; while ( ++v14 != a4 ) { a2 = (_QWORD *)*a5[v14]; if ( (_QWORD *)v9 != a2 ) goto LABEL_38; } } v15 = 0; if ( !a7 ) { v113 = a6; v53 = BN_CTX_new(0, a2, v9); if ( !v53 ) { v22 = (_BYTE *)&unk_F6E000; goto LABEL_82; } v15 = v53; a6 = v113; } if ( !a3 ) { v18 = 0; v98 = 0; v105 = 0; v19 = 0; v97 = 0; v104 = 0; v102 = 0; v100 = nullptr; goto LABEL_16; } v108 = a6; v100 = (_QWORD *)EC_GROUP_get0_generator((__int64)a1); a6 = v108; if ( !v100 ) { v22 = (char *)&unk_F6E000; ERR_put_error(16, 187, 113, "crypto/ec/ec_mult.c", 179); LABEL_82: v28 = 0; v46 = 0; BN_CTX_free(v15); EC_POINT_free(0); CRYPTO_free(0, v22 + 2880, 484); CRYPTO_free(0, v22 + 2880, 485); goto LABEL_49; } v16 = a1[20]; v105 = v16; if ( !v16 ) { v18 = 1; v97 = 0; v102 = 0; v19 = 1; v98 = 1; v104 = 1; goto LABEL_16; } v17 = *(_QWORD *)(v16 + 16); v18 = 1; if ( !v17 ) { LABEL_15: v105 = v17; v97 = v17; v102 = v17; v19 = 1; v98 = 1; v104 = 1; goto LABEL_16; } v55 = EC_POINT_cmp(a1, v100, **(_QWORD ***)(v105 + 32)); a6 = v108; if ( v55 ) { v18 = 1; v17 = 0; goto LABEL_15; } v102 = *(_QWORD *)(v105 + 8); v67 = BN_num_bits(a3); v68 = *(_QWORD *)(v105 + 16); v97 = 1LL << ((unsigned __int8)*(_QWORD *)(v105 + 24) - 1); a6 = v108; if ( *(_QWORD *)(v105 + 40) != v97 * v68 ) { v22 = (char *)&unk_F6E000; ERR_put_error(16, 187, 68, "crypto/ec/ec_mult.c", 207); goto LABEL_82; } v18 = 0; v98 = 0; v19 = v67 / v102 + 1; if ( v19 > v68 ) v19 = *(_QWORD *)(v105 + 16); v104 = v19; LABEL_16: v20 = v19 + a4; v21 = 8 * v20; v22 = (char *)&unk_F6E000; v101 = v20; v103 = a6; v109 = v18; v23 = CRYPTO_malloc(8 * v20, "crypto/ec/ec_mult.c", 221); v24 = CRYPTO_malloc(v21, "crypto/ec/ec_mult.c", 222); v25 = (unsigned __int64 *)v24; v26 = (_QWORD *)CRYPTO_malloc(v21 + 8, "crypto/ec/ec_mult.c", 223); v27 = CRYPTO_malloc(v21, "crypto/ec/ec_mult.c", 225); v28 = v27; if ( !v26 ) { v46 = 0; ERR_put_error(16, 187, 65, "crypto/ec/ec_mult.c", 232); BN_CTX_free(v15); EC_POINT_free(0); CRYPTO_free(v23, "crypto/ec/ec_mult.c", 484); CRYPTO_free(v25, "crypto/ec/ec_mult.c", 485); goto LABEL_49; } *v26 = 0; if ( !v24 || (v29 = v103, !v23) ) { v45 = nullptr; v46 = 0; ERR_put_error(16, 187, 65, "crypto/ec/ec_mult.c", 232); BN_CTX_free(v15); EC_POINT_free(0); CRYPTO_free(v23, "crypto/ec/ec_mult.c", 484); CRYPTO_free(v25, "crypto/ec/ec_mult.c", 485); v47 = *v26; if ( !*v26 ) goto LABEL_144; goto LABEL_43; } if ( !v27 ) { v45 = nullptr; v46 = 0; ERR_put_error(16, 187, 65, "crypto/ec/ec_mult.c", 232); BN_CTX_free(v15); EC_POINT_free(0); CRYPTO_free(v23, "crypto/ec/ec_mult.c", 484); CRYPTO_free(v25, "crypto/ec/ec_mult.c", 485); v47 = *v26; if ( !*v26 ) { LABEL_144: CRYPTO_free(v26, "crypto/ec/ec_mult.c", 492); goto LABEL_49; } LABEL_43: v48 = v26; do { CRYPTO_free(v47, "crypto/ec/ec_mult.c", 490); v49 = v48[1]; ++v48; v47 = v49; } while ( v49 ); goto LABEL_45; } v30 = 0; v31 = v25; v32 = 0; v33 = v109 + a4; v34 = 0; v35 = 0; while ( v32 != v33 ) { if ( a4 <= v32 ) { v112 = v29; v36 = (int)BN_num_bits(a3); v37 = v112; if ( (unsigned __int64)(int)v36 > 0x7CF ) { v38 = 6; *(_QWORD *)(v23 + v30 * 8) = 6; v26[v30 + 1] = 0; v35 += 32; v39 = a3; goto LABEL_26; } } else { v110 = v29; v36 = (int)BN_num_bits(*(_QWORD *)(v29 + v30 * 8)); v37 = v110; if ( (unsigned __int64)(int)v36 > 0x7CF ) { v38 = 6; *(_QWORD *)(v23 + v30 * 8) = 6; v26[v30 + 1] = 0; v35 += 32; LABEL_25: v39 = *(_QWORD *)(v37 + v30 * 8); goto LABEL_26; } } if ( v36 > 0x31F ) { v38 = 5; v43 = 16; v44 = 5; } else if ( v36 > 0x12B ) { v38 = 4; v43 = 8; v44 = 4; } else if ( v36 > 0x45 ) { v38 = 3; v43 = 4; v44 = 3; } else if ( v36 > 0x13 ) { v43 = 2; v38 = 2; v44 = 2; } else { v43 = 1; v38 = 1; v44 = 1; } *(_QWORD *)(v23 + v30 * 8) = v44; v26[v30 + 1] = 0; v35 += v43; v39 = a3; if ( a4 > v32 ) goto LABEL_25; LABEL_26: v111 = v37; v40 = bn_compute_wNAF(v39, v38, v31); v26[v30++] = v40; if ( !v40 ) goto LABEL_58; ++v32; v29 = v111; v41 = *v31; if ( v34 < *v31++ ) v34 = v41; } if ( !v104 ) goto LABEL_70; if ( !v105 ) { if ( v98 == 1 ) goto LABEL_70; v45 = nullptr; v46 = 0; v54 = nullptr; ERR_put_error(16, 187, 68, "crypto/ec/ec_mult.c", 262); goto LABEL_59; } v122 = 0; if ( v98 ) { ERR_put_error(16, 187, 68, "crypto/ec/ec_mult.c", 271); goto LABEL_58; } v114 = a4; v56 = *(_QWORD *)(v105 + 24); *(_QWORD *)(v23 + 8 * a4) = v56; v57 = bn_compute_wNAF(a3, (unsigned int)v56, &v122); if ( !v57 ) { LABEL_58: v45 = nullptr; v46 = 0; v54 = nullptr; goto LABEL_59; } v58 = v122; v59 = 8 * a4; if ( v122 <= v34 ) { v26[a4] = v57; v101 = a4 + 1; v26[v114 + 1] = 0; v25[a4] = v58; *(_QWORD *)(v28 + 8 * a4) = *(_QWORD *)(v105 + 32); goto LABEL_70; } if ( v122 < v104 * v102 ) { v69 = (v122 - 1 + v102) / v102; v101 = v69 + a4; if ( v69 > *(_QWORD *)(v105 + 16) ) { ERR_put_error(16, 187, 68, "crypto/ec/ec_mult.c", 314); CRYPTO_free(v57, "crypto/ec/ec_mult.c", 315); goto LABEL_58; } } v70 = *(_QWORD **)(v105 + 32); if ( v101 > a4 ) { v71 = (char *)v57; v72 = a4; v73 = &v25[v114]; v99 = vshld_n_s64(v97, 3u); do { if ( v72 < v101 - 1 ) { *v73 = v102; if ( v102 > v122 ) { ERR_put_error(16, 187, 68, "crypto/ec/ec_mult.c", 329); CRYPTO_free(v57, "crypto/ec/ec_mult.c", 330); goto LABEL_58; } v122 -= v102; v74 = *v73; } else { v74 = v122; *v73 = v122; } ++v72; v106 = v59; v116 = v70; v26[v72] = 0; v75 = (void *)CRYPTO_malloc(v74, "crypto/ec/ec_mult.c", 342); v76 = v71; *(_QWORD *)((char *)v26 + v106) = v75; v71 += v102; if ( !v75 ) { ERR_put_error(16, 187, 65, "crypto/ec/ec_mult.c", 344); CRYPTO_free(v57, "crypto/ec/ec_mult.c", 345); goto LABEL_58; } v77 = *v73++; memcpy(v75, v76, v77); if ( v34 < *(v73 - 1) ) v34 = *(v73 - 1); if ( !*v116 ) { ERR_put_error(16, 187, 68, "crypto/ec/ec_mult.c", 353); CRYPTO_free(v57, "crypto/ec/ec_mult.c", 354); goto LABEL_58; } *(_QWORD *)(v28 + v106) = v116; v59 = v106 + 8; v70 = (_QWORD *)((char *)v116 + v99); } while ( v101 > v72 ); } CRYPTO_free(v57, "crypto/ec/ec_mult.c", 361); LABEL_70: v60 = CRYPTO_malloc(8 * (v35 + 1), "crypto/ec/ec_mult.c", 371); v45 = (_QWORD **)v60; if ( v60 ) { v61 = (_QWORD *)(v60 + 8 * (v35 + 1) - 8); *v61 = 0; v62 = (_QWORD *)v60; if ( v33 ) { v63 = 0; while ( 1 ) { v64 = *(_QWORD *)(v23 + 8 * v63) - 1; *(_QWORD *)(v28 + 8 * v63) = v62; if ( 1LL << v64 ) break; LABEL_78: if ( ++v63 == v33 ) goto LABEL_79; } v65 = 0; while ( 1 ) { ++v62; v115 = v63; ++v65; v66 = EC_POINT_new(a1); *(v62 - 1) = v66; if ( !v66 ) break; v63 = v115; if ( 1LL << ((unsigned __int8)*(_QWORD *)(v23 + 8 * v115) - 1) <= v65 ) goto LABEL_78; } v46 = 0; v54 = nullptr; } else { LABEL_79: if ( v62 == v61 ) { v54 = EC_POINT_new(a1); if ( v54 ) { for ( i = 0; i != v33; i = v81 + 1 ) { v79 = *(_QWORD ***)(v28 + 8 * i); if ( i >= a4 ) { v120 = i; v80 = EC_POINT_copy(*v79, v100); v81 = v120; if ( !v80 ) goto LABEL_124; } else { v117 = i; v80 = EC_POINT_copy(*v79, a5[i]); v81 = v117; if ( !v80 ) goto LABEL_124; } if ( *(_QWORD *)(v23 + 8 * v81) > 1u ) { v118 = v81; v80 = EC_POINT_dbl(a1, v54, **(_QWORD ***)(v28 + 8 * v81)); if ( !v80 ) goto LABEL_124; v81 = v118; if ( (unsigned __int64)(1LL << ((unsigned __int8)*(_QWORD *)(v23 + 8 * v118) - 1)) > 1 ) { v82 = 0; v83 = 1; while ( 1 ) { v107 = v81; v84 = *(_QWORD *)(v28 + 8 * v81); v85 = *(_QWORD **)(v84 + 8 * v83++); v119 = v82 + 8; v80 = EC_POINT_add(a1, v85, *(_QWORD **)(v84 + v82), v54); if ( !v80 ) break; v81 = v107; v82 = v119; if ( 1LL << ((unsigned __int8)*(_QWORD *)(v23 + 8 * v107) - 1) <= v83 ) goto LABEL_125; } LABEL_124: v46 = v80; goto LABEL_59; } } LABEL_125: ; } v46 = 0; if ( (unsigned int)EC_POINTs_make_affine(a1, v35, v45) ) { v86 = v34 - 1; v87 = 0; v46 = 1; v88 = 0; v89 = v86; v90 = v86; while ( ((v89 - (_DWORD)v87) & 0x80000000) == 0 ) { if ( !v46 && !(unsigned int)EC_POINT_dbl(a1, v11, v11) ) goto LABEL_59; v91 = 0; v92 = v90 - v87; if ( v101 ) { do { if ( v25[v91] > v92 ) { v94 = *(char *)(v26[v91] + v92); if ( *(_BYTE *)(v26[v91] + v92) ) { v95 = ((unsigned int)v94 >> 31) + (v94 ^ (v94 >> 31)); if ( (unsigned int)v94 >> 31 != v88 ) { if ( !v46 ) { v121 = ((unsigned int)v94 >> 31) + (v94 ^ (v94 >> 31)); v96 = EC_POINT_invert((__int64)a1, v11); v95 = v121; if ( !v96 ) goto LABEL_59; } v88 ^= 1u; } v93 = v95 >> 1; if ( v46 ) { v80 = EC_POINT_copy(v11, *(_QWORD **)(*(_QWORD *)(v28 + 8 * v91) + 8LL * v93)); if ( !v80 ) goto LABEL_124; v46 = 0; } else if ( !(unsigned int)EC_POINT_add( a1, v11, v11, *(_QWORD **)(*(_QWORD *)(v28 + 8 * v91) + 8LL * v93)) ) { goto LABEL_59; } } } ++v91; } while ( v91 != v101 ); } ++v87; } if ( v46 ) { v46 = EC_POINT_set_to_infinity((__int64)a1, v11) != 0; } else { v46 = 1; if ( v88 ) v46 = EC_POINT_invert((__int64)a1, v11) != 0; } } } else { v46 = 0; } } else { v46 = 0; v54 = nullptr; ERR_put_error(16, 187, 68, "crypto/ec/ec_mult.c", 390); } } } else { v46 = 0; v54 = nullptr; ERR_put_error(16, 187, 65, "crypto/ec/ec_mult.c", 373); } LABEL_59: BN_CTX_free(v15); EC_POINT_free((__int64)v54); CRYPTO_free(v23, "crypto/ec/ec_mult.c", 484); CRYPTO_free(v25, "crypto/ec/ec_mult.c", 485); v47 = *v26; if ( *v26 ) goto LABEL_43; LABEL_45: CRYPTO_free(v26, "crypto/ec/ec_mult.c", 492); if ( v45 ) { v50 = *v45; v51 = v45; if ( *v45 ) { do { EC_POINT_clear_free((__int64)v50); v52 = v51[1]; ++v51; v50 = v52; } while ( v52 ); } CRYPTO_free(v45, "crypto/ec/ec_mult.c", 498); } LABEL_49: CRYPTO_free(v28, v22 + 2880, 500); return v46; }
GD Web Decomp Icon

GD Web Decomp

Raw Source